blob decoding
This commit is contained in:
parent
6d2dff66a0
commit
d9e83e6cec
@ -49,6 +49,7 @@ pub enum Error {
|
||||
UnsupportedForkVariant(String),
|
||||
BadConversion(String),
|
||||
RlpDecoderError(rlp::DecoderError),
|
||||
BlobTxConversionError,
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for Error {
|
||||
|
@ -22,12 +22,14 @@ use serde::{Deserialize, Serialize};
|
||||
use slog::{crit, debug, error, info, trace, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::collections::HashMap;
|
||||
use std::default::default;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
use ethers_core::types::transaction::eip2930::AccessListItem;
|
||||
use strum::AsRefStr;
|
||||
use task_executor::TaskExecutor;
|
||||
use tokio::{
|
||||
@ -35,6 +37,8 @@ use tokio::{
|
||||
time::sleep,
|
||||
};
|
||||
use tokio_stream::wrappers::WatchStream;
|
||||
use types::consts::eip4844::BLOB_TX_TYPE;
|
||||
use types::transaction::{AccessTuple, BlobTransaction};
|
||||
use types::{AbstractExecPayload, BeaconStateError, Blob, ExecPayload, KzgCommitment};
|
||||
use types::{
|
||||
BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ForkName,
|
||||
@ -1616,7 +1620,59 @@ impl<T: EthSpec> ExecutionLayer<T> {
|
||||
block
|
||||
.transactions()
|
||||
.iter()
|
||||
.map(|transaction| VariableList::new(transaction.rlp().to_vec()))
|
||||
.map(|transaction: Transaction| {
|
||||
let tx_type = transaction
|
||||
.transaction_type
|
||||
.ok_or(ApiError::BlobTxConversionError)?.as_u64();
|
||||
let tx = if BLOB_TX_TYPE as u64 == tx_type {
|
||||
let chain_id = transaction
|
||||
.chain_id
|
||||
.ok_or(ApiError::BlobTxConversionError)?;
|
||||
let nonce = transaction.nonce.as_u64();
|
||||
let max_priority_fee_per_gas = transaction
|
||||
.max_priority_fee_per_gas
|
||||
.ok_or(ApiError::BlobTxConversionError)?;
|
||||
let max_fee_per_gas = transaction
|
||||
.max_fee_per_gas
|
||||
.ok_or(ApiError::BlobTxConversionError)?;
|
||||
let gas = transaction.gas.as_u64();
|
||||
let to = transaction.to;
|
||||
let value = transaction.value;
|
||||
let data = VariableList::from(transaction.input.to_vec());
|
||||
let access_list = VariableList::from(transaction
|
||||
.access_list
|
||||
.ok_or(ApiError::BlobTxConversionError)?
|
||||
.0
|
||||
.into_iter().map(|access_tuple| Ok(AccessTuple {
|
||||
address: access_tuple.address,
|
||||
storage_keys: VariableList::from(
|
||||
access_tuple
|
||||
.storage_keys,
|
||||
),
|
||||
}))
|
||||
.collect::<Result<Vec<AccessTuple>, ApiError>>()?);
|
||||
let max_fee_per_data_gas = transaction.other.get("max_fee_per_data_gas").ok_or(ApiError::BlobTxConversionError)?;
|
||||
let data_str = max_fee_per_data_gas.as_str().ok_or(ApiError::BlobTxConversionError)?;
|
||||
let blob_versioned_hashes = transaction.other.get("blob_versioned_hashes").ok_or(ApiError::BlobTxConversionError)?;
|
||||
Ok(BlobTransaction {
|
||||
chain_id,
|
||||
nonce,
|
||||
max_priority_fee_per_gas,
|
||||
max_fee_per_gas,
|
||||
gas,
|
||||
to,
|
||||
value,
|
||||
data,
|
||||
access_list,
|
||||
max_fee_per_data_gas,
|
||||
blob_versioned_hashes,
|
||||
});
|
||||
vec![]
|
||||
} else {
|
||||
transaction.rlp().to_vec()
|
||||
};
|
||||
VariableList::new(tx)
|
||||
})
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(ApiError::DeserializeTransaction)?,
|
||||
)
|
||||
|
@ -101,6 +101,7 @@ pub mod sqlite;
|
||||
|
||||
pub mod blobs_sidecar;
|
||||
pub mod signed_block_and_blobs;
|
||||
pub mod transaction;
|
||||
|
||||
use ethereum_types::{H160, H256};
|
||||
|
||||
|
38
consensus/types/src/transaction.rs
Normal file
38
consensus/types/src/transaction.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::{Hash256, Transaction, Uint256, VersionedHash};
|
||||
use ethereum_types::Address;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::typenum::U16777216;
|
||||
use ssz_types::VariableList;
|
||||
|
||||
pub type MaxCalldataSize = U16777216;
|
||||
pub type MaxAccessListSize = U16777216;
|
||||
pub type MaxVersionedHashesListSize = U16777216;
|
||||
pub type MaxAccessListStorageKeys = U16777216;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||
pub struct BlobTransaction {
|
||||
pub chain_id: Uint256,
|
||||
pub nonce: u64,
|
||||
pub max_priority_fee_per_gas: Uint256,
|
||||
pub max_fee_per_gas: Uint256,
|
||||
pub gas: u64,
|
||||
pub to: Option<Address>,
|
||||
pub value: Uint256,
|
||||
pub data: VariableList<u8, MaxCalldataSize>,
|
||||
pub access_list: VariableList<AccessTuple, MaxAccessListSize>,
|
||||
pub max_fee_per_data_gas: Uint256,
|
||||
pub blob_versioned_hashes: VariableList<VersionedHash, MaxVersionedHashesListSize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||
pub struct AccessTuple {
|
||||
pub address: Address,
|
||||
pub storage_keys: VariableList<Hash256, MaxAccessListStorageKeys>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||
pub struct EcdsaSignature {
|
||||
y_parity: bool,
|
||||
r: Uint256,
|
||||
s: Uint256,
|
||||
}
|
Loading…
Reference in New Issue
Block a user