From 083deeb592ea1b8c393e1fe3321c23e758e1b201 Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Fri, 8 Nov 2024 15:38:01 +0100 Subject: [PATCH] remove additional locks --- services/ingestion/engine.go | 1 + storage/pebble/blocks.go | 29 ----------------------------- storage/pebble/traces.go | 9 --------- 3 files changed, 1 insertion(+), 38 deletions(-) diff --git a/services/ingestion/engine.go b/services/ingestion/engine.go index 4486bdf81..ab7a01c78 100644 --- a/services/ingestion/engine.go +++ b/services/ingestion/engine.go @@ -3,6 +3,7 @@ package ingestion import ( "context" "fmt" + flowGo "github.com/onflow/flow-go/model/flow" pebbleDB "github.com/cockroachdb/pebble" diff --git a/storage/pebble/blocks.go b/storage/pebble/blocks.go index 5643ba70b..42099b1d4 100644 --- a/storage/pebble/blocks.go +++ b/storage/pebble/blocks.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "slices" - "sync" "github.com/cockroachdb/pebble" "github.com/onflow/flow-go-sdk" @@ -27,7 +26,6 @@ var _ storage.BlockIndexer = &Blocks{} type Blocks struct { store *Storage - mux sync.RWMutex chainID flowGo.ChainID } @@ -35,7 +33,6 @@ func NewBlocks(store *Storage, chainID flowGo.ChainID) *Blocks { return &Blocks{ store: store, chainID: chainID, - mux: sync.RWMutex{}, } } @@ -45,8 +42,6 @@ func (b *Blocks) Store( block *models.Block, batch *pebble.Batch, ) error { - b.mux.Lock() - defer b.mux.Unlock() // dev note: please be careful if any store reads are added here, // store.batchGet must be used instead and batch must be used @@ -122,9 +117,6 @@ func (b *Blocks) Store( } func (b *Blocks) GetByHeight(height uint64) (*models.Block, error) { - b.mux.RLock() - defer b.mux.RUnlock() - last, err := b.latestEVMHeight() if err != nil { return nil, err @@ -144,9 +136,6 @@ func (b *Blocks) GetByHeight(height uint64) (*models.Block, error) { } func (b *Blocks) GetByID(ID common.Hash) (*models.Block, error) { - b.mux.RLock() - defer b.mux.RUnlock() - height, err := b.store.get(blockIDToHeightKey, ID.Bytes()) if err != nil { return nil, fmt.Errorf("failed to get EVM block by ID: %s, with: %w", ID, err) @@ -165,9 +154,6 @@ func (b *Blocks) GetByID(ID common.Hash) (*models.Block, error) { } func (b *Blocks) GetHeightByID(ID common.Hash) (uint64, error) { - b.mux.RLock() - defer b.mux.RUnlock() - height, err := b.store.get(blockIDToHeightKey, ID.Bytes()) if err != nil { return 0, fmt.Errorf("failed to get EVM block by ID: %s, with: %w", ID, err) @@ -177,9 +163,6 @@ func (b *Blocks) GetHeightByID(ID common.Hash) (uint64, error) { } func (b *Blocks) LatestEVMHeight() (uint64, error) { - b.mux.RLock() - defer b.mux.RUnlock() - return b.latestEVMHeight() } @@ -196,9 +179,6 @@ func (b *Blocks) latestEVMHeight() (uint64, error) { } func (b *Blocks) LatestCadenceHeight() (uint64, error) { - b.mux.RLock() - defer b.mux.RUnlock() - val, err := b.store.get(latestCadenceHeightKey) if err != nil { if errors.Is(err, errs.ErrEntityNotFound) { @@ -211,9 +191,6 @@ func (b *Blocks) LatestCadenceHeight() (uint64, error) { } func (b *Blocks) SetLatestCadenceHeight(height uint64, batch *pebble.Batch) error { - b.mux.Lock() - defer b.mux.Unlock() - if err := b.store.set(latestCadenceHeightKey, nil, uint64Bytes(height), batch); err != nil { return fmt.Errorf("failed to store latest Cadence height: %d, with: %w", height, err) } @@ -247,9 +224,6 @@ func (b *Blocks) InitHeights(cadenceHeight uint64, cadenceID flow.Identifier, ba } func (b *Blocks) GetCadenceHeight(evmHeight uint64) (uint64, error) { - b.mux.RLock() - defer b.mux.RUnlock() - val, err := b.store.get(evmHeightToCadenceHeightKey, uint64Bytes(evmHeight)) if err != nil { return 0, err @@ -259,9 +233,6 @@ func (b *Blocks) GetCadenceHeight(evmHeight uint64) (uint64, error) { } func (b *Blocks) GetCadenceID(evmHeight uint64) (flow.Identifier, error) { - b.mux.RLock() - defer b.mux.RUnlock() - val, err := b.store.get(evmHeightToCadenceIDKey, uint64Bytes(evmHeight)) if err != nil { return flow.Identifier{}, err diff --git a/storage/pebble/traces.go b/storage/pebble/traces.go index b3174d04c..7de1784d8 100644 --- a/storage/pebble/traces.go +++ b/storage/pebble/traces.go @@ -2,7 +2,6 @@ package pebble import ( "fmt" - "sync" "github.com/cockroachdb/pebble" "github.com/goccy/go-json" @@ -15,20 +14,15 @@ var _ storage.TraceIndexer = &Traces{} type Traces struct { store *Storage - mux sync.RWMutex } func NewTraces(store *Storage) *Traces { return &Traces{ store: store, - mux: sync.RWMutex{}, } } func (t *Traces) StoreTransaction(ID common.Hash, trace json.RawMessage, batch *pebble.Batch) error { - t.mux.Lock() - defer t.mux.Unlock() - if err := t.store.set(traceTxIDKey, ID.Bytes(), trace, batch); err != nil { return fmt.Errorf("failed to store trace for transaction ID %s: %w", ID.String(), err) } @@ -37,9 +31,6 @@ func (t *Traces) StoreTransaction(ID common.Hash, trace json.RawMessage, batch * } func (t *Traces) GetTransaction(ID common.Hash) (json.RawMessage, error) { - t.mux.RLock() - defer t.mux.RUnlock() - val, err := t.store.get(traceTxIDKey, ID.Bytes()) if err != nil { return nil, fmt.Errorf("failed to get trace for transaction ID %s: %w", ID.String(), err)