Skip to content

Commit

Permalink
Populate prev root from last block before regenesis
Browse files Browse the repository at this point in the history
  • Loading branch information
bvrooman committed May 7, 2024
1 parent 9cc93b1 commit 7245764
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crates/chain-config/src/config/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub struct LastBlockConfig {
pub consensus_parameters_version: ConsensusParametersVersion,
/// The version of state transition function used to produce last block.
pub state_transition_version: StateTransitionBytecodeVersion,
/// The block id of the last block
pub block_hash: Bytes32,
}

impl From<BlockHeader> for LastBlockConfig {
Expand All @@ -108,6 +110,7 @@ impl From<&BlockHeader> for LastBlockConfig {
state_transition_version: header
.application()
.state_transition_bytecode_version,
block_hash: header.consensus().prev_root,
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub fn create_genesis_block(config: &Config) -> Block {
let da_height;
let consensus_parameters_version;
let state_transition_bytecode_version;
let prev_root;

// If the rollup continues the old rollup, the height of the new block should
// be higher than that of the old chain by one to make it continuous.
Expand All @@ -196,8 +197,8 @@ pub fn create_genesis_block(config: &Config) -> Block {
.state_transition_version
.checked_add(1)
.expect("State transition bytecode version overflow");

da_height = latest_block.da_block_height;
prev_root = latest_block.block_hash;
} else {
height = 0u32.into();
#[cfg(feature = "relayer")]
Expand All @@ -214,6 +215,7 @@ pub fn create_genesis_block(config: &Config) -> Block {
}
consensus_parameters_version = ConsensusParametersVersion::MIN;
state_transition_bytecode_version = StateTransitionBytecodeVersion::MIN;
prev_root = Bytes32::zeroed();
}

let transactions_ids = vec![];
Expand All @@ -228,7 +230,7 @@ pub fn create_genesis_block(config: &Config) -> Block {
generated: Empty,
},
consensus: ConsensusHeader::<Empty> {
prev_root: Bytes32::zeroed(),
prev_root,
height,
time: fuel_core_types::tai64::Tai64::UNIX_EPOCH,
generated: Empty,
Expand Down Expand Up @@ -291,7 +293,7 @@ mod tests {
use std::vec;

#[tokio::test]
async fn config_initializes_block_height_of_genesic_block() {
async fn config_initializes_block_height_of_genesis_block() {
let block_height = BlockHeight::from(99u32);
let service_config = Config::local_node_with_state_config(StateConfig {
last_block: Some(LastBlockConfig {
Expand Down

0 comments on commit 7245764

Please sign in to comment.