Skip to content

Commit

Permalink
atomic syncer: simplify interface (#735)
Browse files Browse the repository at this point in the history
Co-authored-by: Ceyhun Onur <[email protected]>
  • Loading branch information
darioush and ceyonur authored Jan 9, 2025
1 parent 24e1459 commit b6b4dfb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
11 changes: 0 additions & 11 deletions plugin/evm/atomic_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/coreth/plugin/evm/atomic"
syncclient "github.com/ava-labs/coreth/sync/client"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
Expand Down Expand Up @@ -57,10 +56,6 @@ type AtomicBackend interface {
// will not have been executed on shared memory.
MarkApplyToSharedMemoryCursor(previousLastAcceptedHeight uint64) error

// Syncer creates and returns a new Syncer object that can be used to sync the
// state of the atomic trie from peers
Syncer(client syncclient.LeafClient, targetRoot common.Hash, targetHeight uint64, requestSize uint16) (Syncer, error)

// SetLastAccepted is used after state-sync to reset the last accepted block.
SetLastAccepted(lastAcceptedHash common.Hash)

Expand Down Expand Up @@ -356,12 +351,6 @@ func (a *atomicBackend) MarkApplyToSharedMemoryCursor(previousLastAcceptedHeight
return database.PutUInt64(a.metadataDB, appliedSharedMemoryCursorKey, previousLastAcceptedHeight+1)
}

// Syncer creates and returns a new Syncer object that can be used to sync the
// state of the atomic trie from peers
func (a *atomicBackend) Syncer(client syncclient.LeafClient, targetRoot common.Hash, targetHeight uint64, requestSize uint16) (Syncer, error) {
return newAtomicSyncer(client, a, targetRoot, targetHeight, requestSize)
}

func (a *atomicBackend) GetVerifiedAtomicState(blockHash common.Hash) (AtomicState, error) {
if state, ok := a.verifiedRoots[blockHash]; ok {
return state, nil
Expand Down
5 changes: 2 additions & 3 deletions plugin/evm/atomic_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ func addZeroes(height uint64) []byte {
return packer.Bytes
}

func newAtomicSyncer(client syncclient.LeafClient, atomicBackend *atomicBackend, targetRoot common.Hash, targetHeight uint64, requestSize uint16) (*atomicSyncer, error) {
atomicTrie := atomicBackend.AtomicTrie()
func newAtomicSyncer(client syncclient.LeafClient, vdb *versiondb.Database, atomicTrie AtomicTrie, targetRoot common.Hash, targetHeight uint64, requestSize uint16) (*atomicSyncer, error) {
lastCommittedRoot, lastCommit := atomicTrie.LastCommitted()
trie, err := atomicTrie.OpenTrie(lastCommittedRoot)
if err != nil {
return nil, err
}

atomicSyncer := &atomicSyncer{
db: atomicBackend.db,
db: vdb,
atomicTrie: atomicTrie,
trie: trie,
targetRoot: targetRoot,
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/atomic_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func testAtomicSyncer(t *testing.T, serverTrieDB *triedb.Database, targetHeight
// next trie.
for i, checkpoint := range checkpoints {
// Create syncer targeting the current [syncTrie].
syncer, err := atomicBackend.Syncer(mockClient, targetRoot, targetHeight, config.DefaultStateSyncRequestSize)
syncer, err := newAtomicSyncer(mockClient, clientDB, atomicBackend.AtomicTrie(), targetRoot, targetHeight, config.DefaultStateSyncRequestSize)
if err != nil {
t.Fatal(err)
}
Expand All @@ -92,7 +92,7 @@ func testAtomicSyncer(t *testing.T, serverTrieDB *triedb.Database, targetHeight
}

// Create syncer targeting the current [targetRoot].
syncer, err := atomicBackend.Syncer(mockClient, targetRoot, targetHeight, config.DefaultStateSyncRequestSize)
syncer, err := newAtomicSyncer(mockClient, clientDB, atomicBackend.AtomicTrie(), targetRoot, targetHeight, config.DefaultStateSyncRequestSize)
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 8 additions & 1 deletion plugin/evm/syncervm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,14 @@ func (client *stateSyncerClient) syncBlocks(ctx context.Context, fromHash common

func (client *stateSyncerClient) syncAtomicTrie(ctx context.Context) error {
log.Info("atomic tx: sync starting", "root", client.syncSummary.AtomicRoot)
atomicSyncer, err := client.atomicBackend.Syncer(client.client, client.syncSummary.AtomicRoot, client.syncSummary.BlockNumber, client.stateSyncRequestSize)
atomicSyncer, err := newAtomicSyncer(
client.client,
client.db,
client.atomicBackend.AtomicTrie(),
client.syncSummary.AtomicRoot,
client.syncSummary.BlockNumber,
client.stateSyncRequestSize,
)
if err != nil {
return err
}
Expand Down

0 comments on commit b6b4dfb

Please sign in to comment.