bsc硬分叉升级
1.设置创世区块hash
var (
OSCGenesisHash = common.HexToHash("0x1c6ff34b83c5fbdddbd1103e4e60b741b5b227c2a1f4d11b897b57a98afa2248")
)
2.修改chainconfig
本次设置了一个UpgradeOne升级,
升级的区块是UpgradeOneBlock==22
升级的时间戳是UpgradeOneTime=1754323200
params/config
type ChainConfig struct {
UpgradeOneTime *uint64 `json:"upgradeOneTime,omitempty"` // UpgradeOne switch time (nil = no fork, 0 = already on upgradeOne)
UpgradeOneBlock *big.Int `json:"upgradeOneBlock,omitempty"` // upgradeOneBlock switch block (nil = no fork, 0 = already activated)
}
OSCChainConfig = &ChainConfig{
UpgradeOneBlock: big.NewInt(22),
UpgradeOneTime: newUint64(1754323200), // 2025-08-5 00:00:00 AM UTC
}
3. 增加升级检查
// IsOnVerkle returns whether currentBlockTime is either equal to the Verkle fork time or greater firstly.
func (c *ChainConfig) IsUpgradeOne(num *big.Int, time uint64) bool {
return isBlockForked(c.UpgradeOneBlock, num) && isTimestampForked(c.UpgradeOneTime, time)
}
4. rules也带上实现
目前不知道干啥用
type Rules struct {
ChainID *big.Int
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsEIP2929, IsEIP4762 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon bool
IsMerge bool
IsNano bool
IsMoran bool
IsPlanck bool
IsLuban bool
IsPlato bool
IsHertz bool
IsHertzfix bool
IsShanghai, IsKepler, IsFeynman, IsCancun, IsHaber bool
IsBohr, IsPascal, IsPrague, IsLorentz, IsMaxwell bool
IsOsaka, IsVerkle, IsUpgradeOne bool
}
// Rules ensures c's ChainID is not nil.
func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules {
chainID := c.ChainID
if chainID == nil {
chainID = new(big.Int)
}
// disallow setting Merge out of order
isMerge = isMerge && c.IsLondon(num)
isVerkle := isMerge && c.IsVerkle(num, timestamp)
return Rules{
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsEIP150: c.IsEIP150(num),
IsEIP155: c.IsEIP155(num),
IsEIP158: c.IsEIP158(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
IsEIP2929: c.IsBerlin(num) && !isVerkle,
IsLondon: c.IsLondon(num),
IsMerge: isMerge,
IsNano: c.IsNano(num),
IsMoran: c.IsMoran(num),
IsPlanck: c.IsPlanck(num),
IsLuban: c.IsLuban(num),
IsPlato: c.IsPlato(num),
IsHertz: c.IsHertz(num),
IsHertzfix: c.IsHertzfix(num),
IsShanghai: c.IsShanghai(num, timestamp),
IsKepler: c.IsKepler(num, timestamp),
IsFeynman: c.IsFeynman(num, timestamp),
IsCancun: c.IsCancun(num, timestamp),
IsHaber: c.IsHaber(num, timestamp),
IsBohr: c.IsBohr(num, timestamp),
IsPascal: c.IsPascal(num, timestamp),
IsPrague: c.IsPrague(num, timestamp),
IsOsaka: c.IsOsaka(num, timestamp),
IsLorentz: c.IsLorentz(num, timestamp),
IsMaxwell: c.IsMaxwell(num, timestamp),
IsVerkle: c.IsVerkle(num, timestamp),
IsEIP4762: isVerkle,
IsUpgradeOne: c.IsUpgradeOne(num, timestamp),
}
}
5. snapshot调用更新
consensus/parlia
func (s *Snapshot) apply(headers []*types.Header, chain consensus.ChainHeaderReader, parents []*types.Header, chainConfig *params.ChainConfig) (*Snapshot, error) {
// Iterate through the headers and create a new snapshot
snap := s.copy()
for _, header := range headers {
number := header.Number.Uint64()
if chainConfig.IsMaxwell(header.Number, header.Time) {
snap.BlockInterval = maxwellBlockInterval
} else if chainConfig.IsLorentz(header.Number, header.Time) {
snap.BlockInterval = lorentzBlockInterval
}
if chainConfig.IsUpgradeOne(header.Number, header.Time) {
snap.BlockInterval = defaultBlockInterval
}
}

浙公网安备 33010602011771号