Skip to content

Commit b8d94a1

Browse files
committed
feat: better consensus hash handling during tip selection
1 parent 986a3d4 commit b8d94a1

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

testnet/stacks-node/src/neon_node.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,55 @@ impl BlockMinerThread {
11691169
return vec![];
11701170
}
11711171

1172+
let sortdb_tip_handle = burn_db.index_handle_at_tip();
1173+
1174+
let stacks_tips: Vec<_> = stacks_tips
1175+
.into_iter()
1176+
.filter(|candidate| {
1177+
let candidate_ch = &candidate.consensus_hash;
1178+
let candidate_burn_ht = match SortitionDB::get_block_snapshot_consensus(
1179+
sortdb_tip_handle.conn(),
1180+
candidate_ch
1181+
) {
1182+
Ok(Some(x)) => x.block_height,
1183+
Ok(None) => {
1184+
warn!("Tried to evaluate potential chain tip with an unknown consensus hash";
1185+
"consensus_hash" => %candidate_ch,
1186+
"stacks_block_hash" => %candidate.anchored_block_hash);
1187+
return false;
1188+
},
1189+
Err(e) => {
1190+
warn!("Error while trying to evaluate potential chain tip with an unknown consensus hash";
1191+
"consensus_hash" => %candidate_ch,
1192+
"stacks_block_hash" => %candidate.anchored_block_hash,
1193+
"err" => ?e);
1194+
return false;
1195+
},
1196+
};
1197+
let tip_ch = match sortdb_tip_handle.get_consensus_at(candidate_burn_ht) {
1198+
Ok(Some(x)) => x,
1199+
Ok(None) => {
1200+
warn!("Tried to evaluate potential chain tip with a consensus hash ahead of canonical tip";
1201+
"consensus_hash" => %candidate_ch,
1202+
"stacks_block_hash" => %candidate.anchored_block_hash);
1203+
return false;
1204+
},
1205+
Err(e) => {
1206+
warn!("Error while trying to evaluate potential chain tip with an unknown consensus hash";
1207+
"consensus_hash" => %candidate_ch,
1208+
"stacks_block_hash" => %candidate.anchored_block_hash,
1209+
"err" => ?e);
1210+
return false;
1211+
},
1212+
};
1213+
if &tip_ch != candidate_ch {
1214+
false
1215+
} else {
1216+
true
1217+
}
1218+
})
1219+
.collect();
1220+
11721221
let mut considered = HashSet::new();
11731222
let mut candidates = vec![];
11741223
let end_height = stacks_tips[0].height;

0 commit comments

Comments
 (0)