mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Remove use of ethers core (#5301)
* Remove use of ethers_core::RlpStream
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core
* Remove old code
* Simplify keccak call
* Remove unused package
* Merge branch 'unstable' of https://github.com/ethDreamer/lighthouse into remove_use_of_ethers_core
* Merge branch 'unstable' into remove_use_of_ethers_core
* Run clippy
* Merge branch 'remove_use_of_ethers_core' of https://github.com/dospore/lighthouse into remove_use_of_ethers_core
* Check all cargo fmt
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core
* Revert lock
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core
* introduce a shim to convert between the two u256 types
* move alloy to wrokspace
* align alloy versions
* update
* update web3signer test certs
* Revert "update web3signer test certs"
This reverts commit effd5910ad.
* Consolidate alloy versions
* Delete empty file
This commit is contained in:
@@ -6,6 +6,7 @@ edition = { workspace = true }
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
alloy-primitives = { workspace = true }
|
||||
types = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
slog = { workspace = true }
|
||||
@@ -48,6 +49,6 @@ hash-db = "0.15.2"
|
||||
pretty_reqwest_error = { workspace = true }
|
||||
arc-swap = "1.6.0"
|
||||
eth2_network_config = { workspace = true }
|
||||
alloy-rlp = "0.3"
|
||||
alloy-consensus = { git = "https://github.com/alloy-rs/alloy.git", rev = "974d488bab5e21e9f17452a39a4bfa56677367b2" }
|
||||
alloy-rlp = { workspace = true }
|
||||
alloy-consensus = { workspace = true }
|
||||
lighthouse_version = { workspace = true }
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::{
|
||||
json_structures::JsonWithdrawal,
|
||||
json_structures::{EncodableJsonWithdrawal, JsonWithdrawal},
|
||||
keccak::{keccak256, KeccakHasher},
|
||||
};
|
||||
use ethers_core::utils::rlp::RlpStream;
|
||||
use alloy_rlp::Encodable;
|
||||
use keccak_hash::KECCAK_EMPTY_LIST_RLP;
|
||||
use triehash::ordered_trie_root;
|
||||
use types::{
|
||||
map_execution_block_header_fields_base, Address, EthSpec, ExecutionBlockHash,
|
||||
ExecutionBlockHeader, ExecutionPayloadRef, Hash256, Hash64, Uint256,
|
||||
EncodableExecutionBlockHeader, EthSpec, ExecutionBlockHash, ExecutionBlockHeader,
|
||||
ExecutionPayloadRef, Hash256,
|
||||
};
|
||||
|
||||
/// Calculate the block hash of an execution block.
|
||||
@@ -60,36 +60,16 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
|
||||
|
||||
/// RLP encode a withdrawal.
|
||||
pub fn rlp_encode_withdrawal(withdrawal: &JsonWithdrawal) -> Vec<u8> {
|
||||
let mut rlp_stream = RlpStream::new();
|
||||
rlp_stream.begin_list(4);
|
||||
rlp_stream.append(&withdrawal.index);
|
||||
rlp_stream.append(&withdrawal.validator_index);
|
||||
rlp_stream.append(&withdrawal.address);
|
||||
rlp_stream.append(&withdrawal.amount);
|
||||
rlp_stream.out().into()
|
||||
let mut out: Vec<u8> = vec![];
|
||||
EncodableJsonWithdrawal::from(withdrawal).encode(&mut out);
|
||||
out
|
||||
}
|
||||
|
||||
/// RLP encode an execution block header.
|
||||
pub fn rlp_encode_block_header(header: &ExecutionBlockHeader) -> Vec<u8> {
|
||||
let mut rlp_header_stream = RlpStream::new();
|
||||
rlp_header_stream.begin_unbounded_list();
|
||||
map_execution_block_header_fields_base!(&header, |_, field| {
|
||||
rlp_header_stream.append(field);
|
||||
});
|
||||
if let Some(withdrawals_root) = &header.withdrawals_root {
|
||||
rlp_header_stream.append(withdrawals_root);
|
||||
}
|
||||
if let Some(blob_gas_used) = &header.blob_gas_used {
|
||||
rlp_header_stream.append(blob_gas_used);
|
||||
}
|
||||
if let Some(excess_blob_gas) = &header.excess_blob_gas {
|
||||
rlp_header_stream.append(excess_blob_gas);
|
||||
}
|
||||
if let Some(parent_beacon_block_root) = &header.parent_beacon_block_root {
|
||||
rlp_header_stream.append(parent_beacon_block_root);
|
||||
}
|
||||
rlp_header_stream.finalize_unbounded_list();
|
||||
rlp_header_stream.out().into()
|
||||
let mut out: Vec<u8> = vec![];
|
||||
EncodableExecutionBlockHeader::from(header).encode(&mut out);
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -97,6 +77,7 @@ mod test {
|
||||
use super::*;
|
||||
use hex::FromHex;
|
||||
use std::str::FromStr;
|
||||
use types::{Address, Hash256, Hash64};
|
||||
|
||||
fn test_rlp_encoding(
|
||||
header: &ExecutionBlockHeader,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use alloy_rlp::RlpEncodable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::EnumString;
|
||||
use superstruct::superstruct;
|
||||
@@ -463,6 +464,24 @@ impl From<JsonWithdrawal> for Withdrawal {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, PartialEq, Clone, RlpEncodable)]
|
||||
pub struct EncodableJsonWithdrawal<'a> {
|
||||
pub index: u64,
|
||||
pub validator_index: u64,
|
||||
pub address: &'a [u8],
|
||||
pub amount: u64,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a JsonWithdrawal> for EncodableJsonWithdrawal<'a> {
|
||||
fn from(json_withdrawal: &'a JsonWithdrawal) -> Self {
|
||||
Self {
|
||||
index: json_withdrawal.index,
|
||||
validator_index: json_withdrawal.validator_index,
|
||||
address: json_withdrawal.address.as_bytes(),
|
||||
amount: json_withdrawal.amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(V1, V2, V3),
|
||||
|
||||
@@ -16,7 +16,7 @@ use hash_db::Hasher;
|
||||
use types::Hash256;
|
||||
|
||||
pub fn keccak256(bytes: &[u8]) -> Hash256 {
|
||||
Hash256::from(ethers_core::utils::keccak256(bytes))
|
||||
Hash256::from(alloy_primitives::utils::keccak256(bytes).as_ref())
|
||||
}
|
||||
|
||||
/// Keccak hasher.
|
||||
|
||||
@@ -42,22 +42,17 @@ pub fn extract_versioned_hashes_from_transactions<E: EthSpec>(
|
||||
let mut versioned_hashes = Vec::new();
|
||||
|
||||
for tx in transactions {
|
||||
match beacon_tx_to_tx_envelope(tx)? {
|
||||
TxEnvelope::Eip4844(signed_tx_eip4844) => {
|
||||
versioned_hashes.extend(
|
||||
signed_tx_eip4844
|
||||
.tx()
|
||||
.blob_versioned_hashes
|
||||
.iter()
|
||||
.map(|fb| Hash256::from(fb.0)),
|
||||
);
|
||||
}
|
||||
// enumerating all variants explicitly to make pattern irrefutable
|
||||
// in case new types are added in the future which also have blobs
|
||||
TxEnvelope::Legacy(_)
|
||||
| TxEnvelope::TaggedLegacy(_)
|
||||
| TxEnvelope::Eip2930(_)
|
||||
| TxEnvelope::Eip1559(_) => {}
|
||||
// TxEnvelope is non-exhaustive so unforunately we can (no longer) write an exhaustive
|
||||
// match here.
|
||||
if let TxEnvelope::Eip4844(signed_tx_eip4844) = beacon_tx_to_tx_envelope(tx)? {
|
||||
versioned_hashes.extend(
|
||||
signed_tx_eip4844
|
||||
.tx()
|
||||
.tx()
|
||||
.blob_versioned_hashes
|
||||
.iter()
|
||||
.map(|fb| Hash256::from(fb.0)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +71,8 @@ pub fn beacon_tx_to_tx_envelope<N: Unsigned>(
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::test_utils::static_valid_tx;
|
||||
use alloy_consensus::{TxKind, TxLegacy};
|
||||
use alloy_consensus::TxLegacy;
|
||||
use alloy_primitives::TxKind;
|
||||
|
||||
type E = types::MainnetEthSpec;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user