Skip to content

Commit

Permalink
remove additional locks
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Nov 12, 2024
1 parent 58102b8 commit 083deeb
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 38 deletions.
1 change: 1 addition & 0 deletions services/ingestion/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ingestion
import (
"context"
"fmt"

flowGo "github.com/onflow/flow-go/model/flow"

pebbleDB "github.com/cockroachdb/pebble"
Expand Down
29 changes: 0 additions & 29 deletions storage/pebble/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"slices"
"sync"

"github.com/cockroachdb/pebble"
"github.com/onflow/flow-go-sdk"
Expand All @@ -27,15 +26,13 @@ var _ storage.BlockIndexer = &Blocks{}

type Blocks struct {
store *Storage
mux sync.RWMutex
chainID flowGo.ChainID
}

func NewBlocks(store *Storage, chainID flowGo.ChainID) *Blocks {
return &Blocks{
store: store,
chainID: chainID,
mux: sync.RWMutex{},
}
}

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
}

Expand All @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions storage/pebble/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pebble

import (
"fmt"
"sync"

"github.com/cockroachdb/pebble"
"github.com/goccy/go-json"
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit 083deeb

Please sign in to comment.