Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ci: add workflow for testing Optimism every night #638

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/test-recent-mainnet-block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ jobs:

- name: Run test
uses: actions-rs/cargo@v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, https://github.com/actions-rs has been archived last year and the actions repos haven't been updated for quite a while. I think it'd be nice to replace them, but maybe best to do it in a separate PR - I could propose it some time this week if you like the idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we use this across all of our GitHub actions, it would be good to do it in a follow-up task.

I created one in our backlog: #642

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a somewhat related note, do we need actions-rs/cargo (cargo specifically) at all? It seem to be just running cargo and we don't seem to need any cross-compilation or other target specs in general (which could be noisy, I guess), so this might be a regular run step, instead.

Copy link
Member

@fvictorio fvictorio Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to what @Xanewok said. I already replaced that action with a plain run step in some workflow some time ago. It's simpler, it's straightforward to understand what it does, and it means one external dependency less.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Off-topic for this PR though)

env:
RUSTFLAGS: ${{ matrix.RUSTFLAGS }}
with:
command: replay-block
args: -u ${{ secrets.ALCHEMY_URL }} -c 1
args: -u ${{ secrets.ALCHEMY_URL }} -c l1

- name: Notify failures
if: failure()
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/test-recent-optimism-block.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Run a recent full Optimism block in the Hardhat Network

on:
schedule:
- cron: "0 */8 * * *"
workflow_dispatch:

defaults:
run:
working-directory: packages/hardhat-core

jobs:
test-recent-optimism-block:
name: Test recent Optimism block
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: feat/multichain

- name: Install Rust (stable)
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true

- uses: Swatinem/rust-cache@v2

- name: Cache EDR RPC cache
uses: actions/cache@v4
with:
path: |
**/edr-cache
key: test-recent-optimism-block-rpc-cache-v1

- name: Run test
uses: actions-rs/cargo@v1
with:
command: replay-block
args: -u ${{ secrets.ALCHEMY_URL }} -c optimism

- name: Notify failures
if: failure()
uses: slackapi/slack-github-action@v1.18.0
with:
payload: |
{
"workflow_name": "${{ github.workflow }}",
"run_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.GH_ACTION_NOTIFICATIONS_SLACK_WEBHOOK_URL }}
1 change: 1 addition & 0 deletions Cargo.lock

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

12 changes: 4 additions & 8 deletions crates/edr_evm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ pub async fn run_full_block<
ChainSpecT: Debug
+ SyncChainSpec<
Block: Default,
Hardfork: Debug + Send + Sync,
RpcBlockConversionError: Send + Sync,
RpcReceiptConversionError: Send + Sync,
Hardfork: Debug,
ExecutionReceipt<FilterLog>: PartialEq,
Transaction: Default
+ TransactionValidation<
Expand All @@ -174,13 +172,13 @@ pub async fn run_full_block<
>(
url: String,
block_number: u64,
chain_id: u64,
) -> anyhow::Result<()> {
let runtime = tokio::runtime::Handle::current();

let rpc_client = EthRpcClient::<ChainSpecT>::new(&url, edr_defaults::CACHE_DIR.into(), None)?;
let rpc_client = Arc::new(rpc_client);
let chain_id = rpc_client.chain_id().await?;

let rpc_client = Arc::new(rpc_client);
let replay_block = {
let block = rpc_client
.get_block_by_number_with_transaction_data(PreEip1898BlockSpec::Number(block_number))
Expand Down Expand Up @@ -376,7 +374,6 @@ pub async fn run_full_block<
/// impl_full_block_tests! {
/// mainnet_byzantium => L1ChainSpec {
/// block_number: 4_370_001,
/// chain_id: 1,
/// url: get_alchemy_url(),
/// },
/// }
Expand All @@ -386,7 +383,6 @@ macro_rules! impl_full_block_tests {
($(
$name:ident => $chain_spec:ident {
block_number: $block_number:expr,
chain_id: $chain_id:expr,
url: $url:expr,
},
)+) => {
Expand All @@ -397,7 +393,7 @@ macro_rules! impl_full_block_tests {
async fn [<full_block_ $name>]() -> anyhow::Result<()> {
let url = $url;

$crate::test_utils::run_full_block::<$chain_spec>(url, $block_number, $chain_id).await
$crate::test_utils::run_full_block::<$chain_spec>(url, $block_number).await
}
}
)+
Expand Down
4 changes: 0 additions & 4 deletions crates/edr_optimism/tests/full_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ use edr_test_utils::env::get_alchemy_url;
impl_full_block_tests! {
mainnet_regolith => OptimismChainSpec {
block_number: 105_235_064,
chain_id: 10,
url: get_alchemy_url().replace("eth-", "opt-"),
},
mainnet_canyon => OptimismChainSpec {
block_number: 115_235_064,
chain_id: 10,
url: get_alchemy_url().replace("eth-", "opt-"),
},
mainnet_ecotone => OptimismChainSpec {
block_number: 121_874_088,
chain_id: 10,
url: get_alchemy_url().replace("eth-", "opt-"),
},
mainnet_fjord => OptimismChainSpec {
block_number: 122_514_212,
chain_id: 10,
url: get_alchemy_url().replace("eth-", "opt-"),
},
}
10 changes: 0 additions & 10 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4092,58 +4092,48 @@ mod tests {
impl_full_block_tests! {
mainnet_byzantium => L1ChainSpec {
block_number: 4_370_001,
chain_id: 1,
url: get_alchemy_url(),
},
mainnet_constantinople => L1ChainSpec {
block_number: 7_280_001,
chain_id: 1,
url: get_alchemy_url(),
},
mainnet_istanbul => L1ChainSpec {
block_number: 9_069_001,
chain_id: 1,
url: get_alchemy_url(),
},
mainnet_muir_glacier => L1ChainSpec {
block_number: 9_300_077,
chain_id: 1,
url: get_alchemy_url(),
},
mainnet_shanghai => L1ChainSpec {
block_number: 17_050_001,
chain_id: 1,
url: get_alchemy_url(),
},
// This block contains a sequence of transaction that first raise
// an empty account's balance and then decrease it
mainnet_19318016 => L1ChainSpec {
block_number: 19_318_016,
chain_id: 1,
url: get_alchemy_url(),
},
// This block has both EIP-2930 and EIP-1559 transactions
sepolia_eip_1559_2930 => L1ChainSpec {
block_number: 5_632_795,
chain_id: 11_155_111,
url: get_alchemy_url().replace("mainnet", "sepolia"),
},
sepolia_shanghai => L1ChainSpec {
block_number: 3_095_000,
chain_id: 11_155_111,
url: get_alchemy_url().replace("mainnet", "sepolia"),
},
// This block has an EIP-4844 transaction
mainnet_cancun => L1ChainSpec {
block_number: 19_529_021,
chain_id: 1,
url: get_alchemy_url(),
},
// This block contains a transaction that uses the KZG point evaluation
// precompile, introduced in Cancun
mainnet_cancun2 => L1ChainSpec {
block_number: 19_562_047,
chain_id: 1,
url: get_alchemy_url(),
},
}
Expand Down
1 change: 1 addition & 0 deletions crates/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edr_defaults = { version = "0.3.5", path = "../edr_defaults" }
edr_eth = { version = "0.3.5", path = "../edr_eth" }
edr_evm = { version = "0.3.5", path = "../edr_evm", features = ["test-utils", "tracing"] }
edr_napi_core = { path = "../edr_napi_core" }
edr_optimism = { path = "../edr_optimism" }
edr_provider = { version = "0.3.5", path = "../edr_provider" }
edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" }
flate2 = "1.0.28"
Expand Down
10 changes: 5 additions & 5 deletions crates/tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod remote_block;
mod scenario;
mod update;

use remote_block::SupportedChainTypes;
use update::Mode;

// Matches `edr_napi`. Important for scenarios.
Expand Down Expand Up @@ -45,15 +46,14 @@ enum Command {
GenExecutionApi,
/// Replays a block from a remote node and compares it to the mined block.
ReplayBlock {
#[clap(long, short, value_enum)]
chain_type: SupportedChainTypes,
/// The URL of the remote node
#[clap(long, short)]
url: String,
/// The block number to replay
#[clap(long, short)]
block_number: Option<u64>,
/// The chain ID
#[clap(long, short)]
chain_id: u64,
},
/// Execute a benchmark scenario and report statistics
Scenario {
Expand All @@ -80,10 +80,10 @@ async fn main() -> anyhow::Result<()> {
} => benchmark::run(working_directory, &test_command, iterations),
Command::GenExecutionApi => execution_api::generate(Mode::Overwrite),
Command::ReplayBlock {
chain_type,
url,
block_number,
chain_id,
} => remote_block::replay(url, block_number, chain_id).await,
} => remote_block::replay(chain_type, url, block_number).await,
Command::Scenario { path, count } => scenario::execute(&path, count).await,
}
}
60 changes: 55 additions & 5 deletions crates/tools/src/remote_block.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
use edr_eth::chain_spec::L1ChainSpec;
use core::fmt::Debug;

use clap::ValueEnum;
use edr_eth::{
chain_spec::L1ChainSpec, log::FilterLog, result::InvalidTransaction,
transaction::TransactionValidation,
};
use edr_evm::test_utils::run_full_block;
use edr_optimism::OptimismChainSpec;
use edr_provider::spec::SyncChainSpec;
use edr_rpc_eth::client::EthRpcClient;

pub async fn replay(url: String, block_number: Option<u64>, chain_id: u64) -> anyhow::Result<()> {
let rpc_client = EthRpcClient::<L1ChainSpec>::new(&url, edr_defaults::CACHE_DIR.into(), None)?;
#[derive(Clone, ValueEnum)]
pub enum SupportedChainTypes {
L1,
Optimism,
}

pub async fn replay(
chain_type: SupportedChainTypes,
url: String,
block_number: Option<u64>,
) -> anyhow::Result<()> {
match chain_type {
SupportedChainTypes::L1 => {
replay_chain_specific_block::<L1ChainSpec>("l1", url, block_number).await
}
SupportedChainTypes::Optimism => {
replay_chain_specific_block::<OptimismChainSpec>(
"optimism",
url.replace("eth-", "opt-"),
block_number,
)
.await
}
}
}

pub async fn replay_chain_specific_block<ChainSpecT>(
chain_type: &str,
url: String,
block_number: Option<u64>,
) -> anyhow::Result<()>
where
ChainSpecT: Debug
+ SyncChainSpec<
Block: Default,
Hardfork: Debug,
ExecutionReceipt<FilterLog>: PartialEq,
Transaction: Default
+ TransactionValidation<
ValidationError: From<InvalidTransaction> + Send + Sync,
>,
>,
{
let rpc_client = EthRpcClient::<ChainSpecT>::new(&url, edr_defaults::CACHE_DIR.into(), None)?;

let block_number = if let Some(block_number) = block_number {
block_number
Expand All @@ -14,6 +64,6 @@ pub async fn replay(url: String, block_number: Option<u64>, chain_id: u64) -> an
.map(|block_number| block_number - 20)?
};

println!("Testing block {block_number}");
run_full_block::<L1ChainSpec>(url, block_number, chain_id).await
println!("Testing block {block_number} for chain type {chain_type}");
run_full_block::<ChainSpecT>(url, block_number).await
}
Loading