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

fix validator state when trying to update the max-rate #4647

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,10 @@ func (db *DB) Finalise(deleteEmptyObjects bool) {
// TODO: remove validator cache after commit
for addr, wrapper := range db.stateValidators {
if err := db.UpdateValidatorWrapper(addr, wrapper); err != nil {
utils.Logger().Warn().Err(err).Msg("Unable to update the validator wrapper on the finalize")
utils.Logger().Warn().Err(err).
Str("name", wrapper.Name).
Str("addr", addr.String()).
Msg("Unable to update the validator wrapper on the finalize")
}
}
addressesToPrefetch := make([][]byte, 0, len(db.journal.dirties))
Expand Down
4 changes: 2 additions & 2 deletions internal/chain/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func setElectionEpochAndMinFee(chain engine.ChainReader, header *block.Header, s

if config.IsMaxRate(newShardState.Epoch) {
for _, addr := range chain.ValidatorCandidates() {
if _, err := availability.UpdateMaxCommissionFee(state, addr, minRate); err != nil {
if _, err := availability.UpdateMaxCommissionFee(newShardState.Epoch, config, state, addr, minRate); err != nil {
return err
}
}
Expand Down Expand Up @@ -489,7 +489,7 @@ func setElectionEpochAndMinFee(chain engine.ChainReader, header *block.Header, s
// higher than the the MaxRate by UpdateMinimumCommissionFee above
if config.IsMaxRate(newShardState.Epoch) && minRateNotZero {
for _, addr := range chain.ValidatorCandidates() {
if _, err := availability.UpdateMaxCommissionFee(state, addr, minRate); err != nil {
if _, err := availability.UpdateMaxCommissionFee(newShardState.Epoch, config, state, addr, minRate); err != nil {
return err
}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var (
HIP30Epoch: big.NewInt(1673), // 2023-11-02 17:30:00+00:00
BlockGas30MEpoch: big.NewInt(1673), // 2023-11-02 17:30:00+00:00
MaxRateEpoch: EpochTBD,
TopMaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
}
Expand Down Expand Up @@ -122,6 +123,7 @@ var (
HIP30Epoch: big.NewInt(2176), // 2023-10-12 10:00:00+00:00
BlockGas30MEpoch: big.NewInt(2176), // 2023-10-12 10:00:00+00:00
MaxRateEpoch: EpochTBD,
TopMaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
}
Expand Down Expand Up @@ -168,6 +170,7 @@ var (
HIP30Epoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
TopMaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
}
Expand Down Expand Up @@ -261,6 +264,7 @@ var (
ValidatorCodeFixEpoch: EpochTBD,
HIP30Epoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
TopMaxRateEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
Expand Down Expand Up @@ -308,6 +312,7 @@ var (
HIP30Epoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
TopMaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
}
Expand Down Expand Up @@ -358,6 +363,7 @@ var (
big.NewInt(0), // MaxRateEpoch
big.NewInt(0), // MaxRateEpoch
big.NewInt(0),
big.NewInt(0),
}

// TestChainConfig ...
Expand Down Expand Up @@ -405,6 +411,7 @@ var (
big.NewInt(0), // BlockGas30M
big.NewInt(0), // MaxRateEpoch
big.NewInt(0), // MaxRateEpoch
big.NewInt(0), // MaxRateEpoch
big.NewInt(0),
}

Expand Down Expand Up @@ -578,6 +585,9 @@ type ChainConfig struct {

// MaxRateEpoch will make sure the validator max-rate is at least equal to the minRate + the validator max-rate-increase
MaxRateEpoch *big.Int `json:"max-rate-epoch,omitempty"`

// TopMaxRateEpoch will make sure the validator max-rate is less to 100% for the cases where the minRate + the validator max-rate-increase > 100%
TopMaxRateEpoch *big.Int `json:"top-max-rate-epoch,omitempty"`
}

// String implements the fmt.Stringer interface.
Expand Down Expand Up @@ -849,6 +859,10 @@ func (c *ChainConfig) IsMaxRate(epoch *big.Int) bool {
return isForked(c.MaxRateEpoch, epoch)
}

func (c *ChainConfig) IsTopMaxRate(epoch *big.Int) bool {
return isForked(c.TopMaxRateEpoch, epoch)
}

// During this epoch, shards 2 and 3 will start sending
// their balances over to shard 0 or 1.
func (c *ChainConfig) IsOneEpochBeforeHIP30(epoch *big.Int) bool {
Expand Down
10 changes: 9 additions & 1 deletion staking/availability/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/numeric"
"github.com/harmony-one/harmony/shard"
Expand Down Expand Up @@ -269,7 +270,7 @@ func UpdateMinimumCommissionFee(
}

// UpdateMaxCommissionFee makes sure the max-rate is at least higher than the rate + max-rate-change.
func UpdateMaxCommissionFee(state *state.DB, addr common.Address, minRate numeric.Dec) (bool, error) {
func UpdateMaxCommissionFee(epoch *big.Int, config *params.ChainConfig, state *state.DB, addr common.Address, minRate numeric.Dec) (bool, error) {
utils.Logger().Info().Msg("begin update max commission fee")

wrapper, err := state.ValidatorWrapper(addr, true, false)
Expand All @@ -279,6 +280,13 @@ func UpdateMaxCommissionFee(state *state.DB, addr common.Address, minRate numeri

minMaxRate := minRate.Add(wrapper.MaxChangeRate)

if config.IsTopMaxRate(epoch) {
hundredPercent := numeric.NewDec(1)
if minMaxRate.GT(hundredPercent) {
minMaxRate = hundredPercent
}
}

if wrapper.MaxRate.LT(minMaxRate) {
utils.Logger().Info().
Str("addr", addr.Hex()).
Expand Down