Skip to content

Fix: max rate issue #4580

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

Merged
merged 10 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,9 @@ func (db *DB) Finalise(deleteEmptyObjects bool) {
// Commit validator changes in cache to stateObjects
// TODO: remove validator cache after commit
for addr, wrapper := range db.stateValidators {
db.UpdateValidatorWrapper(addr, wrapper)
if err := db.UpdateValidatorWrapper(addr, wrapper); err != nil {
utils.Logger().Warn().Err(err).Msg("Unable to update the validator wrapper on the finalize")
}
}
addressesToPrefetch := make([][]byte, 0, len(db.journal.dirties))
for addr := range db.journal.dirties {
Expand Down
8 changes: 8 additions & 0 deletions internal/chain/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ func setElectionEpochAndMinFee(chain engine.ChainReader, header *block.Header, s
}
isElected[addr] = struct{}{}
}

if config.IsMaxRate(newShardState.Epoch) {
for _, addr := range chain.ValidatorCandidates() {
if _, err := availability.UpdateMaxCommissionFee(state, addr, minRate); err != nil {
return err
}
}
}
// due to a bug in the old implementation of the minimum fee,
// unelected validators did not have their fee updated even
// when the protocol required them to do so. here we fix it,
Expand Down
17 changes: 16 additions & 1 deletion internal/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var (
ValidatorCodeFixEpoch: big.NewInt(1535), // 2023-07-20 05:51:07+00:00
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,
}

// TestnetChainConfig contains the chain parameters to run a node on the harmony test network.
Expand Down Expand Up @@ -118,6 +119,7 @@ var (
ValidatorCodeFixEpoch: big.NewInt(1296), // 2023-04-28 07:14:20+00:00
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,
}
// PangaeaChainConfig contains the chain parameters for the Pangaea network.
// All features except for CrossLink are enabled at launch.
Expand Down Expand Up @@ -161,6 +163,7 @@ var (
ValidatorCodeFixEpoch: EpochTBD,
HIP30Epoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
}

// PartnerChainConfig contains the chain parameters for the Partner network.
Expand Down Expand Up @@ -205,6 +208,7 @@ var (
ValidatorCodeFixEpoch: big.NewInt(5),
HIP30Epoch: big.NewInt(7),
BlockGas30MEpoch: big.NewInt(7),
MaxRateEpoch: EpochTBD,
}

// StressnetChainConfig contains the chain parameters for the Stress test network.
Expand Down Expand Up @@ -249,6 +253,7 @@ var (
ValidatorCodeFixEpoch: EpochTBD,
HIP30Epoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
}

// LocalnetChainConfig contains the chain parameters to run for local development.
Expand Down Expand Up @@ -292,6 +297,7 @@ var (
ValidatorCodeFixEpoch: big.NewInt(2),
HIP30Epoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
}

// AllProtocolChanges ...
Expand Down Expand Up @@ -336,7 +342,8 @@ var (
big.NewInt(0), // FeeCollectEpoch
big.NewInt(0), // ValidatorCodeFixEpoch
big.NewInt(0), // BlockGas30M
big.NewInt(0), // HIP30Epoch
big.NewInt(0), // BlockGas30M
big.NewInt(0), // MaxRateEpoch
}

// TestChainConfig ...
Expand Down Expand Up @@ -382,6 +389,7 @@ var (
big.NewInt(0), // ValidatorCodeFixEpoch
big.NewInt(0), // HIP30Epoch
big.NewInt(0), // BlockGas30M
big.NewInt(0), // MaxRateEpoch
}

// TestRules ...
Expand Down Expand Up @@ -547,6 +555,9 @@ type ChainConfig struct {
HIP30Epoch *big.Int `json:"hip30-epoch,omitempty"`

BlockGas30MEpoch *big.Int `json:"block-gas-30m-epoch,omitempty"`

// 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"`
}

// String implements the fmt.Stringer interface.
Expand Down Expand Up @@ -803,6 +814,10 @@ func (c *ChainConfig) IsHIP30(epoch *big.Int) bool {
return isForked(c.HIP30Epoch, epoch)
}

func (c *ChainConfig) IsMaxRate(epoch *big.Int) bool {
return isForked(c.MaxRateEpoch, 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
24 changes: 24 additions & 0 deletions staking/availability/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,27 @@ func UpdateMinimumCommissionFee(
}
return false, nil
}

// 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) {
utils.Logger().Info().Msg("begin update max commission fee")

wrapper, err := state.ValidatorWrapper(addr, true, false)
if err != nil {
return false, err
}

minMaxRate := minRate.Add(wrapper.MaxChangeRate)

if wrapper.MaxRate.LT(minMaxRate) {
utils.Logger().Info().
Str("addr", addr.Hex()).
Str("old max-rate", wrapper.MaxRate.String()).
Str("new max-rate", minMaxRate.String()).
Msg("updating max commission rate")
wrapper.MaxRate.SetBytes(minMaxRate.Bytes())
return true, nil
}

return false, nil
}
4 changes: 2 additions & 2 deletions test/build-localnet-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ hmy --node="http://localhost:9500" staking create-validator \
--bls-pubkeys 4f41a37a3a8d0695dd6edcc58142c6b7d98e74da5c90e79b587b3b960b6a4f5e048e6d8b8a000d77a478d44cd640270c,7dcc035a943e29e17959dabe636efad7303d2c6f273ace457ba9dcc2fd19d3f37e70ba1cd8d082cf8ff7be2f861db48c \
--name "s0-localnet-validator1" --identity "validator1" --details "validator1" \
--security-contact "localnet" --website "localnet.one" \
--max-change-rate 0.1 --max-rate 0.1 --rate 0.1 \
--max-change-rate 0.01 --max-rate 0.01 --rate 0.01 \
--max-total-delegation 100000000 --min-self-delegation 10000 --bls-pubkeys-dir .hmy/extbls/

hmy --node="http://localhost:9500" staking create-validator \
--validator-addr one1auqndgthqu5lznsn7tuma8s5333cq0y07cwc6x --amount 10000 \
--bls-pubkeys b0917378b179a519a5055259c4f8980cce37d58af300b00dd98b07076d3d9a3b16c4a55f84522f553872225a7b1efc0c \
--name "s0-localnet-validator2" --identity "validator2" --details "validator2" \
--security-contact "localnet" --website "localnet.one" \
--max-change-rate 0.1 --max-rate 0.1 --rate 0.1 \
--max-change-rate 0.1 --max-rate 0.1 --rate 0.05 \
--max-total-delegation 100000000 --min-self-delegation 10000 --bls-pubkeys-dir .hmy/extbls/

hmy --node="http://localhost:9500" staking create-validator \
Expand Down