mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Use 2 hour grace period for key timestamps in importmulti rescans
Gregory Maxwell <greg@xiph.org> pointed out the lack of grace period in https://github.com/bitcoin/bitcoin/pull/9490#issue-199407998. The importwallet RPC which uses key timestamps in a similar way already has a 2 hour grace period.
This commit is contained in:
parent
38d3e9ee59
commit
e662af3583
@ -54,7 +54,7 @@ class Variant(collections.namedtuple("Variant", "call data rescan prune")):
|
||||
"scriptPubKey": {
|
||||
"address": self.address["address"]
|
||||
},
|
||||
"timestamp": timestamp + (1 if self.rescan == Rescan.late_timestamp else 0),
|
||||
"timestamp": timestamp + RESCAN_WINDOW + (1 if self.rescan == Rescan.late_timestamp else 0),
|
||||
"pubkeys": [self.address["pubkey"]] if self.data == Data.pub else [],
|
||||
"keys": [self.key] if self.data == Data.priv else [],
|
||||
"label": self.label,
|
||||
@ -99,6 +99,9 @@ IMPORT_VARIANTS = [Variant(*variants) for variants in itertools.product(Call, Da
|
||||
ImportNode = collections.namedtuple("ImportNode", "prune rescan")
|
||||
IMPORT_NODES = [ImportNode(*fields) for fields in itertools.product((False, True), repeat=2)]
|
||||
|
||||
# Rescans start at the earliest block up to 2 hours before the key timestamp.
|
||||
RESCAN_WINDOW = 2 * 60 * 60
|
||||
|
||||
|
||||
class ImportRescanTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
@ -130,7 +133,7 @@ class ImportRescanTest(BitcoinTestFramework):
|
||||
self.nodes[0].generate(1)
|
||||
assert_equal(self.nodes[0].getrawmempool(), [])
|
||||
timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"]
|
||||
set_node_times(self.nodes, timestamp + 1)
|
||||
set_node_times(self.nodes, timestamp + RESCAN_WINDOW + 1)
|
||||
self.nodes[0].generate(1)
|
||||
sync_blocks(self.nodes)
|
||||
|
||||
|
@ -988,7 +988,8 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
||||
" or the string \"now\" to substitute the current synced blockchain time. The timestamp of the oldest\n"
|
||||
" key will determine how far back blockchain rescans need to begin for missing wallet transactions.\n"
|
||||
" \"now\" can be specified to bypass scanning, for keys which are known to never have been used, and\n"
|
||||
" 0 can be specified to scan the entire blockchain.\n"
|
||||
" 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key\n"
|
||||
" creation time of all keys being imported by the importmulti call will be scanned.\n"
|
||||
" \"redeemscript\": \"<script>\" , (string, optional) Allowed only if the scriptPubKey is a P2SH address or a P2SH scriptPubKey\n"
|
||||
" \"pubkeys\": [\"<pubKey>\", ... ] , (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript\n"
|
||||
" \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n"
|
||||
@ -1072,7 +1073,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
||||
}
|
||||
|
||||
if (fRescan && fRunScan && requests.size() && nLowestTimestamp <= chainActive.Tip()->GetBlockTimeMax()) {
|
||||
CBlockIndex* pindex = nLowestTimestamp > minimumTimestamp ? chainActive.FindEarliestAtLeast(nLowestTimestamp) : chainActive.Genesis();
|
||||
CBlockIndex* pindex = nLowestTimestamp > minimumTimestamp ? chainActive.FindEarliestAtLeast(std::max<int64_t>(nLowestTimestamp - 7200, 0)) : chainActive.Genesis();
|
||||
|
||||
if (pindex) {
|
||||
pwalletMain->ScanForWalletTransactions(pindex, true);
|
||||
|
Loading…
Reference in New Issue
Block a user