chainntnfs: add heightHint to RegisterSpendNtfn+ RegisterConfirmationsNtfn

This commit modifies two of the main methods in the ChainNotifier
interface to be more light client friendly. In order to do so, we now
tack on an extra parameter to the methods: heightHint. This value
represents the earliest known height that the chain should be scanned
when attempting to do a dispatch from historical data.

All tests have also been updated to use these new parameters properly
when excising the expected behavior of each interface implementation.
This commit is contained in:
Olaoluwa Osuntokun
2017-05-10 17:00:18 -07:00
parent 45bbeb8f84
commit 2f0639f1af
3 changed files with 80 additions and 16 deletions

View File

@@ -23,23 +23,32 @@ type ChainNotifier interface {
// txid reaches numConfs confirmations. The returned ConfirmationEvent
// should properly notify the client once the specified number of
// confirmations has been reached for the txid, as well as if the
// original tx gets re-org'd out of the mainchain.
// original tx gets re-org'd out of the mainchain. The heightHint
// parameter is provided as a convenience to light clients. The
// heightHint denotes the earlies height in the blockchain in which the
// target txid _could_ have been included in the chain. This can be
// used to bound the search space when checking to see if a
// notification can immediately be dispatched due to historical data.
//
// NOTE: Dispatching notifications to multiple clients subscribed to
// the same (txid, numConfs) tuple MUST be supported.
RegisterConfirmationsNtfn(txid *chainhash.Hash, numConfs uint32) (*ConfirmationEvent, error)
RegisterConfirmationsNtfn(txid *chainhash.Hash, numConfs,
heightHint uint32) (*ConfirmationEvent, error)
// RegisterSpendNtfn registers an intent to be notified once the target
// outpoint is succesfully spent within a confirmed transaction. The
// returned SpendEvent will receive a send on the 'Spend' transaction
// once a transaction spending the input is detected on the blockchain.
// The heightHint parameter is provided as a convenience to light
// clients. The heightHint denotes the earlies height in the blockchain
// in which the target output could've been created.
//
// NOTE: This notifications should be triggered once the transaction is
// *seen* on the network, not when it has received a single confirmation.
//
// NOTE: Dispatching notifications to multiple clients subscribed to a
// spend of the same outpoint MUST be supported.
RegisterSpendNtfn(outpoint *wire.OutPoint) (*SpendEvent, error)
RegisterSpendNtfn(outpoint *wire.OutPoint, heightHint uint32) (*SpendEvent, error)
// RegisterBlockEpochNtfn registers an intent to be notified of each
// new block connected to the tip of the main chain. The returned