merge develop

This commit is contained in:
Arpit Temani 2023-11-03 10:10:02 +05:30
commit 1483c960ed
32 changed files with 214 additions and 96 deletions

View file

@ -27,6 +27,11 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v2 uses: github/codeql-action/init@v2
with: with:

File diff suppressed because one or more lines are too long

View file

@ -382,11 +382,14 @@ func (c *Bor) verifyHeader(chain consensus.ChainHeaderReader, header *types.Head
// Verify that the gas limit is <= 2^63-1 // Verify that the gas limit is <= 2^63-1
gasCap := uint64(0x7fffffffffffffff) gasCap := uint64(0x7fffffffffffffff)
if header.GasLimit > gasCap { if header.GasLimit > gasCap {
return fmt.Errorf("invalid gasLimit: have %v, max %v", 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 // All basic checks passed, verify cascading fields
return c.verifyCascadingFields(chain, header, parents) return c.verifyCascadingFields(chain, header, parents)
} }
@ -817,13 +820,7 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
headerNumber := header.Number.Uint64() headerNumber := header.Number.Uint64()
if len(withdrawals) > 0 { if withdrawals != nil || header.WithdrawalsHash != nil {
log.Error("Bor does not support withdrawals", "number", headerNumber)
return
}
if header.WithdrawalsHash != nil {
log.Error("Bor does not support withdrawalHash", "number", headerNumber)
return return
} }
@ -899,18 +896,14 @@ func (c *Bor) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHead
finalizeCtx, finalizeSpan := tracing.StartSpan(ctx, "bor.FinalizeAndAssemble") finalizeCtx, finalizeSpan := tracing.StartSpan(ctx, "bor.FinalizeAndAssemble")
defer tracing.EndSpan(finalizeSpan) defer tracing.EndSpan(finalizeSpan)
if len(withdrawals) > 0 { headerNumber := header.Number.Uint64()
return nil, errors.New("Bor does not support withdrawals")
}
if header.WithdrawalsHash != nil { if withdrawals != nil || header.WithdrawalsHash != nil {
return nil, errors.New("Bor does not support withdrawalHash") return nil, consensus.ErrUnexpectedWithdrawals
} }
stateSyncData := []*types.StateSyncData{} stateSyncData := []*types.StateSyncData{}
headerNumber := header.Number.Uint64()
var err error var err error
if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) { if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) {

View file

@ -1,6 +1,7 @@
package statefull package statefull
import ( import (
"bytes"
"context" "context"
"math" "math"
"math/big" "math/big"
@ -90,7 +91,11 @@ func ApplyMessage(
success := big.NewInt(5).SetBytes(ret) 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) log.Error("message execution failed on contract", "msgData", msg.Data)
} }

View file

@ -38,4 +38,7 @@ var (
// ErrInvalidTerminalBlock is returned if a block is invalid wrt. the terminal // ErrInvalidTerminalBlock is returned if a block is invalid wrt. the terminal
// total difficulty. // total difficulty.
ErrInvalidTerminalBlock = errors.New("invalid terminal block") ErrInvalidTerminalBlock = errors.New("invalid terminal block")
// ErrUnexpectedWithdrawals is returned if a pre-Shanghai block has withdrawals.
ErrUnexpectedWithdrawals = errors.New("unexpected withdrawals")
) )

View file

@ -17,6 +17,7 @@
package core package core
import ( import (
"bytes"
"errors" "errors"
"math/big" "math/big"
@ -114,7 +115,8 @@ func (f *ForkChoice) ReorgNeeded(current *types.Header, extern *types.Header) (b
currentPreserve, externPreserve = f.preserve(current), f.preserve(extern) 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 return reorg, nil

View file

@ -10,6 +10,8 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/stretchr/testify/require"
) )
// chainValidatorFake is a mock for the chain validator service // chainValidatorFake is a mock for the chain validator service
@ -30,6 +32,60 @@ func newChainReaderFake(getTd func(hash common.Hash, number uint64) *big.Int) *c
return &chainReaderFake{getTd: getTd} 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) { func TestPastChainInsert(t *testing.T) {
t.Parallel() t.Parallel()

View file

@ -527,8 +527,8 @@ func (g *Genesis) ToBlock() *types.Block {
if conf := g.Config; conf != nil { if conf := g.Config; conf != nil {
num := big.NewInt(int64(g.Number)) num := big.NewInt(int64(g.Number))
if conf.IsShanghai(num) { if conf.IsShanghai(num) {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash head.WithdrawalsHash = nil
withdrawals = make([]*types.Withdrawal, 0) withdrawals = nil
} }
if conf.IsCancun(num) { if conf.IsCancun(num) {
head.ExcessBlobGas = g.ExcessBlobGas head.ExcessBlobGas = g.ExcessBlobGas

View file

@ -18,7 +18,6 @@ package core
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"math/big" "math/big"
@ -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. // Fail if Shanghai not enabled and len(withdrawals) is non-zero.
withdrawals := block.Withdrawals() withdrawals := block.Withdrawals()
if len(withdrawals) > 0 && !p.config.IsShanghai(block.Number()) { if !p.config.IsShanghai(block.Number()) && withdrawals != nil {
return nil, nil, 0, errors.New("withdrawals before shanghai") 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) // 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) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), withdrawals)

View file

@ -100,12 +100,15 @@ func newShanghaiInstructionSet() JumpTable {
func newMergeInstructionSet() JumpTable { func newMergeInstructionSet() JumpTable {
instructionSet := newLondonInstructionSet() instructionSet := newLondonInstructionSet()
instructionSet[PREVRANDAO] = &operation{
execute: opRandom, // disabling in pos due to incompatibility with prevrandao
constantGas: GasQuickStep,
minStack: minStack(0, 1), // instructionSet[PREVRANDAO] = &operation{
maxStack: maxStack(0, 1), // execute: opRandom,
} // constantGas: GasQuickStep,
// minStack: minStack(0, 1),
// maxStack: maxStack(0, 1),
// }
return validate(instructionSet) return validate(instructionSet)
} }

View file

@ -68,6 +68,9 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
// Pending block is only known by the miner // Pending block is only known by the miner
if number == rpc.PendingBlockNumber { if number == rpc.PendingBlockNumber {
block := b.eth.miner.PendingBlock() block := b.eth.miner.PendingBlock()
if block == nil {
return nil, errors.New("pending block is not available")
}
return block.Header(), nil return block.Header(), nil
} }
// Otherwise resolve and return the block // Otherwise resolve and return the block
@ -136,6 +139,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
// Pending block is only known by the miner // Pending block is only known by the miner
if number == rpc.PendingBlockNumber { if number == rpc.PendingBlockNumber {
block := b.eth.miner.PendingBlock() block := b.eth.miner.PendingBlock()
if block == nil {
return nil, errors.New("pending block is not available")
}
return block, nil return block, nil
} }
// Otherwise resolve and return the block // Otherwise resolve and return the block

View file

@ -368,11 +368,7 @@ func TestGetBlockBodies68(t *testing.T) {
func testGetBlockBodies(t *testing.T, protocol uint) { func testGetBlockBodies(t *testing.T, protocol uint) {
gen := func(n int, g *core.BlockGen) { gen := func(n int, g *core.BlockGen) {
if n%2 == 0 { if n%2 == 0 {
w := &types.Withdrawal{ g.AddWithdrawal(&types.Withdrawal{})
Address: common.Address{0xaa},
Amount: 42,
}
g.AddWithdrawal(w)
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -41,6 +41,7 @@ func TestFlagsWithoutConfig(t *testing.T) {
require.Equal(t, c.config.Identity, "") require.Equal(t, c.config.Identity, "")
require.Equal(t, c.config.DataDir, "./data") require.Equal(t, c.config.DataDir, "./data")
require.Equal(t, c.config.KeyStoreDir, "")
require.Equal(t, c.config.Verbosity, 3) require.Equal(t, c.config.Verbosity, 3)
require.Equal(t, c.config.RPCBatchLimit, uint64(0)) require.Equal(t, c.config.RPCBatchLimit, uint64(0))
require.Equal(t, c.config.Snapshot, true) require.Equal(t, c.config.Snapshot, true)
@ -74,6 +75,7 @@ func TestFlagsWithConfig(t *testing.T) {
require.Equal(t, c.config.Identity, "") require.Equal(t, c.config.Identity, "")
require.Equal(t, c.config.DataDir, "./data") require.Equal(t, c.config.DataDir, "./data")
require.Equal(t, c.config.KeyStoreDir, "./keystore")
require.Equal(t, c.config.Verbosity, 3) require.Equal(t, c.config.Verbosity, 3)
require.Equal(t, c.config.RPCBatchLimit, uint64(0)) require.Equal(t, c.config.RPCBatchLimit, uint64(0))
require.Equal(t, c.config.Snapshot, true) require.Equal(t, c.config.Snapshot, true)
@ -105,6 +107,7 @@ func TestFlagsWithConfigAndFlags(t *testing.T) {
"--config", "./testdata/test.toml", "--config", "./testdata/test.toml",
"--identity", "Anon", "--identity", "Anon",
"--datadir", "", "--datadir", "",
"--keystore", "",
"--verbosity", "0", "--verbosity", "0",
"--rpc.batchlimit", "5", "--rpc.batchlimit", "5",
"--snapshot=false", "--snapshot=false",
@ -128,6 +131,7 @@ func TestFlagsWithConfigAndFlags(t *testing.T) {
require.Equal(t, c.config.Identity, "Anon") require.Equal(t, c.config.Identity, "Anon")
require.Equal(t, c.config.DataDir, "") require.Equal(t, c.config.DataDir, "")
require.Equal(t, c.config.KeyStoreDir, "")
require.Equal(t, c.config.Verbosity, 0) require.Equal(t, c.config.Verbosity, 0)
require.Equal(t, c.config.RPCBatchLimit, uint64(5)) require.Equal(t, c.config.RPCBatchLimit, uint64(5))
require.Equal(t, c.config.Snapshot, false) require.Equal(t, c.config.Snapshot, false)

View file

@ -604,6 +604,7 @@ func DefaultConfig() *Config {
DataDir: DefaultDataDir(), DataDir: DefaultDataDir(),
Ancient: "", Ancient: "",
DBEngine: "leveldb", DBEngine: "leveldb",
KeyStoreDir: "",
Logging: &LoggingConfig{ Logging: &LoggingConfig{
Vmodule: "", Vmodule: "",
Json: false, Json: false,

View file

@ -17,6 +17,7 @@ func TestConfigLegacy(t *testing.T) {
testConfig.Identity = "" testConfig.Identity = ""
testConfig.DataDir = "./data" testConfig.DataDir = "./data"
testConfig.KeyStoreDir = "./keystore"
testConfig.Verbosity = 3 testConfig.Verbosity = 3
testConfig.RPCBatchLimit = 0 testConfig.RPCBatchLimit = 0
testConfig.Snapshot = true testConfig.Snapshot = true

View file

@ -64,9 +64,10 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
Default: c.cliConfig.DBEngine, Default: c.cliConfig.DBEngine,
}) })
f.StringFlag(&flagset.StringFlag{ f.StringFlag(&flagset.StringFlag{
Name: "keystore", Name: "keystore",
Usage: "Path of the directory where keystores are located", Usage: "Path of the directory where keystores are located",
Value: &c.cliConfig.KeyStoreDir, Value: &c.cliConfig.KeyStoreDir,
Default: c.cliConfig.KeyStoreDir,
}) })
f.Uint64Flag(&flagset.Uint64Flag{ f.Uint64Flag(&flagset.Uint64Flag{
Name: "rpc.batchlimit", Name: "rpc.batchlimit",

View file

@ -1,5 +1,6 @@
identity = "" identity = ""
datadir = "./data" datadir = "./data"
keystore = "./keystore"
verbosity = 3 verbosity = 3
"rpc.batchlimit" = 0 "rpc.batchlimit" = 0
snapshot = true snapshot = true

View file

@ -74,7 +74,11 @@ func (api *BorAPI) SendRawTransactionConditional(ctx context.Context, input hexu
} }
currentHeader := api.b.CurrentHeader() currentHeader := api.b.CurrentHeader()
currentState, _, _ := api.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(currentHeader.Number.Int64())) currentState, _, err := api.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(currentHeader.Number.Int64()))
if currentState == nil || err != nil {
return common.Hash{}, err
}
// check block number range // check block number range
if err := currentHeader.ValidateBlockNumberOptions4337(options.BlockNumberMin, options.BlockNumberMax); err != nil { if err := currentHeader.ValidateBlockNumberOptions4337(options.BlockNumberMin, options.BlockNumberMax); err != nil {

View file

@ -1,5 +1,5 @@
Source: bor Source: bor
Version: 1.1.0 Version: 1.1.0-beta4
Section: develop Section: develop
Priority: standard Priority: standard
Maintainer: Polygon <release-team@polygon.technology> Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor Source: bor
Version: 1.1.0 Version: 1.1.0-beta4
Section: develop Section: develop
Priority: standard Priority: standard
Maintainer: Polygon <release-team@polygon.technology> Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile Source: bor-profile
Version: 1.1.0 Version: 1.1.0-beta4
Section: develop Section: develop
Priority: standard Priority: standard
Maintainer: Polygon <release-team@polygon.technology> Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile Source: bor-profile
Version: 1.1.0 Version: 1.1.0-beta4
Section: develop Section: develop
Priority: standard Priority: standard
Maintainer: Polygon <release-team@polygon.technology> Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile Source: bor-profile
Version: 1.1.0 Version: 1.1.0-beta4
Section: develop Section: develop
Priority: standard Priority: standard
Maintainer: Polygon <release-team@polygon.technology> Maintainer: Polygon <release-team@polygon.technology>

View file

@ -1,5 +1,5 @@
Source: bor-profile Source: bor-profile
Version: 1.1.0 Version: 1.1.0-beta4
Section: develop Section: develop
Priority: standard Priority: standard
Maintainer: Polygon <release-team@polygon.technology> Maintainer: Polygon <release-team@polygon.technology>

File diff suppressed because one or more lines are too long

View file

@ -22,6 +22,8 @@ import (
"testing" "testing"
"time" "time"
"gotest.tools/assert"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
) )
@ -150,3 +152,45 @@ func TestConfigRules(t *testing.T) {
t.Errorf("expected %v to be shanghai", 0) t.Errorf("expected %v to be shanghai", 0)
} }
} }
func TestBorKeyValueConfigHelper(t *testing.T) {
t.Parallel()
backupMultiplier := map[string]uint64{
"0": 2,
"25275000": 5,
"29638656": 2,
}
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 0), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 1), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 25275000-1), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 25275000), uint64(5))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 25275000+1), uint64(5))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 29638656-1), uint64(5))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 29638656), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(backupMultiplier, 29638656+1), uint64(2))
config := map[string]uint64{
"0": 1,
"90000000": 2,
"100000000": 3,
}
assert.Equal(t, borKeyValueConfigHelper(config, 0), uint64(1))
assert.Equal(t, borKeyValueConfigHelper(config, 1), uint64(1))
assert.Equal(t, borKeyValueConfigHelper(config, 90000000-1), uint64(1))
assert.Equal(t, borKeyValueConfigHelper(config, 90000000), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(config, 90000000+1), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(config, 100000000-1), uint64(2))
assert.Equal(t, borKeyValueConfigHelper(config, 100000000), uint64(3))
assert.Equal(t, borKeyValueConfigHelper(config, 100000000+1), uint64(3))
burntContract := map[string]string{
"22640000": "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38",
"41824608": "0x617b94CCCC2511808A3C9478ebb96f455CF167aA",
}
assert.Equal(t, borKeyValueConfigHelper(burntContract, 22640000), "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38")
assert.Equal(t, borKeyValueConfigHelper(burntContract, 22640000+1), "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38")
assert.Equal(t, borKeyValueConfigHelper(burntContract, 41824608-1), "0x70bcA57F4579f58670aB2d18Ef16e02C17553C38")
assert.Equal(t, borKeyValueConfigHelper(burntContract, 41824608), "0x617b94CCCC2511808A3C9478ebb96f455CF167aA")
assert.Equal(t, borKeyValueConfigHelper(burntContract, 41824608+1), "0x617b94CCCC2511808A3C9478ebb96f455CF167aA")
}

View file

@ -21,10 +21,10 @@ import (
) )
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 1 // Minor version component of the current release VersionMinor = 1 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release VersionPatch = 0 // Patch version component of the current release
VersionMeta = "beta" // Version metadata to append to the version string VersionMeta = "beta4" // Version metadata to append to the version string
) )
var GitCommit string var GitCommit string

View file

@ -220,7 +220,11 @@ func buildNextBlock(t *testing.T, _bor consensus.Engine, chain *core.BlockChain,
ctx := context.Background() ctx := context.Background()
// Finalize and seal the block // Finalize and seal the block
block, _ := _bor.FinalizeAndAssemble(ctx, chain, b.header, state, b.txs, nil, b.receipts, []*types.Withdrawal{}) block, err := _bor.FinalizeAndAssemble(ctx, chain, b.header, state, b.txs, nil, b.receipts, nil)
if err != nil {
panic(fmt.Sprintf("error finalizing block: %v", err))
}
// Write state changes to db // Write state changes to db
root, err := state.Commit(block.NumberU64(), chain.Config().IsEIP158(b.header.Number)) root, err := state.Commit(block.NumberU64(), chain.Config().IsEIP158(b.header.Number))