Skip to content

Commit

Permalink
Merge branch 'feat/erc20-gas-token' into chore/aleksuss/charge_gas_optim
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored Jan 24, 2023
2 parents a4c93fb + fed6a15 commit 19f3a12
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 183 deletions.
22 changes: 11 additions & 11 deletions engine-standalone-storage/src/relayer_db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aurora_engine::engine;
use aurora_engine::{engine, state};
use aurora_engine_sdk::env::{self, Env, DEFAULT_PREPAID_GAS};
use aurora_engine_transactions::EthTransactionKind;
use aurora_engine_types::account_id::AccountId;
Expand Down Expand Up @@ -63,7 +63,7 @@ where
pub fn initialize_transactions<I>(
storage: &mut Storage,
mut rows: I,
engine_state: engine::EngineState,
engine_state: state::EngineState,
) -> Result<(), error::Error>
where
I: FallibleIterator<Item = types::TransactionRow, Error = postgres::Error>,
Expand Down Expand Up @@ -159,13 +159,13 @@ where
}

pub mod error {
use aurora_engine::engine;
use aurora_engine::{engine, state};

#[derive(Debug)]
pub enum Error {
Storage(crate::Error),
Postgres(postgres::Error),
EngineState(engine::EngineStateError),
EngineState(state::error::EngineStateError),
Engine(engine::EngineError),
}

Expand All @@ -181,8 +181,8 @@ pub mod error {
}
}

impl From<engine::EngineStateError> for Error {
fn from(e: engine::EngineStateError) -> Self {
impl From<state::error::EngineStateError> for Error {
fn from(e: state::error::EngineStateError) -> Self {
Self::EngineState(e)
}
}
Expand All @@ -198,7 +198,7 @@ pub mod error {
mod test {
use super::FallibleIterator;
use crate::sync::types::{TransactionKind, TransactionMessage};
use aurora_engine::{connector, engine, parameters};
use aurora_engine::{connector, parameters, state};
use aurora_engine_types::H256;

/// Requires a running postgres server to work. A snapshot of the DB can be
Expand All @@ -210,11 +210,11 @@ mod test {
fn test_fill_db() {
let mut storage = crate::Storage::open("rocks_tmp/").unwrap();
let mut connection = super::connect_without_tls(&Default::default()).unwrap();
let engine_state = engine::EngineState {
let engine_state = state::EngineState {
chain_id: aurora_engine_types::types::u256_to_arr(&1313161555.into()),
owner_id: "aurora".parse().unwrap(),
bridge_prover_id: "prover.bridge.near".parse().unwrap(),
upgrade_delay_blocks: 0,
default_gas_token: Default::default(),
};

// Initialize engine and connector states in storage.
Expand All @@ -231,12 +231,12 @@ mod test {
.unwrap();
let result = storage.with_engine_access(block_height, 0, &[], |io| {
let mut local_io = io;
engine::set_state(&mut local_io, engine_state.clone());
state::set_state(&mut local_io, engine_state.clone()).unwrap();
connector::EthConnectorContract::create_contract(
io,
engine_state.owner_id.clone(),
parameters::InitCallArgs {
prover_account: engine_state.bridge_prover_id.clone(),
prover_account: "prover.bridge.near".parse().unwrap(),
eth_custodian_address: "6bfad42cfc4efc96f529d786d643ff4a8b89fa52"
.to_string(),
metadata: Default::default(),
Expand Down
22 changes: 11 additions & 11 deletions engine-standalone-storage/src/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use aurora_engine::pausables::{
EnginePrecompilesPauser, PausedPrecompilesManager, PrecompileFlags,
};
use aurora_engine::{connector, engine, parameters::SubmitResult, xcc};
use aurora_engine::{connector, engine, parameters::SubmitResult, state, xcc};
use aurora_engine_sdk::env::{self, Env, DEFAULT_PREPAID_GAS};
use aurora_engine_types::{
account_id::AccountId,
Expand Down Expand Up @@ -137,7 +137,7 @@ fn execute_transaction<'db>(
let transaction_bytes: Vec<u8> = tx.into();
let tx_hash = aurora_engine_sdk::keccak(&transaction_bytes);

let result = engine::get_state(&io)
let result = state::get_state(&io)
.map(|engine_state| {
let submit_result = engine::submit(
io,
Expand Down Expand Up @@ -335,12 +335,12 @@ fn non_submit_execute<'db>(
}

TransactionKind::RefundOnError(maybe_args) => {
let result: Result<Option<TransactionExecutionResult>, engine::EngineStateError> =
let result: Result<Option<TransactionExecutionResult>, state::error::EngineStateError> =
maybe_args
.clone()
.map(|args| {
let mut handler = crate::promise::NoScheduler { promise_data };
let engine_state = engine::get_state(&io)?;
let engine_state = state::get_state(&io)?;
let result =
engine::refund_on_error(io, &env, engine_state, args, &mut handler);
Ok(TransactionExecutionResult::Submit(result))
Expand All @@ -367,7 +367,7 @@ fn non_submit_execute<'db>(
None
}
TransactionKind::NewEngine(args) => {
engine::set_state(&mut io, args.clone().into());
state::set_state(&mut io, args.clone().into())?;

None
}
Expand Down Expand Up @@ -420,9 +420,9 @@ pub enum ConsumeMessageOutcome {

#[derive(Debug)]
pub struct TransactionIncludedOutcome {
pub hash: aurora_engine_types::H256,
pub hash: H256,
pub info: TransactionMessage,
pub diff: crate::Diff,
pub diff: Diff,
pub maybe_result: Result<Option<TransactionExecutionResult>, error::Error>,
}

Expand All @@ -434,11 +434,11 @@ pub enum TransactionExecutionResult {
}

pub mod error {
use aurora_engine::{connector, engine, fungible_token};
use aurora_engine::{connector, engine, fungible_token, state};

#[derive(Debug)]
pub enum Error {
EngineState(engine::EngineStateError),
EngineState(state::error::EngineStateError),
Engine(engine::EngineError),
DeployErc20(engine::DeployErc20Error),
FtOnTransfer(connector::error::FtTransferCallError),
Expand All @@ -452,8 +452,8 @@ pub mod error {
ConnectorStorage(connector::error::StorageReadError),
}

impl From<engine::EngineStateError> for Error {
fn from(e: engine::EngineStateError) -> Self {
impl From<state::error::EngineStateError> for Error {
fn from(e: state::error::EngineStateError) -> Self {
Self::EngineState(e)
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ pub(crate) fn deploy_evm() -> AuroraRunner {
let args = NewCallArgs {
chain_id: crate::prelude::u256_to_arr(&U256::from(runner.chain_id)),
owner_id: str_to_account_id(runner.aurora_account_id.as_str()),
bridge_prover_id: str_to_account_id("bridge_prover.near"),
upgrade_delay_blocks: 1,
default_gas_token: [0u8; 20],
};

let account_id = runner.aurora_account_id.clone();
Expand Down
8 changes: 4 additions & 4 deletions engine-tests/src/test_utils/standalone/mocks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::test_utils;
use aurora_engine::engine;
use aurora_engine::fungible_token::FungibleTokenMetadata;
use aurora_engine::parameters::{
FinishDepositCallArgs, InitCallArgs, NEP141FtOnTransferArgs, NewCallArgs,
};
use aurora_engine::{engine, state};
use aurora_engine_sdk::env::{Env, DEFAULT_PREPAID_GAS};
use aurora_engine_sdk::io::IO;
use aurora_engine_types::types::{Address, Balance, NEP141Wei, NearGas, Wei};
Expand All @@ -17,7 +17,7 @@ pub const ETH_CUSTODIAN_ADDRESS: Address =
aurora_engine_precompiles::make_address(0xd045f7e1, 0x9b2488924b97f9c145b5e51d0d895a65);

pub fn compute_block_hash(block_height: u64) -> H256 {
aurora_engine::engine::compute_block_hash([0u8; 32], block_height, b"aurora")
engine::compute_block_hash([0u8; 32], block_height, b"aurora")
}

pub fn insert_block(storage: &mut Storage, block_height: u64) {
Expand Down Expand Up @@ -52,11 +52,11 @@ pub fn init_evm<I: IO + Copy, E: Env>(mut io: I, env: &E, chain_id: u64) {
let new_args = NewCallArgs {
chain_id: aurora_engine_types::types::u256_to_arr(&U256::from(chain_id)),
owner_id: env.current_account_id(),
bridge_prover_id: test_utils::str_to_account_id("bridge_prover.near"),
upgrade_delay_blocks: 1,
default_gas_token: [0u8; 20], // Base coin
};

engine::set_state(&mut io, new_args.into());
state::set_state(&mut io, new_args.into()).unwrap();

let connector_args = InitCallArgs {
prover_account: test_utils::str_to_account_id("prover.near"),
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/tests/eth_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use aurora_engine_types::types::{Fee, NEP141Wei};
use borsh::{BorshDeserialize, BorshSerialize};
use byte_slice_cast::AsByteSlice;
use ethabi::ethereum_types::U256;
use near_sdk::test_utils::accounts;
use near_sdk_sim::transaction::ExecutionStatus;
use near_sdk_sim::{to_yocto, ExecutionResult, UserAccount, DEFAULT_GAS, STORAGE_AMOUNT};
use serde_json::json;
Expand Down Expand Up @@ -71,8 +70,8 @@ fn init_contract(
&NewCallArgs {
chain_id: [0u8; 32],
owner_id: str_to_account_id(master_account.account_id.clone().as_str()),
bridge_prover_id: str_to_account_id(accounts(0).as_str()),
upgrade_delay_blocks: 1,
default_gas_token: [0u8; 20],
}
.try_to_vec()
.unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ fn test_state_format() {
let args = aurora_engine::parameters::NewCallArgs {
chain_id: aurora_engine_types::types::u256_to_arr(&666.into()),
owner_id: "boss".parse().unwrap(),
bridge_prover_id: "prover_mcprovy_face".parse().unwrap(),
upgrade_delay_blocks: 3,
default_gas_token: [0u8; 20],
};
let state: aurora_engine::engine::EngineState = args.into();
let state: aurora_engine::state::EngineState = args.into();
let expected_hex: String = [
"000000000000000000000000000000000000000000000000000000000000029a",
"04000000626f7373",
Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/tests/standalone/sanity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aurora_engine::engine;
use aurora_engine::{engine, state};
use aurora_engine_sdk::env::DEFAULT_PREPAID_GAS;
use aurora_engine_test_doubles::io::{Storage, StoragePointer};
use aurora_engine_test_doubles::promise::PromiseTracker;
Expand All @@ -15,11 +15,11 @@ fn test_deploy_code() {
buf
};
let owner_id: AccountId = "aurora".parse().unwrap();
let state = engine::EngineState {
let state = state::EngineState {
chain_id,
owner_id: owner_id.clone(),
bridge_prover_id: "mr_the_prover".parse().unwrap(),
upgrade_delay_blocks: 0,
default_gas_token: Default::default(),
};
let origin = Address::new(H160([0u8; 20]));
let storage = RwLock::new(Storage::default());
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/state_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub fn deploy_evm() -> AuroraAccount {
let new_args = NewCallArgs {
chain_id: crate::prelude::u256_to_arr(&U256::from(aurora_runner.chain_id)),
owner_id: str_to_account_id(main_account.account_id.as_str()),
bridge_prover_id: prover_account.clone(),
upgrade_delay_blocks: 1,
default_gas_token: [0u8; 20],
};
main_account
.call(
Expand Down
Loading

0 comments on commit 19f3a12

Please sign in to comment.