chainregistry+config: add neutrino flag to assert filter header chain

This commit is contained in:
Valentine Wallace authored and Valentine Wallace committed 2019-06-06 16:05:12 -07:00
1 parent 818dbb9e9b
commit 25b540fec4
2 files changed
+39

No files matched your search

+38
View File
@@ -19,6 +19,7 @@ import (
"github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/walletdb" "github.com/btcsuite/btcwallet/walletdb"
"github.com/lightninglabs/neutrino" "github.com/lightninglabs/neutrino"
"github.com/lightninglabs/neutrino/headerfs"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify" "github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify"
"github.com/lightningnetwork/lnd/chainntnfs/btcdnotify" "github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
@@ -705,6 +706,13 @@ func initNeutrinoBackend(chainDir string) (*neutrino.ChainService, func(), error
"database: %v", err) "database: %v", err)
} }
headerStateAssertion, err := parseHeaderStateAssertion(
cfg.NeutrinoMode.AssertFilterHeader,
)
if err != nil {
return nil, nil, err
}
// With the database open, we can now create an instance of the // With the database open, we can now create an instance of the
// neutrino light client. We pass in relevant configuration parameters // neutrino light client. We pass in relevant configuration parameters
// required. // required.
@@ -735,6 +743,7 @@ func initNeutrinoBackend(chainDir string) (*neutrino.ChainService, func(), error
return ips, nil return ips, nil
}, },
AssertFilterHeader: headerStateAssertion,
} }
neutrino.MaxPeers = 8 neutrino.MaxPeers = 8
@@ -758,3 +767,32 @@ func initNeutrinoBackend(chainDir string) (*neutrino.ChainService, func(), error
return neutrinoCS, cleanUp, nil return neutrinoCS, cleanUp, nil
} }
// parseHeaderStateAssertion parses the user-specified neutrino header state
// into a headerfs.FilterHeader.
func parseHeaderStateAssertion(state string) (*headerfs.FilterHeader, error) {
if len(state) == 0 {
return nil, nil
}
split := strings.Split(state, ":")
if len(split) != 2 {
return nil, fmt.Errorf("header state assertion %v in "+
"unexpected format, expected format height:hash", state)
}
height, err := strconv.ParseUint(split[0], 10, 32)
if err != nil {
return nil, fmt.Errorf("invalid filter header height: %v", err)
}
hash, err := chainhash.NewHashFromStr(split[1])
if err != nil {
return nil, fmt.Errorf("invalid filter header hash: %v", err)
}
return &headerfs.FilterHeader{
Height: uint32(height),
FilterHash: *hash,
}, nil
}
+1
View File
@@ -175,6 +175,7 @@ type neutrinoConfig struct {
BanDuration time.Duration `long:"banduration" description:"How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second"` BanDuration time.Duration `long:"banduration" description:"How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second"`
BanThreshold uint32 `long:"banthreshold" description:"Maximum allowed ban score before disconnecting and banning misbehaving peers."` BanThreshold uint32 `long:"banthreshold" description:"Maximum allowed ban score before disconnecting and banning misbehaving peers."`
FeeURL string `long:"feeurl" description:"Optional URL for fee estimation. If a URL is not specified, static fees will be used for estimation."` FeeURL string `long:"feeurl" description:"Optional URL for fee estimation. If a URL is not specified, static fees will be used for estimation."`
AssertFilterHeader string `long:"assertfilterheader" description:"Optional filter header in height:hash format to assert the state of neutrino's filter header chain on startup. If the assertion does not hold, then the filter header chain will be re-synced from the genesis block."`
} }
type btcdConfig struct { type btcdConfig struct {