Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Oct 11, 2023
1 parent a3432b4 commit 7ec2f5c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions core/consensus/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ where
.into());
}

// The address field of Node struct should use the node's secp256k1 public key
let mut authority_list = metadata
.verifier_list
.iter()
Expand Down
4 changes: 3 additions & 1 deletion core/consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<Adapter: ConsensusAdapter + 'static> OverlordConsensus<Adapter> {
metadata.consensus_config.prevote_ratio,
metadata.consensus_config.precommit_ratio,
metadata.consensus_config.brake_ratio,
metadata.verifier_list.into_iter().map(Into::into).collect(),
metadata.verifier_list.iter().map(Into::into).collect(),
)),
)
.unwrap();
Expand All @@ -167,6 +167,7 @@ impl<Adapter: ConsensusAdapter + 'static> OverlordConsensus<Adapter> {
validators: Vec<Validator>,
timer_config: Option<DurationConfig>,
) -> ProtocolResult<()> {
// The address field of Node struct should use the node's secp256k1 public key
let authority_list = validators
.into_iter()
.map(|v| Node {
Expand Down Expand Up @@ -194,6 +195,7 @@ pub fn gen_overlord_status(
brake_ratio: u64,
validators: Vec<Validator>,
) -> Status {
// The address field of Node struct should use the node's secp256k1 public key
let mut authority_list = validators
.into_iter()
.map(|v| Node {
Expand Down
2 changes: 2 additions & 0 deletions core/consensus/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ impl<Adapter: ConsensusAdapter + 'static> Engine<Proposal> for ConsensusEngine<A
.await?
};

// The address field of Node struct should use the node's secp256k1 public key
let mut old_validators = old_metadata
.verifier_list
.into_iter()
Expand Down Expand Up @@ -784,6 +785,7 @@ pub fn generate_new_crypto_map(metadata: Metadata) -> ProtocolResult<HashMap<Byt
}

fn convert_to_overlord_authority(validators: &[ValidatorExtend]) -> Vec<Node> {
// The address field of Node struct should use the node's secp256k1 public key
let mut authority = validators
.iter()
.map(|v| Node {
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/src/synchronization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<Adapter: SynchronizationAdapter> OverlordSynchronization<Adapter> {
metadata.consensus_config.prevote_ratio,
metadata.consensus_config.precommit_ratio,
metadata.consensus_config.brake_ratio,
metadata.verifier_list.into_iter().map(Into::into).collect(),
metadata.verifier_list.iter().map(Into::into).collect(),
)?;

log::info!(
Expand Down
5 changes: 5 additions & 0 deletions core/consensus/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pub fn time_now() -> u64 {
.as_secs()
}

/// The `private_key` is the blst private key of the node. The `addr_pubkey` is
/// a map to get the blst public key by the address. To be notice that the
/// address uses secp256k1 **public key** which is same as the `address` field
/// in `Node` struct. Use secp256k1 public key instead of address can reduce the
/// `keccak256` hash calculation at the end of each height.
pub struct OverlordCrypto {
private_key: BlsPrivateKey,
addr_pubkey: RwLock<HashMap<Bytes, BlsPublicKey>>,
Expand Down
10 changes: 1 addition & 9 deletions core/run/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,7 @@ async fn start<K: KeyProvider>(
metadata_handle.init_hardfork(current_block.header.number)?;

let metadata = metadata_handle.get_metadata_by_block_number(current_block.header.number)?;
let validators: Vec<Validator> = metadata
.verifier_list
.iter()
.map(|v| Validator {
pub_key: v.pub_key.as_bytes(),
propose_weight: v.propose_weight,
vote_weight: v.vote_weight,
})
.collect::<Vec<_>>();
let validators: Vec<Validator> = metadata.verifier_list.iter().map(Into::into).collect();

// Set args in mempool
mempool.set_args(
Expand Down
12 changes: 6 additions & 6 deletions core/run/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ const TESTCASES: &[TestCase] = &[
config_file: "config.toml",
chain_spec_file: "specs/single_node/chain-spec.toml",
key_file: "debug.key",
input_genesis_hash: "0xe3a40f0115fbf101520ceea1ce7103a73cb46554187ac7ed67f3522103e06d99",
genesis_state_root: "0x2f1e8e50d5ab97af96fdb5d6de8e691e5bb80f46f2c98c4133d265bd8b60de61",
input_genesis_hash: "0x274c0c52500c3978776d8836b8afe0999a946a010166c12a85a1c45b9cd2c5a2",
genesis_state_root: "0x940458498b6ac368ab17e9ede64d0cc1d321bc4ec835e09a333a4151c7785ea1",
},
TestCase {
chain_name: "multi_nodes",
config_file: "nodes/node_1.toml",
chain_spec_file: "specs/multi_nodes/chain-spec.toml",
key_file: "debug.key",
input_genesis_hash: "0x1b4cf78373961dabcba5d4a9402c924fc4fecdd9ce367239f02c8971a052f3b5",
genesis_state_root: "0xf684cbec490eb5b8a07b80f369f3bf87f05ec73494b869111010a6ad6fa89894",
input_genesis_hash: "0x70cc025ae586f054157f6d8a6558c39c359cde0eb4b9acbdf3f31a8e14a6a6fc",
genesis_state_root: "0x9976026c069e8d931d55f93637663e494caae772c2c274ad636de9bc7baf5191",
},
TestCase {
chain_name: "multi_nodes_short_epoch_len",
config_file: "nodes/node_1.toml",
chain_spec_file: "specs/multi_nodes_short_epoch_len/chain-spec.toml",
key_file: "debug.key",
input_genesis_hash: "0xd930632a7565acfc149c1d896d79910608768de5b936fdb34cc47c9b2296dd2a",
genesis_state_root: "0xa5e1e7ac3e03f7dc26cc93ab69c0ec49e591cbdaa7694c75682745c40bfca468",
input_genesis_hash: "0x4213963522f2d72fa8b33ab4a8b33d79f0d387999f97f38d5c93d9b047baa743",
genesis_state_root: "0x33a4f19a7d1bca010f6c3f17904e23f099dd2a022e1f1401fbffed27a1919370",
},
];

Expand Down
4 changes: 2 additions & 2 deletions protocol/src/types/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ impl Ord for ValidatorExtend {
}
}

impl From<ValidatorExtend> for Validator {
fn from(ve: ValidatorExtend) -> Self {
impl From<&ValidatorExtend> for Validator {
fn from(ve: &ValidatorExtend) -> Self {
Validator {
pub_key: ve.pub_key.as_bytes(),
propose_weight: ve.propose_weight,
Expand Down

0 comments on commit 7ec2f5c

Please sign in to comment.