Compare commits

..

2 Commits

Author SHA1 Message Date
Omar Abdulla 3ea2a58c8d Update the readme 2025-10-16 01:28:05 +03:00
Omar Abdulla bf35c084d4 Get rid of corpus files 2025-10-16 01:09:07 +03:00
24 changed files with 216 additions and 851 deletions
+1
View File
@@ -9,6 +9,7 @@ node_modules
*.log
profile.json.gz
resolc-compiler-tests
workdir
!/schema.json
-3
View File
@@ -1,6 +1,3 @@
[submodule "polkadot-sdk"]
path = polkadot-sdk
url = https://github.com/paritytech/polkadot-sdk.git
[submodule "resolc-compiler-tests"]
path = resolc-compiler-tests
url = https://github.com/paritytech/resolc-compiler-tests
Generated
-14
View File
@@ -1920,7 +1920,6 @@ dependencies = [
"anstyle",
"clap_lex",
"strsim",
"terminal_size",
]
[[package]]
@@ -5693,7 +5692,6 @@ dependencies = [
"revive-dt-config",
"revive-dt-format",
"revive-dt-node-interaction",
"revive-dt-report",
"serde",
"serde_json",
"serde_with",
@@ -5717,7 +5715,6 @@ dependencies = [
"futures",
"revive-common",
"revive-dt-format",
"revive-dt-report",
]
[[package]]
@@ -5727,7 +5724,6 @@ dependencies = [
"alloy",
"anyhow",
"indexmap 2.10.0",
"itertools 0.14.0",
"paste",
"revive-dt-common",
"revive-dt-compiler",
@@ -7839,16 +7835,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed"
dependencies = [
"rustix",
"windows-sys 0.59.0",
]
[[package]]
name = "thiserror"
version = "1.0.69"
+1 -1
View File
@@ -26,7 +26,7 @@ ansi_term = "0.12.1"
anyhow = "1.0"
bson = { version = "2.15.0" }
cacache = { version = "13.1.0" }
clap = { version = "4", features = ["derive", "wrap_help"] }
clap = { version = "4", features = ["derive"] }
dashmap = { version = "6.1.0" }
foundry-compilers-artifacts = { version = "0.18.0" }
futures = { version = "0.3.31" }
+5 -132
View File
@@ -24,7 +24,7 @@ use strum::{AsRefStr, Display, EnumString, IntoStaticStr};
use temp_dir::TempDir;
#[derive(Clone, Debug, Parser, Serialize, Deserialize)]
#[command(name = "retester", term_width = 100)]
#[command(name = "retester")]
pub enum Context {
/// Executes tests in the MatterLabs format differentially on multiple targets concurrently.
Test(Box<TestExecutionContext>),
@@ -47,15 +47,6 @@ impl Context {
pub fn report_configuration(&self) -> &ReportConfiguration {
self.as_ref()
}
pub fn update_for_profile(&mut self) {
match self {
Context::Test(ctx) => ctx.update_for_profile(),
Context::Benchmark(ctx) => ctx.update_for_profile(),
Context::ExportJsonSchema => {}
Context::ExportGenesis(..) => {}
}
}
}
impl AsRef<WorkingDirectoryConfiguration> for Context {
@@ -229,11 +220,6 @@ impl AsRef<IgnoreSuccessConfiguration> for Context {
#[derive(Clone, Debug, Parser, Serialize, Deserialize)]
pub struct TestExecutionContext {
/// The commandline profile to use. Different profiles change the defaults of the various cli
/// arguments.
#[arg(long = "profile", default_value_t = Profile::Default)]
pub profile: Profile,
/// The set of platforms that the differential tests should run on.
#[arg(
short = 'p',
@@ -320,49 +306,8 @@ pub struct TestExecutionContext {
pub ignore_success_configuration: IgnoreSuccessConfiguration,
}
impl TestExecutionContext {
pub fn update_for_profile(&mut self) {
match self.profile {
Profile::Default => {}
Profile::Debug => {
let default_concurrency_config =
ConcurrencyConfiguration::parse_from(["concurrency-configuration"]);
let working_directory_config = WorkingDirectoryConfiguration::default();
if self.concurrency_configuration.number_of_nodes
== default_concurrency_config.number_of_nodes
{
self.concurrency_configuration.number_of_nodes = 1;
}
if self.concurrency_configuration.number_of_threads
== default_concurrency_config.number_of_threads
{
self.concurrency_configuration.number_of_threads = 5;
}
if self.concurrency_configuration.number_concurrent_tasks
== default_concurrency_config.number_concurrent_tasks
{
self.concurrency_configuration.number_concurrent_tasks = 1;
}
if working_directory_config == self.working_directory {
let home_directory =
PathBuf::from(std::env::var("HOME").expect("Home dir not found"));
let working_directory = home_directory.join(".retester-workdir");
self.working_directory = WorkingDirectoryConfiguration::Path(working_directory)
}
}
}
}
}
#[derive(Clone, Debug, Parser, Serialize, Deserialize)]
pub struct BenchmarkingContext {
/// The commandline profile to use. Different profiles change the defaults of the various cli
/// arguments.
#[arg(long = "profile", default_value_t = Profile::Default)]
pub profile: Profile,
/// The working directory that the program will use for all of the temporary artifacts needed at
/// runtime.
///
@@ -442,42 +387,6 @@ pub struct BenchmarkingContext {
pub report_configuration: ReportConfiguration,
}
impl BenchmarkingContext {
pub fn update_for_profile(&mut self) {
match self.profile {
Profile::Default => {}
Profile::Debug => {
let default_concurrency_config =
ConcurrencyConfiguration::parse_from(["concurrency-configuration"]);
let working_directory_config = WorkingDirectoryConfiguration::default();
if self.concurrency_configuration.number_of_nodes
== default_concurrency_config.number_of_nodes
{
self.concurrency_configuration.number_of_nodes = 1;
}
if self.concurrency_configuration.number_of_threads
== default_concurrency_config.number_of_threads
{
self.concurrency_configuration.number_of_threads = 5;
}
if self.concurrency_configuration.number_concurrent_tasks
== default_concurrency_config.number_concurrent_tasks
{
self.concurrency_configuration.number_concurrent_tasks = 1;
}
if working_directory_config == self.working_directory {
let home_directory =
PathBuf::from(std::env::var("HOME").expect("Home dir not found"));
let working_directory = home_directory.join(".retester-workdir");
self.working_directory = WorkingDirectoryConfiguration::Path(working_directory)
}
}
}
}
}
#[derive(Clone, Debug, Parser, Serialize, Deserialize)]
pub struct ExportGenesisContext {
/// The platform of choice to export the genesis for.
@@ -510,7 +419,7 @@ pub struct ExportGenesisContext {
impl Default for TestExecutionContext {
fn default() -> Self {
Self::parse_from(["execution-context", "--test", "."])
Self::parse_from(["execution-context"])
}
}
@@ -612,7 +521,7 @@ impl AsRef<IgnoreSuccessConfiguration> for TestExecutionContext {
impl Default for BenchmarkingContext {
fn default() -> Self {
Self::parse_from(["benchmarking-context", "--test", "."])
Self::parse_from(["benchmarking-context"])
}
}
@@ -759,7 +668,7 @@ pub struct CorpusConfiguration {
/// - `{metadata_file_path}::{case_idx}::{mode}`: This is very similar to the above specifier
/// with the exception that in this case the mode is specified and will be used in the test.
#[serde_as(as = "Vec<serde_with::DisplayFromStr>")]
#[arg(short = 't', long = "test", required = true)]
#[arg(short = 't', long = "test")]
pub test_specifiers: Vec<ParsedTestSpecifier>,
}
@@ -1080,7 +989,7 @@ pub struct IgnoreSuccessConfiguration {
}
/// Represents the working directory that the program uses.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone)]
pub enum WorkingDirectoryConfiguration {
/// A temporary directory is used as the working directory. This will be removed when dropped.
TemporaryDirectory(Arc<TempDir>),
@@ -1216,39 +1125,3 @@ pub enum OutputFormat {
/// An output format that looks heavily resembles the output from `cargo test`.
CargoTestLike,
}
/// Command line profiles used to override the default values provided for the commands.
#[derive(
Clone,
Copy,
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
ValueEnum,
EnumString,
Display,
AsRefStr,
IntoStaticStr,
)]
#[strum(serialize_all = "kebab-case")]
pub enum Profile {
/// The default profile used by the framework. This profile is optimized to make the test
/// and workload execution happen as fast as possible.
#[default]
Default,
/// A debug profile optimized for use cases when certain tests are being debugged. This profile
/// sets up the framework with the following:
///
/// * `concurrency.number-of-nodes` set to 1 node.
/// * `concurrency.number-of-concurrent-tasks` set to 1 such that tests execute sequentially.
/// * `concurrency.number-of-threads` set to 5.
/// * `working-directory` set to ~/.retester-workdir
Debug,
}
@@ -181,7 +181,7 @@ where
code,
);
let receipt = self
.execute_transaction(tx, None)
.execute_transaction(tx)
.and_then(|(_, receipt_fut)| receipt_fut)
.await
.inspect_err(|err| {
@@ -218,22 +218,6 @@ where
.inspect_err(|err| error!(?err, "Post-linking compilation failed"))
.context("Failed to compile the post-link contracts")?;
for (contract_path, contract_name_to_info_mapping) in compiler_output.contracts.iter() {
for (contract_name, (contract_bytecode, _)) in contract_name_to_info_mapping.iter() {
let contract_bytecode = hex::decode(contract_bytecode)
.expect("Impossible for us to get an undecodable bytecode after linking");
self.platform_information
.reporter
.report_contract_information_event(
contract_path.to_path_buf(),
contract_name.clone(),
contract_bytecode.len(),
)
.expect("Should not fail");
}
}
self.execution_state = ExecutionState::new(
compiler_output.contracts,
deployed_libraries.unwrap_or_default(),
@@ -295,15 +279,15 @@ where
#[instrument(level = "info", skip_all, fields(driver_id = self.driver_id))]
pub async fn execute_function_call(
&mut self,
step_path: &StepPath,
_: &StepPath,
step: &FunctionCallStep,
) -> Result<usize> {
let deployment_receipts = self
.handle_function_call_contract_deployment(step_path, step)
.handle_function_call_contract_deployment(step)
.await
.context("Failed to deploy contracts for the function call step")?;
let transaction_hash = self
.handle_function_call_execution(step_path, step, deployment_receipts)
.handle_function_call_execution(step, deployment_receipts)
.await
.context("Failed to handle the function call execution")?;
self.handle_function_call_variable_assignment(step, transaction_hash)
@@ -314,7 +298,6 @@ where
async fn handle_function_call_contract_deployment(
&mut self,
step_path: &StepPath,
step: &FunctionCallStep,
) -> Result<HashMap<ContractInstance, TransactionReceipt>> {
let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new();
@@ -346,13 +329,7 @@ where
.await?
};
if let (_, _, Some(receipt)) = self
.get_or_deploy_contract_instance(
&instance,
caller,
calldata,
value,
Some(step_path),
)
.get_or_deploy_contract_instance(&instance, caller, calldata, value)
.await
.context("Failed to get or deploy contract instance during input execution")?
{
@@ -365,7 +342,6 @@ where
async fn handle_function_call_execution(
&mut self,
step_path: &StepPath,
step: &FunctionCallStep,
mut deployment_receipts: HashMap<ContractInstance, TransactionReceipt>,
) -> Result<TxHash> {
@@ -380,7 +356,7 @@ where
let tx = step
.as_transaction(self.resolver.as_ref(), self.default_resolution_context())
.await?;
Ok(self.execute_transaction(tx, Some(step_path)).await?.0)
Ok(self.execute_transaction(tx).await?.0)
}
}
}
@@ -544,7 +520,6 @@ where
deployer: Address,
calldata: Option<&Calldata>,
value: Option<EtherValue>,
step_path: Option<&StepPath>,
) -> Result<(Address, JsonAbi, Option<TransactionReceipt>)> {
if let Some((_, address, abi)) = self
.execution_state
@@ -560,7 +535,7 @@ where
} else {
info!("Contract instance requires deployment.");
let (address, abi, receipt) = self
.deploy_contract(contract_instance, deployer, calldata, value, step_path)
.deploy_contract(contract_instance, deployer, calldata, value)
.await
.context("Failed to deploy contract")?;
info!(
@@ -587,7 +562,6 @@ where
deployer: Address,
calldata: Option<&Calldata>,
value: Option<EtherValue>,
step_path: Option<&StepPath>,
) -> Result<(Address, JsonAbi, TransactionReceipt)> {
let Some(ContractPathAndIdent {
contract_source_path,
@@ -647,7 +621,7 @@ where
};
let receipt = match self
.execute_transaction(tx, step_path)
.execute_transaction(tx)
.and_then(|(_, receipt_fut)| receipt_fut)
.await
{
@@ -697,7 +671,6 @@ where
async fn execute_transaction(
&self,
transaction: TransactionRequest,
step_path: Option<&StepPath>,
) -> anyhow::Result<(TxHash, impl Future<Output = Result<TransactionReceipt>>)> {
let node = self.platform_information.node;
let transaction_hash = node
@@ -707,14 +680,9 @@ where
Span::current().record("transaction_hash", display(transaction_hash));
info!("Submitted transaction");
if let Some(step_path) = step_path {
self.watcher_tx
.send(WatcherEvent::SubmittedTransaction {
transaction_hash,
step_path: step_path.clone(),
})
.context("Failed to send the transaction hash to the watcher")?;
};
self.watcher_tx
.send(WatcherEvent::SubmittedTransaction { transaction_hash })
.context("Failed to send the transaction hash to the watcher")?;
Ok((transaction_hash, async move {
info!("Starting to poll for transaction receipt");
@@ -145,14 +145,12 @@ pub async fn handle_differential_benchmarks(
context.wallet_configuration.highest_private_key_exclusive(),
)));
let (watcher, watcher_tx) = Watcher::new(
platform_identifier,
platform_information
.node
.subscribe_to_full_blocks_information()
.await
.context("Failed to subscribe to full blocks information from the node")?,
test_definition
.reporter
.execution_specific_reporter(0usize, platform_identifier),
);
let driver = Driver::new(
platform_information,
@@ -1,15 +1,10 @@
use std::{
collections::HashMap,
pin::Pin,
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use std::{collections::HashSet, pin::Pin, sync::Arc};
use alloy::primitives::{BlockNumber, TxHash};
use anyhow::Result;
use futures::{Stream, StreamExt};
use revive_dt_format::steps::StepPath;
use revive_dt_report::{ExecutionSpecificReporter, MinedBlockInformation, TransactionInformation};
use revive_dt_common::types::PlatformIdentifier;
use revive_dt_node_interaction::MinedBlockInformation;
use tokio::sync::{
RwLock,
mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
@@ -20,6 +15,9 @@ use tracing::{info, instrument};
/// and MUST NOT be re-used between workloads since it holds important internal state for a given
/// workload and is not designed for reuse.
pub struct Watcher {
/// The identifier of the platform that this watcher is for.
platform_identifier: PlatformIdentifier,
/// The receive side of the channel that all of the drivers and various other parts of the code
/// send events to the watcher on.
rx: UnboundedReceiver<WatcherEvent>,
@@ -27,22 +25,19 @@ pub struct Watcher {
/// This is a stream of the blocks that were mined by the node. This is for a single platform
/// and a single node from that platform.
blocks_stream: Pin<Box<dyn Stream<Item = MinedBlockInformation>>>,
/// The reporter used to send events to the report aggregator.
reporter: ExecutionSpecificReporter,
}
impl Watcher {
pub fn new(
platform_identifier: PlatformIdentifier,
blocks_stream: Pin<Box<dyn Stream<Item = MinedBlockInformation>>>,
reporter: ExecutionSpecificReporter,
) -> (Self, UnboundedSender<WatcherEvent>) {
let (tx, rx) = unbounded_channel::<WatcherEvent>();
(
Self {
platform_identifier,
rx,
blocks_stream,
reporter,
},
tx,
)
@@ -66,8 +61,7 @@ impl Watcher {
// This is the set of the transaction hashes that the watcher should be looking for and
// watch for them in the blocks. The watcher will keep watching for blocks until it sees
// that all of the transactions that it was watching for has been seen in the mined blocks.
let watch_for_transaction_hashes =
Arc::new(RwLock::new(HashMap::<TxHash, (StepPath, SystemTime)>::new()));
let watch_for_transaction_hashes = Arc::new(RwLock::new(HashSet::<TxHash>::new()));
// A boolean that keeps track of whether all of the transactions were submitted or if more
// txs are expected to come through the receive side of the channel. We do not want to rely
@@ -87,14 +81,11 @@ impl Watcher {
// contain nested repetitions and therefore there's no use in doing any
// action if the repetitions are nested.
WatcherEvent::RepetitionStartEvent { .. } => {}
WatcherEvent::SubmittedTransaction {
transaction_hash,
step_path,
} => {
WatcherEvent::SubmittedTransaction { transaction_hash } => {
watch_for_transaction_hashes
.write()
.await
.insert(transaction_hash, (step_path, SystemTime::now()));
.insert(transaction_hash);
}
WatcherEvent::AllTransactionsSubmitted => {
*all_transactions_submitted.write().await = true;
@@ -106,21 +97,25 @@ impl Watcher {
}
}
};
let reporter = self.reporter.clone();
let block_information_watching_task = {
let watch_for_transaction_hashes = watch_for_transaction_hashes.clone();
let all_transactions_submitted = all_transactions_submitted.clone();
let mut blocks_information_stream = self.blocks_stream;
async move {
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,ref_time,max_ref_time,proof_size,max_proof_size"
);
// endregion:TEMPORARY
while let Some(block) = blocks_information_stream.next().await {
// 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.
if block.ethereum_block_information.block_number <= ignore_block_before {
if block.block_number <= ignore_block_before {
continue;
}
reporter
.report_block_mined_event(block.clone())
.expect("Can't fail");
if *all_transactions_submitted.read().await
&& watch_for_transaction_hashes.read().await.is_empty()
@@ -129,8 +124,8 @@ impl Watcher {
}
info!(
block_number = block.ethereum_block_information.block_number,
block_tx_count = block.ethereum_block_information.transaction_hashes.len(),
block_number = block.block_number,
block_tx_count = block.transaction_hashes.len(),
remaining_transactions = watch_for_transaction_hashes.read().await.len(),
"Observed a block"
);
@@ -139,31 +134,33 @@ impl Watcher {
// are currently watching for.
let mut watch_for_transaction_hashes =
watch_for_transaction_hashes.write().await;
for tx_hash in block.ethereum_block_information.transaction_hashes.iter() {
let Some((step_path, submission_time)) =
watch_for_transaction_hashes.remove(tx_hash)
else {
continue;
};
let transaction_information = TransactionInformation {
transaction_hash: *tx_hash,
submission_timestamp: submission_time
.duration_since(UNIX_EPOCH)
.expect("Can't fail")
.as_secs() as _,
block_timestamp: block.ethereum_block_information.block_timestamp,
block_number: block.ethereum_block_information.block_number,
};
reporter
.report_step_transaction_information_event(
step_path,
transaction_information,
)
.expect("Can't fail")
for tx_hash in block.transaction_hashes.iter() {
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(),
block.ref_time,
block.max_ref_time,
block.proof_size,
block.max_proof_size,
);
// endregion:TEMPORARY
mined_blocks_information.push(block);
}
info!("Watcher's Block Watching Task Finished");
mined_blocks_information
}
};
@@ -175,7 +172,7 @@ impl Watcher {
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum WatcherEvent {
/// Informs the watcher that it should begin watching for the blocks mined by the platforms.
/// Before the watcher receives this event it will not be watching for the mined blocks. The
@@ -195,8 +192,6 @@ pub enum WatcherEvent {
SubmittedTransaction {
/// The hash of the submitted transaction.
transaction_hash: TxHash,
/// The step path of the step that the transaction belongs to.
step_path: StepPath,
},
/// Informs the watcher that all of the transactions of this benchmark have been submitted and
@@ -205,7 +205,6 @@ pub async fn handle_differential_tests(
?remaining_tasks,
"Remaining Tests"
);
drop(remaining_tasks);
tokio::time::sleep(Duration::from_secs(10)).await
}
});
@@ -330,18 +329,15 @@ async fn start_cli_reporting_task(output_format: OutputFormat, reporter: Reporte
.unwrap();
writeln!(buf).unwrap();
if aggregator_events_rx.is_empty() {
buf = tokio::task::spawn_blocking(move || {
buf.flush().unwrap();
buf
})
.await
.unwrap();
}
buf = tokio::task::spawn_blocking(move || {
buf.flush().unwrap();
buf
})
.await
.unwrap();
}
}
}
info!("Aggregator Broadcast Channel Closed");
// Summary at the end.
match output_format {
+3 -12
View File
@@ -32,18 +32,9 @@ pub async fn create_test_definitions_stream<'a>(
only_execute_failed_tests: Option<&Report>,
reporter: Reporter,
) -> impl Stream<Item = TestDefinition<'a>> {
let cloned_reporter = reporter.clone();
stream::iter(
corpus
.cases_iterator()
.inspect(move |(metadata_file, ..)| {
cloned_reporter
.report_metadata_file_discovery_event(
metadata_file.metadata_file_path.clone(),
metadata_file.content.clone(),
)
.unwrap();
})
.map(move |(metadata_file, case_idx, case, mode)| {
let reporter = reporter.clone();
@@ -319,10 +310,10 @@ impl<'a> TestDefinition<'a> {
};
let test_case_status = report
.execution_information
.test_case_information
.get(&(self.metadata_file_path.to_path_buf().into()))
.and_then(|obj| obj.case_reports.get(&self.case_idx))
.and_then(|obj| obj.mode_execution_reports.get(&self.mode))
.and_then(|obj| obj.get(&self.mode))
.and_then(|obj| obj.get(&self.case_idx))
.and_then(|obj| obj.status.as_ref());
match test_case_status {
+3 -9
View File
@@ -6,7 +6,7 @@ use anyhow::Context as _;
use clap::Parser;
use revive_dt_report::ReportAggregator;
use schemars::schema_for;
use tracing::{info, level_filters::LevelFilter};
use tracing::info;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
use revive_dt_config::Context;
@@ -31,20 +31,14 @@ fn main() -> anyhow::Result<()> {
.with_writer(writer)
.with_thread_ids(false)
.with_thread_names(false)
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::OFF.into())
.from_env_lossy(),
)
.with_env_filter(EnvFilter::from_default_env())
.with_ansi(false)
.pretty()
.finish();
tracing::subscriber::set_global_default(subscriber)?;
info!("Differential testing tool is starting");
let mut context = Context::try_parse()?;
context.update_for_profile();
let context = Context::try_parse()?;
let (reporter, report_aggregator_task) = ReportAggregator::new(context.clone()).into_task();
match context {
+2 -2
View File
@@ -45,12 +45,12 @@ pub enum Step {
}
define_wrapper_type!(
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct StepIdx(usize) impl Display, FromStr;
);
define_wrapper_type!(
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
pub struct StepPath(Vec<StepIdx>);
);
-1
View File
@@ -12,7 +12,6 @@ rust-version.workspace = true
revive-common = { workspace = true }
revive-dt-format = { workspace = true }
revive-dt-report = { workspace = true }
alloy = { workspace = true }
anyhow = { workspace = true }
+31 -2
View File
@@ -4,7 +4,7 @@ use std::pin::Pin;
use std::sync::Arc;
use alloy::network::Ethereum;
use alloy::primitives::{Address, StorageKey, TxHash, U256};
use alloy::primitives::{Address, BlockNumber, BlockTimestamp, StorageKey, TxHash, U256};
use alloy::providers::DynProvider;
use alloy::rpc::types::trace::geth::{DiffMode, GethDebugTracingOptions, GethTrace};
use alloy::rpc::types::{EIP1186AccountProofResponse, TransactionReceipt, TransactionRequest};
@@ -13,7 +13,6 @@ use anyhow::Result;
use futures::Stream;
use revive_common::EVMVersion;
use revive_dt_format::traits::ResolverApi;
use revive_dt_report::MinedBlockInformation;
/// An interface for all interactions with Ethereum compatible nodes.
#[allow(clippy::type_complexity)]
@@ -81,3 +80,33 @@ pub trait EthereumNode {
fn provider(&self)
-> Pin<Box<dyn Future<Output = anyhow::Result<DynProvider<Ethereum>>> + '_>>;
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct MinedBlockInformation {
/// The block number.
pub block_number: BlockNumber,
/// The block timestamp.
pub block_timestamp: BlockTimestamp,
/// The amount of gas mined in the block.
pub mined_gas: u128,
/// The gas limit of the block.
pub block_gas_limit: u128,
/// The hashes of the transactions that were mined as part of the block.
pub transaction_hashes: Vec<TxHash>,
/// The ref time for substrate based chains.
pub ref_time: u128,
/// The max ref time for substrate based chains.
pub max_ref_time: u64,
/// The proof size for substrate based chains.
pub proof_size: u128,
/// The max proof size for substrate based chains.
pub max_proof_size: u64,
}
-1
View File
@@ -21,7 +21,6 @@ revive-dt-common = { workspace = true }
revive-dt-config = { workspace = true }
revive-dt-format = { workspace = true }
revive-dt-node-interaction = { workspace = true }
revive-dt-report = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
+15 -15
View File
@@ -43,8 +43,7 @@ use revive_dt_common::{
};
use revive_dt_config::*;
use revive_dt_format::traits::ResolverApi;
use revive_dt_node_interaction::EthereumNode;
use revive_dt_report::{EthereumMinedBlockInformation, MinedBlockInformation};
use revive_dt_node_interaction::{EthereumNode, MinedBlockInformation};
use crate::{
Node,
@@ -527,19 +526,20 @@ impl EthereumNode for GethNode {
let mined_block_information_stream = block_stream.filter_map(|block| async {
let block = block.ok()?;
Some(MinedBlockInformation {
ethereum_block_information: EthereumMinedBlockInformation {
block_number: block.number(),
block_timestamp: block.header.timestamp,
mined_gas: block.header.gas_used as _,
block_gas_limit: block.header.gas_limit as _,
transaction_hashes: block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
},
substrate_block_information: None,
block_number: block.number(),
block_timestamp: block.header.timestamp,
mined_gas: block.header.gas_used as _,
block_gas_limit: block.header.gas_limit as _,
transaction_hashes: block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
ref_time: 0,
max_ref_time: 0,
proof_size: 0,
max_proof_size: 0,
})
});
@@ -56,8 +56,7 @@ use revive_dt_common::{
};
use revive_dt_config::*;
use revive_dt_format::traits::ResolverApi;
use revive_dt_node_interaction::EthereumNode;
use revive_dt_report::{EthereumMinedBlockInformation, MinedBlockInformation};
use revive_dt_node_interaction::{EthereumNode, MinedBlockInformation};
use crate::{
Node,
@@ -758,19 +757,20 @@ impl EthereumNode for LighthouseGethNode {
let mined_block_information_stream = block_stream.filter_map(|block| async {
let block = block.ok()?;
Some(MinedBlockInformation {
ethereum_block_information: EthereumMinedBlockInformation {
block_number: block.number(),
block_timestamp: block.header.timestamp,
mined_gas: block.header.gas_used as _,
block_gas_limit: block.header.gas_limit as _,
transaction_hashes: block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
},
substrate_block_information: None,
block_number: block.number(),
block_timestamp: block.header.timestamp,
mined_gas: block.header.gas_used as _,
block_gas_limit: block.header.gas_limit as _,
transaction_hashes: block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
ref_time: 0,
max_ref_time: 0,
proof_size: 0,
max_proof_size: 0,
})
});
@@ -37,10 +37,7 @@ use sp_core::crypto::Ss58Codec;
use sp_runtime::AccountId32;
use revive_dt_config::*;
use revive_dt_node_interaction::EthereumNode;
use revive_dt_report::{
EthereumMinedBlockInformation, MinedBlockInformation, SubstrateMinedBlockInformation,
};
use revive_dt_node_interaction::{EthereumNode, MinedBlockInformation};
use subxt::{OnlineClient, SubstrateConfig};
use tokio::sync::OnceCell;
use tracing::{instrument, trace};
@@ -221,7 +218,7 @@ impl SubstrateNode {
}
},
ProcessReadinessWaitBehavior::TimeBoundedWaitFunction {
max_wait_duration: Duration::from_secs(90),
max_wait_duration: Duration::from_secs(30),
check_function: Box::new(|_, stderr_line| match stderr_line {
Some(line) => Ok(line.contains(Self::SUBSTRATE_READY_MARKER)),
None => Ok(false),
@@ -560,24 +557,20 @@ impl EthereumNode for SubstrateNode {
let max_proof_size = limits.max_block.proof_size;
Some(MinedBlockInformation {
ethereum_block_information: EthereumMinedBlockInformation {
block_number: revive_block.number(),
block_timestamp: revive_block.header.timestamp,
mined_gas: revive_block.header.gas_used as _,
block_gas_limit: revive_block.header.gas_limit as _,
transaction_hashes: revive_block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
},
substrate_block_information: Some(SubstrateMinedBlockInformation {
ref_time: block_ref_time,
max_ref_time,
proof_size: block_proof_size,
max_proof_size,
}),
block_number: substrate_block.number() as _,
block_timestamp: revive_block.header.timestamp,
mined_gas: revive_block.header.gas_used as _,
block_gas_limit: revive_block.header.gas_limit as _,
transaction_hashes: revive_block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
ref_time: block_ref_time,
max_ref_time,
proof_size: block_proof_size,
max_proof_size,
})
}
});
@@ -60,10 +60,7 @@ use revive_common::EVMVersion;
use revive_dt_common::fs::clear_directory;
use revive_dt_config::*;
use revive_dt_format::traits::ResolverApi;
use revive_dt_node_interaction::*;
use revive_dt_report::{
EthereumMinedBlockInformation, MinedBlockInformation, SubstrateMinedBlockInformation,
};
use revive_dt_node_interaction::{EthereumNode, MinedBlockInformation};
use serde_json::json;
use sp_core::crypto::Ss58Codec;
use sp_runtime::AccountId32;
@@ -581,24 +578,20 @@ impl EthereumNode for ZombienetNode {
let max_proof_size = limits.max_block.proof_size;
Some(MinedBlockInformation {
ethereum_block_information: EthereumMinedBlockInformation {
block_number: revive_block.number(),
block_timestamp: revive_block.header.timestamp,
mined_gas: revive_block.header.gas_used as _,
block_gas_limit: revive_block.header.gas_limit as _,
transaction_hashes: revive_block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
},
substrate_block_information: Some(SubstrateMinedBlockInformation {
ref_time: block_ref_time,
max_ref_time,
proof_size: block_proof_size,
max_proof_size,
}),
block_number: substrate_block.number() as _,
block_timestamp: revive_block.header.timestamp,
mined_gas: revive_block.header.gas_used as _,
block_gas_limit: revive_block.header.gas_limit as _,
transaction_hashes: revive_block
.transactions
.into_hashes()
.as_hashes()
.expect("Must be hashes")
.to_vec(),
ref_time: block_ref_time,
max_ref_time,
proof_size: block_proof_size,
max_proof_size,
})
}
});
+1 -1
View File
@@ -104,7 +104,7 @@ where
};
debug!(%tx_hash, "Submitted Transaction");
pending_transaction.set_timeout(Some(Duration::from_secs(240)));
pending_transaction.set_timeout(Some(Duration::from_secs(120)));
let tx_hash = pending_transaction.watch().await.context(format!(
"Transaction inclusion watching timeout for {tx_hash}"
))?;
-1
View File
@@ -17,7 +17,6 @@ alloy = { workspace = true }
anyhow = { workspace = true }
paste = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
itertools = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
+37 -447
View File
@@ -4,19 +4,17 @@
use std::{
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
fs::OpenOptions,
ops::{Add, Div},
path::PathBuf,
time::{SystemTime, UNIX_EPOCH},
};
use alloy::primitives::{Address, BlockNumber, BlockTimestamp, TxHash};
use alloy::primitives::Address;
use anyhow::{Context as _, Result};
use indexmap::IndexMap;
use itertools::Itertools;
use revive_dt_common::types::PlatformIdentifier;
use revive_dt_common::types::{ParsedTestSpecifier, PlatformIdentifier};
use revive_dt_compiler::{CompilerInput, CompilerOutput, Mode};
use revive_dt_config::Context;
use revive_dt_format::{case::CaseIdx, metadata::ContractInstance, steps::StepPath};
use revive_dt_format::{case::CaseIdx, metadata::ContractInstance};
use semver::Version;
use serde::{Deserialize, Serialize};
use serde_with::{DisplayFromStr, serde_as};
@@ -41,7 +39,7 @@ pub struct ReportAggregator {
impl ReportAggregator {
pub fn new(context: Context) -> Self {
let (runner_tx, runner_rx) = unbounded_channel::<RunnerEvent>();
let (listener_tx, _) = channel::<ReporterEvent>(0xFFFF);
let (listener_tx, _) = channel::<ReporterEvent>(1024);
Self {
report: Report::new(context),
remaining_cases: Default::default(),
@@ -64,11 +62,14 @@ impl ReportAggregator {
debug!("Starting to aggregate report");
while let Some(event) = self.runner_rx.recv().await {
debug!(event = event.variant_name(), "Received Event");
debug!(?event, "Received Event");
match event {
RunnerEvent::SubscribeToEvents(event) => {
self.handle_subscribe_to_events_event(*event);
}
RunnerEvent::CorpusDiscovery(event) => {
self.handle_corpus_file_discovered_event(*event)
}
RunnerEvent::MetadataFileDiscovery(event) => {
self.handle_metadata_file_discovery_event(*event);
}
@@ -105,20 +106,12 @@ impl ReportAggregator {
RunnerEvent::ContractDeployed(event) => {
self.handle_contract_deployed_event(*event);
}
RunnerEvent::Completion(_) => {
RunnerEvent::Completion(event) => {
self.handle_completion(*event);
break;
}
/* Benchmarks Events */
RunnerEvent::StepTransactionInformation(event) => {
self.handle_step_transaction_information(*event)
}
RunnerEvent::ContractInformation(event) => {
self.handle_contract_information(*event);
}
RunnerEvent::BlockMined(event) => self.handle_block_mined(*event),
}
}
self.handle_completion(CompletionEvent {});
debug!("Report aggregation completed");
let file_name = {
@@ -159,6 +152,10 @@ impl ReportAggregator {
let _ = event.tx.send(self.listener_tx.subscribe());
}
fn handle_corpus_file_discovered_event(&mut self, event: CorpusDiscoveryEvent) {
self.report.corpora.extend(event.test_specifiers);
}
fn handle_metadata_file_discovery_event(&mut self, event: MetadataFileDiscoveryEvent) {
self.report.metadata_files.insert(event.path.clone());
}
@@ -237,19 +234,17 @@ impl ReportAggregator {
let case_status = self
.report
.execution_information
.test_case_information
.entry(specifier.metadata_file_path.clone().into())
.or_default()
.case_reports
.entry(specifier.solc_mode.clone())
.or_default()
.iter()
.flat_map(|(case_idx, mode_to_execution_map)| {
let case_status = mode_to_execution_map
.mode_execution_reports
.get(&specifier.solc_mode)?
.status
.clone()
.expect("Can't be uninitialized");
Some((*case_idx, case_status))
.map(|(case_idx, case_report)| {
(
*case_idx,
case_report.status.clone().expect("Can't be uninitialized"),
)
})
.collect::<BTreeMap<_, _>>();
let event = ReporterEvent::MetadataFileSolcModeCombinationExecutionCompleted {
@@ -388,159 +383,22 @@ impl ReportAggregator {
self.execution_information(&event.execution_specifier)
.deployed_contracts
.get_or_insert_default()
.insert(event.contract_instance.clone(), event.address);
self.test_case_report(&event.execution_specifier.test_specifier)
.contract_addresses
.entry(event.contract_instance)
.or_default()
.entry(event.execution_specifier.platform_identifier)
.or_default()
.push(event.address);
.insert(event.contract_instance, event.address);
}
fn handle_completion(&mut self, _: CompletionEvent) {
self.runner_rx.close();
self.handle_metrics_computation();
}
fn handle_metrics_computation(&mut self) {
for report in self.report.execution_information.values_mut() {
for report in report.case_reports.values_mut() {
for report in report.mode_execution_reports.values_mut() {
for (platform_identifier, block_information) in
report.mined_block_information.iter_mut()
{
block_information.sort_by(|a, b| {
a.ethereum_block_information
.block_timestamp
.cmp(&b.ethereum_block_information.block_timestamp)
});
// Computing the TPS.
let tps = block_information
.iter()
.tuple_windows::<(_, _)>()
.map(|(block1, block2)| {
block2.ethereum_block_information.transaction_hashes.len() as u64
/ (block2.ethereum_block_information.block_timestamp
- block1.ethereum_block_information.block_timestamp)
})
.collect::<Vec<_>>();
report
.metrics
.get_or_insert_default()
.transaction_per_second
.with_list(*platform_identifier, tps);
// Computing the GPS.
let gps = block_information
.iter()
.tuple_windows::<(_, _)>()
.map(|(block1, block2)| {
block2.ethereum_block_information.mined_gas as u64
/ (block2.ethereum_block_information.block_timestamp
- block1.ethereum_block_information.block_timestamp)
})
.collect::<Vec<_>>();
report
.metrics
.get_or_insert_default()
.gas_per_second
.with_list(*platform_identifier, gps);
// Computing the gas block fullness
let gas_block_fullness = block_information
.iter()
.map(|block| block.gas_block_fullness_percentage())
.map(|v| v as u64)
.collect::<Vec<_>>();
report
.metrics
.get_or_insert_default()
.gas_block_fullness
.with_list(*platform_identifier, gas_block_fullness);
// Computing the ref-time block fullness
let reftime_block_fullness = block_information
.iter()
.filter_map(|block| block.ref_time_block_fullness_percentage())
.map(|v| v as u64)
.collect::<Vec<_>>();
dbg!(&reftime_block_fullness);
if !reftime_block_fullness.is_empty() {
report
.metrics
.get_or_insert_default()
.ref_time_block_fullness
.get_or_insert_default()
.with_list(*platform_identifier, reftime_block_fullness);
}
// Computing the proof size block fullness
let proof_size_block_fullness = block_information
.iter()
.filter_map(|block| block.proof_size_block_fullness_percentage())
.map(|v| v as u64)
.collect::<Vec<_>>();
dbg!(&proof_size_block_fullness);
if !proof_size_block_fullness.is_empty() {
report
.metrics
.get_or_insert_default()
.proof_size_block_fullness
.get_or_insert_default()
.with_list(*platform_identifier, proof_size_block_fullness);
}
}
}
}
}
}
fn handle_step_transaction_information(&mut self, event: StepTransactionInformationEvent) {
self.test_case_report(&event.execution_specifier.test_specifier)
.steps
.entry(event.step_path)
.or_default()
.transactions
.entry(event.execution_specifier.platform_identifier)
.or_default()
.push(event.transaction_information);
}
fn handle_contract_information(&mut self, event: ContractInformationEvent) {
self.test_case_report(&event.execution_specifier.test_specifier)
.compiled_contracts
.entry(event.source_code_path)
.or_default()
.entry(event.contract_name)
.or_default()
.contract_size
.insert(
event.execution_specifier.platform_identifier,
event.contract_size,
);
}
fn handle_block_mined(&mut self, event: BlockMinedEvent) {
self.test_case_report(&event.execution_specifier.test_specifier)
.mined_block_information
.entry(event.execution_specifier.platform_identifier)
.or_default()
.push(event.mined_block_information);
}
fn test_case_report(&mut self, specifier: &TestSpecifier) -> &mut ExecutionReport {
fn test_case_report(&mut self, specifier: &TestSpecifier) -> &mut TestCaseReport {
self.report
.execution_information
.test_case_information
.entry(specifier.metadata_file_path.clone().into())
.or_default()
.case_reports
.entry(specifier.case_idx)
.or_default()
.mode_execution_reports
.entry(specifier.solc_mode.clone())
.or_default()
.entry(specifier.case_idx)
.or_default()
}
fn execution_information(
@@ -561,69 +419,35 @@ impl ReportAggregator {
pub struct Report {
/// The context that the tool was started up with.
pub context: Context,
/// The list of corpus files that the tool found.
#[serde_as(as = "Vec<DisplayFromStr>")]
pub corpora: Vec<ParsedTestSpecifier>,
/// The list of metadata files that were found by the tool.
pub metadata_files: BTreeSet<MetadataFilePath>,
/// Metrics from the execution.
#[serde(skip_serializing_if = "Option::is_none")]
pub metrics: Option<Metrics>,
/// Information relating to each test case.
pub execution_information: BTreeMap<MetadataFilePath, MetadataFileReport>,
#[serde_as(as = "BTreeMap<_, HashMap<DisplayFromStr, BTreeMap<DisplayFromStr, _>>>")]
pub test_case_information:
BTreeMap<MetadataFilePath, HashMap<Mode, BTreeMap<CaseIdx, TestCaseReport>>>,
}
impl Report {
pub fn new(context: Context) -> Self {
Self {
context,
metrics: Default::default(),
corpora: Default::default(),
metadata_files: Default::default(),
execution_information: Default::default(),
test_case_information: Default::default(),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct MetadataFileReport {
/// Metrics from the execution.
#[serde(skip_serializing_if = "Option::is_none")]
pub metrics: Option<Metrics>,
/// The report of each case keyed by the case idx.
pub case_reports: BTreeMap<CaseIdx, CaseReport>,
}
#[serde_as]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct CaseReport {
/// Metrics from the execution.
#[serde(skip_serializing_if = "Option::is_none")]
pub metrics: Option<Metrics>,
/// The [`ExecutionReport`] for each one of the [`Mode`]s.
#[serde_as(as = "HashMap<DisplayFromStr, _>")]
pub mode_execution_reports: HashMap<Mode, ExecutionReport>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct ExecutionReport {
pub struct TestCaseReport {
/// Information on the status of the test case and whether it succeeded, failed, or was ignored.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<TestCaseStatus>,
/// Metrics from the execution.
#[serde(skip_serializing_if = "Option::is_none")]
pub metrics: Option<Metrics>,
/// Information related to the execution on one of the platforms.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub platform_execution: PlatformKeyedInformation<Option<ExecutionInformation>>,
/// Information on the compiled contracts.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub compiled_contracts: BTreeMap<PathBuf, BTreeMap<String, ContractInformation>>,
/// The addresses of the deployed contracts
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub contract_addresses: BTreeMap<ContractInstance, PlatformKeyedInformation<Vec<Address>>>,
/// Information on the mined blocks as part of this execution.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub mined_block_information: PlatformKeyedInformation<Vec<MinedBlockInformation>>,
/// Information tracked for each step that was executed.
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub steps: BTreeMap<StepPath, StepReport>,
pub platform_execution: BTreeMap<PlatformIdentifier, Option<ExecutionInformation>>,
}
/// Information related to the status of the test. Could be that the test succeeded, failed, or that
@@ -721,237 +545,3 @@ pub enum CompilationStatus {
compiler_input: Option<CompilerInput>,
},
}
/// Information on each step in the execution.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct StepReport {
/// Information on the transactions submitted as part of this step.
transactions: PlatformKeyedInformation<Vec<TransactionInformation>>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TransactionInformation {
/// The hash of the transaction
pub transaction_hash: TxHash,
pub submission_timestamp: u64,
pub block_timestamp: u64,
pub block_number: BlockNumber,
}
/// The metrics we collect for our benchmarks.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Metrics {
pub transaction_per_second: Metric<u64>,
pub gas_per_second: Metric<u64>,
/* Block Fullness */
pub gas_block_fullness: Metric<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ref_time_block_fullness: Option<Metric<u64>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proof_size_block_fullness: Option<Metric<u64>>,
}
/// The data that we store for a given metric (e.g., TPS).
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Metric<T> {
#[serde(skip_serializing_if = "Option::is_none")]
pub minimum: Option<PlatformKeyedInformation<T>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub maximum: Option<PlatformKeyedInformation<T>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mean: Option<PlatformKeyedInformation<T>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub median: Option<PlatformKeyedInformation<T>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub raw: Option<PlatformKeyedInformation<Vec<T>>>,
}
impl<T> Metric<T>
where
T: Default
+ Copy
+ Ord
+ PartialOrd
+ Add<Output = T>
+ Div<Output = T>
+ TryFrom<usize, Error: std::fmt::Debug>,
{
pub fn new() -> Self {
Default::default()
}
pub fn platform_identifiers(&self) -> BTreeSet<PlatformIdentifier> {
self.minimum
.as_ref()
.map(|m| m.keys())
.into_iter()
.flatten()
.chain(
self.maximum
.as_ref()
.map(|m| m.keys())
.into_iter()
.flatten(),
)
.chain(self.mean.as_ref().map(|m| m.keys()).into_iter().flatten())
.chain(self.median.as_ref().map(|m| m.keys()).into_iter().flatten())
.chain(self.raw.as_ref().map(|m| m.keys()).into_iter().flatten())
.copied()
.collect()
}
pub fn with_list(
&mut self,
platform_identifier: PlatformIdentifier,
mut list: Vec<T>,
) -> &mut Self {
list.sort();
let Some(min) = list.first().copied() else {
return self;
};
let Some(max) = list.last().copied() else {
return self;
};
let sum = list.iter().fold(T::default(), |acc, num| acc + *num);
let mean = sum / TryInto::<T>::try_into(list.len()).unwrap();
let median = match list.len().is_multiple_of(2) {
true => {
let idx = list.len() / 2;
let val1 = *list.get(idx - 1).unwrap();
let val2 = *list.get(idx).unwrap();
(val1 + val2) / TryInto::<T>::try_into(2usize).unwrap()
}
false => {
let idx = list.len() / 2;
*list.get(idx).unwrap()
}
};
self.minimum
.get_or_insert_default()
.insert(platform_identifier, min);
self.maximum
.get_or_insert_default()
.insert(platform_identifier, max);
self.mean
.get_or_insert_default()
.insert(platform_identifier, mean);
self.median
.get_or_insert_default()
.insert(platform_identifier, median);
self.raw
.get_or_insert_default()
.insert(platform_identifier, list);
self
}
pub fn combine(&self, other: &Self) -> Self {
let mut platform_identifiers = self.platform_identifiers();
platform_identifiers.extend(other.platform_identifiers());
let mut this = Self::new();
for platform_identifier in platform_identifiers {
let mut l1 = self
.raw
.as_ref()
.and_then(|m| m.get(&platform_identifier))
.cloned()
.unwrap_or_default();
let l2 = other
.raw
.as_ref()
.and_then(|m| m.get(&platform_identifier))
.cloned()
.unwrap_or_default();
l1.extend(l2);
this.with_list(platform_identifier, l1);
}
this
}
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct ContractInformation {
/// The size of the contract on the various platforms.
pub contract_size: PlatformKeyedInformation<usize>,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct MinedBlockInformation {
pub ethereum_block_information: EthereumMinedBlockInformation,
pub substrate_block_information: Option<SubstrateMinedBlockInformation>,
}
impl MinedBlockInformation {
pub fn gas_block_fullness_percentage(&self) -> u8 {
self.ethereum_block_information
.gas_block_fullness_percentage()
}
pub fn ref_time_block_fullness_percentage(&self) -> Option<u8> {
self.substrate_block_information
.as_ref()
.map(|block| block.ref_time_block_fullness_percentage())
}
pub fn proof_size_block_fullness_percentage(&self) -> Option<u8> {
self.substrate_block_information
.as_ref()
.map(|block| block.proof_size_block_fullness_percentage())
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct EthereumMinedBlockInformation {
/// The block number.
pub block_number: BlockNumber,
/// The block timestamp.
pub block_timestamp: BlockTimestamp,
/// The amount of gas mined in the block.
pub mined_gas: u128,
/// The gas limit of the block.
pub block_gas_limit: u128,
/// The hashes of the transactions that were mined as part of the block.
pub transaction_hashes: Vec<TxHash>,
}
impl EthereumMinedBlockInformation {
pub fn gas_block_fullness_percentage(&self) -> u8 {
(self.mined_gas * 100 / self.block_gas_limit) as u8
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct SubstrateMinedBlockInformation {
/// The ref time for substrate based chains.
pub ref_time: u128,
/// The max ref time for substrate based chains.
pub max_ref_time: u64,
/// The proof size for substrate based chains.
pub proof_size: u128,
/// The max proof size for substrate based chains.
pub max_proof_size: u64,
}
impl SubstrateMinedBlockInformation {
pub fn ref_time_block_fullness_percentage(&self) -> u8 {
(self.ref_time * 100 / self.max_ref_time as u128) as u8
}
pub fn proof_size_block_fullness_percentage(&self) -> u8 {
(self.proof_size * 100 / self.max_proof_size as u128) as u8
}
}
/// Information keyed by the platform identifier.
pub type PlatformKeyedInformation<T> = BTreeMap<PlatformIdentifier, T>;
+7 -42
View File
@@ -6,16 +6,14 @@ use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
use alloy::primitives::Address;
use anyhow::Context as _;
use indexmap::IndexMap;
use revive_dt_common::types::ParsedTestSpecifier;
use revive_dt_common::types::PlatformIdentifier;
use revive_dt_compiler::{CompilerInput, CompilerOutput};
use revive_dt_format::metadata::ContractInstance;
use revive_dt_format::metadata::Metadata;
use revive_dt_format::steps::StepPath;
use semver::Version;
use tokio::sync::{broadcast, oneshot};
use crate::MinedBlockInformation;
use crate::TransactionInformation;
use crate::{ExecutionSpecifier, ReporterEvent, TestSpecifier, common::MetadataFilePath};
macro_rules! __report_gen_emit_test_specific {
@@ -347,16 +345,6 @@ macro_rules! define_event {
),*
}
impl $ident {
pub fn variant_name(&self) -> &'static str {
match self {
$(
Self::$variant_ident { .. } => stringify!($variant_ident)
),*
}
}
}
$(
#[derive(Debug)]
$(#[$variant_meta])*
@@ -493,6 +481,11 @@ define_event! {
/// The channel that the aggregator is to send the receive side of the channel on.
tx: oneshot::Sender<broadcast::Receiver<ReporterEvent>>
},
/// An event emitted by runners when they've discovered a corpus file.
CorpusDiscovery {
/// The contents of the corpus file.
test_specifiers: Vec<ParsedTestSpecifier>
},
/// An event emitted by runners when they've discovered a metadata file.
MetadataFileDiscovery {
/// The path of the metadata file discovered.
@@ -622,35 +615,7 @@ define_event! {
address: Address
},
/// Reports the completion of the run.
Completion {},
/* Benchmarks Events */
/// An event emitted with information on a transaction that was submitted for a certain step
/// of the execution.
StepTransactionInformation {
/// A specifier for the execution that's taking place.
execution_specifier: Arc<ExecutionSpecifier>,
/// The path of the step that this transaction belongs to.
step_path: StepPath,
/// Information about the transaction
transaction_information: TransactionInformation
},
ContractInformation {
/// A specifier for the execution that's taking place.
execution_specifier: Arc<ExecutionSpecifier>,
/// The path of the solidity source code that contains the contract.
source_code_path: PathBuf,
/// The name of the contract
contract_name: String,
/// The size of the contract
contract_size: usize
},
BlockMined {
/// A specifier for the execution that's taking place.
execution_specifier: Arc<ExecutionSpecifier>,
/// Information on the mined block,
mined_block_information: MinedBlockInformation
}
Completion {}
}
}