v29.4-roots.2 · Commit 10: [PATCH 10/21] fix: harden final Roots assurance
src/wallet/spend.cpp
Before: src/wallet/spend.cpp · After: src/wallet/spend.cpp
File metadata
index 3292ae27976c7cc7328426b35c5163c00c43160e..665e6c92a5b067eb381ba4a0cfd3a55ef5b2abbf 100644
Download original patch · Release notes
Diff rows 1–34 of 34. 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
|
@@ -937,6 +937,16 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256&
|
|
|
937
937
|
return true;
|
|
938
938
|
}
|
|
939
939
|
|
|
940
|
+
uint32_t GetAntiFeeSnipingLockTime(int block_height, FastRandomContext& rng_fast)
|
|
941
|
+
{
|
|
942
|
+
uint32_t lock_time{static_cast<uint32_t>(block_height)};
|
|
943
|
+
if (rng_fast.randrange(10) == 0) {
|
|
944
|
+
lock_time = std::max(0, int(lock_time) - int(rng_fast.randrange(100)));
|
|
945
|
+
}
|
|
946
|
+
if (lock_time == PARASITE_CAT21_LOCKTIME) --lock_time;
|
|
947
|
+
return lock_time;
|
|
948
|
+
}
|
|
949
|
+
|
|
940
950
|
/**
|
|
941
951
|
* Set a height-based locktime for new transactions (uses the height of the
|
|
942
952
|
* current chain tip unless we are not synced with the current chain
|
|
@@ -967,15 +977,9 @@ static void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng
|
|
|
967
977
|
// now we ensure code won't be written that makes assumptions about
|
|
968
978
|
// nLockTime that preclude a fix later.
|
|
969
979
|
if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
|
|
970
|
-
tx.nLockTime = block_height;
|
|
971
|
-
|
|
972
|
-
// Secondly occasionally randomly pick a nLockTime even further back, so
|
|
973
|
-
// that transactions that are delayed after signing for whatever reason,
|
|
974
|
-
// e.g. high-latency mix networks and some CoinJoin implementations, have
|
|
975
|
-
// better privacy.
|
|
976
|
-
if (rng_fast.randrange(10) == 0) {
|
|
977
|
-
tx.nLockTime = std::max(0, int(tx.nLockTime) - int(rng_fast.randrange(100)));
|
|
978
|
-
}
|
|
980
|
+
// Occasionally pick a nLockTime further back so delayed transactions do
|
|
981
|
+
// not reveal a unique fingerprint. Avoid values reserved by local policy.
|
|
982
|
+
tx.nLockTime = GetAntiFeeSnipingLockTime(block_height, rng_fast);
|
|
979
983
|
} else {
|
|
980
984
|
// If our chain is lagging behind, we can't discourage fee sniping nor help
|
|
981
985
|
// the privacy of high-latency transactions. To avoid leaking a potentially
|