Skip to content

Commit

Permalink
Merge branch 'master' into parse-leveldb-kv
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Nov 14, 2024
2 parents e611a4f + 4e3933b commit 20d1669
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 56 deletions.
20 changes: 15 additions & 5 deletions src/dfi/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ void CalcMissingRewardTempFix(CCustomCSView &mnview, const uint32_t targetHeight
}
}

std::pair<std::string, std::string> GetDVMDBHashes(CCustomCSView &view) {
std::tuple<std::string, std::string, std::string> GetDVMDBHashes(CCustomCSView &view) {
auto db = view.GetStorage().GetStorageLevelDB()->GetDB();

// Create a CDBIterator
Expand All @@ -1445,6 +1445,7 @@ std::pair<std::string, std::string> GetDVMDBHashes(CCustomCSView &view) {
// Create SHA256 hashers
CSHA256 hasher;
CSHA256 hasherNoUndo;
CSHA256 hasherAccount;

// Seek to the beginning of the database
pcursor->SeekToFirst();
Expand All @@ -1456,9 +1457,15 @@ std::pair<std::string, std::string> GetDVMDBHashes(CCustomCSView &view) {
auto valueSlice = pcursor->GetValue();

const auto key = std::string(keySlice.data(), keySlice.size());
if (!key.empty() && key[0] != 'u') {
hasherNoUndo.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasherNoUndo.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
if (!key.empty()) {
if (key[0] != 'u') {
hasherNoUndo.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasherNoUndo.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
}
if (key[0] == 'a') {
hasherAccount.Write((const unsigned char *)keySlice.data(), keySlice.size());
hasherAccount.Write((const unsigned char *)valueSlice.data(), valueSlice.size());
}
}

hasher.Write((const unsigned char *)keySlice.data(), keySlice.size());
Expand All @@ -1474,12 +1481,15 @@ std::pair<std::string, std::string> GetDVMDBHashes(CCustomCSView &view) {
// Finalize the hashes
unsigned char hash[CSHA256::OUTPUT_SIZE];
unsigned char hashNoUndo[CSHA256::OUTPUT_SIZE];
unsigned char hashAccount[CSHA256::OUTPUT_SIZE];
hasher.Finalize(hash);
hasherNoUndo.Finalize(hashNoUndo);
hasherAccount.Finalize(hashAccount);

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

return {hashHex, hashHexNoUndo};
return {hashHex, hashHexNoUndo, hashHexAccount};
}
2 changes: 1 addition & 1 deletion src/dfi/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CAmount GetProposalCreationFee(int height, const CCustomCSView &view, const CCre
// Missing call fixed in: https://github.com/DeFiCh/ain/pull/1766
void CalcMissingRewardTempFix(CCustomCSView &mnview, const uint32_t targetHeight, const CWallet &wallet);

std::pair<std::string, std::string> GetDVMDBHashes(CCustomCSView &view);
std::tuple<std::string, std::string, std::string> GetDVMDBHashes(CCustomCSView &view);

enum class UpdateMasternodeType : uint8_t {
None = 0x00,
Expand Down
3 changes: 2 additions & 1 deletion src/dfi/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3697,7 +3697,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) {
pcustomcsview->Flush();
pcustomcsDB->Flush();

auto [hashHex, hashHexNoUndo] = GetDVMDBHashes(*pcustomcsview);
auto [hashHex, hashHexNoUndo, hashHexAccount] = GetDVMDBHashes(*pcustomcsview);

// Get the current block height
const auto height = ::ChainActive().Height();
Expand All @@ -3713,6 +3713,7 @@ UniValue logdbhashes(const JSONRPCRequest &request) {
// - consolidaterewards at different points if pre-static addresses are involved.
result.pushKV("dvmhash", hashHex);
result.pushKV("dvmwithoutundohash", hashHexNoUndo);
result.pushKV("dvmaccounthash", hashHexAccount);

auto res = XResultValueLogged(evm_try_get_latest_block_hash(result));
if (res) {
Expand Down
9 changes: 9 additions & 0 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <validation.h>

#include <consensus/params.h>
#include <logging.h>
#include <boost/asio.hpp>

#define MILLI 0.001
Expand Down Expand Up @@ -1573,6 +1574,14 @@ void ConsolidateRewards(CCustomCSView &view,

LogPrintf("%s: address count: %d concurrency: %d\n", __func__, owners.size(), nWorkers);

if (LogAcceptCategory(BCLog::ACCOUNTCONSOLIDATE)) {
UniValue logAddrJsonArr(UniValue::VARR);
for (auto &owner : owners) {
logAddrJsonArr.push_back(ScriptToString(owner));
}
LogPrintf("%s: addrs: %s\n", __func__, logAddrJsonArr.write(2));
}

for (auto &owner : owners) {
// See https://github.com/DeFiCh/ain/pull/1291
// https://github.com/DeFiCh/ain/pull/1291#issuecomment-1137638060
Expand Down
8 changes: 4 additions & 4 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2251,8 +2251,8 @@ bool AppInitMain(InitInterfaces& interfaces)
}

{
auto [hashHex, hashHexNoUndo] = GetDVMDBHashes(*pcustomcsview);
LogPrintf("Pre-consolidate rewards for DVM hash: %s hash-no-undo: %s\n", hashHex, hashHexNoUndo);
auto [hashHex, hashHexNoUndo, hashHexAccount] = GetDVMDBHashes(*pcustomcsview);
LogPrintf("Pre-consolidate rewards for DVM hash: %s hash-no-undo: %s hash-account: %s\n", hashHex, hashHexNoUndo, hashHexAccount);
}

if (fullRewardConsolidation) {
Expand Down Expand Up @@ -2291,8 +2291,8 @@ bool AppInitMain(InitInterfaces& interfaces)
pcustomcsDB->Flush();

{
auto [hashHex, hashHexNoUndo] = GetDVMDBHashes(*pcustomcsview);
LogPrintf("Post-consolidate rewards for DVM hash: %s hash-no-undo: %s\n", hashHex, hashHexNoUndo);
auto [hashHex, hashHexNoUndo, hashHexAccount] = GetDVMDBHashes(*pcustomcsview);
LogPrintf("Post-consolidate rewards for DVM hash: %s hash-no-undo: %s hash-account: %s\n", hashHex, hashHexNoUndo, hashHexAccount);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::CONNECT, "connect"},
{BCLog::OCEAN, "ocean"},
{BCLog::ICXBUG, "icxbug"},
{BCLog::ACCOUNTCONSOLIDATE, "accountconsolidate"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
};
Expand Down
75 changes: 38 additions & 37 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,44 @@ struct CLogCategoryActive

namespace BCLog {
enum LogFlags : uint64_t {
NONE = 0ull,
NET = (1ull << 0ull),
TOR = (1ull << 1ull),
MEMPOOL = (1ull << 2ull),
HTTP = (1ull << 3ull),
BENCH = (1ull << 4ull),
ZMQ = (1ull << 5ull),
DB = (1ull << 6ull),
RPC = (1ull << 7ull),
ESTIMATEFEE = (1ull << 8ull),
ADDRMAN = (1ull << 9ull),
SELECTCOINS = (1ull << 10ull),
REINDEX = (1ull << 11ull),
CMPCTBLOCK = (1ull << 12ull),
RAND = (1ull << 13ull),
PRUNE = (1ull << 14ull),
PROXY = (1ull << 15ull),
MEMPOOLREJ = (1ull << 16ull),
LIBEVENT = (1ull << 17ull),
COINDB = (1ull << 18ull),
LEVELDB = (1ull << 20ull),
STAKING = (1ull << 21ull),
ANCHORING = (1ull << 22ull),
SPV = (1ull << 23ull),
ORACLE = (1ull << 24ull),
LOAN = (1ull << 25ull),
ACCOUNTCHANGE = (1ull << 26ull),
FUTURESWAP = (1ull << 27ull),
TOKENSPLIT = (1ull << 28ull),
RPCCACHE = (1ull << 29ull),
CUSTOMTXBENCH = (1ull << 30ull),
CONNECT = (1ull << 31ull),
SIGN = (1ull << 32ull),
SWAPRESULT = (1ull << 33ull),
OCEAN = (1ull << 34ull),
ICXBUG = (1ull << 35ull),
ALL = ~(0ull),
NONE = 0ull,
NET = (1ull << 0ull),
TOR = (1ull << 1ull),
MEMPOOL = (1ull << 2ull),
HTTP = (1ull << 3ull),
BENCH = (1ull << 4ull),
ZMQ = (1ull << 5ull),
DB = (1ull << 6ull),
RPC = (1ull << 7ull),
ESTIMATEFEE = (1ull << 8ull),
ADDRMAN = (1ull << 9ull),
SELECTCOINS = (1ull << 10ull),
REINDEX = (1ull << 11ull),
CMPCTBLOCK = (1ull << 12ull),
RAND = (1ull << 13ull),
PRUNE = (1ull << 14ull),
PROXY = (1ull << 15ull),
MEMPOOLREJ = (1ull << 16ull),
LIBEVENT = (1ull << 17ull),
COINDB = (1ull << 18ull),
LEVELDB = (1ull << 20ull),
STAKING = (1ull << 21ull),
ANCHORING = (1ull << 22ull),
SPV = (1ull << 23ull),
ORACLE = (1ull << 24ull),
LOAN = (1ull << 25ull),
ACCOUNTCHANGE = (1ull << 26ull),
FUTURESWAP = (1ull << 27ull),
TOKENSPLIT = (1ull << 28ull),
RPCCACHE = (1ull << 29ull),
CUSTOMTXBENCH = (1ull << 30ull),
CONNECT = (1ull << 31ull),
SIGN = (1ull << 32ull),
SWAPRESULT = (1ull << 33ull),
OCEAN = (1ull << 34ull),
ICXBUG = (1ull << 35ull),
ACCOUNTCONSOLIDATE = (1ull << 36ull),
ALL = ~(0ull),
};

class Logger
Expand Down
16 changes: 8 additions & 8 deletions test/functional/feature_consolidate_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def setup(self):
def pre_fork24_consolidate(self):

# Compare hash before consolidation
hash_0 = self.nodes[0].logdbhashes()["dvmhash_no_undo"]
hash_1 = self.nodes[1].logdbhashes()["dvmhash_no_undo"]
hash_0 = self.nodes[0].logdbhashes()["dvmwithoutundohash"]
hash_1 = self.nodes[1].logdbhashes()["dvmwithoutundohash"]
assert_equal(hash_0, hash_1)

# Generate rewards
Expand Down Expand Up @@ -186,8 +186,8 @@ def pre_fork24_consolidate(self):
self.idGOOGL = list(self.nodes[0].gettoken(self.symbolGOOGL).keys())[0]

# Compare hash before consolidation
hash_0 = self.nodes[0].logdbhashes()["dvmhash_no_undo"]
hash_1 = self.nodes[1].logdbhashes()["dvmhash_no_undo"]
hash_0 = self.nodes[0].logdbhashes()["dvmwithoutundohash"]
hash_1 = self.nodes[1].logdbhashes()["dvmwithoutundohash"]
assert_equal(hash_0, hash_1)

def post_fork24_consolidate(self):
Expand All @@ -200,8 +200,8 @@ def post_fork24_consolidate(self):
self.sync_blocks()

# Compare hash before consolidation
hash_0 = self.nodes[0].logdbhashes()["dvmhash_no_undo"]
hash_1 = self.nodes[1].logdbhashes()["dvmhash_no_undo"]
hash_0 = self.nodes[0].logdbhashes()["dvmwithoutundohash"]
hash_1 = self.nodes[1].logdbhashes()["dvmwithoutundohash"]
assert_equal(hash_0, hash_1)

# Stop node
Expand All @@ -224,8 +224,8 @@ def post_fork24_consolidate(self):
self.sync_blocks()

# Compare hash before consolidation
hash_0 = self.nodes[0].logdbhashes()["dvmhash_no_undo"]
hash_1 = self.nodes[1].logdbhashes()["dvmhash_no_undo"]
hash_0 = self.nodes[0].logdbhashes()["dvmwithoutundohash"]
hash_1 = self.nodes[1].logdbhashes()["dvmwithoutundohash"]
assert_equal(hash_0, hash_1)


Expand Down

0 comments on commit 20d1669

Please sign in to comment.