Skip to content

Commit 2a813e3

Browse files
authored
use explicity structs and innervm calls (#1015)
1 parent b0b3d39 commit 2a813e3

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

plugin/evm/atomic/sync/extender.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@ import (
1616
"github.com/ava-labs/libevm/log"
1717
)
1818

19-
var _ sync.Extender = (*extender)(nil)
19+
var _ sync.Extender = (*Extender)(nil)
2020

21-
type extender struct {
21+
// Extender is the sync extender for the atomic VM.
22+
type Extender struct {
2223
backend *state.AtomicBackend
2324
trie *state.AtomicTrie
2425
requestSize uint16 // maximum number of leaves to sync in a single request
2526
}
2627

27-
// Initialize initializes the sync extender with the backend and trie.
28-
func NewExtender() *extender {
29-
return &extender{}
30-
}
31-
32-
func (a *extender) Initialize(backend *state.AtomicBackend, trie *state.AtomicTrie, requestSize uint16) {
28+
// Initialize initializes the sync extender with the backend and trie and request size.
29+
func (a *Extender) Initialize(backend *state.AtomicBackend, trie *state.AtomicTrie, requestSize uint16) {
3330
a.backend = backend
3431
a.trie = trie
3532
a.requestSize = requestSize
3633
}
3734

38-
func (a *extender) Sync(ctx context.Context, client syncclient.LeafClient, verDB *versiondb.Database, summary message.Syncable) error {
35+
// Sync syncs the atomic summary with the given client and verDB.
36+
func (a *Extender) Sync(ctx context.Context, client syncclient.LeafClient, verDB *versiondb.Database, summary message.Syncable) error {
3937
atomicSummary, ok := summary.(*Summary)
4038
if !ok {
4139
return fmt.Errorf("expected *Summary, got %T", summary)
@@ -60,7 +58,8 @@ func (a *extender) Sync(ctx context.Context, client syncclient.LeafClient, verDB
6058
return err
6159
}
6260

63-
func (a *extender) OnFinishBeforeCommit(lastAcceptedHeight uint64, Summary message.Syncable) error {
61+
// OnFinishBeforeCommit implements the sync.Extender interface by marking the previously last accepted block for the shared memory cursor.
62+
func (a *Extender) OnFinishBeforeCommit(lastAcceptedHeight uint64, Summary message.Syncable) error {
6463
// Mark the previously last accepted block for the shared memory cursor, so that we will execute shared
6564
// memory operations from the previously last accepted block when ApplyToSharedMemory
6665
// is called.
@@ -71,7 +70,8 @@ func (a *extender) OnFinishBeforeCommit(lastAcceptedHeight uint64, Summary messa
7170
return nil
7271
}
7372

74-
func (a *extender) OnFinishAfterCommit(summaryHeight uint64) error {
73+
// OnFinishAfterCommit implements the sync.Extender interface by applying the atomic trie to the shared memory.
74+
func (a *Extender) OnFinishAfterCommit(summaryHeight uint64) error {
7575
// the chain state is already restored, and, from this point on,
7676
// the block synced to is the accepted block. The last operation
7777
// is updating shared memory with the atomic trie.

plugin/evm/atomic/sync/leaf_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type leafHandler struct {
3434
handlers.LeafRequestHandler
3535
}
3636

37-
// NewAtomicLeafHandler returns a new uninitialzied atomicLeafHandler that can be later initialized
37+
// NewAtomicLeafHandler returns a new uninitialized leafHandler that can be later initialized
3838
func NewLeafHandler() *leafHandler {
3939
return &leafHandler{
4040
LeafRequestHandler: &uninitializedHandler{},

plugin/evm/atomic/sync/summary_provider.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ import (
1414
"github.com/ava-labs/libevm/core/types"
1515
)
1616

17-
var _ sync.SummaryProvider = (*summaryProvider)(nil)
17+
var _ sync.SummaryProvider = (*SummaryProvider)(nil)
1818

19-
type summaryProvider struct {
19+
// SummaryProvider is the summary provider that provides the state summary for the atomic trie.
20+
type SummaryProvider struct {
2021
trie *state.AtomicTrie
2122
}
2223

23-
func NewSummaryProvider() *summaryProvider {
24-
return &summaryProvider{}
25-
}
26-
27-
func (a *summaryProvider) Initialize(trie *state.AtomicTrie) {
24+
// Initialize initializes the summary provider with the atomic trie.
25+
func (a *SummaryProvider) Initialize(trie *state.AtomicTrie) {
2826
a.trie = trie
2927
}
3028

3129
// StateSummaryAtBlock returns the block state summary at [blk] if valid.
32-
func (a *summaryProvider) StateSummaryAtBlock(blk *types.Block) (block.StateSummary, error) {
30+
func (a *SummaryProvider) StateSummaryAtBlock(blk *types.Block) (block.StateSummary, error) {
3331
height := blk.NumberU64()
3432
atomicRoot, err := a.trie.Root(height)
3533
if err != nil {

plugin/evm/atomic/vm/vm.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func (vm *VM) Initialize(
8686
// Create the atomic extension structs
8787
// some of them need to be initialized after the inner VM is initialized
8888
blockExtender := newBlockExtender(extDataHashes, vm)
89-
syncExtender := sync.NewExtender()
90-
syncProvider := sync.NewSummaryProvider()
89+
syncExtender := &sync.Extender{}
90+
syncProvider := &sync.SummaryProvider{}
9191
// Create and pass the leaf handler to the atomic extension
9292
// it will be initialized after the inner VM is initialized
9393
leafHandler := sync.NewLeafHandler()
@@ -105,7 +105,7 @@ func (vm *VM) Initialize(
105105
ExtraSyncLeafHandlerConfig: atomicLeafTypeConfig,
106106
Clock: &vm.clock,
107107
}
108-
if err := vm.SetExtensionConfig(extensionConfig); err != nil {
108+
if err := vm.InnerVM.SetExtensionConfig(extensionConfig); err != nil {
109109
return fmt.Errorf("failed to set extension config: %w", err)
110110
}
111111

@@ -125,13 +125,15 @@ func (vm *VM) Initialize(
125125
}
126126

127127
// Atomic backend is available now, we can initialize structs that depend on it
128-
syncProvider.Initialize(vm.AtomicBackend().AtomicTrie())
129-
syncExtender.Initialize(vm.AtomicBackend(), vm.AtomicBackend().AtomicTrie(), vm.Config().StateSyncRequestSize)
130-
leafHandler.Initialize(vm.AtomicBackend().AtomicTrie().TrieDB(), state.TrieKeyLength, message.Codec)
128+
atomicBackend := vm.InnerVM.AtomicBackend()
129+
atomicTrie := atomicBackend.AtomicTrie()
130+
syncProvider.Initialize(atomicTrie)
131+
syncExtender.Initialize(atomicBackend, atomicTrie, vm.Config().StateSyncRequestSize)
132+
leafHandler.Initialize(atomicTrie.TrieDB(), state.TrieKeyLength, message.Codec)
131133

132134
return nil
133135
}
134136

135137
func (vm *VM) chainConfigExtra() *extras.ChainConfig {
136-
return params.GetExtra(vm.Ethereum().BlockChain().Config())
138+
return params.GetExtra(vm.InnerVM.Ethereum().BlockChain().Config())
137139
}

0 commit comments

Comments
 (0)