Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apps/whale-api): add updatemasternode indexer #1869

Merged
merged 81 commits into from
Dec 12, 2022

Conversation

imkven
Copy link
Contributor

@imkven imkven commented Nov 23, 2022

What this PR does / why we need it:

Add UpdateMasternodeIndexer extends DfTxIndexer<UpdateMasternode> to update the masternode index when the DfTx UpdaterMasternode transaction is created.

Which issue(s) does this PR fixes?:

Fixes part of #1842

marktanrj and others added 30 commits November 1, 2022 12:42
Bump testcontainers to `grandcentral` with `master-1d169a75`. Fixes all broken tests and known regression from this change.

Co-authored-by: Dilshan Madushanka <[email protected]>
….ts` to match other tests (#1865)

<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:
Uses to the assertion order used by all other tests. Uses a regex
pattern to match instead of `toContain`.

#### Additional comments?:

As requested in
#1841 (comment)
…#1854)

<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:

Add tests for new fixes on defid v3.
}
}

async indexStats (block: RawBlock, data: Masternode): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it won't make sense to indexStats for an update? Since statistically there isn't any changes for updates?

  • count, no changes, updating doesn't change the amount of masternode?
  • tvl, what's locked is still locked

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. Thanks.

Copy link
Contributor Author

@imkven imkven Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed. 3538564

Comment on lines 78 to 90
await this.masternodeMapper.put({
id: data.nodeId,
sort: `${HexEncoder.encodeHeight(block.height)}${txn.txid}`,
ownerAddress: (ownerAddress !== null) ? ownerAddress : mn.ownerAddress,
operatorAddress: (operatorAddress !== null) ? operatorAddress : mn.operatorAddress,
creationHeight: block.height,
resignHeight: -1,
mintedBlocks: 0,
timelock: 0,
block: { hash: block.hash, height: block.height, medianTime: block.mediantime, time: block.time },
collateral: txn.vout[1].value.toFixed(8),
updateRecords
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be replacing all the entries since it's an update, not a new creation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@imkven imkven Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. 0b13304

Comment on lines 149 to 151
async invalidateBlockStart (block: RawBlock): Promise<void> {
await this.masternodeStatsMapper.delete(block.height)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async invalidateBlockStart (block: RawBlock): Promise<void> {
await this.masternodeStatsMapper.delete(block.height)
}

Copy link
Contributor Author

@imkven imkven Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed. c545463

Comment on lines 114 to 120
mapTimelockStats (latest: TimelockStats[], lockStats: TimelockStats): TimelockStats[] {
return latest.map(x => ({
...x,
count: x.weeks === lockStats.weeks ? (x.count - lockStats.count) : x.count,
tvl: x.weeks === lockStats.weeks ? new BigNumber(x.tvl).minus(lockStats.tvl).toFixed(8) : x.tvl
}))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mapTimelockStats (latest: TimelockStats[], lockStats: TimelockStats): TimelockStats[] {
return latest.map(x => ({
...x,
count: x.weeks === lockStats.weeks ? (x.count - lockStats.count) : x.count,
tvl: x.weeks === lockStats.weeks ? new BigNumber(x.tvl).minus(lockStats.tvl).toFixed(8) : x.tvl
}))
}

Copy link
Contributor Author

@imkven imkven Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed. 3538564

shohamc1
shohamc1 previously approved these changes Dec 7, 2022
infinia-yzl
infinia-yzl previously approved these changes Dec 12, 2022
@imkven imkven dismissed stale reviews from infinia-yzl and shohamc1 via 0477441 December 12, 2022 03:38
helloscoopa
helloscoopa previously approved these changes Dec 12, 2022
marktanrj
marktanrj previously approved these changes Dec 12, 2022
Copy link
Contributor

@marktanrj marktanrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fuxingloh
Copy link
Contributor

docs/node/CATEGORIES/11-masternode.md applied in #1921

@fuxingloh fuxingloh dismissed stale reviews from marktanrj and helloscoopa via faf5589 December 12, 2022 06:26
…CreateMasternode (#1920)

#### What this PR does / why we need it:

This utilizes the "forward indexing" design; it doesn't require
`whale-api` to be reindexed. It will automatically create a history
entry to `MasternodeMapper`. You can update your `whale-api` node
without this change.
@fuxingloh fuxingloh merged commit 97aeb47 into main Dec 12, 2022
@fuxingloh fuxingloh deleted the kvenho/updatemasternode-whale-indexer branch December 12, 2022 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants