lnwallet: denominate in fee rate types

This commit is contained in:
Johan T. Halseth 2018-02-13 14:37:47 +01:00
parent 088d9bc42f
commit e1bb762cf7
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 31 additions and 36 deletions

View File

@ -135,9 +135,9 @@ type ChannelReservation struct {
// used only internally by lnwallet. In order to concurrent safety, the // used only internally by lnwallet. In order to concurrent safety, the
// creation of all channel reservations should be carried out via the // creation of all channel reservations should be carried out via the
// lnwallet.InitChannelReservation interface. // lnwallet.InitChannelReservation interface.
func NewChannelReservation(capacity, fundingAmt, commitFeePerKw btcutil.Amount, func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
wallet *LightningWallet, id uint64, pushMSat lnwire.MilliSatoshi, commitFeePerKw SatPerKWeight, wallet *LightningWallet,
chainHash *chainhash.Hash, id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash,
flags lnwire.FundingFlag) (*ChannelReservation, error) { flags lnwire.FundingFlag) (*ChannelReservation, error) {
var ( var (
@ -146,10 +146,7 @@ func NewChannelReservation(capacity, fundingAmt, commitFeePerKw btcutil.Amount,
initiator bool initiator bool
) )
commitFee := btcutil.Amount( commitFee := commitFeePerKw.FeeForWeight(CommitWeight)
(int64(commitFeePerKw) * CommitWeight) / 1000,
)
fundingMSat := lnwire.NewMSatFromSatoshis(fundingAmt) fundingMSat := lnwire.NewMSatFromSatoshis(fundingAmt)
capacityMSat := lnwire.NewMSatFromSatoshis(capacity) capacityMSat := lnwire.NewMSatFromSatoshis(capacity)
feeMSat := lnwire.NewMSatFromSatoshis(commitFee) feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
@ -229,13 +226,13 @@ func NewChannelReservation(capacity, fundingAmt, commitFeePerKw btcutil.Amount,
LocalCommitment: channeldb.ChannelCommitment{ LocalCommitment: channeldb.ChannelCommitment{
LocalBalance: ourBalance, LocalBalance: ourBalance,
RemoteBalance: theirBalance, RemoteBalance: theirBalance,
FeePerKw: commitFeePerKw, FeePerKw: btcutil.Amount(commitFeePerKw),
CommitFee: commitFee, CommitFee: commitFee,
}, },
RemoteCommitment: channeldb.ChannelCommitment{ RemoteCommitment: channeldb.ChannelCommitment{
LocalBalance: ourBalance, LocalBalance: ourBalance,
RemoteBalance: theirBalance, RemoteBalance: theirBalance,
FeePerKw: commitFeePerKw, FeePerKw: btcutil.Amount(commitFeePerKw),
CommitFee: commitFee, CommitFee: commitFee,
}, },
Db: wallet.Cfg.Database, Db: wallet.Cfg.Database,

View File

@ -97,11 +97,11 @@ type initFundingReserveMsg struct {
// of initial commitment transactions. In order to ensure timely // of initial commitment transactions. In order to ensure timely
// confirmation, it is recommended that this fee should be generous, // confirmation, it is recommended that this fee should be generous,
// paying some multiple of the accepted base fee rate of the network. // paying some multiple of the accepted base fee rate of the network.
commitFeePerKw btcutil.Amount commitFeePerKw SatPerKWeight
// fundingFeePerWeight is the fee rate in satoshis per eight unit to // fundingFeePerVSize is the fee rate in sat/vbyte to use for the
// use for the initial funding transaction. // initial funding transaction.
fundingFeePerWeight btcutil.Amount fundingFeePerVSize SatPerVByte
// pushMSat is the number of milli-satoshis that should be pushed over // pushMSat is the number of milli-satoshis that should be pushed over
// the responder as part of the initial channel creation. // the responder as part of the initial channel creation.
@ -450,7 +450,7 @@ out:
// commitment transaction is valid. // commitment transaction is valid.
func (l *LightningWallet) InitChannelReservation( func (l *LightningWallet) InitChannelReservation(
capacity, ourFundAmt btcutil.Amount, pushMSat lnwire.MilliSatoshi, capacity, ourFundAmt btcutil.Amount, pushMSat lnwire.MilliSatoshi,
commitFeePerKw, fundingFeePerWeight btcutil.Amount, commitFeePerKw SatPerKWeight, fundingFeePerVSize SatPerVByte,
theirID *btcec.PublicKey, theirAddr net.Addr, theirID *btcec.PublicKey, theirAddr net.Addr,
chainHash *chainhash.Hash, flags lnwire.FundingFlag) (*ChannelReservation, error) { chainHash *chainhash.Hash, flags lnwire.FundingFlag) (*ChannelReservation, error) {
@ -464,7 +464,7 @@ func (l *LightningWallet) InitChannelReservation(
fundingAmount: ourFundAmt, fundingAmount: ourFundAmt,
capacity: capacity, capacity: capacity,
commitFeePerKw: commitFeePerKw, commitFeePerKw: commitFeePerKw,
fundingFeePerWeight: fundingFeePerWeight, fundingFeePerVSize: fundingFeePerVSize,
pushMSat: pushMSat, pushMSat: pushMSat,
flags: flags, flags: flags,
err: errChan, err: errChan,
@ -516,10 +516,10 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
// don't need to perform any coin selection. Otherwise, attempt to // don't need to perform any coin selection. Otherwise, attempt to
// obtain enough coins to meet the required funding amount. // obtain enough coins to meet the required funding amount.
if req.fundingAmount != 0 { if req.fundingAmount != 0 {
// Coin selection is done on the basis of sat-per-weight, we'll // Coin selection is done on the basis of sat-per-vbyte, we'll
// use the passed sat/byte passed in to perform coin selection. // use the passed sat/vbyte passed in to perform coin selection.
err := l.selectCoinsAndChange( err := l.selectCoinsAndChange(
req.fundingFeePerWeight, req.fundingAmount, req.fundingFeePerVSize, req.fundingAmount,
reservation.ourContribution, reservation.ourContribution,
) )
if err != nil { if err != nil {
@ -1284,7 +1284,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// within the passed contribution's inputs. If necessary, a change address will // within the passed contribution's inputs. If necessary, a change address will
// also be generated. // also be generated.
// TODO(roasbeef): remove hardcoded fees and req'd confs for outputs. // TODO(roasbeef): remove hardcoded fees and req'd confs for outputs.
func (l *LightningWallet) selectCoinsAndChange(feeRatePerWeight btcutil.Amount, func (l *LightningWallet) selectCoinsAndChange(feeRate SatPerVByte,
amt btcutil.Amount, contribution *ChannelContribution) error { amt btcutil.Amount, contribution *ChannelContribution) error {
// We hold the coin select mutex while querying for outputs, and // We hold the coin select mutex while querying for outputs, and
@ -1294,7 +1294,7 @@ func (l *LightningWallet) selectCoinsAndChange(feeRatePerWeight btcutil.Amount,
defer l.coinSelectMtx.Unlock() defer l.coinSelectMtx.Unlock()
walletLog.Infof("Performing funding tx coin selection using %v "+ walletLog.Infof("Performing funding tx coin selection using %v "+
"sat/weight as fee rate", int64(feeRatePerWeight)) "sat/vbyte as fee rate", int64(feeRate))
// Find all unlocked unspent witness outputs with greater than 1 // Find all unlocked unspent witness outputs with greater than 1
// confirmation. // confirmation.
@ -1307,7 +1307,7 @@ func (l *LightningWallet) selectCoinsAndChange(feeRatePerWeight btcutil.Amount,
// Perform coin selection over our available, unlocked unspent outputs // Perform coin selection over our available, unlocked unspent outputs
// in order to find enough coins to meet the funding amount // in order to find enough coins to meet the funding amount
// requirements. // requirements.
selectedCoins, changeAmt, err := coinSelect(feeRatePerWeight, amt, coins) selectedCoins, changeAmt, err := coinSelect(feeRate, amt, coins)
if err != nil { if err != nil {
return err return err
} }
@ -1415,9 +1415,9 @@ func selectInputs(amt btcutil.Amount, coins []*Utxo) (btcutil.Amount, []*Utxo, e
// coinSelect attempts to select a sufficient amount of coins, including a // coinSelect attempts to select a sufficient amount of coins, including a
// change output to fund amt satoshis, adhering to the specified fee rate. The // change output to fund amt satoshis, adhering to the specified fee rate. The
// specified fee rate should be expressed in sat/byte for coin selection to // specified fee rate should be expressed in sat/vbyte for coin selection to
// function properly. // function properly.
func coinSelect(feeRatePerWeight, amt btcutil.Amount, func coinSelect(feeRate SatPerVByte, amt btcutil.Amount,
coins []*Utxo) ([]*Utxo, btcutil.Amount, error) { coins []*Utxo) ([]*Utxo, btcutil.Amount, error) {
amtNeeded := amt amtNeeded := amt
@ -1461,9 +1461,7 @@ func coinSelect(feeRatePerWeight, amt btcutil.Amount,
// amount isn't enough to pay fees, then increase the requested // amount isn't enough to pay fees, then increase the requested
// coin amount by the estimate required fee, performing another // coin amount by the estimate required fee, performing another
// round of coin selection. // round of coin selection.
requiredFee := btcutil.Amount( requiredFee := feeRate.FeeForVSize(int64(weightEstimate.VSize()))
uint64(weightEstimate.Weight()) * uint64(feeRatePerWeight),
)
if overShootAmt < requiredFee { if overShootAmt < requiredFee {
amtNeeded = amt + requiredFee amtNeeded = amt + requiredFee
continue continue