Skip to content

Commit

Permalink
support for non-0 genesis block
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Dec 4, 2023
1 parent 7ffe2d5 commit 421b8dd
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion node/actors/bft/src/testonly/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ pub fn make_genesis(
keys: &[validator::SecretKey],
protocol_version: validator::ProtocolVersion,
payload: validator::Payload,
block_number: validator::BlockNumber,
) -> (validator::FinalBlock, validator::ValidatorSet) {
let header = validator::BlockHeader::genesis(payload.hash());
let header = validator::BlockHeader::genesis(payload.hash(), block_number);
let validator_set = validator::ValidatorSet::new(keys.iter().map(|k| k.public())).unwrap();
let signed_messages: Vec<_> = keys
.iter()
Expand Down
1 change: 1 addition & 0 deletions node/actors/bft/src/testonly/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Test {
&keys,
validator::ProtocolVersion::EARLIEST,
validator::Payload(vec![]),
validator::BlockNumber(0),
);
let nodes: Vec<_> = nodes
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions node/actors/bft/src/testonly/ut_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl UTHarness {
&keys,
validator::ProtocolVersion::EARLIEST,
Payload(vec![]),
validator::BlockNumber(0),
);
let (mut consensus, pipe) =
crate::testonly::make_consensus(ctx, &keys[0], &val_set, &genesis).await;
Expand Down
9 changes: 4 additions & 5 deletions node/actors/executor/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use std::collections::HashMap;
use zksync_concurrency::net;
use zksync_consensus_bft::testonly::make_genesis;
use zksync_consensus_network::{consensus, testonly::Instance};
use zksync_consensus_roles::{
node,
validator::{self, Payload},
};
use zksync_consensus_roles::{node, validator};

impl ConsensusConfig {
fn from_network_config(
Expand Down Expand Up @@ -44,7 +41,8 @@ impl FullValidatorConfig {
pub fn for_single_validator(
rng: &mut impl Rng,
protocol_version: validator::ProtocolVersion,
genesis_block_payload: Payload,
genesis_block_payload: validator::Payload,
genesis_block_number: validator::BlockNumber,
) -> Self {
let mut net_configs = Instance::new_configs(rng, 1, 0);
assert_eq!(net_configs.len(), 1);
Expand All @@ -58,6 +56,7 @@ impl FullValidatorConfig {
&[validator_key.clone()],
protocol_version,
genesis_block_payload,
genesis_block_number,
);
let node_key = net_config.gossip.key.clone();
let node_config = ExecutorConfig {
Expand Down
5 changes: 5 additions & 0 deletions node/actors/executor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async fn executor_misconfiguration(name: &str, mutation: fn(&mut FinalBlock)) {
rng,
validator::ProtocolVersion::EARLIEST,
Payload(vec![]),
BlockNumber(0),
);
let genesis_block = &mut validator.node_config.genesis_block;
mutation(genesis_block);
Expand All @@ -98,6 +99,7 @@ async fn genesis_block_mismatch() {
rng,
validator::ProtocolVersion::EARLIEST,
Payload(vec![]),
BlockNumber(0),
);
let mut genesis_block = validator.node_config.genesis_block.clone();
genesis_block.header.number = BlockNumber(1);
Expand All @@ -119,6 +121,7 @@ async fn executing_single_validator() {
rng,
validator::ProtocolVersion::EARLIEST,
Payload(vec![]),
BlockNumber(0),
);
let genesis_block = &validator.node_config.genesis_block;
let storage = InMemoryStorage::new(genesis_block.clone());
Expand Down Expand Up @@ -148,6 +151,7 @@ async fn executing_validator_and_full_node() {
rng,
validator::ProtocolVersion::EARLIEST,
Payload(vec![]),
BlockNumber(0),
);
let full_node = validator.connect_full_node(rng);

Expand Down Expand Up @@ -194,6 +198,7 @@ async fn syncing_full_node_from_snapshot(delay_block_storage: bool) {
rng,
validator::ProtocolVersion::EARLIEST,
Payload(vec![]),
BlockNumber(0),
);
let mut full_node = validator.connect_full_node(rng);

Expand Down
2 changes: 1 addition & 1 deletion node/actors/sync_blocks/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl TestValidators {
};

let payload = Payload(vec![]);
let mut latest_block = BlockHeader::genesis(payload.hash());
let mut latest_block = BlockHeader::genesis(payload.hash(), BlockNumber(0));
let final_blocks = (0..block_count).map(|_| {
let final_block = FinalBlock {
header: latest_block,
Expand Down
4 changes: 2 additions & 2 deletions node/libs/roles/src/validator/messages/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ impl BlockHeader {
}

/// Creates a genesis block.
pub fn genesis(payload: PayloadHash) -> Self {
pub fn genesis(payload: PayloadHash, number: BlockNumber) -> Self {
Self {
parent: BlockHeaderHash(Keccak256::default()),
number: BlockNumber(0),
number,
payload,
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/libs/roles/src/validator/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn make_justification<R: Rng>(
/// WARNING: it is not a fully correct FinalBlock.
pub fn make_genesis_block<R: Rng>(rng: &mut R, protocol_version: ProtocolVersion) -> FinalBlock {
let payload: Payload = rng.gen();
let header = BlockHeader::genesis(payload.hash());
let header = BlockHeader::genesis(payload.hash(), BlockNumber(0));
let justification = make_justification(rng, &header, protocol_version);
FinalBlock {
header,
Expand Down
2 changes: 1 addition & 1 deletion node/libs/storage/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl InitStore for () {
fn genesis_block(rng: &mut impl Rng) -> FinalBlock {
let payload = Payload(vec![]);
FinalBlock {
header: BlockHeader::genesis(payload.hash()),
header: BlockHeader::genesis(payload.hash(), BlockNumber(0)),
payload,
justification: rng.gen(),
}
Expand Down
1 change: 1 addition & 0 deletions node/tools/src/bin/localnet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn main() -> anyhow::Result<()> {
&validator_keys,
protocol_version,
validator::Payload(vec![]),
validator::BlockNumber(0),
);

// Each node will have `gossip_peers` outbound peers.
Expand Down

0 comments on commit 421b8dd

Please sign in to comment.