mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-22 11:27:59 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 320accc62a | |||
| 92effaf6c0 | |||
| d38e6d419d | |||
| 62478ee2f9 | |||
| dda369c8b5 | |||
| 08c1572870 | |||
| cd6b7969ac | |||
| 78ac7ee381 | |||
| 3edaebdcae |
@@ -0,0 +1,131 @@
|
||||
name: "Run Revive Differential Tests"
|
||||
description: "Builds and runs revive-differential-tests (retester) from this repo against the caller's Polkadot SDK."
|
||||
|
||||
inputs:
|
||||
# Setup arguments & environment
|
||||
polkadot-sdk-path:
|
||||
description: "The path of the polkadot-sdk that should be compiled for the tests to run against."
|
||||
required: false
|
||||
default: "."
|
||||
type: string
|
||||
cargo-command:
|
||||
description: "The cargo command to use in compilations and running of tests (e.g., forklift cargo)."
|
||||
required: false
|
||||
default: "cargo"
|
||||
type: string
|
||||
revive-differential-tests-ref:
|
||||
description: "The branch, tag or SHA to checkout for the revive-differential-tests."
|
||||
required: false
|
||||
default: "main"
|
||||
type: string
|
||||
resolc-version:
|
||||
description: "The version of resolc to install and use in tests."
|
||||
required: false
|
||||
default: "0.5.0"
|
||||
type: string
|
||||
use-compilation-caches:
|
||||
description: "Controls if the compilation caches will be used for the test run or not."
|
||||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
# Test Execution Arguments
|
||||
platform:
|
||||
description: "The identifier of the platform to run the tests on (e.g., geth-evm-solc, revive-dev-node-revm-solc)"
|
||||
required: true
|
||||
type: string
|
||||
polkadot-omnichain-node-chain-spec-path:
|
||||
description: "The path of the chain-spec of the chain we're spawning'. This is only required if the polkadot-omni-node is one of the selected platforms."
|
||||
required: false
|
||||
type: string
|
||||
polkadot-omnichain-node-parachain-id:
|
||||
description: "The id of the parachain to spawn with the polkadot-omni-node. This is only required if the polkadot-omni-node is one of the selected platforms."
|
||||
type: number
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Checkout the Differential Tests Repository
|
||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
with:
|
||||
repository: paritytech/revive-differential-tests
|
||||
ref: ${{ inputs['revive-differential-tests-ref'] }}
|
||||
path: revive-differential-tests
|
||||
submodules: recursive
|
||||
- name: Installing the Latest Resolc
|
||||
shell: bash
|
||||
if: ${{ runner.os == 'Linux' && runner.arch == 'X64' }}
|
||||
run: |
|
||||
VERSION="${{ inputs['resolc-version'] }}"
|
||||
ASSET_URL="https://github.com/paritytech/revive/releases/download/v$VERSION/resolc-x86_64-unknown-linux-musl"
|
||||
echo "Downloading resolc v$VERSION from $ASSET_URL"
|
||||
curl -Lsf --show-error -o resolc "$ASSET_URL"
|
||||
chmod +x resolc
|
||||
./resolc --version
|
||||
- name: Installing Retester
|
||||
shell: bash
|
||||
run: ${{ inputs['cargo-command'] }} install --locked --path revive-differential-tests/crates/core
|
||||
- name: Creating a workdir for retester
|
||||
shell: bash
|
||||
run: mkdir workdir
|
||||
- name: Downloading & Initializing the compilation caches
|
||||
shell: bash
|
||||
if: ${{ inputs['use-compilation-caches'] == true }}
|
||||
run: |
|
||||
curl -fL --retry 3 --retry-all-errors --connect-timeout 10 -o cache.tar.gz "https://github.com/paritytech/revive-differential-tests/releases/download/compilation-caches-v1.1/cache.tar.gz"
|
||||
tar -zxf cache.tar.gz -C ./workdir > /dev/null 2>&1
|
||||
- name: Building the dependencies from the Polkadot SDK
|
||||
shell: bash
|
||||
run: |
|
||||
${{ inputs['cargo-command'] }} build --locked --profile release -p pallet-revive-eth-rpc -p revive-dev-node --manifest-path ${{ inputs['polkadot-sdk-path'] }}/Cargo.toml
|
||||
${{ inputs['cargo-command'] }} build --locked --profile release --bin polkadot-omni-node --manifest-path ${{ inputs['polkadot-sdk-path'] }}/Cargo.toml
|
||||
- name: Running the Differential Tests
|
||||
shell: bash
|
||||
run: |
|
||||
OMNI_ARGS=()
|
||||
if [[ -n "${{ inputs['polkadot-omnichain-node-parachain-id'] }}" ]]; then
|
||||
OMNI_ARGS+=(
|
||||
--polkadot-omni-node.parachain-id
|
||||
"${{ inputs['polkadot-omnichain-node-parachain-id'] }}"
|
||||
)
|
||||
fi
|
||||
if [[ -n "${{ inputs['polkadot-omnichain-node-chain-spec-path'] }}" ]]; then
|
||||
OMNI_ARGS+=(
|
||||
--polkadot-omni-node.chain-spec-path
|
||||
"${{ inputs['polkadot-omnichain-node-chain-spec-path'] }}"
|
||||
)
|
||||
fi
|
||||
|
||||
${{ inputs['cargo-command'] }} run --locked --manifest-path revive-differential-tests/Cargo.toml -- test \
|
||||
--test ./revive-differential-tests/resolc-compiler-tests/fixtures/solidity/simple \
|
||||
--test ./revive-differential-tests/resolc-compiler-tests/fixtures/solidity/complex \
|
||||
--test ./revive-differential-tests/resolc-compiler-tests/fixtures/solidity/translated_semantic_tests \
|
||||
--platform ${{ inputs['platform'] }} \
|
||||
--concurrency.number-of-nodes 10 \
|
||||
--concurrency.number-of-threads 10 \
|
||||
--concurrency.number-of-concurrent-tasks 100 \
|
||||
--working-directory ./workdir \
|
||||
--revive-dev-node.consensus manual-seal-200 \
|
||||
--revive-dev-node.path ${{ inputs['polkadot-sdk-path'] }}/target/release/revive-dev-node \
|
||||
--eth-rpc.path ${{ inputs['polkadot-sdk-path'] }}/target/release/eth-rpc \
|
||||
--polkadot-omni-node.path ${{ inputs['polkadot-sdk-path'] }}/target/release/polkadot-omni-node \
|
||||
--resolc.path ./resolc \
|
||||
"${OMNI_ARGS[@]}"
|
||||
- name: Creating a markdown report of the test execution
|
||||
shell: bash
|
||||
if: ${{ always() }}
|
||||
run: |
|
||||
mv ./workdir/*.json report.json
|
||||
python3 revive-differential-tests/scripts/process-differential-tests-report.py report.json ${{ inputs['platform'] }}
|
||||
- name: Upload the Report to the CI
|
||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
|
||||
if: ${{ always() }}
|
||||
with:
|
||||
name: report-${{ inputs['platform'] }}.md
|
||||
path: report.md
|
||||
- name: Posting the report as a comment on the PR
|
||||
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405
|
||||
if: ${{ always() }}
|
||||
with:
|
||||
header: diff-tests-report-${{ inputs['platform'] }}
|
||||
path: report.md
|
||||
@@ -39,6 +39,12 @@ pub enum PlatformIdentifier {
|
||||
ZombienetPolkavmResolc,
|
||||
/// A zombienet based Substrate/Polkadot node with the REVM backend with the solc compiler.
|
||||
ZombienetRevmSolc,
|
||||
/// A polkadot-omni-chain based node with a custom runtime with the PolkaVM backend and the
|
||||
/// resolc compiler.
|
||||
PolkadotOmniNodePolkavmResolc,
|
||||
/// A polkadot-omni-chain based node with a custom runtime with the REVM backend and the solc
|
||||
/// compiler.
|
||||
PolkadotOmniNodeRevmSolc,
|
||||
}
|
||||
|
||||
/// An enum of the platform identifiers of all of the platforms supported by this framework.
|
||||
@@ -95,6 +101,8 @@ pub enum NodeIdentifier {
|
||||
ReviveDevNode,
|
||||
/// A zombienet spawned nodes
|
||||
Zombienet,
|
||||
/// The polkadot-omni-node.
|
||||
PolkadotOmniNode,
|
||||
}
|
||||
|
||||
/// An enum representing the identifiers of the supported VMs.
|
||||
|
||||
@@ -208,14 +208,18 @@ impl SolidityCompiler for Resolc {
|
||||
anyhow::bail!("Compilation failed with an error: {message}");
|
||||
}
|
||||
|
||||
let parsed = serde_json::from_slice::<SolcStandardJsonOutput>(&stdout)
|
||||
.map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"failed to parse resolc JSON output: {e}\nstderr: {}",
|
||||
String::from_utf8_lossy(&stderr)
|
||||
)
|
||||
})
|
||||
.context("Failed to parse resolc standard JSON output")?;
|
||||
let parsed: SolcStandardJsonOutput = {
|
||||
let mut deserializer = serde_json::Deserializer::from_slice(&stdout);
|
||||
deserializer.disable_recursion_limit();
|
||||
serde::de::Deserialize::deserialize(&mut deserializer)
|
||||
.map_err(|e| {
|
||||
anyhow::anyhow!(
|
||||
"failed to parse resolc JSON output: {e}\nstderr: {}",
|
||||
String::from_utf8_lossy(&stderr)
|
||||
)
|
||||
})
|
||||
.context("Failed to parse resolc standard JSON output")?
|
||||
};
|
||||
|
||||
tracing::debug!(
|
||||
output = %serde_json::to_string(&parsed).unwrap(),
|
||||
|
||||
@@ -143,6 +143,17 @@ impl AsRef<ReviveDevNodeConfiguration> for Context {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<PolkadotOmnichainNodeConfiguration> for Context {
|
||||
fn as_ref(&self) -> &PolkadotOmnichainNodeConfiguration {
|
||||
match self {
|
||||
Self::Test(context) => context.as_ref().as_ref(),
|
||||
Self::Benchmark(context) => context.as_ref().as_ref(),
|
||||
Self::ExportGenesis(context) => context.as_ref().as_ref(),
|
||||
Self::ExportJsonSchema => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<EthRpcConfiguration> for Context {
|
||||
fn as_ref(&self) -> &EthRpcConfiguration {
|
||||
match self {
|
||||
@@ -228,6 +239,7 @@ pub struct TestExecutionContext {
|
||||
#[arg(
|
||||
short = 'p',
|
||||
long = "platform",
|
||||
id = "platforms",
|
||||
default_values = ["geth-evm-solc", "revive-dev-node-polkavm-resolc"]
|
||||
)]
|
||||
pub platforms: Vec<PlatformIdentifier>,
|
||||
@@ -277,6 +289,10 @@ pub struct TestExecutionContext {
|
||||
#[clap(flatten, next_help_heading = "Revive Dev Node Configuration")]
|
||||
pub revive_dev_node_configuration: ReviveDevNodeConfiguration,
|
||||
|
||||
/// Configuration parameters for the Polkadot Omnichain Node.
|
||||
#[clap(flatten, next_help_heading = "Polkadot Omnichain Node Configuration")]
|
||||
pub polkadot_omnichain_node_configuration: PolkadotOmnichainNodeConfiguration,
|
||||
|
||||
/// Configuration parameters for the Eth Rpc.
|
||||
#[clap(flatten, next_help_heading = "Eth RPC Configuration")]
|
||||
pub eth_rpc_configuration: EthRpcConfiguration,
|
||||
@@ -375,6 +391,23 @@ pub struct BenchmarkingContext {
|
||||
#[arg(short = 'r', long = "default-repetition-count", default_value_t = 1000)]
|
||||
pub default_repetition_count: usize,
|
||||
|
||||
/// This transaction controls whether the benchmarking driver should await for transactions to
|
||||
/// be included in a block before moving on to the next transaction in the sequence or not.
|
||||
///
|
||||
/// This behavior is useful in certain cases and not so useful in others. For example, in some
|
||||
/// repetition block if there's some kind of relationship between txs n and n+1 (for example a
|
||||
/// mint then a transfer) then you would want to wait for the minting to happen and then move on
|
||||
/// to the transfers. On the other hand, if there's no relationship between the transactions n
|
||||
/// and n+1 (e.g., mint and another mint of a different token) then awaiting the first mint to
|
||||
/// be included in a block might not seem necessary.
|
||||
///
|
||||
/// By default, this behavior is set to false to allow the benchmarking framework to saturate
|
||||
/// the node's mempool as quickly as possible. However, as explained above, there are cases
|
||||
/// where it's needed and certain workloads where failure to provide this argument would lead to
|
||||
/// inaccurate results.
|
||||
#[arg(long)]
|
||||
pub await_transaction_inclusion: bool,
|
||||
|
||||
/// Configuration parameters for the corpus files to use.
|
||||
#[clap(flatten, next_help_heading = "Corpus Configuration")]
|
||||
pub corpus_configuration: CorpusConfiguration,
|
||||
@@ -403,6 +436,10 @@ pub struct BenchmarkingContext {
|
||||
#[clap(flatten, next_help_heading = "Revive Dev Node Configuration")]
|
||||
pub revive_dev_node_configuration: ReviveDevNodeConfiguration,
|
||||
|
||||
/// Configuration parameters for the Polkadot Omnichain Node.
|
||||
#[clap(flatten, next_help_heading = "Polkadot Omnichain Node Configuration")]
|
||||
pub polkadot_omnichain_node_configuration: PolkadotOmnichainNodeConfiguration,
|
||||
|
||||
/// Configuration parameters for the Eth Rpc.
|
||||
#[clap(flatten, next_help_heading = "Eth RPC Configuration")]
|
||||
pub eth_rpc_configuration: EthRpcConfiguration,
|
||||
@@ -481,6 +518,10 @@ pub struct ExportGenesisContext {
|
||||
#[clap(flatten, next_help_heading = "Revive Dev Node Configuration")]
|
||||
pub revive_dev_node_configuration: ReviveDevNodeConfiguration,
|
||||
|
||||
/// Configuration parameters for the Polkadot Omnichain Node.
|
||||
#[clap(flatten, next_help_heading = "Polkadot Omnichain Node Configuration")]
|
||||
pub polkadot_omnichain_node_configuration: PolkadotOmnichainNodeConfiguration,
|
||||
|
||||
/// Configuration parameters for the wallet.
|
||||
#[clap(flatten, next_help_heading = "Wallet Configuration")]
|
||||
pub wallet_configuration: WalletConfiguration,
|
||||
@@ -540,6 +581,12 @@ impl AsRef<ReviveDevNodeConfiguration> for TestExecutionContext {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<PolkadotOmnichainNodeConfiguration> for TestExecutionContext {
|
||||
fn as_ref(&self) -> &PolkadotOmnichainNodeConfiguration {
|
||||
&self.polkadot_omnichain_node_configuration
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<EthRpcConfiguration> for TestExecutionContext {
|
||||
fn as_ref(&self) -> &EthRpcConfiguration {
|
||||
&self.eth_rpc_configuration
|
||||
@@ -636,6 +683,12 @@ impl AsRef<ReviveDevNodeConfiguration> for BenchmarkingContext {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<PolkadotOmnichainNodeConfiguration> for BenchmarkingContext {
|
||||
fn as_ref(&self) -> &PolkadotOmnichainNodeConfiguration {
|
||||
&self.polkadot_omnichain_node_configuration
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<EthRpcConfiguration> for BenchmarkingContext {
|
||||
fn as_ref(&self) -> &EthRpcConfiguration {
|
||||
&self.eth_rpc_configuration
|
||||
@@ -696,6 +749,12 @@ impl AsRef<ReviveDevNodeConfiguration> for ExportGenesisContext {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<PolkadotOmnichainNodeConfiguration> for ExportGenesisContext {
|
||||
fn as_ref(&self) -> &PolkadotOmnichainNodeConfiguration {
|
||||
&self.polkadot_omnichain_node_configuration
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<WalletConfiguration> for ExportGenesisContext {
|
||||
fn as_ref(&self) -> &WalletConfiguration {
|
||||
&self.wallet_configuration
|
||||
@@ -852,6 +911,54 @@ pub struct ReviveDevNodeConfiguration {
|
||||
pub existing_rpc_url: Vec<String>,
|
||||
}
|
||||
|
||||
/// A set of configuration parameters for the polkadot-omni-node.
|
||||
#[derive(Clone, Debug, Parser, Serialize, Deserialize)]
|
||||
pub struct PolkadotOmnichainNodeConfiguration {
|
||||
/// Specifies the path of the polkadot-omni-node to be used by the tool.
|
||||
///
|
||||
/// If this is not specified, then the tool assumes that it should use the polkadot-omni-node
|
||||
/// binary that's provided in the user's $PATH.
|
||||
#[clap(
|
||||
id = "polkadot-omni-node.path",
|
||||
long = "polkadot-omni-node.path",
|
||||
default_value = "polkadot-omni-node"
|
||||
)]
|
||||
pub path: PathBuf,
|
||||
|
||||
/// The amount of time to wait upon startup before considering that the node timed out.
|
||||
#[clap(
|
||||
id = "polkadot-omni-node.start-timeout-ms",
|
||||
long = "polkadot-omni-node.start-timeout-ms",
|
||||
default_value = "90000",
|
||||
value_parser = parse_duration
|
||||
)]
|
||||
pub start_timeout_ms: Duration,
|
||||
|
||||
/// Defines how often blocks will be sealed by the node in milliseconds.
|
||||
#[clap(
|
||||
id = "polkadot-omni-node.block-time-ms",
|
||||
long = "polkadot-omni-node.block-time-ms",
|
||||
default_value = "200",
|
||||
value_parser = parse_duration
|
||||
)]
|
||||
pub block_time: Duration,
|
||||
|
||||
/// The path of the chainspec of the chain that we're spawning
|
||||
#[clap(
|
||||
id = "polkadot-omni-node.chain-spec-path",
|
||||
long = "polkadot-omni-node.chain-spec-path"
|
||||
)]
|
||||
pub chain_spec_path: Option<PathBuf>,
|
||||
|
||||
/// The ID of the parachain that the polkadot-omni-node will spawn. This argument is required if
|
||||
/// the polkadot-omni-node is one of the selected platforms for running the tests or benchmarks.
|
||||
#[clap(
|
||||
id = "polkadot-omni-node.parachain-id",
|
||||
long = "polkadot-omni-node.parachain-id"
|
||||
)]
|
||||
pub parachain_id: Option<usize>,
|
||||
}
|
||||
|
||||
/// A set of configuration parameters for the ETH RPC.
|
||||
#[derive(Clone, Debug, Parser, Serialize, Deserialize)]
|
||||
pub struct EthRpcConfiguration {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::ControlFlow,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
@@ -13,6 +12,7 @@ use alloy::{
|
||||
json_abi::JsonAbi,
|
||||
network::{Ethereum, TransactionBuilder},
|
||||
primitives::{Address, TxHash, U256},
|
||||
providers::Provider,
|
||||
rpc::types::{
|
||||
TransactionReceipt, TransactionRequest,
|
||||
trace::geth::{
|
||||
@@ -22,12 +22,9 @@ use alloy::{
|
||||
},
|
||||
};
|
||||
use anyhow::{Context as _, Result, bail};
|
||||
use futures::TryFutureExt;
|
||||
use futures::{FutureExt as _, TryFutureExt};
|
||||
use indexmap::IndexMap;
|
||||
use revive_dt_common::{
|
||||
futures::{PollingWaitBehavior, poll},
|
||||
types::PrivateKeyAllocator,
|
||||
};
|
||||
use revive_dt_common::types::PrivateKeyAllocator;
|
||||
use revive_dt_format::{
|
||||
metadata::{ContractInstance, ContractPathAndIdent},
|
||||
steps::{
|
||||
@@ -37,7 +34,7 @@ use revive_dt_format::{
|
||||
traits::{ResolutionContext, ResolverApi},
|
||||
};
|
||||
use tokio::sync::{Mutex, OnceCell, mpsc::UnboundedSender};
|
||||
use tracing::{Instrument, Span, debug, error, field::display, info, info_span, instrument};
|
||||
use tracing::{Span, debug, error, field::display, info, instrument};
|
||||
|
||||
use crate::{
|
||||
differential_benchmarks::{ExecutionState, WatcherEvent},
|
||||
@@ -73,6 +70,10 @@ pub struct Driver<'a, I> {
|
||||
/// The number of steps that were executed on the driver.
|
||||
steps_executed: usize,
|
||||
|
||||
/// This function controls if the driver should wait for transactions to be included in a block
|
||||
/// or not before proceeding forward.
|
||||
await_transaction_inclusion: bool,
|
||||
|
||||
/// This is the queue of steps that are to be executed by the driver for this test case. Each
|
||||
/// time `execute_step` is called one of the steps is executed.
|
||||
steps_iterator: I,
|
||||
@@ -89,6 +90,7 @@ where
|
||||
private_key_allocator: Arc<Mutex<PrivateKeyAllocator>>,
|
||||
cached_compiler: &CachedCompiler<'a>,
|
||||
watcher_tx: UnboundedSender<WatcherEvent>,
|
||||
await_transaction_inclusion: bool,
|
||||
steps: I,
|
||||
) -> Result<Self> {
|
||||
let mut this = Driver {
|
||||
@@ -104,6 +106,7 @@ where
|
||||
execution_state: ExecutionState::empty(),
|
||||
steps_executed: 0,
|
||||
steps_iterator: steps,
|
||||
await_transaction_inclusion,
|
||||
watcher_tx,
|
||||
};
|
||||
this.init_execution_state(cached_compiler)
|
||||
@@ -166,7 +169,7 @@ where
|
||||
code,
|
||||
);
|
||||
let receipt = self
|
||||
.execute_transaction(tx, None)
|
||||
.execute_transaction(tx, None, Duration::from_secs(5 * 60))
|
||||
.and_then(|(_, receipt_fut)| receipt_fut)
|
||||
.await
|
||||
.inspect_err(|err| {
|
||||
@@ -365,7 +368,30 @@ 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)
|
||||
|
||||
let (tx_hash, receipt_future) = self
|
||||
.execute_transaction(tx.clone(), Some(step_path), Duration::from_secs(30 * 60))
|
||||
.await?;
|
||||
if self.await_transaction_inclusion {
|
||||
let receipt = receipt_future
|
||||
.await
|
||||
.context("Failed while waiting for transaction inclusion in block")?;
|
||||
|
||||
if !receipt.status() {
|
||||
error!(
|
||||
?tx,
|
||||
tx.hash = %receipt.transaction_hash,
|
||||
?receipt,
|
||||
"Encountered a failing benchmark transaction"
|
||||
);
|
||||
bail!(
|
||||
"Encountered a failing transaction in benchmarks: {}",
|
||||
receipt.transaction_hash
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(tx_hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,6 +492,7 @@ where
|
||||
.collect::<Vec<_>>();
|
||||
steps.into_iter()
|
||||
},
|
||||
await_transaction_inclusion: self.await_transaction_inclusion,
|
||||
watcher_tx: self.watcher_tx.clone(),
|
||||
})
|
||||
.map(|driver| driver.execute_all());
|
||||
@@ -632,7 +659,7 @@ where
|
||||
};
|
||||
|
||||
let receipt = match self
|
||||
.execute_transaction(tx, step_path)
|
||||
.execute_transaction(tx, step_path, Duration::from_secs(5 * 60))
|
||||
.and_then(|(_, receipt_fut)| receipt_fut)
|
||||
.await
|
||||
{
|
||||
@@ -677,18 +704,33 @@ where
|
||||
#[instrument(
|
||||
level = "info",
|
||||
skip_all,
|
||||
fields(driver_id = self.driver_id, transaction_hash = tracing::field::Empty)
|
||||
fields(
|
||||
driver_id = self.driver_id,
|
||||
transaction = ?transaction,
|
||||
transaction_hash = tracing::field::Empty
|
||||
),
|
||||
err(Debug)
|
||||
)]
|
||||
async fn execute_transaction(
|
||||
&self,
|
||||
transaction: TransactionRequest,
|
||||
step_path: Option<&StepPath>,
|
||||
receipt_wait_duration: Duration,
|
||||
) -> anyhow::Result<(TxHash, impl Future<Output = Result<TransactionReceipt>>)> {
|
||||
let node = self.platform_information.node;
|
||||
let transaction_hash = node
|
||||
.submit_transaction(transaction)
|
||||
let provider = node.provider().await.context("Creating provider failed")?;
|
||||
|
||||
let pending_transaction_builder = provider
|
||||
.send_transaction(transaction)
|
||||
.await
|
||||
.context("Failed to submit transaction")?;
|
||||
|
||||
let transaction_hash = *pending_transaction_builder.tx_hash();
|
||||
let receipt_future = pending_transaction_builder
|
||||
.with_timeout(Some(receipt_wait_duration))
|
||||
.with_required_confirmations(2)
|
||||
.get_receipt()
|
||||
.map(|res| res.context("Failed to get the receipt of the transaction"));
|
||||
Span::current().record("transaction_hash", display(transaction_hash));
|
||||
|
||||
info!("Submitted transaction");
|
||||
@@ -701,28 +743,7 @@ where
|
||||
.context("Failed to send the transaction hash to the watcher")?;
|
||||
};
|
||||
|
||||
Ok((transaction_hash, async move {
|
||||
info!("Starting to poll for transaction receipt");
|
||||
poll(
|
||||
Duration::from_secs(30 * 60),
|
||||
PollingWaitBehavior::Constant(Duration::from_secs(1)),
|
||||
|| {
|
||||
async move {
|
||||
match node.get_receipt(transaction_hash).await {
|
||||
Ok(receipt) => {
|
||||
info!("Polling succeeded, receipt found");
|
||||
Ok(ControlFlow::Break(receipt))
|
||||
}
|
||||
Err(_) => Ok(ControlFlow::Continue(())),
|
||||
}
|
||||
}
|
||||
.instrument(info_span!("Polling for receipt"))
|
||||
},
|
||||
)
|
||||
.instrument(info_span!("Polling for receipt", %transaction_hash))
|
||||
.await
|
||||
.inspect(|_| info!("Found the transaction receipt"))
|
||||
}))
|
||||
Ok((transaction_hash, receipt_future))
|
||||
}
|
||||
// endregion:Transaction Execution
|
||||
}
|
||||
|
||||
@@ -160,6 +160,7 @@ pub async fn handle_differential_benchmarks(
|
||||
private_key_allocator,
|
||||
cached_compiler.as_ref(),
|
||||
watcher_tx.clone(),
|
||||
context.await_transaction_inclusion,
|
||||
test_definition
|
||||
.case
|
||||
.steps_iterator_for_benchmarks(context.default_repetition_count)
|
||||
|
||||
@@ -139,23 +139,18 @@ impl Watcher {
|
||||
break;
|
||||
}
|
||||
|
||||
info!(
|
||||
block_number = block.ethereum_block_information.block_number,
|
||||
block_tx_count = block.ethereum_block_information.transaction_hashes.len(),
|
||||
remaining_transactions = watch_for_transaction_hashes.read().await.len(),
|
||||
"Observed a block"
|
||||
);
|
||||
|
||||
// Remove all of the transaction hashes observed in this block from the txs we
|
||||
// are currently watching for.
|
||||
let mut watch_for_transaction_hashes =
|
||||
watch_for_transaction_hashes.write().await;
|
||||
let mut relevant_transactions_observed = 0;
|
||||
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;
|
||||
};
|
||||
relevant_transactions_observed += 1;
|
||||
let transaction_information = TransactionInformation {
|
||||
transaction_hash: *tx_hash,
|
||||
submission_timestamp: submission_time
|
||||
@@ -172,6 +167,14 @@ impl Watcher {
|
||||
)
|
||||
.expect("Can't fail")
|
||||
}
|
||||
|
||||
info!(
|
||||
block_number = block.ethereum_block_information.block_number,
|
||||
block_tx_count = block.ethereum_block_information.transaction_hashes.len(),
|
||||
relevant_transactions_observed,
|
||||
remaining_transactions = watch_for_transaction_hashes.len(),
|
||||
"Observed a block"
|
||||
);
|
||||
}
|
||||
|
||||
info!("Watcher's Block Watching Task Finished");
|
||||
|
||||
+152
-7
@@ -14,9 +14,12 @@ use revive_dt_common::types::*;
|
||||
use revive_dt_compiler::{SolidityCompiler, revive_resolc::Resolc, solc::Solc};
|
||||
use revive_dt_config::*;
|
||||
use revive_dt_node::{
|
||||
Node, node_implementations::geth::GethNode,
|
||||
node_implementations::lighthouse_geth::LighthouseGethNode,
|
||||
node_implementations::substrate::SubstrateNode, node_implementations::zombienet::ZombienetNode,
|
||||
Node,
|
||||
node_implementations::{
|
||||
geth::GethNode, lighthouse_geth::LighthouseGethNode,
|
||||
polkadot_omni_node::PolkadotOmnichainNode, substrate::SubstrateNode,
|
||||
zombienet::ZombienetNode,
|
||||
},
|
||||
};
|
||||
use revive_dt_node_interaction::EthereumNode;
|
||||
use tracing::info;
|
||||
@@ -91,7 +94,8 @@ impl Platform for GethEvmSolcPlatform {
|
||||
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let node = GethNode::new(context);
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node = GethNode::new(context, use_fallback_gas_filler);
|
||||
let node = spawn_node::<GethNode>(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
}))
|
||||
@@ -145,7 +149,8 @@ impl Platform for LighthouseGethEvmSolcPlatform {
|
||||
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let node = LighthouseGethNode::new(context);
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node = LighthouseGethNode::new(context, use_fallback_gas_filler);
|
||||
let node = spawn_node::<LighthouseGethNode>(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
}))
|
||||
@@ -206,12 +211,14 @@ impl Platform for ReviveDevNodePolkavmResolcPlatform {
|
||||
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node = SubstrateNode::new(
|
||||
revive_dev_node_path,
|
||||
SubstrateNode::REVIVE_DEV_NODE_EXPORT_CHAINSPEC_COMMAND,
|
||||
Some(revive_dev_node_consensus),
|
||||
context,
|
||||
ð_rpc_connection_strings,
|
||||
use_fallback_gas_filler,
|
||||
);
|
||||
let node = spawn_node(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
@@ -274,12 +281,14 @@ impl Platform for ReviveDevNodeRevmSolcPlatform {
|
||||
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node = SubstrateNode::new(
|
||||
revive_dev_node_path,
|
||||
SubstrateNode::REVIVE_DEV_NODE_EXPORT_CHAINSPEC_COMMAND,
|
||||
Some(revive_dev_node_consensus),
|
||||
context,
|
||||
ð_rpc_connection_strings,
|
||||
use_fallback_gas_filler,
|
||||
);
|
||||
let node = spawn_node(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
@@ -338,7 +347,9 @@ impl Platform for ZombienetPolkavmResolcPlatform {
|
||||
.clone();
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let node = ZombienetNode::new(polkadot_parachain_path, context);
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node =
|
||||
ZombienetNode::new(polkadot_parachain_path, context, use_fallback_gas_filler);
|
||||
let node = spawn_node(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
}))
|
||||
@@ -395,7 +406,9 @@ impl Platform for ZombienetRevmSolcPlatform {
|
||||
.clone();
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let node = ZombienetNode::new(polkadot_parachain_path, context);
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node =
|
||||
ZombienetNode::new(polkadot_parachain_path, context, use_fallback_gas_filler);
|
||||
let node = spawn_node(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
}))
|
||||
@@ -422,6 +435,126 @@ impl Platform for ZombienetRevmSolcPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
||||
pub struct PolkadotOmniNodePolkavmResolcPlatform;
|
||||
|
||||
impl Platform for PolkadotOmniNodePolkavmResolcPlatform {
|
||||
fn platform_identifier(&self) -> PlatformIdentifier {
|
||||
PlatformIdentifier::PolkadotOmniNodePolkavmResolc
|
||||
}
|
||||
|
||||
fn node_identifier(&self) -> NodeIdentifier {
|
||||
NodeIdentifier::PolkadotOmniNode
|
||||
}
|
||||
|
||||
fn vm_identifier(&self) -> VmIdentifier {
|
||||
VmIdentifier::PolkaVM
|
||||
}
|
||||
|
||||
fn compiler_identifier(&self) -> CompilerIdentifier {
|
||||
CompilerIdentifier::Resolc
|
||||
}
|
||||
|
||||
fn new_node(
|
||||
&self,
|
||||
context: Context,
|
||||
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
|
||||
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node = PolkadotOmnichainNode::new(context, use_fallback_gas_filler);
|
||||
let node = spawn_node(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
}))
|
||||
}
|
||||
|
||||
fn new_compiler(
|
||||
&self,
|
||||
context: Context,
|
||||
version: Option<VersionOrRequirement>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<Box<dyn SolidityCompiler>>>>> {
|
||||
Box::pin(async move {
|
||||
let compiler = Resolc::new(context, version).await;
|
||||
compiler.map(|compiler| Box::new(compiler) as Box<dyn SolidityCompiler>)
|
||||
})
|
||||
}
|
||||
|
||||
fn export_genesis(&self, context: Context) -> anyhow::Result<serde_json::Value> {
|
||||
let polkadot_omnichain_node_configuration =
|
||||
AsRef::<PolkadotOmnichainNodeConfiguration>::as_ref(&context);
|
||||
let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet();
|
||||
|
||||
PolkadotOmnichainNode::node_genesis(
|
||||
&wallet,
|
||||
polkadot_omnichain_node_configuration
|
||||
.chain_spec_path
|
||||
.as_ref()
|
||||
.context("No WASM runtime path found in the polkadot-omni-node configuration")?,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
|
||||
pub struct PolkadotOmniNodeRevmSolcPlatform;
|
||||
|
||||
impl Platform for PolkadotOmniNodeRevmSolcPlatform {
|
||||
fn platform_identifier(&self) -> PlatformIdentifier {
|
||||
PlatformIdentifier::PolkadotOmniNodeRevmSolc
|
||||
}
|
||||
|
||||
fn node_identifier(&self) -> NodeIdentifier {
|
||||
NodeIdentifier::PolkadotOmniNode
|
||||
}
|
||||
|
||||
fn vm_identifier(&self) -> VmIdentifier {
|
||||
VmIdentifier::Evm
|
||||
}
|
||||
|
||||
fn compiler_identifier(&self) -> CompilerIdentifier {
|
||||
CompilerIdentifier::Solc
|
||||
}
|
||||
|
||||
fn new_node(
|
||||
&self,
|
||||
context: Context,
|
||||
) -> anyhow::Result<JoinHandle<anyhow::Result<Box<dyn EthereumNode + Send + Sync>>>> {
|
||||
let genesis_configuration = AsRef::<GenesisConfiguration>::as_ref(&context);
|
||||
let genesis = genesis_configuration.genesis()?.clone();
|
||||
Ok(thread::spawn(move || {
|
||||
let use_fallback_gas_filler = matches!(context, Context::Test(..));
|
||||
let node = PolkadotOmnichainNode::new(context, use_fallback_gas_filler);
|
||||
let node = spawn_node(node, genesis)?;
|
||||
Ok(Box::new(node) as Box<_>)
|
||||
}))
|
||||
}
|
||||
|
||||
fn new_compiler(
|
||||
&self,
|
||||
context: Context,
|
||||
version: Option<VersionOrRequirement>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<Box<dyn SolidityCompiler>>>>> {
|
||||
Box::pin(async move {
|
||||
let compiler = Solc::new(context, version).await;
|
||||
compiler.map(|compiler| Box::new(compiler) as Box<dyn SolidityCompiler>)
|
||||
})
|
||||
}
|
||||
|
||||
fn export_genesis(&self, context: Context) -> anyhow::Result<serde_json::Value> {
|
||||
let polkadot_omnichain_node_configuration =
|
||||
AsRef::<PolkadotOmnichainNodeConfiguration>::as_ref(&context);
|
||||
let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet();
|
||||
|
||||
PolkadotOmnichainNode::node_genesis(
|
||||
&wallet,
|
||||
polkadot_omnichain_node_configuration
|
||||
.chain_spec_path
|
||||
.as_ref()
|
||||
.context("No WASM runtime path found in the polkadot-omni-node configuration")?,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PlatformIdentifier> for Box<dyn Platform> {
|
||||
fn from(value: PlatformIdentifier) -> Self {
|
||||
match value {
|
||||
@@ -439,6 +572,12 @@ impl From<PlatformIdentifier> for Box<dyn Platform> {
|
||||
Box::new(ZombienetPolkavmResolcPlatform) as Box<_>
|
||||
}
|
||||
PlatformIdentifier::ZombienetRevmSolc => Box::new(ZombienetRevmSolcPlatform) as Box<_>,
|
||||
PlatformIdentifier::PolkadotOmniNodePolkavmResolc => {
|
||||
Box::new(PolkadotOmniNodePolkavmResolcPlatform) as Box<_>
|
||||
}
|
||||
PlatformIdentifier::PolkadotOmniNodeRevmSolc => {
|
||||
Box::new(PolkadotOmniNodeRevmSolcPlatform) as Box<_>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -460,6 +599,12 @@ impl From<PlatformIdentifier> for &dyn Platform {
|
||||
&ZombienetPolkavmResolcPlatform as &dyn Platform
|
||||
}
|
||||
PlatformIdentifier::ZombienetRevmSolc => &ZombienetRevmSolcPlatform as &dyn Platform,
|
||||
PlatformIdentifier::PolkadotOmniNodePolkavmResolc => {
|
||||
&PolkadotOmniNodePolkavmResolcPlatform as &dyn Platform
|
||||
}
|
||||
PlatformIdentifier::PolkadotOmniNodeRevmSolc => {
|
||||
&PolkadotOmniNodeRevmSolcPlatform as &dyn Platform
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-6
@@ -2,9 +2,9 @@ mod differential_benchmarks;
|
||||
mod differential_tests;
|
||||
mod helpers;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use anyhow::{Context as _, bail};
|
||||
use clap::Parser;
|
||||
use revive_dt_report::ReportAggregator;
|
||||
use revive_dt_report::{ReportAggregator, TestCaseStatus};
|
||||
use schemars::schema_for;
|
||||
use tracing::{info, level_filters::LevelFilter};
|
||||
use tracing_subscriber::{EnvFilter, FmtSubscriber};
|
||||
@@ -57,8 +57,22 @@ fn main() -> anyhow::Result<()> {
|
||||
let differential_tests_handling_task =
|
||||
handle_differential_tests(*context, reporter);
|
||||
|
||||
futures::future::try_join(differential_tests_handling_task, report_aggregator_task)
|
||||
.await?;
|
||||
let (_, report) = futures::future::try_join(
|
||||
differential_tests_handling_task,
|
||||
report_aggregator_task,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let contains_failure = report
|
||||
.execution_information
|
||||
.values()
|
||||
.flat_map(|values| values.case_reports.values())
|
||||
.flat_map(|values| values.mode_execution_reports.values())
|
||||
.any(|report| matches!(report.status, Some(TestCaseStatus::Failed { .. })));
|
||||
|
||||
if contains_failure {
|
||||
bail!("Some tests failed")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}),
|
||||
@@ -71,12 +85,23 @@ fn main() -> anyhow::Result<()> {
|
||||
let differential_benchmarks_handling_task =
|
||||
handle_differential_benchmarks(*context, reporter);
|
||||
|
||||
futures::future::try_join(
|
||||
let (_, report) = futures::future::try_join(
|
||||
differential_benchmarks_handling_task,
|
||||
report_aggregator_task,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let contains_failure = report
|
||||
.execution_information
|
||||
.values()
|
||||
.flat_map(|values| values.case_reports.values())
|
||||
.flat_map(|values| values.mode_execution_reports.values())
|
||||
.any(|report| matches!(report.status, Some(TestCaseStatus::Failed { .. })));
|
||||
|
||||
if contains_failure {
|
||||
bail!("Some benchmarks failed")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}),
|
||||
Context::ExportGenesis(ref export_genesis_context) => {
|
||||
@@ -85,11 +110,17 @@ fn main() -> anyhow::Result<()> {
|
||||
let genesis_json = serde_json::to_string_pretty(&genesis)
|
||||
.context("Failed to serialize the genesis to JSON")?;
|
||||
println!("{genesis_json}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Context::ExportJsonSchema => {
|
||||
let schema = schema_for!(Metadata);
|
||||
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&schema)
|
||||
.context("Failed to export the JSON schema")?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ pub struct GethNode {
|
||||
wallet: Arc<EthereumWallet>,
|
||||
nonce_manager: CachedNonceManager,
|
||||
provider: OnceCell<ConcreteProvider<Ethereum, Arc<EthereumWallet>>>,
|
||||
use_fallback_gas_filler: bool,
|
||||
}
|
||||
|
||||
impl GethNode {
|
||||
@@ -100,6 +101,7 @@ impl GethNode {
|
||||
+ AsRef<WalletConfiguration>
|
||||
+ AsRef<GethConfiguration>
|
||||
+ Clone,
|
||||
use_fallback_gas_filler: bool,
|
||||
) -> Self {
|
||||
let working_directory_configuration =
|
||||
AsRef::<WorkingDirectoryConfiguration>::as_ref(&context);
|
||||
@@ -126,6 +128,7 @@ impl GethNode {
|
||||
wallet: wallet.clone(),
|
||||
nonce_manager: Default::default(),
|
||||
provider: Default::default(),
|
||||
use_fallback_gas_filler,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +249,8 @@ impl GethNode {
|
||||
.get_or_try_init(|| async move {
|
||||
construct_concurrency_limited_provider::<Ethereum, _>(
|
||||
self.connection_string.as_str(),
|
||||
FallbackGasFiller::default(),
|
||||
FallbackGasFiller::default()
|
||||
.with_fallback_mechanism(self.use_fallback_gas_filler),
|
||||
ChainIdFiller::new(Some(CHAIN_ID)),
|
||||
NonceFiller::new(self.nonce_manager.clone()),
|
||||
self.wallet.clone(),
|
||||
@@ -742,7 +746,7 @@ mod tests {
|
||||
|
||||
fn new_node() -> (TestExecutionContext, GethNode) {
|
||||
let context = test_config();
|
||||
let mut node = GethNode::new(&context);
|
||||
let mut node = GethNode::new(&context, true);
|
||||
node.init(context.genesis_configuration.genesis().unwrap().clone())
|
||||
.expect("Failed to initialize the node")
|
||||
.spawn_process()
|
||||
|
||||
@@ -106,6 +106,8 @@ pub struct LighthouseGethNode {
|
||||
|
||||
persistent_http_provider: OnceCell<ConcreteProvider<Ethereum, Arc<EthereumWallet>>>,
|
||||
persistent_ws_provider: OnceCell<ConcreteProvider<Ethereum, Arc<EthereumWallet>>>,
|
||||
|
||||
use_fallback_gas_filler: bool,
|
||||
}
|
||||
|
||||
impl LighthouseGethNode {
|
||||
@@ -127,6 +129,7 @@ impl LighthouseGethNode {
|
||||
+ AsRef<WalletConfiguration>
|
||||
+ AsRef<KurtosisConfiguration>
|
||||
+ Clone,
|
||||
use_fallback_gas_filler: bool,
|
||||
) -> Self {
|
||||
let working_directory_configuration =
|
||||
AsRef::<WorkingDirectoryConfiguration>::as_ref(&context);
|
||||
@@ -176,6 +179,7 @@ impl LighthouseGethNode {
|
||||
nonce_manager: Default::default(),
|
||||
persistent_http_provider: OnceCell::const_new(),
|
||||
persistent_ws_provider: OnceCell::const_new(),
|
||||
use_fallback_gas_filler,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +378,8 @@ impl LighthouseGethNode {
|
||||
.get_or_try_init(|| async move {
|
||||
construct_concurrency_limited_provider::<Ethereum, _>(
|
||||
self.ws_connection_string.as_str(),
|
||||
FallbackGasFiller::default(),
|
||||
FallbackGasFiller::default()
|
||||
.with_fallback_mechanism(self.use_fallback_gas_filler),
|
||||
ChainIdFiller::new(Some(CHAIN_ID)),
|
||||
NonceFiller::new(self.nonce_manager.clone()),
|
||||
self.wallet.clone(),
|
||||
@@ -1152,7 +1157,7 @@ mod tests {
|
||||
let _guard = NODE_START_MUTEX.lock().unwrap();
|
||||
|
||||
let context = test_config();
|
||||
let mut node = LighthouseGethNode::new(&context);
|
||||
let mut node = LighthouseGethNode::new(&context, true);
|
||||
node.init(context.genesis_configuration.genesis().unwrap().clone())
|
||||
.expect("Failed to initialize the node")
|
||||
.spawn_process()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod geth;
|
||||
pub mod lighthouse_geth;
|
||||
pub mod polkadot_omni_node;
|
||||
pub mod substrate;
|
||||
pub mod zombienet;
|
||||
|
||||
@@ -0,0 +1,790 @@
|
||||
use std::{
|
||||
fs::{File, create_dir_all, remove_dir_all},
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
process::{Command, Stdio},
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicU32, Ordering},
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use alloy::{
|
||||
eips::BlockNumberOrTag,
|
||||
genesis::Genesis,
|
||||
network::{Ethereum, EthereumWallet, NetworkWallet},
|
||||
primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, StorageKey, TxHash, U256},
|
||||
providers::{
|
||||
Provider,
|
||||
ext::DebugApi,
|
||||
fillers::{CachedNonceManager, ChainIdFiller, NonceFiller},
|
||||
},
|
||||
rpc::types::{
|
||||
EIP1186AccountProofResponse, TransactionReceipt, TransactionRequest,
|
||||
trace::geth::{
|
||||
DiffMode, GethDebugTracingOptions, GethTrace, PreStateConfig, PreStateFrame,
|
||||
},
|
||||
},
|
||||
};
|
||||
use anyhow::Context as _;
|
||||
use futures::{FutureExt, Stream, StreamExt};
|
||||
use revive_common::EVMVersion;
|
||||
use revive_dt_common::fs::clear_directory;
|
||||
use revive_dt_format::traits::ResolverApi;
|
||||
use serde_json::json;
|
||||
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 subxt::{OnlineClient, SubstrateConfig};
|
||||
use tokio::sync::OnceCell;
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
use crate::{
|
||||
Node,
|
||||
constants::INITIAL_BALANCE,
|
||||
helpers::{Process, ProcessReadinessWaitBehavior},
|
||||
provider_utils::{
|
||||
ConcreteProvider, FallbackGasFiller, construct_concurrency_limited_provider,
|
||||
execute_transaction,
|
||||
},
|
||||
};
|
||||
|
||||
static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
/// The number of blocks that should be cached by the polkadot-omni-node and the eth-rpc.
|
||||
const NUMBER_OF_CACHED_BLOCKS: u32 = 100_000;
|
||||
|
||||
/// A node implementation for the polkadot-omni-node.
|
||||
#[derive(Debug)]
|
||||
|
||||
pub struct PolkadotOmnichainNode {
|
||||
/// The id of the node.
|
||||
id: u32,
|
||||
|
||||
/// The path of the polkadot-omni-chain node binary.
|
||||
polkadot_omnichain_node_binary_path: PathBuf,
|
||||
/// The path of the eth-rpc binary.
|
||||
eth_rpc_binary_path: PathBuf,
|
||||
/// The path of the runtime's WASM that this node will be spawned with.
|
||||
chain_spec_path: Option<PathBuf>,
|
||||
/// The path of the base directory which contains all of the stored data for this node.
|
||||
base_directory_path: PathBuf,
|
||||
/// The path of the logs directory which contains all of the stored logs.
|
||||
logs_directory_path: PathBuf,
|
||||
|
||||
/// Defines the amount of time to wait before considering that the node start has timed out.
|
||||
node_start_timeout: Duration,
|
||||
|
||||
/// The id of the parachain that this node will be spawning.
|
||||
parachain_id: Option<usize>,
|
||||
/// The block time.
|
||||
block_time: Duration,
|
||||
|
||||
/// The node's process.
|
||||
polkadot_omnichain_node_process: Option<Process>,
|
||||
/// The eth-rpc's process.
|
||||
eth_rpc_process: Option<Process>,
|
||||
|
||||
/// The URL of the eth-rpc.
|
||||
rpc_url: String,
|
||||
/// The wallet object that's used to sign any transaction submitted through this node.
|
||||
wallet: Arc<EthereumWallet>,
|
||||
/// The nonce manager used to populate nonces for all transactions submitted through this node.
|
||||
nonce_manager: CachedNonceManager,
|
||||
/// The provider used for all RPC interactions with the RPC of this node.
|
||||
provider: OnceCell<ConcreteProvider<Ethereum, Arc<EthereumWallet>>>,
|
||||
|
||||
/// A boolean that controls if the fallback gas filler should be used or not.
|
||||
use_fallback_gas_filler: bool,
|
||||
}
|
||||
|
||||
impl PolkadotOmnichainNode {
|
||||
const BASE_DIRECTORY: &str = "polkadot-omni-node";
|
||||
const LOGS_DIRECTORY: &str = "logs";
|
||||
|
||||
const POLKADOT_OMNICHAIN_NODE_READY_MARKER: &str = "Running JSON-RPC server";
|
||||
const ETH_RPC_READY_MARKER: &str = "Running JSON-RPC server";
|
||||
const CHAIN_SPEC_JSON_FILE: &str = "template_chainspec.json";
|
||||
const BASE_POLKADOT_OMNICHAIN_NODE_RPC_PORT: u16 = 9944;
|
||||
const BASE_ETH_RPC_PORT: u16 = 8545;
|
||||
|
||||
const POLKADOT_OMNICHAIN_NODE_LOG_ENV: &str =
|
||||
"error,evm=debug,sc_rpc_server=info,runtime::revive=debug";
|
||||
const RPC_LOG_ENV: &str = "info,eth-rpc=debug";
|
||||
|
||||
pub fn new(
|
||||
context: impl AsRef<WorkingDirectoryConfiguration>
|
||||
+ AsRef<EthRpcConfiguration>
|
||||
+ AsRef<WalletConfiguration>
|
||||
+ AsRef<PolkadotOmnichainNodeConfiguration>,
|
||||
use_fallback_gas_filler: bool,
|
||||
) -> Self {
|
||||
let polkadot_omnichain_node_configuration =
|
||||
AsRef::<PolkadotOmnichainNodeConfiguration>::as_ref(&context);
|
||||
let working_directory_path =
|
||||
AsRef::<WorkingDirectoryConfiguration>::as_ref(&context).as_path();
|
||||
let eth_rpc_path = AsRef::<EthRpcConfiguration>::as_ref(&context)
|
||||
.path
|
||||
.as_path();
|
||||
let wallet = AsRef::<WalletConfiguration>::as_ref(&context).wallet();
|
||||
|
||||
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
|
||||
let base_directory = working_directory_path
|
||||
.join(Self::BASE_DIRECTORY)
|
||||
.join(id.to_string());
|
||||
let logs_directory = base_directory.join(Self::LOGS_DIRECTORY);
|
||||
|
||||
Self {
|
||||
id,
|
||||
polkadot_omnichain_node_binary_path: polkadot_omnichain_node_configuration
|
||||
.path
|
||||
.to_path_buf(),
|
||||
eth_rpc_binary_path: eth_rpc_path.to_path_buf(),
|
||||
chain_spec_path: polkadot_omnichain_node_configuration
|
||||
.chain_spec_path
|
||||
.clone(),
|
||||
base_directory_path: base_directory,
|
||||
logs_directory_path: logs_directory,
|
||||
parachain_id: polkadot_omnichain_node_configuration.parachain_id,
|
||||
block_time: polkadot_omnichain_node_configuration.block_time,
|
||||
polkadot_omnichain_node_process: Default::default(),
|
||||
eth_rpc_process: Default::default(),
|
||||
rpc_url: Default::default(),
|
||||
wallet,
|
||||
nonce_manager: Default::default(),
|
||||
provider: Default::default(),
|
||||
use_fallback_gas_filler,
|
||||
node_start_timeout: polkadot_omnichain_node_configuration.start_timeout_ms,
|
||||
}
|
||||
}
|
||||
|
||||
fn init(&mut self, _: Genesis) -> anyhow::Result<&mut Self> {
|
||||
trace!("Removing the various directories");
|
||||
let _ = remove_dir_all(self.base_directory_path.as_path());
|
||||
let _ = clear_directory(&self.base_directory_path);
|
||||
let _ = clear_directory(&self.logs_directory_path);
|
||||
|
||||
trace!("Creating the various directories");
|
||||
create_dir_all(&self.base_directory_path)
|
||||
.context("Failed to create base directory for polkadot-omni-node node")?;
|
||||
create_dir_all(&self.logs_directory_path)
|
||||
.context("Failed to create logs directory for polkadot-omni-node node")?;
|
||||
|
||||
let template_chainspec_path = self.base_directory_path.join(Self::CHAIN_SPEC_JSON_FILE);
|
||||
|
||||
let chainspec_json = Self::node_genesis(
|
||||
&self.wallet,
|
||||
self.chain_spec_path
|
||||
.as_ref()
|
||||
.context("No runtime path provided")?,
|
||||
)
|
||||
.context("Failed to prepare the chainspec command")?;
|
||||
|
||||
serde_json::to_writer_pretty(
|
||||
std::fs::File::create(&template_chainspec_path)
|
||||
.context("Failed to create polkadot-omni-node template chainspec file")?,
|
||||
&chainspec_json,
|
||||
)
|
||||
.context("Failed to write polkadot-omni-node template chainspec JSON")?;
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn spawn_process(&mut self) -> anyhow::Result<()> {
|
||||
// Error out if the runtime's path or the parachain id are not set which means that the
|
||||
// arguments we require were not provided.
|
||||
self.chain_spec_path
|
||||
.as_ref()
|
||||
.context("No WASM path provided for the runtime")?;
|
||||
self.parachain_id
|
||||
.as_ref()
|
||||
.context("No argument provided for the parachain-id")?;
|
||||
|
||||
let polkadot_omnichain_node_rpc_port =
|
||||
Self::BASE_POLKADOT_OMNICHAIN_NODE_RPC_PORT + self.id as u16;
|
||||
let eth_rpc_port = Self::BASE_ETH_RPC_PORT + self.id as u16;
|
||||
|
||||
let chainspec_path = self.base_directory_path.join(Self::CHAIN_SPEC_JSON_FILE);
|
||||
|
||||
self.rpc_url = format!("http://127.0.0.1:{eth_rpc_port}");
|
||||
|
||||
let polkadot_omnichain_node_process = Process::new(
|
||||
"node",
|
||||
self.logs_directory_path.as_path(),
|
||||
self.polkadot_omnichain_node_binary_path.as_path(),
|
||||
|command, stdout_file, stderr_file| {
|
||||
command
|
||||
.arg("--log")
|
||||
.arg(Self::POLKADOT_OMNICHAIN_NODE_LOG_ENV)
|
||||
.arg("--dev-block-time")
|
||||
.arg(self.block_time.as_millis().to_string())
|
||||
.arg("--rpc-port")
|
||||
.arg(polkadot_omnichain_node_rpc_port.to_string())
|
||||
.arg("--base-path")
|
||||
.arg(self.base_directory_path.as_path())
|
||||
.arg("--no-prometheus")
|
||||
.arg("--no-hardware-benchmarks")
|
||||
.arg("--authoring")
|
||||
.arg("slot-based")
|
||||
.arg("--chain")
|
||||
.arg(chainspec_path)
|
||||
.arg("--name")
|
||||
.arg(format!("polkadot-omni-node-{}", self.id))
|
||||
.arg("--rpc-methods")
|
||||
.arg("unsafe")
|
||||
.arg("--rpc-cors")
|
||||
.arg("all")
|
||||
.arg("--rpc-max-connections")
|
||||
.arg(u32::MAX.to_string())
|
||||
.arg("--pool-limit")
|
||||
.arg(u32::MAX.to_string())
|
||||
.arg("--pool-kbytes")
|
||||
.arg(u32::MAX.to_string())
|
||||
.arg("--state-pruning")
|
||||
.arg(NUMBER_OF_CACHED_BLOCKS.to_string())
|
||||
.env("RUST_LOG", Self::POLKADOT_OMNICHAIN_NODE_LOG_ENV)
|
||||
.stdout(stdout_file)
|
||||
.stderr(stderr_file);
|
||||
},
|
||||
ProcessReadinessWaitBehavior::TimeBoundedWaitFunction {
|
||||
max_wait_duration: self.node_start_timeout,
|
||||
check_function: Box::new(|_, stderr_line| match stderr_line {
|
||||
Some(line) => Ok(line.contains(Self::POLKADOT_OMNICHAIN_NODE_READY_MARKER)),
|
||||
None => Ok(false),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
match polkadot_omnichain_node_process {
|
||||
Ok(process) => self.polkadot_omnichain_node_process = Some(process),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
?err,
|
||||
"Failed to start polkadot-omni-node, shutting down gracefully"
|
||||
);
|
||||
self.shutdown().context(
|
||||
"Failed to gracefully shutdown after polkadot-omni-node start error",
|
||||
)?;
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
let eth_rpc_process = Process::new(
|
||||
"eth-rpc",
|
||||
self.logs_directory_path.as_path(),
|
||||
self.eth_rpc_binary_path.as_path(),
|
||||
|command, stdout_file, stderr_file| {
|
||||
command
|
||||
.arg("--dev")
|
||||
.arg("--rpc-port")
|
||||
.arg(eth_rpc_port.to_string())
|
||||
.arg("--node-rpc-url")
|
||||
.arg(format!("ws://127.0.0.1:{polkadot_omnichain_node_rpc_port}"))
|
||||
.arg("--rpc-max-connections")
|
||||
.arg(u32::MAX.to_string())
|
||||
.arg("--index-last-n-blocks")
|
||||
.arg(NUMBER_OF_CACHED_BLOCKS.to_string())
|
||||
.arg("--cache-size")
|
||||
.arg(NUMBER_OF_CACHED_BLOCKS.to_string())
|
||||
.env("RUST_LOG", Self::RPC_LOG_ENV)
|
||||
.stdout(stdout_file)
|
||||
.stderr(stderr_file);
|
||||
},
|
||||
ProcessReadinessWaitBehavior::TimeBoundedWaitFunction {
|
||||
max_wait_duration: Duration::from_secs(30),
|
||||
check_function: Box::new(|_, stderr_line| match stderr_line {
|
||||
Some(line) => Ok(line.contains(Self::ETH_RPC_READY_MARKER)),
|
||||
None => Ok(false),
|
||||
}),
|
||||
},
|
||||
);
|
||||
match eth_rpc_process {
|
||||
Ok(process) => self.eth_rpc_process = Some(process),
|
||||
Err(err) => {
|
||||
tracing::error!(?err, "Failed to start eth-rpc, shutting down gracefully");
|
||||
self.shutdown()
|
||||
.context("Failed to gracefully shutdown after eth-rpc start error")?;
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn eth_to_substrate_address(address: &Address) -> String {
|
||||
let eth_bytes = address.0.0;
|
||||
|
||||
let mut padded = [0xEEu8; 32];
|
||||
padded[..20].copy_from_slice(ð_bytes);
|
||||
|
||||
let account_id = AccountId32::from(padded);
|
||||
account_id.to_ss58check()
|
||||
}
|
||||
|
||||
pub fn eth_rpc_version(&self) -> anyhow::Result<String> {
|
||||
let output = Command::new(&self.eth_rpc_binary_path)
|
||||
.arg("--version")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()?
|
||||
.wait_with_output()?
|
||||
.stdout;
|
||||
Ok(String::from_utf8_lossy(&output).trim().to_string())
|
||||
}
|
||||
|
||||
async fn provider(&self) -> anyhow::Result<ConcreteProvider<Ethereum, Arc<EthereumWallet>>> {
|
||||
self.provider
|
||||
.get_or_try_init(|| async move {
|
||||
construct_concurrency_limited_provider::<Ethereum, _>(
|
||||
self.rpc_url.as_str(),
|
||||
FallbackGasFiller::default()
|
||||
.with_fallback_mechanism(self.use_fallback_gas_filler),
|
||||
ChainIdFiller::default(),
|
||||
NonceFiller::new(self.nonce_manager.clone()),
|
||||
self.wallet.clone(),
|
||||
)
|
||||
.await
|
||||
.context("Failed to construct the provider")
|
||||
})
|
||||
.await
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn node_genesis(
|
||||
wallet: &EthereumWallet,
|
||||
chain_spec_path: &Path,
|
||||
) -> anyhow::Result<serde_json::Value> {
|
||||
let unmodified_chainspec_file =
|
||||
File::open(chain_spec_path).context("Failed to open the unmodified chainspec file")?;
|
||||
let mut chainspec_json =
|
||||
serde_json::from_reader::<_, serde_json::Value>(&unmodified_chainspec_file)
|
||||
.context("Failed to read the unmodified chainspec JSON")?;
|
||||
|
||||
let existing_chainspec_balances =
|
||||
chainspec_json["genesis"]["runtimeGenesis"]["patch"]["balances"]["balances"]
|
||||
.as_array_mut()
|
||||
.expect("Can't fail");
|
||||
|
||||
for address in NetworkWallet::<Ethereum>::signer_addresses(wallet) {
|
||||
let substrate_address = Self::eth_to_substrate_address(&address);
|
||||
let balance = INITIAL_BALANCE;
|
||||
existing_chainspec_balances.push(json!((substrate_address, balance)));
|
||||
}
|
||||
|
||||
Ok(chainspec_json)
|
||||
}
|
||||
}
|
||||
|
||||
impl EthereumNode for PolkadotOmnichainNode {
|
||||
fn pre_transactions(&mut self) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + '_>> {
|
||||
Box::pin(async move { Ok(()) })
|
||||
}
|
||||
|
||||
fn id(&self) -> usize {
|
||||
self.id as _
|
||||
}
|
||||
|
||||
fn connection_string(&self) -> &str {
|
||||
&self.rpc_url
|
||||
}
|
||||
|
||||
fn submit_transaction(
|
||||
&self,
|
||||
transaction: TransactionRequest,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<TxHash>> + '_>> {
|
||||
Box::pin(async move {
|
||||
let provider = self
|
||||
.provider()
|
||||
.await
|
||||
.context("Failed to create the provider for transaction submission")?;
|
||||
let pending_transaction = provider
|
||||
.send_transaction(transaction)
|
||||
.await
|
||||
.context("Failed to submit the transaction through the provider")?;
|
||||
Ok(*pending_transaction.tx_hash())
|
||||
})
|
||||
}
|
||||
|
||||
fn get_receipt(
|
||||
&self,
|
||||
tx_hash: TxHash,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<TransactionReceipt>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider()
|
||||
.await
|
||||
.context("Failed to create provider for getting the receipt")?
|
||||
.get_transaction_receipt(tx_hash)
|
||||
.await
|
||||
.context("Failed to get the receipt of the transaction")?
|
||||
.context("Failed to get the receipt of the transaction")
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_transaction(
|
||||
&self,
|
||||
transaction: TransactionRequest,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<TransactionReceipt>> + '_>> {
|
||||
Box::pin(async move {
|
||||
let provider = self
|
||||
.provider()
|
||||
.await
|
||||
.context("Failed to create the provider")?;
|
||||
execute_transaction(provider, transaction).await
|
||||
})
|
||||
}
|
||||
|
||||
fn trace_transaction(
|
||||
&self,
|
||||
tx_hash: TxHash,
|
||||
trace_options: GethDebugTracingOptions,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<GethTrace>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider()
|
||||
.await
|
||||
.context("Failed to create provider for debug tracing")?
|
||||
.debug_trace_transaction(tx_hash, trace_options)
|
||||
.await
|
||||
.context("Failed to obtain debug trace from eth-proxy")
|
||||
})
|
||||
}
|
||||
|
||||
fn state_diff(
|
||||
&self,
|
||||
tx_hash: TxHash,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<DiffMode>> + '_>> {
|
||||
Box::pin(async move {
|
||||
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
|
||||
diff_mode: Some(true),
|
||||
disable_code: None,
|
||||
disable_storage: None,
|
||||
});
|
||||
match self
|
||||
.trace_transaction(tx_hash, trace_options)
|
||||
.await?
|
||||
.try_into_pre_state_frame()?
|
||||
{
|
||||
PreStateFrame::Diff(diff) => Ok(diff),
|
||||
_ => anyhow::bail!("expected a diff mode trace"),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn balance_of(
|
||||
&self,
|
||||
address: Address,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<U256>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider()
|
||||
.await
|
||||
.context("Failed to get the eth-rpc provider")?
|
||||
.get_balance(address)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
}
|
||||
|
||||
fn latest_state_proof(
|
||||
&self,
|
||||
address: Address,
|
||||
keys: Vec<StorageKey>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<EIP1186AccountProofResponse>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider()
|
||||
.await
|
||||
.context("Failed to get the eth-rpc provider")?
|
||||
.get_proof(address, keys)
|
||||
.latest()
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
}
|
||||
|
||||
fn resolver(
|
||||
&self,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<Arc<dyn ResolverApi + '_>>> + '_>> {
|
||||
Box::pin(async move {
|
||||
let id = self.id;
|
||||
let provider = self.provider().await?;
|
||||
Ok(Arc::new(PolkadotOmnichainNodeResolver { id, provider }) as Arc<dyn ResolverApi>)
|
||||
})
|
||||
}
|
||||
|
||||
fn evm_version(&self) -> EVMVersion {
|
||||
EVMVersion::Cancun
|
||||
}
|
||||
|
||||
fn subscribe_to_full_blocks_information(
|
||||
&self,
|
||||
) -> Pin<
|
||||
Box<
|
||||
dyn Future<Output = anyhow::Result<Pin<Box<dyn Stream<Item = MinedBlockInformation>>>>>
|
||||
+ '_,
|
||||
>,
|
||||
> {
|
||||
#[subxt::subxt(runtime_metadata_path = "../../assets/revive_metadata.scale")]
|
||||
pub mod revive {}
|
||||
|
||||
Box::pin(async move {
|
||||
let polkadot_omnichain_node_rpc_port =
|
||||
Self::BASE_POLKADOT_OMNICHAIN_NODE_RPC_PORT + self.id as u16;
|
||||
let polkadot_omnichain_node_rpc_url =
|
||||
format!("ws://127.0.0.1:{polkadot_omnichain_node_rpc_port}");
|
||||
let api = OnlineClient::<SubstrateConfig>::from_url(polkadot_omnichain_node_rpc_url)
|
||||
.await
|
||||
.context("Failed to create subxt rpc client")?;
|
||||
let provider = self.provider().await.context("Failed to create provider")?;
|
||||
|
||||
let block_stream = api
|
||||
.blocks()
|
||||
.subscribe_all()
|
||||
.await
|
||||
.context("Failed to subscribe to blocks")?;
|
||||
|
||||
let mined_block_information_stream = block_stream.filter_map(move |block| {
|
||||
let api = api.clone();
|
||||
let provider = provider.clone();
|
||||
|
||||
async move {
|
||||
let substrate_block = block.ok()?;
|
||||
let revive_block = provider
|
||||
.get_block_by_number(
|
||||
BlockNumberOrTag::Number(substrate_block.number() as _),
|
||||
)
|
||||
.await
|
||||
.expect("TODO: Remove")
|
||||
.expect("TODO: Remove");
|
||||
|
||||
let used = api
|
||||
.storage()
|
||||
.at(substrate_block.reference())
|
||||
.fetch_or_default(&revive::storage().system().block_weight())
|
||||
.await
|
||||
.expect("TODO: Remove");
|
||||
|
||||
let block_ref_time = (used.normal.ref_time as u128)
|
||||
+ (used.operational.ref_time as u128)
|
||||
+ (used.mandatory.ref_time as u128);
|
||||
let block_proof_size = (used.normal.proof_size as u128)
|
||||
+ (used.operational.proof_size as u128)
|
||||
+ (used.mandatory.proof_size as u128);
|
||||
|
||||
let limits = api
|
||||
.constants()
|
||||
.at(&revive::constants().system().block_weights())
|
||||
.expect("TODO: Remove");
|
||||
|
||||
let max_ref_time = limits.max_block.ref_time;
|
||||
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,
|
||||
}),
|
||||
tx_counts: Default::default(),
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Box::pin(mined_block_information_stream)
|
||||
as Pin<Box<dyn Stream<Item = MinedBlockInformation>>>)
|
||||
})
|
||||
}
|
||||
|
||||
fn provider(
|
||||
&self,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<alloy::providers::DynProvider<Ethereum>>> + '_>>
|
||||
{
|
||||
Box::pin(
|
||||
self.provider()
|
||||
.map(|provider| provider.map(|provider| provider.erased())),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PolkadotOmnichainNodeResolver {
|
||||
id: u32,
|
||||
provider: ConcreteProvider<Ethereum, Arc<EthereumWallet>>,
|
||||
}
|
||||
|
||||
impl ResolverApi for PolkadotOmnichainNodeResolver {
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn chain_id(
|
||||
&self,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<alloy::primitives::ChainId>> + '_>> {
|
||||
Box::pin(async move { self.provider.get_chain_id().await.map_err(Into::into) })
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn transaction_gas_price(
|
||||
&self,
|
||||
tx_hash: TxHash,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<u128>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_transaction_receipt(tx_hash)
|
||||
.await?
|
||||
.context("Failed to get the transaction receipt")
|
||||
.map(|receipt| receipt.effective_gas_price)
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn block_gas_limit(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<u128>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_block_by_number(number)
|
||||
.await
|
||||
.context("Failed to get the eth-rpc block")?
|
||||
.context("Failed to get the eth-rpc block, perhaps the chain has no blocks?")
|
||||
.map(|block| block.header.gas_limit as _)
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn block_coinbase(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<Address>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_block_by_number(number)
|
||||
.await
|
||||
.context("Failed to get the eth-rpc block")?
|
||||
.context("Failed to get the eth-rpc block, perhaps the chain has no blocks?")
|
||||
.map(|block| block.header.beneficiary)
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn block_difficulty(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<U256>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_block_by_number(number)
|
||||
.await
|
||||
.context("Failed to get the eth-rpc block")?
|
||||
.context("Failed to get the eth-rpc block, perhaps the chain has no blocks?")
|
||||
.map(|block| U256::from_be_bytes(block.header.mix_hash.0))
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn block_base_fee(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<u64>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_block_by_number(number)
|
||||
.await
|
||||
.context("Failed to get the eth-rpc block")?
|
||||
.context("Failed to get the eth-rpc block, perhaps the chain has no blocks?")
|
||||
.and_then(|block| {
|
||||
block
|
||||
.header
|
||||
.base_fee_per_gas
|
||||
.context("Failed to get the base fee per gas")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn block_hash(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<BlockHash>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_block_by_number(number)
|
||||
.await
|
||||
.context("Failed to get the eth-rpc block")?
|
||||
.context("Failed to get the eth-rpc block, perhaps the chain has no blocks?")
|
||||
.map(|block| block.header.hash)
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn block_timestamp(
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<BlockTimestamp>> + '_>> {
|
||||
Box::pin(async move {
|
||||
self.provider
|
||||
.get_block_by_number(number)
|
||||
.await
|
||||
.context("Failed to get the eth-rpc block")?
|
||||
.context("Failed to get the eth-rpc block, perhaps the chain has no blocks?")
|
||||
.map(|block| block.header.timestamp)
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip_all, fields(polkadot_omnichain_node_id = self.id))]
|
||||
fn last_block_number(&self) -> Pin<Box<dyn Future<Output = anyhow::Result<BlockNumber>> + '_>> {
|
||||
Box::pin(async move { self.provider.get_block_number().await.map_err(Into::into) })
|
||||
}
|
||||
}
|
||||
|
||||
impl Node for PolkadotOmnichainNode {
|
||||
fn shutdown(&mut self) -> anyhow::Result<()> {
|
||||
drop(self.polkadot_omnichain_node_process.take());
|
||||
drop(self.eth_rpc_process.take());
|
||||
|
||||
// Remove the node's database so that subsequent runs do not run on the same database. We
|
||||
// ignore the error just in case the directory didn't exist in the first place and therefore
|
||||
// there's nothing to be deleted.
|
||||
let _ = remove_dir_all(self.base_directory_path.join("data"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn spawn(&mut self, genesis: Genesis) -> anyhow::Result<()> {
|
||||
self.init(genesis)?.spawn_process()
|
||||
}
|
||||
|
||||
fn version(&self) -> anyhow::Result<String> {
|
||||
let output = Command::new(&self.polkadot_omnichain_node_binary_path)
|
||||
.arg("--version")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
.context("Failed to spawn substrate --version")?
|
||||
.wait_with_output()
|
||||
.context("Failed to wait for substrate --version")?
|
||||
.stdout;
|
||||
Ok(String::from_utf8_lossy(&output).into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PolkadotOmnichainNode {
|
||||
fn drop(&mut self) {
|
||||
self.shutdown().expect("Failed to shutdown")
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ use tracing::{instrument, trace};
|
||||
|
||||
use crate::{
|
||||
Node,
|
||||
constants::{CHAIN_ID, INITIAL_BALANCE},
|
||||
constants::INITIAL_BALANCE,
|
||||
helpers::{Process, ProcessReadinessWaitBehavior},
|
||||
provider_utils::{
|
||||
ConcreteProvider, FallbackGasFiller, construct_concurrency_limited_provider,
|
||||
@@ -79,6 +79,7 @@ pub struct SubstrateNode {
|
||||
nonce_manager: CachedNonceManager,
|
||||
provider: OnceCell<ConcreteProvider<Ethereum, Arc<EthereumWallet>>>,
|
||||
consensus: Option<String>,
|
||||
use_fallback_gas_filler: bool,
|
||||
}
|
||||
|
||||
impl SubstrateNode {
|
||||
@@ -105,6 +106,7 @@ impl SubstrateNode {
|
||||
+ AsRef<EthRpcConfiguration>
|
||||
+ AsRef<WalletConfiguration>,
|
||||
existing_connection_strings: &[String],
|
||||
use_fallback_gas_filler: bool,
|
||||
) -> Self {
|
||||
let working_directory_path =
|
||||
AsRef::<WorkingDirectoryConfiguration>::as_ref(&context).as_path();
|
||||
@@ -137,6 +139,7 @@ impl SubstrateNode {
|
||||
nonce_manager: Default::default(),
|
||||
provider: Default::default(),
|
||||
consensus,
|
||||
use_fallback_gas_filler,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,8 +327,9 @@ impl SubstrateNode {
|
||||
.get_or_try_init(|| async move {
|
||||
construct_concurrency_limited_provider::<Ethereum, _>(
|
||||
self.rpc_url.as_str(),
|
||||
FallbackGasFiller::new(u64::MAX, 50_000_000_000, 1_000_000_000),
|
||||
ChainIdFiller::new(Some(CHAIN_ID)),
|
||||
FallbackGasFiller::default()
|
||||
.with_fallback_mechanism(self.use_fallback_gas_filler),
|
||||
ChainIdFiller::default(),
|
||||
NonceFiller::new(self.nonce_manager.clone()),
|
||||
self.wallet.clone(),
|
||||
)
|
||||
@@ -825,6 +829,7 @@ mod tests {
|
||||
None,
|
||||
&context,
|
||||
&[],
|
||||
true,
|
||||
);
|
||||
node.init(context.genesis_configuration.genesis().unwrap().clone())
|
||||
.expect("Failed to initialize the node")
|
||||
@@ -896,6 +901,7 @@ mod tests {
|
||||
None,
|
||||
&context,
|
||||
&[],
|
||||
true,
|
||||
);
|
||||
|
||||
// Call `init()`
|
||||
|
||||
@@ -114,6 +114,8 @@ pub struct ZombienetNode {
|
||||
nonce_manager: CachedNonceManager,
|
||||
|
||||
provider: OnceCell<ConcreteProvider<Ethereum, Arc<EthereumWallet>>>,
|
||||
|
||||
use_fallback_gas_filler: bool,
|
||||
}
|
||||
|
||||
impl ZombienetNode {
|
||||
@@ -137,6 +139,7 @@ impl ZombienetNode {
|
||||
context: impl AsRef<WorkingDirectoryConfiguration>
|
||||
+ AsRef<EthRpcConfiguration>
|
||||
+ AsRef<WalletConfiguration>,
|
||||
use_fallback_gas_filler: bool,
|
||||
) -> Self {
|
||||
let eth_proxy_binary = AsRef::<EthRpcConfiguration>::as_ref(&context)
|
||||
.path
|
||||
@@ -164,6 +167,7 @@ impl ZombienetNode {
|
||||
connection_string: String::new(),
|
||||
node_rpc_port: None,
|
||||
provider: Default::default(),
|
||||
use_fallback_gas_filler,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +334,8 @@ impl ZombienetNode {
|
||||
.get_or_try_init(|| async move {
|
||||
construct_concurrency_limited_provider::<Ethereum, _>(
|
||||
self.connection_string.as_str(),
|
||||
FallbackGasFiller::new(u64::MAX, 5_000_000_000, 1_000_000_000),
|
||||
FallbackGasFiller::default()
|
||||
.with_fallback_mechanism(self.use_fallback_gas_filler),
|
||||
ChainIdFiller::default(), // TODO: use CHAIN_ID constant
|
||||
NonceFiller::new(self.nonce_manager.clone()),
|
||||
self.wallet.clone(),
|
||||
@@ -823,6 +828,7 @@ mod tests {
|
||||
let mut node = ZombienetNode::new(
|
||||
context.polkadot_parachain_configuration.path.clone(),
|
||||
&context,
|
||||
true,
|
||||
);
|
||||
let genesis = context.genesis_configuration.genesis().unwrap().clone();
|
||||
node.init(genesis).unwrap();
|
||||
@@ -936,6 +942,7 @@ mod tests {
|
||||
let node = ZombienetNode::new(
|
||||
context.polkadot_parachain_configuration.path.clone(),
|
||||
&context,
|
||||
true,
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -956,6 +963,7 @@ mod tests {
|
||||
let node = ZombienetNode::new(
|
||||
context.polkadot_parachain_configuration.path.clone(),
|
||||
&context,
|
||||
true,
|
||||
);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -1,42 +1,71 @@
|
||||
use std::{borrow::Cow, fmt::Display};
|
||||
|
||||
use alloy::{
|
||||
eips::BlockNumberOrTag,
|
||||
network::{Network, TransactionBuilder},
|
||||
providers::{
|
||||
Provider, SendableTx,
|
||||
fillers::{GasFiller, TxFiller},
|
||||
ext::DebugApi,
|
||||
fillers::{GasFillable, GasFiller, TxFiller},
|
||||
},
|
||||
transports::TransportResult,
|
||||
rpc::types::trace::geth::{
|
||||
GethDebugBuiltInTracerType, GethDebugTracerType, GethDebugTracingCallOptions,
|
||||
GethDebugTracingOptions,
|
||||
},
|
||||
transports::{RpcError, TransportResult},
|
||||
};
|
||||
|
||||
// Percentage padding applied to estimated gas (e.g. 120 = 20% padding)
|
||||
const GAS_ESTIMATE_PADDING_NUMERATOR: u64 = 120;
|
||||
const GAS_ESTIMATE_PADDING_DENOMINATOR: u64 = 100;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// An implementation of [`GasFiller`] with a fallback mechanism for reverting transactions.
|
||||
///
|
||||
/// This struct provides a fallback mechanism for alloy's [`GasFiller`] which kicks in when a
|
||||
/// transaction's dry run fails due to it reverting allowing us to get gas estimates even for
|
||||
/// failing transactions. In this codebase, this is very important since the MatterLabs tests
|
||||
/// expect some transactions in the test suite revert. Since we're expected to run a number of
|
||||
/// assertions on these reverting transactions we must commit them to the ledger.
|
||||
///
|
||||
/// Therefore, this struct does the following:
|
||||
///
|
||||
/// 1. It first attempts to estimate the gas through the mechanism implemented in the [`GasFiller`].
|
||||
/// 2. If it fails, then we perform a debug trace of the transaction to find out how much gas the
|
||||
/// transaction needs until it reverts.
|
||||
/// 3. We fill in these values (either the success or failure case) into the transaction.
|
||||
///
|
||||
/// The fallback mechanism of this filler can be completely disabled if we don't want it to be used.
|
||||
/// In that case, this gas filler will act in an identical way to alloy's [`GasFiller`].
|
||||
///
|
||||
/// We then fill in these values into the transaction.
|
||||
///
|
||||
/// The previous implementation of this fallback gas filler relied on making use of default values
|
||||
/// for the gas limit in order to be able to submit the reverting transactions to the network. But,
|
||||
/// it introduced a number of issues that we weren't anticipating at the time when it was built.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct FallbackGasFiller {
|
||||
/// The inner [`GasFiller`] which we pass all of the calls to in the happy path.
|
||||
inner: GasFiller,
|
||||
default_gas_limit: u64,
|
||||
default_max_fee_per_gas: u128,
|
||||
default_priority_fee: u128,
|
||||
|
||||
/// A [`bool`] that controls if the fallback mechanism is enabled or not.
|
||||
enable_fallback_mechanism: bool,
|
||||
}
|
||||
|
||||
impl FallbackGasFiller {
|
||||
pub fn new(
|
||||
default_gas_limit: u64,
|
||||
default_max_fee_per_gas: u128,
|
||||
default_priority_fee: u128,
|
||||
) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: GasFiller,
|
||||
default_gas_limit,
|
||||
default_max_fee_per_gas,
|
||||
default_priority_fee,
|
||||
inner: Default::default(),
|
||||
enable_fallback_mechanism: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FallbackGasFiller {
|
||||
fn default() -> Self {
|
||||
FallbackGasFiller::new(25_000_000, 1_000_000_000, 1_000_000_000)
|
||||
pub fn with_fallback_mechanism(mut self, enable: bool) -> Self {
|
||||
self.enable_fallback_mechanism = enable;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_fallback_mechanism_enabled(self) -> Self {
|
||||
self.with_fallback_mechanism(true)
|
||||
}
|
||||
|
||||
pub fn with_fallback_mechanism_disabled(self) -> Self {
|
||||
self.with_fallback_mechanism(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,27 +73,89 @@ impl<N> TxFiller<N> for FallbackGasFiller
|
||||
where
|
||||
N: Network,
|
||||
{
|
||||
type Fillable = Option<<GasFiller as TxFiller<N>>::Fillable>;
|
||||
type Fillable = <GasFiller as TxFiller<N>>::Fillable;
|
||||
|
||||
fn status(
|
||||
&self,
|
||||
tx: &<N as Network>::TransactionRequest,
|
||||
) -> alloy::providers::fillers::FillerControlFlow {
|
||||
<GasFiller as TxFiller<N>>::status(&self.inner, tx)
|
||||
TxFiller::<N>::status(&self.inner, tx)
|
||||
}
|
||||
|
||||
fn fill_sync(&self, _: &mut alloy::providers::SendableTx<N>) {}
|
||||
fn fill_sync(&self, _: &mut SendableTx<N>) {}
|
||||
|
||||
async fn prepare<P: Provider<N>>(
|
||||
&self,
|
||||
provider: &P,
|
||||
tx: &<N as Network>::TransactionRequest,
|
||||
) -> TransportResult<Self::Fillable> {
|
||||
match self.inner.prepare(provider, tx).await {
|
||||
Ok(fill) => Ok(Some(fill)),
|
||||
Err(err) => {
|
||||
tracing::debug!(error = ?err, "Gas Provider Estimation Failed, using fallback");
|
||||
Ok(None)
|
||||
match (
|
||||
self.inner.prepare(provider, tx).await,
|
||||
self.enable_fallback_mechanism,
|
||||
) {
|
||||
// Return the same thing if either this calls succeeds, or if the call falls and the
|
||||
// fallback mechanism is disabled.
|
||||
(rtn @ Ok(..), ..) | (rtn @ Err(..), false) => rtn,
|
||||
(Err(..), true) => {
|
||||
// Perform a trace of the transaction.
|
||||
let trace = provider
|
||||
.debug_trace_call(
|
||||
tx.clone(),
|
||||
BlockNumberOrTag::Latest.into(),
|
||||
GethDebugTracingCallOptions {
|
||||
tracing_options: GethDebugTracingOptions {
|
||||
tracer: Some(GethDebugTracerType::BuiltInTracer(
|
||||
GethDebugBuiltInTracerType::CallTracer,
|
||||
)),
|
||||
..Default::default()
|
||||
},
|
||||
state_overrides: Default::default(),
|
||||
block_overrides: Default::default(),
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.try_into_call_frame()
|
||||
.map_err(|err| {
|
||||
RpcError::LocalUsageError(
|
||||
FallbackGasFillerError::new(format!(
|
||||
"Expected a callframe trace, but got: {err:?}"
|
||||
))
|
||||
.boxed(),
|
||||
)
|
||||
})?;
|
||||
|
||||
let gas_used = u64::try_from(trace.gas_used).map_err(|_| {
|
||||
RpcError::LocalUsageError(
|
||||
FallbackGasFillerError::new(
|
||||
"Transaction trace returned a value of gas used that exceeds u64",
|
||||
)
|
||||
.boxed(),
|
||||
)
|
||||
})?;
|
||||
let gas_limit = gas_used.saturating_mul(120) / 100;
|
||||
|
||||
if let Some(gas_price) = tx.gas_price() {
|
||||
return Ok(GasFillable::Legacy {
|
||||
gas_limit,
|
||||
gas_price,
|
||||
});
|
||||
}
|
||||
|
||||
let estimate = if let (Some(max_fee_per_gas), Some(max_priority_fee_per_gas)) =
|
||||
(tx.max_fee_per_gas(), tx.max_priority_fee_per_gas())
|
||||
{
|
||||
alloy::eips::eip1559::Eip1559Estimation {
|
||||
max_fee_per_gas,
|
||||
max_priority_fee_per_gas,
|
||||
}
|
||||
} else {
|
||||
provider.estimate_eip1559_fees().await?
|
||||
};
|
||||
|
||||
Ok(GasFillable::Eip1559 {
|
||||
gas_limit,
|
||||
estimate,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,27 +163,35 @@ where
|
||||
async fn fill(
|
||||
&self,
|
||||
fillable: Self::Fillable,
|
||||
mut tx: alloy::providers::SendableTx<N>,
|
||||
tx: SendableTx<N>,
|
||||
) -> TransportResult<SendableTx<N>> {
|
||||
if let Some(fill) = fillable {
|
||||
let mut tx = self.inner.fill(fill, tx).await?;
|
||||
if let Some(builder) = tx.as_mut_builder() {
|
||||
if let Some(estimated) = builder.gas_limit() {
|
||||
let padded = estimated
|
||||
.checked_mul(GAS_ESTIMATE_PADDING_NUMERATOR)
|
||||
.and_then(|v| v.checked_div(GAS_ESTIMATE_PADDING_DENOMINATOR))
|
||||
.unwrap_or(u64::MAX);
|
||||
builder.set_gas_limit(padded);
|
||||
}
|
||||
}
|
||||
Ok(tx)
|
||||
} else {
|
||||
if let Some(builder) = tx.as_mut_builder() {
|
||||
builder.set_gas_limit(self.default_gas_limit);
|
||||
builder.set_max_fee_per_gas(self.default_max_fee_per_gas);
|
||||
builder.set_max_priority_fee_per_gas(self.default_priority_fee);
|
||||
}
|
||||
Ok(tx)
|
||||
}
|
||||
self.inner.fill(fillable, tx).await
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FallbackGasFiller {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
struct FallbackGasFillerError(Cow<'static, str>);
|
||||
|
||||
impl FallbackGasFillerError {
|
||||
pub fn new(string: impl Into<Cow<'static, str>>) -> Self {
|
||||
Self(string.into())
|
||||
}
|
||||
|
||||
pub fn boxed(self) -> Box<Self> {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for FallbackGasFillerError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for FallbackGasFillerError {}
|
||||
|
||||
@@ -51,7 +51,7 @@ impl ReportAggregator {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_task(mut self) -> (Reporter, impl Future<Output = Result<()>>) {
|
||||
pub fn into_task(mut self) -> (Reporter, impl Future<Output = Result<Report>>) {
|
||||
let reporter = self
|
||||
.runner_tx
|
||||
.take()
|
||||
@@ -60,7 +60,7 @@ impl ReportAggregator {
|
||||
(reporter, async move { self.aggregate().await })
|
||||
}
|
||||
|
||||
async fn aggregate(mut self) -> Result<()> {
|
||||
async fn aggregate(mut self) -> Result<Report> {
|
||||
debug!("Starting to aggregate report");
|
||||
|
||||
while let Some(event) = self.runner_rx.recv().await {
|
||||
@@ -152,7 +152,7 @@ impl ReportAggregator {
|
||||
format!("Failed to serialize report JSON to {}", file_path.display())
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
Ok(self.report)
|
||||
}
|
||||
|
||||
fn handle_subscribe_to_events_event(&self, event: SubscribeToEventsEvent) {
|
||||
|
||||
+1
-1
Submodule resolc-compiler-tests updated: 7bc445491e...55da34c4f6
@@ -28,7 +28,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import sys
|
||||
import csv
|
||||
from typing import List, Mapping, TypedDict
|
||||
from typing import List, Mapping, TypedDict, no_type_check
|
||||
|
||||
|
||||
class EthereumMinedBlockInformation(TypedDict):
|
||||
@@ -69,7 +69,43 @@ class MinedBlockInformation(TypedDict):
|
||||
"""Block-level information for a mined block with both EVM and optional Substrate fields."""
|
||||
|
||||
ethereum_block_information: EthereumMinedBlockInformation
|
||||
substrate_block_information: SubstrateMinedBlockInformation
|
||||
substrate_block_information: SubstrateMinedBlockInformation | None
|
||||
|
||||
|
||||
def substrate_block_information_ref_time(
|
||||
block: SubstrateMinedBlockInformation | None,
|
||||
) -> int | None:
|
||||
if block is None:
|
||||
return None
|
||||
else:
|
||||
return block["ref_time"]
|
||||
|
||||
|
||||
def substrate_block_information_max_ref_time(
|
||||
block: SubstrateMinedBlockInformation | None,
|
||||
) -> int | None:
|
||||
if block is None:
|
||||
return None
|
||||
else:
|
||||
return block["max_ref_time"]
|
||||
|
||||
|
||||
def substrate_block_information_proof_size(
|
||||
block: SubstrateMinedBlockInformation | None,
|
||||
) -> int | None:
|
||||
if block is None:
|
||||
return None
|
||||
else:
|
||||
return block["proof_size"]
|
||||
|
||||
|
||||
def substrate_block_information_max_proof_size(
|
||||
block: SubstrateMinedBlockInformation | None,
|
||||
) -> int | None:
|
||||
if block is None:
|
||||
return None
|
||||
else:
|
||||
return block["max_proof_size"]
|
||||
|
||||
|
||||
class Metric(TypedDict):
|
||||
@@ -100,8 +136,19 @@ class Metrics(TypedDict):
|
||||
transaction_per_second: Metric
|
||||
gas_per_second: Metric
|
||||
gas_block_fullness: Metric
|
||||
ref_time_block_fullness: Metric
|
||||
proof_size_block_fullness: Metric
|
||||
ref_time_block_fullness: Metric | None
|
||||
proof_size_block_fullness: Metric | None
|
||||
|
||||
|
||||
@no_type_check
|
||||
def metrics_raw_item(
|
||||
metrics: Metrics, name: str, target: str, index: int
|
||||
) -> int | None:
|
||||
l: list[int] = metrics.get(name, dict()).get("raw", dict()).get(target, dict())
|
||||
try:
|
||||
return l[index]
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
class ExecutionReport(TypedDict):
|
||||
@@ -144,12 +191,15 @@ BlockInformation = TypedDict(
|
||||
"Transaction Count": int,
|
||||
"TPS": int | None,
|
||||
"GPS": int | None,
|
||||
"Ref Time": int,
|
||||
"Max Ref Time": int,
|
||||
"Block Fullness Ref Time": int,
|
||||
"Proof Size": int,
|
||||
"Max Proof Size": int,
|
||||
"Block Fullness Proof Size": int,
|
||||
"Gas Mined": int,
|
||||
"Block Gas Limit": int,
|
||||
"Block Fullness Gas": float,
|
||||
"Ref Time": int | None,
|
||||
"Max Ref Time": int | None,
|
||||
"Block Fullness Ref Time": int | None,
|
||||
"Proof Size": int | None,
|
||||
"Max Proof Size": int | None,
|
||||
"Block Fullness Proof Size": int | None,
|
||||
},
|
||||
)
|
||||
"""A typed dictionary used to hold all of the block information"""
|
||||
@@ -175,7 +225,7 @@ def main() -> None:
|
||||
report: ReportRoot = load_report(report_path)
|
||||
|
||||
# TODO: Remove this in the future, but for now, the target is fixed.
|
||||
target: str = "revive-dev-node-revm-solc"
|
||||
target: str = sys.argv[2]
|
||||
|
||||
csv_writer = csv.writer(sys.stdout)
|
||||
|
||||
@@ -188,6 +238,12 @@ def main() -> None:
|
||||
|
||||
resolved_blocks: list[BlockInformation] = []
|
||||
for i, block_information in enumerate(blocks_information):
|
||||
mined_gas: int = block_information["ethereum_block_information"][
|
||||
"mined_gas"
|
||||
]
|
||||
block_gas_limit: int = block_information[
|
||||
"ethereum_block_information"
|
||||
]["block_gas_limit"]
|
||||
resolved_blocks.append(
|
||||
{
|
||||
"Block Number": block_information[
|
||||
@@ -216,24 +272,37 @@ def main() -> None:
|
||||
"raw"
|
||||
][target][i - 1]
|
||||
),
|
||||
"Ref Time": block_information[
|
||||
"substrate_block_information"
|
||||
]["ref_time"],
|
||||
"Max Ref Time": block_information[
|
||||
"substrate_block_information"
|
||||
]["max_ref_time"],
|
||||
"Block Fullness Ref Time": execution_report["metrics"][
|
||||
"ref_time_block_fullness"
|
||||
]["raw"][target][i],
|
||||
"Proof Size": block_information[
|
||||
"substrate_block_information"
|
||||
]["proof_size"],
|
||||
"Max Proof Size": block_information[
|
||||
"substrate_block_information"
|
||||
]["max_proof_size"],
|
||||
"Block Fullness Proof Size": execution_report["metrics"][
|
||||
"proof_size_block_fullness"
|
||||
]["raw"][target][i],
|
||||
"Gas Mined": block_information[
|
||||
"ethereum_block_information"
|
||||
]["mined_gas"],
|
||||
"Block Gas Limit": block_information[
|
||||
"ethereum_block_information"
|
||||
]["block_gas_limit"],
|
||||
"Block Fullness Gas": mined_gas / block_gas_limit,
|
||||
"Ref Time": substrate_block_information_ref_time(
|
||||
block_information["substrate_block_information"]
|
||||
),
|
||||
"Max Ref Time": substrate_block_information_max_ref_time(
|
||||
block_information["substrate_block_information"]
|
||||
),
|
||||
"Block Fullness Ref Time": metrics_raw_item(
|
||||
execution_report["metrics"],
|
||||
"ref_time_block_fullness",
|
||||
target,
|
||||
i,
|
||||
),
|
||||
"Proof Size": substrate_block_information_proof_size(
|
||||
block_information["substrate_block_information"]
|
||||
),
|
||||
"Max Proof Size": substrate_block_information_max_proof_size(
|
||||
block_information["substrate_block_information"]
|
||||
),
|
||||
"Block Fullness Proof Size": metrics_raw_item(
|
||||
execution_report["metrics"],
|
||||
"proof_size_block_fullness",
|
||||
target,
|
||||
i,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -5,51 +5,54 @@ CI. The full models used in the JSON report can be found in the revive different
|
||||
the models used in this script are just a partial reproduction of the full report models.
|
||||
"""
|
||||
|
||||
from typing import TypedDict, Literal, Union
|
||||
|
||||
import json, io
|
||||
import json, typing, io, sys
|
||||
|
||||
|
||||
class Report(TypedDict):
|
||||
class Report(typing.TypedDict):
|
||||
context: "Context"
|
||||
execution_information: dict[
|
||||
"MetadataFilePathString",
|
||||
dict["ModeString", dict["CaseIdxString", "CaseReport"]],
|
||||
]
|
||||
execution_information: dict["MetadataFilePathString", "MetadataFileReport"]
|
||||
|
||||
|
||||
class Context(TypedDict):
|
||||
class MetadataFileReport(typing.TypedDict):
|
||||
case_reports: dict["CaseIdxString", "CaseReport"]
|
||||
|
||||
|
||||
class CaseReport(typing.TypedDict):
|
||||
mode_execution_reports: dict["ModeString", "ExecutionReport"]
|
||||
|
||||
|
||||
class ExecutionReport(typing.TypedDict):
|
||||
status: "TestCaseStatus"
|
||||
|
||||
|
||||
class Context(typing.TypedDict):
|
||||
Test: "TestContext"
|
||||
|
||||
|
||||
class TestContext(TypedDict):
|
||||
class TestContext(typing.TypedDict):
|
||||
corpus_configuration: "CorpusConfiguration"
|
||||
|
||||
|
||||
class CorpusConfiguration(TypedDict):
|
||||
class CorpusConfiguration(typing.TypedDict):
|
||||
test_specifiers: list["TestSpecifier"]
|
||||
|
||||
|
||||
class CaseReport(TypedDict):
|
||||
status: "CaseStatus"
|
||||
|
||||
|
||||
class CaseStatusSuccess(TypedDict):
|
||||
status: Literal["Succeeded"]
|
||||
class CaseStatusSuccess(typing.TypedDict):
|
||||
status: typing.Literal["Succeeded"]
|
||||
steps_executed: int
|
||||
|
||||
|
||||
class CaseStatusFailure(TypedDict):
|
||||
status: Literal["Failed"]
|
||||
class CaseStatusFailure(typing.TypedDict):
|
||||
status: typing.Literal["Failed"]
|
||||
reason: str
|
||||
|
||||
|
||||
class CaseStatusIgnored(TypedDict):
|
||||
status: Literal["Ignored"]
|
||||
class CaseStatusIgnored(typing.TypedDict):
|
||||
status: typing.Literal["Ignored"]
|
||||
reason: str
|
||||
|
||||
|
||||
CaseStatus = Union[CaseStatusSuccess, CaseStatusFailure, CaseStatusIgnored]
|
||||
TestCaseStatus = typing.Union[CaseStatusSuccess, CaseStatusFailure, CaseStatusIgnored]
|
||||
"""A union type of all of the possible statuses that could be reported for a case."""
|
||||
|
||||
TestSpecifier = str
|
||||
@@ -64,6 +67,12 @@ MetadataFilePathString = str
|
||||
CaseIdxString = str
|
||||
"""The index of a case as a string. For example '0'"""
|
||||
|
||||
PlatformString = typing.Union[
|
||||
typing.Literal["revive-dev-node-revm-solc"],
|
||||
typing.Literal["revive-dev-node-polkavm-resolc"],
|
||||
]
|
||||
"""A string of the platform on which the test was run"""
|
||||
|
||||
|
||||
def path_relative_to_resolc_compiler_test_directory(path: str) -> str:
|
||||
"""
|
||||
@@ -78,12 +87,22 @@ def path_relative_to_resolc_compiler_test_directory(path: str) -> str:
|
||||
|
||||
|
||||
def main() -> None:
|
||||
with open("report.json", "r") as file:
|
||||
with open(sys.argv[1], "r") as file:
|
||||
report: Report = json.load(file)
|
||||
|
||||
# Getting the platform string and resolving it into a simpler version of
|
||||
# itself.
|
||||
platform_identifier: PlatformString = typing.cast(PlatformString, sys.argv[2])
|
||||
if platform_identifier == "revive-dev-node-polkavm-resolc":
|
||||
platform: str = "PolkaVM"
|
||||
elif platform_identifier == "revive-dev-node-revm-solc":
|
||||
platform: str = "REVM"
|
||||
else:
|
||||
platform: str = platform_identifier
|
||||
|
||||
# Starting the markdown document and adding information to it as we go.
|
||||
markdown_document: io.TextIOWrapper = open("report.md", "w")
|
||||
print("# Differential Tests Results", file=markdown_document)
|
||||
print(f"# Differential Tests Results ({platform})", file=markdown_document)
|
||||
|
||||
# Getting all of the test specifiers from the report and making them relative to the tests dir.
|
||||
test_specifiers: list[str] = list(
|
||||
@@ -94,7 +113,7 @@ def main() -> None:
|
||||
)
|
||||
print("## Specified Tests", file=markdown_document)
|
||||
for test_specifier in test_specifiers:
|
||||
print(f"* `{test_specifier}`", file=markdown_document)
|
||||
print(f"* ``{test_specifier}``", file=markdown_document)
|
||||
|
||||
# Counting the total number of test cases, successes, failures, and ignored tests
|
||||
total_number_of_cases: int = 0
|
||||
@@ -102,9 +121,13 @@ def main() -> None:
|
||||
total_number_of_failures: int = 0
|
||||
total_number_of_ignores: int = 0
|
||||
for _, mode_to_case_mapping in report["execution_information"].items():
|
||||
for _, case_idx_to_report_mapping in mode_to_case_mapping.items():
|
||||
for _, case_report in case_idx_to_report_mapping.items():
|
||||
status: CaseStatus = case_report["status"]
|
||||
for _, case_idx_to_report_mapping in mode_to_case_mapping[
|
||||
"case_reports"
|
||||
].items():
|
||||
for _, execution_report in case_idx_to_report_mapping[
|
||||
"mode_execution_reports"
|
||||
].items():
|
||||
status: TestCaseStatus = execution_report["status"]
|
||||
|
||||
total_number_of_cases += 1
|
||||
if status["status"] == "Succeeded":
|
||||
@@ -144,9 +167,13 @@ def main() -> None:
|
||||
for metadata_file_path, mode_to_case_mapping in report[
|
||||
"execution_information"
|
||||
].items():
|
||||
for mode_string, case_idx_to_report_mapping in mode_to_case_mapping.items():
|
||||
for case_idx_string, case_report in case_idx_to_report_mapping.items():
|
||||
status: CaseStatus = case_report["status"]
|
||||
for case_idx_string, case_idx_to_report_mapping in mode_to_case_mapping[
|
||||
"case_reports"
|
||||
].items():
|
||||
for mode_string, execution_report in case_idx_to_report_mapping[
|
||||
"mode_execution_reports"
|
||||
].items():
|
||||
status: TestCaseStatus = execution_report["status"]
|
||||
metadata_file_path: str = (
|
||||
path_relative_to_resolc_compiler_test_directory(metadata_file_path)
|
||||
)
|
||||
@@ -183,9 +210,13 @@ def main() -> None:
|
||||
for metadata_file_path, mode_to_case_mapping in report[
|
||||
"execution_information"
|
||||
].items():
|
||||
for mode_string, case_idx_to_report_mapping in mode_to_case_mapping.items():
|
||||
for case_idx_string, case_report in case_idx_to_report_mapping.items():
|
||||
status: CaseStatus = case_report["status"]
|
||||
for case_idx_string, case_idx_to_report_mapping in mode_to_case_mapping[
|
||||
"case_reports"
|
||||
].items():
|
||||
for mode_string, execution_report in case_idx_to_report_mapping[
|
||||
"mode_execution_reports"
|
||||
].items():
|
||||
status: TestCaseStatus = execution_report["status"]
|
||||
metadata_file_path: str = (
|
||||
path_relative_to_resolc_compiler_test_directory(metadata_file_path)
|
||||
)
|
||||
@@ -194,7 +225,9 @@ def main() -> None:
|
||||
if status["status"] != "Failed":
|
||||
continue
|
||||
|
||||
failure_reason: str = status["reason"].replace("\n", " ")
|
||||
failure_reason: str = (
|
||||
status["reason"].replace("\n", " ").replace("|", " ")
|
||||
)
|
||||
|
||||
note: str = ""
|
||||
modes_where_this_case_succeeded: set[ModeString] = (
|
||||
@@ -212,7 +245,7 @@ def main() -> None:
|
||||
f"{metadata_file_path}::{case_idx_string}::{mode_string}"
|
||||
)
|
||||
print(
|
||||
f"| `{test_specifier}` | `{failure_reason}` | {note} |",
|
||||
f"| ``{test_specifier}`` | ``{failure_reason}`` | {note} |",
|
||||
file=markdown_document,
|
||||
)
|
||||
print("\n\n</details>", file=markdown_document)
|
||||
|
||||
Reference in New Issue
Block a user