Skip to content

Commit

Permalink
Merge branch 'main' into drew/vesting-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone authored Jan 21, 2025
2 parents 6e9f147 + 035f264 commit 2e88163
Show file tree
Hide file tree
Showing 16 changed files with 1,084 additions and 113 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ futures-timer = { workspace = true }
[dev-dependencies]
tangle-subxt = { workspace = true }
sp-tracing = { workspace = true }
alloy = { version = "0.9", features = ["full"] }
alloy = { version = "0.9", features = ["full", "provider-debug-api"] }
anyhow = "1.0"

[features]
Expand Down
22 changes: 20 additions & 2 deletions node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use sp_runtime::{
};
use tangle_primitives::types::{BlockNumber, Signature};
use tangle_runtime::{
AccountId, Balance, MaxVestingSchedules, Perbill, StakerStatus, TreasuryPalletId, UNIT,
WASM_BINARY,
AccountId, Balance, MaxVestingSchedules, Perbill, Precompiles, StakerStatus, TreasuryPalletId,
UNIT, WASM_BINARY,
};

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
Expand Down Expand Up @@ -200,12 +200,30 @@ fn mainnet_genesis(
})
.collect();

// As precompiles are implemented inside the Runtime, they don't have a bytecode, and
// their account code is empty by default. However in Solidity calling a function of a
// contract often automatically adds a check that the contract bytecode is non-empty.
// For that reason a dummy code (0x60006000fd) can be inserted at the precompile address
// to pass that check.
let revert_bytecode = [0x60, 0x00, 0x60, 0x00, 0xFD];
let evm_accounts = {
let mut map = BTreeMap::new();

for (address, account) in genesis_evm_distribution {
map.insert(address, account);
}

Precompiles::used_addresses_h160().for_each(|address| {
map.insert(
address,
fp_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: revert_bytecode.to_vec(),
},
);
});
map
};

Expand Down
28 changes: 14 additions & 14 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use tangle_primitives::{
TESTNET_LOCAL_SS58_PREFIX,
};
use tangle_testnet_runtime::{
AccountId, Balance, MaxVestingSchedules, Perbill, StakerStatus, TreasuryPalletId, UNIT,
WASM_BINARY,
AccountId, Balance, MaxVestingSchedules, Perbill, Precompiles, StakerStatus, TreasuryPalletId,
UNIT, WASM_BINARY,
};

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
Expand Down Expand Up @@ -259,7 +259,7 @@ fn testnet_genesis(
// contract often automatically adds a check that the contract bytecode is non-empty.
// For that reason a dummy code (0x60006000fd) can be inserted at the precompile address
// to pass that check.
let _revert_bytecode = [0x60, 0x00, 0x60, 0x00, 0xFD];
let revert_bytecode = [0x60, 0x00, 0x60, 0x00, 0xFD];

let evm_accounts = {
let mut map = BTreeMap::new();
Expand All @@ -268,17 +268,17 @@ fn testnet_genesis(
map.insert(address, account);
}

// Precompiles::used_addresses().for_each(|address| {
// map.insert(
// address.into(),
// fp_evm::GenesisAccount {
// nonce: Default::default(),
// balance: Default::default(),
// storage: Default::default(),
// code: revert_bytecode.clone(),
// },
// );
// });
Precompiles::used_addresses_h160().for_each(|address| {
map.insert(
address,
fp_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: revert_bytecode.to_vec(),
},
);
});

let fully_loaded_accounts = get_fully_funded_accounts_for([
"8efcaf2c4ebbf88bf07f3bb44a2869c4c675ad7a",
Expand Down
1 change: 1 addition & 0 deletions node/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl std::str::FromStr for EthApi {
}

#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct RpcConfig {
pub ethapi: Vec<EthApi>,
pub ethapi_max_permits: u32,
Expand Down
18 changes: 18 additions & 0 deletions node/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use alloy::{
},
transports::BoxTransport,
};
use parity_scale_codec::Encode;
use sc_cli::{CliConfiguration, SubstrateCli};
use sp_tracing::warn;
use tangle::{chainspec, cli, eth, service};
use tangle_primitives::types::Block;
use tangle_subxt::{subxt, subxt_signer};
Expand Down Expand Up @@ -189,6 +191,10 @@ pub trait AddressConverter {
fn to_account_id(&self) -> subxt::utils::AccountId32;
}

pub trait AccountIdConverter {
fn to_address(&self) -> alloy::primitives::Address;
}

impl AddressConverter for alloy::primitives::Address {
fn to_account_id(&self) -> subxt::utils::AccountId32 {
let mut data = [0u8; 24];
Expand All @@ -200,6 +206,16 @@ impl AddressConverter for alloy::primitives::Address {
}
}

impl AccountIdConverter for subxt::utils::AccountId32 {
fn to_address(&self) -> alloy::primitives::Address {
self.using_encoded(|b| {
let mut addr = [0u8; 20];
addr.copy_from_slice(&b[0..20]);
alloy::primitives::Address::from(addr)
})
}
}

/// Run an end-to-end test with the given future.
#[track_caller]
pub fn run_e2e_test<F>(f: F)
Expand All @@ -216,6 +232,7 @@ where
"--rpc-methods=unsafe",
"--rpc-external",
"--rpc-port=9944",
"--ethapi=trace,debug,txpool",
#[cfg(feature = "manual-seal")]
"--sealing=manual",
"--auto-insert-keys",
Expand Down Expand Up @@ -258,6 +275,7 @@ where
max_past_logs: cli.eth.max_past_logs,
tracing_raw_max_memory_usage: cli.eth.tracing_raw_max_memory_usage,
};
warn!("Starting the node with the following RPC config: {:?}", rpc_config);

runner
.async_run(|config| {
Expand Down
Loading

0 comments on commit 2e88163

Please sign in to comment.