Bounty program is to help the community take part in the development of the Harmony blockchain. It covers from core feature to validator tooling, from dApp development to DeFi integration.
MIT License
59
stars
23
forks
source link
Adding revert mechanism to `statedb.UpdateValidatorWrapper` #90
Implement the revert mechanism for state.DB.UpdateValidatorWrapper in state.Journal.
Context
During the staking launch, we added in-memory cache of ValidatorWrapper in statedb to reduce read attempts from level db.
// core/state/statedb.go:81
type DB struct {
stateValidators map[common.Address]*stk.ValidatorWrapper
}
This is a temporary hack since there is no revert mechanism for setting stateValidators. This is OK for now since IntermediateRoot is called after execution of each staking transaction, so there is no revert mechanism needed for reverting ValidatorWrapper structure. But if we want to put the staking transactions into the smart contract, the revert mechanism is definitely needed for a smart contract execution failure.
Acceptance Criteria
[ ] Implement the revert mechanism in state DB.
[ ] The correctness of the state data must be ensured as highest priority.
[ ] Implement unit test cases with coverage >70% for new code.
[ ] Implement a unit test to show:
The UpdateValidatorWrapper operation can be reverted upon explicit Revert call;
The state execution result (state root) is the same as not executing the revert logic;
The read result (ValidatorWrapperCopy, ValidatorWrapper) is as expected. (May need to delete one of the read method)
[ ] A benchmark on mainnet beacon validator node about memory and cpu performance with the new logic. Some optimization logic may be needed if the memory and cpu usage have a huge rise after this PR.
Description
Implement the revert mechanism for
state.DB.UpdateValidatorWrapper
instate.Journal
.Context
During the staking launch, we added in-memory cache of
ValidatorWrapper
instatedb
to reduce read attempts from level db.This is a temporary hack since there is no revert mechanism for setting
stateValidators
. This is OK for now sinceIntermediateRoot
is called after execution of each staking transaction, so there is no revert mechanism needed for revertingValidatorWrapper
structure. But if we want to put the staking transactions into the smart contract, the revert mechanism is definitely needed for a smart contract execution failure.Acceptance Criteria
UpdateValidatorWrapper
operation can be reverted upon explicitRevert
call;ValidatorWrapperCopy
,ValidatorWrapper
) is as expected. (May need to delete one of the read method)Reward
$7,000 in ONE token.