From d8ecccf7f1dfb1b24b1c7f1eecd884be111e44f4 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Tue, 17 Sep 2024 15:56:17 -0500 Subject: [PATCH] fix: add read locks in ledger query functions (#128) --- state/state.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/state/state.go b/state/state.go index b355b59..80f566b 100644 --- a/state/state.go +++ b/state/state.go @@ -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 @@ -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