multi: add new method FeePerVByte to avoid manual conversion

This commit is contained in:
yyforyongyu 2023-10-13 15:13:50 +08:00
parent a46168e669
commit 0532b82dd5
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
6 changed files with 17 additions and 16 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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]),

View File

@ -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))

View File

@ -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",