fix revm database error handling

This commit is contained in:
Noah Citron 2022-08-24 12:28:43 -04:00
parent 748af6ce95
commit 072142b88f
2 changed files with 14 additions and 19 deletions

View File

@ -61,32 +61,30 @@ impl ProofDB {
error: None, error: None,
} }
} }
pub fn safe_unwrap<T: Default>(&mut self, res: Result<T>) -> T {
match res {
Ok(value) => value,
Err(err) => {
self.error = Some(err.to_string());
T::default()
},
}
}
} }
impl Database for ProofDB { impl Database for ProofDB {
fn basic(&mut self, address: H160) -> AccountInfo { fn basic(&mut self, address: H160) -> AccountInfo {
self.error = None;
if is_precompile(&address) { if is_precompile(&address) {
return AccountInfo::default() return AccountInfo::default()
} }
let account_future = self.execution.get_account(&address, None, &self.payload); let account_future = self.execution.get_account(&address, None, &self.payload);
let account_res = block_on(account_future); let account = self.safe_unwrap(block_on(account_future));
if account_res.is_err() {
self.error = Some(account_res.as_ref().err().unwrap().to_string())
}
let account = account_res.unwrap();
let bytecode_future = self.execution.get_code(&address, &self.payload); let bytecode_future = self.execution.get_code(&address, &self.payload);
let bytecode_res = block_on(bytecode_future); let bytecode = self.safe_unwrap(block_on(bytecode_future));
if bytecode_res.is_err() {
self.error = Some(bytecode_res.as_ref().err().unwrap().to_string())
}
let bytecode = bytecode_res.unwrap();
let bytecode = Bytecode::new_raw(Bytes::from(bytecode)); let bytecode = Bytecode::new_raw(Bytes::from(bytecode));
AccountInfo::new(account.balance, account.nonce.as_u64(), bytecode) AccountInfo::new(account.balance, account.nonce.as_u64(), bytecode)
@ -99,12 +97,8 @@ impl Database for ProofDB {
fn storage(&mut self, address: H160, slot: U256) -> U256 { fn storage(&mut self, address: H160, slot: U256) -> U256 {
let slots = [slot]; let slots = [slot];
let account_future = self.execution.get_account(&address, Some(&slots), &self.payload); let account_future = self.execution.get_account(&address, Some(&slots), &self.payload);
let account_res = block_on(account_future); let account = self.safe_unwrap(block_on(account_future));
if account_res.is_err() {
self.error = Some(account_res.as_ref().err().unwrap().to_string());
}
let account = account_res.unwrap();
*account.slots.get(&slot).unwrap() *account.slots.get(&slot).unwrap()
} }

View File

@ -29,6 +29,7 @@ pub struct StorageProof {
pub proof: Vec<Vec<u8>>, pub proof: Vec<Vec<u8>>,
} }
#[derive(Default)]
pub struct Account { pub struct Account {
pub balance: U256, pub balance: U256,
pub nonce: U256, pub nonce: U256,