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
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 // settings from the first request as all of them should be equal
// anyway. // anyway.
firstReq := b.channels[0].fundingReq firstReq := b.channels[0].fundingReq
feeRateSatPerKVByte := firstReq.FundingFeePerKw.FeePerKVByte() feeRateSatPerVByte := firstReq.FundingFeePerKw.FeePerVByte()
changeType := walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR changeType := walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR
fundPsbtReq := &walletrpc.FundPsbtRequest{ fundPsbtReq := &walletrpc.FundPsbtRequest{
Template: &walletrpc.FundPsbtRequest_Raw{ Template: &walletrpc.FundPsbtRequest_Raw{
Raw: txTemplate, Raw: txTemplate,
}, },
Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{ Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{
SatPerVbyte: uint64(feeRateSatPerKVByte) / 1000, SatPerVbyte: uint64(feeRateSatPerVByte),
}, },
MinConfs: firstReq.MinConfs, MinConfs: firstReq.MinConfs,
SpendUnconfirmed: firstReq.MinConfs == 0, 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 // 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 // but the config exposed to the user is in sats/byte, so we convert the
// default here before exposing it to the user. // default here before exposing it to the user.
sweepSatsPerKvB := wtpolicy.DefaultSweepFeeRate.FeePerKVByte() sweepSatsPerVB := wtpolicy.DefaultSweepFeeRate.FeePerVByte()
sweepFeeRate := uint64(sweepSatsPerKvB / 1000) sweepFeeRate := uint64(sweepSatsPerVB)
return &WtClient{ return &WtClient{
SweepFeeRate: sweepFeeRate, SweepFeeRate: sweepFeeRate,

View File

@ -782,12 +782,12 @@ func (w *WalletKit) PendingSweeps(ctx context.Context,
op := lnrpc.MarshalOutPoint(&pendingInput.OutPoint) op := lnrpc.MarshalOutPoint(&pendingInput.OutPoint)
amountSat := uint32(pendingInput.Amount) amountSat := uint32(pendingInput.Amount)
satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerKVByte() / 1000) satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerVByte())
broadcastAttempts := uint32(pendingInput.BroadcastAttempts) broadcastAttempts := uint32(pendingInput.BroadcastAttempts)
nextBroadcastHeight := uint32(pendingInput.NextBroadcastHeight) nextBroadcastHeight := uint32(pendingInput.NextBroadcastHeight)
requestedFee := pendingInput.Params.Fee requestedFee := pendingInput.Params.Fee
requestedFeeRate := uint64(requestedFee.FeeRate.FeePerKVByte() / 1000) requestedFeeRate := uint64(requestedFee.FeeRate.FeePerVByte())
rpcPendingSweeps = append(rpcPendingSweeps, &PendingSweep{ rpcPendingSweeps = append(rpcPendingSweeps, &PendingSweep{
Outpoint: op, Outpoint: op,

View File

@ -476,15 +476,11 @@ func (c *WatchtowerClient) Policy(ctx context.Context,
} }
return &PolicyResponse{ return &PolicyResponse{
MaxUpdates: uint32(policy.MaxUpdates), MaxUpdates: uint32(policy.MaxUpdates),
SweepSatPerVbyte: uint32( SweepSatPerVbyte: uint32(policy.SweepFeeRate.FeePerVByte()),
policy.SweepFeeRate.FeePerKVByte() / 1000,
),
// Deprecated field. // Deprecated field.
SweepSatPerByte: uint32( SweepSatPerByte: uint32(policy.SweepFeeRate.FeePerVByte()),
policy.SweepFeeRate.FeePerKVByte() / 1000,
),
}, nil }, nil
} }
@ -519,7 +515,7 @@ func marshallTower(tower *wtclient.RegisteredTower, policyType PolicyType,
rpcSessions = make([]*TowerSession, 0, len(tower.Sessions)) rpcSessions = make([]*TowerSession, 0, len(tower.Sessions))
for _, session := range sessions { for _, session := range sessions {
satPerVByte := session.Policy.SweepFeeRate.FeePerKVByte() / 1000 satPerVByte := session.Policy.SweepFeeRate.FeePerVByte()
rpcSessions = append(rpcSessions, &TowerSession{ rpcSessions = append(rpcSessions, &TowerSession{
NumBackups: uint32(ackCounts[session.ID]), NumBackups: uint32(ackCounts[session.ID]),
NumPendingBackups: uint32(pendingCounts[session.ID]), NumPendingBackups: uint32(pendingCounts[session.ID]),

View File

@ -70,6 +70,11 @@ func (s SatPerKWeight) FeePerKVByte() SatPerKVByte {
return SatPerKVByte(s * blockchain.WitnessScaleFactor) 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. // String returns a human-readable string of the fee rate.
func (s SatPerKWeight) String() string { func (s SatPerKWeight) String() string {
return fmt.Sprintf("%v sat/kw", int64(s)) return fmt.Sprintf("%v sat/kw", int64(s))

View File

@ -1197,10 +1197,10 @@ func (r *rpcServer) EstimateFee(ctx context.Context,
resp := &lnrpc.EstimateFeeResponse{ resp := &lnrpc.EstimateFeeResponse{
FeeSat: totalFee, FeeSat: totalFee,
SatPerVbyte: uint64(feePerKw.FeePerKVByte() / 1000), SatPerVbyte: uint64(feePerKw.FeePerVByte()),
// Deprecated field. // Deprecated field.
FeerateSatPerByte: int64(feePerKw.FeePerKVByte() / 1000), FeerateSatPerByte: int64(feePerKw.FeePerVByte()),
} }
rpcsLog.Debugf("[estimatefee] fee estimate for conf target %d: %v", rpcsLog.Debugf("[estimatefee] fee estimate for conf target %d: %v",