From 72457642702df981714bff727ecd6451aed60e9b Mon Sep 17 00:00:00 2001 From: Brandon Vrooman Date: Tue, 7 May 2024 19:48:24 -0400 Subject: [PATCH] Populate prev root from last block before regenesis --- crates/chain-config/src/config/state.rs | 3 +++ crates/fuel-core/src/service/genesis.rs | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/chain-config/src/config/state.rs b/crates/chain-config/src/config/state.rs index ffef804f90..a8444d36be 100644 --- a/crates/chain-config/src/config/state.rs +++ b/crates/chain-config/src/config/state.rs @@ -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 for LastBlockConfig { @@ -108,6 +110,7 @@ impl From<&BlockHeader> for LastBlockConfig { state_transition_version: header .application() .state_transition_bytecode_version, + block_hash: header.consensus().prev_root, } } } diff --git a/crates/fuel-core/src/service/genesis.rs b/crates/fuel-core/src/service/genesis.rs index a1b879adf5..ebaf8d5502 100644 --- a/crates/fuel-core/src/service/genesis.rs +++ b/crates/fuel-core/src/service/genesis.rs @@ -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. @@ -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")] @@ -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![]; @@ -228,7 +230,7 @@ pub fn create_genesis_block(config: &Config) -> Block { generated: Empty, }, consensus: ConsensusHeader:: { - prev_root: Bytes32::zeroed(), + prev_root, height, time: fuel_core_types::tai64::Tai64::UNIX_EPOCH, generated: Empty, @@ -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 {