From 273f45dab94960da348490d8fa02fb75bd478a72 Mon Sep 17 00:00:00 2001 From: Eason Date: Tue, 26 Sep 2023 12:00:49 +0800 Subject: [PATCH] style: change some code style and annotation --- .../metadata/contracts/metadata.sol | 93 ++----------------- core/executor/src/system_contract/mod.rs | 2 +- 2 files changed, 9 insertions(+), 86 deletions(-) diff --git a/builtin-contract/metadata/contracts/metadata.sol b/builtin-contract/metadata/contracts/metadata.sol index f9795bb8d..a1b83da03 100644 --- a/builtin-contract/metadata/contracts/metadata.sol +++ b/builtin-contract/metadata/contracts/metadata.sol @@ -2,7 +2,9 @@ pragma solidity >=0.7.0; -// import "hardhat/console.sol"; +// **Notice** +// The solidity contract only define the interface of metadata contract. The real +// implementation is in `core/executor/src/system_contract/metadata`. contract MetadataManager { uint64 constant U64_MAX = 2 ** 64 - 1; @@ -60,92 +62,13 @@ contract MetadataManager { // to identify current highest epoch number uint64 highest_epoch; - function construct() public { - highest_epoch = U64_MAX; - } + function construct() public {} - // push new metadata into `metadata_set` - function appendMetadata(Metadata memory metadata) public { - require(metadata.epoch >= 0, "fatal/invalid epoch"); - - bool find_sender = false; - for (uint256 i = 0; i < metadata.verifier_list.length; i++) { - if (metadata.verifier_list[i].address_ == msg.sender) { - find_sender = true; - break; - } - } - require(find_sender, "fatal/verifier_list has no sender"); - - uint64 epoch = metadata.epoch; - if (highest_epoch != U64_MAX) { - require(highest_epoch + 1 == epoch, "fatal/discontinuous epoch"); - require( - metadata.version.start == - metadata_set[highest_epoch].version.end + 1, - "fatal/discontinuous version" - ); - } - - Metadata storage target = metadata_set[epoch]; - target.version = metadata.version; - target.epoch = metadata.epoch; - target.consensus_config.gas_limit = metadata.consensus_config.gas_limit; - target.consensus_config.gas_price = metadata.consensus_config.gas_price; - target.consensus_config.interval = metadata.consensus_config.interval; - target.consensus_config.propose_ratio = metadata - .consensus_config - .propose_ratio; - target.consensus_config.prevote_ratio = metadata - .consensus_config - .prevote_ratio; - target.consensus_config.precommit_ratio = metadata - .consensus_config - .precommit_ratio; - target.consensus_config.brake_ratio = metadata - .consensus_config - .brake_ratio; - target.consensus_config.tx_num_limit = metadata - .consensus_config - .tx_num_limit; - target.consensus_config.max_tx_size = metadata - .consensus_config - .max_tx_size; - for (uint256 i = 0; i < metadata.propose_counter.length; i++) { - target.propose_counter.push(metadata.propose_counter[i]); - } - for (uint256 i = 0; i < metadata.verifier_list.length; i++) { - target.verifier_list.push(metadata.verifier_list[i]); - } - highest_epoch = epoch; - } + function appendMetadata(Metadata memory metadata) public {} - // update current consensus_config - function updateConsensusConfig(ConsensusConfig memory config) public view { - Metadata memory highest_metadata = metadata_set[highest_epoch]; - - bool find_sender = false; - for (uint256 i = 0; i < highest_metadata.verifier_list.length; i++) { - if (highest_metadata.verifier_list[i].address_ == msg.sender) { - find_sender = true; - break; - } - } - require(find_sender, "fatal/verifier_list has no sender"); - highest_metadata.consensus_config = config; - } + function updateConsensusConfig(ConsensusConfig memory config) public view {} - // get metadata from `metadata_set` by epoch - function getMetadata(uint64 epoch) public view returns (Metadata memory) { - Metadata memory metadata = metadata_set[epoch]; - require( - metadata.consensus_config.gas_limit != 0, - "fatal/non-indexed epoch" - ); - return metadata; - } + function getMetadata(uint64 epoch) public view returns (Metadata memory) {} - function setCkbRelatedInfo( - CkbRelatedInfo memory ckbRelatedInfo - ) public view {} + function setCkbRelatedInfo() public view {} } diff --git a/core/executor/src/system_contract/mod.rs b/core/executor/src/system_contract/mod.rs index fc3a85bbb..827a3e1aa 100644 --- a/core/executor/src/system_contract/mod.rs +++ b/core/executor/src/system_contract/mod.rs @@ -132,7 +132,7 @@ pub fn init( adapter.storage(CKB_LIGHT_CLIENT_CONTRACT_ADDRESS, *HEADER_CELL_ROOT_KEY); if current_cell_root.is_zero() { - let changes = generate_mpt_root_changes(adapter, IMAGE_CELL_CONTRACT_ADDRESS); + let changes = generate_mpt_root_changes(adapter, CKB_LIGHT_CLIENT_CONTRACT_ADDRESS); adapter.apply(changes, vec![], false); } (current_metadata_root, current_cell_root)