Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion consensus/dummy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The dynamic fee algorithm aims to adjust the base fee to handle network congesti

- EIP-1559 is intended for Ethereum where a block is produced roughly every 10s
- C-Chain typically produces blocks every 2 seconds, but the dynamic fee algorithm needs to handle the case that the network quiesces and there are no blocks for a long period of time
- Since C-Chain produces blocks at a different cadence, it adapts EIP-1559 to sum the amount of gas consumed within a 10 second interval instead of using only the amount of gas consumed in the parent block
- Since C-Chain produces blocks at a different cadence, it adapts EIP-1559 to sum the amount of gas consumed within a 10-second interval instead of using only the amount of gas consumed in the parent block

## Consensus Engine Callbacks

Expand Down
2 changes: 1 addition & 1 deletion core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
// stateBloomFilePrefix is the filename prefix of state bloom filter.
stateBloomFilePrefix = "statebloom"

// stateBloomFilePrefix is the filename suffix of state bloom filter.
// stateBloomFileSuffix is the filename suffix of state bloom filter.
stateBloomFileSuffix = "bf.gz"

// stateBloomFileTempSuffix is the filename suffix of state bloom filter
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/js/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestHaltBetweenSteps(t *testing.T) {
}
}

// testNoStepExec tests a regular value transfer (no exec), and accessing the statedb
// TestNoStepExec tests a regular value transfer (no exec), and accessing the statedb
// in 'result'
func TestNoStepExec(t *testing.T) {
execTracer := func(code string) []byte {
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/logger/access_list_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (al accessList) equal(other accessList) bool {
return true
}

// accesslist converts the accesslist to a types.AccessList.
// accessList converts the accesslist to a types.AccessList.
func (al accessList) accessList() types.AccessList {
acl := make(types.AccessList, 0, len(al))
for addr, slots := range al {
Expand Down
File renamed without changes.
33 changes: 17 additions & 16 deletions plugin/evm/atomic_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/codec"
"github.com/ava-labs/avalanchego/database"
avalanchedatabase "github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/utils/wrappers"
Expand All @@ -18,6 +18,7 @@ import (
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/plugin/evm/atomic"
"github.com/ava-labs/coreth/plugin/evm/database"
"github.com/ava-labs/coreth/trie"
"github.com/ava-labs/coreth/trie/trienode"
"github.com/ava-labs/coreth/triedb"
Expand Down Expand Up @@ -117,12 +118,12 @@ type AtomicTrieIterator interface {

// atomicTrie implements the AtomicTrie interface
type atomicTrie struct {
commitInterval uint64 // commit interval, same as commitHeightInterval by default
metadataDB database.Database // Underlying database containing the atomic trie metadata
trieDB *triedb.Database // Trie database
lastCommittedRoot common.Hash // trie root of the most recent commit
lastCommittedHeight uint64 // index height of the most recent commit
lastAcceptedRoot common.Hash // most recent trie root passed to accept trie or the root of the atomic trie on intialization.
commitInterval uint64 // commit interval, same as commitHeightInterval by default
metadataDB avalanchedatabase.Database // Underlying database containing the atomic trie metadata
trieDB *triedb.Database // Trie database
lastCommittedRoot common.Hash // trie root of the most recent commit
lastCommittedHeight uint64 // index height of the most recent commit
lastAcceptedRoot common.Hash // most recent trie root passed to accept trie or the root of the atomic trie on intialization.
codec codec.Manager
memoryCap common.StorageSize
tipBuffer *core.BoundedBuffer[common.Hash]
Expand All @@ -131,7 +132,7 @@ type atomicTrie struct {
// newAtomicTrie returns a new instance of a atomicTrie with a configurable commitHeightInterval, used in testing.
// Initializes the trie before returning it.
func newAtomicTrie(
atomicTrieDB database.Database, metadataDB database.Database,
atomicTrieDB avalanchedatabase.Database, metadataDB avalanchedatabase.Database,
codec codec.Manager, lastAcceptedHeight uint64, commitHeightInterval uint64,
) (*atomicTrie, error) {
root, height, err := lastCommittedRootIfExists(metadataDB)
Expand All @@ -153,7 +154,7 @@ func newAtomicTrie(
}

trieDB := triedb.NewDatabase(
rawdb.NewDatabase(Database{atomicTrieDB}),
rawdb.NewDatabase(database.WrapDatabase(atomicTrieDB)),
&triedb.Config{
HashDB: &hashdb.Config{
CleanCacheSize: 64 * units.MiB, // Allocate 64MB of memory for clean cache
Expand Down Expand Up @@ -182,17 +183,17 @@ func newAtomicTrie(
// else returns empty common.Hash{} and 0
// returns error only if there are issues with the underlying data store
// or if values present in the database are not as expected
func lastCommittedRootIfExists(db database.Database) (common.Hash, uint64, error) {
func lastCommittedRootIfExists(db avalanchedatabase.Database) (common.Hash, uint64, error) {
// read the last committed entry if it exists and set the root hash
lastCommittedHeightBytes, err := db.Get(lastCommittedKey)
switch {
case err == database.ErrNotFound:
case err == avalanchedatabase.ErrNotFound:
return common.Hash{}, 0, nil
case err != nil:
return common.Hash{}, 0, err
}

height, err := database.ParseUInt64(lastCommittedHeightBytes)
height, err := avalanchedatabase.ParseUInt64(lastCommittedHeightBytes)
if err != nil {
return common.Hash{}, 0, fmt.Errorf("expected value at lastCommittedKey to be a valid uint64: %w", err)
}
Expand Down Expand Up @@ -251,7 +252,7 @@ func (a *atomicTrie) LastCommitted() (common.Hash, uint64) {
// updateLastCommitted adds [height] -> [root] to the index and marks it as the last committed
// root/height pair.
func (a *atomicTrie) updateLastCommitted(root common.Hash, height uint64) error {
heightBytes := database.PackUInt64(height)
heightBytes := avalanchedatabase.PackUInt64(height)

// now save the trie hash against the height it was committed at
if err := a.metadataDB.Put(heightBytes, root[:]); err != nil {
Expand Down Expand Up @@ -297,18 +298,18 @@ func (a *atomicTrie) Root(height uint64) (common.Hash, error) {

// getRoot is a helper function to return the committed atomic trie root hash at [height]
// from [metadataDB].
func getRoot(metadataDB database.Database, height uint64) (common.Hash, error) {
func getRoot(metadataDB avalanchedatabase.Database, height uint64) (common.Hash, error) {
if height == 0 {
// if root is queried at height == 0, return the empty root hash
// this may occur if peers ask for the most recent state summary
// and number of accepted blocks is less than the commit interval.
return types.EmptyRootHash, nil
}

heightBytes := database.PackUInt64(height)
heightBytes := avalanchedatabase.PackUInt64(height)
hash, err := metadataDB.Get(heightBytes)
switch {
case err == database.ErrNotFound:
case err == avalanchedatabase.ErrNotFound:
return common.Hash{}, nil
case err != nil:
return common.Hash{}, err
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (b *Block) Accept(context.Context) error {

// Although returning an error from Accept is considered fatal, it is good
// practice to cleanup the batch we were modifying in the case of an error.
defer vm.db.Abort()
defer vm.versiondb.Abort()

log.Debug(fmt.Sprintf("Accepting block %s (%s) at height %d", b.ID().Hex(), b.ID(), b.Height()))

Expand Down Expand Up @@ -176,7 +176,7 @@ func (b *Block) Accept(context.Context) error {
}
// Get pending operations on the vm's versionDB so we can apply them atomically
// with the shared memory changes.
vdbBatch, err := b.vm.db.CommitBatch()
vdbBatch, err := b.vm.versiondb.CommitBatch()
if err != nil {
return fmt.Errorf("could not create commit batch processing block[%s]: %w", b.ID(), err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package evm
package database

import (
"errors"
Expand All @@ -11,33 +11,37 @@ import (
)

var (
_ ethdb.KeyValueStore = &Database{}
_ ethdb.KeyValueStore = &ethDbWrapper{}

ErrSnapshotNotSupported = errors.New("snapshot is not supported")
)

// Database implements ethdb.Database
type Database struct{ database.Database }
// ethDbWrapper implements ethdb.Database
type ethDbWrapper struct{ database.Database }

func WrapDatabase(db database.Database) ethdb.KeyValueStore { return ethDbWrapper{db} }

// Stat implements ethdb.Database
func (db Database) Stat(string) (string, error) { return "", database.ErrNotFound }
func (db ethDbWrapper) Stat(string) (string, error) { return "", database.ErrNotFound }

// NewBatch implements ethdb.Database
func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} }
func (db ethDbWrapper) NewBatch() ethdb.Batch { return wrappedBatch{db.Database.NewBatch()} }

// NewBatchWithSize implements ethdb.Database
// TODO: propagate size through avalanchego Database interface
func (db Database) NewBatchWithSize(size int) ethdb.Batch { return Batch{db.Database.NewBatch()} }
func (db ethDbWrapper) NewBatchWithSize(size int) ethdb.Batch {
return wrappedBatch{db.Database.NewBatch()}
}

func (db Database) NewSnapshot() (ethdb.Snapshot, error) {
func (db ethDbWrapper) NewSnapshot() (ethdb.Snapshot, error) {
return nil, ErrSnapshotNotSupported
}

// NewIterator implements ethdb.Database
//
// Note: This method assumes that the prefix is NOT part of the start, so there's
// no need for the caller to prepend the prefix to the start.
func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
func (db ethDbWrapper) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
// avalanchego's database implementation assumes that the prefix is part of the
// start, so it is added here (if it is provided).
if len(prefix) > 0 {
Expand All @@ -50,15 +54,15 @@ func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
}

// NewIteratorWithStart implements ethdb.Database
func (db Database) NewIteratorWithStart(start []byte) ethdb.Iterator {
func (db ethDbWrapper) NewIteratorWithStart(start []byte) ethdb.Iterator {
return db.Database.NewIteratorWithStart(start)
}

// Batch implements ethdb.Batch
type Batch struct{ database.Batch }
// wrappedBatch implements ethdb.wrappedBatch
type wrappedBatch struct{ database.Batch }

// ValueSize implements ethdb.Batch
func (batch Batch) ValueSize() int { return batch.Batch.Size() }
func (batch wrappedBatch) ValueSize() int { return batch.Batch.Size() }

// Replay implements ethdb.Batch
func (batch Batch) Replay(w ethdb.KeyValueWriter) error { return batch.Batch.Replay(w) }
func (batch wrappedBatch) Replay(w ethdb.KeyValueWriter) error { return batch.Batch.Replay(w) }
6 changes: 3 additions & 3 deletions plugin/evm/export_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ func TestExportTxAccept(t *testing.T) {
t.Fatal(err)
}

commitBatch, err := vm.db.CommitBatch()
commitBatch, err := vm.versiondb.CommitBatch()
if err != nil {
t.Fatalf("Failed to create commit batch for VM due to %s", err)
}
Expand Down Expand Up @@ -1800,7 +1800,7 @@ func TestNewExportTx(t *testing.T) {
t.Fatalf("burned wrong amount of AVAX - expected %d burned %d", test.expectedBurnedAVAX, burnedAVAX)
}

commitBatch, err := vm.db.CommitBatch()
commitBatch, err := vm.versiondb.CommitBatch()
if err != nil {
t.Fatalf("Failed to create commit batch for VM due to %s", err)
}
Expand Down Expand Up @@ -2000,7 +2000,7 @@ func TestNewExportTxMulticoin(t *testing.T) {
t.Fatal("newExportTx created an invalid transaction", err)
}

commitBatch, err := vm.db.CommitBatch()
commitBatch, err := vm.versiondb.CommitBatch()
if err != nil {
t.Fatalf("Failed to create commit batch for VM due to %s", err)
}
Expand Down
9 changes: 5 additions & 4 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/stretchr/testify/require"

avalancheatomic "github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database"
avalanchedatabase "github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
Expand All @@ -36,6 +36,7 @@ import (
"github.com/ava-labs/coreth/metrics"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/plugin/evm/atomic"
"github.com/ava-labs/coreth/plugin/evm/database"
"github.com/ava-labs/coreth/predicate"
statesyncclient "github.com/ava-labs/coreth/sync/client"
"github.com/ava-labs/coreth/sync/statesync"
Expand Down Expand Up @@ -334,7 +335,7 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest, numBlocks int) *s
serverAtomicTrie := serverVM.atomicTrie.(*atomicTrie)
serverAtomicTrie.commitInterval = test.syncableInterval
require.NoError(serverAtomicTrie.commit(test.syncableInterval, serverAtomicTrie.LastAcceptedRoot()))
require.NoError(serverVM.db.Commit())
require.NoError(serverVM.versiondb.Commit())

serverSharedMemories := newSharedMemories(serverAtomicMemory, serverVM.ctx.ChainID, serverVM.ctx.XChainID)
serverSharedMemories.assertOpsApplied(t, mustAtomicOps(importTx))
Expand Down Expand Up @@ -430,7 +431,7 @@ type syncVMSetup struct {
fundedAccounts map[*keystore.Key]*types.StateAccount

syncerVM *VM
syncerDB database.Database
syncerDB avalanchedatabase.Database
syncerEngineChan <-chan commonEng.Message
syncerAtomicMemory *avalancheatomic.Memory
shutdownOnceSyncerVM *shutdownOnceVM
Expand Down Expand Up @@ -491,7 +492,7 @@ func testSyncerVM(t *testing.T, vmSetup *syncVMSetup, test syncTest) {
if test.expectedErr != nil {
require.ErrorIs(err, test.expectedErr)
// Note we re-open the database here to avoid a closed error when the test is for a shutdown VM.
chaindb := Database{prefixdb.NewNested(ethDBPrefix, syncerVM.db)}
chaindb := database.WrapDatabase(prefixdb.NewNested(ethDBPrefix, syncerVM.db))
assertSyncPerformedHeights(t, chaindb, map[uint64]struct{}{})
return
}
Expand Down
Loading
Loading