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

Rosetta Implementation - pt2 FIX2 (Stage 3.2 of Node API Overhaul) #3338

Merged
merged 22 commits into from
Sep 11, 2020

Conversation

Daniel-VDM
Copy link
Contributor

@Daniel-VDM Daniel-VDM commented Sep 11, 2020

Stage 3.2 FIX2 of Node API Overhaul

This PR is related to #3312 .

TLDR: This fixes the Undelegation reward operation as well as correctly accounts for the redelegation balance changes. This also adds an info dump for the last block that was garbage collected for non-archival DBs.

Details

Previously, the Undelegation transaction would result in a balance changing operation (other than gas). As this is not the case due to the locking period, the balance at a given block could be different than what it is on-chain. Therefore a 'special' transaction is added to the implementation to account for the Undelegation payouts at the last block of an epoch (similar to the pre-staking era block rewards).

Note that all nodes (archival & pruned) store the last block of an epoch, however, the Undelegations saved for the said block are after the Undelegations have been paid out. Since the unpaid Undelegations are needed to recompute the paid out amount for each delegator, the state of the second to the last block of an epoch is required. This means that the non-archival nodes/DBs will not be able to provide this data unless the state is still in memory. This is why I have added the 'oldest block identifier' on the network endpoint for nodes running in the non-archival mode.

The oldest block number is computed from the biggest block number that has been garbage collected plus 1. Since the block garbage collection is done monotonically w.r.t. block number, this should always give a block number that is in memory.

Lastly, I used the transaction receipt to report how much of the redelegation took from the account's balance. As well as did some general refactoring/clean-up given the new functions & variables.

All logic was tested using localnet as well as testnet using the rosetta-cli.

@Daniel-VDM Daniel-VDM added bug Something isn't working rpc RPC or API labels Sep 11, 2020
@Daniel-VDM Daniel-VDM requested a review from rlan35 September 11, 2020 00:45
@Daniel-VDM Daniel-VDM self-assigned this Sep 11, 2020
@codecov
Copy link

codecov bot commented Sep 11, 2020

Codecov Report

Merging #3338 into main will decrease coverage by 0.07%.
The diff coverage is 22.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3338      +/-   ##
==========================================
- Coverage   34.38%   34.30%   -0.08%     
==========================================
  Files         209      209              
  Lines       24906    25020     +114     
==========================================
+ Hits         8564     8584      +20     
- Misses      15685    15785     +100     
+ Partials      657      651       -6     
Impacted Files Coverage Δ
rosetta/common/errors.go 0.00% <0.00%> (ø)
rosetta/services/network.go 40.80% <0.00%> (-3.85%) ⬇️
core/blockchain.go 8.17% <11.11%> (-0.23%) ⬇️
rosetta/services/block.go 46.44% <26.11%> (-3.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f42338c...834e09b. Read the comment docs.

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
…dInEpoch

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Fix GetUndelegationPayouts
* Add GetDelegationsByValidatorAtBlock
* Keep beaconchain usage at a minimum

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Use refactored token lock period getter

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Add UndelegationPayoutOperation
* Rename PreStakingEraBlockRewardOperation to UndelegationPayoutOperation

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Refactor special case transaction handeling & add helper functions
for determanining when payouts should be calculated
* Make getBlockSignerInfo a method of BlockAPI
* Rename constants for clarity
* Add unit tests for formatting Undelegation payout special transaction

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
@Daniel-VDM Daniel-VDM force-pushed the rosetta-undelegation-fix branch from 15d8cc1 to 257041d Compare September 11, 2020 06:18
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
@Daniel-VDM Daniel-VDM force-pushed the rosetta-undelegation-fix branch from 23a0490 to 834e09b Compare September 11, 2020 08:44
@Daniel-VDM Daniel-VDM merged commit e74ab0b into harmony-one:main Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rpc RPC or API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants