Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
temaniarpit27 committed Nov 3, 2023
2 parents 2cb1ee4 + bc338be commit 1483c96
Show file tree
Hide file tree
Showing 32 changed files with 211 additions and 93 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
Expand Down
6 changes: 3 additions & 3 deletions builder/files/genesis-testnet-v4.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/evm/testdata/5/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
These files exemplify a transition where there are no transactions, two ommers, at block `N-1` (delta 1) and `N-2` (delta 2).
These files exemplify a transition where there are no transactions, two ommers, at block `N-1` (delta 1) and `N-2` (delta 2).
23 changes: 8 additions & 15 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,14 @@ func (c *Bor) verifyHeader(chain consensus.ChainHeaderReader, header *types.Head

// Verify that the gas limit is <= 2^63-1
gasCap := uint64(0x7fffffffffffffff)

if header.GasLimit > gasCap {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, gasCap)
}

if header.WithdrawalsHash != nil {
return consensus.ErrUnexpectedWithdrawals
}

// All basic checks passed, verify cascading fields
return c.verifyCascadingFields(chain, header, parents)
}
Expand Down Expand Up @@ -817,13 +820,7 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,

headerNumber := header.Number.Uint64()

if len(withdrawals) > 0 {
log.Error("Bor does not support withdrawals", "number", headerNumber)
return
}

if header.WithdrawalsHash != nil {
log.Error("Bor does not support withdrawalHash", "number", headerNumber)
if withdrawals != nil || header.WithdrawalsHash != nil {
return
}

Expand Down Expand Up @@ -899,18 +896,14 @@ 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 header.WithdrawalsHash != nil {
return nil, errors.New("Bor does not support withdrawalHash")
if withdrawals != nil || header.WithdrawalsHash != nil {
return nil, consensus.ErrUnexpectedWithdrawals
}

stateSyncData := []*types.StateSyncData{}

headerNumber := header.Number.Uint64()

var err error

if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) {
Expand Down
7 changes: 6 additions & 1 deletion consensus/bor/statefull/processor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package statefull

import (
"bytes"
"context"
"math"
"math/big"
Expand Down Expand Up @@ -90,7 +91,11 @@ func ApplyMessage(

success := big.NewInt(5).SetBytes(ret)

if success.Cmp(big.NewInt(0)) == 0 {
validatorContract := common.HexToAddress(chainConfig.Bor.ValidatorContract)

// if success == 0 and msg.To() != validatorContractAddress, log Error
// if msg.To() == validatorContractAddress, its committing a span and we don't get any return value
if success.Cmp(big.NewInt(0)) == 0 && !bytes.Equal(msg.To().Bytes(), validatorContract.Bytes()) {
log.Error("message execution failed on contract", "msgData", msg.Data)
}

Expand Down
3 changes: 3 additions & 0 deletions consensus/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ var (
// ErrInvalidTerminalBlock is returned if a block is invalid wrt. the terminal
// total difficulty.
ErrInvalidTerminalBlock = errors.New("invalid terminal block")

// ErrUnexpectedWithdrawals is returned if a pre-Shanghai block has withdrawals.
ErrUnexpectedWithdrawals = errors.New("unexpected withdrawals")
)
4 changes: 3 additions & 1 deletion core/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"bytes"
"errors"
"math/big"

Expand Down Expand Up @@ -114,7 +115,8 @@ func (f *ForkChoice) ReorgNeeded(current *types.Header, extern *types.Header) (b
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern)
}

reorg = !currentPreserve && (externPreserve || f.rand.Float64() < 0.5)
// Compare hashes of block in case of tie breaker. Lexicographically larger hash wins.
reorg = !currentPreserve && (externPreserve || bytes.Compare(current.Hash().Bytes(), extern.Hash().Bytes()) < 0)
}

return reorg, nil
Expand Down
56 changes: 56 additions & 0 deletions core/forkchoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"

"github.com/stretchr/testify/require"
)

// chainValidatorFake is a mock for the chain validator service
Expand All @@ -30,6 +32,60 @@ func newChainReaderFake(getTd func(hash common.Hash, number uint64) *big.Int) *c
return &chainReaderFake{getTd: getTd}
}

// nolint: tparallel
func TestForkChoice(t *testing.T) {
t.Parallel()

// Create mocks for forker
getTd := func(hash common.Hash, number uint64) *big.Int {
if number <= 2 {
return big.NewInt(int64(number))
}

return big.NewInt(0)
}
mockChainReader := newChainReaderFake(getTd)
mockForker := NewForkChoice(mockChainReader, nil, nil)

createHeader := func(number int64, extra []byte) *types.Header {
return &types.Header{
Number: big.NewInt(number),
Extra: extra,
}
}

// Create headers for different cases
headerA := createHeader(1, []byte("A"))
headerB := createHeader(2, []byte("B"))
headerC := createHeader(3, []byte("C"))
headerD := createHeader(4, []byte("D")) // 0x96b0f70c01f4d2b1ee2df5b0202c099776f24c9375ffc89d94b880007633961b (hash)
headerE := createHeader(4, []byte("E")) // 0xdc0acf54354ff86194baeaab983098a49a40218cffcc77a583726fc06c429685 (hash)

testCases := []struct {
name string
current *types.Header
incoming *types.Header
want bool
}{
{"tdd(incoming) > tdd(current)", headerA, headerB, true},
{"tdd(current) > tdd(incoming)", headerB, headerA, false},
{"tdd(current) = tdd(incoming), number(incoming) > number(current)", headerC, headerD, false},
{"tdd(current) = tdd(incoming), number(current) > number(incoming)", headerD, headerC, true},
{"tdd(current) = tdd(incoming), number(current) = number(incoming), hash(current) > hash(incoming)", headerE, headerD, false},
{"tdd(current) = tdd(incoming), number(current) = number(incoming), hash(incoming) > hash(current)", headerD, headerE, true},
}

// nolint: paralleltest
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
res, err := mockForker.ReorgNeeded(tc.current, tc.incoming)
require.Equal(t, tc.want, res, tc.name)
require.NoError(t, err, tc.name)
})
}
}

func TestPastChainInsert(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ func (g *Genesis) ToBlock() *types.Block {
if conf := g.Config; conf != nil {
num := big.NewInt(int64(g.Number))
if conf.IsShanghai(num) {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = make([]*types.Withdrawal, 0)
head.WithdrawalsHash = nil
withdrawals = nil
}
if conf.IsCancun(num) {
head.ExcessBlobGas = g.ExcessBlobGas
Expand Down
9 changes: 6 additions & 3 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package core

import (
"context"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -103,8 +102,12 @@ 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()) {
return nil, nil, 0, errors.New("withdrawals before shanghai")
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)
Expand Down
15 changes: 9 additions & 6 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ func newShanghaiInstructionSet() JumpTable {

func newMergeInstructionSet() JumpTable {
instructionSet := newLondonInstructionSet()
instructionSet[PREVRANDAO] = &operation{
execute: opRandom,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
}

// disabling in pos due to incompatibility with prevrandao

// instructionSet[PREVRANDAO] = &operation{
// execute: opRandom,
// constantGas: GasQuickStep,
// minStack: minStack(0, 1),
// maxStack: maxStack(0, 1),
// }

return validate(instructionSet)
}
Expand Down
6 changes: 6 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
// Pending block is only known by the miner
if number == rpc.PendingBlockNumber {
block := b.eth.miner.PendingBlock()
if block == nil {
return nil, errors.New("pending block is not available")
}
return block.Header(), nil
}
// Otherwise resolve and return the block
Expand Down Expand Up @@ -136,6 +139,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
// Pending block is only known by the miner
if number == rpc.PendingBlockNumber {
block := b.eth.miner.PendingBlock()
if block == nil {
return nil, errors.New("pending block is not available")
}
return block, nil
}
// Otherwise resolve and return the block
Expand Down
6 changes: 1 addition & 5 deletions eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,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{})
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/cli/server/chains/mumbai.go

Large diffs are not rendered by default.

Loading

0 comments on commit 1483c96

Please sign in to comment.