Skip to content

Commit

Permalink
Ana/polkadot fix store rewards 0 and set fixed decimals for rewards a…
Browse files Browse the repository at this point in the history
…mounts (#583)

* handle polkadot rewards amounts as bignumber

* hyper important fix. store previous era rewards

* enable polkadot

* fix polkador rewards amounts for real

* try fix store empty rewards

* fix rewards amounts decimals for real

* changelog

* changelog

* disable polkadot for production again

* oops

* Apply suggestions from code review

* linted

Co-authored-by: Fabian <[email protected]>
  • Loading branch information
Bitcoinera and faboweb authored Apr 13, 2020
1 parent bc5a18d commit eb37e13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changes/ana_polkadot-rewards-amounts-as-bignumber-and-enable
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions lib/block-listeners/polkadot-node-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/reducers/polkadotV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit eb37e13

Please sign in to comment.