-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RPC: Shift evm debug logging RPCs to regular RPC (#2729)
* Initial dev to port evm logging RPCs * Revert "Revert "EVM: Fix create token (#2686)"" This reverts commit 5455aa5. * Fix create token calls * Remove cpp utf8 encoding * Rename to DF23Height and DF24Height * Shift dumpdb to regular RPC * Add null check * Add debug log account state to rust ffi * Add logaccountstates into regular RPC * Fmt cpp * Fmt * Revert CreateToken to bool arg * Fix create token --------- Co-authored-by: Prasanna Loganathar <[email protected]>
- Loading branch information
1 parent
876a5d1
commit 79eaa98
Showing
10 changed files
with
243 additions
and
95 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use std::fmt::Write; | ||
|
||
use ain_evm::{services::SERVICES, storage::block_store::DumpArg, Result}; | ||
use ain_macros::ffi_fallible; | ||
use anyhow::format_err; | ||
use ethereum::Account; | ||
use rlp::{Decodable, Rlp}; | ||
|
||
use crate::{ffi, prelude::*}; | ||
|
||
#[ffi_fallible] | ||
pub fn debug_dump_db(arg: String, start: String, limit: String) -> Result<String> { | ||
if !ain_cpp_imports::is_eth_debug_rpc_enabled() { | ||
return Err("debug_* RPCs have not been enabled".into()); | ||
} | ||
|
||
let arg = if arg.is_empty() { | ||
DumpArg::All | ||
} else { | ||
DumpArg::try_from(arg)? | ||
}; | ||
|
||
let default_limit = 100usize; | ||
let limit = if limit.is_empty() { | ||
default_limit | ||
} else { | ||
limit.as_str().parse().map_err(|_| "Invalid limit")? | ||
}; | ||
|
||
let start = if start.is_empty() { | ||
None | ||
} else { | ||
Some(start.as_str()) | ||
}; | ||
|
||
SERVICES.evm.storage.dump_db(arg, start, limit) | ||
} | ||
|
||
#[ffi_fallible] | ||
pub fn debug_log_account_states() -> Result<String> { | ||
if !ain_cpp_imports::is_eth_debug_rpc_enabled() { | ||
return Err("debug_* RPCs have not been enabled".into()); | ||
} | ||
|
||
let backend = SERVICES | ||
.evm | ||
.core | ||
.get_latest_block_backend() | ||
.expect("Error restoring backend"); | ||
let ro_handle = backend.ro_handle(); | ||
|
||
let mut out = String::new(); | ||
let response_max_size = usize::try_from(ain_cpp_imports::get_max_response_byte_size()) | ||
.map_err(|_| format_err!("failed to convert response size limit to usize"))?; | ||
|
||
for el in ro_handle.iter() { | ||
if out.len() > response_max_size { | ||
return Err(format_err!("exceed response max size limit").into()); | ||
} | ||
|
||
match el { | ||
Ok((_, v)) => { | ||
if let Ok(account) = Account::decode(&Rlp::new(&v)) { | ||
writeln!(&mut out, "Account {:?}:", account) | ||
.map_err(|_| format_err!("failed to write to stream"))?; | ||
} else { | ||
writeln!(&mut out, "Error decoding account {:?}", v) | ||
.map_err(|_| format_err!("failed to write to stream"))?; | ||
} | ||
} | ||
Err(e) => { | ||
writeln!(&mut out, "Error on iter element {e}") | ||
.map_err(|_| format_err!("failed to write to stream"))?; | ||
} | ||
}; | ||
} | ||
|
||
Ok(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.