stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3k stars 658 forks source link

Fix: never consider Stacks chain tips that are not on the canonical burn chain #4886

Closed jcnelson closed 1 week ago

jcnelson commented 2 weeks ago

This PR fixes an incident from earlier this morning whereby miners consistently failed to mine blocks because their preferred chain tip was no longer on the canonical Bitcoin fork. This was due to (1) an omitted check when searching for ancestral Stacks tips to consider, and (2) an off-by-one error which meant that the highest considered ancestor had the same height as the already-filtered Stacks tips (instead of an earlier height).

You can see the difference as follows:

With the fix:

$ stacks-node pick-best-tip --config ~/mainnet-2.5.toml --at-stacks-height 153917
INFO [1718387049.331670] [testnet/stacks-node/src/main.rs:293] [main] stacks-node 0.1.0 (:, debug build, linux [x86_64])
INFO [1718387049.331731] [testnet/stacks-node/src/main.rs:66] [main] Loading config at path /home/jude/mainnet-2.5.toml
INFO [1718387049.500576] [testnet/stacks-node/src/neon_node.rs:1493] [main] Tip #0 ea37553db307bca3a2dc0413dd7eb943f4fbfecc/3a852c6ea871ea45528e9cd4800349e8685a46d9470e2c53b45b30fe15c18234 at 847851:153917 has score 1 (1 (non-ancestor) + 0 (earlier sibs) + 0 (earlier sibs) + 0 (earlier sibs))
INFO [1718387049.500607] [testnet/stacks-node/src/neon_node.rs:1493] [main] Tip #1 6a7f03e8da186957d979b0d3ec7330478f8ab600/36a21c1b248d205136378fc1409aa7d7727b61571bc3bea5c63da65c97e25817 at 847852:153917 has score 2 (1 (uncles) + 1 (non-ancestor) + 0 (earlier sibs) + 0 (earlier sibs) + 0 (earlier sibs))
INFO [1718387049.500619] [testnet/stacks-node/src/neon_node.rs:1524] [main] Best tip is #0 ea37553db307bca3a2dc0413dd7eb943f4fbfecc/3a852c6ea871ea45528e9cd4800349e8685a46d9470e2c53b45b30fe15c18234
Best tip is TipCandidate { stacks_height: 153917, consensus_hash: ea37553db307bca3a2dc0413dd7eb943f4fbfecc, anchored_block_hash: 3a852c6ea871ea45528e9cd4800349e8685a46d9470e2c53b45b30fe15c18234, parent_consensus_hash: ef78a4c1acf7a004d9ef170bee78245527cb5dcb, parent_anchored_block_hash: 678d064fbb1c9abc1a69c333ce2977535ef69791d846ed88917acefcf930dde7, burn_height: 847851, num_earlier_siblings: 0 }

Without the fix:

$ stacks-node pick-best-tip --config ~/mainnet-2.5.toml --at-stacks-height 153917
INFO [1718387084.670752] [testnet/stacks-node/src/main.rs:293] [main] stacks-node 0.1.0 (:, release build, linux [x86_64])
INFO [1718387084.670805] [testnet/stacks-node/src/main.rs:66] [main] Loading config at path /home/jude/mainnet-2.5.toml
INFO [1718387084.823874] [testnet/stacks-node/src/neon_node.rs:1472] [main] Tip #0 1b2ef7d48334989af51335211c218a5164f57ba5/7a08061efeb9516be3835e8478e15872d247be9fb2c42e690ba0af43fc494073 at 847849:153917 has score 2 (1 (non-ancestor) + 1 (non-ancestor) + 0 (earlier sibs) + 0 (earlier sibs) + 0 (earlier sibs))
INFO [1718387084.823901] [testnet/stacks-node/src/neon_node.rs:1472] [main] Tip #1 ea37553db307bca3a2dc0413dd7eb943f4fbfecc/3a852c6ea871ea45528e9cd4800349e8685a46d9470e2c53b45b30fe15c18234 at 847851:153917 has score 3 (1 (non-ancestor) + 1 (uncles) + 1 (non-ancestor) + 0 (earlier sibs) + 0 (earlier sibs) + 0 (earlier sibs))
INFO [1718387084.823918] [testnet/stacks-node/src/neon_node.rs:1472] [main] Tip #2 6a7f03e8da186957d979b0d3ec7330478f8ab600/36a21c1b248d205136378fc1409aa7d7727b61571bc3bea5c63da65c97e25817 at 847852:153917 has score 5 (2 (uncles) + 1 (non-ancestor) + 1 (uncles) + 1 (non-ancestor) + 0 (earlier sibs) + 0 (earlier sibs) + 0 (earlier sibs))
INFO [1718387084.823925] [testnet/stacks-node/src/neon_node.rs:1503] [main] Best tip is #0 1b2ef7d48334989af51335211c218a5164f57ba5/7a08061efeb9516be3835e8478e15872d247be9fb2c42e690ba0af43fc494073
Best tip is TipCandidate { stacks_height: 153917, consensus_hash: 1b2ef7d48334989af51335211c218a5164f57ba5, anchored_block_hash: 7a08061efeb9516be3835e8478e15872d247be9fb2c42e690ba0af43fc494073, parent_consensus_hash: ef78a4c1acf7a004d9ef170bee78245527cb5dcb, parent_anchored_block_hash: 678d064fbb1c9abc1a69c333ce2977535ef69791d846ed88917acefcf930dde7, burn_height: 847849, num_earlier_siblings: 0 }