Skip to content

Commit

Permalink
Blockchain: add network_id to SkipBlockInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
styppo committed Oct 23, 2024
1 parent 1ca95c2 commit 669dad9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions blockchain/src/block_production/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl BlockProducer {

let skip_block_info = if skip_block_proof.is_some() {
Some(SkipBlockInfo {
network_id: blockchain.network_id,
block_number,
vrf_entropy: prev_seed.entropy(),
})
Expand Down
1 change: 1 addition & 0 deletions blockchain/tests/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn test_skip_block_single_signature() {

// create skip block data
let skip_block_info = SkipBlockInfo {
network_id: NetworkId::UnitAlbatross,
block_number: 1234,
vrf_entropy: VrfEntropy::default(),
};
Expand Down
1 change: 1 addition & 0 deletions primitives/block/src/micro_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl MicroBlock {
match justification {
MicroJustification::Skip(proof) => {
let skip_block = SkipBlockInfo {
network_id: self.header.network,
block_number: self.header.block_number,
vrf_entropy: self.header.seed.entropy(),
};
Expand Down
7 changes: 6 additions & 1 deletion primitives/block/src/skip_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::fmt::Debug;
use nimiq_bls::AggregatePublicKey;
use nimiq_hash_derive::SerializeContent;
use nimiq_primitives::{
policy::Policy, slots_allocation::Validators, Message, SignedMessage, PREFIX_SKIP_BLOCK_INFO,
networks::NetworkId, policy::Policy, slots_allocation::Validators, Message, SignedMessage,
PREFIX_SKIP_BLOCK_INFO,
};
use nimiq_serde::{Deserialize, Serialize, SerializedMaxSize};
use nimiq_vrf::VrfEntropy;
Expand All @@ -17,6 +18,9 @@ pub type SignedSkipBlockInfo = SignedMessage<SkipBlockInfo>;
Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Deserialize, Serialize, SerializeContent,
)]
pub struct SkipBlockInfo {
/// The network of this skip block.
pub network_id: NetworkId,

/// The number of the block for which the skip block is constructed.
pub block_number: u32,

Expand All @@ -31,6 +35,7 @@ impl SkipBlockInfo {
pub fn from_micro_block(block: &MicroBlock) -> Option<Self> {
if block.is_skip_block() {
Some(SkipBlockInfo {
network_id: block.header.network,
block_number: block.header.block_number,
vrf_entropy: block.header.seed.entropy(),
})
Expand Down
1 change: 1 addition & 0 deletions test-utils/src/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ impl TemporaryBlockProducer {
let skip_block_info = {
let blockchain = self.blockchain.read();
SkipBlockInfo {
network_id: blockchain.network_id,
block_number: blockchain.block_number() + 1,
vrf_entropy: blockchain.head().seed().entropy(),
}
Expand Down
2 changes: 2 additions & 0 deletions test-utils/src/test_custom_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ pub fn next_skip_block(
let prev_seed = blockchain.head().seed().clone();

let skip_block_info = SkipBlockInfo {
network_id: blockchain.network_id,
block_number,
vrf_entropy: prev_seed.entropy(),
};
Expand Down Expand Up @@ -490,6 +491,7 @@ fn create_skip_block_proof(
.unwrap_or_else(|| blockchain.head().seed().clone());

let skip_block_info = SkipBlockInfo {
network_id: blockchain.network_id,
block_number: (blockchain.block_number() as i32 + 1 + config.block_number_offset) as u32,
vrf_entropy: seed.entropy(),
};
Expand Down
1 change: 1 addition & 0 deletions validator/src/micro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ impl<TValidatorNetwork: ValidatorNetwork + 'static> NextProduceMicroBlockEvent<T
}

let skip_block_info = SkipBlockInfo {
network_id: self.blockchain.read().network_id,
block_number: self.block_number,
vrf_entropy: self.prev_seed.entropy(),
};
Expand Down
1 change: 1 addition & 0 deletions validator/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ async fn validator_can_catch_up() {
.collect();

let skip_block_info = SkipBlockInfo {
network_id: blockchain.read().network_id,
block_number: 1,
vrf_entropy: blockchain.read().head().seed().entropy(),
};
Expand Down

0 comments on commit 669dad9

Please sign in to comment.