From 00b0c273dad242caaac0cefb47c2a4e5107ca43a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 24 Dec 2016 18:39:30 -0600 Subject: [PATCH] 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 --- chainntnfs/interface.go | 22 ++++++++++++++++++++-- chainntnfs/interface_test.go | 10 +++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/chainntnfs/interface.go b/chainntnfs/interface.go index a75bd02e4..c68fc38c6 100644 --- a/chainntnfs/interface.go +++ b/chainntnfs/interface.go @@ -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 diff --git a/chainntnfs/interface_test.go b/chainntnfs/interface_test.go index 66d378848..f7562999d 100644 --- a/chainntnfs/interface_test.go +++ b/chainntnfs/interface_test.go @@ -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 }()