Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip bonus blocks applying atomic ops from trie to shared memory #409

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion plugin/evm/atomic_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,16 @@ func (a *atomicBackend) ApplyToSharedMemory(lastAcceptedBlock uint64) error {
break
}

atomicOps := it.AtomicOps()
// If [height] is a bonus block, do not apply the atomic operations to shared memory
if _, found := a.bonusBlocks[height]; found {
log.Debug(
"skipping bonus block in applying atomic ops from atomic trie to shared memory",
"height", height,
)
continue
}

atomicOps := it.AtomicOps()
putRequests += len(atomicOps.PutRequests)
removeRequests += len(atomicOps.RemoveRequests)
totalPutRequests += len(atomicOps.PutRequests)
Expand Down
15 changes: 14 additions & 1 deletion plugin/evm/atomic_trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ func TestApplyToSharedMemory(t *testing.T) {
commitInterval, lastAcceptedHeight uint64
setMarker func(*atomicBackend) error
expectOpsApplied func(height uint64) bool
bonusBlockHeights map[uint64]ids.ID
}

for name, test := range map[string]test{
Expand All @@ -493,6 +494,18 @@ func TestApplyToSharedMemory(t *testing.T) {
setMarker: func(a *atomicBackend) error { return a.MarkApplyToSharedMemoryCursor(10) },
expectOpsApplied: func(height uint64) bool { return height > 10 && height <= 20 },
},
"marker is set to height, should skip bonus blocks": {
commitInterval: 10,
lastAcceptedHeight: 25,
setMarker: func(a *atomicBackend) error { return a.MarkApplyToSharedMemoryCursor(10) },
bonusBlockHeights: map[uint64]ids.ID{15: {}},
expectOpsApplied: func(height uint64) bool {
if height == 15 {
return false
}
return height > 10 && height <= 20
},
},
"marker is set to height + blockchain ID": {
commitInterval: 10,
lastAcceptedHeight: 25,
Expand Down Expand Up @@ -522,7 +535,7 @@ func TestApplyToSharedMemory(t *testing.T) {
// Initialize atomic repository
m := atomic.NewMemory(db)
sharedMemories := newSharedMemories(m, testCChainID, blockChainID)
backend, err := NewAtomicBackend(db, sharedMemories.thisChain, nil, repo, test.lastAcceptedHeight, common.Hash{}, test.commitInterval)
backend, err := NewAtomicBackend(db, sharedMemories.thisChain, test.bonusBlockHeights, repo, test.lastAcceptedHeight, common.Hash{}, test.commitInterval)
assert.NoError(t, err)
atomicTrie := backend.AtomicTrie().(*atomicTrie)

Expand Down