Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/fixed-p2p-reconnection-i…
Browse files Browse the repository at this point in the history
…ssue' into feature/fixed-p2p-reconnection-issue
  • Loading branch information
xgreenx committed Jun 3, 2024
2 parents 54d4fd5 + e9da8b9 commit 290fe5f
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 123 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- [#1929](https://github.com/FuelLabs/fuel-core/pull/1929): Added support of customization of the state transition version in the `ChainConfig`.

### Removed
- [#1913](https://github.com/FuelLabs/fuel-core/pull/1913): Removed dead code from the project.

Expand Down
81 changes: 32 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/fuel-core/chainspec/local-testnet/chain_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
"privileged_address": "b62c6f41c4c380d78ae67a8b432a4a41e2465383f8cc9869b67106835685c388"
}
},
"genesis_state_transition_version": 1,
"consensus": {
"PoA": {
"signing_key": "e8df6d432b2584a3ea9d0badf297c3b525bae71b577d22c1ccc12519adb64d92"
Expand Down
Binary file not shown.
9 changes: 8 additions & 1 deletion crates/chain-config/src/config/chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fuel_core_storage::MerkleRoot;
use fuel_core_types::{
blockchain::header::StateTransitionBytecodeVersion,
fuel_crypto::Hasher,
fuel_tx::ConsensusParameters,
fuel_types::{
Expand Down Expand Up @@ -32,8 +33,11 @@ pub const BYTECODE_NAME: &str = "state_transition_bytecode.wasm";
pub struct ChainConfig {
pub chain_name: String,
pub consensus_parameters: ConsensusParameters,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub genesis_state_transition_version: Option<StateTransitionBytecodeVersion>,
/// Note: The state transition bytecode is stored in a separate file
/// under the `BYTECODE NAME` name in serialization form.
/// under the `BYTECODE_NAME` name in serialization form.
#[serde(skip)]
#[derivative(Debug(format_with = "fmt_truncated_hex::<16>"))]
pub state_transition_bytecode: Vec<u8>,
Expand All @@ -46,6 +50,9 @@ impl Default for ChainConfig {
Self {
chain_name: "local".into(),
consensus_parameters: ConsensusParameters::default(),
genesis_state_transition_version: Some(
fuel_core_types::blockchain::header::LATEST_STATE_TRANSITION_VERSION,
),
// Note: It is invalid bytecode.
state_transition_bytecode: vec![123; 1024],
consensus: ConsensusConfig::default_poa(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ expression: json
"privileged_address": "0000000000000000000000000000000000000000000000000000000000000000"
}
},
"genesis_state_transition_version": 1,
"consensus": {
"PoA": {
"signing_key": "22ec92c3105c942a6640bdc4e4907286ec4728e8cfc0d8ac59aad4d8e1ccaefb"
Expand Down
4 changes: 3 additions & 1 deletion crates/fuel-core/src/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ impl Config {
// In tests, we always want to use the native executor as a default configuration.
let native_executor_version = latest_block
.map(|last_block| last_block.state_transition_version.saturating_add(1))
.unwrap_or(StateTransitionBytecodeVersion::MIN);
.unwrap_or(
fuel_core_types::blockchain::header::LATEST_STATE_TRANSITION_VERSION,
);

let utxo_validation = false;
let min_gas_price = 0;
Expand Down
12 changes: 11 additions & 1 deletion crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ pub fn create_genesis_block(config: &Config) -> Block {
da_height = 0u64.into();
}
consensus_parameters_version = ConsensusParametersVersion::MIN;
state_transition_bytecode_version = StateTransitionBytecodeVersion::MIN;
state_transition_bytecode_version = config
.snapshot_reader
.chain_config()
.genesis_state_transition_version
.unwrap_or(StateTransitionBytecodeVersion::MIN);
prev_root = Bytes32::zeroed();
}

Expand Down Expand Up @@ -646,6 +650,12 @@ mod tests {
let mut expected_state = initial_state;
let mut last_block = LastBlockConfig::default();
last_block.block_height = db.on_chain().latest_height().unwrap().unwrap();
last_block.state_transition_version = db
.on_chain()
.latest_block()
.unwrap()
.header()
.state_transition_bytecode_version;
last_block.blocks_root = db
.on_chain()
.block_header_merkle_root(&last_block.block_height)
Expand Down
12 changes: 8 additions & 4 deletions crates/services/upgradable-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ where
}
} else {
let module = self.get_module(block_version)?;
Self::trace_block_version_warning(block_version);
self.wasm_produce_inner(&module, block, options, dry_run)
}
}
Expand Down Expand Up @@ -415,18 +414,17 @@ where
}
} else {
let module = self.get_module(block_version)?;
Self::trace_block_version_warning(block_version);
self.wasm_validate_inner(&module, block, self.config.as_ref().into())
}
}

#[cfg(feature = "wasm-executor")]
fn trace_block_version_warning(block_version: StateTransitionBytecodeVersion) {
fn trace_block_version_warning(&self, block_version: StateTransitionBytecodeVersion) {
tracing::warn!(
"The block version({}) is different from the native executor version({}). \
The WASM executor will be used.",
block_version,
Self::VERSION
self.native_executor_version()
);
}

Expand Down Expand Up @@ -465,6 +463,9 @@ where
coinbase_recipient,
gas_price,
} = component;
self.trace_block_version_warning(
header_to_produce.state_transition_bytecode_version,
);

let source = Some(transactions_source);

Expand Down Expand Up @@ -502,6 +503,9 @@ where
block: &Block,
options: ExecutionOptions,
) -> ExecutorResult<Uncommitted<ValidationResult, Changes>> {
self.trace_block_version_warning(
block.header().state_transition_bytecode_version,
);
let storage = self.storage_view_provider.latest_view();
let relayer = self.relayer_view_provider.latest_view();

Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rand = { workspace = true }
reqwest = { workspace = true }
rstest = "0.15"
serde_json = { workspace = true }
tempfile = "3.3"
tempfile = { workspace = true }
test-case = { workspace = true }
test-helpers = { path = "./test-helpers" }
tokio = { workspace = true, features = [
Expand Down
4 changes: 4 additions & 0 deletions tests/test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
fuel-core = { path = "../../crates/fuel-core", default-features = false, features = [
"test-helpers",
] }
fuel-core-bin = { path = "../../bin/fuel-core", features = ["parquet", "p2p"] }
fuel-core-client = { path = "../../crates/client", features = ["test-helpers"] }
fuel-core-p2p = { path = "../../crates/services/p2p", features = [
"test-helpers",
Expand All @@ -29,3 +32,4 @@ fuel-core-txpool = { path = "../../crates/services/txpool", features = [
fuel-core-types = { path = "../../crates/types", features = ["test-helpers"] }
itertools = { workspace = true }
rand = { workspace = true }
tempfile = { workspace = true }
Loading

0 comments on commit 290fe5f

Please sign in to comment.