Skip to content

Commit

Permalink
Skip bonus blocks applying atomic ops from trie to shared memory (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Dec 1, 2023
1 parent 0eef20a commit 0a6a7a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit 0a6a7a3

Please sign in to comment.