Skip to content

Commit 97593c1

Browse files
committed
Merge bitcoin/bitcoin#32975: assumevalid: log every script validation state change
fab2980 assumevalid: log every script validation state change (Lőrinc) Pull request description: The `-assumevalid` option skips script verification for a specified block and all its ancestors during Initial Block Download. Many new [users are surprised](bitcoin/bitcoin#32832) when this suddenly slows their node to a halt. This commit adds a log message to clearly indicate when this optimization ends and full validation begins (and vice versa). <details> <summary>Testing instructions</summary> The behavior can easily be tested by adding this before the new log: ```C++ // TODO hack to enable/disable script checks based on block height for testing purposes if (pindex->nHeight < 100) fScriptChecks = false; else if (pindex->nHeight < 200) fScriptChecks = true; else if (pindex->nHeight < 300) fScriptChecks = false; else if (pindex->nHeight < 400) fScriptChecks = true; ``` and exercise the new code with: ```bash cmake -B build && cmake --build build && mkdir -p demo && build/bin/bitcoind -datadir=demo -stopatheight=500 | grep 'signature validation' ``` showing something like: * Disabling signature validations at block #1 (00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048). * Enabling signature validations at block #100 (000000007bc154e0fa7ea32218a72fe2c1bb9f86cf8c9ebf9a715ed27fdb229a). * Disabling signature validations at block #200 (000000008f1a7008320c16b8402b7f11e82951f44ca2663caf6860ab2eeef320). * Enabling signature validations at block #300 (0000000062b69e4a2c3312a5782d7798b0711e9ebac065cd5d19f946439f8609). </details> ACKs for top commit: achow101: ACK fab2980 ajtowns: crACK fab2980 davidgumberg: untested crACK bitcoin/bitcoin@fab2980 Tree-SHA512: e90b66f7423b639356daace476942ce83e65e70466544394cbe2f15738bdbf716163eaf590c64c5448f9b41aeeaafe3342c48c6a7a478678a70b0310ca94e11d
2 parents 7b4a135 + fab2980 commit 97593c1

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/validation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
25632563
Ticks<SecondsDouble>(m_chainman.time_forks),
25642564
Ticks<MillisecondsDouble>(m_chainman.time_forks) / m_chainman.num_blocks_total);
25652565

2566+
if (fScriptChecks != m_prev_script_checks_logged && GetRole() == ChainstateRole::NORMAL) {
2567+
LogInfo("%s signature validations at block #%d (%s).", fScriptChecks ? "Enabling" : "Disabling", pindex->nHeight, block_hash.ToString());
2568+
m_prev_script_checks_logged = fScriptChecks;
2569+
}
2570+
25662571
CBlockUndo blockundo;
25672572

25682573
// Precomputed transaction data pointers must not be invalidated

src/validation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ class Chainstate
560560
//! Cached result of LookupBlockIndex(*m_from_snapshot_blockhash)
561561
mutable const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main){nullptr};
562562

563+
std::atomic_bool m_prev_script_checks_logged{true};
564+
563565
public:
564566
//! Reference to a BlockManager instance which itself is shared across all
565567
//! Chainstate instances.

test/functional/feature_assumevalid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ def run_test(self):
153153
p2p1 = self.nodes[1].add_p2p_connection(BaseNode())
154154
p2p1.send_header_for_blocks(self.blocks[0:2000])
155155
p2p1.send_header_for_blocks(self.blocks[2000:])
156-
157-
# Send all blocks to node1. All blocks will be accepted.
158-
for i in range(2202):
159-
p2p1.send_without_ping(msg_block(self.blocks[i]))
160-
# Syncing 2200 blocks can take a while on slow systems. Give it plenty of time to sync.
161-
p2p1.sync_with_ping(timeout=960)
156+
with self.nodes[1].assert_debug_log(expected_msgs=['Disabling signature validations at block #1', 'Enabling signature validations at block #103']):
157+
# Send all blocks to node1. All blocks will be accepted.
158+
for i in range(2202):
159+
p2p1.send_without_ping(msg_block(self.blocks[i]))
160+
# Syncing 2200 blocks can take a while on slow systems. Give it plenty of time to sync.
161+
p2p1.sync_with_ping(timeout=960)
162162
assert_equal(self.nodes[1].getblock(self.nodes[1].getbestblockhash())['height'], 2202)
163163

164164
p2p2 = self.nodes[2].add_p2p_connection(BaseNode())

0 commit comments

Comments
 (0)