chainntfs: include height in spending+conf notifications

This commit is contained in:
Olaoluwa Osuntokun 2016-06-20 21:33:41 -07:00
parent 7bff2e07a8
commit 43c84c2ce5
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 19 additions and 10 deletions

@ -168,6 +168,9 @@ out:
case *spendNotification: case *spendNotification:
b.spendNotifications[*msg.targetOutpoint] = msg b.spendNotifications[*msg.targetOutpoint] = msg
case *confirmationsNotification: case *confirmationsNotification:
chainntnfs.Log.Infof("New confirmations "+
"subscription: txid=%v, numconfs=%v",
*msg.txid, msg.numConfirmations)
b.confNotifications[*msg.txid] = msg b.confNotifications[*msg.txid] = msg
} }
case staleBlockHash := <-b.disconnectedBlockHashes: case staleBlockHash := <-b.disconnectedBlockHashes:
@ -182,6 +185,9 @@ out:
continue continue
} }
chainntnfs.Log.Infof("New block: height=%v, sha=%v",
connectedBlock.height, connectedBlock.sha)
newHeight := connectedBlock.height newHeight := connectedBlock.height
for _, tx := range newBlock.Transactions() { for _, tx := range newBlock.Transactions() {
// Check if the inclusion of this transaction // Check if the inclusion of this transaction
@ -247,7 +253,7 @@ func (b *BtcdNotifier) notifyConfs(newBlockHeight int32) {
// is eligible until there are no more eligible entries. // is eligible until there are no more eligible entries.
nextConf := heap.Pop(b.confHeap).(*confEntry) nextConf := heap.Pop(b.confHeap).(*confEntry)
for nextConf.triggerHeight <= uint32(newBlockHeight) { for nextConf.triggerHeight <= uint32(newBlockHeight) {
nextConf.finConf <- struct{}{} nextConf.finConf <- newBlockHeight
if b.confHeap.Len() == 0 { if b.confHeap.Len() == 0 {
return return
@ -273,7 +279,10 @@ func (b *BtcdNotifier) checkConfirmationTrigger(txSha *wire.ShaHash, blockHeight
if confNtfn, ok := b.confNotifications[*txSha]; ok { if confNtfn, ok := b.confNotifications[*txSha]; ok {
delete(b.confNotifications, *txSha) delete(b.confNotifications, *txSha)
if confNtfn.numConfirmations == 1 { if confNtfn.numConfirmations == 1 {
confNtfn.finConf <- struct{}{} chainntnfs.Log.Infof("Dispatching single conf "+
"notification, sha=%v, height=%v", txSha,
blockHeight)
confNtfn.finConf <- blockHeight
return return
} }
@ -328,7 +337,7 @@ type confirmationsNotification struct {
initialConfirmHeight uint32 initialConfirmHeight uint32
numConfirmations uint32 numConfirmations uint32
finConf chan struct{} finConf chan int32
negativeConf chan int32 // TODO(roasbeef): re-org funny business negativeConf chan int32 // TODO(roasbeef): re-org funny business
} }
@ -341,7 +350,7 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *wire.ShaHash,
ntfn := &confirmationsNotification{ ntfn := &confirmationsNotification{
txid: txid, txid: txid,
numConfirmations: numConfs, numConfirmations: numConfs,
finConf: make(chan struct{}, 1), finConf: make(chan int32, 1),
negativeConf: make(chan int32, 1), negativeConf: make(chan int32, 1),
} }

@ -6,12 +6,12 @@ import (
"time" "time"
"github.com/Roasbeef/btcd/rpctest" "github.com/Roasbeef/btcd/rpctest"
"github.com/lightningnetwork/lnd/chainntfs"
"github.com/roasbeef/btcd/btcec" "github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg" "github.com/roasbeef/btcd/chaincfg"
"github.com/roasbeef/btcd/txscript" "github.com/roasbeef/btcd/txscript"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
"github.com/lightningnetwork/lnd/chainntfs"
) )
var ( var (
@ -68,7 +68,7 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
t.Fatalf("unable to generate single block: %v", err) t.Fatalf("unable to generate single block: %v", err)
} }
confSent := make(chan struct{}) confSent := make(chan int32)
go func() { go func() {
confSent <- <-confIntent.Confirmed confSent <- <-confIntent.Confirmed
}() }()
@ -105,7 +105,7 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
t.Fatalf("unable to generate single block: %v", err) t.Fatalf("unable to generate single block: %v", err)
} }
confSent := make(chan struct{}) confSent := make(chan int32)
go func() { go func() {
confSent <- <-confIntent.Confirmed confSent <- <-confIntent.Confirmed
}() }()
@ -163,7 +163,7 @@ func testBatchConfirmationNotification(miner *rpctest.Harness,
t.Fatalf("unable to generate single block: %v", err) t.Fatalf("unable to generate single block: %v", err)
} }
confSent := make(chan struct{}) confSent := make(chan int32)
go func() { go func() {
confSent <- <-confIntents[i].Confirmed confSent <- <-confIntents[i].Confirmed
}() }()

@ -62,8 +62,7 @@ type ChainNotifier interface {
// chain, the 'NegativeConf' will be sent upon with a value representing the // chain, the 'NegativeConf' will be sent upon with a value representing the
// depth of the re-org. // depth of the re-org.
type ConfirmationEvent struct { type ConfirmationEvent struct {
Confirmed chan struct{} // MUST be buffered. Confirmed chan int32 // MUST be buffered.
// TODO(roasbeef): all goroutines on ln channel updates should also // TODO(roasbeef): all goroutines on ln channel updates should also
// have a struct chan that's closed if funding gets re-org out. Need // have a struct chan that's closed if funding gets re-org out. Need
// to sync, to request another confirmation event ntfn, then re-open // to sync, to request another confirmation event ntfn, then re-open
@ -82,6 +81,7 @@ type SpendDetail struct {
SpenderTxHash *wire.ShaHash SpenderTxHash *wire.ShaHash
SpendingTx *wire.MsgTx SpendingTx *wire.MsgTx
SpenderInputIndex uint32 SpenderInputIndex uint32
SpendingHeight int32
} }
// SpendEvent encapsulates a spentness notification. Its only field 'Spend' will // SpendEvent encapsulates a spentness notification. Its only field 'Spend' will