chainntfs: add new RegisterBlockHeightNtfn method
This commit adds a new method to the ChainNotifier interface which subscribes the caller to a continuous stream of notifications generated by new blocks added to the tip of the Bitcoin main chain. Concurrently, this method is intended to be used in order to obtain the necessary block height information to properly handle the timeout period on any pending HTLCs. A continuos stream, rather than a one-off notification is chosen in order to discourage a goroutine-per-HTLC model which would be rather wasteful.
This commit is contained in:
parent
1879c00c55
commit
7bff2e07a8
@ -352,3 +352,11 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *wire.ShaHash,
|
||||
NegativeConf: ntfn.negativeConf,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the
|
||||
// caller to receive notificationsm, of each new block connected to the main
|
||||
// chain.
|
||||
func (b *BtcdNotifier) RegisterBlockEpochNtfn(targetHeight int32) (*chainntnfs.BlockEpochEvent, error) {
|
||||
// TODO(roasbeef): implement
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -27,6 +27,12 @@ type ChainNotifier interface {
|
||||
// *seen* on the network, not when it has received a single confirmation.
|
||||
RegisterSpendNtfn(outpoint *wire.OutPoint) (*SpendEvent, error)
|
||||
|
||||
// RegisterBlockEpochNtfn registers an intent to be notified of each
|
||||
// new block connected to the tip of the main chain. The returned
|
||||
// BlockEpochEvent struct contains a channel which will be sent upon
|
||||
// for each new block discovered.
|
||||
RegisterBlockEpochNtfn(targetHeight int32) (*BlockEpochEvent, error)
|
||||
|
||||
// Start the ChainNotifier. Once started, the implementation should be
|
||||
// ready, and able to receive notification registrations from clients.
|
||||
Start() error
|
||||
@ -42,6 +48,8 @@ type ChainNotifier interface {
|
||||
// inputs to funding tx also, consider channel closed if funding tx re-org'd
|
||||
// out and inputs double spent.
|
||||
|
||||
// TODO(roasbeef): all chans should be receive only.
|
||||
|
||||
// ConfirmationEvent encapsulates a confirmation notification. With this struct,
|
||||
// callers can be notified of: the instance the target txid reaches the targeted
|
||||
// number of confirmations, and also in the event that the original txid becomes
|
||||
@ -82,3 +90,17 @@ type SpendDetail struct {
|
||||
type SpendEvent struct {
|
||||
Spend chan *SpendDetail // MUST be buffered.
|
||||
}
|
||||
|
||||
// BlockEpoch represents meta-data concerning each new block connected to the
|
||||
// main chain.
|
||||
type BlockEpoch struct {
|
||||
Height int32
|
||||
Hash *wire.ShaHash
|
||||
}
|
||||
|
||||
// BlockEpochEvent encapsulates an on-going stream of block epoch
|
||||
// notifications. Its only field 'Epoochs' will be sent upon for each new block
|
||||
// connected to the main-chain.
|
||||
type BlockEpochEvent struct {
|
||||
Epochs chan *BlockEpoch // MUST be buffered.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user