From 6a42100a1425432b08c78126f97f76b704f10dda Mon Sep 17 00:00:00 2001 From: Alex Pozhylenkov Date: Mon, 30 May 2022 16:31:05 +0300 Subject: [PATCH] update to the latest chain-libs (#4001) --- Cargo.lock | 30 +++++------ jcli/src/jcli_lib/transaction/staging.rs | 43 +++------------ .../src/interfaces/evm_transaction.rs | 11 ++-- jormungandr/src/fragment/pool.rs | 6 ++- jormungandr/src/jrpc/eth_types/block.rs | 7 ++- jormungandr/src/jrpc/eth_types/transaction.rs | 54 ++++++------------- .../metrics/backends/prometheus_exporter.rs | 5 +- .../src/metrics/backends/simple_counter.rs | 5 +- 8 files changed, 58 insertions(+), 103 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 146a30baca..f9f8f45a1e 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" 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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "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#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" dependencies = [ "proptest", "rustc_version", @@ -4705,7 +4705,7 @@ dependencies = [ [[package]] name = "sparse-array" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" [[package]] name = "spin" @@ -5466,7 +5466,7 @@ dependencies = [ [[package]] name = "typed-bytes" version = "0.1.0" -source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#8de67ffd1798220a92cc9d72e83529141248d0a2" +source = "git+https://github.com/input-output-hk/chain-libs.git?branch=master#c9fba3e1c1c5df4d486c856fddaf2f2da686bfe3" [[package]] name = "typenum" diff --git a/jcli/src/jcli_lib/transaction/staging.rs b/jcli/src/jcli_lib/transaction/staging.rs index 609a2a8bc9..1712b70c31 100644 --- a/jcli/src/jcli_lib/transaction/staging.rs +++ b/jcli/src/jcli_lib/transaction/staging.rs @@ -375,22 +375,9 @@ impl Staging { } match &self.extra { - None => match &self.evm_transaction { - None => self.finalize_payload( - &chain::transaction::NoExtra, - fee_algorithm, - output_policy, - ), - Some(_tx) => { - #[cfg(feature = "evm")] - { - let _tx: chain::evm::EvmTransaction = _tx.clone().into(); - self.finalize_payload(&_tx, fee_algorithm, output_policy) - } - #[cfg(not(feature = "evm"))] - unreachable!() - } - }, + None => { + self.finalize_payload(&chain::transaction::NoExtra, fee_algorithm, output_policy) + } Some(c) => match c.clone().into() { Certificate::PoolRegistration(c) => { self.finalize_payload(&c, fee_algorithm, output_policy) @@ -522,14 +509,9 @@ impl Staging { return Err(Error::TxNeedPayloadAuth); } match &self.extra { - None => match &self.evm_transaction { - None => self.make_fragment( - &chain::transaction::NoExtra, - &(), - Fragment::Transaction, - ), - Some(tx) => self.make_fragment(&tx.clone().into(), &(), Fragment::Evm), - }, + None => { + self.make_fragment(&chain::transaction::NoExtra, &(), Fragment::Transaction) + } Some(cert) => match cert.clone().into() { Certificate::OwnerStakeDelegation(osd) => { self.make_fragment(&osd, &(), Fragment::OwnerStakeDelegation) @@ -608,18 +590,7 @@ impl Staging { } let res = match &self.extra { - None => match &self.evm_transaction { - None => self.transaction_sign_data_hash_on(TxBuilder::new().set_nopayload()), - Some(_tx) => { - #[cfg(feature = "evm")] - { - let _tx: chain::evm::EvmTransaction = _tx.clone().into(); - self.transaction_sign_data_hash_on(TxBuilder::new().set_payload(&_tx)) - } - #[cfg(not(feature = "evm"))] - unreachable!() - } - }, + None => self.transaction_sign_data_hash_on(TxBuilder::new().set_nopayload()), Some(c) => match c.clone().into() { Certificate::PoolRegistration(c) => { self.transaction_sign_data_hash_on(TxBuilder::new().set_payload(&c)) diff --git a/jormungandr-lib/src/interfaces/evm_transaction.rs b/jormungandr-lib/src/interfaces/evm_transaction.rs index 1a0521c4b0..43fb7e56ad 100644 --- a/jormungandr-lib/src/interfaces/evm_transaction.rs +++ b/jormungandr-lib/src/interfaces/evm_transaction.rs @@ -1,13 +1,11 @@ use chain_core::{ packer::Codec, - property::{DeserializeFromSlice, ReadError}, + property::{DeserializeFromSlice, ReadError, Serialize as _}, }; use chain_impl_mockchain::evm; use serde::{Deserialize, Serialize}; use std::{fmt, str::FromStr}; use thiserror::Error; -use typed_bytes::ByteBuilder; - #[derive(Debug, Clone, PartialEq, Eq)] pub struct EvmTransaction(pub evm::EvmTransaction); @@ -36,7 +34,7 @@ impl fmt::Display for EvmTransaction { write!( f, "{}", - hex::encode(self.0.serialize_in(ByteBuilder::new()).finalize_as_vec()) + hex::encode(self.0.serialize_as_vec().map_err(|_| fmt::Error)?) ) } } @@ -56,7 +54,10 @@ impl Serialize for EvmTransaction { where S: serde::Serializer, { - let data = self.0.serialize_in(ByteBuilder::new()).finalize_as_vec(); + let data = self + .0 + .serialize_as_vec() + .map_err(|e| serde::ser::Error::custom(e.to_string()))?; if serializer.is_human_readable() { hex::encode(data).serialize(serializer) } else { diff --git a/jormungandr/src/fragment/pool.rs b/jormungandr/src/fragment/pool.rs index d7f0c77bd8..05ecdad84c 100644 --- a/jormungandr/src/fragment/pool.rs +++ b/jormungandr/src/fragment/pool.rs @@ -359,7 +359,9 @@ fn is_fragment_valid(fragment: &Fragment) -> bool { Fragment::VoteCast(ref tx) => is_transaction_valid(tx), Fragment::VoteTally(ref tx) => is_transaction_valid(tx), Fragment::MintToken(ref tx) => is_transaction_valid(tx), - Fragment::Evm(ref tx) => is_transaction_valid(tx), + // evm stuff + // TODO, maybe we need to develop some evm specific stateless validation in this place + Fragment::Evm(_) => true, Fragment::EvmMapping(ref tx) => is_transaction_valid(tx), } } @@ -372,6 +374,7 @@ fn get_transaction_expiry_date(fragment: &Fragment) -> Option { match fragment { Fragment::Initial(_) => None, Fragment::OldUtxoDeclaration(_) => None, + Fragment::Evm(_) => None, Fragment::Transaction(tx) => Some(tx.as_slice().valid_until()), Fragment::OwnerStakeDelegation(tx) => Some(tx.as_slice().valid_until()), Fragment::StakeDelegation(tx) => Some(tx.as_slice().valid_until()), @@ -384,7 +387,6 @@ fn get_transaction_expiry_date(fragment: &Fragment) -> Option { Fragment::VoteCast(tx) => Some(tx.as_slice().valid_until()), Fragment::VoteTally(tx) => Some(tx.as_slice().valid_until()), Fragment::MintToken(tx) => Some(tx.as_slice().valid_until()), - Fragment::Evm(tx) => Some(tx.as_slice().valid_until()), Fragment::EvmMapping(tx) => Some(tx.as_slice().valid_until()), } } diff --git a/jormungandr/src/jrpc/eth_types/block.rs b/jormungandr/src/jrpc/eth_types/block.rs index 8ec612b840..712f68bc00 100644 --- a/jormungandr/src/jrpc/eth_types/block.rs +++ b/jormungandr/src/jrpc/eth_types/block.rs @@ -107,9 +107,8 @@ impl Block { let mut res = Vec::new(); for (i, fragment) in block.fragments().enumerate() { if let Fragment::Evm(evm_tx) = fragment { - let evm_tx = evm_tx.as_slice().payload().into_payload(); res.push(Transaction::build( - evm_tx, + evm_tx.clone(), Some(header.hash), Some(header.number.clone()), Some((i as u64).into()), @@ -121,8 +120,8 @@ impl Block { } else { let mut res = Vec::new(); for fragment in block.fragments() { - if let Fragment::Evm(evm_tx) = fragment { - res.push(H256::from_slice(evm_tx.hash().as_ref())); + if let Fragment::Evm(_) = fragment { + res.push(H256::from_slice(fragment.hash().as_ref())); } } BlockTransactions::Hashes(res) diff --git a/jormungandr/src/jrpc/eth_types/transaction.rs b/jormungandr/src/jrpc/eth_types/transaction.rs index c96c24e303..ba7b100c92 100644 --- a/jormungandr/src/jrpc/eth_types/transaction.rs +++ b/jormungandr/src/jrpc/eth_types/transaction.rs @@ -1,6 +1,6 @@ use super::{bytes::Bytes, number::Number}; use chain_evm::ethereum_types::{H160, H256, U256}; -use chain_impl_mockchain::evm::EvmTransaction; +use chain_impl_mockchain::evm::{EvmActionType, EvmTransaction}; use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -47,22 +47,15 @@ impl Transaction { transaction_index: Option, gas_price: u64, ) -> Self { - match tx { - EvmTransaction::Call { - caller, - address, - value, - data, - gas_limit, - access_list: _, - } => Self { + match tx.action_type { + EvmActionType::Call { address, data } => Self { block_hash, block_number, - nonce: 1.into(), - from: caller, + nonce: tx.nonce.into(), + from: tx.caller, to: Some(address), - value: value.into(), - gas: gas_limit.into(), + value: tx.value.into(), + gas: tx.gas_limit.into(), input: data.into(), gas_price: gas_price.into(), chain_id: Some(1.into()), @@ -72,20 +65,14 @@ impl Transaction { s: U256::one(), transaction_type: 1.into(), }, - EvmTransaction::Create { - caller, - value, - init_code, - gas_limit, - access_list: _, - } => Self { + EvmActionType::Create { init_code } => Self { block_hash, block_number, - nonce: 1.into(), - from: caller, + nonce: tx.nonce.into(), + from: tx.caller, to: None, - value: value.into(), - gas: gas_limit.into(), + value: tx.value.into(), + gas: tx.gas_limit.into(), input: init_code.into(), gas_price: gas_price.into(), chain_id: Some(1.into()), @@ -95,21 +82,14 @@ impl Transaction { s: U256::one(), transaction_type: 1.into(), }, - EvmTransaction::Create2 { - caller, - value, - init_code, - salt: _, - gas_limit, - access_list: _, - } => Self { + EvmActionType::Create2 { init_code, salt: _ } => Self { block_hash, block_number, - nonce: 1.into(), - from: caller, + nonce: tx.nonce.into(), + from: tx.caller, to: None, - value: value.into(), - gas: gas_limit.into(), + value: tx.value.into(), + gas: tx.gas_limit.into(), input: init_code.into(), gas_price: gas_price.into(), chain_id: Some(1.into()), diff --git a/jormungandr/src/metrics/backends/prometheus_exporter.rs b/jormungandr/src/metrics/backends/prometheus_exporter.rs index 901ab77394..21bb5406ff 100644 --- a/jormungandr/src/metrics/backends/prometheus_exporter.rs +++ b/jormungandr/src/metrics/backends/prometheus_exporter.rs @@ -268,9 +268,10 @@ impl MetricsBackend for Prometheus { Fragment::MintToken(tx) => totals(tx), Fragment::UpdateProposal(tx) => totals(tx), Fragment::UpdateVote(tx) => totals(tx), - Fragment::Evm(tx) => totals(tx), Fragment::EvmMapping(tx) => totals(tx), - Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) => return Ok(()), + Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) | Fragment::Evm(_) => { + return Ok(()) + } }?; block_tx_count += 1; block_input_sum = (block_input_sum + total_input)?; diff --git a/jormungandr/src/metrics/backends/simple_counter.rs b/jormungandr/src/metrics/backends/simple_counter.rs index 65f7b4dfdf..00686a3c14 100644 --- a/jormungandr/src/metrics/backends/simple_counter.rs +++ b/jormungandr/src/metrics/backends/simple_counter.rs @@ -201,9 +201,10 @@ impl MetricsBackend for SimpleCounter { Fragment::MintToken(tx) => totals(tx), Fragment::UpdateProposal(tx) => totals(tx), Fragment::UpdateVote(tx) => totals(tx), - Fragment::Evm(tx) => totals(tx), Fragment::EvmMapping(tx) => totals(tx), - Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) => return Ok(()), + Fragment::Initial(_) | Fragment::OldUtxoDeclaration(_) | Fragment::Evm(_) => { + return Ok(()) + } }?; block_tx_count += 1; block_input_sum = (block_input_sum + total_input)?;