chainntnfs: ConfirmationEvent now returns details of tx confirmation

This commit modifies the ChainNotifier interface, specifically the
ConfirmationEvent struct to now return additional details concerning
the exact location in the chain that the transaction was confirmed at.

This information will be very useful within the new routing package, as
within the network, channels are identified via their channel-ID which
is a compact encoding of: blockHeight | txIndex | outputIndex
This commit is contained in:
Olaoluwa Osuntokun 2016-12-24 18:39:30 -06:00
parent 42c90794ac
commit 00b0c273da
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 25 additions and 7 deletions

@ -57,7 +57,21 @@ type ChainNotifier interface {
Stop() error
}
// TODO(roasbeef): all chans should be receive only.
// TxConfirmation carries some additional block-level details of the exact
// block that specified transactions was confirmed wihtin.
type TxConfirmation struct {
// BlockHash is the hash of the block that confirmed the original
// transition.
BlockHash *wire.ShaHash
// BlockHeight is the height of the block in which the transaction was
// confirmed within.
BlockHeight uint32
// TxIndex is the index within the block of the ultimate confirmed
// transaction.
TxIndex uint32
}
// ConfirmationEvent encapsulates a confirmation notification. With this struct,
// callers can be notified of: the instance the target txid reaches the targeted
@ -71,7 +85,11 @@ type ChainNotifier interface {
// chain, the 'NegativeConf' will be sent upon with a value representing the
// depth of the re-org.
type ConfirmationEvent struct {
Confirmed chan int32 // MUST be buffered.
// Confirmed is a channel that will be sent upon once the transaction
// has been fully confirmed. The struct sent will contain all the
// details of the channel's confirmation.
Confirmed chan *TxConfirmation // MUST be buffered.
// TODO(roasbeef): all goroutines on ln channel updates should also
// 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

@ -74,7 +74,7 @@ func testSingleConfirmationNotification(miner *rpctest.Harness,
t.Fatalf("unable to generate single block: %v", err)
}
confSent := make(chan int32)
confSent := make(chan *chainntnfs.TxConfirmation)
go func() {
confSent <- <-confIntent.Confirmed
}()
@ -113,7 +113,7 @@ func testMultiConfirmationNotification(miner *rpctest.Harness,
t.Fatalf("unable to generate single block: %v", err)
}
confSent := make(chan int32)
confSent := make(chan *chainntnfs.TxConfirmation)
go func() {
confSent <- <-confIntent.Confirmed
}()
@ -173,7 +173,7 @@ func testBatchConfirmationNotification(miner *rpctest.Harness,
t.Fatalf("unable to generate single block: %v", err)
}
confSent := make(chan int32)
confSent := make(chan *chainntnfs.TxConfirmation)
go func() {
confSent <- <-confIntents[i].Confirmed
}()
@ -445,7 +445,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
t.Fatalf("unable to register ntfn: %v", err)
}
confSent := make(chan int32)
confSent := make(chan *chainntnfs.TxConfirmation)
go func() {
confSent <- <-confIntent.Confirmed
}()
@ -487,7 +487,7 @@ func testTxConfirmedBeforeNtfnRegistration(miner *rpctest.Harness,
t.Fatalf("unable to generate blocks: %v", err)
}
confSent = make(chan int32)
confSent = make(chan *chainntnfs.TxConfirmation)
go func() {
confSent <- <-confIntent.Confirmed
}()