Skip to content

Commit

Permalink
Merge pull request #1068 from maticnetwork/v1.1.0-beta-candidate
Browse files Browse the repository at this point in the history
Merge V1.1.0 beta candidate to 'develop'
  • Loading branch information
temaniarpit27 authored Nov 2, 2023
2 parents ab42a16 + 6169648 commit bc338be
Show file tree
Hide file tree
Showing 30 changed files with 157 additions and 89 deletions.
6 changes: 3 additions & 3 deletions builder/files/genesis-testnet-v4.json

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,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 @@ -816,13 +819,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 @@ -898,18 +895,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: 2 additions & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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 @@ -90,12 +90,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.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
// both the pending block as well as the pending state from
// the miner and operate on those
_, stateDb := api.eth.miner.Pending()
if stateDb == nil {
return state.Dump{}, errors.New("pending state is not available")
}
return stateDb.RawDump(opts), nil
}

Expand Down Expand Up @@ -385,6 +388,9 @@ func (api *DebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, start hex
// both the pending block as well as the pending state from
// the miner and operate on those
_, stateDb = api.eth.miner.Pending()
if stateDb == nil {
return state.IteratorDump{}, errors.New("pending state is not available")
}
} else {
var header *types.Header
if number == rpc.LatestBlockNumber {
Expand Down
9 changes: 9 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 Expand Up @@ -217,6 +223,9 @@ func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.B
// Pending state is only known by the miner
if number == rpc.PendingBlockNumber {
block, state := b.eth.miner.Pending()
if block == nil || state == nil {
return nil, nil, errors.New("pending state is not available")
}
return state, block.Header(), nil
}
// Otherwise resolve the block number and return its state
Expand Down
3 changes: 3 additions & 0 deletions eth/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
// pendingLogs returns the logs matching the filter criteria within the pending block.
func (f *Filter) pendingLogs() ([]*types.Log, error) {
block, receipts := f.sys.backend.PendingBlockAndReceipts()
if block == nil || receipts == nil {
return nil, errors.New("pending block is not available")
}
if bloomFilter(block.Bloom(), f.addresses, f.topics) {
var unfiltered []*types.Log
for _, r := range receipts {
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 @@ -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{})
}
}

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 bc338be

Please sign in to comment.