v30.3-roots.1 · Commit 10: [PATCH 10/68] fix: harden Roots priority and wallet policy boundaries
src/wallet/spend.cpp
Before: src/wallet/spend.cpp · After: src/wallet/spend.cpp
File metadata
index 9524e7a0beceff13126431a188106fff6d948f34..f58d9f27ae022e4594642ffc9c633729e2e4800b 100644
Download original patch · Release notes
Diff rows 1–38 of 38. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/wallet/spend.cpp
CHANGED
|
@@ -983,6 +983,20 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256&
|
|
|
983
983
|
return true;
|
|
984
984
|
}
|
|
985
985
|
|
|
986
|
+
uint32_t GetAntiFeeSnipingLockTime(int block_height, FastRandomContext& rng_fast)
|
|
987
|
+
{
|
|
988
|
+
uint32_t lock_time{static_cast<uint32_t>(block_height)};
|
|
989
|
+
if (rng_fast.randrange(10) == 0) {
|
|
990
|
+
lock_time = std::max(0, int(lock_time) - int(rng_fast.randrange(100)));
|
|
991
|
+
}
|
|
992
|
+
if (lock_time == PARASITE_CAT21_LOCKTIME) --lock_time;
|
|
993
|
+
return lock_time;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Set a height-based locktime for new transactions (uses the height of the
|
|
998
|
+
* current chain tip unless we are not synced with the current chain
|
|
999
|
+
*/
|
|
986
1000
|
void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast,
|
|
987
1001
|
interfaces::Chain& chain, const uint256& block_hash, int block_height)
|
|
988
1002
|
{
|
|
@@ -1009,15 +1023,9 @@ void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast,
|
|
|
1009
1023
|
// now we ensure code won't be written that makes assumptions about
|
|
1010
1024
|
// nLockTime that preclude a fix later.
|
|
1011
1025
|
if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
|
|
1012
|
-
tx.nLockTime = block_height;
|
|
1013
|
-
|
|
1014
|
-
// Secondly occasionally randomly pick a nLockTime even further back, so
|
|
1015
|
-
// that transactions that are delayed after signing for whatever reason,
|
|
1016
|
-
// e.g. high-latency mix networks and some CoinJoin implementations, have
|
|
1017
|
-
// better privacy.
|
|
1018
|
-
if (rng_fast.randrange(10) == 0) {
|
|
1019
|
-
tx.nLockTime = std::max(0, int(tx.nLockTime) - int(rng_fast.randrange(100)));
|
|
1020
|
-
}
|
|
1026
|
+
// Occasionally pick a nLockTime further back so delayed transactions do
|
|
1027
|
+
// not reveal a unique fingerprint. Avoid values reserved by local policy.
|
|
1028
|
+
tx.nLockTime = GetAntiFeeSnipingLockTime(block_height, rng_fast);
|
|
1021
1029
|
} else {
|
|
1022
1030
|
// If our chain is lagging behind, we can't discourage fee sniping nor help
|
|
1023
1031
|
// the privacy of high-latency transactions. To avoid leaking a potentially
|