Merge pull request #3405 from wpaulino/chainrpc-sane-defaults

chainntnfs: validate conf/spend ntfn registration parameters
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2019-08-26 16:25:06 -07:00
commit 3868bdc490
16 files changed
+634 -684

No files matched your search

+4
View File
@@ -43,4 +43,8 @@ type Config struct {
// Sweeper is the central batching engine of lnd. It is responsible for
// sweeping inputs in batches back into the wallet.
Sweeper *sweep.UtxoSweeper
// Chain is an interface that the WalletKit will use to determine state
// about the backing chain of the wallet.
Chain lnwallet.BlockChainIO
}
+8
View File
@@ -51,6 +51,14 @@ func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (lnrpc.S
case config.KeyRing == nil:
return nil, nil, fmt.Errorf("KeyRing must be set to create " +
"WalletKit RPC server")
case config.Sweeper == nil:
return nil, nil, fmt.Errorf("Sweeper must be set to create " +
"WalletKit RPC server")
case config.Chain == nil:
return nil, nil, fmt.Errorf("Chain must be set to create " +
"WalletKit RPC server")
}
return New(config)
+24 -6
View File
@@ -4,6 +4,7 @@ package walletrpc
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
@@ -496,27 +497,44 @@ func (w *WalletKit) BumpFee(ctx context.Context,
//
// We'll gather all of the information required by the UtxoSweeper in
// order to sweep the output.
txOut, err := w.cfg.Wallet.FetchInputInfo(op)
utxo, err := w.cfg.Wallet.FetchInputInfo(op)
if err != nil {
return nil, err
}
// We're only able to bump the fee of unconfirmed transactions.
if utxo.Confirmations > 0 {
return nil, errors.New("unable to bump fee of a confirmed " +
"transaction")
}
var witnessType input.WitnessType
switch {
case txscript.IsPayToWitnessPubKeyHash(txOut.PkScript):
switch utxo.AddressType {
case lnwallet.WitnessPubKey:
witnessType = input.WitnessKeyHash
case txscript.IsPayToScriptHash(txOut.PkScript):
case lnwallet.NestedWitnessPubKey:
witnessType = input.NestedWitnessKeyHash
default:
return nil, fmt.Errorf("unknown input witness %v", op)
}
signDesc := &input.SignDescriptor{
Output: txOut,
Output: &wire.TxOut{
PkScript: utxo.PkScript,
Value: int64(utxo.Value),
},
HashType: txscript.SigHashAll,
}
input := input.NewBaseInput(op, witnessType, signDesc, 0)
// We'll use the current height as the height hint since we're dealing
// with an unconfirmed transaction.
_, currentHeight, err := w.cfg.Chain.GetBestBlock()
if err != nil {
return nil, fmt.Errorf("unable to retrieve current height: %v",
err)
}
input := input.NewBaseInput(op, witnessType, signDesc, uint32(currentHeight))
if _, err = w.cfg.Sweeper.SweepInput(input, feePreference); err != nil {
return nil, err
}