github.com/decred/dcrlnd@v0.7.6/routing/chainview/interface.go (about)

     1  package chainview
     2  
     3  import (
     4  	"github.com/decred/dcrd/chaincfg/chainhash"
     5  	"github.com/decred/dcrd/wire"
     6  	"github.com/decred/dcrlnd/channeldb"
     7  )
     8  
     9  // FilteredChainView represents a subscription to a certain subset of the
    10  // UTXO set for a particular chain. This interface is useful from the point of
    11  // view of maintaining an up-to-date channel graph for the Lightning Network.
    12  // The subset of the UTXO to be subscribed is that of all the currently opened
    13  // channels. Each time a channel is closed (the output is spent), a
    14  // notification is to be sent allowing the graph to be pruned.
    15  //
    16  // NOTE: As FilteredBlocks are generated, it is recommended that
    17  // implementations reclaim the space occupied by newly spent outputs.
    18  type FilteredChainView interface {
    19  	// FilteredBlocks returns the channel that filtered blocks are to be
    20  	// sent over. Each time a block is connected to the end of a main
    21  	// chain, and appropriate FilteredBlock which contains the transactions
    22  	// which mutate our watched UTXO set is to be returned. In case of a
    23  	// UpdateFilter call with an updateHeight lower than the current best
    24  	// height, blocks with the updated filter will be resent, and must be
    25  	// handled by the receiver as an update to an already known block, NOT
    26  	// as a new block being connected to the chain.
    27  	FilteredBlocks() <-chan *FilteredBlock
    28  
    29  	// DisconnectedBlocks returns a receive only channel which will be sent
    30  	// upon with the empty filtered blocks of blocks which are disconnected
    31  	// from the main chain in the case of a re-org.
    32  	// NOTE: In case of a reorg, connected blocks will not be available to
    33  	// read from the FilteredBlocks() channel before all disconnected block
    34  	// have been received.
    35  	DisconnectedBlocks() <-chan *FilteredBlock
    36  
    37  	// UpdateFilter updates the UTXO filter which is to be consulted when
    38  	// creating FilteredBlocks to be sent to subscribed clients. This
    39  	// method is cumulative meaning repeated calls to this method should
    40  	// _expand_ the size of the UTXO sub-set currently being watched.  If
    41  	// the set updateHeight is _lower_ than the best known height of the
    42  	// implementation, then the state should be rewound to ensure all
    43  	// relevant notifications are dispatched, meaning blocks with a height
    44  	// lower than the best known height might be sent over the
    45  	// FilteredBlocks() channel.
    46  	UpdateFilter(ops []channeldb.EdgePoint, updateHeight int64) error
    47  
    48  	// FilterBlock takes a block hash, and returns a FilteredBlocks which
    49  	// is the result of applying the current registered UTXO sub-set on the
    50  	// block corresponding to that block hash.
    51  	//
    52  	// TODO(roasbeef): make a version that does by height also?
    53  	FilterBlock(blockHash *chainhash.Hash) (*FilteredBlock, error)
    54  
    55  	// Start starts all goroutine necessary for the operation of the
    56  	// FilteredChainView implementation.
    57  	Start() error
    58  
    59  	// Stop stops all goroutines which we launched by the prior call to the
    60  	// Start method.
    61  	Stop() error
    62  }
    63  
    64  // FilteredBlock is a block which includes the transactions that modify the
    65  // subscribed sub-set of the UTXO set registered to the current
    66  // FilteredChainView concrete implementation.
    67  type FilteredBlock struct {
    68  	// Hash is the hash of the newly filtered block.
    69  	Hash chainhash.Hash
    70  
    71  	// Height is the height of the newly filtered block.
    72  	Height int64
    73  
    74  	// Transactions is the set of transactions which modify (spend) the
    75  	// subscribed UTXO subset.
    76  	Transactions []*wire.MsgTx
    77  }