diff --git a/Cargo.lock b/Cargo.lock index 7e0a63fa47..bb3a46487f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,7 +568,7 @@ dependencies = [ [[package]] name = "cardano-legacy-address" version = "0.1.1" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "cbor_event", "cryptoxide 0.4.2", @@ -639,7 +639,7 @@ dependencies = [ [[package]] name = "chain-addr" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "bech32 0.8.1", "chain-core", @@ -653,7 +653,7 @@ dependencies = [ [[package]] name = "chain-core" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "chain-ser", ] @@ -661,7 +661,7 @@ dependencies = [ [[package]] name = "chain-crypto" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "bech32 0.8.1", "cryptoxide 0.4.2", @@ -683,7 +683,7 @@ dependencies = [ [[package]] name = "chain-evm" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "aurora-bn", "base64", @@ -712,7 +712,7 @@ dependencies = [ [[package]] name = "chain-impl-mockchain" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "cardano-legacy-address", "chain-addr", @@ -744,7 +744,7 @@ dependencies = [ [[package]] name = "chain-network" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "async-trait", "chain-crypto", @@ -761,7 +761,7 @@ dependencies = [ [[package]] name = "chain-ser" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "thiserror", ] @@ -769,7 +769,7 @@ dependencies = [ [[package]] name = "chain-storage" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "criterion", "data-pile", @@ -782,7 +782,7 @@ dependencies = [ [[package]] name = "chain-time" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "chain-core", "chain-ser", @@ -794,9 +794,9 @@ dependencies = [ [[package]] name = "chain-vote" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "chain-core", "chain-crypto", "const_format", @@ -2261,7 +2261,7 @@ dependencies = [ [[package]] name = "imhamt" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" dependencies = [ "proptest", "rustc_version", @@ -2619,6 +2619,7 @@ dependencies = [ "chain-addr", "chain-core", "chain-crypto", + "chain-evm", "chain-impl-mockchain", "chain-time", "chain-vote", @@ -4706,7 +4707,7 @@ dependencies = [ [[package]] name = "sparse-array" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" [[package]] name = "spin" @@ -5467,7 +5468,7 @@ dependencies = [ [[package]] name = "typed-bytes" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#bc4d5d8b84860a7c47ce7ee99089600d3434fe7a" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#4944822385be1a8987d319dc97e27677c6a89d77" [[package]] name = "typenum" diff --git a/jcli/src/jcli_lib/utils/mod.rs b/jcli/src/jcli_lib/utils/mod.rs index 89fe430ce4..11f3b7e35c 100644 --- a/jcli/src/jcli_lib/utils/mod.rs +++ b/jcli/src/jcli_lib/utils/mod.rs @@ -37,7 +37,7 @@ impl Utils { pub fn exec(self) -> Result<(), Error> { match self { Utils::Bech32Convert(convert_args) => { - convert_prefix(convert_args.from_bech32, convert_args.new_hrp).map_err(|e| e) + convert_prefix(convert_args.from_bech32, convert_args.new_hrp) } } } diff --git a/jormungandr-lib/Cargo.toml b/jormungandr-lib/Cargo.toml index a23e6db7fe..88431e4c69 100644 --- a/jormungandr-lib/Cargo.toml +++ b/jormungandr-lib/Cargo.toml @@ -15,6 +15,7 @@ chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", b chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master"} chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } +chain-evm = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", optional = true } cardano-legacy-address = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } typed-bytes = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } rand = "0.8" @@ -43,4 +44,4 @@ serde_yaml = "0.8" serde_json = "1.0" [features] -evm = ["chain-impl-mockchain/evm"] +evm = ["chain-impl-mockchain/evm", "chain-evm"] diff --git a/jormungandr/src/context/mod.rs b/jormungandr/src/context/mod.rs index fc117c2776..3c376e501f 100644 --- a/jormungandr/src/context/mod.rs +++ b/jormungandr/src/context/mod.rs @@ -159,6 +159,8 @@ pub struct FullContext { pub transaction_task: MessageBox, pub leadership_logs: LeadershipLogs, pub enclave: Enclave, + #[cfg(feature = "evm")] + pub evm_keys: Arc>, pub network_state: NetworkStateR, #[cfg(feature = "prometheus-metrics")] pub prometheus: Option>, diff --git a/jormungandr/src/jrpc/eth_account/logic.rs b/jormungandr/src/jrpc/eth_account/logic.rs index 2c5ef581e3..9413560f83 100644 --- a/jormungandr/src/jrpc/eth_account/logic.rs +++ b/jormungandr/src/jrpc/eth_account/logic.rs @@ -1,13 +1,19 @@ -use super::Error; use crate::{ context::Context, - jrpc::eth_types::{block_number::BlockNumber, bytes::Bytes, number::Number}, + jrpc::{ + eth_types::{block_number::BlockNumber, bytes::Bytes, number::Number}, + Error, + }, }; use chain_evm::ethereum_types::{H160, H256}; -pub fn accounts(_context: &Context) -> Result, Error> { - // TODO implement - Ok(vec![H160::zero()]) +pub fn accounts(context: &Context) -> Result, Error> { + Ok(context + .try_full()? + .evm_keys + .iter() + .map(|secret_key| secret_key.address()) + .collect()) } pub fn get_transaction_count( diff --git a/jormungandr/src/jrpc/eth_account/mod.rs b/jormungandr/src/jrpc/eth_account/mod.rs index 5fb42f4a7f..bebd063e83 100644 --- a/jormungandr/src/jrpc/eth_account/mod.rs +++ b/jormungandr/src/jrpc/eth_account/mod.rs @@ -3,9 +3,6 @@ use jsonrpsee_http_server::RpcModule; mod logic; -#[derive(Debug, thiserror::Error)] -pub enum Error {} - pub fn eth_account_module(context: ContextLock) -> RpcModule { let mut module = RpcModule::new(context); diff --git a/jormungandr/src/jrpc/eth_block_info/logic.rs b/jormungandr/src/jrpc/eth_block_info/logic.rs index f033abdd59..b8a2b6582c 100644 --- a/jormungandr/src/jrpc/eth_block_info/logic.rs +++ b/jormungandr/src/jrpc/eth_block_info/logic.rs @@ -42,8 +42,8 @@ pub async fn get_block_by_hash( context: &Context, ) -> Result, Error> { let blockchain_tip = context.blockchain_tip()?.get_ref().await; - let gas_limit = blockchain_tip.ledger().evm_block_gas_limit(); - let gas_price = blockchain_tip.ledger().evm_gas_price(); + let gas_limit = blockchain_tip.ledger().get_evm_block_gas_limit(); + let gas_price = blockchain_tip.ledger().get_evm_gas_price(); let block = context.blockchain()?.storage().get(hash.0.into())?; Ok(block.map(|block| Block::build(block, full, gas_limit, gas_price))) } @@ -55,8 +55,8 @@ pub async fn get_block_by_number( ) -> Result, Error> { let blockchain = context.blockchain()?; let blockchain_tip = context.blockchain_tip()?.get_ref().await; - let gas_limit = blockchain_tip.ledger().evm_block_gas_limit(); - let gas_price = blockchain_tip.ledger().evm_gas_price(); + let gas_limit = blockchain_tip.ledger().get_evm_block_gas_limit(); + let gas_price = blockchain_tip.ledger().get_evm_gas_price(); Ok( get_block_by_number_from_context(number, blockchain, blockchain_tip)? .map(|block| Block::build(block, full, gas_limit, gas_price)), diff --git a/jormungandr/src/jrpc/eth_transaction/logic.rs b/jormungandr/src/jrpc/eth_transaction/logic.rs index 345d608e94..127cd7351a 100644 --- a/jormungandr/src/jrpc/eth_transaction/logic.rs +++ b/jormungandr/src/jrpc/eth_transaction/logic.rs @@ -101,7 +101,7 @@ pub async fn get_transaction_by_block_hash_and_index( context: &Context, ) -> Result, Error> { let blockchain_tip = context.blockchain_tip()?.get_ref().await; - let gas_price = blockchain_tip.ledger().evm_gas_price(); + let gas_price = blockchain_tip.ledger().get_evm_gas_price(); let block = context.blockchain()?.storage().get(hash.0.into())?; Ok(get_transaction_from_block_by_index(block, index, gas_price)) } @@ -112,7 +112,7 @@ pub async fn get_transaction_by_block_number_and_index( context: &Context, ) -> Result, Error> { let blockchain_tip = context.blockchain_tip()?.get_ref().await; - let gas_price = blockchain_tip.ledger().evm_gas_price(); + let gas_price = blockchain_tip.ledger().get_evm_gas_price(); let blockchain = context.blockchain()?; let block = get_block_by_number_from_context(number, blockchain, blockchain_tip).unwrap(); Ok(get_transaction_from_block_by_index(block, index, gas_price)) diff --git a/jormungandr/src/lib.rs b/jormungandr/src/lib.rs index 29a5260b76..6805cdde21 100644 --- a/jormungandr/src/lib.rs +++ b/jormungandr/src/lib.rs @@ -232,29 +232,40 @@ fn start_services(bootstrapped_node: BootstrappedNode) -> Result<(), start_up::E None } }); - let leader_secret = bootstrapped_node + let node_secret = bootstrapped_node .settings .secret .map::, _>(|secret_path| { let secret = secure::NodeSecret::load_from_file(secret_path.as_path())?; - if let (Some(leaders), Some(leader)) = (&bft_leaders, secret.bft()) { - let public_key = &leader.sig_key.to_public(); - if !leaders.contains(public_key) { - tracing::warn!( - "node was started with a BFT secret key but the corresponding \ - public key {} is not listed among consensus leaders", - public_key - ); - } - }; - Ok(Leader { - bft_leader: secret.bft(), - genesis_leader: secret.genesis(), - }) + Ok(secret) }) .transpose()?; + + let leader_secret = node_secret.as_ref().map(|secret| { + if let (Some(leaders), Some(leader)) = (&bft_leaders, secret.bft()) { + let public_key = &leader.sig_key.to_public(); + if !leaders.contains(public_key) { + tracing::warn!( + "node was started with a BFT secret key but the corresponding \ + public key {} is not listed among consensus leaders", + public_key + ); + } + }; + Leader { + bft_leader: secret.bft(), + genesis_leader: secret.genesis(), + } + }); let enclave = Enclave::new(leader_secret); + #[cfg(feature = "evm")] + let evm_keys = Arc::new( + node_secret + .map(|secret| secret.evm_keys()) + .unwrap_or_default(), + ); + { let logs = leadership_logs.clone(); let block_message = block_msgbox; @@ -310,6 +321,8 @@ fn start_services(bootstrapped_node: BootstrappedNode) -> Result<(), start_up::E transaction_task: fragment_msgbox, topology_task: topology_msgbox, leadership_logs, + #[cfg(feature = "evm")] + evm_keys, enclave, network_state, #[cfg(feature = "prometheus-metrics")] diff --git a/jormungandr/src/rest/v0/logic.rs b/jormungandr/src/rest/v0/logic.rs index e4046cd005..0cf678c0ae 100644 --- a/jormungandr/src/rest/v0/logic.rs +++ b/jormungandr/src/rest/v0/logic.rs @@ -601,7 +601,7 @@ pub async fn get_jor_address(context: &Context, evm_id_hex: &str) -> Result Result::from_str(jor_id_hex) .map_err(|e| Error::AddressParseError(e.to_string()))? .into(), diff --git a/jormungandr/src/secure/mod.rs b/jormungandr/src/secure/mod.rs index 24385af4d6..4be53287b2 100644 --- a/jormungandr/src/secure/mod.rs +++ b/jormungandr/src/secure/mod.rs @@ -31,8 +31,10 @@ pub struct OwnerKey(Identifier); /// Node Secret(s) #[derive(Clone, Deserialize)] pub struct NodeSecret { - pub bft: Option, - pub genesis: Option, + bft: Option, + genesis: Option, + #[cfg(feature = "evm")] + evm_keys: Vec, } /// Node Secret's Public parts @@ -68,4 +70,12 @@ impl NodeSecret { vrf_key: genesis.vrf_key.into_secret_key(), }) } + + #[cfg(feature = "evm")] + pub fn evm_keys(&self) -> Vec { + self.evm_keys + .iter() + .map(chain_evm::util::Secret::from_hash) + .collect() + } } diff --git a/jormungandr/src/settings/start/config.rs b/jormungandr/src/settings/start/config.rs index 2d20691e2b..eb69bd25f4 100644 --- a/jormungandr/src/settings/start/config.rs +++ b/jormungandr/src/settings/start/config.rs @@ -16,7 +16,6 @@ use tracing::level_filters::LevelFilter; #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct Config { - #[serde(default)] pub secret_file: Option, pub storage: Option, pub log: Option,