Skip to content

Commit

Permalink
update hardfork info
Browse files Browse the repository at this point in the history
  • Loading branch information
qinglin89 committed Mar 1, 2023
1 parent 48035d2 commit f5ddf27
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
17 changes: 8 additions & 9 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ func (p *Parlia) backOffTime(snap *Snapshot, header *types.Header, val common.Ad
n := len(snap.Validators)
backOffSteps := make([]uint64, 0, n)

if !p.chainConfig.IsTmpSlash(header.Number) {
if !p.chainConfig.IsBohr(header.Number) {
for i := uint64(0); i < uint64(n); i++ {
backOffSteps = append(backOffSteps, i)
}
Expand All @@ -1305,17 +1305,16 @@ func (p *Parlia) backOffTime(snap *Snapshot, header *types.Header, val common.Ad
delay := initialBackOffTime + backOffSteps[idx]*wiggleTime
return delay
}

// Exclude the recently signed validators first, and then compute the backOffTime.
recentVals := make(map[common.Address]bool, len(snap.Recents))
limit := len(snap.Validators)
for seen, recent := range snap.Recents {
if header.Number.Uint64() < uint64(limit) || seen > header.Number.Uint64()-uint64(limit) {
if val == recent {
// The backOffTime does not matter when a validator has signed recently.
return 0
}
recentVals[recent] = true
//for seen, recent := range snap.Recents {
for _, recent := range snap.Recents {
if val == recent {
// The backOffTime does not matter when a validator has signed recently.
return 0
}
recentVals[recent] = true
}

backOffIndex := idx
Expand Down
22 changes: 18 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ var (
NanoBlock: big.NewInt(21962149),
MoranBlock: big.NewInt(22107423),
GibbsBlock: big.NewInt(23846001),
BohrBlock: nil,

Parlia: &ParliaConfig{
Period: 3,
Expand All @@ -325,6 +326,7 @@ var (
GibbsBlock: big.NewInt(22800220),
NanoBlock: big.NewInt(23482428),
MoranBlock: big.NewInt(23603940),
BohrBlock: nil,
Parlia: &ParliaConfig{
Period: 3,
Epoch: 200,
Expand All @@ -350,6 +352,7 @@ var (
GibbsBlock: big.NewInt(400),
NanoBlock: nil,
MoranBlock: nil,
BohrBlock: nil,

Parlia: &ParliaConfig{
Period: 3,
Expand Down Expand Up @@ -497,7 +500,7 @@ type ChainConfig struct {
GibbsBlock *big.Int `json:"gibbsBlock,omitempty" toml:",omitempty"` // gibbsBlock switch block (nil = no fork, 0 = already activated)
NanoBlock *big.Int `json:"nanoBlock,omitempty" toml:",omitempty"` // nanoBlock switch block (nil = no fork, 0 = already activated)
MoranBlock *big.Int `json:"moranBlock,omitempty" toml:",omitempty"` // moranBlock switch block (nil = no fork, 0 = already activated)
TmpslashBlock *big.Int `json:"tmpslashBlock,omitempty" toml:",omitempty"` // tmpslashBlock switch block (nil = no fork, 0 = already activated)
BohrBlock *big.Int `json:"BohrBlock,omitempty" toml:",omitempty"` // BohrBlock switch block (nil = no fork, 0 = already activated)

// Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty" toml:",omitempty"`
Expand Down Expand Up @@ -548,7 +551,7 @@ func (c *ChainConfig) String() string {
default:
engine = "unknown"
}
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Engine: %v}",
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Bohr: %v, Engine: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand All @@ -575,6 +578,7 @@ func (c *ChainConfig) String() string {
c.GibbsBlock,
c.NanoBlock,
c.MoranBlock,
c.BohrBlock,
engine,
)
}
Expand Down Expand Up @@ -730,8 +734,12 @@ func (c *ChainConfig) IsOnMoran(num *big.Int) bool {
return configNumEqual(c.MoranBlock, num)
}

func (c *ChainConfig) IsTmpSlash(num *big.Int) bool {
return configNumEqual(c.TmpslashBlock, num)
func (c *ChainConfig) IsBohr(num *big.Int) bool {
return isForked(c.BohrBlock, num)
}

func (c *ChainConfig) IsOnBohr(num *big.Int) bool {
return configNumEqual(c.BohrBlock, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
Expand Down Expand Up @@ -862,6 +870,10 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.MoranBlock, newcfg.MoranBlock, head) {
return newCompatError("moran fork block", c.MoranBlock, newcfg.MoranBlock)
}
if isForkIncompatible(c.BohrBlock, newcfg.BohrBlock, head) {
return newCompatError("bohr fork block", c.BohrBlock, newcfg.BohrBlock)
}

return nil
}

Expand Down Expand Up @@ -933,6 +945,7 @@ type Rules struct {
IsMerge bool
IsNano bool
IsMoran bool
IsBohr bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -956,5 +969,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool) Rules {
IsMerge: isMerge,
IsNano: c.IsNano(num),
IsMoran: c.IsMoran(num),
IsBohr: c.IsBohr(num),
}
}

0 comments on commit f5ddf27

Please sign in to comment.