From def24b5d8dbbbb8dd208b88a71b820e497dcc775 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Mon, 11 Nov 2024 07:16:39 +0000 Subject: [PATCH 1/7] Add block hash to logdbhashes --- src/dfi/rpc_accounts.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index e5630cec40..528afe0631 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3701,10 +3701,12 @@ UniValue logdbhashes(const JSONRPCRequest &request) { // Get the current block height const auto height = ::ChainActive().Height(); + const auto blockHash = ::ChainActive().Tip()->GetBlockHash().ToString(); // Prepare result UniValue result(UniValue::VOBJ); result.pushKV("height", height); + result.pushKV("blockhash", blockHash); result.pushKV("dvmhash", hashHex); result.pushKV("dvmhash_no_undo", hashHexNoUndo); From 720c49929d7cdd2d0437e38d6bc16d467bb9ad9f Mon Sep 17 00:00:00 2001 From: jouzo <15011228+Jouzo@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:05:38 +0000 Subject: [PATCH 2/7] Only hash evm blocks --- lib/ain-evm/src/storage/block_store.rs | 2 +- src/dfi/rpc_accounts.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ain-evm/src/storage/block_store.rs b/lib/ain-evm/src/storage/block_store.rs index b6cf09679e..5497a9089d 100644 --- a/lib/ain-evm/src/storage/block_store.rs +++ b/lib/ain-evm/src/storage/block_store.rs @@ -56,7 +56,7 @@ impl BlockStore { } pub fn hash_db_state(&self) -> Result { - Ok(self.0.hash_db_state(&COLUMN_NAMES)?) + Ok(self.0.hash_db_state(&[columns::Blocks::NAME])?) } } diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 528afe0631..c7af2b55c6 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3712,7 +3712,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) { const auto evmHashHex = XResultValueLogged(evm_try_get_hash_db_state(result)); if (evmHashHex) { - result.pushKV("evmhash", std::string(*evmHashHex)); + result.pushKV("evm_db_node_hash", std::string(*evmHashHex)); } if (gArgs.GetBoolArg("-oceanarchive", DEFAULT_OCEAN_INDEXER_ENABLED) || From d159556c6657ec78d619febbc975a405f3ab24ec Mon Sep 17 00:00:00 2001 From: jouzo <15011228+Jouzo@users.noreply.github.com> Date: Mon, 11 Nov 2024 09:39:59 +0000 Subject: [PATCH 3/7] Add evm block hash directly --- lib/ain-evm/src/storage/block_store.rs | 2 +- src/dfi/rpc_accounts.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ain-evm/src/storage/block_store.rs b/lib/ain-evm/src/storage/block_store.rs index 5497a9089d..b6cf09679e 100644 --- a/lib/ain-evm/src/storage/block_store.rs +++ b/lib/ain-evm/src/storage/block_store.rs @@ -56,7 +56,7 @@ impl BlockStore { } pub fn hash_db_state(&self) -> Result { - Ok(self.0.hash_db_state(&[columns::Blocks::NAME])?) + Ok(self.0.hash_db_state(&COLUMN_NAMES)?) } } diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index c7af2b55c6..04fbf55632 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3703,6 +3703,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) { const auto height = ::ChainActive().Height(); const auto blockHash = ::ChainActive().Tip()->GetBlockHash().ToString(); + // Prepare result UniValue result(UniValue::VOBJ); result.pushKV("height", height); @@ -3710,9 +3711,16 @@ UniValue logdbhashes(const JSONRPCRequest &request) { result.pushKV("dvmhash", hashHex); result.pushKV("dvmhash_no_undo", hashHexNoUndo); - const auto evmHashHex = XResultValueLogged(evm_try_get_hash_db_state(result)); - if (evmHashHex) { - result.pushKV("evm_db_node_hash", std::string(*evmHashHex)); + auto res = XResultValueLogged(evm_try_get_latest_block_hash(result)); + if (res) { + // Only available after EVM activation + auto evmBlockHash = uint256::FromByteArray(*res).GetHex(); + result.pushKV("evmhash", evmBlockHash); + } + + const auto evmDbNodeHashHex = XResultValueLogged(evm_try_get_hash_db_state(result)); + if (evmDbNodeHashHex) { + result.pushKV("evm_db_node_hash", std::string(*evmDbNodeHashHex)); } if (gArgs.GetBoolArg("-oceanarchive", DEFAULT_OCEAN_INDEXER_ENABLED) || From 492616f3833d0b9b9b36589361ab2de5e8e03289 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Mon, 11 Nov 2024 18:11:21 +0800 Subject: [PATCH 4/7] Add comments --- src/dfi/rpc_accounts.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 04fbf55632..7304b60061 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3708,18 +3708,25 @@ UniValue logdbhashes(const JSONRPCRequest &request) { UniValue result(UniValue::VOBJ); result.pushKV("height", height); result.pushKV("blockhash", blockHash); + // Note that this only guaranteed to be equal with other nodes + // if they didn't hit undo changes at different points. + // Example, consolidaterewards at different points can cause this + // to change on pre static reward addresses. result.pushKV("dvmhash", hashHex); result.pushKV("dvmhash_no_undo", hashHexNoUndo); auto res = XResultValueLogged(evm_try_get_latest_block_hash(result)); if (res) { // Only available after EVM activation + // EVM block hash already is inclusive of it's all it's + // state, so we don't need to do the DVM shenangins. auto evmBlockHash = uint256::FromByteArray(*res).GetHex(); result.pushKV("evmhash", evmBlockHash); } const auto evmDbNodeHashHex = XResultValueLogged(evm_try_get_hash_db_state(result)); if (evmDbNodeHashHex) { + // Note: This can vary from node to node unlike the rest. result.pushKV("evm_db_node_hash", std::string(*evmDbNodeHashHex)); } From 8dc246d0dfca4778470f634e3eae3973d99bec3f Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Mon, 11 Nov 2024 18:14:31 +0800 Subject: [PATCH 5/7] Make consolidatrewards note accurate --- src/dfi/rpc_accounts.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 7304b60061..81c4aa07b9 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3710,8 +3710,8 @@ UniValue logdbhashes(const JSONRPCRequest &request) { result.pushKV("blockhash", blockHash); // Note that this only guaranteed to be equal with other nodes // if they didn't hit undo changes at different points. - // Example, consolidaterewards at different points can cause this - // to change on pre static reward addresses. + // Other instances that can cause this to differ are: + // consolidaterewards at different points, etc result.pushKV("dvmhash", hashHex); result.pushKV("dvmhash_no_undo", hashHexNoUndo); From 433ad3a56e9676d554c9be5a05c212a36f72d21d Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Mon, 11 Nov 2024 18:15:44 +0800 Subject: [PATCH 6/7] More accurate notes --- src/dfi/rpc_accounts.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 81c4aa07b9..7442d04c56 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3710,15 +3710,15 @@ UniValue logdbhashes(const JSONRPCRequest &request) { result.pushKV("blockhash", blockHash); // Note that this only guaranteed to be equal with other nodes // if they didn't hit undo changes at different points. - // Other instances that can cause this to differ are: - // consolidaterewards at different points, etc + // Other known instance that can cause this to differ: + // - consolidaterewards at different points if pre-static addresses are involved. result.pushKV("dvmhash", hashHex); result.pushKV("dvmhash_no_undo", hashHexNoUndo); auto res = XResultValueLogged(evm_try_get_latest_block_hash(result)); if (res) { // Only available after EVM activation - // EVM block hash already is inclusive of it's all it's + // EVM block hash already is inclusive of all it's // state, so we don't need to do the DVM shenangins. auto evmBlockHash = uint256::FromByteArray(*res).GetHex(); result.pushKV("evmhash", evmBlockHash); From ed39179d831f160ac69c088def0242bfaa47070b Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Mon, 11 Nov 2024 18:19:34 +0800 Subject: [PATCH 7/7] Make keys consistent and clearer --- src/dfi/rpc_accounts.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 7442d04c56..e5fea69d01 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -3713,7 +3713,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) { // Other known instance that can cause this to differ: // - consolidaterewards at different points if pre-static addresses are involved. result.pushKV("dvmhash", hashHex); - result.pushKV("dvmhash_no_undo", hashHexNoUndo); + result.pushKV("dvmwithoutundohash", hashHexNoUndo); auto res = XResultValueLogged(evm_try_get_latest_block_hash(result)); if (res) { @@ -3727,7 +3727,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) { const auto evmDbNodeHashHex = XResultValueLogged(evm_try_get_hash_db_state(result)); if (evmDbNodeHashHex) { // Note: This can vary from node to node unlike the rest. - result.pushKV("evm_db_node_hash", std::string(*evmDbNodeHashHex)); + result.pushKV("varhash_evmalldb", std::string(*evmDbNodeHashHex)); } if (gArgs.GetBoolArg("-oceanarchive", DEFAULT_OCEAN_INDEXER_ENABLED) ||