reorganize bisect function so we lock it properly
This commit is contained in:
parent
ac77edcace
commit
7d492948ce
2 changed files with 19 additions and 6 deletions
|
@ -37,11 +37,7 @@ func PrepareResolveResult(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var txCounts []interface{}
|
||||
txCounts = db.TxCounts.GetSlice()
|
||||
txCounts = txCounts[:db.TxCounts.Len()]
|
||||
height := BisectRight(txCounts, txNum)
|
||||
createdHeight := BisectRight(txCounts, rootTxNum)
|
||||
height, createdHeight := db.TxCounts.TxCountsBisectRight(txNum, rootTxNum, BisectRight)
|
||||
lastTakeoverHeight := controllingClaim.Height
|
||||
|
||||
expirationHeight := GetExpirationHeight(height)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package db_stack
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type SliceBackedStack struct {
|
||||
slice []interface{}
|
||||
|
@ -77,3 +79,18 @@ func (s *SliceBackedStack) GetSlice() []interface{} {
|
|||
// This is not thread safe so I won't bother with locking
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// This function is dangerous because it assumes underlying types
|
||||
func (s *SliceBackedStack) TxCountsBisectRight(
|
||||
txNum, rootTxNum uint32,
|
||||
bisectFunc func([]interface{}, uint32) uint32,
|
||||
) (uint32, uint32) {
|
||||
s.mut.RLock()
|
||||
defer s.mut.RUnlock()
|
||||
|
||||
txCounts := s.slice[:s.Len()]
|
||||
height := bisectFunc(txCounts, txNum)
|
||||
createdHeight := bisectFunc(txCounts, rootTxNum)
|
||||
|
||||
return height, createdHeight
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue