Skip to content

Commit be1f6ed

Browse files
committed
Fix consensus hash and stacks tip in MockMinerMessage
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 37a2533 commit be1f6ed

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

libsigner/src/v0/messages.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,6 @@ impl StacksMessageCodec for MockSignature {
459459
pub struct MockMinerMessage {
460460
/// The view of the stacks node peer information at the time of the mock signature
461461
pub peer_info: PeerInfo,
462-
/// The burn block height of the miner's tenure
463-
pub tenure_burn_block_height: u64,
464462
/// The chain id for the mock signature
465463
pub chain_id: u32,
466464
/// The mock signatures that the miner received
@@ -470,20 +468,17 @@ pub struct MockMinerMessage {
470468
impl StacksMessageCodec for MockMinerMessage {
471469
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), CodecError> {
472470
self.peer_info.consensus_serialize(fd)?;
473-
write_next(fd, &self.tenure_burn_block_height)?;
474471
write_next(fd, &self.chain_id)?;
475472
write_next(fd, &self.mock_signatures)?;
476473
Ok(())
477474
}
478475

479476
fn consensus_deserialize<R: Read>(fd: &mut R) -> Result<Self, CodecError> {
480477
let peer_info = PeerInfo::consensus_deserialize(fd)?;
481-
let tenure_burn_block_height = read_next::<u64, _>(fd)?;
482478
let chain_id = read_next::<u32, _>(fd)?;
483479
let mock_signatures = read_next::<Vec<MockSignature>, _>(fd)?;
484480
Ok(Self {
485481
peer_info,
486-
tenure_burn_block_height,
487482
chain_id,
488483
mock_signatures,
489484
})
@@ -1002,7 +997,6 @@ mod test {
1002997
};
1003998
let mock_miner_message = MockMinerMessage {
1004999
peer_info: random_peer_data(),
1005-
tenure_burn_block_height: thread_rng().next_u64(),
10061000
chain_id: thread_rng().gen_range(0..=1),
10071001
mock_signatures: vec![mock_signature_1, mock_signature_2],
10081002
};

testnet/stacks-node/src/neon_node.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ use stacks::net::stackerdb::{StackerDBConfig, StackerDBSync, StackerDBs, MINER_S
194194
use stacks::net::{
195195
Error as NetError, NetworkResult, PeerNetworkComms, RPCHandlerArgs, ServiceFlags,
196196
};
197+
use stacks::types::StacksEpoch;
197198
use stacks::util_lib::strings::{UrlString, VecDisplay};
198199
use stacks::{monitoring, version_string};
199200
use stacks_common::codec::StacksMessageCodec;
@@ -2273,12 +2274,20 @@ impl BlockMinerThread {
22732274
let burn_db_path = self.config.get_burn_db_file_path();
22742275
let burn_db = SortitionDB::open(&burn_db_path, false, self.burnchain.pox_constants.clone())
22752276
.expect("FATAL: could not open sortition DB");
2276-
let p2p_net = StacksNode::setup_peer_network(
2277-
&self.config,
2278-
&self.config.atlas,
2279-
self.burnchain.clone(),
2280-
);
2281-
let epoch_id = p2p_net.get_current_epoch().epoch_id;
2277+
let epochs = SortitionDB::get_stacks_epochs(burn_db.conn())
2278+
.expect("Error while loading stacks epochs");
2279+
let epoch_index = StacksEpoch::find_epoch(&epochs, self.burn_block.block_height)
2280+
.unwrap_or_else(|| {
2281+
panic!(
2282+
"BUG: block {} is not in a known epoch",
2283+
self.burn_block.block_height
2284+
)
2285+
});
2286+
let epoch_id = epochs
2287+
.get(epoch_index)
2288+
.expect("BUG: no epoch at found index")
2289+
.epoch_id;
2290+
22822291
if epoch_id != StacksEpochId::Epoch25 {
22832292
debug!("Mock miner messaging is disabled for non-epoch 2.5 blocks.";
22842293
"epoch_id" => epoch_id.to_string()
@@ -2300,7 +2309,7 @@ impl BlockMinerThread {
23002309
else {
23012310
continue;
23022311
};
2303-
if miner_message.tenure_burn_block_height == self.burn_block.block_height {
2312+
if miner_message.peer_info.burn_block_height == self.burn_block.block_height {
23042313
debug!(
23052314
"Already sent mock miner message for tenure burn block height {:?}",
23062315
self.burn_block.block_height
@@ -2350,11 +2359,11 @@ impl BlockMinerThread {
23502359
.or(option_env!("CARGO_PKG_VERSION"))
23512360
.unwrap_or("0.0.0.0"),
23522361
);
2353-
let stacks_tip_height = p2p_net.stacks_tip.height;
2354-
let stacks_tip = p2p_net.stacks_tip.block_hash.clone();
2355-
let stacks_tip_consensus_hash = p2p_net.stacks_tip.consensus_hash.clone();
2356-
let pox_consensus = p2p_net.burnchain_tip.consensus_hash.clone();
2357-
let burn_block_height = p2p_net.chain_view.burn_block_height;
2362+
let stacks_tip_height = self.burn_block.canonical_stacks_tip_height;
2363+
let stacks_tip = self.burn_block.canonical_stacks_tip_hash;
2364+
let stacks_tip_consensus_hash = self.burn_block.canonical_stacks_tip_consensus_hash;
2365+
let pox_consensus = self.burn_block.consensus_hash;
2366+
let burn_block_height = self.burn_block.block_height;
23582367

23592368
let peer_info = PeerInfo {
23602369
burn_block_height,
@@ -2369,10 +2378,9 @@ impl BlockMinerThread {
23692378
peer_info,
23702379
chain_id: self.config.burnchain.chain_id,
23712380
mock_signatures,
2372-
tenure_burn_block_height: self.burn_block.block_height,
23732381
};
23742382

2375-
info!("Sending mock miner message in response to mock signatures for burn block {:?}", message.tenure_burn_block_height;
2383+
info!("Sending mock miner message in response to mock signatures for burn block {:?}", message.peer_info.burn_block_height;
23762384
"stacks_tip_consensus_hash" => ?message.peer_info.stacks_tip_consensus_hash.clone(),
23772385
"stacks_tip" => ?message.peer_info.stacks_tip.clone(),
23782386
"peer_burn_block_height" => message.peer_info.burn_block_height,

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,13 +2457,9 @@ fn mock_miner_message_epoch_25() {
24572457
else {
24582458
continue;
24592459
};
2460-
if message.tenure_burn_block_height == current_burn_block_height {
2460+
if message.peer_info.burn_block_height == current_burn_block_height {
24612461
mock_miner_message = Some(message);
24622462
break;
2463-
} else {
2464-
info!(
2465-
"Received MockMinerMessage for burn block height {} but expected {current_burn_block_height}", message.tenure_burn_block_height
2466-
);
24672463
}
24682464
}
24692465
assert!(

0 commit comments

Comments
 (0)