chainntfs: expand ChainNotifier interface
* The `NotificationTrigger` struct has been dropped. Instead we know simply employ a non-blocking send over a chan struct. This moves the responsibility of triggering callbacks a level above to the registering client. * Confirmation notifications also now have a counter part in order to notify a caller of the scenario wherein a funding transaction drops out of the chain due to a re-org. A “neagtiveConf” value will be sent to the client over a channel in this case. This will allow a caller to re-register for another confirmation notification. Note that due to this scenario, callers should also register for notifications concerning spends of the counterparty’s inputs to the funding transaction. If a second spend (other than the funding) is detected, the channel should be closed immediately. * Notifications concerning spends now also include the spending transaction, hash, and the input on the spending transaction at which the outpoint is spent.
This commit is contained in:
1 parent
2367300d71
commit
b913bda472
1 file changed
+31
-5
+31
-5
@@ -2,6 +2,7 @@ package chainntnfs
|
|||||||
|
|
||||||
import "github.com/btcsuite/btcd/wire"
|
import "github.com/btcsuite/btcd/wire"
|
||||||
|
|
||||||
|
// ChainNotifier ...
|
||||||
// TODO(roasbeef): finish
|
// TODO(roasbeef): finish
|
||||||
// * multiple backends for interface
|
// * multiple backends for interface
|
||||||
// * btcd - websockets
|
// * btcd - websockets
|
||||||
@@ -12,14 +13,39 @@ import "github.com/btcsuite/btcd/wire"
|
|||||||
// * SPV bloomfilter
|
// * SPV bloomfilter
|
||||||
// * other stuff maybe...
|
// * other stuff maybe...
|
||||||
type ChainNotifier interface {
|
type ChainNotifier interface {
|
||||||
RegisterConfirmationsNotification(txid *wire.ShaHash, numConfs uint32, trigger *NotificationTrigger) error
|
RegisterConfirmationsNtfn(txid *wire.ShaHash, numConfs uint32) (*ConfirmationEvent, error)
|
||||||
RegisterSpendNotification(outpoint *wire.OutPoint, trigger *NotificationTrigger) error
|
RegisterSpendNtfn(outpoint *wire.OutPoint) (*SpendEvent, error)
|
||||||
|
|
||||||
Start() error
|
Start() error
|
||||||
Stop() error
|
Stop() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationTrigger struct {
|
// TODO(roasbeef): ln channels should request spend ntfns for counterparty's
|
||||||
TriggerChan chan struct{}
|
// inputs to funding tx also, consider channel closed if funding tx re-org'd
|
||||||
Callback func()
|
// out and inputs double spent.
|
||||||
|
|
||||||
|
// ConfirmationEvent ...
|
||||||
|
type ConfirmationEvent struct {
|
||||||
|
Confirmed chan struct{} // 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
|
||||||
|
// channel after confs.
|
||||||
|
|
||||||
|
NegativeConf chan uint32 // MUST be buffered.
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpendDetail ...
|
||||||
|
type SpendDetail struct {
|
||||||
|
SpentOutPoint *wire.OutPoint
|
||||||
|
|
||||||
|
SpendingTx *wire.MsgTx
|
||||||
|
SpenderTxHash *wire.ShaHash
|
||||||
|
SpenderInputIndex uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpendEvent ...
|
||||||
|
type SpendEvent struct {
|
||||||
|
Spend chan *SpendDetail // MUST be buffered.
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user