Skip to content

Commit

Permalink
Building using the latest telos-reth v1.1 rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
poplexity committed Dec 31, 2024
1 parent 2dc6b14 commit b4e5890
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 853 deletions.
1,505 changes: 756 additions & 749 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ license = "MIT OR Apache-2.0"

[workspace.dependencies]
telos-translator-rs = { path = "./translator" }
reth-primitives = { git = "https://github.com/telosnetwork/telos-reth", branch = "telos-main" }
reth-trie-common = { git = "https://github.com/telosnetwork/telos-reth.git", branch = "telos-main" }
reth-telos-rpc-engine-api = { git = "https://github.com/telosnetwork/telos-reth.git", branch = "telos-main" }
reth-primitives = { git = "https://github.com/telosnetwork/telos-reth", branch = "telos-main-v1.1" }
reth-trie-common = { git = "https://github.com/telosnetwork/telos-reth.git", branch = "telos-main-v1.1" }
reth-telos-rpc-engine-api = { git = "https://github.com/telosnetwork/telos-reth.git", branch = "telos-main-v1.1" }
#reth-trie-common = { path = "../telos-reth/crates/trie/common" }
#reth-telos-rpc-engine-api = { path = "../telos-reth/crates/telos/rpc-engine-api" }
#reth-primitives = { path = "../telos-reth/crates/primitives" }
alloy = "0.3.0"
alloy-rlp = "0.3.0"
alloy-rpc-types = "0.3.0"
alloy-rpc-types-engine = "0.3.0"
alloy-eips = "0.3.0"
alloy-consensus = "0.3.0"
alloy-primitives = { version = "0.8.11", default-features = false }
alloy-rlp = { version = "0.3.10", default-features = false }
alloy-rpc-types = { version = "0.7.3", features = [
"eth",
], default-features = false }
alloy-rpc-types-engine = { version = "0.7.3", features = ["serde"], default-features = false }
alloy-eips = { version = "0.7.3", default-features = false }
alloy-consensus = { version = "0.7.3", default-features = false }
alloy-trie = { version = "0.7", default-features = false }
antelope-client = { git = "https://github.com/telosnetwork/antelope-rs.git", branch = "master" }
bytes = "1.7.1"
clap = { version = "4.5.6", features = ["derive"] }
Expand Down
11 changes: 1 addition & 10 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ edition = "2021"

[dependencies]
telos-translator-rs = { workspace = true }
reth-primitives = { workspace = true }
alloy = { workspace = true }
alloy-rlp = { workspace = true }
alloy-primitives = { workspace = true }
alloy-rpc-types-engine = { workspace = true }
alloy-rpc-types = { workspace = true }
alloy-consensus = { workspace = true }
antelope-client = { workspace = true }
bytes = { workspace = true }
clap = { workspace = true }
serde = { workspace = true }
eyre = { workspace = true }
Expand All @@ -22,15 +18,10 @@ toml = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
hex = { workspace = true }
futures = "0.3.30"
csv = "1.3.0"
rocksdb = "0.22.0"
chrono = "0.4.33"
reqwest = { version = "0.11.23", features = ["json"] }
rand = "0.8.5"
zeroize = "1.7.0"
jsonwebtoken = "9.2.0"
base64 = "0.22.1"
thiserror = "1.0.62"
tokio-retry = "0.3.0"

Expand Down
19 changes: 9 additions & 10 deletions client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloy_primitives::B256;
use crate::client::Error::ForkChoiceUpdated;
use crate::config::{AppConfig, CliArgs};
use crate::data::{self, Database, Lib};
Expand All @@ -6,8 +7,6 @@ use crate::json_rpc::JsonResponseBody;
use alloy_rpc_types::Block;
use alloy_rpc_types_engine::{ForkchoiceState, ForkchoiceUpdated};
use eyre::{Context, Result};
use reth_primitives::revm_primitives::bitvec::macros::internal::funty::Fundamental;
use reth_primitives::B256;
use serde_json::json;
use telos_translator_rs::block::TelosEVMBlock;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -106,7 +105,7 @@ impl ConsensusClient {
fn latest_evm_block(&self) -> Option<(u32, String)> {
let latest = self.latest_finalized_executor_block.as_ref()?;
let (number, hash) = (latest.header.number, latest.header.hash);
Some((number.as_u32(), hash.to_string()))
Some((number as u32, hash.to_string()))
}

pub fn is_in_start_stop_range(&self, block: u32) -> bool {
Expand All @@ -116,28 +115,28 @@ impl ConsensusClient {
}
}

pub fn is_in_check_range(&self, block: u64) -> bool {
pub fn is_in_check_range(&self, block: u32) -> bool {
match (
&self.latest_finalized_executor_block,
&self.latest_executor_block,
) {
(None, None) => false,
(None, Some(latest)) => block < latest.header.number,
(None, Some(latest)) => block < latest.header.number as u32,
(Some(_), None) => unreachable!(),
(Some(valid), Some(latest)) => {
valid.header.number <= block && block <= latest.header.number
valid.header.number as u32 <= block && block <= latest.header.number as u32
}
}
}

pub fn latest_evm_number(&self) -> Option<u32> {
pub fn latest_evm_number(&self) -> Option<u64> {
self.latest_finalized_executor_block
.as_ref()
.map(|block| block.header.number.as_u32())
.map(|block| block.header.number)
}

pub fn sync_range(&self) -> Option<u32> {
self.latest_evm_number()?
(self.latest_evm_number()? as u32)
.checked_sub(self.config.evm_start_block)
}

Expand Down Expand Up @@ -199,7 +198,7 @@ impl ConsensusClient {

let block_hash = block.block_hash;

if self.is_in_check_range(block_num.as_u64()) {
if self.is_in_check_range(block_num) {
debug!("Checking if block {block_num} exists...");
let evm_block = self
.execution_api
Expand Down
2 changes: 1 addition & 1 deletion client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct AppConfig {
pub latest_blocks_in_db_num: u32,

/// Number of retry attempts
pub max_retry: Option<u8>,
pub max_retry: Option<usize>,

/// Delay between retries
pub retry_interval: Option<u64>,
Expand Down
3 changes: 1 addition & 2 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::fs;

use clap::Parser;
use eyre::{Context, Result};
use reth_primitives::revm_primitives::bitvec::macros::internal::funty::Fundamental;
use telos_consensus_client::{
config::{AppConfig, CliArgs},
main_utils::{parse_log_level, run_client},
Expand All @@ -26,7 +25,7 @@ async fn main() -> Result<()> {
.init();

let retry_interval = config.retry_interval.unwrap_or(8000u64);
let max_retries = config.max_retry.unwrap_or(8u8).as_usize();
let max_retries = config.max_retry.unwrap_or(8usize);
let retry_strategy = FixedInterval::from_millis(retry_interval).take(max_retries);

if let Err(error) =
Expand Down
2 changes: 1 addition & 1 deletion client/src/main_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn build_consensus_client(
.as_ref()
.map(|lib| lib.number + client.config.chain_id.block_delta())
.zip(client.latest_evm_number())
.map(|(lib, latest)| cmp::min(lib, latest));
.map(|(lib, latest)| cmp::min(lib, latest as u32));

let last_checked = match latest_number {
Some(latest_number) => client.db.get_block_or_prev(latest_number)?,
Expand Down
12 changes: 3 additions & 9 deletions translator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
alloy-consensus.workspace = true
alloy-primitives.workspace = true
alloy-trie.workspace = true
reth-primitives = { workspace = true }
alloy = { workspace = true }
alloy-rlp = { workspace = true }
alloy-rpc-types-engine = { workspace = true }
alloy-eips = { workspace = true }
alloy-consensus = { workspace = true }
antelope-client = { workspace = true }
bytes = { workspace = true }
clap = { workspace = true }
Expand All @@ -26,18 +27,11 @@ hex = { workspace = true }
reth-trie-common = { workspace = true }
reth-telos-rpc-engine-api = { workspace = true }
num-bigint = "0.4.5"
dashmap = "5.5.3"
k256 = { version = "0.13.3", features = ["ecdsa"] }
moka = { version = "0.12.7", features = ["sync"] }
tokio-tungstenite = "0.23.0"
futures-util = "0.3.30"
ruint = "0.3.0"
rlp = "0.5.2"
lazy_static = "1.5.0"


#alloy = { version = "0.2.1", features = ["k256"] }

[dev-dependencies]
testcontainers = { workspace = true }

Expand Down
22 changes: 12 additions & 10 deletions translator/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::types::ship_types::{
ActionTrace, ContractRow, GetBlocksResultV0, SignedBlock, TableDelta, TransactionTrace,
};
use crate::types::translator_types::{ChainId, NameToAddressCache};
use alloy::primitives::{Bloom, Bytes, FixedBytes, B256, U256};
use alloy_primitives::{Bloom, Bytes, FixedBytes, B256, U256};
use alloy_consensus::constants::{EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};
use alloy_consensus::{Header, Transaction, TxEnvelope};
use alloy_eips::eip2718::Encodable2718;
Expand All @@ -21,12 +21,13 @@ use antelope::serializer::Packer;
use eyre::eyre;
use reth_primitives::ReceiptWithBloom;
use reth_telos_rpc_engine_api::structs::TelosEngineAPIExtraFields;
use reth_trie_common::root::ordered_trie_root_with_encoder;
use alloy_trie::root::ordered_trie_root_with_encoder;
use std::cmp::{max, Ordering};
use std::collections::HashMap;
use alloy_consensus::transaction::RlpEcdsaTx;
use tracing::{debug, warn};

const MINIMUM_FEE_PER_GAS: u128 = 7;
const MINIMUM_FEE_PER_GAS: u64 = 7;

pub trait BasicTrace {
fn action_name(&self) -> u64;
Expand Down Expand Up @@ -97,7 +98,7 @@ pub struct ProcessingEVMBlock {
block_traces: Option<Vec<TransactionTrace>>,
contract_rows: Option<Vec<(bool, ContractRow)>>,
cumulative_gas_used: u64,
dyn_gas_limit: Option<u128>,
dyn_gas_limit: Option<u64>,
pub decoded_rows: Vec<DecodedRow>,
pub transactions: Vec<(TelosEVMTransaction, ReceiptWithBloom)>,
pub new_gas_price: Option<(u64, U256)>,
Expand Down Expand Up @@ -246,8 +247,8 @@ impl ProcessingEVMBlock {

fn add_transaction(&mut self, transaction: TelosEVMTransaction) {
let full_receipt = transaction.receipt(self.cumulative_gas_used);
let gas_limit = transaction.envelope.gas_limit() + self.cumulative_gas_used as u128;
self.cumulative_gas_used = full_receipt.receipt.cumulative_gas_used;
let gas_limit = transaction.envelope.gas_limit() + self.cumulative_gas_used;
self.cumulative_gas_used = full_receipt.receipt.cumulative_gas_used as u64;
self.transactions.push((transaction, full_receipt));

if self.dyn_gas_limit.is_none() {
Expand Down Expand Up @@ -470,7 +471,7 @@ impl ProcessingEVMBlock {

if envelope.is_eip1559() {
let stx = envelope.as_eip1559().unwrap();
stx.tx().encode_with_signature_fields(stx.signature(), buf);
stx.tx().rlp_encode_signed(stx.signature(), buf);
} else {
panic!("unimplemented tx type");
}
Expand All @@ -481,7 +482,7 @@ impl ProcessingEVMBlock {
ordered_trie_root_with_encoder(&self.transactions, |(_trx, r), buf| r.encode(buf));
let mut logs_bloom = Bloom::default();
for (_trx, receipt) in &self.transactions {
logs_bloom.accrue_bloom(&receipt.bloom);
logs_bloom.accrue_bloom(&receipt.logs_bloom);
}

let gas_limit = if let Some(dyn_gas) = self.dyn_gas_limit {
Expand All @@ -503,7 +504,7 @@ impl ProcessingEVMBlock {
difficulty: Default::default(),
number: (self.block_num - block_delta) as u64,
gas_limit,
gas_used: self.cumulative_gas_used as u128,
gas_used: self.cumulative_gas_used,
timestamp: (((self.signed_block.clone().unwrap().header.header.timestamp as u64)
* ANTELOPE_INTERVAL_MS)
+ ANTELOPE_EPOCH_MS)
Expand All @@ -514,8 +515,9 @@ impl ProcessingEVMBlock {
blob_gas_used: None,
excess_blob_gas: None,
parent_beacon_block_root: None,
requests_root: None,
requests_hash: None,
extra_data: Bytes::from(self.block_hash.data),
target_blobs_per_block: None,
};

let base_fee_per_gas = U256::from(
Expand Down
2 changes: 1 addition & 1 deletion translator/src/injection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy::primitives::{Address, Bytes, U256};
use alloy_primitives::{Address, Bytes, U256};
use antelope::api::client::{APIClient, DefaultProvider};
use antelope::api::v1::structs::{GetTableRowsParams, TableIndexType};
use antelope::chain::checksum::{Checksum160, Checksum256};
Expand Down
46 changes: 25 additions & 21 deletions translator/src/rlp/telos_rlp_decode.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use alloy::primitives::private::alloy_rlp::{Decodable, Error, Header};
use alloy::primitives::{Bytes, Parity, Signature, TxKind, U256};
use alloy_primitives::private::alloy_rlp::{Decodable, Error, Header};
use alloy_primitives::{normalize_v, Bytes, Parity, PrimitiveSignature, Signature, TxKind, U256};
use alloy_consensus::{SignableTransaction, Signed, TxLegacy};

use alloy_consensus::transaction::from_eip155_value;
use alloy_rlp::Result;
use bytes::Buf;
use tracing::error;

fn decode_fields(data: &mut &[u8]) -> Result<TxLegacy, Error> {
let nonce = u64::decode(data).map_err(|_| Error::Custom("Failed to decode nonce"))?;
let gas_price = u128::decode(data).map_err(|_| Error::Custom("Failed to decode gas price"))?;
let gas_limit = u128::decode(data).map_err(|_| Error::Custom("Failed to decode gas limit"))?;
let gas_limit = u64::decode(data).map_err(|_| Error::Custom("Failed to decode gas limit"))?;
let to = TxKind::decode(data).map_err(|_| Error::Custom("Failed to decode to"))?;
let value = decode_telos_u256(data).map_err(|_| Error::Custom("Failed to decode value"))?;
let input = Bytes::decode(data).map_err(|_| Error::Custom("Failed to decode input"))?;
Expand All @@ -28,17 +28,17 @@ fn decode_fields(data: &mut &[u8]) -> Result<TxLegacy, Error> {
pub trait TelosTxDecodable {
fn decode_telos_signed_fields(
buf: &mut &[u8],
sig: Option<Signature>,
) -> Result<Signed<Self>, Error>
sig: Option<PrimitiveSignature>,
) -> Result<(Self, PrimitiveSignature)>
where
Self: Sized;
}

impl TelosTxDecodable for TxLegacy {
fn decode_telos_signed_fields(
buf: &mut &[u8],
provided_sig: Option<Signature>,
) -> Result<Signed<Self>, Error> {
provided_sig: Option<PrimitiveSignature>,
) -> Result<(Self, PrimitiveSignature)> {
let header = Header::decode(buf)?;
if !header.list {
return Err(Error::Custom("Not a list."));
Expand All @@ -62,11 +62,16 @@ impl TelosTxDecodable for TxLegacy {
} else if buf[0] == 0 {
buf.advance(buf.len());
} else {
let decoded_signature = Signature::decode_rlp_vrs(buf)?;
let v = decoded_signature.v();
let mut decoded_v: u128 = 0;
let decoded_signature = PrimitiveSignature::decode_rlp_vrs(buf, |buf| {
let decoded_v = Decodable::decode(buf)?;
let (parity, _chain_id) =
from_eip155_value(decoded_v).ok_or(Error::Custom("invalid parity value"))?;
Ok(parity)
})?;
let r = decoded_signature.r();
let s = decoded_signature.s();
if v.to_u64() != 0 || r != U256::ZERO || s != U256::ZERO {
if decoded_v != 0 || r != U256::ZERO || s != U256::ZERO {
return Err(Error::Custom(
"Unsigned Telos Native trx with signature data",
));
Expand All @@ -79,24 +84,23 @@ impl TelosTxDecodable for TxLegacy {
if buf.is_empty() {
return Err(Error::Custom("Trx without signature"));
}

let parity: Parity = Decodable::decode(buf)?;
let v: u128 = Decodable::decode(buf)?;
let (parity, chain_id) =
from_eip155_value(v).ok_or(Error::Custom("invalid parity value"))?;

let r = decode_telos_u256(buf)?;
let s = decode_telos_u256(buf)?;

Signature::from_rs_and_parity(r, s, parity)
.map_err(|_| Error::Custom("attempted to decode invalid field element"))?
tx.chain_id = chain_id;
PrimitiveSignature::new(r, s, parity)
}
};

tx.chain_id = sig.v().chain_id();

let signed = tx.into_signed(sig);
// let signed = tx.into_signed(sig);
if buf.len() + header.payload_length == original_len || buf.iter().all(|&b| b == 128) {
return Ok(signed);
return Ok((tx, sig));
}

error!("Transaction has trailing non-zero RLP values: {:?}", signed);
error!("Transaction has trailing non-zero RLP values, tx: {:?} sig: {:?}", tx, sig);
Err(Error::ListLengthMismatch {
expected: header.payload_length,
got: original_len - buf.len(),
Expand Down
4 changes: 2 additions & 2 deletions translator/src/tasks/final_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use crate::{
block::ProcessingEVMBlock, translator::TranslatorConfig,
types::translator_types::NameToAddressCache,
};
use alloy::primitives::{Address, Bytes, FixedBytes, U256};
use alloy_primitives::{Address, Bytes, FixedBytes, U256};
use alloy_rlp::Encodable;
use antelope::api::client::{APIClient, DefaultProvider};
use eyre::{eyre, Context, Result};
use hex::encode;
use reth_primitives::B256;
use alloy_primitives::B256;
use reth_telos_rpc_engine_api::structs::{
TelosAccountStateTableRow, TelosAccountTableRow, TelosEngineAPIExtraFields,
};
Expand Down
Loading

0 comments on commit b4e5890

Please sign in to comment.