From 968fb0124bc6a99d02179a4ce6f285284a8043d3 Mon Sep 17 00:00:00 2001 From: wgr523 Date: Sat, 20 Sep 2025 04:43:31 +0800 Subject: [PATCH] style: change limitPenaltyEpoch in config to real meaning, avoid +1 (#1538) --- eth/hooks/engine_v2_hooks.go | 11 ++++++++--- params/config.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/eth/hooks/engine_v2_hooks.go b/eth/hooks/engine_v2_hooks.go index 63d1af53b3..5a1c2f68fb 100644 --- a/eth/hooks/engine_v2_hooks.go +++ b/eth/hooks/engine_v2_hooks.go @@ -182,13 +182,18 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf } } } else { // after penalty upgrade - comebackHeight := (uint64(currentConfig.LimitPenaltyEpoch)+1)*chain.Config().XDPoS.Epoch + chain.Config().XDPoS.V2.SwitchBlock.Uint64() + limitPenaltyEpoch := 1 + if currentConfig.LimitPenaltyEpoch > 0 { + // if non-zero parameter, use it + limitPenaltyEpoch = currentConfig.LimitPenaltyEpoch + } + comebackHeight := uint64(limitPenaltyEpoch)*chain.Config().XDPoS.Epoch + chain.Config().XDPoS.V2.SwitchBlock.Uint64() if number.Uint64() > comebackHeight { // penParolees record those who stayed enough epoch of LimitPenaltyEpoch penParoleeMap := map[common.Address]int{} // lastPenalty record the last epoch penalties lastPenalty := []common.Address{} - for i := 0; i <= currentConfig.LimitPenaltyEpoch; i++ { + for i := 0; i < limitPenaltyEpoch; i++ { pens := adaptor.EngineV2.GetPreviousPenaltyByHash(chain, currentHash, i) for _, p := range pens { penParoleeMap[p]++ @@ -230,7 +235,7 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf } // check addr in lastPenalty, and if they does not meet condition, add them to penalty for _, p := range lastPenalty { - if penParoleeMap[p] == currentConfig.LimitPenaltyEpoch+1 { + if penParoleeMap[p] == limitPenaltyEpoch { // check if this node signs enough if txSignerMap[p] >= currentConfig.MinimumSigningTx { continue diff --git a/params/config.go b/params/config.go index e4a31e0e81..7234c13da8 100644 --- a/params/config.go +++ b/params/config.go @@ -217,7 +217,7 @@ var ( MasternodeReward: 500, // double as Reward ProtectorReward: 400, ObserverReward: 300.125, - LimitPenaltyEpoch: 1, + LimitPenaltyEpoch: 2, MinimumSigningTx: 2, }, }