From b941457dc19410cca674a111875bff772babf9a6 Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Tue, 24 May 2022 19:59:00 +0530 Subject: [PATCH] Add logging for token splits --- src/validation.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 2de0769a5a0..c5b90da075f 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3711,6 +3711,8 @@ void CChainState::ProcessTokenToGovVar(const CBlockIndex* pindex, CCustomCSView& cache.EraseLoanCollateralToken(token); } } + + LogPrintf("Migrated %d loan tokens and %d collateral tokens (height: %d)\n", loanCount, collateralCount, pindex->nHeight); } catch(std::out_of_range&) { LogPrintf("Non-existant map entry referenced in loan/collateral token to Gov var migration\n"); } @@ -3824,6 +3826,9 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at throw std::runtime_error(strprintf("Failed to get related pool: %d", oldPoolId.v)); } + LogPrintf("Old pool pair (a: %d / b: %d), reserve (a: %d, b: %d), liquidity: %d\n", + oldPoolPair->idTokenA.v, oldPoolPair->idTokenB.v, oldPoolPair->reserveA, oldPoolPair->reserveB, oldPoolPair->totalLiquidity); + CPoolPair newPoolPair{*oldPoolPair}; if (oldPoolPair->idTokenA == oldTokenId) { newPoolPair.idTokenA = newTokenId; @@ -3849,6 +3854,8 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at return true; }); + LogPrintf("Migrating %d balances from old pool\n", balancesToMigrate.size()); + // Largest first to make sure we are over MINIMUM_LIQUIDITY on first call to AddLiquidity std::sort(balancesToMigrate.begin(), balancesToMigrate.end(), [](const std::pair&a, const std::pair& b){ return a.second > b.second; @@ -3956,6 +3963,9 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at throw std::runtime_error(strprintf("totalLiquidity should be zero. Remainder: %d", oldPoolPair->totalLiquidity)); } + LogPrintf("New pool pair (a: %d / b: %d), reserve (a: %d, b: %d), liquidity: %d\n", + newPoolPair.idTokenA.v, newPoolPair.idTokenB.v, newPoolPair.reserveA, newPoolPair.reserveB, newPoolPair.totalLiquidity); + res = view.SetPoolPair(newPoolId, pindex->nHeight, newPoolPair); if (!res) { throw std::runtime_error(strprintf("SetPoolPair on new pool pair: %s", res.msg)); @@ -3993,8 +4003,6 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at if (!res) { throw std::runtime_error(res.msg); } - - } } catch (const std::runtime_error& e) { return Res::Err(e.what()); @@ -4163,6 +4171,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin } const DCT_ID newTokenId{resVal.val->v}; + LogPrintf("Token split %d (symbol: %s, old token id: %d, new token id: %d)\n", id, token->symbol, oldTokenId.v, newTokenId.v); std::vector eraseKeys; for (const auto& [key, value] : attributes->GetAttributesMap()) { @@ -4204,7 +4213,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin CAccounts addAccounts; CAccounts subAccounts; - view.ForEachBalance([&, multiplier = multiplier](CScript const & owner, const CTokenAmount& balance) { + view.ForEachBalance([&, multiplier = multiplier](CScript const& owner, const CTokenAmount& balance) { if (oldTokenId.v == balance.nTokenId.v) { const auto newBalance = CalculateNewAmount(multiplier, balance.nValue); addAccounts[owner].Add({newTokenId, newBalance}); @@ -4214,6 +4223,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin return true; }); + LogPrintf("Token split %d (symbol: %s, add: %d, sub: %d, balance: %d)\n", id, token->symbol, newTokenId.v, addAccounts.size(), subAccounts.size(), totalBalance); res = view.AddMintedTokens(newTokenId, totalBalance); if (!res) { LogPrintf("%s: Token split failed. %s\n", __func__, res.msg);