diff --git a/core/consensus/src/consensus.rs b/core/consensus/src/consensus.rs index c434ea2bb..a145747d0 100644 --- a/core/consensus/src/consensus.rs +++ b/core/consensus/src/consensus.rs @@ -133,11 +133,11 @@ impl OverlordConsensus { Context::new(), OverlordMsg::RichStatus(gen_overlord_status( status.last_number + 1, - metadata.interval, - metadata.propose_ratio, - metadata.prevote_ratio, - metadata.precommit_ratio, - metadata.brake_ratio, + metadata.consensus_config.interval, + metadata.consensus_config.propose_ratio, + metadata.consensus_config.prevote_ratio, + metadata.consensus_config.precommit_ratio, + metadata.consensus_config.brake_ratio, metadata.verifier_list.into_iter().map(Into::into).collect(), )), ) diff --git a/core/consensus/src/engine.rs b/core/consensus/src/engine.rs index 5fbbe75ce..a2f9c1ad4 100644 --- a/core/consensus/src/engine.rs +++ b/core/consensus/src/engine.rs @@ -212,7 +212,7 @@ impl Engine for ConsensusEngine Engine for ConsensusEngine OverlordSynchronization { prev_hash: block.hash(), last_number: block.header.number, last_state_root: resp.state_root, - tx_num_limit: metadata.tx_num_limit, - max_tx_size: metadata.max_tx_size.into(), + tx_num_limit: metadata.consensus_config.tx_num_limit, + max_tx_size: metadata.consensus_config.max_tx_size.into(), proof: proof.clone(), }; @@ -484,6 +484,7 @@ impl OverlordSynchronization { self.adapter .get_metadata_by_block_number(current_number) .await? + .consensus_config .interval, )) .await; @@ -512,11 +513,11 @@ impl OverlordSynchronization { self.adapter.update_status( ctx, sync_status.last_number, - metadata.interval, - metadata.propose_ratio, - metadata.prevote_ratio, - metadata.precommit_ratio, - metadata.brake_ratio, + metadata.consensus_config.interval, + metadata.consensus_config.propose_ratio, + metadata.consensus_config.prevote_ratio, + metadata.consensus_config.precommit_ratio, + metadata.consensus_config.brake_ratio, metadata.verifier_list.into_iter().map(Into::into).collect(), )?; diff --git a/core/executor/src/system_contract/metadata/abi/mod.rs b/core/executor/src/system_contract/metadata/abi/mod.rs index 4d0dc2fe0..0c17da406 100644 --- a/core/executor/src/system_contract/metadata/abi/mod.rs +++ b/core/executor/src/system_contract/metadata/abi/mod.rs @@ -1,28 +1,31 @@ pub mod metadata_abi; use protocol::types::{ - CkbRelatedInfo, Hex, Metadata, MetadataVersion, ProposeCount, ValidatorExtend, H256, + CkbRelatedInfo, ConsensusConfig, Hex, Metadata, MetadataVersion, ProposeCount, ValidatorExtend, + H256, }; impl From for Metadata { fn from(value: metadata_abi::Metadata) -> Metadata { Metadata { - version: MetadataVersion { + version: MetadataVersion { start: value.version.start, end: value.version.end, }, - epoch: value.epoch, - gas_limit: value.gas_limit, - gas_price: value.gas_price, - interval: value.interval, - verifier_list: value.verifier_list.into_iter().map(Into::into).collect(), - propose_ratio: value.propose_ratio, - prevote_ratio: value.prevote_ratio, - precommit_ratio: value.precommit_ratio, - brake_ratio: value.brake_ratio, - tx_num_limit: value.tx_num_limit, - max_tx_size: value.max_tx_size, - propose_counter: value.propose_counter.into_iter().map(Into::into).collect(), + epoch: value.epoch, + verifier_list: value.verifier_list.into_iter().map(Into::into).collect(), + propose_counter: value.propose_counter.into_iter().map(Into::into).collect(), + consensus_config: ConsensusConfig { + gas_limit: value.gas_limit, + gas_price: value.gas_price, + interval: value.interval, + propose_ratio: value.propose_ratio, + prevote_ratio: value.prevote_ratio, + precommit_ratio: value.precommit_ratio, + brake_ratio: value.brake_ratio, + tx_num_limit: value.tx_num_limit, + max_tx_size: value.max_tx_size, + }, } } } @@ -32,16 +35,16 @@ impl From for metadata_abi::Metadata { metadata_abi::Metadata { version: value.version.into(), epoch: value.epoch, - gas_limit: value.gas_limit, - gas_price: value.gas_price, - interval: value.interval, + gas_limit: value.consensus_config.gas_limit, + gas_price: value.consensus_config.gas_price, + interval: value.consensus_config.interval, verifier_list: value.verifier_list.into_iter().map(Into::into).collect(), - propose_ratio: value.propose_ratio, - prevote_ratio: value.prevote_ratio, - precommit_ratio: value.precommit_ratio, - brake_ratio: value.brake_ratio, - tx_num_limit: value.tx_num_limit, - max_tx_size: value.max_tx_size, + propose_ratio: value.consensus_config.propose_ratio, + prevote_ratio: value.consensus_config.prevote_ratio, + precommit_ratio: value.consensus_config.precommit_ratio, + brake_ratio: value.consensus_config.brake_ratio, + tx_num_limit: value.consensus_config.tx_num_limit, + max_tx_size: value.consensus_config.max_tx_size, propose_counter: value.propose_counter.into_iter().map(Into::into).collect(), } } diff --git a/core/run/src/lib.rs b/core/run/src/lib.rs index 3c0685b7c..af30dd7db 100644 --- a/core/run/src/lib.rs +++ b/core/run/src/lib.rs @@ -335,8 +335,8 @@ impl Axon { mempool.set_args( Context::new(), current_block.header.state_root, - metadata.gas_limit, - metadata.max_tx_size, + metadata.consensus_config.gas_limit, + metadata.consensus_config.max_tx_size, ); // Init overlord consensus and synchronization @@ -582,8 +582,8 @@ impl Axon { let current_consensus_status = CurrentStatus { prev_hash: block.hash(), last_number: header.number, - max_tx_size: metadata.max_tx_size.into(), - tx_num_limit: metadata.tx_num_limit, + max_tx_size: metadata.consensus_config.max_tx_size.into(), + tx_num_limit: metadata.consensus_config.tx_num_limit, proof: latest_proof, last_state_root: if header.number == 0 { self.state_root @@ -808,17 +808,17 @@ impl Axon { DB: TrieDB, { let timer_config = DurationConfig { - propose_ratio: metadata.propose_ratio, - prevote_ratio: metadata.prevote_ratio, - precommit_ratio: metadata.precommit_ratio, - brake_ratio: metadata.brake_ratio, + propose_ratio: metadata.consensus_config.propose_ratio, + prevote_ratio: metadata.consensus_config.prevote_ratio, + precommit_ratio: metadata.consensus_config.precommit_ratio, + brake_ratio: metadata.consensus_config.brake_ratio, }; tokio::spawn(async move { if let Err(e) = overlord_consensus .run( current_block.header.number, - metadata.interval, + metadata.consensus_config.interval, validators, Some(timer_config), ) diff --git a/core/run/src/tests.rs b/core/run/src/tests.rs index da099a508..d8d8a103b 100644 --- a/core/run/src/tests.rs +++ b/core/run/src/tests.rs @@ -25,7 +25,7 @@ const CONFIG_FILE: &str = "config.toml"; const GENESIS_HASH: &str = "0x2cc987996d5d26d18cb76dceb85d9b46e4f05f11ff331247225d983ec7a7b78f"; const GENESIS_STATE_ROOT: &str = - "0x65f57a6a666e656de33ed68957e04b35b3fe1b35a90f6eafb6f283c907dc3d77"; + "0x47bd35cdb8bd43da1d5ce85ad77fd68de4d654fc2677ac36bd3e18cfda0ff136"; const GENESIS_RECEIPTS_ROOT: &str = "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b"; diff --git a/devtools/genesis-generator/metadata.json b/devtools/genesis-generator/metadata.json index 2f3541ad6..4a8361714 100644 --- a/devtools/genesis-generator/metadata.json +++ b/devtools/genesis-generator/metadata.json @@ -4,11 +4,6 @@ "end": 100000000 }, "epoch": 0, - "common_ref": "0x6c747758636859487038", - "timeout_gap": 1000, - "gas_limit": 4294967295000, - "gas_price": 1, - "interval": 3000, "verifier_list": [ { "bls_pub_key": "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22", @@ -18,10 +13,15 @@ "vote_weight": 1 } ], - "propose_ratio": 15, - "prevote_ratio": 10, - "precommit_ratio": 10, - "brake_ratio": 10, - "tx_num_limit": 20000, - "max_tx_size": 409600000 + "consensus_config": { + "propose_ratio": 15, + "prevote_ratio": 10, + "precommit_ratio": 10, + "brake_ratio": 10, + "tx_num_limit": 20000, + "max_tx_size": 409600000, + "gas_limit": 4294967295000, + "gas_price": 1, + "interval": 3000 + } } diff --git a/protocol/src/types/block.rs b/protocol/src/types/block.rs index f5ad0fc1a..3c59eeaaa 100644 --- a/protocol/src/types/block.rs +++ b/protocol/src/types/block.rs @@ -278,8 +278,8 @@ impl RichBlock { #[cfg(test)] mod tests { use crate::types::{ - Block, BlockVersion, Header, Hex, Metadata, MetadataVersion, ProposeCount, RichBlock, - ValidatorExtend, H160, + Block, BlockVersion, ConsensusConfig, Header, Hex, Metadata, MetadataVersion, ProposeCount, + RichBlock, ValidatorExtend, H160, }; use std::time::{SystemTime, UNIX_EPOCH}; @@ -339,15 +339,6 @@ mod tests { let metadata = Metadata { version: MetadataVersion::new(0, 1000000000), epoch: 0, - gas_limit: 4294967295, - gas_price: 1, - interval: 3000, - propose_ratio: 15, - prevote_ratio: 10, - precommit_ratio: 10, - brake_ratio: 10, - tx_num_limit: 20000, - max_tx_size: 1024, verifier_list: vec![ValidatorExtend { bls_pub_key: Hex::from_string("0x04102947214862a503c73904deb5818298a186d68c7907bb609583192a7de6331493835e5b8281f4d9ee705537c0e765580e06f86ddce5867812fceb42eecefd209f0eddd0389d6b7b0100f00fb119ef9ab23826c6ea09aadcc76fa6cea6a32724".to_string()).unwrap(), pub_key: Hex::from_string("0x02ef0cb0d7bc6c18b4bea1f5908d9106522b35ab3c399369605d4242525bda7e60".to_string()).unwrap(), @@ -359,6 +350,17 @@ mod tests { address: H160::default(), count: 0, }], + consensus_config: ConsensusConfig { + gas_limit: 4294967295, + gas_price: 1, + interval: 3000, + propose_ratio: 15, + prevote_ratio: 10, + precommit_ratio: 10, + brake_ratio: 10, + tx_num_limit: 20000, + max_tx_size: 1024, + } }; println!("{}", serde_json::to_string(&metadata).unwrap()); diff --git a/protocol/src/types/primitive.rs b/protocol/src/types/primitive.rs index 949fb91ce..006097036 100644 --- a/protocol/src/types/primitive.rs +++ b/protocol/src/types/primitive.rs @@ -320,16 +320,25 @@ impl MetadataVersion { RlpEncodable, RlpDecodable, Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, )] pub struct Metadata { - pub version: MetadataVersion, + pub version: MetadataVersion, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] - pub epoch: u64, + pub epoch: u64, + pub verifier_list: Vec, + #[serde(skip_deserializing)] + pub propose_counter: Vec, + pub consensus_config: ConsensusConfig, +} + +#[derive( + RlpEncodable, RlpDecodable, Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, +)] +pub struct ConsensusConfig { #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] pub gas_limit: u64, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] pub gas_price: u64, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] pub interval: u64, - pub verifier_list: Vec, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] pub propose_ratio: u64, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] @@ -342,17 +351,15 @@ pub struct Metadata { pub tx_num_limit: u64, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] pub max_tx_size: u64, - #[serde(skip_deserializing)] - pub propose_counter: Vec, } impl From for DurationConfig { fn from(m: Metadata) -> Self { DurationConfig { - propose_ratio: m.propose_ratio, - prevote_ratio: m.prevote_ratio, - precommit_ratio: m.precommit_ratio, - brake_ratio: m.brake_ratio, + propose_ratio: m.consensus_config.propose_ratio, + prevote_ratio: m.consensus_config.prevote_ratio, + precommit_ratio: m.consensus_config.precommit_ratio, + brake_ratio: m.consensus_config.brake_ratio, } } }