rpcserver: rename UpdateFees -> UpdateChannelPolicy

This commit changes the name of the UpdateFee method to
UpdateChannelPolicy, to mimic the recent proto change.
It also reads and validates the passed TimeLockDelta,
and sends it to the gossiper for announcing it to the
network, and to the switch for updating the forwarding
policy of the links.
This commit is contained in:
Johan T. Halseth 2017-12-16 23:14:58 +01:00
parent 26421031e2
commit c4139b9f89
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -3192,13 +3192,13 @@ func (r *rpcServer) FeeReport(ctx context.Context,
// 0.000001, or 0.0001%. // 0.000001, or 0.0001%.
const minFeeRate = 1e-6 const minFeeRate = 1e-6
// UpdateFees allows the caller to update the fee schedule for all channels // UpdateChannelPolicy allows the caller to update the channel forwarding policy
// globally, or a particular channel. // for all channels globally, or a particular channel.
func (r *rpcServer) UpdateFees(ctx context.Context, func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
req *lnrpc.FeeUpdateRequest) (*lnrpc.FeeUpdateResponse, error) { req *lnrpc.PolicyUpdateRequest) (*lnrpc.PolicyUpdateResponse, error) {
if r.authSvc != nil { if r.authSvc != nil {
if err := macaroons.ValidateMacaroon(ctx, "udpatefees", if err := macaroons.ValidateMacaroon(ctx, "updatechannelpolicy",
r.authSvc); err != nil { r.authSvc); err != nil {
return nil, err return nil, err
} }
@ -3208,11 +3208,11 @@ func (r *rpcServer) UpdateFees(ctx context.Context,
switch scope := req.Scope.(type) { switch scope := req.Scope.(type) {
// If the request is targeting all active channels, then we don't need // If the request is targeting all active channels, then we don't need
// target any channels by their channel point. // target any channels by their channel point.
case *lnrpc.FeeUpdateRequest_Global: case *lnrpc.PolicyUpdateRequest_Global:
// Otherwise, we're targeting an individual channel by its channel // Otherwise, we're targeting an individual channel by its channel
// point. // point.
case *lnrpc.FeeUpdateRequest_ChanPoint: case *lnrpc.PolicyUpdateRequest_ChanPoint:
txid, err := chainhash.NewHash(scope.ChanPoint.FundingTxid) txid, err := chainhash.NewHash(scope.ChanPoint.FundingTxid)
if err != nil { if err != nil {
return nil, err return nil, err
@ -3226,12 +3226,19 @@ func (r *rpcServer) UpdateFees(ctx context.Context,
} }
// As a sanity check, we'll ensure that the passed fee rate is below // As a sanity check, we'll ensure that the passed fee rate is below
// 1e-6, or the lowest allowed fee rate. // 1e-6, or the lowest allowed fee rate, and that the passed timelock
// is large enough.
if req.FeeRate < minFeeRate { if req.FeeRate < minFeeRate {
return nil, fmt.Errorf("fee rate of %v is too small, min fee "+ return nil, fmt.Errorf("fee rate of %v is too small, min fee "+
"rate is %v", req.FeeRate, minFeeRate) "rate is %v", req.FeeRate, minFeeRate)
} }
if req.TimeLockDelta < minTimeLockDelta {
return nil, fmt.Errorf("time lock delta of %v is too small, "+
"minimum supported is %v", req.TimeLockDelta,
minTimeLockDelta)
}
// We'll also need to convert the floating point fee rate we accept // We'll also need to convert the floating point fee rate we accept
// over RPC to the fixed point rate that we use within the protocol. We // over RPC to the fixed point rate that we use within the protocol. We
// do this by multiplying the passed fee rate by the fee base. This // do this by multiplying the passed fee rate by the fee base. This
@ -3244,16 +3251,21 @@ func (r *rpcServer) UpdateFees(ctx context.Context,
FeeRate: feeRateFixed, FeeRate: feeRateFixed,
} }
rpcsLog.Tracef("[updatefees] updating fee schedule base_fee=%v, "+ chanPolicy := routing.ChannelPolicy{
"rate_float=%v, rate_fixed=%v, targets=%v", FeeSchema: feeSchema,
req.BaseFeeMsat, req.FeeRate, feeRateFixed, TimeLockDelta: req.TimeLockDelta,
}
rpcsLog.Tracef("[updatechanpolicy] updating channel policy base_fee=%v, "+
"rate_float=%v, rate_fixed=%v, time_lock_delta: %v, targets=%v",
req.BaseFeeMsat, req.FeeRate, feeRateFixed, req.TimeLockDelta,
spew.Sdump(targetChans)) spew.Sdump(targetChans))
// With the scope resolved, we'll now send this to the // With the scope resolved, we'll now send this to the
// AuthenticatedGossiper so it can propagate the new fee schema for out // AuthenticatedGossiper so it can propagate the new policy for our
// target channel(s). // target channel(s).
err := r.server.authGossiper.PropagateFeeUpdate( err := r.server.authGossiper.PropagateChanPolicyUpdate(
feeSchema, targetChans..., chanPolicy, targetChans...,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -3265,8 +3277,9 @@ func (r *rpcServer) UpdateFees(ctx context.Context,
// We create a partially policy as the logic won't overwrite a valid // We create a partially policy as the logic won't overwrite a valid
// sub-policy with a "nil" one. // sub-policy with a "nil" one.
p := htlcswitch.ForwardingPolicy{ p := htlcswitch.ForwardingPolicy{
BaseFee: baseFeeMsat, BaseFee: baseFeeMsat,
FeeRate: lnwire.MilliSatoshi(feeRateFixed), FeeRate: lnwire.MilliSatoshi(feeRateFixed),
TimeLockDelta: req.TimeLockDelta,
} }
err = r.server.htlcSwitch.UpdateForwardingPolicies(p, targetChans...) err = r.server.htlcSwitch.UpdateForwardingPolicies(p, targetChans...)
if err != nil { if err != nil {
@ -3276,5 +3289,5 @@ func (r *rpcServer) UpdateFees(ctx context.Context,
rpcsLog.Warnf("Unable to update link fees: %v", err) rpcsLog.Warnf("Unable to update link fees: %v", err)
} }
return &lnrpc.FeeUpdateResponse{}, nil return &lnrpc.PolicyUpdateResponse{}, nil
} }