mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-13 23:21:04 +00:00
Improve the benchmarks driver
This commit is contained in:
@@ -22,6 +22,7 @@ use alloy::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{Context as _, Result, bail};
|
use anyhow::{Context as _, Result, bail};
|
||||||
|
use futures::TryFutureExt;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use revive_dt_common::{
|
use revive_dt_common::{
|
||||||
futures::{PollingWaitBehavior, poll},
|
futures::{PollingWaitBehavior, poll},
|
||||||
@@ -179,13 +180,17 @@ where
|
|||||||
TransactionRequest::default().from(deployer_address),
|
TransactionRequest::default().from(deployer_address),
|
||||||
code,
|
code,
|
||||||
);
|
);
|
||||||
let receipt = self.execute_transaction(tx).await.inspect_err(|err| {
|
let receipt = self
|
||||||
error!(
|
.execute_transaction(tx)
|
||||||
?err,
|
.and_then(|(_, receipt_fut)| receipt_fut)
|
||||||
%library_instance,
|
.await
|
||||||
"Failed to deploy the library"
|
.inspect_err(|err| {
|
||||||
)
|
error!(
|
||||||
})?;
|
?err,
|
||||||
|
%library_instance,
|
||||||
|
"Failed to deploy the library"
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
debug!(?library_instance, "Deployed library");
|
debug!(?library_instance, "Deployed library");
|
||||||
|
|
||||||
@@ -281,11 +286,11 @@ where
|
|||||||
.handle_function_call_contract_deployment(step)
|
.handle_function_call_contract_deployment(step)
|
||||||
.await
|
.await
|
||||||
.context("Failed to deploy contracts for the function call step")?;
|
.context("Failed to deploy contracts for the function call step")?;
|
||||||
let execution_receipt = self
|
let transaction_hash = self
|
||||||
.handle_function_call_execution(step, deployment_receipts)
|
.handle_function_call_execution(step, deployment_receipts)
|
||||||
.await
|
.await
|
||||||
.context("Failed to handle the function call execution")?;
|
.context("Failed to handle the function call execution")?;
|
||||||
self.handle_function_call_variable_assignment(step, execution_receipt.transaction_hash)
|
self.handle_function_call_variable_assignment(step, transaction_hash)
|
||||||
.await
|
.await
|
||||||
.context("Failed to handle function call variable assignment")?;
|
.context("Failed to handle function call variable assignment")?;
|
||||||
Ok(1)
|
Ok(1)
|
||||||
@@ -339,18 +344,19 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
step: &FunctionCallStep,
|
step: &FunctionCallStep,
|
||||||
mut deployment_receipts: HashMap<ContractInstance, TransactionReceipt>,
|
mut deployment_receipts: HashMap<ContractInstance, TransactionReceipt>,
|
||||||
) -> Result<TransactionReceipt> {
|
) -> Result<TxHash> {
|
||||||
match step.method {
|
match step.method {
|
||||||
// This step was already executed when `handle_step` was called. We just need to
|
// This step was already executed when `handle_step` was called. We just need to
|
||||||
// lookup the transaction receipt in this case and continue on.
|
// lookup the transaction receipt in this case and continue on.
|
||||||
Method::Deployer => deployment_receipts
|
Method::Deployer => deployment_receipts
|
||||||
.remove(&step.instance)
|
.remove(&step.instance)
|
||||||
.context("Failed to find deployment receipt for constructor call"),
|
.context("Failed to find deployment receipt for constructor call")
|
||||||
|
.map(|receipt| receipt.transaction_hash),
|
||||||
Method::Fallback | Method::FunctionName(_) => {
|
Method::Fallback | Method::FunctionName(_) => {
|
||||||
let tx = step
|
let tx = step
|
||||||
.as_transaction(self.resolver.as_ref(), self.default_resolution_context())
|
.as_transaction(self.resolver.as_ref(), self.default_resolution_context())
|
||||||
.await?;
|
.await?;
|
||||||
self.execute_transaction(tx).await
|
Ok(self.execute_transaction(tx).await?.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -634,7 +640,11 @@ where
|
|||||||
TransactionBuilder::<Ethereum>::with_deploy_code(tx, code)
|
TransactionBuilder::<Ethereum>::with_deploy_code(tx, code)
|
||||||
};
|
};
|
||||||
|
|
||||||
let receipt = match self.execute_transaction(tx).await {
|
let receipt = match self
|
||||||
|
.execute_transaction(tx)
|
||||||
|
.and_then(|(_, receipt_fut)| receipt_fut)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(receipt) => receipt,
|
Ok(receipt) => receipt,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
tracing::error!(?error, "Contract deployment transaction failed.");
|
tracing::error!(?error, "Contract deployment transaction failed.");
|
||||||
@@ -708,7 +718,7 @@ where
|
|||||||
async fn execute_transaction(
|
async fn execute_transaction(
|
||||||
&self,
|
&self,
|
||||||
transaction: TransactionRequest,
|
transaction: TransactionRequest,
|
||||||
) -> anyhow::Result<TransactionReceipt> {
|
) -> anyhow::Result<(TxHash, impl Future<Output = Result<TransactionReceipt>>)> {
|
||||||
let node = self.platform_information.node;
|
let node = self.platform_information.node;
|
||||||
let transaction_hash = node
|
let transaction_hash = node
|
||||||
.submit_transaction(transaction)
|
.submit_transaction(transaction)
|
||||||
@@ -721,26 +731,28 @@ where
|
|||||||
.send(WatcherEvent::SubmittedTransaction { transaction_hash })
|
.send(WatcherEvent::SubmittedTransaction { transaction_hash })
|
||||||
.context("Failed to send the transaction hash to the watcher")?;
|
.context("Failed to send the transaction hash to the watcher")?;
|
||||||
|
|
||||||
info!("Starting to poll for transaction receipt");
|
Ok((transaction_hash, async move {
|
||||||
poll(
|
info!("Starting to poll for transaction receipt");
|
||||||
Duration::from_secs(30 * 60),
|
poll(
|
||||||
PollingWaitBehavior::Constant(Duration::from_secs(1)),
|
Duration::from_secs(30 * 60),
|
||||||
|| {
|
PollingWaitBehavior::Constant(Duration::from_secs(1)),
|
||||||
async move {
|
|| {
|
||||||
match node.get_receipt(transaction_hash).await {
|
async move {
|
||||||
Ok(receipt) => {
|
match node.get_receipt(transaction_hash).await {
|
||||||
info!("Polling succeeded, receipt found");
|
Ok(receipt) => {
|
||||||
Ok(ControlFlow::Break(receipt))
|
info!("Polling succeeded, receipt found");
|
||||||
|
Ok(ControlFlow::Break(receipt))
|
||||||
|
}
|
||||||
|
Err(_) => Ok(ControlFlow::Continue(())),
|
||||||
}
|
}
|
||||||
Err(_) => Ok(ControlFlow::Continue(())),
|
|
||||||
}
|
}
|
||||||
}
|
.instrument(info_span!("Polling for receipt"))
|
||||||
.instrument(info_span!("Polling for receipt"))
|
},
|
||||||
},
|
)
|
||||||
)
|
.instrument(info_span!("Polling for receipt", %transaction_hash))
|
||||||
.instrument(info_span!("Polling for receipt", %transaction_hash))
|
.await
|
||||||
.await
|
.inspect(|_| info!("Found the transaction receipt"))
|
||||||
.inspect(|_| info!("Found the transaction receipt"))
|
}))
|
||||||
}
|
}
|
||||||
// endregion:Transaction Execution
|
// endregion:Transaction Execution
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,10 @@ impl Watcher {
|
|||||||
async move {
|
async move {
|
||||||
let mut mined_blocks_information = Vec::new();
|
let mut mined_blocks_information = Vec::new();
|
||||||
|
|
||||||
|
// region:TEMPORARY
|
||||||
|
eprintln!("Watcher information for {}", self.platform_identifier);
|
||||||
|
eprintln!("block_number,block_timestamp,mined_gas,block_gas_limit,tx_count");
|
||||||
|
// endregion:TEMPORARY
|
||||||
while let Some(block) = blocks_information_stream.next().await {
|
while let Some(block) = blocks_information_stream.next().await {
|
||||||
// If the block number is equal to or less than the last block before the
|
// If the block number is equal to or less than the last block before the
|
||||||
// repetition then we ignore it and continue on to the next block.
|
// repetition then we ignore it and continue on to the next block.
|
||||||
@@ -132,6 +136,20 @@ impl Watcher {
|
|||||||
watch_for_transaction_hashes.remove(tx_hash);
|
watch_for_transaction_hashes.remove(tx_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// region:TEMPORARY
|
||||||
|
// TODO: The following core is TEMPORARY and will be removed once we have proper
|
||||||
|
// reporting in place and then it can be removed. This serves as as way of doing
|
||||||
|
// some very simple reporting for the time being.
|
||||||
|
eprintln!(
|
||||||
|
"\"{}\",\"{}\",\"{}\",\"{}\",\"{}\"",
|
||||||
|
block.block_number,
|
||||||
|
block.block_timestamp,
|
||||||
|
block.mined_gas,
|
||||||
|
block.block_gas_limit,
|
||||||
|
block.transaction_hashes.len()
|
||||||
|
);
|
||||||
|
// endregion:TEMPORARY
|
||||||
|
|
||||||
mined_blocks_information.push(block);
|
mined_blocks_information.push(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,41 +158,10 @@ impl Watcher {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (_, mined_blocks_information) =
|
let (_, _) =
|
||||||
futures::future::join(watcher_event_watching_task, block_information_watching_task)
|
futures::future::join(watcher_event_watching_task, block_information_watching_task)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// region:TEMPORARY
|
|
||||||
{
|
|
||||||
// TODO: The following core is TEMPORARY and will be removed once we have proper
|
|
||||||
// reporting in place and then it can be removed. This serves as as way of doing some
|
|
||||||
// very simple reporting for the time being.
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
let mut stderr = std::io::stderr().lock();
|
|
||||||
writeln!(
|
|
||||||
stderr,
|
|
||||||
"Watcher information for {}",
|
|
||||||
self.platform_identifier
|
|
||||||
)?;
|
|
||||||
writeln!(
|
|
||||||
stderr,
|
|
||||||
"block_number,block_timestamp,mined_gas,block_gas_limit,tx_count"
|
|
||||||
)?;
|
|
||||||
for block in mined_blocks_information {
|
|
||||||
writeln!(
|
|
||||||
stderr,
|
|
||||||
"{},{},{},{},{}",
|
|
||||||
block.block_number,
|
|
||||||
block.block_timestamp,
|
|
||||||
block.mined_gas,
|
|
||||||
block.block_gas_limit,
|
|
||||||
block.transaction_hashes.len()
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// endregion:TEMPORARY
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user