From fe1d97a4608ad56f93b3fdd845c182b1cb835582 Mon Sep 17 00:00:00 2001 From: Konstantin <355847+Frozen@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:35:04 -0400 Subject: [PATCH 1/3] Removed outdated check. (#4574) * Removed outdated check. * Fallback for old sync for BeaconBlockChannel. --- node/node.go | 4 ---- node/node_handler.go | 2 -- node/node_syncing.go | 11 ++++++++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/node/node.go b/node/node.go index dbc9639eb..573786c00 100644 --- a/node/node.go +++ b/node/node.go @@ -499,10 +499,6 @@ func (node *Node) validateNodeMessage(ctx context.Context, payload []byte) ( utils.Logger().Debug().Uint64("receivedNum", block.NumberU64()). Uint64("currentNum", curBeaconHeight).Msg("beacon block sync message rejected") return nil, 0, errors.New("beacon block height smaller than current height beyond tolerance") - } else if block.NumberU64()-beaconBlockHeightTolerance > curBeaconHeight { - utils.Logger().Debug().Uint64("receivedNum", block.NumberU64()). - Uint64("currentNum", curBeaconHeight).Msg("beacon block sync message rejected") - return nil, 0, errors.Errorf("beacon block height too much higher than current height beyond tolerance, block %d, current %d, epoch %d , current %d", block.NumberU64(), curBeaconHeight, block.Epoch().Uint64(), curBeaconBlock.Epoch().Uint64()) } else if block.NumberU64() <= curBeaconHeight { utils.Logger().Debug().Uint64("receivedNum", block.NumberU64()). Uint64("currentNum", curBeaconHeight).Msg("beacon block sync message ignored") diff --git a/node/node_handler.go b/node/node_handler.go index eeaf90f2d..c5feeed07 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -76,8 +76,6 @@ func (node *Node) HandleNodeMessage( if node.Blockchain().ShardID() != shard.BeaconChainShardID { for _, block := range blocks { if block.ShardID() == 0 { - utils.Logger().Info(). - Msgf("Beacon block being handled by block channel: %d", block.NumberU64()) if block.IsLastBlockInEpoch() { go func(blk *types.Block) { node.BeaconBlockChannel <- blk diff --git a/node/node_syncing.go b/node/node_syncing.go index 830df25c0..5319827ff 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -231,7 +231,16 @@ func (node *Node) doBeaconSyncing() { // If Downloader is not working, we need also deal with blocks from beaconBlockChannel go func(node *Node) { // TODO ek – infinite loop; add shutdown/cleanup logic - for _ = range node.BeaconBlockChannel { + for b := range node.BeaconBlockChannel { + if b != nil && b.IsLastBlockInEpoch() { + _, err := node.EpochChain().InsertChain(types.Blocks{b}, true) + if err != nil { + utils.Logger().Error().Err(err).Msgf("[SYNC] InsertChain failed shard: %d epoch:%d number:%d", b.Header().ShardID(), b.Epoch().Uint64(), b.NumberU64()) + } else { + utils.Logger().Info(). + Msgf("Beacon block being handled by block channel: epoch: %d, number: %d", b.Epoch().Uint64(), b.NumberU64()) + } + } } }(node) } From f9934683252e42d73e1cd6f71e82f687a456999b Mon Sep 17 00:00:00 2001 From: Diego Nava <8563843+diego1q2w@users.noreply.github.com> Date: Wed, 29 Nov 2023 22:35:36 +0100 Subject: [PATCH 2/3] fix: max-rate bellow the era min-rate (#4552) * fix: max-rate bellow the era min-rate * fix comments * add localnet epoch config * update config * update config * update config * update config --- internal/chain/engine.go | 8 ++++++++ internal/params/config.go | 19 +++++++++++++++++-- staking/availability/measure.go | 24 ++++++++++++++++++++++++ test/build-localnet-validator.sh | 4 ++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/internal/chain/engine.go b/internal/chain/engine.go index 4f3aac9ff..c77d86487 100644 --- a/internal/chain/engine.go +++ b/internal/chain/engine.go @@ -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, diff --git a/internal/params/config.go b/internal/params/config.go index 86695ba40..090e5599c 100644 --- a/internal/params/config.go +++ b/internal/params/config.go @@ -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. @@ -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. @@ -161,6 +163,7 @@ var ( ValidatorCodeFixEpoch: EpochTBD, HIP30Epoch: EpochTBD, BlockGas30MEpoch: big.NewInt(0), + MaxRateEpoch: EpochTBD, } // PartnerChainConfig contains the chain parameters for the Partner network. @@ -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. @@ -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. @@ -290,8 +295,9 @@ var ( LeaderRotationExternalValidatorsEpoch: big.NewInt(6), FeeCollectEpoch: big.NewInt(2), ValidatorCodeFixEpoch: big.NewInt(2), - HIP30Epoch: EpochTBD, + HIP30Epoch: big.NewInt(3), BlockGas30MEpoch: big.NewInt(0), + MaxRateEpoch: big.NewInt(4), } // AllProtocolChanges ... @@ -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 ... @@ -382,6 +389,7 @@ var ( big.NewInt(0), // ValidatorCodeFixEpoch big.NewInt(0), // HIP30Epoch big.NewInt(0), // BlockGas30M + big.NewInt(0), // MaxRateEpoch } // TestRules ... @@ -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. @@ -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 { diff --git a/staking/availability/measure.go b/staking/availability/measure.go index 881baa855..6bf36bfb0 100644 --- a/staking/availability/measure.go +++ b/staking/availability/measure.go @@ -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 +} diff --git a/test/build-localnet-validator.sh b/test/build-localnet-validator.sh index 08d987777..70501c8d6 100644 --- a/test/build-localnet-validator.sh +++ b/test/build-localnet-validator.sh @@ -32,7 +32,7 @@ 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 \ @@ -40,7 +40,7 @@ hmy --node="http://localhost:9500" staking create-validator \ --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 \ From 7be2b0260bdfb6e98397f923ad441b65b79367ca Mon Sep 17 00:00:00 2001 From: Konstantin <355847+Frozen@users.noreply.github.com> Date: Fri, 1 Dec 2023 21:19:57 -0400 Subject: [PATCH 3/3] Revert "fix: max-rate bellow the era min-rate (#4552)" (#4578) This reverts commit f9934683252e42d73e1cd6f71e82f687a456999b. --- internal/chain/engine.go | 8 -------- internal/params/config.go | 19 ++----------------- staking/availability/measure.go | 24 ------------------------ test/build-localnet-validator.sh | 4 ++-- 4 files changed, 4 insertions(+), 51 deletions(-) diff --git a/internal/chain/engine.go b/internal/chain/engine.go index c77d86487..4f3aac9ff 100644 --- a/internal/chain/engine.go +++ b/internal/chain/engine.go @@ -448,14 +448,6 @@ 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, diff --git a/internal/params/config.go b/internal/params/config.go index 090e5599c..86695ba40 100644 --- a/internal/params/config.go +++ b/internal/params/config.go @@ -75,7 +75,6 @@ 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. @@ -119,7 +118,6 @@ 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. @@ -163,7 +161,6 @@ var ( ValidatorCodeFixEpoch: EpochTBD, HIP30Epoch: EpochTBD, BlockGas30MEpoch: big.NewInt(0), - MaxRateEpoch: EpochTBD, } // PartnerChainConfig contains the chain parameters for the Partner network. @@ -208,7 +205,6 @@ 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. @@ -253,7 +249,6 @@ var ( ValidatorCodeFixEpoch: EpochTBD, HIP30Epoch: EpochTBD, BlockGas30MEpoch: big.NewInt(0), - MaxRateEpoch: EpochTBD, } // LocalnetChainConfig contains the chain parameters to run for local development. @@ -295,9 +290,8 @@ var ( LeaderRotationExternalValidatorsEpoch: big.NewInt(6), FeeCollectEpoch: big.NewInt(2), ValidatorCodeFixEpoch: big.NewInt(2), - HIP30Epoch: big.NewInt(3), + HIP30Epoch: EpochTBD, BlockGas30MEpoch: big.NewInt(0), - MaxRateEpoch: big.NewInt(4), } // AllProtocolChanges ... @@ -342,8 +336,7 @@ var ( big.NewInt(0), // FeeCollectEpoch big.NewInt(0), // ValidatorCodeFixEpoch big.NewInt(0), // BlockGas30M - big.NewInt(0), // BlockGas30M - big.NewInt(0), // MaxRateEpoch + big.NewInt(0), // HIP30Epoch } // TestChainConfig ... @@ -389,7 +382,6 @@ var ( big.NewInt(0), // ValidatorCodeFixEpoch big.NewInt(0), // HIP30Epoch big.NewInt(0), // BlockGas30M - big.NewInt(0), // MaxRateEpoch } // TestRules ... @@ -555,9 +547,6 @@ 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. @@ -814,10 +803,6 @@ 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 { diff --git a/staking/availability/measure.go b/staking/availability/measure.go index 6bf36bfb0..881baa855 100644 --- a/staking/availability/measure.go +++ b/staking/availability/measure.go @@ -267,27 +267,3 @@ 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 -} diff --git a/test/build-localnet-validator.sh b/test/build-localnet-validator.sh index 70501c8d6..08d987777 100644 --- a/test/build-localnet-validator.sh +++ b/test/build-localnet-validator.sh @@ -32,7 +32,7 @@ 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.01 --max-rate 0.01 --rate 0.01 \ + --max-change-rate 0.1 --max-rate 0.1 --rate 0.1 \ --max-total-delegation 100000000 --min-self-delegation 10000 --bls-pubkeys-dir .hmy/extbls/ hmy --node="http://localhost:9500" staking create-validator \ @@ -40,7 +40,7 @@ hmy --node="http://localhost:9500" staking create-validator \ --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.05 \ + --max-change-rate 0.1 --max-rate 0.1 --rate 0.1 \ --max-total-delegation 100000000 --min-self-delegation 10000 --bls-pubkeys-dir .hmy/extbls/ hmy --node="http://localhost:9500" staking create-validator \