Skip to content

Commit

Permalink
fix: add read locks in ledger query functions (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney committed Sep 17, 2024
1 parent 41c8689 commit d8ecccf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ func (ls *LedgerState) removeBlock(txn *database.Txn, block models.Block) error
}

func (ls *LedgerState) GetBlock(point ocommon.Point) (*models.Block, error) {
ls.RLock()
defer ls.RUnlock()
ret, err := models.BlockByPoint(ls.db, point)
if err != nil {
return nil, err
Expand Down Expand Up @@ -368,6 +370,8 @@ func (ls *LedgerState) RecentChainPoints(count int) ([]ocommon.Point, error) {

// GetIntersectPoint returns the intersect between the specified points and the current chain
func (ls *LedgerState) GetIntersectPoint(points []ocommon.Point) (*ocommon.Point, error) {
ls.RLock()
defer ls.RUnlock()
var ret ocommon.Point
for _, point := range points {
// Ignore points with a slot earlier than an existing match
Expand Down

0 comments on commit d8ecccf

Please sign in to comment.