Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/mock signing revamp #5070

Merged
merged 21 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a574768
Add pre_nakamoto_miner_messaging option to MinerConfig
jferrant Aug 13, 2024
4e37d0b
Have miners respond to mock signature messages in epoch 2.5 via stack…
jferrant Aug 13, 2024
c6c3aa4
Rust fmt
jferrant Aug 13, 2024
5d77eab
WIP: add test for mock miner messages. Failing to write to miner slot
jferrant Aug 14, 2024
4c7598c
WIP: Failing to write to miner slot
jferrant Aug 14, 2024
edfaa10
WIP: No longer failing to write to .miners but failing to find approp…
jferrant Aug 14, 2024
c590bcf
WIP: failing at 222
jferrant Aug 14, 2024
993d55b
WIP: missing stackerdb messages
jferrant Aug 15, 2024
d93d07d
WIP: use latest election winner to send mock miner messages
jferrant Aug 15, 2024
b597a11
WIP: stuck at 250
jferrant Aug 15, 2024
37a2533
WIP: need to fix stacks tip consensus hash and stacks tip
jferrant Aug 15, 2024
be1f6ed
Fix consensus hash and stacks tip in MockMinerMessage
jferrant Aug 15, 2024
6661194
CRC: get sort db from SortitionDB
jferrant Aug 15, 2024
22ea256
CRC: simulate block proposal, signatures, and appending a block in mo…
jferrant Aug 15, 2024
f12961e
Rename pre_nakamoto_miner_messaging to pre_nakamoto_mock_signing
jferrant Aug 15, 2024
82e390d
Add a bit more logging
jferrant Aug 15, 2024
b4987f7
CRC: improve logging
jferrant Aug 16, 2024
3a85972
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Aug 16, 2024
62f5a6a
Do not enable pre nakamoto mock signing unless the miner key is set
jferrant Aug 16, 2024
c8d8743
Remove panic in tests when deserializing the block proposal slot due …
jferrant Aug 16, 2024
1610ce3
Set pre nakamoto mock signing to true for mock sign test
jferrant Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 74 additions & 3 deletions libsigner/src/v0/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ MinerSlotID {
/// Block proposal from the miner
BlockProposal = 0,
/// Block pushed from the miner
BlockPushed = 1
BlockPushed = 1,
/// Mock Miner Message from the miner
MockMinerMessage = 2
});

impl MessageSlotIDTrait for MessageSlotID {
Expand Down Expand Up @@ -116,7 +118,9 @@ SignerMessageTypePrefix {
/// Block Pushed message from miners
BlockPushed = 2,
/// Mock Signature message from Epoch 2.5 signers
MockSignature = 3
MockSignature = 3,
/// Mock Pre-Nakamoto message from Epoch 2.5 miners
MockMinerMessage = 4
});

#[cfg_attr(test, mutants::skip)]
Expand Down Expand Up @@ -160,6 +164,7 @@ impl From<&SignerMessage> for SignerMessageTypePrefix {
SignerMessage::BlockResponse(_) => SignerMessageTypePrefix::BlockResponse,
SignerMessage::BlockPushed(_) => SignerMessageTypePrefix::BlockPushed,
SignerMessage::MockSignature(_) => SignerMessageTypePrefix::MockSignature,
SignerMessage::MockMinerMessage(_) => SignerMessageTypePrefix::MockMinerMessage,
}
}
}
Expand All @@ -175,6 +180,8 @@ pub enum SignerMessage {
BlockPushed(NakamotoBlock),
/// A mock signature from the epoch 2.5 signers
MockSignature(MockSignature),
/// A mock message from the epoch 2.5 miners
MockMinerMessage(MockMinerMessage),
}

impl SignerMessage {
Expand All @@ -184,7 +191,7 @@ impl SignerMessage {
#[cfg_attr(test, mutants::skip)]
pub fn msg_id(&self) -> Option<MessageSlotID> {
match self {
Self::BlockProposal(_) | Self::BlockPushed(_) => None,
Self::BlockProposal(_) | Self::BlockPushed(_) | Self::MockMinerMessage(_) => None,
Self::BlockResponse(_) => Some(MessageSlotID::BlockResponse),
Self::MockSignature(_) => Some(MessageSlotID::MockSignature),
}
Expand All @@ -201,6 +208,7 @@ impl StacksMessageCodec for SignerMessage {
SignerMessage::BlockResponse(block_response) => block_response.consensus_serialize(fd),
SignerMessage::BlockPushed(block) => block.consensus_serialize(fd),
SignerMessage::MockSignature(signature) => signature.consensus_serialize(fd),
SignerMessage::MockMinerMessage(message) => message.consensus_serialize(fd),
}?;
Ok(())
}
Expand All @@ -226,6 +234,10 @@ impl StacksMessageCodec for SignerMessage {
let signature = StacksMessageCodec::consensus_deserialize(fd)?;
SignerMessage::MockSignature(signature)
}
SignerMessageTypePrefix::MockMinerMessage => {
let message = StacksMessageCodec::consensus_deserialize(fd)?;
SignerMessage::MockMinerMessage(message)
}
};
Ok(message)
}
Expand Down Expand Up @@ -441,6 +453,43 @@ impl StacksMessageCodec for MockSignature {
}
}

/// A mock message for the stacks node to be used for mock mining messages
/// This is only used by Epoch 2.5 miners to simulate miners responding to mock signatures
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MockMinerMessage {
/// The view of the stacks node peer information at the time of the mock signature
pub peer_info: PeerInfo,
/// The burn block height of the miner's tenure
pub tenure_burn_block_height: u64,
/// The chain id for the mock signature
pub chain_id: u32,
/// The mock signatures that the miner received
pub mock_signatures: Vec<MockSignature>,
}

impl StacksMessageCodec for MockMinerMessage {
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), CodecError> {
self.peer_info.consensus_serialize(fd)?;
write_next(fd, &self.tenure_burn_block_height)?;
write_next(fd, &self.chain_id)?;
write_next(fd, &self.mock_signatures)?;
Ok(())
}

fn consensus_deserialize<R: Read>(fd: &mut R) -> Result<Self, CodecError> {
let peer_info = PeerInfo::consensus_deserialize(fd)?;
let tenure_burn_block_height = read_next::<u64, _>(fd)?;
let chain_id = read_next::<u32, _>(fd)?;
let mock_signatures = read_next::<Vec<MockSignature>, _>(fd)?;
Ok(Self {
peer_info,
tenure_burn_block_height,
chain_id,
mock_signatures,
})
}
}

define_u8_enum!(
/// Enum representing the reject code type prefix
RejectCodeTypePrefix {
Expand Down Expand Up @@ -940,4 +989,26 @@ mod test {
.expect("Failed to deserialize MockSignData");
assert_eq!(sign_data, deserialized_data);
}

#[test]
fn serde_mock_miner_message() {
let mock_signature_1 = MockSignature {
signature: MessageSignature::empty(),
sign_data: random_mock_sign_data(),
};
let mock_signature_2 = MockSignature {
signature: MessageSignature::empty(),
sign_data: random_mock_sign_data(),
};
let mock_miner_message = MockMinerMessage {
peer_info: random_peer_data(),
tenure_burn_block_height: thread_rng().next_u64(),
chain_id: thread_rng().gen_range(0..=1),
mock_signatures: vec![mock_signature_1, mock_signature_2],
};
let serialized_data = mock_miner_message.serialize_to_vec();
let deserialized_data = read_next::<MockMinerMessage, _>(&mut &serialized_data[..])
.expect("Failed to deserialize MockSignData");
assert_eq!(mock_miner_message, deserialized_data);
}
}
1 change: 0 additions & 1 deletion stackslib/src/chainstate/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4210,7 +4210,6 @@ impl NakamotoChainState {
"stackerdb_slots" => ?stackerdb_config.signers,
"queried_sortition" => %election_sortition,
"sortition_hashes" => ?miners_info.get_sortitions());

return Ok(None);
}
let slot_id_range = signer_ranges.swap_remove(signer_ix);
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/net/stackerdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub const STACKERDB_MAX_PAGE_COUNT: u32 = 2;

pub const STACKERDB_SLOTS_FUNCTION: &str = "stackerdb-get-signer-slots";
pub const STACKERDB_CONFIG_FUNCTION: &str = "stackerdb-get-config";
pub const MINER_SLOT_COUNT: u32 = 2;
pub const MINER_SLOT_COUNT: u32 = 3;
jferrant marked this conversation as resolved.
Show resolved Hide resolved

/// Final result of synchronizing state with a remote set of DB replicas
#[derive(Clone)]
Expand Down
5 changes: 5 additions & 0 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,8 @@ pub struct MinerConfig {
pub max_reorg_depth: u64,
/// Amount of time while mining in nakamoto to wait for signers to respond to a proposed block
pub wait_on_signers: Duration,
/// Whether to send miner messages in Epoch 2.5 through the .miners contract. This is used for testing.
pub pre_nakamoto_miner_messaging: bool,
}

impl Default for MinerConfig {
Expand Down Expand Up @@ -2362,6 +2364,7 @@ impl Default for MinerConfig {
max_reorg_depth: 3,
// TODO: update to a sane value based on stackerdb benchmarking
wait_on_signers: Duration::from_secs(200),
pre_nakamoto_miner_messaging: true,
}
}
}
Expand Down Expand Up @@ -2693,6 +2696,7 @@ pub struct MinerConfigFile {
pub filter_origins: Option<String>,
pub max_reorg_depth: Option<u64>,
pub wait_on_signers_ms: Option<u64>,
pub pre_nakamoto_miner_messaging: Option<bool>,
}

impl MinerConfigFile {
Expand Down Expand Up @@ -2795,6 +2799,7 @@ impl MinerConfigFile {
.wait_on_signers_ms
.map(Duration::from_millis)
.unwrap_or(miner_default_config.wait_on_signers),
pre_nakamoto_miner_messaging: self.pre_nakamoto_miner_messaging.unwrap_or(true),
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions testnet/stacks-node/src/nakamoto_node/sign_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,10 @@ impl SignCoordinator {
debug!("Received mock signature message. Ignoring.");
continue;
}
SignerMessageV0::MockMinerMessage(_) => {
debug!("Received mock miner message. Ignoring.");
continue;
}
};
let block_sighash = block.header.signer_signature_hash();
if block_sighash != response_hash {
Expand Down
Loading