core, consensus: use slice.Clip capacity to Simplify code (#1892)

This commit is contained in:
wit liu 2026-01-05 14:46:20 +08:00 committed by GitHub
parent fb89c95640
commit 2855f1b48c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View file

@ -580,7 +580,7 @@ func (api *API) getRewardFileNamesInRange(begin, end *rpc.BlockNumber) ([]reward
// compact the slice's memory // compact the slice's memory
ret := rewardFileNames[startIndex:endIndex] ret := rewardFileNames[startIndex:endIndex]
return ret[:len(ret):len(ret)], nil return slices.Clip(ret), nil
} }
func getEpochReward(account common.Address, header *types.Header) (AccountEpochReward, error) { func getEpochReward(account common.Address, header *types.Header) (AccountEpochReward, error) {

View file

@ -19,6 +19,7 @@ package vm
import ( import (
"errors" "errors"
"math/big" "math/big"
"slices"
"sync/atomic" "sync/atomic"
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate" "github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
@ -170,20 +171,20 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStat
default: default:
evm.table = &frontierInstructionSet evm.table = &frontierInstructionSet
} }
var extraEips []int
if len(evm.Config.ExtraEips) > 0 { if len(evm.Config.ExtraEips) > 0 {
// Deep-copy jumptable to prevent modification of opcodes in other tables // Deep-copy jumptable to prevent modification of opcodes in other tables
evm.table = copyJumpTable(evm.table) evm.table = copyJumpTable(evm.table)
} for _, eip := range evm.Config.ExtraEips {
extraEips := make([]int, 0, len(evm.Config.ExtraEips)) if err := EnableEIP(eip, evm.table); err != nil {
for _, eip := range evm.Config.ExtraEips { // Disable it, so caller can check if it's activated or not
if err := EnableEIP(eip, evm.table); err != nil { log.Error("EIP activation failed", "eip", eip, "error", err)
// Disable it, so caller can check if it's activated or not } else {
log.Error("EIP activation failed", "eip", eip, "error", err) extraEips = append(extraEips, eip)
} else { }
extraEips = append(extraEips, eip)
} }
} }
evm.Config.ExtraEips = extraEips[0:len(extraEips):len(extraEips)] evm.Config.ExtraEips = slices.Clip(extraEips)
return evm return evm
} }