Skip to content

Commit 8df941a

Browse files
committed
Bugfix when updating input addresses (pointer to range variable)
1 parent 0d2aba6 commit 8df941a

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

indexer/pchain/in_updater.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func (iu *pChainInputUpdater) updateFromDB(
4646
return nil, err
4747
}
4848
baseOuts := shared.NewOutputMap()
49-
for _, out := range outs {
50-
baseOuts.Add(shared.NewIdIndexKey(out.TxID, out.Index()), &out.TxOutput)
49+
for i, out := range outs {
50+
baseOuts.Add(shared.NewIdIndexKey(out.TxID, out.Index()), &outs[i].TxOutput)
5151
}
5252
return inputs.UpdateWithOutputs(baseOuts), nil
5353
}

utils/cache.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type Cache[K comparable, V any] interface {
1717

1818
// Map object cache
1919
type cache[K comparable, V any] struct {
20-
sync.RWMutex
21-
2220
cacheMap map[K]V
2321
accessed []K
22+
23+
sync.RWMutex
2424
}
2525

2626
func NewCache[K comparable, V any]() Cache[K, V] {
@@ -31,24 +31,29 @@ func NewCache[K comparable, V any]() Cache[K, V] {
3131
}
3232

3333
func (c *cache[K, V]) Add(k K, v V) {
34+
c.Lock()
35+
defer c.Unlock()
36+
3437
c.cacheMap[k] = v
3538
}
3639

3740
func (c *cache[K, V]) Get(k K) (V, bool) {
38-
c.RWMutex.Lock()
41+
c.Lock()
42+
defer c.Unlock()
43+
3944
v, ok := c.cacheMap[k]
4045
if ok {
4146
c.accessed = append(c.accessed, k)
4247
}
43-
c.RWMutex.Unlock()
4448
return v, ok
4549
}
4650

4751
func (c *cache[K, V]) RemoveAccessed() {
48-
c.RWMutex.Lock()
52+
c.Lock()
53+
defer c.Unlock()
54+
4955
for _, k := range c.accessed {
5056
delete(c.cacheMap, k)
5157
}
5258
c.accessed = nil
53-
c.RWMutex.Unlock()
5459
}

0 commit comments

Comments
 (0)