* Resolve harmony-one/bounties#77: Staking precompiles
Create write capable precompiles that can perform staking transactions
Add hard fork logic (EpochTBD) for these precompiles
Tests for new code with at least 80% unit test coverage
Staking library + tests in MaxMustermann2/harmony-staking-precompiles
* Fix small typo in comment
* Run goimports on files to fix Travis
* Do not activate staking precompile on shard 0
* Cascade readOnly to WriteCapableContract
* No overlap in readOnly + writeCapable precompiles
* Use function selector instead of directive
From Solidity, use abi.encodeWithSelector and match it against the
exact ABI of the functions. This allows us to remove the need for
a directive (32) being encoded, and thus saves 28 bytes of data.
* Do not allow contracts to become validators
As discussed with Jacky on #3906
* Merge harmony-one/harmony/main properly this time
* Run goimports
* Update gas calculation for staking precompile
Please see comment in core/vm/contracts_write.go RequiredGas
* Do not allow contract to become validator (2/2)
* Cache StakeMsgs from precompiled transactions
Add the StakeMsgs to ProcessorResult and cascade them in insertChain
* Remove ContractCode fields from validators
Since smart contracts can no longer beecome validators,
this field is superfluous. Remove it from the Wrapper
structure, and do not assign it a value when creating
a validator. Build and goimports checked
* Update comments in response to feedback
(1) Comments to start with function names
(2) Comments for public variables
(3) Comment to match function name RunPrecompiledContract
(4) Clarify that CreateValidatorFunc + EditValidatorFunc are still used
* Fix Travis build by reverting rosetta change
* Add revert capability to 3 staking tx types
- Delegate
- Undelegate
- CollectRewards
* Fix build: Update evm_test for ValidatorWrapper
* Merge main into harmony-staking-precompiles
* Add gas for precompile calls and allow EOA usage
- Each time the precompile is called, charge the base gas fee plus data
cost (if data can be parsed successfully). A gas fee is added to
prevent benevolent contract deployers from subsidizing the staking
transactions for EOAs through repeated assembly `delegatecall`.
- Allow EOAs to use the staking precompile directly. Some changes to
the Solidity library are associated with this change.
- Remove bytes from parsing address, since the ABI unpacks it into an
address format correctly.
- Add or update tests. Test coverage report to be attached to the PR
shortly.
* Run goimports
* Check read only and write capable for overlap
* Handle precompile stakeMsgs for block proposer
The staking precompile generates staking messages which are cascaded to
the block via the EVM in `state_processor.go`. This change cascades them
in `worker.go` to allow block proposers and block verifiers to keep the
same state.
* Run goimports for cf2dfac4081444e36a120c9432f4e..
* Update staking precompile epoch to 2 for localnet
Bring it in line with staking epoch. Change effects all configurations
except mainnet and testnet. `goimports` included.
* Add read only precompile to fetch the epoch num
* Move epoch precompile to 250
* precompiles: left pad the returned epoch number
* chainConfig: check epochs for precompiles
panic if staking precompile epoch < pre staking epoch
* Add staking migration precompile
- Lives at address 251
- Migrates delegations + pending undelegations from address A to B
- Useful if address A is hacked
- Charges gas of 21k + cost of bytes for two addresses
- Does not remove existing delegations, just sets them to zero.
Replicates current undelegate setup
- Unit tests and `goimports` included. Integration test following
shortly in MaxMustermann2/harmony-staking-precompiles
* Migration precompile: merge into staking
Merge the two precompiles into one, add gas calculation for migration
precompile. Move epoch precompile to 251 as a result. When migrating,
add undelegations to `To`'s existing undelegations, if any match the
epoch.
* Add migration gas test, remove panic, add check
In response to review comments, add tests for migration gas wherein
there are 0/1/2 delegations to migrate. Add the index out of bound check
to migration gas calculator and remove panics. Lastly, re-sort
migrated undelegations if no existing undelegation in the same epoch was
found on `To`.
* Move undelegations sorting to end of loop
* [rpc] fix some test cases
* fix test cases
* [rpc] use harmony/eth/rpc for customized changes
* [RPC] replace one more use of RPC at accounts module
* [RPC] fix test cases
1. Refactored service manager with cleaner interface.
2. Add prometheus to the service manager.
3. Graceful shutdown of the services (including consensus).
4. Some code refactor regarding consensus graceful shutdown.
Co-authored-by: Rongjian Lan <rongjian.lan@gmail.com>
* [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 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
* [rosetta] Fix staking + plain tx receipt fetch
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add receipt check error catch
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix special case ID check
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix receipt check error catch
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Refactor operations & prep for internal tx exposure
* Remove gas op relation for tx operations. Gas is for submission & processing
the tx, thus not really related to the amount being transferred
* Make optional starting op a ptr to a uint to keep consistent
* Reorg file for consistency of fn placement
* Rename functions for clarity
* Make getContractCreationNativeOperations consume getBasicTransferOperations for consistency
* Remove invariant doc as it does not apply anymore
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add framework for parsing traced txs
* Define ContractInfo struct for FormatTransaction
* Add tx trace helper function defs & propagate type defs
* Add a GetTransactionStatus helper fn for Operation formatting/creation
* Add wrapper function, getContractTransferNativeOperations, to get internal operations
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Implement transaction tracer
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [tracer] Add CallerAddress & CodeAddress to tracer logs
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [tracer] Remove ptr to slice & map in StructLogRes
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Implement getContractInternalTransferNativeOperations
* Add ContractAddress to ContractInfo for future usages (i.e: erc20 parsing)
* Only check for contract address if there is tx data in BlockTransaction
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix status report for contract related txs
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [tracer] Expose contract address instead of code address
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add trace cache & update TODO
* Trace any PLAIN transaction instead of only transactions with data.
This is to account for fall back contract fn calls & ignore staking data.
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Make internal tx formatter not return err on nil exec result
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* Fix lint
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix tests
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add internal tx unit tests
* Fix tx data len check for contract related transfers as a transaction with len 0
data can happen for a contract (and fail) due to fall back operations.
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update invariant comment
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Expose mutually exclusive ops + update docs & tests
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix docs and err msgs
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Start refactor of side effect transactions
* Rename special transactions to side effect transactions
* Rename various variables for consistancy within context of side effect transasctions
* Remove all individual transaction for side effects, instead start process of batching
all side effects under one transaction.
* Finish batching of genesis side effect transaction.
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add `getSideEffectTransaction` & refactor consumers
This will hook in the logic to report all side effects under 1 transactions.
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Remove genesis logic path for special effect txs
It is not integrated with the normal special effect logic
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Rename helper fns to use 'side effect'
Replacing special case
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix special case operation index
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Consolidate side effect operation logic
* Update tests for new side effect logic
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix import
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update inline doc
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix comment for /block logic
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Support EVM pre-process for contract creation txs
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix re-delegation amount
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [node] Add Cx epoch check
* Report invalid epoch for staking tx
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add Cx epoch check in Metadata request
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [node] Fix lint
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Make nonsensical native tx construction error
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Refactor native constant names to match value
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Remove hex address comparison
This is done since the hex address in the metadata is more of a
QOL feature, all that matters is the b32 address.
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix error message for incorrect signed tx parse
* Add check for sender address when parsing unsigned tx
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Make bad signature error message clearer
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add shard ID check when combining transactions
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add shard ID check for tx Hash & Submission
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix invalid signature type err msg
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add shard check for tx parse
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Add check for shard ID when creating Tx payload
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update to v1.4.6 of rosetta SDK
* Set rosetta release version
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rpc] Expose DoEVMCall
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix contract related operations
* Make contract creation be a 2 operation pair, with contract addr as receiver
* Add Contract address to all transaction metadata that involving contract operations
* Update construction API to include framework for contract functionality
* Update tests
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix imports
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix construction metadata check for contracts
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [ntp] Make TestCheckLocalTimeAccurate fault tolerant
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix nil block ptr crash & generalize getBlock
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Correct error type for account rosetta errors
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix pre-staking rewards with GetPreStakingBlockRewards
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [hmy] Refactor GetDetailedBlockSignerInfo to use availability
* Add GetPreStakingBlockRewards with cache
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Fix prestaking block reward unit tests
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Report tx fees of coinbase for prestaking rewards
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
* [rosetta] Update docker file name in readme
* [rosetta] Print node version when running node using docker
* [rosetta] Make docker image smaller & update README.md
Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>