Skip to content

Commit

Permalink
fix(evm): Fix creating of empty block on reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
vldm committed Oct 12, 2021
1 parent eb8d768 commit 71481d9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
11 changes: 9 additions & 2 deletions evm-utils/evm-state/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,15 @@ impl Executor {
}

/// After "swap from evm" transaction EVM_MINT_ADDRESS will cleanup. Using this method.
pub fn reset_balance(&mut self, balance: H160) {
self.with_executor(|_, _, _, _| None, |e| e.state_mut().reset_balance(balance));
pub fn reset_balance(&mut self, swap_addr: H160, ignore_reset_on_cleared: bool) {
self.with_executor(
|_, _, _, _| None,
|e| {
if !ignore_reset_on_cleared || e.state().basic(swap_addr).balance != U256::zero() {
e.state_mut().reset_balance(swap_addr)
}
},
);
}

// /// Burn some tokens on address:
Expand Down
2 changes: 1 addition & 1 deletion evm-utils/programs/evm_loader/src/precompiles/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
//
// NativeContracts declaration below
//

// 0x56454c41532d434841494e000000000053574150 for better search
// TODO: Implement some procedural macro to render this in more
pub static ETH_TO_VLX_ADDR: Lazy<H160> = Lazy::new(|| {
H160::from_str(concat!(
Expand Down
5 changes: 4 additions & 1 deletion evm-utils/programs/evm_loader/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl EvmProcessor {
.is_feature_active(&solana_sdk::feature_set::velas::evm_new_error_handling::id());
let unsigned_tx_fix = invoke_context
.is_feature_active(&solana_sdk::feature_set::velas::unsigned_tx_fix::id());
let ignore_reset_on_cleared = invoke_context
.is_feature_active(&solana_sdk::feature_set::velas::ignore_reset_on_cleared::id());

if cross_execution && !cross_execution_enabled {
ic_msg!(invoke_context, "Cross-Program evm execution not enabled.");
return Err(EvmError::CrossExecutionNotEnabled.into());
Expand Down Expand Up @@ -114,7 +117,7 @@ impl EvmProcessor {
};

if register_swap_tx_in_evm {
executor.reset_balance(*precompiles::ETH_TO_VLX_ADDR)
executor.reset_balance(*precompiles::ETH_TO_VLX_ADDR, ignore_reset_on_cleared)
}

// When old error handling, manually convert EvmError to InstructionError
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ pub mod velas {
pub mod unsigned_tx_fix {
solana_sdk::declare_id!("HfCMpyxjAmu7sPtRdnqdrTf3zDpkErKugzYPnKs4vhat");
}

pub mod ignore_reset_on_cleared {
solana_sdk::declare_id!("HC6ZH7Dx92Q5dwVLYAaK3SPNCDc1L7Wq41Zuc7FU1mR1");
}
}
lazy_static! {
/// Map of feature identifiers to user-visible description
Expand Down Expand Up @@ -218,6 +222,7 @@ lazy_static! {
(velas::native_swap_in_evm_history::id(), "Native swap in evm history."),
(velas::evm_new_error_handling::id(), "EVM new error handling."),
(velas::unsigned_tx_fix::id(), "Authorized transaction hash fixed."),
(velas::ignore_reset_on_cleared::id(), "Don't reset evm_swap address balance, when it already swapped, to avoid empty blocks."),
/*************** ADD NEW FEATURES HERE ***************/
]
).collect();
Expand Down

0 comments on commit 71481d9

Please sign in to comment.