* Add revert mechanism for UpdateValidatorWrapper
Closesharmony-one/bounties#90
(1) Use LRU for ValidatorWrapper objects in stateDB to plug a potential
memory leak
(2) Merge ValidatorWrapper and ValidatorWrapperCopy to let callers ask
for either a copy, or a pointer to the cached object. Additionally,
give callers the option to not deep copy delegations (which is a
heavy process). Copies need to be explicitly committed (and thus
can be reverted), while the pointers are committed when Finalise
is called.
(3) Add a UpdateValidatorWrapperWithRevert function, which is used by
staking txs `Delegate`, `Undelegate`, and `CollectRewards`. Other
2 types of staking txs and `db.Finalize` continue to use
UpdateValidateWrapper without revert, again, to save memoery
(4) Add unit tests which check
a) Revert goes through
b) Wrapper is as expected after revert
c) State is as expected after revert
* Change back to dictionary for stateValidators
Since the memory / CPU usage saved is not significantly different when
using an LRU + map structure, go back to the original dictionary
structure to keep code easy to read and have limited modifications.
* Add tests for validator wrapper reverts
As requested by @rlan35, add tests beyond just adding and reverting a
delegation. The tests are successive in the sense that we do multiple
modifications to the wrapper, save a snapshot before each modification
and revert to each of them to confirm everything works well. This change
improves test coverage of statedb.go to 66.7% from 64.8% and that of
core/state to 71.9% from 70.8%, and covers all the code that has been
modified by this PR in statedb.go.
For clarity, the modifications to the wrapper include (1) creation of
wrapper in state, (2) adding a delegation to the wrapper, (3)
increasing the blocks signed, and (4) a change in the validator Name and
the BlockReward. Two additional tests have been added to cover the
`panic` and the `GetCode` cases.
* Add logic to do aggregated reward distribution
* Fix build and consensus
* add aggregated reward logic
* refactor payouts
* Fix batch scheduling
* test code
* revert test code
* more comments
* [rpc] updated rpc to GetCirculationSupply to sub token burnt
* [explorer] add a small fix
* [rpc] fix at getInaccessible tokens
* [rpc] added fix at header.Root
* [staking] Move reward values from Network pkg to its own
* Refactor code for the move
* Implement logic to accurately set total supply
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Add totalPreStakingNetworkRewards to reward values
* Implement GetTotalTokens for use in other packages
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [core] Move getGenesisSpec to core pkg
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [core] Update gen spec docs
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Hook in updateInitialRewardValues on node init
* Add some docs for clarification
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rpc] Fix GetCirculatingSupply & GetTotalSupply RPCs
* Updated err msg in staking reward values.go
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rpc] Move GetCirculatingSupply logic into internal pkg
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [explorer] Update circulating supply & total supply vals
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Add Localnet rewards val & Errs
* [internal] Make GetCirculatingSupply consistent with WhatPercentStakedNow
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Fix imports
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [consensus] Make PercentageForTimeStamp return 1 for non-mainnet chains
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Fix reward dec math + Testnet testnet vals
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Make all const reward vals ONE instead of ATTO
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [internal] Correct returned value to ONE instead of Atto
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Fix dec precision
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Fix TestGetPreStakingRewardsFromBlockNumber test
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [staking] Use TotalInitialTokens instead of TotalPreStakingTokens
* Done so basis is off block 0 to account for phased mainnet release
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [internal] Fix GetCirculatingSupply
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Add ethereum transaction support
* fix fmt
* fix lint
* add new block body fork logic
* add back deleted code
* lower case block version const
* add eth txn into new version of block
* refactor back
* refactor more
* fix test code
* Fix build
* Fix build
* revert eth txn in block and block proposal
* fix build
* fix build
* fix build
* Add 3s block time and change of block reward
* fixes
* add new blocks per epoch for testnet
* remove unused code
* fix 2s changing logic
* enable 2s at epoch 73000 at testnet
* [core] Add FindLogsWithTopic & unit test
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Add GetDetailedBlockSignerInfo
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Add IsCommitteeSelectionBlock
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [test] Add test transaction creation helpers
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Refactor account.go & add tests
* Move TestNewAccountIdentifier & TestGetAddress to account_test.go
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Move Operation & Tx formatting to own files
* Move Respective unit tests to own files
* Expose GetOperations & GetStakingOperations
* Expose FormatTransaction, FormatCrossShardReceiverTransaction,
FormatGenesisTransaction, FormatPreStakingRewardTransaction & FormatUndelegationPayoutTransaction
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Move TransactionMetadata to transaction_construction.go
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update construction to use new helpers & formatters
* Make docs consistent for mempool.go
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Move all special tx & blk handling to own file
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Remove all moved fns, methods & tests from block.go
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Fix lint & imports
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Rename all tx related files for clarity
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Rename DefaultSenderAddress to FormatDefaultSenderAddress
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Rename Currency to NativeCurrency
* This is in anticipation of HRC20 token support with rosetta
* Rename various native operation functions accordingly
* Add documentation to explain what a native token is
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix pre-staking block reward calculation
* Move getPreStakingRewardTransactionIdentifiers to block_special.go
* Add epoch to block metadata
* Update unit tests
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Add IsLastBlockInEpoch method to Block & Header
* Refactor all uses of length check `ShardState`
* [hmy] Refactor IsCommitteeSelectionBlock to use chain.IsCommitteeSelectionBlock
* Address PR comments
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update var names in preStakingRewardBlockTransaction
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update staking operations to account for re-delegation
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Add GetUndelegationChange
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Add GetAllUndelegatedDelegators
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Fix GetAllUndelegatedDelegators & add GetDelegationLockingPeriodInEpoch
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix block reward TX ID formatting
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Remove unused GetUndelegationChange
* Fix GetUndelegationPayouts
* Add GetDelegationsByValidatorAtBlock
* Keep beaconchain usage at a minimum
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Remove debug print & update comments for GetUndelegationPayouts
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [core] Add last garbage collected number to blockchain.go
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add oldest block ID in net stat for non-archival nodes
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix network oldest block case when garb col blk unknown
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [core] Rename lastGarbCollectedBlkNum to maxGarbCollectedBlkNum
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [internal/chain] Refactor token lock period getter & expose
* Use refactored token lock period getter
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Add UndelegationPayouts type
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Improve NewError detail failure message
* Add UndelegationPayoutOperation
* Rename PreStakingEraBlockRewardOperation to UndelegationPayoutOperation
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Integrate Correct undelegation payout operations
* 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>
* [hmy] Add caching to GetUndelegationPayouts
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Nit - fix comment
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add block not found error
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Refactor special case txID to be for general
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix lint
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Nit - fix comment
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Nit - Make GetUndelegationPayouts more readable
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* add support for redelegation
* Add test
* Revert "[go.mod] version upgrade of libp2p modules"
This reverts commit ce53468e3e.
* Fix bug that validator self delegation doesn't work
* Restore 7 epoch locking time at redelegation epoch
* Add debug log for chain context
* fix signers share computation to use only non-harmony nodes (#3008)
* Add LastEpochInCommittee at prestaking epoch too (#3014)
* write validator stats at the end of prestaking epoch (#3021)
* write validator stats at the end of prestaking epoch
* also need to write block reward accumulator
* [build] enable static build by default (#2885)
scripts/go_executable_build.sh -s (static build, default)
scripts/go_executable_build.sh -S (non-static build)
Signed-off-by: Leo Chen <leo@harmony.one>
* Code formatting fix based on `staticcheck` (#3023)
* fix some static check issues
* more fixes according to staticcheck
* add nil check on getHeader
* Add more log info
* [rpc] Revert change to v2 GetBalance RPC (#3037)
* Cherrypick crosslink related fixes from t3 to master. (#3045)
* Optimize crosslink verification logic and add more cache (#3032)
* make crosslink broadcast smarter and more efficient (#3036)
* adjust catch up speed to be a sane number
* Fix crosslink broadcast condition (#3041)
* Tx pool error report fix & local build fix (#3046)
* [tx_list] Add transaction after you can fetch tx cost
* [tx_pool] Add error sink reports for removed tx
* Correct log levels for known transactions
* Remove redundant hash to `enqueue` and `add` signatures
* Update tests for signature changes
* [build] Fix local build for MacOs
* [tx_pool] Correct typo & logging level for known tx
* [config] Create Testnet config
* [node.sh] update testnet network config
* [config] correct testnet config
* [main] Enable beacon sync for explorer nodes (#3059)
* [apr] should not use snapshot from last epoch, use current epoch snapshot (#3051)
* use snapshot total delegation instead of current total delegation
* should not use snapshot from last epoch, use current epoch snapshot (#3049)
Co-authored-by: Rongjian Lan <rongjian.lan@gmail.com>
Co-authored-by: Rongjian Lan <rongjian.lan@gmail.com>
* cherrypick log level change
* [rpc] Add active status back to Validator information
[validator] Fix typo for ValidatorRPCEnhanced
[Makefile] Change make exe to build non-static by default
* [network] Added caching to node server (#3048)
* [network] Added caching to node server
* [network] renamed two singleflight.Group
* [network] added two error handling
* [network] added forget logic for single flight
* [network] changed single flight to lru cache solution
* [network] adjusted the cache size
* [network] changed cache size to 10000
* Transaction api improvements (#3057)
* [node] Add option to broadcast invalid tx (on by default)
* update main args to take in broadcast invalid tx
* update node.sh for new broadcast invalid tx option
* [rpc] Do not submit transaction if tx has been finalized
* Support legacy behavior and not return errors on tx submission
* [main] make broadcasting invalid tx default false
* [node] Fix formatting
* Add timeouts for the explorer HTTP service
* [test] State trans unit test (#3043)
* completing create-validator tests
generalizing create validator tests, started with edit validator tests
one round completed before major refactor
* [test] finished coding test TestCheckDuplicateFields
* [test] finished debug TestCheckDuplicateFields
* [test] Added TestDescription_EnsureLength
* [test] added test in validator_test.go TestUpdateDescription
* [test] Added test TestComputed_String
* [test] refactored TestValidatorSanityCheck and added some message in error message returned from sanity check
* [test] removed test index for debugging
* [test] Added test TestValidatorWrapper_SanityCheck. Added value check for TestMarshalUnmarshalValidator. Fixed rlp usage defect in UnmarshalValidator
* [test] added test TestVerifyBLSKeys
* [test] added test TestContainsHarmonyBLSKeys
* [test] added test TestCreateValidatorFromNewMsg
* [test] fixed some tests errors
* [test] added test TestUpdateValidatorFromEditMsg, last editted the test file, finished testing validator_test.go
* [staking] added numeric.Dec.Copy method
* [staking] added CommissionRates.Copy
* [staking] add nil case handle to copy method and related test case
* [test] added nil case for commissionRates.Copy test
* [staking] finished CreateValidator.Copy and related test case
* [staking] added EditValidator.Copy method and related test case
* [test] added zero test cases for Copy method
* [staking] implemented Delegate.Copy and related unit test case
* [staking] added Undelegate.Copy and CollectReward.Copy method. Implemented corresponding test cases
* [test] added two more simple unit tests
* [test] solving the merge conflict with deep copy fix
* [test] added schedule for sharding
* [test] refactored double_sign_test.go
* [test] comment out all test cases for now.
* [test] added record Copy method for testing
* [test] added the first test case in TestVerify
* [test] finished test TestVerify
* [test] Added test TestVerify, TestApplySlashRate, TestSetDifference
* [test] half through TestDelegatorSlashApply
* [test] fix the problem cause by unsafe usage of big.Int
* [staking] added the copy methods to validatorWrapper
* [test] added test cases for copy method for staking/validatorWrapper
* [test] added test case TestApply
* [test] added test case TestRate
* [test] fix the golint errors
* [test] removed commented out unit test code
* [test] remote the empty line in imports
* [test] moved copy methods to stake_testing module
* [test] removed usage of interface stateDB
* [test] removed empty lines in imports
* [test] fixed golint package name issues
* [test] removed a todo when writing code
* [test] moved record.Copy to staking/slash/test
* [test] add some changes
* [test] added prototypes in staketest module
* [test] fix the golint issue in staketest
* [test] make prototype more beautiful
* [test] refactored test TestCheckDuplicateFields
* [test] add createValidator test data
* [test] added positive test case for VerifyAndCreateValidatorFromMsg
* [test] added create validator test
* [test] added the positive test case for TestVerifyAndEditValidatorFromMsg
* [test] added the tests case TestVerifyAndEditValidatorFromMsg
* [test] fix one of the error is not triggered as expected
* [test] more changes in test
* [test] fix the positive test data for TestVerifyAndDelegateFromMsg
* [test] Fixed two comment golint errors
* [test] added delegate tests
* [test] added a make function. WIP
* [test] added undelegate positive test
* [test] added negative test cases for undelegate
* [test] added positive test. not passed. Need to add assert method in test suites
* [test] added equal function to check Validator Equality
* [test] added equals for staketest
* [test] replaced deep equal with new equal methods:
* [test] removed unused codes
* [test] Finishing touch
* [test] fix comment golint issue
* [test] removed dead code in staking_verifier_test.go
Co-authored-by: Ganesha Upadhyaya <ganeshrvce@gmail.com>
* changed the sync port to dns port in flag
* [network] Limit client sync connection (#3071)
* [network] limit client connected peers
* Changed signature and added tests
* Set secure permissions on generated blskey pass file in node.sh
* Fix spellin gtypo in node.sh
* fix latest param handling in api v1
* added comment for the isGreaterThanLatestBlockNum check
* fix a nil pointer crash due to previous revert
Signed-off-by: Leo Chen <leo@harmony.one>
* fix nil pointer crash
Signed-off-by: Leo Chen <leo@harmony.one>
* fix nil pointer of block
Signed-off-by: Leo Chen <leo@harmony.one>
* [rpc] add viewID and epoch to RPCMarshalBlock (#3009)
* [rpc] add viewID and epoch to RPCMarshalBlock
* add apt-get update
* Do not rollback current block on failed block sync (#3101)
Co-authored-by: Ganesha Upadhyaya <ganeshrvce@gmail.com>
Co-authored-by: Rongjian Lan <rongjian.lan@gmail.com>
Co-authored-by: Jacky Wang <jackyw.se@gmail.com>
Co-authored-by: Janet Liang <56005637+janet-harmony@users.noreply.github.com>
Co-authored-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
Co-authored-by: Janet Liang <janet@harmony.one>
Co-authored-by: Sebastian Johnsson <sebastian.johnsson@gmail.com>
Co-authored-by: hsiung <hsiung@pinterest.com>
Co-authored-by: Dennis Won <jhwon0820@gmail.com>
Co-authored-by: Yishuang Chen <34232522+ivorytowerdds@users.noreply.github.com>