use hex decode instead of parse
This commit is contained in:
parent
a42d07592c
commit
8661477675
@ -14,7 +14,7 @@ pub use engine_api::{http, http::deposit_methods, http::HttpJsonRpc};
|
|||||||
use engines::{Engine, EngineError};
|
use engines::{Engine, EngineError};
|
||||||
pub use engines::{EngineState, ForkchoiceState};
|
pub use engines::{EngineState, ForkchoiceState};
|
||||||
use eth2::types::{builder_bid::SignedBuilderBid, ForkVersionedResponse};
|
use eth2::types::{builder_bid::SignedBuilderBid, ForkVersionedResponse};
|
||||||
use ethers_core::types::Transaction as EthersTransaction;
|
use ethers_core::types::{Transaction as EthersTransaction, U64};
|
||||||
use fork_choice::ForkchoiceUpdateParameters;
|
use fork_choice::ForkchoiceUpdateParameters;
|
||||||
use lru::LruCache;
|
use lru::LruCache;
|
||||||
use payload_status::process_payload_status;
|
use payload_status::process_payload_status;
|
||||||
@ -39,8 +39,10 @@ use tokio::{
|
|||||||
};
|
};
|
||||||
use tokio_stream::wrappers::WatchStream;
|
use tokio_stream::wrappers::WatchStream;
|
||||||
use types::consts::eip4844::BLOB_TX_TYPE;
|
use types::consts::eip4844::BLOB_TX_TYPE;
|
||||||
use types::transaction::{AccessTuple, BlobTransaction};
|
use types::transaction::{AccessTuple, BlobTransaction, EcdsaSignature, SignedBlobTransaction};
|
||||||
use types::{AbstractExecPayload, BeaconStateError, Blob, ExecPayload, KzgCommitment};
|
use types::{
|
||||||
|
AbstractExecPayload, BeaconStateError, Blob, ExecPayload, KzgCommitment, VersionedHash,
|
||||||
|
};
|
||||||
use types::{
|
use types::{
|
||||||
BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ForkName,
|
BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ForkName,
|
||||||
ProposerPreparationData, PublicKeyBytes, Signature, SignedBeaconBlock, Slot, Transaction,
|
ProposerPreparationData, PublicKeyBytes, Signature, SignedBeaconBlock, Slot, Transaction,
|
||||||
@ -2030,10 +2032,14 @@ pub enum BlobTxConversionError {
|
|||||||
MaxFeePerDataGasMissing,
|
MaxFeePerDataGasMissing,
|
||||||
/// Missing the `blob_versioned_hashes` field.
|
/// Missing the `blob_versioned_hashes` field.
|
||||||
BlobVersionedHashesMissing,
|
BlobVersionedHashesMissing,
|
||||||
|
/// `y_parity` field was greater than one.
|
||||||
|
InvalidYParity,
|
||||||
/// There was an error converting the transaction to SSZ.
|
/// There was an error converting the transaction to SSZ.
|
||||||
SszError(ssz_types::Error),
|
SszError(ssz_types::Error),
|
||||||
/// There was an error converting the transaction from JSON.
|
/// There was an error converting the transaction from JSON.
|
||||||
SerdeJson(serde_json::Error),
|
SerdeJson(serde_json::Error),
|
||||||
|
/// There was an error converting the transaction from hex.
|
||||||
|
FromHexError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ssz_types::Error> for BlobTxConversionError {
|
impl From<ssz_types::Error> for BlobTxConversionError {
|
||||||
@ -2096,23 +2102,36 @@ fn ethers_tx_to_bytes<T: EthSpec>(
|
|||||||
})
|
})
|
||||||
.collect::<Result<Vec<AccessTuple>, BlobTxConversionError>>()?,
|
.collect::<Result<Vec<AccessTuple>, BlobTxConversionError>>()?,
|
||||||
)?;
|
)?;
|
||||||
let max_fee_per_data_gas = transaction
|
let max_fee_per_data_gas = Uint256::from_big_endian(
|
||||||
|
ð2_serde_utils::hex::decode(
|
||||||
|
transaction
|
||||||
|
.other
|
||||||
|
.get("maxFeePerDataGas")
|
||||||
|
.ok_or(BlobTxConversionError::MaxFeePerDataGasMissing)?
|
||||||
|
.as_str()
|
||||||
|
.ok_or(BlobTxConversionError::MaxFeePerDataGasMissing)?,
|
||||||
|
)
|
||||||
|
.map_err(BlobTxConversionError::FromHexError)?,
|
||||||
|
);
|
||||||
|
let blob_versioned_hashes = transaction
|
||||||
.other
|
.other
|
||||||
.get("maxFeePerDataGas")
|
.get("blobVersionedHashes")
|
||||||
.ok_or(BlobTxConversionError::MaxFeePerDataGasMissing)?
|
.ok_or(BlobTxConversionError::BlobVersionedHashesMissing)?
|
||||||
.as_str()
|
.as_array()
|
||||||
.ok_or(BlobTxConversionError::MaxFeePerDataGasMissing)?
|
.ok_or(BlobTxConversionError::BlobVersionedHashesMissing)?
|
||||||
.parse()
|
.into_iter()
|
||||||
.map_err(|_| BlobTxConversionError::MaxFeePerDataGasMissing)?;
|
.map(|versioned_hash| {
|
||||||
let blob_versioned_hashes = serde_json::from_str(
|
Ok(Hash256::from_slice(
|
||||||
transaction
|
ð2_serde_utils::hex::decode(
|
||||||
.other
|
versioned_hash
|
||||||
.get("blobVersionedHashes")
|
.as_str()
|
||||||
.ok_or(BlobTxConversionError::BlobVersionedHashesMissing)?
|
.ok_or(BlobTxConversionError::BlobVersionedHashesMissing)?,
|
||||||
.as_str()
|
)
|
||||||
.ok_or(BlobTxConversionError::BlobVersionedHashesMissing)?,
|
.map_err(BlobTxConversionError::FromHexError)?,
|
||||||
)?;
|
))
|
||||||
BlobTransaction {
|
})
|
||||||
|
.collect::<Result<Vec<VersionedHash>, BlobTxConversionError>>()?;
|
||||||
|
let message = BlobTransaction {
|
||||||
chain_id,
|
chain_id,
|
||||||
nonce,
|
nonce,
|
||||||
max_priority_fee_per_gas,
|
max_priority_fee_per_gas,
|
||||||
@ -2123,9 +2142,23 @@ fn ethers_tx_to_bytes<T: EthSpec>(
|
|||||||
data,
|
data,
|
||||||
access_list,
|
access_list,
|
||||||
max_fee_per_data_gas,
|
max_fee_per_data_gas,
|
||||||
blob_versioned_hashes,
|
blob_versioned_hashes: VariableList::new(blob_versioned_hashes)?,
|
||||||
}
|
};
|
||||||
.as_ssz_bytes()
|
|
||||||
|
let y_parity = if transaction.v == U64::zero() {
|
||||||
|
false
|
||||||
|
} else if transaction.v == U64::one() {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
return Err(BlobTxConversionError::InvalidYParity);
|
||||||
|
};
|
||||||
|
let r = transaction.r;
|
||||||
|
let s = transaction.s;
|
||||||
|
let signature = EcdsaSignature { y_parity, r, s };
|
||||||
|
|
||||||
|
let mut signed_tx = SignedBlobTransaction { message, signature }.as_ssz_bytes();
|
||||||
|
signed_tx.insert(0, BLOB_TX_TYPE);
|
||||||
|
signed_tx
|
||||||
} else {
|
} else {
|
||||||
transaction.rlp().to_vec()
|
transaction.rlp().to_vec()
|
||||||
};
|
};
|
||||||
|
@ -9,6 +9,12 @@ pub type MaxAccessListSize = U16777216;
|
|||||||
pub type MaxVersionedHashesListSize = U16777216;
|
pub type MaxVersionedHashesListSize = U16777216;
|
||||||
pub type MaxAccessListStorageKeys = U16777216;
|
pub type MaxAccessListStorageKeys = U16777216;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||||
|
pub struct SignedBlobTransaction {
|
||||||
|
pub message: BlobTransaction,
|
||||||
|
pub signature: EcdsaSignature,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||||
pub struct BlobTransaction {
|
pub struct BlobTransaction {
|
||||||
pub chain_id: Uint256,
|
pub chain_id: Uint256,
|
||||||
@ -29,3 +35,10 @@ pub struct AccessTuple {
|
|||||||
pub address: Address,
|
pub address: Address,
|
||||||
pub storage_keys: VariableList<Hash256, MaxAccessListStorageKeys>,
|
pub storage_keys: VariableList<Hash256, MaxAccessListStorageKeys>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||||
|
pub struct EcdsaSignature {
|
||||||
|
pub y_parity: bool,
|
||||||
|
pub r: Uint256,
|
||||||
|
pub s: Uint256,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user