Wait table nit
This commit is contained in:
parent
08dfb32a78
commit
08af56517c
2 changed files with 13 additions and 13 deletions
|
@ -288,7 +288,7 @@ func (i *Indexer) BlockAdded(ctx context.Context, block *types.Block) error {
|
|||
for _, transaction := range block.Transactions {
|
||||
ops += len(transaction.Operations)
|
||||
txHash := transaction.TransactionIdentifier.Hash
|
||||
val, ok := i.waiter.Get(txHash, true)
|
||||
val, ok := i.waiter.Get(txHash, false)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ func (i *Indexer) findCoin(
|
|||
// Put Transaction in WaitTable if doesn't already exist (could be
|
||||
// multiple listeners)
|
||||
transactionHash := bitcoin.TransactionHash(coinIdentifier)
|
||||
val, ok := i.waiter.Get(transactionHash, true)
|
||||
val, ok := i.waiter.Get(transactionHash, false)
|
||||
if !ok {
|
||||
val = &waitTableEntry{
|
||||
channel: make(chan struct{}),
|
||||
|
@ -446,7 +446,7 @@ func (i *Indexer) findCoin(
|
|||
val.earliestBlock = btcBlock.Height
|
||||
}
|
||||
val.listeners++
|
||||
i.waiter.Set(transactionHash, val, true)
|
||||
i.waiter.Set(transactionHash, val, false)
|
||||
i.waiter.Unlock()
|
||||
|
||||
return nil, nil, errMissingTransaction
|
||||
|
@ -517,7 +517,7 @@ func (i *Indexer) findCoins(
|
|||
for _, coinIdentifier := range remainingCoins {
|
||||
// Wait on Channel
|
||||
txHash := bitcoin.TransactionHash(coinIdentifier)
|
||||
entry, ok := i.waiter.Get(txHash, false)
|
||||
entry, ok := i.waiter.Get(txHash, true)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("transaction %s not in waiter", txHash)
|
||||
}
|
||||
|
@ -530,7 +530,7 @@ func (i *Indexer) findCoins(
|
|||
|
||||
// Delete Transaction from WaitTable if last listener
|
||||
i.waiter.Lock()
|
||||
val, ok := i.waiter.Get(txHash, true)
|
||||
val, ok := i.waiter.Get(txHash, false)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("transaction %s not in waiter", txHash)
|
||||
}
|
||||
|
@ -544,9 +544,9 @@ func (i *Indexer) findCoins(
|
|||
|
||||
val.listeners--
|
||||
if val.listeners == 0 {
|
||||
i.waiter.Delete(txHash, true)
|
||||
i.waiter.Delete(txHash, false)
|
||||
} else {
|
||||
i.waiter.Set(txHash, val, true)
|
||||
i.waiter.Set(txHash, val, false)
|
||||
}
|
||||
i.waiter.Unlock()
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ func (t *waitTable) Unlock() {
|
|||
t.lock.Unlock()
|
||||
}
|
||||
|
||||
func (t *waitTable) Get(key string, unsafe bool) (*waitTableEntry, bool) {
|
||||
if !unsafe {
|
||||
func (t *waitTable) Get(key string, safe bool) (*waitTableEntry, bool) {
|
||||
if safe {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
}
|
||||
|
@ -54,16 +54,16 @@ func (t *waitTable) Get(key string, unsafe bool) (*waitTableEntry, bool) {
|
|||
return v, true
|
||||
}
|
||||
|
||||
func (t *waitTable) Set(key string, value *waitTableEntry, unsafe bool) {
|
||||
if !unsafe {
|
||||
func (t *waitTable) Set(key string, value *waitTableEntry, safe bool) {
|
||||
if safe {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
}
|
||||
t.table[key] = value
|
||||
}
|
||||
|
||||
func (t *waitTable) Delete(key string, unsafe bool) {
|
||||
if !unsafe {
|
||||
func (t *waitTable) Delete(key string, safe bool) {
|
||||
if safe {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue