Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c6c0b1d
Author: Dan Laine <daniel.laine@avalabs.org>
Date:   Tue Jul 18 10:02:30 2023 -0400

    Rename sorting method imported from avalanchego (#272)

    * update avalanchego version

    * rename sorting method import

    * update avalanchego dep

    * fix sorting method name

    * fix sorting method name for real

commit 734c238
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Mon Jul 17 21:13:39 2023 -0400

    Add release notes and bump AvalancheGo dep (#289)

commit e024457
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Mon Jul 17 14:39:58 2023 -0400

    Prevent panic for LOG edge cases in callTracer (#285)

    * cherry-pick tracer log edge case handling

    * Update goja

    ---------

    Co-authored-by: jwasinger <j-wasinger@hotmail.com>

commit 1855d7e
Author: Darioush Jalali <darioush.jalali@avalabs.org>
Date:   Mon Jul 17 11:39:11 2023 -0700

    Whitespace and nits (#287)

    * Whitespace and nits

    * add cpfg fix

commit 72df753
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Mon Jul 17 14:37:11 2023 -0400

    Prestate lookup account storage (#286)

    * Add lookupAccount in lookupStorage

    * fix tracer regression

    * Move tracer test to new directory

    ---------

    Co-authored-by: morrisettjohn <morrisettjohn@gmail.com>

commit 261d2ad
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Fri Jul 14 11:17:33 2023 -0400

    Cleanup accepted logs subscription test (#283)

commit a025ecc
Author: Darioush Jalali <darioush.jalali@avalabs.org>
Date:   Mon Jul 10 11:50:09 2023 -0700

    Use go1.19 in CI for consistency with avalanchego (#278)

commit 419b262
Author: Darioush Jalali <darioush.jalali@avalabs.org>
Date:   Fri Jul 7 13:07:54 2023 -0700

    Fix goroutine leaks in core/ tests (#273)

commit fbd9dad
Author: Dan Laine <daniel.laine@avalabs.org>
Date:   Wed Jun 28 14:22:38 2023 -0400

    Use avalanchego's sorting methods (#260)

    * use avalanchgo sorting functions

    * add tests for Less

    * import ordering

    * import ordering

    * Use `slices` methods instead of `sort` methods (#261)

    * use slices.Sort instead of sort.Slice

    * import ordering

    * add test case

commit 3f0df72
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Mon Jun 26 23:10:03 2023 -0400

    Bump to v0.12.4 (#271)

commit 6c9d2c3
Author: aaronbuchwald <aaron.buchwald56@gmail.com>
Date:   Thu Jun 22 00:42:44 2023 -0400

    Fix collect unflattened logs (#270)

    * Handle empty logs edge case in collectUnflattenedLogs

    * Add unit test to check log handling for block with atomic tx and no eth transactions

    * Fix race and add nil check

commit c08a7c1
Author: Darioush Jalali <darioush.jalali@avalabs.org>
Date:   Tue Jun 20 15:05:03 2023 -0700

    Restrict ClearPrefix by key size (#265)

commit 0d02ea7
Author: Dan Laine <daniel.laine@avalabs.org>
Date:   Thu Jun 15 11:07:31 2023 -0400

    export CalculateDynamicFee (#259)

commit 0eb8685
Author: Dan Laine <daniel.laine@avalabs.org>
Date:   Thu Jun 15 10:48:26 2023 -0400

    update golangci-lint-action (#263)
  • Loading branch information
joshua-kim committed Jul 18, 2023
1 parent 04ada76 commit 811c52e
Show file tree
Hide file tree
Showing 43 changed files with 727 additions and 280 deletions.
10 changes: 5 additions & 5 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@v3
with:
go-version: "1.20"
go-version: "1.19"
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
Expand All @@ -41,7 +41,7 @@ jobs:
- run: ./scripts/lint_allowed_geth_imports.sh
shell: bash
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.51
working-directory: .
Expand All @@ -51,7 +51,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go: ['1.20']
go: ['1.19']
os: [macos-11.0, ubuntu-20.04, windows-latest]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go: ['1.20']
go: ['1.19']
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go: [ '1.20' ]
go: [ '1.19' ]
os: [ ubuntu-20.04 ]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.20.1-buster AS builder
FROM golang:1.19.10-buster AS builder

RUN apt-get update && apt-get install -y --no-install-recommends bash=5.0-4 make=4.2.1-1.2 gcc=4:8.3.0-1 musl-dev=1.1.21-2 ca-certificates=20200601~deb10u2 linux-headers-amd64

Expand Down
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes

## [v0.12.4](https://github.com/ava-labs/coreth/releases/tag/v0.12.4)

- Fix API handler crash for `lookupState` in `prestate` tracer
- Fix API handler crash for LOG edge cases in the `callTracer`
- Fix regression in `eth_getLogs` serving request for blocks containing no Ethereum transactions
- Export `CalculateDynamicFee`

## [v0.12.3](https://github.com/ava-labs/coreth/releases/tag/v0.12.3)

- Migrate go-ethereum changes through v1.11.4
Expand Down
6 changes: 3 additions & 3 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ type SimulatedBackend struct {
// and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337.
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
cpcfg := params.TestChainConfig
cpcfg.ChainID = big.NewInt(1337)
copyConfig := *params.TestChainConfig
copyConfig.ChainID = big.NewInt(1337)
genesis := core.Genesis{
Config: cpcfg,
Config: &copyConfig,
GasLimit: gasLimit,
Alloc: alloc,
}
Expand Down
8 changes: 0 additions & 8 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ func TestNewSimulatedBackend(t *testing.T) {
sim := simTestBackend(testAddr)
defer sim.Close()

if sim.config != params.TestChainConfig {
t.Errorf("expected sim config to equal params.AllEthashProtocolChanges, got %v", sim.config)
}

if sim.blockchain.Config() != params.TestChainConfig {
t.Errorf("expected sim blockchain config to equal params.AllEthashProtocolChanges, got %v", sim.config)
}

stateDB, _ := sim.blockchain.State()
bal := stateDB.GetBalance(testAddr)
if bal.Cmp(expectedBal) != 0 {
Expand Down
18 changes: 9 additions & 9 deletions accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ var (
if err != nil {
return *outstruct, err
}
{{range $i, $t := .Normalized.Outputs}}
{{range $i, $t := .Normalized.Outputs}}
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return *outstruct, err
Expand All @@ -345,7 +345,7 @@ var (
}
{{range $i, $t := .Normalized.Outputs}}
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
{{end}}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ var (
}
{{end}}
{{if .Fallback}}
{{if .Fallback}}
// Fallback is a paid mutator transaction binding the contract fallback function.
//
// Solidity: {{.Fallback.Original.String}}
Expand All @@ -402,16 +402,16 @@ var (
func (_{{$contract.Type}} *{{$contract.Type}}Session) Fallback(calldata []byte) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
}
// Fallback is a paid mutator transaction binding the contract fallback function.
//
//
// Solidity: {{.Fallback.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Fallback(calldata []byte) (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
}
{{end}}
{{if .Receive}}
{{if .Receive}}
// Receive is a paid mutator transaction binding the contract receive function.
//
// Solidity: {{.Receive.Original.String}}
Expand All @@ -425,9 +425,9 @@ var (
func (_{{$contract.Type}} *{{$contract.Type}}Session) Receive() (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
}
// Receive is a paid mutator transaction binding the contract receive function.
//
//
// Solidity: {{.Receive.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Receive() (*types.Transaction, error) {
return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
Expand Down Expand Up @@ -576,6 +576,6 @@ var (
return event, nil
}
{{end}}
{{end}}
{{end}}
`
2 changes: 1 addition & 1 deletion accounts/abi/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Error struct {
str string

// Sig contains the string signature according to the ABI spec.
// e.g. error foo(uint32 a, int b) = "foo(uint32,int256)"
// e.g. error foo(uint32 a, int b) = "foo(uint32,int256)"
// Please note that "int" is substitute for its canonical representation "int256"
Sig string

Expand Down
8 changes: 5 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,10 @@ func (bc *BlockChain) collectUnflattenedLogs(b *types.Block, removed bool) [][]*
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), b.Transactions())

var logs [][]*types.Log
for _, receipt := range receipts {
// Note: gross but this needs to be initialized here because returning nil will be treated specially as an incorrect
// error case downstream.
logs := make([][]*types.Log, len(receipts))
for i, receipt := range receipts {
receiptLogs := make([]*types.Log, len(receipt.Logs))
for i, log := range receipt.Logs {
l := *log
Expand All @@ -1405,7 +1407,7 @@ func (bc *BlockChain) collectUnflattenedLogs(b *types.Block, removed bool) [][]*
}
receiptLogs[i] = &l
}
logs = append(logs, receiptLogs)
logs[i] = receiptLogs
}
return logs
}
Expand Down
32 changes: 17 additions & 15 deletions core/blockchain_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ import (
"github.com/stretchr/testify/require"
)

/*
Example contract to test event emission:
pragma solidity >=0.7.0 <0.9.0;
contract Callable {
event Called();
function Call() public { emit Called(); }
}
*/
const callableAbi = "[{\"anonymous\":false,\"inputs\":[],\"name\":\"Called\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"Call\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"

const callableBin = "6080604052348015600f57600080fd5b5060998061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806334e2292114602d575b600080fd5b60336035565b005b7f81fab7a4a0aa961db47eefc81f143a5220e8c8495260dd65b1356f1d19d3c7b860405160405180910390a156fea2646970667358221220029436d24f3ac598ceca41d4d712e13ced6d70727f4cdc580667de66d2f51d8b64736f6c63430008010033"

func TestEmitLogsCorrectness(t *testing.T) {
func TestAcceptedLogsSubscription(t *testing.T) {
/*
Example contract to test event emission:
pragma solidity >=0.7.0 <0.9.0;
contract Callable {
event Called();
function Call() public { emit Called(); }
}
*/

const (
callableABI = "[{\"anonymous\":false,\"inputs\":[],\"name\":\"Called\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"Call\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
callableBin = "6080604052348015600f57600080fd5b5060998061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806334e2292114602d575b600080fd5b60336035565b005b7f81fab7a4a0aa961db47eefc81f143a5220e8c8495260dd65b1356f1d19d3c7b860405160405180910390a156fea2646970667358221220029436d24f3ac598ceca41d4d712e13ced6d70727f4cdc580667de66d2f51d8b64736f6c63430008010033"
)
var (
require = require.New(t)
engine = dummy.NewFaker()
Expand All @@ -48,7 +49,7 @@ func TestEmitLogsCorrectness(t *testing.T) {
signer = types.LatestSigner(gspec.Config)
)

parsed, err := abi.JSON(strings.NewReader(callableAbi))
parsed, err := abi.JSON(strings.NewReader(callableABI))
require.NoError(err)

packedFunction, err := parsed.Pack("Call")
Expand All @@ -74,6 +75,7 @@ func TestEmitLogsCorrectness(t *testing.T) {

chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfig, gspec, engine, vm.Config{}, common.Hash{}, false)
require.NoError(err)
defer chain.Stop()

// Create Log Subscriber
logsCh := make(chan []*types.Log, 10)
Expand Down
1 change: 1 addition & 0 deletions core/blockchain_repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
if err != nil {
t.Fatalf("Failed to create chain: %v", err)
}
defer chain.Stop()
lastAcceptedHash := chain.GetBlockByNumber(0).Hash()

// If sidechain blocks are needed, make a light chain and import it
Expand Down
12 changes: 9 additions & 3 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,14 @@ func TestBlockChainOfflinePruningUngracefulShutdown(t *testing.T) {
return blockchain, nil
}

tempDir := t.TempDir()
if err := blockchain.CleanBlockRootsAboveLastAccepted(); err != nil {
return nil, err
}
// get the target root to prune to before stopping the blockchain
targetRoot := blockchain.LastAcceptedBlock().Root()
blockchain.Stop()

tempDir := t.TempDir()
prunerConfig := pruner.Config{
Datadir: tempDir,
BloomSize: 256,
Expand All @@ -371,16 +374,15 @@ func TestBlockChainOfflinePruningUngracefulShutdown(t *testing.T) {
return nil, fmt.Errorf("offline pruning failed (%s, %d): %w", tempDir, 256, err)
}

targetRoot := blockchain.LastAcceptedBlock().Root()
if err := pruner.Prune(targetRoot); err != nil {
return nil, fmt.Errorf("failed to prune blockchain with target root: %s due to: %w", targetRoot, err)
}
// Re-initialize the blockchain after pruning
return createBlockChain(db, pruningConfig, gspec, lastAcceptedHash)
}
for _, tt := range tests {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
tt := tt
t.Parallel()
tt.testFunc(t, create)
})
Expand Down Expand Up @@ -465,6 +467,7 @@ func testRepopulateMissingTriesParallel(t *testing.T, parallelism int) {
if err != nil {
t.Fatal(err)
}
defer blockchain.Stop()

for _, block := range chain {
if !blockchain.HasState(block.Root()) {
Expand Down Expand Up @@ -951,6 +954,7 @@ func testCreateThenDelete(t *testing.T, config *params.ChainConfig) {
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
defer chain.Stop()
// Import the blocks
for _, block := range blocks {
if _, err := chain.InsertChain([]*types.Block{block}); err != nil {
Expand Down Expand Up @@ -1037,6 +1041,7 @@ func TestTransientStorageReset(t *testing.T) {
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
defer chain.Stop()
// Import the blocks
if _, err := chain.InsertChain(blocks); err != nil {
t.Fatalf("failed to insert into chain: %v", err)
Expand Down Expand Up @@ -1125,6 +1130,7 @@ func TestEIP3651(t *testing.T) {
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
}
defer chain.Stop()
if n, err := chain.InsertChain(blocks); err != nil {
t.Fatalf("block %d: failed to insert into chain: %v", n, err)
}
Expand Down
2 changes: 2 additions & 0 deletions core/headerchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func TestHeaderInsertion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer chain.Stop()

// chain A: G->A1->A2...A128
chainA, _, _ := GenerateChain(params.TestChainConfig, types.NewBlockWithHeader(genesis.Header()), dummy.NewFaker(), db, 128, 10, func(i int, b *BlockGen) {
b.SetCoinbase(common.Address{0: byte(10), 19: byte(i)})
Expand Down
22 changes: 22 additions & 0 deletions core/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package core

import (
"testing"

"go.uber.org/goleak"
)

// TestMain uses goleak to verify tests in this package do not leak unexpected
// goroutines.
func TestMain(m *testing.M) {
opts := []goleak.Option{
// No good way to shut down these goroutines:
goleak.IgnoreTopFunction("github.com/ava-labs/coreth/core/state/snapshot.(*diskLayer).generate"),
goleak.IgnoreTopFunction("github.com/ava-labs/coreth/metrics.(*meterArbiter).tick"),
goleak.IgnoreTopFunction("github.com/syndtr/goleveldb/leveldb.(*DB).mpoolDrain"),
}
goleak.VerifyTestMain(m, opts...)
}
9 changes: 4 additions & 5 deletions core/rawdb/accessors_state_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ func ClearSyncSegments(db ethdb.KeyValueStore, root common.Hash) error {
segmentsPrefix := make([]byte, len(syncSegmentsPrefix)+common.HashLength)
copy(segmentsPrefix, syncSegmentsPrefix)
copy(segmentsPrefix[len(syncSegmentsPrefix):], root[:])

return ClearPrefix(db, segmentsPrefix)
return ClearPrefix(db, segmentsPrefix, syncSegmentsKeyLength)
}

// ClearAllSyncSegments removes all segment markers from db
func ClearAllSyncSegments(db ethdb.KeyValueStore) error {
return ClearPrefix(db, syncSegmentsPrefix)
return ClearPrefix(db, syncSegmentsPrefix, syncSegmentsKeyLength)
}

// UnpackSyncSegmentKey returns the root and start position for a trie segment
Expand Down Expand Up @@ -131,12 +130,12 @@ func ClearSyncStorageTrie(db ethdb.KeyValueStore, root common.Hash) error {
accountsPrefix := make([]byte, len(syncStorageTriesPrefix)+common.HashLength)
copy(accountsPrefix, syncStorageTriesPrefix)
copy(accountsPrefix[len(syncStorageTriesPrefix):], root[:])
return ClearPrefix(db, accountsPrefix)
return ClearPrefix(db, accountsPrefix, syncStorageTriesKeyLength)
}

// ClearAllSyncStorageTries removes all storage tries added for syncing from db
func ClearAllSyncStorageTries(db ethdb.KeyValueStore) error {
return ClearPrefix(db, syncStorageTriesPrefix)
return ClearPrefix(db, syncStorageTriesPrefix, syncStorageTriesKeyLength)
}

// UnpackSyncStorageTrieKey returns the root and account for a storage trie
Expand Down
Loading

0 comments on commit 811c52e

Please sign in to comment.