From 0532b82dd5e771c54f6883577dab1f140c8a7469 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 13 Oct 2023 15:13:50 +0800 Subject: [PATCH] multi: add new method `FeePerVByte` to avoid manual conversion --- funding/batch.go | 4 ++-- lncfg/wtclient.go | 4 ++-- lnrpc/walletrpc/walletkit_server.go | 4 ++-- lnrpc/wtclientrpc/wtclient.go | 12 ++++-------- lnwallet/chainfee/rates.go | 5 +++++ rpcserver.go | 4 ++-- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/funding/batch.go b/funding/batch.go index 8a902bc92..a45c7e96c 100644 --- a/funding/batch.go +++ b/funding/batch.go @@ -331,14 +331,14 @@ func (b *Batcher) BatchFund(ctx context.Context, // settings from the first request as all of them should be equal // anyway. firstReq := b.channels[0].fundingReq - feeRateSatPerKVByte := firstReq.FundingFeePerKw.FeePerKVByte() + feeRateSatPerVByte := firstReq.FundingFeePerKw.FeePerVByte() changeType := walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR fundPsbtReq := &walletrpc.FundPsbtRequest{ Template: &walletrpc.FundPsbtRequest_Raw{ Raw: txTemplate, }, Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{ - SatPerVbyte: uint64(feeRateSatPerKVByte) / 1000, + SatPerVbyte: uint64(feeRateSatPerVByte), }, MinConfs: firstReq.MinConfs, SpendUnconfirmed: firstReq.MinConfs == 0, diff --git a/lncfg/wtclient.go b/lncfg/wtclient.go index 461a2c9d0..d4e2c6b27 100644 --- a/lncfg/wtclient.go +++ b/lncfg/wtclient.go @@ -39,8 +39,8 @@ func DefaultWtClientCfg() *WtClient { // The sweep fee rate used internally by the tower client is in sats/kw // but the config exposed to the user is in sats/byte, so we convert the // default here before exposing it to the user. - sweepSatsPerKvB := wtpolicy.DefaultSweepFeeRate.FeePerKVByte() - sweepFeeRate := uint64(sweepSatsPerKvB / 1000) + sweepSatsPerVB := wtpolicy.DefaultSweepFeeRate.FeePerVByte() + sweepFeeRate := uint64(sweepSatsPerVB) return &WtClient{ SweepFeeRate: sweepFeeRate, diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 9fff649ee..205eb2ed2 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -782,12 +782,12 @@ func (w *WalletKit) PendingSweeps(ctx context.Context, op := lnrpc.MarshalOutPoint(&pendingInput.OutPoint) amountSat := uint32(pendingInput.Amount) - satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerKVByte() / 1000) + satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerVByte()) broadcastAttempts := uint32(pendingInput.BroadcastAttempts) nextBroadcastHeight := uint32(pendingInput.NextBroadcastHeight) requestedFee := pendingInput.Params.Fee - requestedFeeRate := uint64(requestedFee.FeeRate.FeePerKVByte() / 1000) + requestedFeeRate := uint64(requestedFee.FeeRate.FeePerVByte()) rpcPendingSweeps = append(rpcPendingSweeps, &PendingSweep{ Outpoint: op, diff --git a/lnrpc/wtclientrpc/wtclient.go b/lnrpc/wtclientrpc/wtclient.go index 228877743..aa7e1ae21 100644 --- a/lnrpc/wtclientrpc/wtclient.go +++ b/lnrpc/wtclientrpc/wtclient.go @@ -476,15 +476,11 @@ func (c *WatchtowerClient) Policy(ctx context.Context, } return &PolicyResponse{ - MaxUpdates: uint32(policy.MaxUpdates), - SweepSatPerVbyte: uint32( - policy.SweepFeeRate.FeePerKVByte() / 1000, - ), + MaxUpdates: uint32(policy.MaxUpdates), + SweepSatPerVbyte: uint32(policy.SweepFeeRate.FeePerVByte()), // Deprecated field. - SweepSatPerByte: uint32( - policy.SweepFeeRate.FeePerKVByte() / 1000, - ), + SweepSatPerByte: uint32(policy.SweepFeeRate.FeePerVByte()), }, nil } @@ -519,7 +515,7 @@ func marshallTower(tower *wtclient.RegisteredTower, policyType PolicyType, rpcSessions = make([]*TowerSession, 0, len(tower.Sessions)) for _, session := range sessions { - satPerVByte := session.Policy.SweepFeeRate.FeePerKVByte() / 1000 + satPerVByte := session.Policy.SweepFeeRate.FeePerVByte() rpcSessions = append(rpcSessions, &TowerSession{ NumBackups: uint32(ackCounts[session.ID]), NumPendingBackups: uint32(pendingCounts[session.ID]), diff --git a/lnwallet/chainfee/rates.go b/lnwallet/chainfee/rates.go index 34da55374..0bdb8a17a 100644 --- a/lnwallet/chainfee/rates.go +++ b/lnwallet/chainfee/rates.go @@ -70,6 +70,11 @@ func (s SatPerKWeight) FeePerKVByte() SatPerKVByte { return SatPerKVByte(s * blockchain.WitnessScaleFactor) } +// FeePerVByte converts the current fee rate from sat/kw to sat/vb. +func (s SatPerKWeight) FeePerVByte() SatPerVByte { + return SatPerVByte(s * blockchain.WitnessScaleFactor / 1000) +} + // String returns a human-readable string of the fee rate. func (s SatPerKWeight) String() string { return fmt.Sprintf("%v sat/kw", int64(s)) diff --git a/rpcserver.go b/rpcserver.go index d8f99c91d..85a156cf9 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1197,10 +1197,10 @@ func (r *rpcServer) EstimateFee(ctx context.Context, resp := &lnrpc.EstimateFeeResponse{ FeeSat: totalFee, - SatPerVbyte: uint64(feePerKw.FeePerKVByte() / 1000), + SatPerVbyte: uint64(feePerKw.FeePerVByte()), // Deprecated field. - FeerateSatPerByte: int64(feePerKw.FeePerKVByte() / 1000), + FeerateSatPerByte: int64(feePerKw.FeePerVByte()), } rpcsLog.Debugf("[estimatefee] fee estimate for conf target %d: %v",