Skip to content

Commit f258d79

Browse files
committed
cleanup unused code, call storage even for empty data
1 parent 020e964 commit f258d79

File tree

8 files changed

+17
-62
lines changed

8 files changed

+17
-62
lines changed

module/executiondatasync/optimistic_sync/core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func (c *CoreImpl) Persist() error {
334334
persisterStores := []stores.PersisterStore{
335335
stores.NewEventsStore(indexerData.Events, c.workingData.persistentEvents, c.executionResult.BlockID),
336336
stores.NewResultsStore(indexerData.Results, c.workingData.persistentResults, c.executionResult.BlockID),
337-
stores.NewCollectionsStore(indexerData.Collections, c.workingData.persistentCollections, c.workingData.lockManager),
337+
stores.NewCollectionsStore(indexerData.Collections, c.workingData.persistentCollections),
338338
stores.NewTxResultErrMsgStore(c.workingData.txResultErrMsgsData, c.workingData.persistentTxResultErrMsgs, c.executionResult.BlockID),
339339
stores.NewLatestSealedResultStore(c.workingData.latestPersistedSealedResult, c.executionResult.ID(), c.block.Height),
340340
}

module/executiondatasync/optimistic_sync/persisters/block_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func (p *PersisterSuite) TestPersister_HappyPath() {
6767
}
6868

6969
func (p *PersisterSuite) TestPersister_EmptyData() {
70-
p.indexerData = &indexer.IndexerData{}
70+
p.indexerData = &indexer.IndexerData{
71+
// this is needed because the events storage caches an empty slice when no events are passed.
72+
// without it, assert.Equals will fail because nil != empty slice
73+
Events: []flow.Event{},
74+
}
7175
p.txErrMsgs = nil
7276
p.testWithDatabase()
7377
}
@@ -106,7 +110,7 @@ func (p *PersisterSuite) testWithDatabase() {
106110
[]stores.PersisterStore{
107111
stores.NewEventsStore(p.indexerData.Events, events, p.executionResult.BlockID),
108112
stores.NewResultsStore(p.indexerData.Results, results, p.executionResult.BlockID),
109-
stores.NewCollectionsStore(p.indexerData.Collections, collections, lockManager),
113+
stores.NewCollectionsStore(p.indexerData.Collections, collections),
110114
stores.NewTxResultErrMsgStore(p.txErrMsgs, txResultErrMsg, p.executionResult.BlockID),
111115
stores.NewLatestSealedResultStore(latestPersistedSealedResult, p.executionResult.ID(), p.header.Height),
112116
},
@@ -186,7 +190,7 @@ func (p *PersisterSuite) TestPersister_ErrorHandling() {
186190
lockManager,
187191
p.executionResult,
188192
[]stores.PersisterStore{
189-
stores.NewCollectionsStore(p.indexerData.Collections, collections, lockManager),
193+
stores.NewCollectionsStore(p.indexerData.Collections, collections),
190194
stores.NewEventsStore(p.indexerData.Events, events, p.executionResult.BlockID),
191195
},
192196
)
@@ -208,7 +212,7 @@ func (p *PersisterSuite) TestPersister_ErrorHandling() {
208212
lockManager,
209213
p.executionResult,
210214
[]stores.PersisterStore{
211-
stores.NewCollectionsStore(p.indexerData.Collections, collections, lockManager),
215+
stores.NewCollectionsStore(p.indexerData.Collections, collections),
212216
stores.NewEventsStore(p.indexerData.Events, events, p.executionResult.BlockID),
213217
},
214218
)

module/executiondatasync/optimistic_sync/persisters/stores/events.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ func NewEventsStore(
3434
//
3535
// No error returns are expected during normal operations
3636
func (e *EventsStore) Persist(_ lockctx.Proof, batch storage.ReaderBatchWriter) error {
37-
if len(e.data) > 0 {
38-
if err := e.persistedEvents.BatchStore(e.blockID, []flow.EventsList{e.data}, batch); err != nil {
39-
return fmt.Errorf("could not add events to batch: %w", err)
40-
}
37+
if err := e.persistedEvents.BatchStore(e.blockID, []flow.EventsList{e.data}, batch); err != nil {
38+
return fmt.Errorf("could not add events to batch: %w", err)
4139
}
4240
return nil
4341
}

module/executiondatasync/optimistic_sync/persisters/stores/light_collections.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type LightCollectionsStore struct {
2020
func NewCollectionsStore(
2121
data []*flow.Collection,
2222
persistedCollections storage.Collections,
23-
lockManager storage.LockManager,
2423
) *LightCollectionsStore {
2524
return &LightCollectionsStore{
2625
data: data,

module/executiondatasync/optimistic_sync/persisters/stores/persister_store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
// PersisterStore is the interface to handle persisting of a data type to persisted storage using batch operation.
1010
type PersisterStore interface {
1111
// Persist adds data to the batch for later commitment.
12-
// No errors are expected during normal operations
12+
//
13+
// No error returns are expected during normal operations
1314
Persist(lctx lockctx.Proof, batch storage.ReaderBatchWriter) error
1415
}

module/executiondatasync/optimistic_sync/persisters/stores/results.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ func NewResultsStore(
3434
//
3535
// No error returns are expected during normal operations
3636
func (r *ResultsStore) Persist(_ lockctx.Proof, batch storage.ReaderBatchWriter) error {
37-
if len(r.data) > 0 {
38-
if err := r.persistedResults.BatchStore(r.blockID, r.data, batch); err != nil {
39-
return fmt.Errorf("could not add transaction results to batch: %w", err)
40-
}
37+
if err := r.persistedResults.BatchStore(r.blockID, r.data, batch); err != nil {
38+
return fmt.Errorf("could not add transaction results to batch: %w", err)
4139
}
42-
4340
return nil
4441
}

module/executiondatasync/optimistic_sync/persisters/stores/transaction_result_error_messages.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ func NewTxResultErrMsgStore(
3434
//
3535
// No error returns are expected during normal operations
3636
func (t *TxResultErrMsgStore) Persist(_ lockctx.Proof, batch storage.ReaderBatchWriter) error {
37-
if len(t.data) > 0 {
38-
if err := t.persistedTxResultErrMsg.BatchStore(t.blockID, t.data, batch); err != nil {
39-
return fmt.Errorf("could not add transaction result error messages to batch: %w", err)
40-
}
37+
if err := t.persistedTxResultErrMsg.BatchStore(t.blockID, t.data, batch); err != nil {
38+
return fmt.Errorf("could not add transaction result error messages to batch: %w", err)
4139
}
42-
4340
return nil
4441
}

module/executiondatasync/optimistic_sync/persisters/stores/transactions.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)