From b3d45b5c7ce0eec76ee739fb1b88d0c2d6b92bc7 Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Fri, 13 Sep 2024 00:14:02 +0300 Subject: [PATCH] add logging when balance from delta doesnt match --- packages/subgraph/src/mappingHelpers.ts | 36 +++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/subgraph/src/mappingHelpers.ts b/packages/subgraph/src/mappingHelpers.ts index 2b54d2c663..fa13bcf919 100644 --- a/packages/subgraph/src/mappingHelpers.ts +++ b/packages/subgraph/src/mappingHelpers.ts @@ -997,10 +997,7 @@ function updateATSBalanceAndUpdatedAt( const hasBalanceBeenUpdatedInThisBlock = accountTokenSnapshot.updatedAtBlockNumber === block.number; if (balanceDelta && isAccountWithOnlyVeryPredictableBalanceSources && !hasBalanceBeenUpdatedInThisBlock) { - accountTokenSnapshot.balanceUntilUpdatedAt = - accountTokenSnapshot.balanceUntilUpdatedAt.plus( - balanceDelta as BigInt - ); + accountTokenSnapshot.balanceUntilUpdatedAt = accountTokenSnapshot.balanceUntilUpdatedAt.plus(balanceDelta); } else { // if the account has any subscriptions with units we assume that // the balance data requires a RPC call for balance because we did not @@ -1010,14 +1007,37 @@ function updateATSBalanceAndUpdatedAt( Address.fromString(accountTokenSnapshot.account), block.timestamp ); + + let balanceFromRpc = accountTokenSnapshot.balanceUntilUpdatedAt; + if (!newBalanceResult.reverted) { + balanceFromRpc = newBalanceResult.value.value0; + } + + if (balanceDelta) { + const balanceFromDelta = accountTokenSnapshot.balanceUntilUpdatedAt.plus(balanceDelta); + if (balanceFromRpc !== balanceFromDelta) { + log.debug( + "Balance would have been different when using delta over RPC. Block: {}, Timestamp: {}, Account: {}, Token: {}, Balance from RPC: {}, Balance from delta: {}, Balance delta: {}, Outgoing stream count: {}, Incoming stream count: {}", + [ + block.number.toString(), + block.timestamp.toString(), + accountTokenSnapshot.account.toString(), + accountTokenSnapshot.token.toString(), + balanceFromRpc.toString(), + balanceFromDelta.toString(), + balanceDelta.toString(), + accountTokenSnapshot.activeOutgoingStreamCount.toString(), + accountTokenSnapshot.activeIncomingStreamCount.toString() + ] + ); + } + } + if (!newBalanceResult.reverted) { - accountTokenSnapshot.balanceUntilUpdatedAt = - newBalanceResult.value.value0; + log.warning("Fetching balance from RPC failed.", []); } else { accountTokenSnapshot.balanceLastUpdatedFromRpcBlocknumber = block.number; } - - // TODO: console.log here if update from delta would differ from the RPC } }