Skip to content

Commit 993d55b

Browse files
committed
WIP: missing stackerdb messages
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent c590bcf commit 993d55b

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

libsigner/src/v0/messages.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ MinerSlotID {
8888
/// Block proposal from the miner
8989
BlockProposal = 0,
9090
/// Block pushed from the miner
91-
BlockPushed = 1
91+
BlockPushed = 1,
92+
/// Mock Miner Message from the miner
93+
MockMinerMessage = 2
9294
});
9395

9496
impl MessageSlotIDTrait for MessageSlotID {

stackslib/src/net/stackerdb/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub const STACKERDB_MAX_PAGE_COUNT: u32 = 2;
152152

153153
pub const STACKERDB_SLOTS_FUNCTION: &str = "stackerdb-get-signer-slots";
154154
pub const STACKERDB_CONFIG_FUNCTION: &str = "stackerdb-get-config";
155-
pub const MINER_SLOT_COUNT: u32 = 2;
155+
pub const MINER_SLOT_COUNT: u32 = 3;
156156

157157
/// Final result of synchronizing state with a remote set of DB replicas
158158
#[derive(Clone)]

testnet/stacks-node/src/neon_node.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,11 +2288,8 @@ impl BlockMinerThread {
22882288
let miner_contract_id = boot_code_id(MINERS_NAME, self.config.is_mainnet());
22892289
let mut miners_stackerdb =
22902290
StackerDBSession::new(&self.config.node.rpc_bind, miner_contract_id);
2291-
let slot_id = MinerSlotID::BlockProposal.to_u8().into();
2292-
if let Ok(messages) =
2293-
miners_stackerdb.get_latest_chunks(&[slot_id, slot_id * MINER_SLOT_COUNT])
2294-
{
2295-
debug!("Miner got messages: {:?}", messages.len());
2291+
let miner_slot_ids: Vec<_> = (0..MINER_SLOT_COUNT * 2).collect();
2292+
if let Ok(messages) = miners_stackerdb.get_latest_chunks(&miner_slot_ids) {
22962293
for message in messages {
22972294
if let Some(message) = message {
22982295
if message.is_empty() {
@@ -2303,7 +2300,7 @@ impl BlockMinerThread {
23032300
else {
23042301
continue;
23052302
};
2306-
if miner_message.peer_info.burn_block_height == self.burn_block.block_height {
2303+
if miner_message.tenure_burn_block_height == self.burn_block.block_height {
23072304
debug!(
23082305
"Already sent mock miner message for tenure burn block height {:?}",
23092306
self.burn_block.block_height
@@ -2368,29 +2365,30 @@ impl BlockMinerThread {
23682365
server_version,
23692366
};
23702367

2371-
info!("Sending mock miner message in response to mock signatures for burn block {:?}", &self.burn_block.block_height;
2372-
"stacks_tip_consensus_hash" => ?peer_info.stacks_tip_consensus_hash.clone(),
2373-
"stacks_tip" => ?peer_info.stacks_tip.clone(),
2374-
"peer_burn_block_height" => peer_info.burn_block_height,
2375-
"pox_consensus" => ?peer_info.pox_consensus.clone(),
2376-
"server_version" => peer_info.server_version.clone(),
2377-
"chain_id" => self.config.burnchain.chain_id,
2378-
"num_mock_signatures" => mock_signatures.len(),
2379-
);
23802368
let message = MockMinerMessage {
23812369
peer_info,
23822370
chain_id: self.config.burnchain.chain_id,
23832371
mock_signatures,
23842372
tenure_burn_block_height: self.burn_block.block_height,
23852373
};
23862374

2375+
info!("Sending mock miner message in response to mock signatures for burn block {:?}", message.tenure_burn_block_height;
2376+
"stacks_tip_consensus_hash" => ?message.peer_info.stacks_tip_consensus_hash.clone(),
2377+
"stacks_tip" => ?message.peer_info.stacks_tip.clone(),
2378+
"peer_burn_block_height" => message.peer_info.burn_block_height,
2379+
"pox_consensus" => ?message.peer_info.pox_consensus.clone(),
2380+
"server_version" => message.peer_info.server_version.clone(),
2381+
"chain_id" => message.chain_id,
2382+
"num_mock_signatures" => message.mock_signatures.len(),
2383+
);
2384+
23872385
if let Err(e) = SignCoordinator::send_miners_message(
23882386
&miner_config.mining_key.expect("BUG: no mining key"),
23892387
&burn_db,
23902388
&self.burn_block,
23912389
&stackerdbs,
2392-
SignerMessage::MockMinerMessage(message),
2393-
MinerSlotID::BlockProposal, // We are sending a mock miner message NOT a block proposal, but since we do not propose blocks in epoch 2.5, it is fine
2390+
SignerMessage::MockMinerMessage(message.clone()),
2391+
MinerSlotID::MockMinerMessage,
23942392
self.config.is_mainnet(),
23952393
&mut miners_stackerdb,
23962394
&self.burn_block.consensus_hash,

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{env, thread};
2323
use clarity::vm::types::PrincipalData;
2424
use clarity::vm::StacksEpoch;
2525
use libsigner::v0::messages::{
26-
BlockRejection, BlockResponse, MessageSlotID, MinerSlotID, RejectCode, SignerMessage,
26+
BlockRejection, BlockResponse, MessageSlotID, RejectCode, SignerMessage,
2727
};
2828
use libsigner::{BlockProposal, SignerSession, StackerDBSession};
2929
use rand::RngCore;
@@ -2408,6 +2408,7 @@ fn mock_miner_message_epoch_25() {
24082408
.unwrap();
24092409
let epoch_3 = &epochs[StacksEpoch::find_epoch_by_id(&epochs, StacksEpochId::Epoch30).unwrap()];
24102410
let epoch_3_start_height = epoch_3.start_height;
2411+
debug!("Epoch 3.0 starts at height {}", epoch_3_start_height);
24112412

24122413
signer_test.boot_to_epoch_25_reward_cycle();
24132414

@@ -2447,20 +2448,22 @@ fn mock_miner_message_epoch_25() {
24472448
})
24482449
.flatten()
24492450
{
2450-
if chunk.slot_id == MinerSlotID::BlockProposal.to_u8() as u32 {
2451-
if chunk.data.is_empty() {
2452-
continue;
2453-
}
2454-
let SignerMessage::MockMinerMessage(message) =
2455-
SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
2456-
.expect("Failed to deserialize MockMinerMessage")
2457-
else {
2458-
continue;
2459-
};
2460-
if message.peer_info.burn_block_height == current_burn_block_height {
2461-
mock_miner_message = Some(message);
2462-
break;
2463-
}
2451+
if chunk.data.is_empty() {
2452+
continue;
2453+
}
2454+
let SignerMessage::MockMinerMessage(message) =
2455+
SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
2456+
.expect("Failed to deserialize SignerMessage")
2457+
else {
2458+
continue;
2459+
};
2460+
if message.tenure_burn_block_height == current_burn_block_height {
2461+
mock_miner_message = Some(message);
2462+
break;
2463+
} else {
2464+
info!(
2465+
"Received MockMinerMessage for burn block height {} but expected {current_burn_block_height}", message.tenure_burn_block_height
2466+
);
24642467
}
24652468
}
24662469
assert!(

0 commit comments

Comments
 (0)