From 9f4457958de15a38dcc5ed503259bc751fd005cb Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 20 Oct 2023 15:05:41 +0530 Subject: [PATCH 1/4] bor: make withdrawals nil --- consensus/bor/bor.go | 16 ++++++++-------- core/genesis.go | 4 ++-- core/state_processor.go | 6 +++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index d1a9b9f2b2..9ecd7d17ca 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -816,14 +816,14 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header, headerNumber := header.Number.Uint64() - if len(withdrawals) > 0 { + if withdrawals != nil { + withdrawals = nil log.Error("Bor does not support withdrawals", "number", headerNumber) - return } if header.WithdrawalsHash != nil { + header.WithdrawalsHash = nil log.Error("Bor does not support withdrawalHash", "number", headerNumber) - return } if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { @@ -898,18 +898,18 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead finalizeCtx, finalizeSpan := tracing.StartSpan(ctx, "bor.FinalizeAndAssemble") defer tracing.EndSpan(finalizeSpan) - if len(withdrawals) > 0 { - return nil, errors.New("Bor does not support withdrawals") + headerNumber := header.Number.Uint64() + + if withdrawals != nil { + log.Error("Bor does not support withdrawals", "number", headerNumber) } if header.WithdrawalsHash != nil { - return nil, errors.New("Bor does not support withdrawalHash") + log.Error("Bor does not support withdrawalHash", "number", headerNumber) } stateSyncData := []*types.StateSyncData{} - headerNumber := header.Number.Uint64() - var err error if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { diff --git a/core/genesis.go b/core/genesis.go index b41d693ef7..06235986cc 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -529,8 +529,8 @@ func (g *Genesis) ToBlock() *types.Block { var withdrawals []*types.Withdrawal if g.Config != nil && g.Config.IsShanghai(new(big.Int).SetUint64(g.Number)) { - head.WithdrawalsHash = &types.EmptyWithdrawalsHash - withdrawals = make([]*types.Withdrawal, 0) + head.WithdrawalsHash = nil + withdrawals = nil } return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals) diff --git a/core/state_processor.go b/core/state_processor.go index fbd164f40f..4833919364 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -101,9 +101,13 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg } // Fail if Shanghai not enabled and len(withdrawals) is non-zero. withdrawals := block.Withdrawals() - if len(withdrawals) > 0 && !p.config.IsShanghai(block.Number()) { + if !p.config.IsShanghai(block.Number()) && withdrawals != nil { return nil, nil, 0, fmt.Errorf("withdrawals before shanghai") } + // Bor does not support withdrawals + if withdrawals != nil { + withdrawals = nil + } // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), withdrawals) From aff2f1fa7352e13c3fb42e4416d864f27533a736 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 20 Oct 2023 19:58:02 +0530 Subject: [PATCH 2/4] fix: linting --- consensus/bor/bor.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 9ecd7d17ca..80761ecba7 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -172,6 +172,12 @@ func encodeSigHeader(w io.Writer, header *types.Header, c *params.BorConfig) { } } + if header.WithdrawalsHash != nil { + header.WithdrawalsHash = nil + + log.Warn("Bor does not support withdrawals", "number", header.Number) + } + if err := rlp.Encode(w, enc); err != nil { panic("can't encode: " + err.Error()) } @@ -817,13 +823,14 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header, headerNumber := header.Number.Uint64() if withdrawals != nil { - withdrawals = nil - log.Error("Bor does not support withdrawals", "number", headerNumber) + // withdrawals = nil is not required because withdrawals are not used + log.Warn("Bor does not support withdrawals", "number", headerNumber) } if header.WithdrawalsHash != nil { header.WithdrawalsHash = nil - log.Error("Bor does not support withdrawalHash", "number", headerNumber) + + log.Warn("Bor does not support withdrawalHash", "number", headerNumber) } if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { @@ -901,11 +908,14 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead headerNumber := header.Number.Uint64() if withdrawals != nil { - log.Error("Bor does not support withdrawals", "number", headerNumber) + // withdrawals != nil not required because withdrawals are not used + log.Warn("Bor does not support withdrawals", "number", headerNumber) } if header.WithdrawalsHash != nil { - log.Error("Bor does not support withdrawalHash", "number", headerNumber) + header.WithdrawalsHash = nil + + log.Warn("Bor does not support withdrawalHash", "number", headerNumber) } stateSyncData := []*types.StateSyncData{} From a504fa6e2fb7245848493f4eeb60bc7d780f5fc5 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 20 Oct 2023 23:09:00 +0530 Subject: [PATCH 3/4] fix tests --- eth/protocols/eth/handler_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/eth/protocols/eth/handler_test.go b/eth/protocols/eth/handler_test.go index d1a252b7cf..c001ec07ce 100644 --- a/eth/protocols/eth/handler_test.go +++ b/eth/protocols/eth/handler_test.go @@ -367,11 +367,7 @@ func TestGetBlockBodies68(t *testing.T) { func testGetBlockBodies(t *testing.T, protocol uint) { gen := func(n int, g *core.BlockGen) { if n%2 == 0 { - w := &types.Withdrawal{ - Address: common.Address{0xaa}, - Amount: 42, - } - g.AddWithdrawal(w) + g.AddWithdrawal(&types.Withdrawal{}) } } From da5b880669dd55a796b903ccddb27107d96251e8 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Mon, 23 Oct 2023 12:12:27 +0530 Subject: [PATCH 4/4] chg: club error conditions --- consensus/bor/bor.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 80761ecba7..1dd630f755 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -822,15 +822,11 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header, headerNumber := header.Number.Uint64() - if withdrawals != nil { + if withdrawals != nil || header.WithdrawalsHash != nil { // withdrawals = nil is not required because withdrawals are not used - log.Warn("Bor does not support withdrawals", "number", headerNumber) - } - - if header.WithdrawalsHash != nil { header.WithdrawalsHash = nil - log.Warn("Bor does not support withdrawalHash", "number", headerNumber) + log.Warn("Bor does not support withdrawals", "number", headerNumber) } if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { @@ -907,15 +903,11 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead headerNumber := header.Number.Uint64() - if withdrawals != nil { + if withdrawals != nil || header.WithdrawalsHash != nil { // withdrawals != nil not required because withdrawals are not used - log.Warn("Bor does not support withdrawals", "number", headerNumber) - } - - if header.WithdrawalsHash != nil { header.WithdrawalsHash = nil - log.Warn("Bor does not support withdrawalHash", "number", headerNumber) + log.Warn("Bor does not support withdrawals", "number", headerNumber) } stateSyncData := []*types.StateSyncData{}