Skip to content

Commit

Permalink
style: change some code style and annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Sep 26, 2023
1 parent 9ce5aa0 commit 273f45d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 86 deletions.
93 changes: 8 additions & 85 deletions builtin-contract/metadata/contracts/metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}
}
2 changes: 1 addition & 1 deletion core/executor/src/system_contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn init<Adapter: ExecutorAdapter + ApplyBackend>(
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)
Expand Down

0 comments on commit 273f45d

Please sign in to comment.