Compare commits

...

5 Commits

Author SHA1 Message Date
Omar Abdulla 4ad3084fe1 Cache the chainspec 2025-12-03 19:37:01 +03:00
Omar 66feb36b4e Update the number of cached blocks (#215)
* Update the commit hash of the tests

* Update the number of cached blocks in revive-dev-node
2025-11-25 12:06:07 +00:00
Omar cc753a1a2c Update the commit hash of the tests (#214) 2025-11-24 15:15:58 +00:00
Torsten Stüber 31dfd67569 Increase the default gas price (#213) 2025-11-24 13:49:52 +00:00
Omar a6e4932a08 Upload code when initializing the driver (#212) 2025-11-12 09:56:53 +00:00
8 changed files with 99 additions and 48 deletions
Generated
+1
View File
@@ -5657,6 +5657,7 @@ dependencies = [
"semver 1.0.26", "semver 1.0.26",
"serde", "serde",
"serde_json", "serde_json",
"subxt 0.44.0",
"tokio", "tokio",
"tracing", "tracing",
"tracing-appender", "tracing-appender",
Binary file not shown.
+1
View File
@@ -37,6 +37,7 @@ schemars = { workspace = true }
semver = { workspace = true } semver = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
subxt = { workspace = true }
[lints] [lints]
workspace = true workspace = true
@@ -127,6 +127,8 @@ where
.inspect_err(|err| error!(?err, "Pre-linking compilation failed")) .inspect_err(|err| error!(?err, "Pre-linking compilation failed"))
.context("Failed to produce the pre-linking compiled contracts")?; .context("Failed to produce the pre-linking compiled contracts")?;
let deployer_address = self.test_definition.case.deployer_address();
let mut deployed_libraries = None::<HashMap<_, _>>; let mut deployed_libraries = None::<HashMap<_, _>>;
let mut contract_sources = self let mut contract_sources = self
.test_definition .test_definition
@@ -159,23 +161,6 @@ where
let code = alloy::hex::decode(code)?; let code = alloy::hex::decode(code)?;
// Getting the deployer address from the cases themselves. This is to ensure
// that we're doing the deployments from different accounts and therefore we're
// not slowed down by the nonce.
let deployer_address = self
.test_definition
.case
.steps
.iter()
.filter_map(|step| match step {
Step::FunctionCall(input) => input.caller.as_address().copied(),
Step::BalanceAssertion(..) => None,
Step::StorageEmptyAssertion(..) => None,
Step::Repeat(..) => None,
Step::AllocateAccount(..) => None,
})
.next()
.unwrap_or(FunctionCallStep::default_caller_address());
let tx = TransactionBuilder::<Ethereum>::with_deploy_code( let tx = TransactionBuilder::<Ethereum>::with_deploy_code(
TransactionRequest::default().from(deployer_address), TransactionRequest::default().from(deployer_address),
code, code,
+51 -19
View File
@@ -8,7 +8,7 @@ use alloy::{
hex, hex,
json_abi::JsonAbi, json_abi::JsonAbi,
network::{Ethereum, TransactionBuilder}, network::{Ethereum, TransactionBuilder},
primitives::{Address, TxHash, U256}, primitives::{Address, TxHash, U256, address},
rpc::types::{ rpc::types::{
TransactionReceipt, TransactionRequest, TransactionReceipt, TransactionRequest,
trace::geth::{ trace::geth::{
@@ -18,9 +18,9 @@ use alloy::{
}, },
}; };
use anyhow::{Context as _, Result, bail}; use anyhow::{Context as _, Result, bail};
use futures::TryStreamExt; use futures::{TryStreamExt, future::try_join_all};
use indexmap::IndexMap; use indexmap::IndexMap;
use revive_dt_common::types::{PlatformIdentifier, PrivateKeyAllocator}; use revive_dt_common::types::{PlatformIdentifier, PrivateKeyAllocator, VmIdentifier};
use revive_dt_format::{ use revive_dt_format::{
metadata::{ContractInstance, ContractPathAndIdent}, metadata::{ContractInstance, ContractPathAndIdent},
steps::{ steps::{
@@ -30,6 +30,7 @@ use revive_dt_format::{
}, },
traits::ResolutionContext, traits::ResolutionContext,
}; };
use subxt::{ext::codec::Decode, metadata::Metadata, tx::Payload};
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tracing::{error, info, instrument}; use tracing::{error, info, instrument};
@@ -198,6 +199,8 @@ where
}) })
.context("Failed to produce the pre-linking compiled contracts")?; .context("Failed to produce the pre-linking compiled contracts")?;
let deployer_address = test_definition.case.deployer_address();
let mut deployed_libraries = None::<HashMap<_, _>>; let mut deployed_libraries = None::<HashMap<_, _>>;
let mut contract_sources = test_definition let mut contract_sources = test_definition
.metadata .metadata
@@ -232,22 +235,6 @@ where
let code = alloy::hex::decode(code)?; let code = alloy::hex::decode(code)?;
// Getting the deployer address from the cases themselves. This is to ensure
// that we're doing the deployments from different accounts and therefore we're
// not slowed down by the nonce.
let deployer_address = test_definition
.case
.steps
.iter()
.filter_map(|step| match step {
Step::FunctionCall(input) => input.caller.as_address().copied(),
Step::BalanceAssertion(..) => None,
Step::StorageEmptyAssertion(..) => None,
Step::Repeat(..) => None,
Step::AllocateAccount(..) => None,
})
.next()
.unwrap_or(FunctionCallStep::default_caller_address());
let tx = TransactionBuilder::<Ethereum>::with_deploy_code( let tx = TransactionBuilder::<Ethereum>::with_deploy_code(
TransactionRequest::default().from(deployer_address), TransactionRequest::default().from(deployer_address),
code, code,
@@ -295,6 +282,51 @@ where
}) })
.context("Failed to compile the post-link contracts")?; .context("Failed to compile the post-link contracts")?;
// Factory contracts on the PVM refer to the code that they're instantiating by hash rather
// than including the actual bytecode. This creates a problem where a factory contract could
// be deployed but the code it's supposed to create is not on chain. Therefore, we upload
// all the code to the chain prior to running any transactions on the driver.
if platform_information.platform.vm_identifier() == VmIdentifier::PolkaVM {
#[subxt::subxt(runtime_metadata_path = "../../assets/revive_metadata.scale")]
pub mod revive {}
let metadata_bytes = include_bytes!("../../../../assets/revive_metadata.scale");
let metadata = Metadata::decode(&mut &metadata_bytes[..])
.context("Failed to decode the revive metadata")?;
const RUNTIME_PALLET_ADDRESS: Address =
address!("0x6d6f646c70792f70616464720000000000000000");
let code_upload_tasks = compiler_output
.contracts
.values()
.flat_map(|item| item.values())
.map(|(code_string, _)| {
let metadata = metadata.clone();
async move {
let code = alloy::hex::decode(code_string)
.context("Failed to hex-decode the post-link code. This is a bug")?;
let payload = revive::tx().revive().upload_code(code, u128::MAX);
let encoded_payload = payload
.encode_call_data(&metadata)
.context("Failed to encode the upload code payload")?;
let tx_request = TransactionRequest::default()
.from(deployer_address)
.to(RUNTIME_PALLET_ADDRESS)
.input(encoded_payload.into());
platform_information
.node
.execute_transaction(tx_request)
.await
.context("Failed to execute transaction")
}
});
try_join_all(code_upload_tasks)
.await
.context("Code upload failed")?;
}
Ok(ExecutionState::new( Ok(ExecutionState::new(
compiler_output.contracts, compiler_output.contracts,
deployed_libraries.unwrap_or_default(), deployed_libraries.unwrap_or_default(),
+15
View File
@@ -1,3 +1,4 @@
use alloy::primitives::Address;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -107,6 +108,20 @@ impl Case {
None => Mode::all().cloned().collect(), None => Mode::all().cloned().collect(),
} }
} }
pub fn deployer_address(&self) -> Address {
self.steps
.iter()
.filter_map(|step| match step {
Step::FunctionCall(input) => input.caller.as_address().copied(),
Step::BalanceAssertion(..) => None,
Step::StorageEmptyAssertion(..) => None,
Step::Repeat(..) => None,
Step::AllocateAccount(..) => None,
})
.next()
.unwrap_or(FunctionCallStep::default_caller_address())
}
} }
define_wrapper_type!( define_wrapper_type!(
@@ -4,7 +4,7 @@ use std::{
pin::Pin, pin::Pin,
process::{Command, Stdio}, process::{Command, Stdio},
sync::{ sync::{
Arc, Arc, Mutex,
atomic::{AtomicU32, Ordering}, atomic::{AtomicU32, Ordering},
}, },
time::Duration, time::Duration,
@@ -32,7 +32,7 @@ use futures::{FutureExt, Stream, StreamExt};
use revive_common::EVMVersion; use revive_common::EVMVersion;
use revive_dt_common::fs::clear_directory; use revive_dt_common::fs::clear_directory;
use revive_dt_format::traits::ResolverApi; use revive_dt_format::traits::ResolverApi;
use serde_json::json; use serde_json::{Value, json};
use sp_core::crypto::Ss58Codec; use sp_core::crypto::Ss58Codec;
use sp_runtime::AccountId32; use sp_runtime::AccountId32;
@@ -57,6 +57,9 @@ use crate::{
static NODE_COUNT: AtomicU32 = AtomicU32::new(0); static NODE_COUNT: AtomicU32 = AtomicU32::new(0);
/// The number of blocks that should be cached by the revive-dev-node and the eth-rpc.
const NUMBER_OF_CACHED_BLOCKS: u32 = 100_000;
/// A node implementation for Substrate based chains. Currently, this supports either substrate /// A node implementation for Substrate based chains. Currently, this supports either substrate
/// or the revive-dev-node which is done by changing the path and some of the other arguments passed /// or the revive-dev-node which is done by changing the path and some of the other arguments passed
/// to the command. /// to the command.
@@ -138,6 +141,8 @@ impl SubstrateNode {
} }
fn init(&mut self, _: Genesis) -> anyhow::Result<&mut Self> { fn init(&mut self, _: Genesis) -> anyhow::Result<&mut Self> {
static CHAINSPEC_MUTEX: Mutex<Option<Value>> = Mutex::new(None);
if !self.rpc_url.is_empty() { if !self.rpc_url.is_empty() {
return Ok(self); return Ok(self);
} }
@@ -156,12 +161,22 @@ impl SubstrateNode {
let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE); let template_chainspec_path = self.base_directory.join(Self::CHAIN_SPEC_JSON_FILE);
trace!("Creating the node genesis"); trace!("Creating the node genesis");
let chainspec_json = Self::node_genesis( let chainspec_json = {
&self.node_binary, let mut chainspec_mutex = CHAINSPEC_MUTEX.lock().expect("Poisoned");
&self.export_chainspec_command, match chainspec_mutex.as_ref() {
&self.wallet, Some(chainspec_json) => chainspec_json.clone(),
) None => {
.context("Failed to prepare the chainspec command")?; let chainspec_json = Self::node_genesis(
&self.node_binary,
&self.export_chainspec_command,
&self.wallet,
)
.context("Failed to prepare the chainspec command")?;
*chainspec_mutex = Some(chainspec_json.clone());
chainspec_json
}
}
};
trace!("Writing the node genesis"); trace!("Writing the node genesis");
serde_json::to_writer_pretty( serde_json::to_writer_pretty(
@@ -212,6 +227,8 @@ impl SubstrateNode {
.arg(u32::MAX.to_string()) .arg(u32::MAX.to_string())
.arg("--pool-kbytes") .arg("--pool-kbytes")
.arg(u32::MAX.to_string()) .arg(u32::MAX.to_string())
.arg("--state-pruning")
.arg(NUMBER_OF_CACHED_BLOCKS.to_string())
.env("RUST_LOG", Self::SUBSTRATE_LOG_ENV) .env("RUST_LOG", Self::SUBSTRATE_LOG_ENV)
.stdout(stdout_file) .stdout(stdout_file)
.stderr(stderr_file); .stderr(stderr_file);
@@ -252,9 +269,9 @@ impl SubstrateNode {
.arg("--rpc-max-connections") .arg("--rpc-max-connections")
.arg(u32::MAX.to_string()) .arg(u32::MAX.to_string())
.arg("--index-last-n-blocks") .arg("--index-last-n-blocks")
.arg(1_000u32.to_string()) .arg(NUMBER_OF_CACHED_BLOCKS.to_string())
.arg("--cache-size") .arg("--cache-size")
.arg(1_000u32.to_string()) .arg(NUMBER_OF_CACHED_BLOCKS.to_string())
.env("RUST_LOG", Self::PROXY_LOG_ENV) .env("RUST_LOG", Self::PROXY_LOG_ENV)
.stdout(stdout_file) .stdout(stdout_file)
.stderr(stderr_file); .stderr(stderr_file);
@@ -307,7 +324,7 @@ impl SubstrateNode {
.get_or_try_init(|| async move { .get_or_try_init(|| async move {
construct_concurrency_limited_provider::<Ethereum, _>( construct_concurrency_limited_provider::<Ethereum, _>(
self.rpc_url.as_str(), self.rpc_url.as_str(),
FallbackGasFiller::new(u64::MAX, 5_000_000_000, 1_000_000_000), FallbackGasFiller::new(u64::MAX, 50_000_000_000, 1_000_000_000),
ChainIdFiller::new(Some(CHAIN_ID)), ChainIdFiller::new(Some(CHAIN_ID)),
NonceFiller::new(self.nonce_manager.clone()), NonceFiller::new(self.nonce_manager.clone()),
self.wallet.clone(), self.wallet.clone(),