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 {
|
for _, transaction := range block.Transactions {
|
||||||
ops += len(transaction.Operations)
|
ops += len(transaction.Operations)
|
||||||
txHash := transaction.TransactionIdentifier.Hash
|
txHash := transaction.TransactionIdentifier.Hash
|
||||||
val, ok := i.waiter.Get(txHash, true)
|
val, ok := i.waiter.Get(txHash, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,7 @@ func (i *Indexer) findCoin(
|
||||||
// Put Transaction in WaitTable if doesn't already exist (could be
|
// Put Transaction in WaitTable if doesn't already exist (could be
|
||||||
// multiple listeners)
|
// multiple listeners)
|
||||||
transactionHash := bitcoin.TransactionHash(coinIdentifier)
|
transactionHash := bitcoin.TransactionHash(coinIdentifier)
|
||||||
val, ok := i.waiter.Get(transactionHash, true)
|
val, ok := i.waiter.Get(transactionHash, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
val = &waitTableEntry{
|
val = &waitTableEntry{
|
||||||
channel: make(chan struct{}),
|
channel: make(chan struct{}),
|
||||||
|
@ -446,7 +446,7 @@ func (i *Indexer) findCoin(
|
||||||
val.earliestBlock = btcBlock.Height
|
val.earliestBlock = btcBlock.Height
|
||||||
}
|
}
|
||||||
val.listeners++
|
val.listeners++
|
||||||
i.waiter.Set(transactionHash, val, true)
|
i.waiter.Set(transactionHash, val, false)
|
||||||
i.waiter.Unlock()
|
i.waiter.Unlock()
|
||||||
|
|
||||||
return nil, nil, errMissingTransaction
|
return nil, nil, errMissingTransaction
|
||||||
|
@ -517,7 +517,7 @@ func (i *Indexer) findCoins(
|
||||||
for _, coinIdentifier := range remainingCoins {
|
for _, coinIdentifier := range remainingCoins {
|
||||||
// Wait on Channel
|
// Wait on Channel
|
||||||
txHash := bitcoin.TransactionHash(coinIdentifier)
|
txHash := bitcoin.TransactionHash(coinIdentifier)
|
||||||
entry, ok := i.waiter.Get(txHash, false)
|
entry, ok := i.waiter.Get(txHash, true)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("transaction %s not in waiter", txHash)
|
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
|
// Delete Transaction from WaitTable if last listener
|
||||||
i.waiter.Lock()
|
i.waiter.Lock()
|
||||||
val, ok := i.waiter.Get(txHash, true)
|
val, ok := i.waiter.Get(txHash, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("transaction %s not in waiter", txHash)
|
return nil, fmt.Errorf("transaction %s not in waiter", txHash)
|
||||||
}
|
}
|
||||||
|
@ -544,9 +544,9 @@ func (i *Indexer) findCoins(
|
||||||
|
|
||||||
val.listeners--
|
val.listeners--
|
||||||
if val.listeners == 0 {
|
if val.listeners == 0 {
|
||||||
i.waiter.Delete(txHash, true)
|
i.waiter.Delete(txHash, false)
|
||||||
} else {
|
} else {
|
||||||
i.waiter.Set(txHash, val, true)
|
i.waiter.Set(txHash, val, false)
|
||||||
}
|
}
|
||||||
i.waiter.Unlock()
|
i.waiter.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ func (t *waitTable) Unlock() {
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *waitTable) Get(key string, unsafe bool) (*waitTableEntry, bool) {
|
func (t *waitTable) Get(key string, safe bool) (*waitTableEntry, bool) {
|
||||||
if !unsafe {
|
if safe {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -54,16 +54,16 @@ func (t *waitTable) Get(key string, unsafe bool) (*waitTableEntry, bool) {
|
||||||
return v, true
|
return v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *waitTable) Set(key string, value *waitTableEntry, unsafe bool) {
|
func (t *waitTable) Set(key string, value *waitTableEntry, safe bool) {
|
||||||
if !unsafe {
|
if safe {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
}
|
}
|
||||||
t.table[key] = value
|
t.table[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *waitTable) Delete(key string, unsafe bool) {
|
func (t *waitTable) Delete(key string, safe bool) {
|
||||||
if !unsafe {
|
if safe {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue