Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log DVM hash without undos #3109

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/dfi/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,8 +3700,9 @@ UniValue logdbhashes(const JSONRPCRequest &request) {
// Create a CDBIterator
auto pcursor = db->NewIterator(leveldb::ReadOptions());

// Create a SHA256 hasher
// Create SHA256 hashers
CSHA256 hasher;
CSHA256 hasherNoUndo;

// Seek to the beginning of the database
pcursor->SeekToFirst();
Expand All @@ -3712,9 +3713,16 @@ UniValue logdbhashes(const JSONRPCRequest &request) {
auto keySlice = pcursor->GetKey();
auto valueSlice = pcursor->GetValue();

// Feed the key and value into the hasher
hasher.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasher.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
const auto key = std::string(keySlice.data(), keySlice.size());
if (!key.empty() && key[0] == 'u') {
Bushstar marked this conversation as resolved.
Show resolved Hide resolved
hasher.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasher.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
} else {
hasher.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasher.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
hasherNoUndo.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasherNoUndo.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
}

// Move to the next key-value pair
pcursor->Next();
Expand All @@ -3723,12 +3731,15 @@ UniValue logdbhashes(const JSONRPCRequest &request) {
// Delete iterator
delete pcursor;

// Finalize the hash
// Finalize the hashes
unsigned char hash[CSHA256::OUTPUT_SIZE];
unsigned char hashNoUndo[CSHA256::OUTPUT_SIZE];
hasher.Finalize(hash);
hasher.Finalize(hashNoUndo);

// Convert hash to hex string
// Convert hashes to hex string
const auto hashHex = HexStr(hash, hash + CSHA256::OUTPUT_SIZE);
const auto hashHexNoUndo = HexStr(hashNoUndo, hashNoUndo + CSHA256::OUTPUT_SIZE);

// Get the current block height
const auto height = ::ChainActive().Height();
Expand All @@ -3737,6 +3748,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) {
UniValue result(UniValue::VOBJ);
result.pushKV("height", height);
result.pushKV("dvmhash", hashHex);
result.pushKV("dvmhash_no_undo", hashHexNoUndo);

const auto evmHashHex = XResultValueLogged(evm_try_get_hash_db_state(result));
if (evmHashHex) {
Expand Down
Loading