harmony-one / bounties

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

Closed JackyWYX closed 2 years ago

JackyWYX commented 2 years ago

Description

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

Reward

$7,000 in ONE token.