Skip to content

Commit

Permalink
Merge pull request #10 from taurusgroup/master-sync-v0.13.9-rc.1
Browse files Browse the repository at this point in the history
Master sync v0.13.9 rc.1
  • Loading branch information
oxbee authored Dec 10, 2024
2 parents 4e2cd00 + c06af9b commit 5b50f39
Show file tree
Hide file tree
Showing 77 changed files with 1,241 additions and 1,191 deletions.
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
## How this works

## How this was tested

## Need to be documented?

## Need to update RELEASES.md?
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v5
with:
go-version: "~1.21.12"
go-version: "~1.22.8"
check-latest: true
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v5
with:
go-version: "~1.21.12"
go-version: "~1.22.8"
check-latest: true
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v5
with:
go-version: "~1.21.12"
go-version: "~1.22.8"
check-latest: true
- name: Run e2e tests
run: E2E_SERIAL=1 ./scripts/tests.e2e.sh
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/sync-subnet-evm-branch.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: "Sync Subnet EVM Branch"
name: "Sync Subnet EVM Branch"
on:
workflow_dispatch:
inputs:
remoteBranch:
description: "Subnet EVM Branch"
required: true
default: "master"
inputs:
remoteBranch:
description: "Subnet EVM Branch"
required: true
default: "master"

jobs:
sync_branch:
Expand All @@ -16,5 +16,5 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "~1.21.12"
check-latest: true
go-version: "~1.22.8"
check-latest: true
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.21.12-bullseye AS builder
FROM golang:1.22.8-bullseye AS builder

ARG AVALANCHE_VERSION

Expand All @@ -17,7 +17,7 @@ WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego
RUN go mod download
# Replace the coreth dependency
RUN go mod edit -replace github.com/ava-labs/coreth=../coreth
RUN go mod download && go mod tidy -compat=1.21
RUN go mod download && go mod tidy -compat=1.22

# Build the AvalancheGo binary with local version of coreth.
RUN ./scripts/build_avalanche.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[Avalanche](https://docs.avax.network/intro) is a network composed of multiple blockchains.
Each blockchain is an instance of a Virtual Machine (VM), much like an object in an object-oriented language is an instance of a class.
That is, the VM defines the behavior of the blockchain.
Coreth (from core Ethereum) is the [Virtual Machine (VM)](https://docs.avax.network/learn/avalanche/virtual-machines) that defines the Contract Chain (C-Chain).
Coreth (from core Ethereum) is the [Virtual Machine (VM)](https://docs.avax.network/learn/virtual-machines) that defines the Contract Chain (C-Chain).
This chain implements the Ethereum Virtual Machine and supports Solidity smart contracts as well as most other Ethereum client functionality.

## Building
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.21")
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.22")
tidier.Dir = pkg
if out, err := tidier.CombinedOutput(); err != nil {
t.Fatalf("failed to tidy Go module file: %v\n%s", err, out)
Expand Down
12 changes: 8 additions & 4 deletions accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ func TestWaitDeployedCornerCases(t *testing.T) {
// Create a transaction to an account.
code := "6060604052600a8060106000396000f360606040526008565b00"
tx := types.NewTransaction(0, common.HexToAddress("0x01"), big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
tx, _ = types.SignTx(tx, types.LatestSigner(params.TestChainConfig), testKey)
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
backend.Client().SendTransaction(ctx, tx)
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
t.Fatalf("Failed to send transaction: %s", err)
}
backend.Commit(true)
notContractCreation := errors.New("tx is not contract creation")
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != notContractCreation.Error() {
Expand All @@ -137,7 +139,7 @@ func TestWaitDeployedCornerCases(t *testing.T) {

// Create a transaction that is not mined.
tx = types.NewContractCreation(1, big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
tx, _ = types.SignTx(tx, types.LatestSigner(params.TestChainConfig), testKey)
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)

go func() {
contextCanceled := errors.New("context canceled")
Expand All @@ -146,6 +148,8 @@ func TestWaitDeployedCornerCases(t *testing.T) {
}
}()

backend.Client().SendTransaction(ctx, tx)
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
t.Fatalf("Failed to send transaction: %s", err)
}
cancel()
}
18 changes: 9 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ type CacheConfig struct {
// triedbConfig derives the configures for trie database.
func (c *CacheConfig) triedbConfig() *triedb.Config {
config := &triedb.Config{Preimages: c.Preimages}
if c.StateScheme == rawdb.HashScheme {
if c.StateScheme == rawdb.HashScheme || c.StateScheme == "" {
config.HashDB = &hashdb.Config{
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
StatsPrefix: trieCleanCacheStatsNamespace,
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
StatsPrefix: trieCleanCacheStatsNamespace,
ReferenceRootAtomicallyOnUpdate: true,
}
}
if c.StateScheme == rawdb.PathScheme {
Expand Down Expand Up @@ -1161,9 +1162,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// diff layer for the block.
var err error
if bc.snaps == nil {
_, err = state.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), true)
_, err = state.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()))
} else {
_, err = state.CommitWithSnap(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.snaps, block.Hash(), block.ParentHash(), true)
_, err = state.CommitWithSnap(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()), bc.snaps, block.Hash(), block.ParentHash())
}
if err != nil {
return err
Expand Down Expand Up @@ -1695,9 +1696,9 @@ func (bc *BlockChain) reprocessBlock(parent *types.Block, current *types.Block)
// If snapshots are enabled, call CommitWithSnaps to explicitly create a snapshot
// diff layer for the block.
if bc.snaps == nil {
return statedb.Commit(current.NumberU64(), bc.chainConfig.IsEIP158(current.Number()), false)
return statedb.Commit(current.NumberU64(), bc.chainConfig.IsEIP158(current.Number()))
}
return statedb.CommitWithSnap(current.NumberU64(), bc.chainConfig.IsEIP158(current.Number()), bc.snaps, current.Hash(), current.ParentHash(), false)
return statedb.CommitWithSnap(current.NumberU64(), bc.chainConfig.IsEIP158(current.Number()), bc.snaps, current.Hash(), current.ParentHash())
}

// initSnapshot instantiates a Snapshot instance and adds it to [bc]
Expand Down Expand Up @@ -1838,8 +1839,7 @@ func (bc *BlockChain) reprocessState(current *types.Block, reexec uint64) error
// Flatten snapshot if initialized, holding a reference to the state root until the next block
// is processed.
if err := bc.flattenSnapshot(func() error {
triedb.Reference(root, common.Hash{})
if previousRoot != (common.Hash{}) {
if previousRoot != (common.Hash{}) && previousRoot != root {
triedb.Dereference(previousRoot)
}
previousRoot = root
Expand Down
3 changes: 3 additions & 0 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ func TestCreateThenDeletePreByzantium(t *testing.T) {
config.PetersburgBlock = nil
config.IstanbulBlock = nil
config.MuirGlacierBlock = nil
config.BerlinBlock = nil
config.LondonBlock = nil

testCreateThenDelete(t, &config)
}
func TestCreateThenDeletePostByzantium(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}

// Write state changes to db
root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), false)
root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number))
if err != nil {
panic(fmt.Sprintf("state write error: %v", err))
}
Expand Down
3 changes: 2 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func SetupGenesisBlock(
rawdb.WriteChainConfig(db, stored, newcfg)
return newcfg, stored, nil
}
storedcfg.SetEthUpgrades()
storedData, _ := json.Marshal(storedcfg)
// Check config compatibility and write the config. Compatibility errors
// are returned to the caller unless we're already at block zero.
Expand Down Expand Up @@ -298,7 +299,7 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
}
}

statedb.Commit(0, false, false)
statedb.Commit(0, false)
// Commit newly generated states into disk if it's not empty.
if root != types.EmptyRootHash {
if err := triedb.Commit(root, true); err != nil {
Expand Down
90 changes: 90 additions & 0 deletions core/genesis_extra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// (c) 2019-2021, Ava Labs, Inc.
//
// This file is a derived work, based on the go-ethereum library whose original
// notices appear below.
//
// It is distributed under a license compatible with the licensing terms of the
// original code from which it is derived.
//
// Much love to the original authors for their work.
// **********
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package core

import (
"math/big"
"testing"
"time"

"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/triedb"
"github.com/ava-labs/coreth/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestGenesisEthUpgrades(t *testing.T) {
db := rawdb.NewMemoryDatabase()
preEthUpgrades := &params.ChainConfig{
ChainID: big.NewInt(43114), // Specifically refers to mainnet for this UT
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: false,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
NetworkUpgrades: params.NetworkUpgrades{
ApricotPhase1BlockTimestamp: utils.NewUint64(0),
ApricotPhase2BlockTimestamp: utils.NewUint64(0),
},
}

tdb := triedb.NewDatabase(db, triedb.HashDefaults)
config := *preEthUpgrades
// Set this up once, just to get the genesis hash
_, genHash, err := SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, common.Hash{}, false)
require.NoError(t, err)

// Write the configuration back to the db as it would be in prior versions
rawdb.WriteChainConfig(db, genHash, preEthUpgrades)

// Make some other block
block := types.NewBlock(
&types.Header{
Number: big.NewInt(1640340), // Berlin activation on mainnet
Difficulty: big.NewInt(1),
ParentHash: genHash,
Time: uint64(time.Now().Unix()),
},
nil, nil, nil, nil,
)
rawdb.WriteBlock(db, block)

// We should still be able to re-initialize
config = *preEthUpgrades
config.SetEthUpgrades() // New versions will set additional fields eg, LondonBlock
_, _, err = SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, block.Hash(), false)
require.NoError(t, err)
}
3 changes: 3 additions & 0 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ func TestVerkleGenesisCommit(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ShanghaiTime: &verkleTime,
CancunTime: &verkleTime,
VerkleTime: &verkleTime,
}
Expand Down
8 changes: 4 additions & 4 deletions core/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestDump(t *testing.T) {
// write some of them to the trie
s.state.updateStateObject(obj1)
s.state.updateStateObject(obj2)
root, _ := s.state.Commit(0, false, false)
root, _ := s.state.Commit(0, false)

// check that DumpToCollector contains the state objects that are in trie
s.state, _ = New(root, tdb, nil)
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestIterativeDump(t *testing.T) {
// write some of them to the trie
s.state.updateStateObject(obj1)
s.state.updateStateObject(obj2)
root, _ := s.state.Commit(0, false, false)
root, _ := s.state.Commit(0, false)
s.state, _ = New(root, tdb, nil)

b := &bytes.Buffer{}
Expand All @@ -156,7 +156,7 @@ func TestNull(t *testing.T) {
var value common.Hash

s.state.SetState(address, common.Hash{}, value)
s.state.Commit(0, false, false)
s.state.Commit(0, false)

if value := s.state.GetState(address, common.Hash{}); value != (common.Hash{}) {
t.Errorf("expected empty current value, got %x", value)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestSnapshot2(t *testing.T) {
so0.deleted = false
state.setStateObject(so0)

root, _ := state.Commit(0, false, false)
root, _ := state.Commit(0, false)
state, _ = New(root, state.db, nil)

// and one with deleted == true
Expand Down
20 changes: 7 additions & 13 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,14 +1263,14 @@ func (s *StateDB) handleDestruction(nodes *trienode.MergedNodeSet) (map[common.A
}

// Commit writes the state to the underlying in-memory trie database.
func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool, referenceRoot bool) (common.Hash, error) {
return s.commit(block, deleteEmptyObjects, nil, common.Hash{}, common.Hash{}, referenceRoot)
func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error) {
return s.commit(block, deleteEmptyObjects, nil, common.Hash{}, common.Hash{})
}

// CommitWithSnap writes the state to the underlying in-memory trie database and
// generates a snapshot layer for the newly committed state.
func (s *StateDB) CommitWithSnap(block uint64, deleteEmptyObjects bool, snaps *snapshot.Tree, blockHash, parentHash common.Hash, referenceRoot bool) (common.Hash, error) {
return s.commit(block, deleteEmptyObjects, snaps, blockHash, parentHash, referenceRoot)
func (s *StateDB) CommitWithSnap(block uint64, deleteEmptyObjects bool, snaps *snapshot.Tree, blockHash, parentHash common.Hash) (common.Hash, error) {
return s.commit(block, deleteEmptyObjects, snaps, blockHash, parentHash)
}

// Once the state is committed, tries cached in stateDB (including account
Expand All @@ -1280,7 +1280,7 @@ func (s *StateDB) CommitWithSnap(block uint64, deleteEmptyObjects bool, snaps *s
//
// The associated block number of the state transition is also provided
// for more chain context.
func (s *StateDB) commit(block uint64, deleteEmptyObjects bool, snaps *snapshot.Tree, blockHash, parentHash common.Hash, referenceRoot bool) (common.Hash, error) {
func (s *StateDB) commit(block uint64, deleteEmptyObjects bool, snaps *snapshot.Tree, blockHash, parentHash common.Hash) (common.Hash, error) {
// Short circuit in case any database failure occurred earlier.
if s.dbErr != nil {
return common.Hash{}, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr)
Expand Down Expand Up @@ -1389,14 +1389,8 @@ func (s *StateDB) commit(block uint64, deleteEmptyObjects bool, snaps *snapshot.
if root != origin {
start := time.Now()
set := triestate.New(s.accountsOrigin, s.storagesOrigin, incomplete)
if referenceRoot {
if err := s.db.TrieDB().UpdateAndReferenceRoot(root, origin, block, nodes, set); err != nil {
return common.Hash{}, err
}
} else {
if err := s.db.TrieDB().Update(root, origin, block, nodes, set); err != nil {
return common.Hash{}, err
}
if err := s.db.TrieDB().Update(root, origin, block, nodes, set); err != nil {
return common.Hash{}, err
}
s.originalRoot = root
if metrics.EnabledExpensive {
Expand Down
Loading

0 comments on commit 5b50f39

Please # to comment.