You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inconsistency between AccountBalance and AccountHistory
Summary
The AuctionBid entries that according to the AccountHistory (provided by FullNode) were sent to df1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z in block 1438560 were not included in the balance.
If all accountHistory entries for a certain DToken (see steps to reproduce) are summed up, you should get the present tokenBalance as result.
However, the example provided below, clearly shows, that the data provided by the FullNode have a inconsistency here.
The issue I found was with address df1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z for example for the token SPY.
Change the RPC-Endpoint within the fol where it says ADD-YOUR-RPC-ENDPOINT-HERE to one you have access to.
Run the example:
const{ JsonRpcClient }=require('@defichain/jellyfish-api-jsonrpc');const{ BigNumber }=require('bignumber.js');// This function will sum up every single accountHistory entry for a certain symbol and address// from present blockHeight to genesis Block. asyncfunctioncompareBalanceAndHistorySum(address,symbol){constfullNode=newJsonRpcClient('ADD-YOUR-RPC-ENDPOINT-HERE',{timeout: 60000,});constlimit=20000;letamountSum=BigNumber('0');letroundCounter=0;letsymbolBalance=BigNumber(0);// Determine present balance for the token with corresponding symbolconstbalances=awaitfullNode.account.getAccount(address);constblockHeight=awaitfullNode.blockchain.getBlockCount();balances.forEach((amount)=>{const[tokenAmount,tokenSymbol]=amount.split('@');if(tokenSymbol===symbol){symbolBalance=BigNumber(tokenAmount);}});console.log(`Present Balance of ${symbol}: ${symbolBalance.toString()} at blockHeight: ${blockHeight}`);console.log(`Starting accountHistory fetching. This may take a while...`);while(true){// Fetch entire accountHistory for the symbolconstaccountHistory=awaitfullNode.account.listAccountHistory(address,{maxBlockHeight: blockHeight,
limit,start: limit*roundCounter,including_start: true,token: symbol,},);roundCounter++;console.log(`${roundCounter}. round of accountHistory fetching done.`);for(constaccountHistoryElementofaccountHistory){// Split Amount@SymbolconstconvertedAmounts=accountHistoryElement.amounts.map((amount)=>{const[tokenAmount,tokenSymbol]=amount.split('@');return{amount: BigNumber(tokenAmount),symbol: tokenSymbol};},);// Sum up the amounts.convertedAmounts.forEach((element)=>{if(element.symbol===symbol){amountSum=amountSum.plus(element.amount);}});}// As soon as the length of accountHistory isn't equal to the limit we have reached the end.if(accountHistory.length!=limit)break;}console.log(`Adding up every single accountHistoryEntry results to ${amountSum}${symbol}`);console.log(`Comparing this to the actual present balance of ${symbolBalance}${symbol} results to a difference of ${symbolBalance-amountSum}${symbol}`);}// Call the function with the appropriate valuescompareBalanceAndHistorySum('df1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z','SPY');
Results (detailed):
The example (df1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z, SPY) shows that based on the accountHistory the account should have a balance of 0.00000621 SPY. And yet the FullNode reports a present balance of 0 Spy.
This example can also be done with different setups:
The values within this entry represent exactly the amount by which the accountHistory and the accountBalance differ. It seems, that this entry isn't valid and should not be part of the account History.
Environment
[Please fill all of the following or NA if not applicable]
Node Version: v16.13.1
Block height on bug if applicable: 1438560
TX or TX type on bug if applicable: AuctionBid
OS with version: NA
Any other relevant environment info: NA
The text was updated successfully, but these errors were encountered:
Inconsistency between AccountBalance and AccountHistory
Summary
AuctionBid
entries that according to the AccountHistory (provided by FullNode) were sent todf1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z
in block1438560
were not included in the balance.df1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z
for example for the tokenSPY
.Steps to Reproduce
Ensure you have
npm
andnode
installed.Install the required packages:
Change the RPC-Endpoint within the fol where it says
ADD-YOUR-RPC-ENDPOINT-HERE
to one you have access to.Run the example:
Results (detailed):
The example (df1qvzdgd85m67eym95l0jxrdn6aue5cjthpg78r4z, SPY) shows that based on the
accountHistory
the account should have a balance of 0.00000621 SPY. And yet the FullNode reports a present balance of 0 Spy.This example can also be done with different setups:
All of these show a different balance than the one reported by the fullNode.
I could pinpoint this down to the wrong entry:
The values within this entry represent exactly the amount by which the
accountHistory
and theaccountBalance
differ. It seems, that this entry isn't valid and should not be part of the account History.Environment
[Please fill all of the following or NA if not applicable]
The text was updated successfully, but these errors were encountered: