pkg/leaderschedule: use RWMutex for bySlot

This commit is contained in:
Leopold Schabel 2022-06-15 23:54:35 +02:00
parent a6b1ef02cf
commit 4cfb389389
1 changed files with 3 additions and 3 deletions

View File

@ -23,7 +23,7 @@ type Tracker struct {
// bySlot maps slots to their leader. Grows indefinitely as epochs progress.
bySlot map[uint64]solana.PublicKey
bySlotMu sync.Mutex
bySlotMu sync.RWMutex
// slotsPerEpoch is the number of slots per epoch on the network.
// Fetched once via RPC. Used to calculate epoch boundaries.
@ -188,8 +188,8 @@ func (t *Tracker) Get(slot uint64) solana.PublicKey {
<-t.initCh
}
t.bySlotMu.Lock()
defer t.bySlotMu.Unlock()
t.bySlotMu.RLock()
defer t.bySlotMu.RUnlock()
return t.bySlot[slot]
}