mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-23 09:37:57 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed1a0a1dcd | |||
| 746f5db66f | |||
| 1400086794 | |||
| edba49b301 | |||
| 9980926d40 | |||
| ff993d44a5 | |||
| 8cbb1a9f77 |
Generated
+1
@@ -4030,6 +4030,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"semver 1.0.26",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -11,3 +11,4 @@ rust-version.workspace = true
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
semver = { workspace = true }
|
||||
tokio = { workspace = true, default-features = false, features = ["time"] }
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
mod poll;
|
||||
|
||||
pub use poll::*;
|
||||
@@ -0,0 +1,69 @@
|
||||
use std::ops::ControlFlow;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{Result, anyhow};
|
||||
|
||||
const EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION: Duration = Duration::from_secs(60);
|
||||
|
||||
/// A function that polls for a fallible future for some period of time and errors if it fails to
|
||||
/// get a result after polling.
|
||||
///
|
||||
/// Given a future that returns a [`Result<ControlFlow<O, ()>>`], this function calls the future
|
||||
/// repeatedly (with some wait period) until the future returns a [`ControlFlow::Break`] or until it
|
||||
/// returns an [`Err`] in which case the function stops polling and returns the error.
|
||||
///
|
||||
/// If the future keeps returning [`ControlFlow::Continue`] and fails to return a [`Break`] within
|
||||
/// the permitted polling duration then this function returns an [`Err`]
|
||||
///
|
||||
/// [`Break`]: ControlFlow::Break
|
||||
/// [`Continue`]: ControlFlow::Continue
|
||||
pub async fn poll<F, O>(
|
||||
polling_duration: Duration,
|
||||
polling_wait_behavior: PollingWaitBehavior,
|
||||
mut future: impl FnMut() -> F,
|
||||
) -> Result<O>
|
||||
where
|
||||
F: Future<Output = Result<ControlFlow<O, ()>>>,
|
||||
{
|
||||
let mut retries = 0;
|
||||
let mut total_wait_duration = Duration::ZERO;
|
||||
let max_allowed_wait_duration = polling_duration;
|
||||
|
||||
loop {
|
||||
if total_wait_duration >= max_allowed_wait_duration {
|
||||
break Err(anyhow!(
|
||||
"Polling failed after {} retries and a total of {:?} of wait time",
|
||||
retries,
|
||||
total_wait_duration
|
||||
));
|
||||
}
|
||||
|
||||
match future().await? {
|
||||
ControlFlow::Continue(()) => {
|
||||
let next_wait_duration = match polling_wait_behavior {
|
||||
PollingWaitBehavior::Constant(duration) => duration,
|
||||
PollingWaitBehavior::ExponentialBackoff => {
|
||||
Duration::from_secs(2u64.pow(retries))
|
||||
.min(EXPONENTIAL_BACKOFF_MAX_WAIT_DURATION)
|
||||
}
|
||||
};
|
||||
let next_wait_duration =
|
||||
next_wait_duration.min(max_allowed_wait_duration - total_wait_duration);
|
||||
total_wait_duration += next_wait_duration;
|
||||
retries += 1;
|
||||
|
||||
tokio::time::sleep(next_wait_duration).await;
|
||||
}
|
||||
ControlFlow::Break(output) => {
|
||||
break Ok(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
pub enum PollingWaitBehavior {
|
||||
Constant(Duration),
|
||||
#[default]
|
||||
ExponentialBackoff,
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! the workspace can benefit from.
|
||||
|
||||
pub mod fs;
|
||||
pub mod futures;
|
||||
pub mod iterators;
|
||||
pub mod macros;
|
||||
pub mod types;
|
||||
|
||||
@@ -238,4 +238,25 @@ mod test {
|
||||
Version::new(0, 7, 6)
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn compiler_version_can_be_obtained1() {
|
||||
// Arrange
|
||||
let args = Arguments::default();
|
||||
println!("Getting compiler path");
|
||||
let path = Solc::get_compiler_executable(&args, Version::new(0, 4, 21))
|
||||
.await
|
||||
.unwrap();
|
||||
println!("Got compiler path");
|
||||
let compiler = Solc::new(path);
|
||||
|
||||
// Act
|
||||
let version = compiler.version();
|
||||
|
||||
// Assert
|
||||
assert_eq!(
|
||||
version.expect("Failed to get version"),
|
||||
Version::new(0, 4, 21)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ pub struct Arguments {
|
||||
/// This argument controls which private keys the nodes should have access to and be added to
|
||||
/// its wallet signers. With a value of N, private keys (0, N] will be added to the signer set
|
||||
/// of the node.
|
||||
#[arg(long = "private-keys-count", default_value_t = 15_000)]
|
||||
#[arg(long = "private-keys-count", default_value_t = 100_000)]
|
||||
pub private_keys_to_add: usize,
|
||||
|
||||
/// The differential testing leader node implementation.
|
||||
|
||||
@@ -4,9 +4,11 @@ use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use alloy::eips::BlockNumberOrTag;
|
||||
use alloy::hex;
|
||||
use alloy::json_abi::JsonAbi;
|
||||
use alloy::network::{Ethereum, TransactionBuilder};
|
||||
use alloy::primitives::U256;
|
||||
use alloy::primitives::{BlockNumber, U256};
|
||||
use alloy::rpc::types::TransactionReceipt;
|
||||
use alloy::rpc::types::trace::geth::{
|
||||
CallFrame, GethDebugBuiltInTracerType, GethDebugTracerType, GethDebugTracingOptions, GethTrace,
|
||||
@@ -21,6 +23,7 @@ use alloy::{
|
||||
};
|
||||
use anyhow::Context;
|
||||
use indexmap::IndexMap;
|
||||
use revive_dt_format::traits::ResolverApi;
|
||||
use semver::Version;
|
||||
|
||||
use revive_dt_format::case::{Case, CaseIdx};
|
||||
@@ -29,6 +32,7 @@ use revive_dt_format::metadata::{ContractInstance, ContractPathAndIdent};
|
||||
use revive_dt_format::{input::Input, metadata::Metadata};
|
||||
use revive_dt_node::Node;
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use tracing::Instrument;
|
||||
|
||||
use crate::Platform;
|
||||
|
||||
@@ -84,7 +88,13 @@ where
|
||||
.handle_input_call_frame_tracing(&execution_receipt, node)
|
||||
.await?;
|
||||
self.handle_input_variable_assignment(input, &tracing_result)?;
|
||||
self.handle_input_expectations(input, &execution_receipt, node, &tracing_result)
|
||||
let resolver = BlockPinnedResolver::<'_, T> {
|
||||
node,
|
||||
block_number: execution_receipt
|
||||
.block_number
|
||||
.context("Transaction was not included in a block")?,
|
||||
};
|
||||
self.handle_input_expectations(input, &execution_receipt, &resolver, &tracing_result)
|
||||
.await?;
|
||||
self.handle_input_diff(case_idx, execution_receipt, node)
|
||||
.await
|
||||
@@ -233,6 +243,11 @@ where
|
||||
) {
|
||||
let value = U256::from_be_slice(output_word);
|
||||
self.variables.insert(variable_name.clone(), value);
|
||||
tracing::info!(
|
||||
variable_name,
|
||||
variable_value = hex::encode(value.to_be_bytes::<32>()),
|
||||
"Assigned variable"
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -242,7 +257,7 @@ where
|
||||
&mut self,
|
||||
input: &Input,
|
||||
execution_receipt: &TransactionReceipt,
|
||||
node: &T::Blockchain,
|
||||
resolver: &impl ResolverApi,
|
||||
tracing_result: &CallFrame,
|
||||
) -> anyhow::Result<()> {
|
||||
let span = tracing::info_span!("Handling input expectations");
|
||||
@@ -279,7 +294,7 @@ where
|
||||
for expectation in expectations.iter() {
|
||||
self.handle_input_expectation_item(
|
||||
execution_receipt,
|
||||
node,
|
||||
resolver,
|
||||
expectation,
|
||||
tracing_result,
|
||||
)
|
||||
@@ -292,7 +307,7 @@ where
|
||||
async fn handle_input_expectation_item(
|
||||
&mut self,
|
||||
execution_receipt: &TransactionReceipt,
|
||||
node: &T::Blockchain,
|
||||
resolver: &impl ResolverApi,
|
||||
expectation: &ExpectedOutput,
|
||||
tracing_result: &CallFrame,
|
||||
) -> anyhow::Result<()> {
|
||||
@@ -304,7 +319,6 @@ where
|
||||
|
||||
let deployed_contracts = &mut self.deployed_contracts;
|
||||
let variables = &mut self.variables;
|
||||
let chain_state_provider = node;
|
||||
|
||||
// Handling the receipt state assertion.
|
||||
let expected = !expectation.exception;
|
||||
@@ -327,12 +341,7 @@ where
|
||||
let expected = expected_calldata;
|
||||
let actual = &tracing_result.output.as_ref().unwrap_or_default();
|
||||
if !expected
|
||||
.is_equivalent(
|
||||
actual,
|
||||
deployed_contracts,
|
||||
&*variables,
|
||||
chain_state_provider,
|
||||
)
|
||||
.is_equivalent(actual, deployed_contracts, &*variables, resolver)
|
||||
.await?
|
||||
{
|
||||
tracing::error!(
|
||||
@@ -358,14 +367,16 @@ where
|
||||
}
|
||||
|
||||
// Handling the events assertion.
|
||||
for (expected_event, actual_event) in
|
||||
expected_events.iter().zip(execution_receipt.logs())
|
||||
for (event_idx, (expected_event, actual_event)) in expected_events
|
||||
.iter()
|
||||
.zip(execution_receipt.logs())
|
||||
.enumerate()
|
||||
{
|
||||
// Handling the emitter assertion.
|
||||
if let Some(ref expected_address) = expected_event.address {
|
||||
let expected = Address::from_slice(
|
||||
Calldata::new_compound([expected_address])
|
||||
.calldata(deployed_contracts, &*variables, node)
|
||||
.calldata(deployed_contracts, &*variables, resolver)
|
||||
.await?
|
||||
.get(12..32)
|
||||
.expect("Can't fail"),
|
||||
@@ -373,6 +384,7 @@ where
|
||||
let actual = actual_event.address();
|
||||
if actual != expected {
|
||||
tracing::error!(
|
||||
event_idx,
|
||||
%expected,
|
||||
%actual,
|
||||
"Event emitter assertion failed",
|
||||
@@ -392,15 +404,11 @@ where
|
||||
{
|
||||
let expected = Calldata::new_compound([expected]);
|
||||
if !expected
|
||||
.is_equivalent(
|
||||
&actual.0,
|
||||
deployed_contracts,
|
||||
&*variables,
|
||||
chain_state_provider,
|
||||
)
|
||||
.is_equivalent(&actual.0, deployed_contracts, &*variables, resolver)
|
||||
.await?
|
||||
{
|
||||
tracing::error!(
|
||||
event_idx,
|
||||
?execution_receipt,
|
||||
?expected,
|
||||
?actual,
|
||||
@@ -416,15 +424,11 @@ where
|
||||
let expected = &expected_event.values;
|
||||
let actual = &actual_event.data().data;
|
||||
if !expected
|
||||
.is_equivalent(
|
||||
&actual.0,
|
||||
deployed_contracts,
|
||||
&*variables,
|
||||
chain_state_provider,
|
||||
)
|
||||
.is_equivalent(&actual.0, deployed_contracts, &*variables, resolver)
|
||||
.await?
|
||||
{
|
||||
tracing::error!(
|
||||
event_idx,
|
||||
?execution_receipt,
|
||||
?expected,
|
||||
?actual,
|
||||
@@ -649,15 +653,16 @@ where
|
||||
let mut inputs_executed = 0;
|
||||
for (input_idx, input) in self.case.inputs_iterator().enumerate() {
|
||||
let tracing_span = tracing::info_span!("Handling input", input_idx);
|
||||
let _guard = tracing_span.enter();
|
||||
|
||||
let (leader_receipt, _, leader_diff) = self
|
||||
.leader_state
|
||||
.handle_input(self.metadata, self.case_idx, &input, self.leader_node)
|
||||
.instrument(tracing_span.clone())
|
||||
.await?;
|
||||
let (follower_receipt, _, follower_diff) = self
|
||||
.follower_state
|
||||
.handle_input(self.metadata, self.case_idx, &input, self.follower_node)
|
||||
.instrument(tracing_span)
|
||||
.await?;
|
||||
|
||||
if leader_diff == follower_diff {
|
||||
@@ -680,3 +685,67 @@ where
|
||||
Ok(inputs_executed)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BlockPinnedResolver<'a, T: Platform> {
|
||||
block_number: BlockNumber,
|
||||
node: &'a T::Blockchain,
|
||||
}
|
||||
|
||||
impl<'a, T: Platform> ResolverApi for BlockPinnedResolver<'a, T> {
|
||||
async fn chain_id(&self) -> anyhow::Result<alloy::primitives::ChainId> {
|
||||
self.node.chain_id().await
|
||||
}
|
||||
|
||||
async fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result<u128> {
|
||||
self.node
|
||||
.block_gas_limit(self.resolve_block_number_or_tag(number))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result<Address> {
|
||||
self.node
|
||||
.block_coinbase(self.resolve_block_number_or_tag(number))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result<U256> {
|
||||
self.node
|
||||
.block_difficulty(self.resolve_block_number_or_tag(number))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn block_hash(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> anyhow::Result<alloy::primitives::BlockHash> {
|
||||
self.node
|
||||
.block_hash(self.resolve_block_number_or_tag(number))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn block_timestamp(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> anyhow::Result<alloy::primitives::BlockTimestamp> {
|
||||
self.node
|
||||
.block_timestamp(self.resolve_block_number_or_tag(number))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn last_block_number(&self) -> anyhow::Result<alloy::primitives::BlockNumber> {
|
||||
Ok(self.block_number)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Platform> BlockPinnedResolver<'a, T> {
|
||||
fn resolve_block_number_or_tag(&self, number: BlockNumberOrTag) -> BlockNumberOrTag {
|
||||
match number {
|
||||
BlockNumberOrTag::Latest => BlockNumberOrTag::Number(self.block_number),
|
||||
n @ BlockNumberOrTag::Finalized
|
||||
| n @ BlockNumberOrTag::Safe
|
||||
| n @ BlockNumberOrTag::Earliest
|
||||
| n @ BlockNumberOrTag::Pending
|
||||
| n @ BlockNumberOrTag::Number(_) => n,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+231
-48
@@ -150,49 +150,196 @@ where
|
||||
})
|
||||
},
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let compilation_cache = Arc::new(RwLock::new(HashMap::new()));
|
||||
futures::stream::iter(test_cases)
|
||||
.for_each_concurrent(
|
||||
None,
|
||||
|(metadata_file_path, metadata, case_idx, case, solc_mode)| {
|
||||
let compilation_cache = compilation_cache.clone();
|
||||
let leader_node = leader_nodes.round_robbin();
|
||||
let follower_node = follower_nodes.round_robbin();
|
||||
let tracing_span = tracing::span!(
|
||||
Level::INFO,
|
||||
"Running driver",
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
case_idx = case_idx,
|
||||
solc_mode = ?solc_mode,
|
||||
);
|
||||
async move {
|
||||
let result = handle_case_driver::<L, F>(
|
||||
metadata_file_path.as_path(),
|
||||
metadata,
|
||||
case_idx.into(),
|
||||
case,
|
||||
solc_mode,
|
||||
args,
|
||||
compilation_cache.clone(),
|
||||
leader_node,
|
||||
follower_node,
|
||||
span,
|
||||
)
|
||||
.await;
|
||||
match result {
|
||||
Ok(inputs_executed) => {
|
||||
tracing::info!(inputs_executed, "Execution succeeded")
|
||||
}
|
||||
Err(error) => tracing::info!(%error, "Execution failed"),
|
||||
}
|
||||
tracing::info!("Execution completed");
|
||||
.filter(
|
||||
|(metadata_file_path, metadata, _, _, _)| match metadata.ignore {
|
||||
Some(true) => {
|
||||
tracing::warn!(
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
"Ignoring metadata file"
|
||||
);
|
||||
false
|
||||
}
|
||||
.instrument(tracing_span)
|
||||
Some(false) | None => true,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
.filter(
|
||||
|(metadata_file_path, _, case_idx, case, _)| match case.ignore {
|
||||
Some(true) => {
|
||||
tracing::warn!(
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
case_idx,
|
||||
case_name = ?case.name,
|
||||
"Ignoring case"
|
||||
);
|
||||
false
|
||||
}
|
||||
Some(false) | None => true,
|
||||
},
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let metadata_case_status = Arc::new(RwLock::new(test_cases.iter().fold(
|
||||
HashMap::<_, HashMap<_, _>>::new(),
|
||||
|mut map, (path, _, case_idx, case, solc_mode)| {
|
||||
map.entry((path.to_path_buf(), solc_mode.clone()))
|
||||
.or_default()
|
||||
.insert((CaseIdx::new(*case_idx), case.name.clone()), None::<bool>);
|
||||
map
|
||||
},
|
||||
)));
|
||||
let status_reporter_task = {
|
||||
let metadata_case_status = metadata_case_status.clone();
|
||||
async move {
|
||||
const GREEN: &str = "\x1B[32m";
|
||||
const RED: &str = "\x1B[31m";
|
||||
const RESET: &str = "\x1B[0m";
|
||||
|
||||
let mut entries_to_delete = Vec::new();
|
||||
let mut number_of_successes = 0;
|
||||
let mut number_of_failures = 0;
|
||||
loop {
|
||||
let metadata_case_status_read = metadata_case_status.read().await;
|
||||
if metadata_case_status_read.is_empty() {
|
||||
break;
|
||||
}
|
||||
|
||||
for ((metadata_file_path, solc_mode), case_status) in
|
||||
metadata_case_status_read.iter()
|
||||
{
|
||||
if case_status.values().any(|value| value.is_none()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let contains_failures = case_status
|
||||
.values()
|
||||
.any(|value| value.is_some_and(|value| !value));
|
||||
|
||||
if !contains_failures {
|
||||
eprintln!(
|
||||
"{}Succeeded:{} {} - {:?}",
|
||||
GREEN,
|
||||
RESET,
|
||||
metadata_file_path.display(),
|
||||
solc_mode
|
||||
)
|
||||
} else {
|
||||
eprintln!(
|
||||
"{}Failed:{} {} - {:?}",
|
||||
RED,
|
||||
RESET,
|
||||
metadata_file_path.display(),
|
||||
solc_mode
|
||||
)
|
||||
};
|
||||
|
||||
number_of_successes += case_status
|
||||
.values()
|
||||
.filter(|value| value.is_some_and(|value| value))
|
||||
.count();
|
||||
number_of_failures += case_status
|
||||
.values()
|
||||
.filter(|value| value.is_some_and(|value| !value))
|
||||
.count();
|
||||
|
||||
let mut case_status = case_status
|
||||
.iter()
|
||||
.map(|((case_idx, case_name), case_status)| {
|
||||
(case_idx.into_inner(), case_name, case_status.unwrap())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
case_status.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
for (case_idx, case_name, case_status) in case_status.into_iter() {
|
||||
if case_status {
|
||||
eprintln!(
|
||||
" {GREEN}Case Succeeded:{RESET} {} - Case Idx: {case_idx}",
|
||||
case_name
|
||||
.as_ref()
|
||||
.map(|string| string.as_str())
|
||||
.unwrap_or("Unnamed case")
|
||||
)
|
||||
} else {
|
||||
eprintln!(
|
||||
" {RED}Case Failed:{RESET} {} - Case Idx: {case_idx}",
|
||||
case_name
|
||||
.as_ref()
|
||||
.map(|string| string.as_str())
|
||||
.unwrap_or("Unnamed case")
|
||||
)
|
||||
};
|
||||
}
|
||||
eprintln!();
|
||||
|
||||
entries_to_delete.push((metadata_file_path.clone(), solc_mode.clone()));
|
||||
}
|
||||
|
||||
drop(metadata_case_status_read);
|
||||
let mut metadata_case_status_write = metadata_case_status.write().await;
|
||||
for entry in entries_to_delete.drain(..) {
|
||||
metadata_case_status_write.remove(&entry);
|
||||
}
|
||||
|
||||
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
|
||||
}
|
||||
|
||||
eprintln!(
|
||||
"{GREEN}{number_of_successes}{RESET} cases succeeded, {RED}{number_of_failures}{RESET} cases failed"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let compilation_cache = Arc::new(RwLock::new(HashMap::new()));
|
||||
let driver_task = futures::stream::iter(test_cases).for_each_concurrent(
|
||||
None,
|
||||
|(metadata_file_path, metadata, case_idx, case, solc_mode)| {
|
||||
let compilation_cache = compilation_cache.clone();
|
||||
let leader_node = leader_nodes.round_robbin();
|
||||
let follower_node = follower_nodes.round_robbin();
|
||||
let tracing_span = tracing::span!(
|
||||
Level::INFO,
|
||||
"Running driver",
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
case_idx = case_idx,
|
||||
solc_mode = ?solc_mode,
|
||||
);
|
||||
let metadata_case_status = metadata_case_status.clone();
|
||||
async move {
|
||||
let result = handle_case_driver::<L, F>(
|
||||
metadata_file_path.as_path(),
|
||||
metadata,
|
||||
case_idx.into(),
|
||||
case,
|
||||
solc_mode.clone(),
|
||||
args,
|
||||
compilation_cache.clone(),
|
||||
leader_node,
|
||||
follower_node,
|
||||
span,
|
||||
)
|
||||
.await;
|
||||
let mut metadata_case_status = metadata_case_status.write().await;
|
||||
match result {
|
||||
Ok(inputs_executed) => {
|
||||
tracing::info!(inputs_executed, "Execution succeeded");
|
||||
metadata_case_status
|
||||
.entry((metadata_file_path.clone(), solc_mode))
|
||||
.or_default()
|
||||
.insert((CaseIdx::new(case_idx), case.name.clone()), Some(true));
|
||||
}
|
||||
Err(error) => {
|
||||
metadata_case_status
|
||||
.entry((metadata_file_path.clone(), solc_mode))
|
||||
.or_default()
|
||||
.insert((CaseIdx::new(case_idx), case.name.clone()), Some(false));
|
||||
tracing::error!(%error, "Execution failed")
|
||||
}
|
||||
}
|
||||
tracing::info!("Execution completed");
|
||||
}
|
||||
.instrument(tracing_span)
|
||||
},
|
||||
);
|
||||
|
||||
tokio::join!(status_reporter_task, driver_task);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -330,6 +477,17 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
tracing::info!(
|
||||
?library_instance,
|
||||
library_address = ?leader_receipt.contract_address,
|
||||
"Deployed library to leader"
|
||||
);
|
||||
tracing::info!(
|
||||
?library_instance,
|
||||
library_address = ?follower_receipt.contract_address,
|
||||
"Deployed library to follower"
|
||||
);
|
||||
|
||||
let Some(leader_library_address) = leader_receipt.contract_address else {
|
||||
tracing::error!("Contract deployment transaction didn't return an address");
|
||||
anyhow::bail!("Contract deployment didn't return an address");
|
||||
@@ -439,7 +597,14 @@ async fn get_or_build_contracts<'a, P: Platform>(
|
||||
None => {
|
||||
tracing::debug!(?key, "Compiled contracts cache miss");
|
||||
let compiled_contracts = Arc::new(
|
||||
compile_contracts::<P>(metadata, &mode, config, deployed_libraries).await?,
|
||||
compile_contracts::<P>(
|
||||
metadata,
|
||||
metadata_file_path,
|
||||
&mode,
|
||||
config,
|
||||
deployed_libraries,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
*compilation_artifact = Some(compiled_contracts.clone());
|
||||
return Ok(compiled_contracts.clone());
|
||||
@@ -455,14 +620,23 @@ async fn get_or_build_contracts<'a, P: Platform>(
|
||||
mutex
|
||||
};
|
||||
let mut compilation_artifact = mutex.lock().await;
|
||||
let compiled_contracts =
|
||||
Arc::new(compile_contracts::<P>(metadata, &mode, config, deployed_libraries).await?);
|
||||
let compiled_contracts = Arc::new(
|
||||
compile_contracts::<P>(
|
||||
metadata,
|
||||
metadata_file_path,
|
||||
&mode,
|
||||
config,
|
||||
deployed_libraries,
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
*compilation_artifact = Some(compiled_contracts.clone());
|
||||
Ok(compiled_contracts.clone())
|
||||
}
|
||||
|
||||
async fn compile_contracts<P: Platform>(
|
||||
metadata: &Metadata,
|
||||
metadata_file_path: &Path,
|
||||
mode: &SolcMode,
|
||||
config: &Arguments,
|
||||
deployed_libraries: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
@@ -472,6 +646,13 @@ async fn compile_contracts<P: Platform>(
|
||||
P::Compiler::get_compiler_executable(config, compiler_version_or_requirement).await?;
|
||||
let compiler_version = P::Compiler::new(compiler_path.clone()).version()?;
|
||||
|
||||
tracing::info!(
|
||||
%compiler_version,
|
||||
metadata_file_path = %metadata_file_path.display(),
|
||||
mode = ?mode,
|
||||
"Compiling contracts"
|
||||
);
|
||||
|
||||
let compiler = Compiler::<P::Compiler>::new()
|
||||
.with_allow_path(metadata.directory()?)
|
||||
.with_optimization(mode.solc_optimize());
|
||||
@@ -486,11 +667,11 @@ async fn compile_contracts<P: Platform>(
|
||||
.expect("Impossible for library to not be found in contracts")
|
||||
.contract_ident;
|
||||
|
||||
// Note the following: we need to tell solc which files require the libraries to be
|
||||
// linked into them. We do not have access to this information and therefore we choose
|
||||
// an easier, yet more compute intensive route, of telling solc that all of the files
|
||||
// need to link the library and it will only perform the linking for the files that do
|
||||
// actually need the library.
|
||||
// Note the following: we need to tell solc which files require the libraries to be linked
|
||||
// into them. We do not have access to this information and therefore we choose an easier,
|
||||
// yet more compute intensive route, of telling solc that all of the files need to link the
|
||||
// library and it will only perform the linking for the files that do actually need the
|
||||
// library.
|
||||
compiler = FilesWithExtensionIterator::new(metadata.directory()?)
|
||||
.with_allowed_extension("sol")
|
||||
.fold(compiler, |compiler, path| {
|
||||
@@ -540,6 +721,7 @@ async fn compile_corpus(
|
||||
TestingPlatform::Geth => {
|
||||
let _ = compile_contracts::<Geth>(
|
||||
&metadata.content,
|
||||
&metadata.path,
|
||||
&mode,
|
||||
config,
|
||||
&Default::default(),
|
||||
@@ -549,6 +731,7 @@ async fn compile_corpus(
|
||||
TestingPlatform::Kitchensink => {
|
||||
let _ = compile_contracts::<Geth>(
|
||||
&metadata.content,
|
||||
&metadata.path,
|
||||
&mode,
|
||||
config,
|
||||
&Default::default(),
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct Case {
|
||||
pub inputs: Vec<Input>,
|
||||
pub group: Option<String>,
|
||||
pub expected: Option<Expected>,
|
||||
pub ignore: Option<bool>,
|
||||
}
|
||||
|
||||
impl Case {
|
||||
|
||||
+26
-45
@@ -202,13 +202,13 @@ impl Input {
|
||||
&'a self,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<Bytes> {
|
||||
match self.method {
|
||||
Method::Deployer | Method::Fallback => {
|
||||
let calldata = self
|
||||
.calldata
|
||||
.calldata(deployed_contracts, variables, chain_state_provider)
|
||||
.calldata(deployed_contracts, variables, resolver)
|
||||
.await?;
|
||||
|
||||
Ok(calldata.into())
|
||||
@@ -256,12 +256,7 @@ impl Input {
|
||||
let mut calldata = Vec::<u8>::with_capacity(4 + self.calldata.size_requirement());
|
||||
calldata.extend(function.selector().0);
|
||||
self.calldata
|
||||
.calldata_into_slice(
|
||||
&mut calldata,
|
||||
deployed_contracts,
|
||||
variables,
|
||||
chain_state_provider,
|
||||
)
|
||||
.calldata_into_slice(&mut calldata, deployed_contracts, variables, resolver)
|
||||
.await?;
|
||||
|
||||
Ok(calldata.into())
|
||||
@@ -274,10 +269,10 @@ impl Input {
|
||||
&'a self,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<TransactionRequest> {
|
||||
let input_data = self
|
||||
.encoded_input(deployed_contracts, variables, chain_state_provider)
|
||||
.encoded_input(deployed_contracts, variables, resolver)
|
||||
.await?;
|
||||
let transaction_request = TransactionRequest::default().from(self.caller).value(
|
||||
self.value
|
||||
@@ -360,16 +355,11 @@ impl Calldata {
|
||||
&'a self,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<Vec<u8>> {
|
||||
let mut buffer = Vec::<u8>::with_capacity(self.size_requirement());
|
||||
self.calldata_into_slice(
|
||||
&mut buffer,
|
||||
deployed_contracts,
|
||||
variables,
|
||||
chain_state_provider,
|
||||
)
|
||||
.await?;
|
||||
self.calldata_into_slice(&mut buffer, deployed_contracts, variables, resolver)
|
||||
.await?;
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
@@ -378,7 +368,7 @@ impl Calldata {
|
||||
buffer: &mut Vec<u8>,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<()> {
|
||||
match self {
|
||||
Calldata::Single(bytes) => {
|
||||
@@ -387,7 +377,7 @@ impl Calldata {
|
||||
Calldata::Compound(items) => {
|
||||
for (arg_idx, arg) in items.iter().enumerate() {
|
||||
match arg
|
||||
.resolve(deployed_contracts, variables.clone(), chain_state_provider)
|
||||
.resolve(deployed_contracts, variables.clone(), resolver)
|
||||
.await
|
||||
{
|
||||
Ok(resolved) => {
|
||||
@@ -417,7 +407,7 @@ impl Calldata {
|
||||
other: &[u8],
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<bool> {
|
||||
match self {
|
||||
Calldata::Single(calldata) => Ok(calldata == other),
|
||||
@@ -440,7 +430,7 @@ impl Calldata {
|
||||
};
|
||||
|
||||
let this = this
|
||||
.resolve(deployed_contracts, variables.clone(), chain_state_provider)
|
||||
.resolve(deployed_contracts, variables.clone(), resolver)
|
||||
.await?;
|
||||
let other = U256::from_be_slice(&other);
|
||||
if this != other {
|
||||
@@ -458,13 +448,13 @@ impl CalldataItem {
|
||||
&'a self,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<U256> {
|
||||
let mut stack = Vec::<CalldataToken<U256>>::new();
|
||||
|
||||
for token in self
|
||||
.calldata_tokens()
|
||||
.map(|token| token.resolve(deployed_contracts, variables.clone(), chain_state_provider))
|
||||
.map(|token| token.resolve(deployed_contracts, variables.clone(), resolver))
|
||||
{
|
||||
let token = token.await?;
|
||||
let new_token = match token {
|
||||
@@ -569,7 +559,7 @@ impl<T: AsRef<str>> CalldataToken<T> {
|
||||
self,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
variables: impl Into<Option<&'a HashMap<String, U256>>> + Clone,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<CalldataToken<U256>> {
|
||||
match self {
|
||||
Self::Item(item) => {
|
||||
@@ -599,22 +589,17 @@ impl<T: AsRef<str>> CalldataToken<T> {
|
||||
anyhow::anyhow!("Invalid hexadecimal literal: {}", error)
|
||||
})?)
|
||||
} else if item == Self::CHAIN_VARIABLE {
|
||||
let chain_id = chain_state_provider.chain_id().await?;
|
||||
let chain_id = resolver.chain_id().await?;
|
||||
Ok(U256::from(chain_id))
|
||||
} else if item == Self::GAS_LIMIT_VARIABLE {
|
||||
let gas_limit = chain_state_provider
|
||||
.block_gas_limit(BlockNumberOrTag::Latest)
|
||||
.await?;
|
||||
let gas_limit = resolver.block_gas_limit(BlockNumberOrTag::Latest).await?;
|
||||
Ok(U256::from(gas_limit))
|
||||
} else if item == Self::COINBASE_VARIABLE {
|
||||
let coinbase = chain_state_provider
|
||||
.block_coinbase(BlockNumberOrTag::Latest)
|
||||
.await?;
|
||||
let coinbase = resolver.block_coinbase(BlockNumberOrTag::Latest).await?;
|
||||
Ok(U256::from_be_slice(coinbase.as_ref()))
|
||||
} else if item == Self::DIFFICULTY_VARIABLE {
|
||||
let block_difficulty = chain_state_provider
|
||||
.block_difficulty(BlockNumberOrTag::Latest)
|
||||
.await?;
|
||||
let block_difficulty =
|
||||
resolver.block_difficulty(BlockNumberOrTag::Latest).await?;
|
||||
Ok(block_difficulty)
|
||||
} else if item.starts_with(Self::BLOCK_HASH_VARIABLE_PREFIX) {
|
||||
let offset: u64 = item
|
||||
@@ -623,21 +608,17 @@ impl<T: AsRef<str>> CalldataToken<T> {
|
||||
.and_then(|value| value.parse().ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
let current_block_number = chain_state_provider.last_block_number().await?;
|
||||
let current_block_number = resolver.last_block_number().await?;
|
||||
let desired_block_number = current_block_number - offset;
|
||||
|
||||
let block_hash = chain_state_provider
|
||||
.block_hash(desired_block_number.into())
|
||||
.await?;
|
||||
let block_hash = resolver.block_hash(desired_block_number.into()).await?;
|
||||
|
||||
Ok(U256::from_be_bytes(block_hash.0))
|
||||
} else if item == Self::BLOCK_NUMBER_VARIABLE {
|
||||
let current_block_number = chain_state_provider.last_block_number().await?;
|
||||
let current_block_number = resolver.last_block_number().await?;
|
||||
Ok(U256::from(current_block_number))
|
||||
} else if item == Self::BLOCK_TIMESTAMP_VARIABLE {
|
||||
let timestamp = chain_state_provider
|
||||
.block_timestamp(BlockNumberOrTag::Latest)
|
||||
.await?;
|
||||
let timestamp = resolver.block_timestamp(BlockNumberOrTag::Latest).await?;
|
||||
Ok(U256::from(timestamp))
|
||||
} else if let Some(variable_name) = item.strip_prefix(Self::VARIABLE_PREFIX) {
|
||||
let Some(variables) = variables.into() else {
|
||||
@@ -882,10 +863,10 @@ mod tests {
|
||||
async fn resolve_calldata_item(
|
||||
input: &str,
|
||||
deployed_contracts: &HashMap<ContractInstance, (Address, JsonAbi)>,
|
||||
chain_state_provider: &impl ResolverApi,
|
||||
resolver: &impl ResolverApi,
|
||||
) -> anyhow::Result<U256> {
|
||||
CalldataItem::new(input)
|
||||
.resolve(deployed_contracts, None, chain_state_provider)
|
||||
.resolve(deployed_contracts, None, resolver)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
+74
-55
@@ -3,9 +3,13 @@
|
||||
use std::{
|
||||
fs::{File, OpenOptions, create_dir_all, remove_dir_all},
|
||||
io::{BufRead, BufReader, Read, Write},
|
||||
ops::ControlFlow,
|
||||
path::PathBuf,
|
||||
process::{Child, Command, Stdio},
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicU32, Ordering},
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
@@ -25,11 +29,12 @@ use alloy::{
|
||||
},
|
||||
signers::local::PrivateKeySigner,
|
||||
};
|
||||
use revive_dt_common::fs::clear_directory;
|
||||
use tracing::{Instrument, Level};
|
||||
|
||||
use revive_dt_common::{fs::clear_directory, futures::poll};
|
||||
use revive_dt_config::Arguments;
|
||||
use revive_dt_format::traits::ResolverApi;
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use tracing::Level;
|
||||
|
||||
use crate::{Node, common::FallbackGasFiller, constants::INITIAL_BALANCE};
|
||||
|
||||
@@ -77,6 +82,10 @@ impl GethNode {
|
||||
const GETH_STDERR_LOG_FILE_NAME: &str = "node_stderr.log";
|
||||
|
||||
const TRANSACTION_INDEXING_ERROR: &str = "transaction indexing is in progress";
|
||||
const TRANSACTION_TRACING_ERROR: &str = "historical state not available in path scheme yet";
|
||||
|
||||
const RECEIPT_POLLING_DURATION: Duration = Duration::from_secs(5 * 60);
|
||||
const TRACE_POLLING_DURATION: Duration = Duration::from_secs(60);
|
||||
|
||||
/// Create the node directory and call `geth init` to configure the genesis.
|
||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||
@@ -102,6 +111,8 @@ impl GethNode {
|
||||
serde_json::to_writer(File::create(&genesis_path)?, &genesis)?;
|
||||
|
||||
let mut child = Command::new(&self.geth)
|
||||
.arg("--state.scheme")
|
||||
.arg("hash")
|
||||
.arg("init")
|
||||
.arg("--datadir")
|
||||
.arg(&self.data_directory)
|
||||
@@ -159,6 +170,12 @@ impl GethNode {
|
||||
.arg("0")
|
||||
.arg("--cache.blocklogs")
|
||||
.arg("512")
|
||||
.arg("--state.scheme")
|
||||
.arg("hash")
|
||||
.arg("--syncmode")
|
||||
.arg("full")
|
||||
.arg("--gcmode")
|
||||
.arg("archive")
|
||||
.stderr(stderr_logs_file.try_clone()?)
|
||||
.stdout(stdout_logs_file.try_clone()?)
|
||||
.spawn()?
|
||||
@@ -248,22 +265,17 @@ impl GethNode {
|
||||
}
|
||||
|
||||
impl EthereumNode for GethNode {
|
||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||
async fn execute_transaction(
|
||||
&self,
|
||||
transaction: TransactionRequest,
|
||||
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
|
||||
let outer_span = tracing::debug_span!("Submitting transaction", ?transaction);
|
||||
let _outer_guard = outer_span.enter();
|
||||
|
||||
let provider = self.provider().await?;
|
||||
|
||||
let pending_transaction = provider.send_transaction(transaction).await?;
|
||||
let transaction_hash = pending_transaction.tx_hash();
|
||||
|
||||
let span = tracing::info_span!("Awaiting transaction receipt", ?transaction_hash);
|
||||
let span = tracing::debug_span!("Submitting transaction", ?transaction);
|
||||
let _guard = span.enter();
|
||||
|
||||
let provider = Arc::new(self.provider().await?);
|
||||
let transaction_hash = *provider.send_transaction(transaction).await?.tx_hash();
|
||||
|
||||
// The following is a fix for the "transaction indexing is in progress" error that we
|
||||
// used to get. You can find more information on this in the following GH issue in geth
|
||||
// https://github.com/ethereum/go-ethereum/issues/28877. To summarize what's going on,
|
||||
@@ -282,57 +294,64 @@ impl EthereumNode for GethNode {
|
||||
// allow for a larger wait time. Therefore, in here we allow for 5 minutes of waiting
|
||||
// with exponential backoff each time we attempt to get the receipt and find that it's
|
||||
// not available.
|
||||
let mut retries = 0;
|
||||
let mut total_wait_duration = Duration::from_secs(0);
|
||||
let max_allowed_wait_duration = Duration::from_secs(5 * 60);
|
||||
loop {
|
||||
if total_wait_duration >= max_allowed_wait_duration {
|
||||
tracing::error!(
|
||||
?total_wait_duration,
|
||||
?max_allowed_wait_duration,
|
||||
retry_count = retries,
|
||||
"Failed to get receipt after polling for it"
|
||||
);
|
||||
anyhow::bail!(
|
||||
"Polled for receipt for {total_wait_duration:?} but failed to get it"
|
||||
);
|
||||
}
|
||||
|
||||
match provider.get_transaction_receipt(*transaction_hash).await {
|
||||
Ok(Some(receipt)) => {
|
||||
tracing::info!(?total_wait_duration, "Found receipt");
|
||||
break Ok(receipt);
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(error) => {
|
||||
let error_string = error.to_string();
|
||||
if !error_string.contains(Self::TRANSACTION_INDEXING_ERROR) {
|
||||
break Err(error.into());
|
||||
poll(
|
||||
Self::RECEIPT_POLLING_DURATION,
|
||||
Default::default(),
|
||||
move || {
|
||||
let provider = provider.clone();
|
||||
async move {
|
||||
match provider.get_transaction_receipt(transaction_hash).await {
|
||||
Ok(Some(receipt)) => Ok(ControlFlow::Break(receipt)),
|
||||
Ok(None) => Ok(ControlFlow::Continue(())),
|
||||
Err(error) => {
|
||||
let error_string = error.to_string();
|
||||
match error_string.contains(Self::TRANSACTION_INDEXING_ERROR) {
|
||||
true => Ok(ControlFlow::Continue(())),
|
||||
false => Err(error.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let next_wait_duration = Duration::from_secs(2u64.pow(retries))
|
||||
.min(max_allowed_wait_duration - total_wait_duration);
|
||||
total_wait_duration += next_wait_duration;
|
||||
retries += 1;
|
||||
|
||||
tokio::time::sleep(next_wait_duration).await;
|
||||
}
|
||||
},
|
||||
)
|
||||
.instrument(tracing::info_span!(
|
||||
"Awaiting transaction receipt",
|
||||
?transaction_hash
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||
#[tracing::instrument(level = "info", skip_all, fields(geth_node_id = self.id))]
|
||||
async fn trace_transaction(
|
||||
&self,
|
||||
transaction: &TransactionReceipt,
|
||||
trace_options: GethDebugTracingOptions,
|
||||
) -> anyhow::Result<alloy::rpc::types::trace::geth::GethTrace> {
|
||||
let tx_hash = transaction.transaction_hash;
|
||||
Ok(self
|
||||
.provider()
|
||||
.await?
|
||||
.debug_trace_transaction(tx_hash, trace_options)
|
||||
.await?)
|
||||
let provider = Arc::new(self.provider().await?);
|
||||
poll(
|
||||
Self::TRACE_POLLING_DURATION,
|
||||
Default::default(),
|
||||
move || {
|
||||
let provider = provider.clone();
|
||||
let trace_options = trace_options.clone();
|
||||
async move {
|
||||
match provider
|
||||
.debug_trace_transaction(transaction.transaction_hash, trace_options)
|
||||
.await
|
||||
{
|
||||
Ok(trace) => Ok(ControlFlow::Break(trace)),
|
||||
Err(error) => {
|
||||
let error_string = error.to_string();
|
||||
match error_string.contains(Self::TRANSACTION_TRACING_ERROR) {
|
||||
true => Ok(ControlFlow::Continue(())),
|
||||
false => Err(error.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(geth_node_id = self.id))]
|
||||
|
||||
@@ -209,7 +209,7 @@ impl KitchensinkNode {
|
||||
if let Err(error) = Self::wait_ready(
|
||||
self.kitchensink_stderr_log_file_path().as_path(),
|
||||
Self::SUBSTRATE_READY_MARKER,
|
||||
Duration::from_secs(30),
|
||||
Duration::from_secs(60),
|
||||
) {
|
||||
tracing::error!(
|
||||
?error,
|
||||
@@ -238,7 +238,7 @@ impl KitchensinkNode {
|
||||
if let Err(error) = Self::wait_ready(
|
||||
self.proxy_stderr_log_file_path().as_path(),
|
||||
Self::ETH_PROXY_READY_MARKER,
|
||||
Duration::from_secs(30),
|
||||
Duration::from_secs(60),
|
||||
) {
|
||||
tracing::error!(?error, "Failed to start proxy, shutting down gracefully");
|
||||
self.shutdown()?;
|
||||
|
||||
@@ -11,14 +11,14 @@ use std::{
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::download::GHDownloader;
|
||||
use crate::download::SolcDownloader;
|
||||
|
||||
pub const SOLC_CACHE_DIRECTORY: &str = "solc";
|
||||
pub(crate) static SOLC_CACHER: LazyLock<Mutex<HashSet<PathBuf>>> = LazyLock::new(Default::default);
|
||||
|
||||
pub(crate) async fn get_or_download(
|
||||
working_directory: &Path,
|
||||
downloader: &GHDownloader,
|
||||
downloader: &SolcDownloader,
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
let target_directory = working_directory
|
||||
.join(SOLC_CACHE_DIRECTORY)
|
||||
@@ -38,7 +38,7 @@ pub(crate) async fn get_or_download(
|
||||
Ok(target_file)
|
||||
}
|
||||
|
||||
async fn download_to_file(path: &Path, downloader: &GHDownloader) -> anyhow::Result<()> {
|
||||
async fn download_to_file(path: &Path, downloader: &SolcDownloader) -> anyhow::Result<()> {
|
||||
tracing::info!("caching file: {}", path.display());
|
||||
|
||||
let Ok(file) = File::create_new(path) else {
|
||||
|
||||
@@ -38,21 +38,21 @@ impl List {
|
||||
}
|
||||
}
|
||||
|
||||
/// Download solc binaries from GitHub releases (IPFS links aren't reliable).
|
||||
/// Download solc binaries from the official SolidityLang site
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GHDownloader {
|
||||
pub struct SolcDownloader {
|
||||
pub version: Version,
|
||||
pub target: &'static str,
|
||||
pub list: &'static str,
|
||||
}
|
||||
|
||||
impl GHDownloader {
|
||||
pub const BASE_URL: &str = "https://github.com/ethereum/solidity/releases/download";
|
||||
impl SolcDownloader {
|
||||
pub const BASE_URL: &str = "https://binaries.soliditylang.org";
|
||||
|
||||
pub const LINUX_NAME: &str = "solc-static-linux";
|
||||
pub const MACOSX_NAME: &str = "solc-macos";
|
||||
pub const WINDOWS_NAME: &str = "solc-windows.exe";
|
||||
pub const WASM_NAME: &str = "soljson.js";
|
||||
pub const LINUX_NAME: &str = "linux-amd64";
|
||||
pub const MACOSX_NAME: &str = "macosx-amd64";
|
||||
pub const WINDOWS_NAME: &str = "windows-amd64";
|
||||
pub const WASM_NAME: &str = "wasm";
|
||||
|
||||
async fn new(
|
||||
version: impl Into<VersionOrRequirement>,
|
||||
@@ -102,26 +102,27 @@ impl GHDownloader {
|
||||
Self::new(version, Self::WASM_NAME, List::WASM_URL).await
|
||||
}
|
||||
|
||||
/// Returns the download link.
|
||||
pub fn url(&self) -> String {
|
||||
format!("{}/v{}/{}", Self::BASE_URL, &self.version, &self.target)
|
||||
}
|
||||
|
||||
/// Download the solc binary.
|
||||
///
|
||||
/// Errors out if the download fails or the digest of the downloaded file
|
||||
/// mismatches the expected digest from the release [List].
|
||||
pub async fn download(&self) -> anyhow::Result<Vec<u8>> {
|
||||
tracing::info!("downloading solc: {self:?}");
|
||||
let expected_digest = List::download(self.list)
|
||||
.await?
|
||||
.builds
|
||||
let builds = List::download(self.list).await?.builds;
|
||||
let build = builds
|
||||
.iter()
|
||||
.find(|build| build.version == self.version)
|
||||
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))
|
||||
.map(|b| b.sha256.strip_prefix("0x").unwrap_or(&b.sha256).to_string())?;
|
||||
.ok_or_else(|| anyhow::anyhow!("solc v{} not found builds", self.version))?;
|
||||
|
||||
let file = reqwest::get(self.url()).await?.bytes().await?.to_vec();
|
||||
let path = build.path.clone();
|
||||
let expected_digest = build
|
||||
.sha256
|
||||
.strip_prefix("0x")
|
||||
.unwrap_or(&build.sha256)
|
||||
.to_string();
|
||||
let url = format!("{}/{}/{}", Self::BASE_URL, self.target, path.display());
|
||||
|
||||
let file = reqwest::get(url).await?.bytes().await?.to_vec();
|
||||
|
||||
if hex::encode(Sha256::digest(&file)) != expected_digest {
|
||||
anyhow::bail!("sha256 mismatch for solc version {}", self.version);
|
||||
@@ -133,7 +134,7 @@ impl GHDownloader {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{download::GHDownloader, list::List};
|
||||
use crate::{download::SolcDownloader, list::List};
|
||||
|
||||
#[tokio::test]
|
||||
async fn try_get_windows() {
|
||||
@@ -141,7 +142,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap()
|
||||
.latest_release;
|
||||
GHDownloader::windows(version)
|
||||
SolcDownloader::windows(version)
|
||||
.await
|
||||
.unwrap()
|
||||
.download()
|
||||
@@ -155,7 +156,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap()
|
||||
.latest_release;
|
||||
GHDownloader::macosx(version)
|
||||
SolcDownloader::macosx(version)
|
||||
.await
|
||||
.unwrap()
|
||||
.download()
|
||||
@@ -169,7 +170,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap()
|
||||
.latest_release;
|
||||
GHDownloader::linux(version)
|
||||
SolcDownloader::linux(version)
|
||||
.await
|
||||
.unwrap()
|
||||
.download()
|
||||
@@ -180,7 +181,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn try_get_wasm() {
|
||||
let version = List::download(List::WASM_URL).await.unwrap().latest_release;
|
||||
GHDownloader::wasm(version)
|
||||
SolcDownloader::wasm(version)
|
||||
.await
|
||||
.unwrap()
|
||||
.download()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use cache::get_or_download;
|
||||
use download::GHDownloader;
|
||||
use download::SolcDownloader;
|
||||
|
||||
use revive_dt_common::types::VersionOrRequirement;
|
||||
|
||||
@@ -25,13 +25,13 @@ pub async fn download_solc(
|
||||
wasm: bool,
|
||||
) -> anyhow::Result<PathBuf> {
|
||||
let downloader = if wasm {
|
||||
GHDownloader::wasm(version).await
|
||||
SolcDownloader::wasm(version).await
|
||||
} else if cfg!(target_os = "linux") {
|
||||
GHDownloader::linux(version).await
|
||||
SolcDownloader::linux(version).await
|
||||
} else if cfg!(target_os = "macos") {
|
||||
GHDownloader::macosx(version).await
|
||||
SolcDownloader::macosx(version).await
|
||||
} else if cfg!(target_os = "windows") {
|
||||
GHDownloader::windows(version).await
|
||||
SolcDownloader::windows(version).await
|
||||
} else {
|
||||
unimplemented!()
|
||||
}?;
|
||||
|
||||
Reference in New Issue
Block a user