From 02bf6490dc0ab0c46feeb97d6d65a6463c18fb4d Mon Sep 17 00:00:00 2001 From: Eason Date: Wed, 11 Oct 2023 15:06:00 +0800 Subject: [PATCH] refactor: split bls and secp256k1 private key --- common/config-parser/src/types/config.rs | 5 ++++- core/network/src/config.rs | 2 +- core/run/src/lib.rs | 9 ++++++--- devtools/chain/config.toml | 3 ++- devtools/chain/k8s/node_1.toml | 3 ++- devtools/chain/k8s/node_2.toml | 3 ++- devtools/chain/k8s/node_3.toml | 3 ++- devtools/chain/k8s/node_4.toml | 3 ++- devtools/chain/nodes/node_1.toml | 3 ++- devtools/chain/nodes/node_2.toml | 3 ++- devtools/chain/nodes/node_3.toml | 3 ++- devtools/chain/nodes/node_4.toml | 3 ++- devtools/chain/specs/multi_nodes/chain-spec.toml | 8 ++++---- .../specs/multi_nodes_short_epoch_len/chain-spec.toml | 8 ++++---- devtools/chain/specs/single_node/chain-spec.toml | 2 +- protocol/src/traits/consensus.rs | 11 +++++++---- 16 files changed, 45 insertions(+), 27 deletions(-) diff --git a/common/config-parser/src/types/config.rs b/common/config-parser/src/types/config.rs index 4dda9deae..d4efae6f6 100644 --- a/common/config-parser/src/types/config.rs +++ b/common/config-parser/src/types/config.rs @@ -24,7 +24,10 @@ pub const DEFAULT_CACHE_SIZE: usize = 100; pub struct Config { // crypto #[serde(deserialize_with = "deserialize_256bits_key")] - pub privkey: Key256Bits, + pub net_privkey: Key256Bits, + #[serde(deserialize_with = "deserialize_256bits_key")] + pub bls_privkey: Key256Bits, + // db config pub data_path: PathBuf, diff --git a/core/network/src/config.rs b/core/network/src/config.rs index 36dc5817a..bd74b1db8 100644 --- a/core/network/src/config.rs +++ b/core/network/src/config.rs @@ -114,7 +114,7 @@ impl NetworkConfig { .collect(), ) .listen_addr(config.network.listening_address.clone()) - .secio_keypair(config.privkey.as_ref())? + .secio_keypair(config.net_privkey.as_ref())? .chain_id(chain_id) .max_connections(config.network.max_connected_peers) } diff --git a/core/run/src/lib.rs b/core/run/src/lib.rs index 99381440e..801b46fea 100644 --- a/core/run/src/lib.rs +++ b/core/run/src/lib.rs @@ -5,7 +5,7 @@ use common_config_parser::types::spec::{ChainSpec, InitialAccount}; use common_config_parser::types::{Config, ConfigMempool}; use common_crypto::{ BlsPrivateKey, BlsPublicKey, Secp256k1, Secp256k1PrivateKey, Secp256k1RecoverablePrivateKey, - ToPublicKey, + ToBlsPublicKey, ToPublicKey, }; use protocol::tokio::{ @@ -224,7 +224,7 @@ async fn start( // Init overlord consensus and synchronization let lock = Arc::new(AsyncMutex::new(())); - let crypto = init_crypto(config.privkey.as_ref(), &metadata.verifier_list)?; + let crypto = init_crypto(config.bls_privkey.as_ref(), &metadata.verifier_list)?; let consensus_adapter = OverlordConsensusAdapter::<_, _, _, _>::new( Arc::new(network_service.handle()), Arc::clone(&mempool), @@ -238,11 +238,14 @@ async fn start( let hardfork_info = storage.hardfork_proposal(Default::default()).await?; let overlord_consensus = { let consensus_wal_path = config.data_path_for_consensus_wal(); - let node_info = Secp256k1PrivateKey::try_from(config.privkey.as_ref()) + let bls_priv_key = + BlsPrivateKey::try_from(config.bls_privkey.as_ref()).map_err(MainError::Crypto)?; + let node_info = Secp256k1PrivateKey::try_from(config.net_privkey.as_ref()) .map(|privkey| { NodeInfo::new( current_block.header.chain_id, privkey.pub_key(), + bls_priv_key.pub_key(&Default::default()), hardfork_info, ) }) diff --git a/devtools/chain/config.toml b/devtools/chain/config.toml index c422489e2..aa4b00f7d 100644 --- a/devtools/chain/config.toml +++ b/devtools/chain/config.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d" +net_privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d" +bls_privkey = "0x4179b05f5ad5bdd46ca98a9e8b435b00a504562dfe02687895edf747ddf5de18" # db config data_path = "./devtools/chain/data" diff --git a/devtools/chain/k8s/node_1.toml b/devtools/chain/k8s/node_1.toml index 7a5f2cbe7..5ff758ce2 100644 --- a/devtools/chain/k8s/node_1.toml +++ b/devtools/chain/k8s/node_1.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d" +net_privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d" +bls_privkey = "0x4179b05f5ad5bdd46ca98a9e8b435b00a504562dfe02687895edf747ddf5de18" # db config data_path = "./devtools/chain/data1" diff --git a/devtools/chain/k8s/node_2.toml b/devtools/chain/k8s/node_2.toml index 2caf6c0c7..56ab53a55 100644 --- a/devtools/chain/k8s/node_2.toml +++ b/devtools/chain/k8s/node_2.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32" +net_privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32" +bls_privkey = "0x422951d5ac7ddbe86cae7d2d4c82af713785b3177043ac6feb50eda7e360b860" # db config data_path = "./devtools/chain/data2" diff --git a/devtools/chain/k8s/node_3.toml b/devtools/chain/k8s/node_3.toml index c83d3de26..e0608b012 100644 --- a/devtools/chain/k8s/node_3.toml +++ b/devtools/chain/k8s/node_3.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936" +net_privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936" +bls_privkey = "0x51a04542786ca3bae046d1c7451b6a0745efdcc66c39ede37827172f964d5fdf" # db config data_path = "./devtools/chain/data3" diff --git a/devtools/chain/k8s/node_4.toml b/devtools/chain/k8s/node_4.toml index 1e8d6f661..16b48542c 100644 --- a/devtools/chain/k8s/node_4.toml +++ b/devtools/chain/k8s/node_4.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e" +net_privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e" +bls_privkey = "0x67fc8772fdcff8140564e9c4ed693fffd0929c68f24529ee2fb2adfbe9c453fe" # db config data_path = "./devtools/chain/data4" diff --git a/devtools/chain/nodes/node_1.toml b/devtools/chain/nodes/node_1.toml index cd009919f..6aba2724d 100644 --- a/devtools/chain/nodes/node_1.toml +++ b/devtools/chain/nodes/node_1.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d" +net_privkey = "0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d" +bls_privkey = "0x4179b05f5ad5bdd46ca98a9e8b435b00a504562dfe02687895edf747ddf5de18" # db config data_path = "./devtools/chain/data/node_1" diff --git a/devtools/chain/nodes/node_2.toml b/devtools/chain/nodes/node_2.toml index 169503aa4..6f3b72fb6 100644 --- a/devtools/chain/nodes/node_2.toml +++ b/devtools/chain/nodes/node_2.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32" +net_privkey = "0x383fcff8683b8115e31613949be24254b4204ffbe43c227408a76334a2e3fb32" +bls_privkey = "0x422951d5ac7ddbe86cae7d2d4c82af713785b3177043ac6feb50eda7e360b860" # db config data_path = "./devtools/chain/data/node_2" diff --git a/devtools/chain/nodes/node_3.toml b/devtools/chain/nodes/node_3.toml index 4a7c3f30f..4ca7e7f62 100644 --- a/devtools/chain/nodes/node_3.toml +++ b/devtools/chain/nodes/node_3.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936" +net_privkey = "0x51ce21643b911347c5d5c85c323d9d5421810dc89f46b688720b2715f5e8e936" +bls_privkey = "0x51a04542786ca3bae046d1c7451b6a0745efdcc66c39ede37827172f964d5fdf" # db config data_path = "./devtools/chain/data/node_3" diff --git a/devtools/chain/nodes/node_4.toml b/devtools/chain/nodes/node_4.toml index 0b8c8f0d2..29e64952a 100644 --- a/devtools/chain/nodes/node_4.toml +++ b/devtools/chain/nodes/node_4.toml @@ -1,5 +1,6 @@ # crypto -privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e" +net_privkey = "0x69ff51f4c22f30615f68b88efa740f8f1b9169e88842b83d189748d06f1a948e" +bls_privkey = "0x67fc8772fdcff8140564e9c4ed693fffd0929c68f24529ee2fb2adfbe9c453fe" # db config data_path = "./devtools/chain/data/node_4" diff --git a/devtools/chain/specs/multi_nodes/chain-spec.toml b/devtools/chain/specs/multi_nodes/chain-spec.toml index 34b7c7764..583fe7c05 100644 --- a/devtools/chain/specs/multi_nodes/chain-spec.toml +++ b/devtools/chain/specs/multi_nodes/chain-spec.toml @@ -77,28 +77,28 @@ gas_limit = 4294967295000 interval = 3000 [[params.verifier_list]] -bls_pub_key = "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22" +bls_pub_key = "0xa26e3fe1cf51bd4822072c61bdc315ac32e3d3c2e2484bb92942666399e863b4bf56cf2926383cc706ffc15dfebc85c6" pub_key = "0x031ddc35212b7fc7ff6685b17d91f77c972535aee5c7ae5684d3e72b986f08834b" address = "0x8ab0cf264df99d83525e9e11c7e4db01558ae1b1" propose_weight = 1 vote_weight = 1 [[params.verifier_list]] -bls_pub_key = "0x91ed9f3c51c580e56948b1bda9d00c2159665f8a6e284191ab816ee64ef2487d78453a547a0f14efbf842bba5b5a3b4f" +bls_pub_key = "0x80310fa9df724b5603d283b472ed3bf85254a8a4ceda8a274b421f6cf2be1d9184267cdfe9a199d36ff14e57668a55d0" pub_key = "0x02b77c74eb68af3d4d6cc7884ed6709f1a2a1af0f713382a4438ec2ea3a70d4d7f" address = "0xf386573563c3a75dbbd269fce9782620826ddac2" propose_weight = 1 vote_weight = 1 [[params.verifier_list]] -bls_pub_key = "0x92e5d0856fb20ea9cb5ab5da2d3331c38d32cc96507f6ad902fa3da9400096a485fb4e09834bc93de55db224f26c229c" +bls_pub_key = "0x897721e9016864141a8b982a48217f66ef318ce598aa31842cddaaebe3cd7feab17050022afa6c2123aba39938fe4142" pub_key = "0x027ffd6a6a231561f2afe5878b1c743323b34263d16787130b1815fe35649b0bf5" address = "0x8af204ac5d7cb8815a6c53a50b72d01e729d3b22" propose_weight = 1 vote_weight = 1 [[params.verifier_list]] -bls_pub_key = "0xa694f4e48a5a173b61731998f8f1204342dc5c8eb1e32cdae37415c20d11ae035ddac4a39f105e9c2d4d3691024d385d" +bls_pub_key = "0x98eef09a3927acb225191101a1d9aa85775fdcdc87b9ba36898f6c132b485d66aef91c0f51cda331be4f985c3be6761c" pub_key = "0x0232c489c23b1207107e9a24648c1e4754a8c1c0b38db96df57a526201035058cb" address = "0xf4cc1652dcec2e5de9ce6fb1b6f9fa9456e957f1" propose_weight = 1 diff --git a/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml b/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml index b346a78d4..82c0784e9 100644 --- a/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml +++ b/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml @@ -77,28 +77,28 @@ gas_limit = 4294967295000 interval = 3000 [[params.verifier_list]] -bls_pub_key = "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22" +bls_pub_key = "0xa26e3fe1cf51bd4822072c61bdc315ac32e3d3c2e2484bb92942666399e863b4bf56cf2926383cc706ffc15dfebc85c6" pub_key = "0x031ddc35212b7fc7ff6685b17d91f77c972535aee5c7ae5684d3e72b986f08834b" address = "0x8ab0cf264df99d83525e9e11c7e4db01558ae1b1" propose_weight = 1 vote_weight = 1 [[params.verifier_list]] -bls_pub_key = "0x91ed9f3c51c580e56948b1bda9d00c2159665f8a6e284191ab816ee64ef2487d78453a547a0f14efbf842bba5b5a3b4f" +bls_pub_key = "0x80310fa9df724b5603d283b472ed3bf85254a8a4ceda8a274b421f6cf2be1d9184267cdfe9a199d36ff14e57668a55d0" pub_key = "0x02b77c74eb68af3d4d6cc7884ed6709f1a2a1af0f713382a4438ec2ea3a70d4d7f" address = "0xf386573563c3a75dbbd269fce9782620826ddac2" propose_weight = 1 vote_weight = 1 [[params.verifier_list]] -bls_pub_key = "0x92e5d0856fb20ea9cb5ab5da2d3331c38d32cc96507f6ad902fa3da9400096a485fb4e09834bc93de55db224f26c229c" +bls_pub_key = "0x897721e9016864141a8b982a48217f66ef318ce598aa31842cddaaebe3cd7feab17050022afa6c2123aba39938fe4142" pub_key = "0x027ffd6a6a231561f2afe5878b1c743323b34263d16787130b1815fe35649b0bf5" address = "0x8af204ac5d7cb8815a6c53a50b72d01e729d3b22" propose_weight = 1 vote_weight = 1 [[params.verifier_list]] -bls_pub_key = "0xa694f4e48a5a173b61731998f8f1204342dc5c8eb1e32cdae37415c20d11ae035ddac4a39f105e9c2d4d3691024d385d" +bls_pub_key = "0x98eef09a3927acb225191101a1d9aa85775fdcdc87b9ba36898f6c132b485d66aef91c0f51cda331be4f985c3be6761c" pub_key = "0x0232c489c23b1207107e9a24648c1e4754a8c1c0b38db96df57a526201035058cb" address = "0xf4cc1652dcec2e5de9ce6fb1b6f9fa9456e957f1" propose_weight = 1 diff --git a/devtools/chain/specs/single_node/chain-spec.toml b/devtools/chain/specs/single_node/chain-spec.toml index e3fa68787..69b52ea4f 100644 --- a/devtools/chain/specs/single_node/chain-spec.toml +++ b/devtools/chain/specs/single_node/chain-spec.toml @@ -77,7 +77,7 @@ gas_limit = 4294967295000 interval = 3000 [[params.verifier_list]] -bls_pub_key = "0xac85bbb40347b6e06ac2dc2da1f75eece029cdc0ed2d456c457d27e288bfbfbcd4c5c19716e9b250134a0e76ce50fa22" +bls_pub_key = "0xa26e3fe1cf51bd4822072c61bdc315ac32e3d3c2e2484bb92942666399e863b4bf56cf2926383cc706ffc15dfebc85c6" pub_key = "0x031ddc35212b7fc7ff6685b17d91f77c972535aee5c7ae5684d3e72b986f08834b" address = "0x8ab0cf264df99d83525e9e11c7e4db01558ae1b1" propose_weight = 1 diff --git a/protocol/src/traits/consensus.rs b/protocol/src/traits/consensus.rs index 83f7c0528..fd96bbe57 100644 --- a/protocol/src/traits/consensus.rs +++ b/protocol/src/traits/consensus.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, RwLock}, }; -use common_crypto::Secp256k1PublicKey; +use common_crypto::{BlsPublicKey, Secp256k1PublicKey}; use crate::types::{ Address, Block, BlockNumber, Bytes, ExecResp, HardforkInfoInner, Hash, Header, Hex, MerkleRoot, @@ -21,6 +21,7 @@ pub enum MessageTarget { pub struct NodeInfo { pub chain_id: u64, pub self_pub_key: Secp256k1PublicKey, + pub self_bls_pub_key: BlsPublicKey, pub self_address: Address, pub hardfork_proposals: Arc>>, } @@ -28,13 +29,15 @@ pub struct NodeInfo { impl NodeInfo { pub fn new( chain_id: u64, - pubkey: Secp256k1PublicKey, + pub_key: Secp256k1PublicKey, + bls_pub_key: BlsPublicKey, hardfork_info: Option, ) -> Self { - let address = Address::from_pubkey(&pubkey); + let address = Address::from_pubkey(&pub_key); Self { chain_id, - self_pub_key: pubkey, + self_pub_key: pub_key, + self_bls_pub_key: bls_pub_key, self_address: address, hardfork_proposals: Arc::new(RwLock::new(hardfork_info)), }