diff --git a/changes/ana_polkadot-rewards-amounts-as-bignumber-and-enable b/changes/ana_polkadot-rewards-amounts-as-bignumber-and-enable new file mode 100644 index 0000000000..f97b0d2be4 --- /dev/null +++ b/changes/ana_polkadot-rewards-amounts-as-bignumber-and-enable @@ -0,0 +1,2 @@ +[Changed] [#583](https://github.com/cosmos/lunie/pull/583) Polkadot rewards amounts stored in DB have now a fixed number of decimals of 9 @Bitcoinera +[Fixed] [#583](https://github.com/cosmos/lunie/pull/583) Perhaps fixes storing empty rewards bug ("store rewards 0") @Bitcoinera \ No newline at end of file diff --git a/lib/block-listeners/polkadot-node-subscription.js b/lib/block-listeners/polkadot-node-subscription.js index bc63319b78..7fe0c87a03 100644 --- a/lib/block-listeners/polkadot-node-subscription.js +++ b/lib/block-listeners/polkadot-node-subscription.js @@ -222,6 +222,14 @@ class PolkadotNodeSubscription { } async updateRewards(era, chainId) { const rewards = await this.polkadotAPI.getEraRewards(era) // ATTENTION: era means "get all rewards of all eras since that era". putting a low number takes a long time. + // perhaps the moment of era change it is still too early to fetch the previous era rewards + // we loop waiting for rewards every 10 seconds + if (rewards.length === 0) { + console.log('Rewards in era are 0, will retry getting rewards in 10s') + setTimeout(async () => { + await this.updateRewards(era, chainId) + }, 10000) + } console.log('store rewards', rewards.length) this.storeRewards( rewards diff --git a/lib/reducers/polkadotV0-reducers.js b/lib/reducers/polkadotV0-reducers.js index 80c6784121..32f346d97e 100644 --- a/lib/reducers/polkadotV0-reducers.js +++ b/lib/reducers/polkadotV0-reducers.js @@ -316,9 +316,10 @@ function rewardsReducer(network, validators, rewards, reducers) { JSON.stringify(validatorReward.validator) ) if (existingRewardCollectionForValidator) { - existingRewardCollectionForValidator.amount = + existingRewardCollectionForValidator.amount = ( parseFloat(existingRewardCollectionForValidator.amount) + parseFloat(validatorReward.amount) + ).toFixed(9) } else { collection.push(validatorReward) }