Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eth-sender): Make eth-sender tests use blob txs + refactor of eth-sender tests #2316

Merged
merged 9 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,55 @@ impl EthSenderDal<'_, '_> {
Ok(txs.into_iter().map(|tx| tx.into()).collect())
}

pub async fn get_eth_txs_history_entries_max_id(&mut self) -> usize {
tomg10 marked this conversation as resolved.
Show resolved Hide resolved
sqlx::query!(
r#"
SELECT
MAX(id)
FROM
eth_txs_history
"#
)
.fetch_one(self.storage.conn())
.await
.unwrap()
.max
.unwrap()
.try_into()
.unwrap()
}

pub async fn get_last_sent_eth_tx_hash(
&mut self,
l1_batch_number: L1BatchNumber,
op_type: AggregatedActionType,
) -> Option<TxHistory> {
let row = sqlx::query!(
r#"
SELECT
eth_commit_tx_id,
eth_prove_tx_id,
eth_execute_tx_id
FROM
l1_batches
WHERE
number = $1
"#,
i64::from(l1_batch_number.0)
)
.fetch_optional(self.storage.conn())
.await
.unwrap()
.unwrap();
let eth_tx_id = match op_type {
AggregatedActionType::Commit => row.eth_commit_tx_id,
AggregatedActionType::PublishProofOnchain => row.eth_prove_tx_id,
AggregatedActionType::Execute => row.eth_execute_tx_id,
}
.unwrap() as u32;
self.get_last_sent_eth_tx(eth_tx_id).await.unwrap()
}

pub async fn get_eth_l1_batches(&mut self) -> sqlx::Result<L1BatchEthSenderStats> {
struct EthTxRow {
number: i64,
Expand Down
19 changes: 16 additions & 3 deletions core/lib/eth_client/src/clients/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jsonrpsee::{core::ClientError, types::ErrorObject};
use zksync_types::{
ethabi,
web3::{self, contract::Tokenize, BlockId},
Address, L1ChainId, H160, H256, U256, U64,
Address, L1ChainId, EIP_4844_TX_TYPE, H160, H256, U256, U64,
};
use zksync_web3_decl::client::{DynClient, MockClient, L1};

Expand All @@ -28,7 +28,15 @@ struct MockTx {
}

impl From<Vec<u8>> for MockTx {
fn from(tx: Vec<u8>) -> Self {
fn from(raw_tx: Vec<u8>) -> Self {
let is_eip4844 = raw_tx[0] == EIP_4844_TX_TYPE;
let tx: Vec<u8> = if is_eip4844 {
// decoding rlp-encoded length
let len = raw_tx[2] as usize * 256 + raw_tx[3] as usize - 2;
tomg10 marked this conversation as resolved.
Show resolved Hide resolved
raw_tx[3..3 + len].to_vec()
} else {
raw_tx
};
let len = tx.len();
let recipient = Address::from_slice(&tx[len - 116..len - 96]);
let max_fee_per_gas = U256::from(&tx[len - 96..len - 64]);
Expand All @@ -37,6 +45,9 @@ impl From<Vec<u8>> for MockTx {
let hash = {
let mut buffer = [0_u8; 32];
buffer.copy_from_slice(&tx[..32]);
if is_eip4844 {
buffer[0] = 0x00;
}
buffer.into()
};

Expand Down Expand Up @@ -94,11 +105,12 @@ impl MockEthereumInner {
self.block_number += confirmations;
let nonce = self.current_nonce;
self.current_nonce += 1;
tracing::info!("Executing tx with hash {tx_hash:?}, success: {success}, current nonce: {}, confirmations: {confirmations}", self.current_nonce);
let tx_nonce = self.sent_txs[&tx_hash].nonce;

if non_ordering_confirmations {
if tx_nonce >= nonce {
self.current_nonce = tx_nonce;
self.current_nonce = tx_nonce + 1;
}
} else {
assert_eq!(tx_nonce, nonce, "nonce mismatch");
Expand Down Expand Up @@ -140,6 +152,7 @@ impl MockEthereumInner {
fn send_raw_transaction(&mut self, tx: web3::Bytes) -> Result<H256, ClientError> {
let mock_tx = MockTx::from(tx.0);
let mock_tx_hash = mock_tx.hash;
tracing::info!("Sending tx with hash {mock_tx_hash:?}");

if mock_tx.nonce < self.current_nonce {
let err = ErrorObject::owned(
Expand Down
1 change: 1 addition & 0 deletions core/node/consistency_checker/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub(crate) fn create_pre_boojum_l1_batch_with_metadata(number: u32) -> L1BatchWi
raw_published_factory_deps: vec![],
};
l1_batch.header.protocol_version = Some(PRE_BOOJUM_PROTOCOL_VERSION);
l1_batch.header.l2_to_l1_logs = vec![];
l1_batch.metadata.bootloader_initial_content_commitment = None;
l1_batch.metadata.events_queue_commitment = None;
l1_batch
Expand Down
1 change: 1 addition & 0 deletions core/node/eth_sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ test-casing.workspace = true
zksync_node_test_utils.workspace = true
once_cell.workspace = true
assert_matches.workspace = true
test-log.workspace = true
28 changes: 24 additions & 4 deletions core/node/eth_sender/src/abstract_l1_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ pub(super) trait AbstractL1Interface: 'static + Sync + Send + fmt::Debug {
async fn get_tx_status(
&self,
tx_hash: H256,
operator_type: OperatorType,
) -> Result<Option<ExecutedTxStatus>, EthSenderError>;

async fn send_raw_tx(&self, tx_bytes: RawTransactionBytes) -> EnrichedClientResult<H256>;
async fn send_raw_tx(
tomg10 marked this conversation as resolved.
Show resolved Hide resolved
&self,
tx_bytes: RawTransactionBytes,
operator_type: OperatorType,
) -> EnrichedClientResult<H256>;

fn get_blobs_operator_account(&self) -> Option<Address>;

Expand Down Expand Up @@ -89,6 +94,14 @@ impl RealL1Interface {
pub(crate) fn query_client(&self) -> &DynClient<L1> {
self.ethereum_gateway().as_ref()
}

pub(crate) fn query_client_for_operator(&self, operator_type: OperatorType) -> &DynClient<L1> {
if operator_type == OperatorType::Blob {
self.ethereum_gateway_blobs().unwrap().as_ref()
} else {
self.ethereum_gateway().as_ref()
}
}
}
#[async_trait]
impl AbstractL1Interface for RealL1Interface {
Expand All @@ -106,15 +119,22 @@ impl AbstractL1Interface for RealL1Interface {
async fn get_tx_status(
&self,
tx_hash: H256,
operator_type: OperatorType,
) -> Result<Option<ExecutedTxStatus>, EthSenderError> {
self.query_client()
self.query_client_for_operator(operator_type)
.get_tx_status(tx_hash)
.await
.map_err(Into::into)
}

async fn send_raw_tx(&self, tx_bytes: RawTransactionBytes) -> EnrichedClientResult<H256> {
self.query_client().send_raw_tx(tx_bytes).await
async fn send_raw_tx(
&self,
tx_bytes: RawTransactionBytes,
operator_type: OperatorType,
) -> EnrichedClientResult<H256> {
self.query_client_for_operator(operator_type)
.send_raw_tx(tx_bytes)
.await
}

fn get_blobs_operator_account(&self) -> Option<Address> {
Expand Down
2 changes: 1 addition & 1 deletion core/node/eth_sender/src/eth_fees_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl GasAdjusterFeesOracle {
base_fee_to_use: u64,
) -> Result<(), EthSenderError> {
let next_block_minimal_base_fee = self.gas_adjuster.get_next_block_minimal_base_fee();
if base_fee_to_use <= min(next_block_minimal_base_fee, previous_base_fee) {
if base_fee_to_use < min(next_block_minimal_base_fee, previous_base_fee) {
// If the base fee is lower than the previous used one
// or is lower than the minimal possible value for the next block, sending is skipped.
tracing::info!(
Expand Down
Loading
Loading