Skip to content

Commit

Permalink
chainconfig: use cancun fork for BSC;
Browse files Browse the repository at this point in the history
feat: fill WithdrawalsHash when BSC enable cancun fork;
  • Loading branch information
galaio committed Feb 22, 2024
1 parent b2f6a56 commit 8a6f979
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
25 changes: 18 additions & 7 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,24 @@ func (p *Parlia) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
}
// Verify the existence / non-existence of excessBlobGas
cancun := chain.Config().IsCancun(header.Number, header.Time)
if !cancun && header.ExcessBlobGas != nil {
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
}
if !cancun && header.BlobGasUsed != nil {
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
}
if cancun {
if !cancun {
switch {
case header.ExcessBlobGas != nil:
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
case header.BlobGasUsed != nil:
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
case header.WithdrawalsHash != nil:
return fmt.Errorf("invalid WithdrawalsHash, have %#x, expected nil", header.WithdrawalsHash)
}
} else {
switch {
case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
case *header.WithdrawalsHash != common.Hash{}:
return errors.New("header has wrong WithdrawalsHash")
}
if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
header.ExcessBlobGas = &excessBlobGas
header.BlobGasUsed = new(uint64)
header.ParentBeaconRoot = new(common.Hash)
if cm.config.Parlia != nil {
header.WithdrawalsHash = new(common.Hash)
}
}
return header
}
Expand Down
3 changes: 3 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ func (g *Genesis) ToBlock() *types.Block {
if head.BlobGasUsed == nil {
head.BlobGasUsed = new(uint64)
}
if conf.Parlia != nil {
head.WithdrawalsHash = new(common.Hash)
}
}
}
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals)
Expand Down
3 changes: 3 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
header.BlobGasUsed = new(uint64)
header.ExcessBlobGas = &excessBlobGas
header.ParentBeaconRoot = genParams.beaconRoot
if w.chainConfig.Parlia != nil {
header.WithdrawalsHash = new(common.Hash)
}
}
// Run the consensus preparation with the default or customized consensus engine.
if err := w.engine.Prepare(w.chain, header); err != nil {
Expand Down
15 changes: 13 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ var (
// UnixTime: 1705996800 is January 23, 2024 8:00:00 AM UTC
ShanghaiTime: newUint64(1705996800),
KeplerTime: newUint64(1705996800),
// TODO(GalaIO): enable cancun fork time later
//CancunTime: newUint64(),

Parlia: &ParliaConfig{
Period: 3,
Expand Down Expand Up @@ -185,6 +187,8 @@ var (
// UnixTime: 1702972800 is December 19, 2023 8:00:00 AM UTC
ShanghaiTime: newUint64(1702972800),
KeplerTime: newUint64(1702972800),
// TODO(GalaIO): enable cancun fork time later
//CancunTime: newUint64(),

Parlia: &ParliaConfig{
Period: 3,
Expand Down Expand Up @@ -221,6 +225,7 @@ var (
HertzfixBlock: big.NewInt(8),
ShanghaiTime: newUint64(0),
KeplerTime: newUint64(0),
CancunTime: newUint64(0),

Parlia: &ParliaConfig{
Period: 3,
Expand Down Expand Up @@ -578,7 +583,12 @@ func (c *ChainConfig) String() string {
KeplerTime = big.NewInt(0).SetUint64(*c.KeplerTime)
}

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, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime: %v, Engine: %v}",
var CancunTime *big.Int
if c.CancunTime != nil {
CancunTime = big.NewInt(0).SetUint64(*c.CancunTime)
}

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, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Hertzfix: %v, ShanghaiTime: %v, KeplerTime: %v, CancunTime: %v, Engine: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand Down Expand Up @@ -612,6 +622,7 @@ func (c *ChainConfig) String() string {
c.HertzfixBlock,
ShanghaiTime,
KeplerTime,
CancunTime,
engine,
)
}
Expand Down Expand Up @@ -911,7 +922,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "hertzBlock", block: c.HertzBlock},
{name: "hertzfixBlock", block: c.HertzfixBlock},
{name: "keplerTime", timestamp: c.KeplerTime},
{name: "cancunTime", timestamp: c.CancunTime, optional: true},
{name: "cancunTime", timestamp: c.CancunTime},
{name: "pragueTime", timestamp: c.PragueTime, optional: true},
{name: "verkleTime", timestamp: c.VerkleTime, optional: true},
} {
Expand Down

0 comments on commit 8a6f979

Please sign in to comment.