routing/chainview: ensure bitcoind impl meets new interface requirements
This commit is contained in:
parent
9b9029cf4b
commit
fb98f59407
@ -13,9 +13,9 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BitcoindFilteredChainView is an implementation of the FilteredChainView
|
// BitcoindFilteredChainView is an implementation of the FilteredChainView
|
||||||
@ -66,6 +66,7 @@ var _ FilteredChainView = (*BitcoindFilteredChainView)(nil)
|
|||||||
func NewBitcoindFilteredChainView(config rpcclient.ConnConfig,
|
func NewBitcoindFilteredChainView(config rpcclient.ConnConfig,
|
||||||
zmqConnect string, params chaincfg.Params) (*BitcoindFilteredChainView,
|
zmqConnect string, params chaincfg.Params) (*BitcoindFilteredChainView,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
chainView := &BitcoindFilteredChainView{
|
chainView := &BitcoindFilteredChainView{
|
||||||
chainFilter: make(map[wire.OutPoint]struct{}),
|
chainFilter: make(map[wire.OutPoint]struct{}),
|
||||||
filterUpdates: make(chan filterUpdate),
|
filterUpdates: make(chan filterUpdate),
|
||||||
@ -308,7 +309,6 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
// filter, so we'll apply the update, possibly rewinding our
|
// filter, so we'll apply the update, possibly rewinding our
|
||||||
// state partially.
|
// state partially.
|
||||||
case update := <-b.filterUpdates:
|
case update := <-b.filterUpdates:
|
||||||
|
|
||||||
// First, we'll add all the new UTXO's to the set of
|
// First, we'll add all the new UTXO's to the set of
|
||||||
// watched UTXO's, eliminating any duplicates in the
|
// watched UTXO's, eliminating any duplicates in the
|
||||||
// process.
|
// process.
|
||||||
@ -325,8 +325,9 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
// will cause all following notifications from and
|
// will cause all following notifications from and
|
||||||
// calls to it return blocks filtered with the new
|
// calls to it return blocks filtered with the new
|
||||||
// filter.
|
// filter.
|
||||||
b.chainClient.LoadTxFilter(false, []btcutil.Address{},
|
b.chainClient.LoadTxFilter(
|
||||||
update.newUtxos)
|
false, update.newUtxos,
|
||||||
|
)
|
||||||
|
|
||||||
// All blocks gotten after we loaded the filter will
|
// All blocks gotten after we loaded the filter will
|
||||||
// have the filter applied, but we will need to rescan
|
// have the filter applied, but we will need to rescan
|
||||||
@ -362,7 +363,8 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
// block at a time, skipping blocks that might
|
// block at a time, skipping blocks that might
|
||||||
// have gone missing.
|
// have gone missing.
|
||||||
rescanned, err := b.chainClient.RescanBlocks(
|
rescanned, err := b.chainClient.RescanBlocks(
|
||||||
[]chainhash.Hash{*blockHash})
|
[]chainhash.Hash{*blockHash},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Unable to rescan block "+
|
log.Warnf("Unable to rescan block "+
|
||||||
"with hash %v at height %d: %v",
|
"with hash %v at height %d: %v",
|
||||||
@ -379,7 +381,8 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
decoded, err := decodeJSONBlock(
|
decoded, err := decodeJSONBlock(
|
||||||
&rescanned[0], i)
|
&rescanned[0], i,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to decode block: %v",
|
log.Errorf("Unable to decode block: %v",
|
||||||
err)
|
err)
|
||||||
@ -421,9 +424,12 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
// We've received a new event from the chain client.
|
// We've received a new event from the chain client.
|
||||||
case event := <-b.chainClient.Notifications():
|
case event := <-b.chainClient.Notifications():
|
||||||
switch e := event.(type) {
|
switch e := event.(type) {
|
||||||
|
|
||||||
case chain.FilteredBlockConnected:
|
case chain.FilteredBlockConnected:
|
||||||
b.onFilteredBlockConnected(e.Block.Height,
|
b.onFilteredBlockConnected(
|
||||||
e.Block.Hash, e.RelevantTxs)
|
e.Block.Height, e.Block.Hash, e.RelevantTxs,
|
||||||
|
)
|
||||||
|
|
||||||
case chain.BlockDisconnected:
|
case chain.BlockDisconnected:
|
||||||
b.onFilteredBlockDisconnected(e.Height, e.Hash)
|
b.onFilteredBlockDisconnected(e.Height, e.Hash)
|
||||||
}
|
}
|
||||||
@ -442,11 +448,18 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
// rewound to ensure all relevant notifications are dispatched.
|
// rewound to ensure all relevant notifications are dispatched.
|
||||||
//
|
//
|
||||||
// NOTE: This is part of the FilteredChainView interface.
|
// NOTE: This is part of the FilteredChainView interface.
|
||||||
func (b *BitcoindFilteredChainView) UpdateFilter(ops []wire.OutPoint, updateHeight uint32) error {
|
func (b *BitcoindFilteredChainView) UpdateFilter(ops []channeldb.EdgePoint,
|
||||||
|
updateHeight uint32) error {
|
||||||
|
|
||||||
|
newUtxos := make([]wire.OutPoint, len(ops))
|
||||||
|
for i, op := range ops {
|
||||||
|
newUtxos[i] = op.OutPoint
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
||||||
case b.filterUpdates <- filterUpdate{
|
case b.filterUpdates <- filterUpdate{
|
||||||
newUtxos: ops,
|
newUtxos: newUtxos,
|
||||||
updateHeight: updateHeight,
|
updateHeight: updateHeight,
|
||||||
}:
|
}:
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user