Merge pull request #1959 from halseth/neutrino-api
Update to new Neutrino API
This commit is contained in:
commit
77553707a0
8
Gopkg.lock
generated
8
Gopkg.lock
generated
@ -106,7 +106,7 @@
|
|||||||
revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b"
|
revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:e6575f3ee773e72a38319dbd8f4cb7f1b574eccfed7cb103c3a25c254d5c250f"
|
digest = "1:ac01796bf202b80d6cb1b92d42df0fbbf3aff964451376bfa7c39bc2bf94d108"
|
||||||
name = "github.com/btcsuite/btcwallet"
|
name = "github.com/btcsuite/btcwallet"
|
||||||
packages = [
|
packages = [
|
||||||
"chain",
|
"chain",
|
||||||
@ -126,7 +126,7 @@
|
|||||||
"wtxmgr",
|
"wtxmgr",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "421298df22601db0fe4adb8f4be71b7014324ba9"
|
revision = "c4dd27e481f9801866cf5226bfe532084772ec2a"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -268,7 +268,7 @@
|
|||||||
revision = "462a8a75388506b68f76661af8d649f0b88e5301"
|
revision = "462a8a75388506b68f76661af8d649f0b88e5301"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:48a9bc825edca0f6b562512f77d935b26a4fa3a645dc5468ed96bdd6897f4d82"
|
digest = "1:231ca602530410e89201db1f6377f8699ebdb6b690bf57fd83f292722d6f2be6"
|
||||||
name = "github.com/lightninglabs/neutrino"
|
name = "github.com/lightninglabs/neutrino"
|
||||||
packages = [
|
packages = [
|
||||||
".",
|
".",
|
||||||
@ -279,7 +279,7 @@
|
|||||||
"headerlist",
|
"headerlist",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "838f7ba74d217d188efc223604bd280b4e3f0238"
|
revision = "4d60692991302a44509d1a9234ccd51373c120b4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:58ab6d6525898cbeb86dc29a68f8e9bfe95254b9032134eb9458779574872260"
|
digest = "1:58ab6d6525898cbeb86dc29a68f8e9bfe95254b9032134eb9458779574872260"
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/lightninglabs/neutrino"
|
name = "github.com/lightninglabs/neutrino"
|
||||||
revision = "838f7ba74d217d188efc223604bd280b4e3f0238"
|
revision = "4d60692991302a44509d1a9234ccd51373c120b4"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/lightningnetwork/lightning-onion"
|
name = "github.com/lightningnetwork/lightning-onion"
|
||||||
@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/btcsuite/btcwallet"
|
name = "github.com/btcsuite/btcwallet"
|
||||||
revision = "421298df22601db0fe4adb8f4be71b7014324ba9"
|
revision = "c4dd27e481f9801866cf5226bfe532084772ec2a"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tv42/zbase32"
|
name = "github.com/tv42/zbase32"
|
||||||
|
@ -137,15 +137,12 @@ func (n *NeutrinoNotifier) Start() error {
|
|||||||
// start the auto-rescan from this point. Once a caller actually wishes
|
// start the auto-rescan from this point. Once a caller actually wishes
|
||||||
// to register a chain view, the rescan state will be rewound
|
// to register a chain view, the rescan state will be rewound
|
||||||
// accordingly.
|
// accordingly.
|
||||||
bestHeader, bestHeight, err := n.p2pNode.BlockHeaders.ChainTip()
|
startingPoint, err := n.p2pNode.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
startingPoint := &waddrmgr.BlockStamp{
|
|
||||||
Height: int32(bestHeight),
|
n.bestHeight = uint32(startingPoint.Height)
|
||||||
Hash: bestHeader.BlockHash(),
|
|
||||||
}
|
|
||||||
n.bestHeight = bestHeight
|
|
||||||
|
|
||||||
// Next, we'll create our set of rescan options. Currently it's
|
// Next, we'll create our set of rescan options. Currently it's
|
||||||
// required that a user MUST set an addr/outpoint/txid when creating a
|
// required that a user MUST set an addr/outpoint/txid when creating a
|
||||||
@ -165,7 +162,7 @@ func (n *NeutrinoNotifier) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n.txConfNotifier = chainntnfs.NewTxConfNotifier(
|
n.txConfNotifier = chainntnfs.NewTxConfNotifier(
|
||||||
bestHeight, reorgSafetyLimit, n.confirmHintCache,
|
n.bestHeight, reorgSafetyLimit, n.confirmHintCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
n.chainConn = &NeutrinoChainConn{n.p2pNode}
|
n.chainConn = &NeutrinoChainConn{n.p2pNode}
|
||||||
@ -476,20 +473,17 @@ out:
|
|||||||
"blocks, attempting to catch up")
|
"blocks, attempting to catch up")
|
||||||
}
|
}
|
||||||
|
|
||||||
header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(
|
hash, err := n.p2pNode.GetBlockHash(int64(n.bestHeight))
|
||||||
n.bestHeight,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chainntnfs.Log.Errorf("Unable to fetch header"+
|
chainntnfs.Log.Errorf("Unable to fetch block hash"+
|
||||||
"for height %d: %v", n.bestHeight, err)
|
"for height %d: %v", n.bestHeight, err)
|
||||||
n.heightMtx.Unlock()
|
n.heightMtx.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
hash := header.BlockHash()
|
|
||||||
notifierBestBlock := chainntnfs.BlockEpoch{
|
notifierBestBlock := chainntnfs.BlockEpoch{
|
||||||
Height: int32(n.bestHeight),
|
Height: int32(n.bestHeight),
|
||||||
Hash: &hash,
|
Hash: hash,
|
||||||
}
|
}
|
||||||
newBestBlock, err := chainntnfs.RewindChain(
|
newBestBlock, err := chainntnfs.RewindChain(
|
||||||
n.chainConn, n.txConfNotifier, notifierBestBlock,
|
n.chainConn, n.txConfNotifier, notifierBestBlock,
|
||||||
@ -536,17 +530,16 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
|
|
||||||
// First, we'll fetch the block header for this height so we
|
// First, we'll fetch the block header for this height so we
|
||||||
// can compute the current block hash.
|
// can compute the current block hash.
|
||||||
header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(scanHeight)
|
blockHash, err := n.p2pNode.GetBlockHash(int64(scanHeight))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to get header for height=%v: %v",
|
return nil, fmt.Errorf("unable to get header for height=%v: %v",
|
||||||
scanHeight, err)
|
scanHeight, err)
|
||||||
}
|
}
|
||||||
blockHash := header.BlockHash()
|
|
||||||
|
|
||||||
// With the hash computed, we can now fetch the basic filter
|
// With the hash computed, we can now fetch the basic filter
|
||||||
// for this height.
|
// for this height.
|
||||||
regFilter, err := n.p2pNode.GetCFilter(
|
regFilter, err := n.p2pNode.GetCFilter(
|
||||||
blockHash, wire.GCSFilterRegular,
|
*blockHash, wire.GCSFilterRegular,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to retrieve regular filter for "+
|
return nil, fmt.Errorf("unable to retrieve regular filter for "+
|
||||||
@ -562,7 +555,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
|
|
||||||
// In the case that the filter exists, we'll attempt to see if
|
// In the case that the filter exists, we'll attempt to see if
|
||||||
// any element in it matches our target public key script.
|
// any element in it matches our target public key script.
|
||||||
key := builder.DeriveKey(&blockHash)
|
key := builder.DeriveKey(blockHash)
|
||||||
match, err := regFilter.Match(key, pkScript)
|
match, err := regFilter.Match(key, pkScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to query filter: %v", err)
|
return nil, fmt.Errorf("unable to query filter: %v", err)
|
||||||
@ -577,7 +570,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
// In the case that we do have a match, we'll fetch the block
|
// In the case that we do have a match, we'll fetch the block
|
||||||
// from the network so we can find the positional data required
|
// from the network so we can find the positional data required
|
||||||
// to send the proper response.
|
// to send the proper response.
|
||||||
block, err := n.p2pNode.GetBlock(blockHash)
|
block, err := n.p2pNode.GetBlock(*blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to get block from network: %v", err)
|
return nil, fmt.Errorf("unable to get block from network: %v", err)
|
||||||
}
|
}
|
||||||
@ -585,7 +578,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(targetHash *chainhash.Hash,
|
|||||||
txHash := tx.Hash()
|
txHash := tx.Hash()
|
||||||
if txHash.IsEqual(targetHash) {
|
if txHash.IsEqual(targetHash) {
|
||||||
confDetails := chainntnfs.TxConfirmation{
|
confDetails := chainntnfs.TxConfirmation{
|
||||||
BlockHash: &blockHash,
|
BlockHash: blockHash,
|
||||||
BlockHeight: scanHeight,
|
BlockHeight: scanHeight,
|
||||||
TxIndex: uint32(j),
|
TxIndex: uint32(j),
|
||||||
}
|
}
|
||||||
@ -1085,11 +1078,7 @@ type NeutrinoChainConn struct {
|
|||||||
|
|
||||||
// GetBlockHeader returns the block header for a hash.
|
// GetBlockHeader returns the block header for a hash.
|
||||||
func (n *NeutrinoChainConn) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
|
func (n *NeutrinoChainConn) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
|
||||||
header, _, err := n.p2pNode.BlockHeaders.FetchHeader(blockHash)
|
return n.p2pNode.GetBlockHeader(blockHash)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return header, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockHeaderVerbose returns a verbose block header result for a hash. This
|
// GetBlockHeaderVerbose returns a verbose block header result for a hash. This
|
||||||
@ -1097,7 +1086,7 @@ func (n *NeutrinoChainConn) GetBlockHeader(blockHash *chainhash.Hash) (*wire.Blo
|
|||||||
func (n *NeutrinoChainConn) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (
|
func (n *NeutrinoChainConn) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (
|
||||||
*btcjson.GetBlockHeaderVerboseResult, error) {
|
*btcjson.GetBlockHeaderVerboseResult, error) {
|
||||||
|
|
||||||
_, height, err := n.p2pNode.BlockHeaders.FetchHeader(blockHash)
|
height, err := n.p2pNode.GetBlockHeight(blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1107,10 +1096,5 @@ func (n *NeutrinoChainConn) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (
|
|||||||
|
|
||||||
// GetBlockHash returns the hash from a block height.
|
// GetBlockHash returns the hash from a block height.
|
||||||
func (n *NeutrinoChainConn) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
|
func (n *NeutrinoChainConn) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
|
||||||
header, err := n.p2pNode.BlockHeaders.FetchHeaderByHeight(uint32(blockHeight))
|
return n.p2pNode.GetBlockHash(blockHeight)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hash := header.BlockHash()
|
|
||||||
return &hash, nil
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ 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/btcwallet/waddrmgr"
|
|
||||||
"github.com/lightninglabs/neutrino"
|
"github.com/lightninglabs/neutrino"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
)
|
)
|
||||||
@ -26,14 +25,10 @@ func (n *NeutrinoNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Has
|
|||||||
// start the auto-rescan from this point. Once a caller actually wishes
|
// start the auto-rescan from this point. Once a caller actually wishes
|
||||||
// to register a chain view, the rescan state will be rewound
|
// to register a chain view, the rescan state will be rewound
|
||||||
// accordingly.
|
// accordingly.
|
||||||
header, height, err := n.p2pNode.BlockHeaders.ChainTip()
|
startingPoint, err := n.p2pNode.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
startingPoint := &waddrmgr.BlockStamp{
|
|
||||||
Height: int32(height),
|
|
||||||
Hash: header.BlockHash(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, we'll create our set of rescan options. Currently it's
|
// Next, we'll create our set of rescan options. Currently it's
|
||||||
// required that a user MUST set an addr/outpoint/txid when creating a
|
// required that a user MUST set an addr/outpoint/txid when creating a
|
||||||
|
@ -750,17 +750,5 @@ func (b *BtcWallet) IsSynced() (bool, int64, error) {
|
|||||||
return false, bestTimestamp, nil
|
return false, bestTimestamp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is neutrino, then we'll also want to wait until the set of
|
|
||||||
// filter headers also match
|
|
||||||
if neutrinoNode, ok := b.chain.(*chain.NeutrinoClient); ok {
|
|
||||||
filterDB := neutrinoNode.CS.RegFilterHeaders
|
|
||||||
_, filterHeaderTip, err := filterDB.ChainTip()
|
|
||||||
if err != nil {
|
|
||||||
return false, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return filterHeaderTip == uint32(bestHeight), bestTimestamp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, bestTimestamp, nil
|
return true, bestTimestamp, nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcutil/gcs/builder"
|
"github.com/btcsuite/btcutil/gcs/builder"
|
||||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
|
||||||
"github.com/lightninglabs/neutrino"
|
"github.com/lightninglabs/neutrino"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
)
|
)
|
||||||
@ -84,14 +83,10 @@ func (c *CfFilteredChainView) Start() error {
|
|||||||
// start the auto-rescan from this point. Once a caller actually wishes
|
// start the auto-rescan from this point. Once a caller actually wishes
|
||||||
// to register a chain view, the rescan state will be rewound
|
// to register a chain view, the rescan state will be rewound
|
||||||
// accordingly.
|
// accordingly.
|
||||||
bestHeader, bestHeight, err := c.p2pNode.BlockHeaders.ChainTip()
|
startingPoint, err := c.p2pNode.BestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
startingPoint := &waddrmgr.BlockStamp{
|
|
||||||
Height: int32(bestHeight),
|
|
||||||
Hash: bestHeader.BlockHash(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, we'll create our set of rescan options. Currently it's
|
// Next, we'll create our set of rescan options. Currently it's
|
||||||
// required that an user MUST set a addr/outpoint/txid when creating a
|
// required that an user MUST set a addr/outpoint/txid when creating a
|
||||||
@ -215,14 +210,14 @@ func (c *CfFilteredChainView) chainFilterer() {
|
|||||||
func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredBlock, error) {
|
func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredBlock, error) {
|
||||||
// First, we'll fetch the block header itself so we can obtain the
|
// First, we'll fetch the block header itself so we can obtain the
|
||||||
// height which is part of our return value.
|
// height which is part of our return value.
|
||||||
_, blockHeight, err := c.p2pNode.BlockHeaders.FetchHeader(blockHash)
|
blockHeight, err := c.p2pNode.GetBlockHeight(blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredBlock := &FilteredBlock{
|
filteredBlock := &FilteredBlock{
|
||||||
Hash: *blockHash,
|
Hash: *blockHash,
|
||||||
Height: blockHeight,
|
Height: uint32(blockHeight),
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't have any items within our current chain filter, then we
|
// If we don't have any items within our current chain filter, then we
|
||||||
|
Loading…
Reference in New Issue
Block a user