Skip to content

Commit

Permalink
fix(eth-wallet-contract): use hash of the contract WASM in contract c…
Browse files Browse the repository at this point in the history
…ache (near#12093)

This fixes the stalls that some of the 2.1 and 2.2 nodes experienced
while doing state sync.
  • Loading branch information
jancionear authored Sep 16, 2024
1 parent cdb8055 commit 0e7df47
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion runtime/runtime/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,24 @@ pub(crate) struct RuntimeContractExt<'a> {

impl<'a> Contract for RuntimeContractExt<'a> {
fn hash(&self) -> CryptoHash {
// For eth implicit accounts return the wallet contract code hash.
// The account.code_hash() contains hash of the magic bytes, not the contract hash.
if checked_feature!("stable", EthImplicitAccounts, self.current_protocol_version)
&& self.account_id.get_account_type() == AccountType::EthImplicitAccount
{
// There are old eth implicit accounts without magic bytes in the code hash.
// Result can be None and it's a valid option. See https://github.com/near/nearcore/pull/11606
if let Some(wallet_contract) = wallet_contract(self.account.code_hash()) {
return *wallet_contract.hash();
}
}

self.account.code_hash()
}

fn get_code(&self) -> Option<Arc<ContractCode>> {
let account_id = self.account_id;
let code_hash = self.hash();
let code_hash = self.account.code_hash();
let version = self.current_protocol_version;

if checked_feature!("stable", EthImplicitAccounts, version)
Expand Down

0 comments on commit 0e7df47

Please sign in to comment.