Remove channel_fee_start_amount and add channel_fee_permyriad

This commit is contained in:
Yaacov Akiba Slama
2020-09-09 17:41:12 +03:00
parent 5e4f1a1aeb
commit 980d2b40e5
4 changed files with 68 additions and 83 deletions

View File

@@ -25,10 +25,7 @@ import (
) )
func checkPayment(incomingAmountMsat, outgoingAmountMsat int64) error { func checkPayment(incomingAmountMsat, outgoingAmountMsat int64) error {
var fees int64 = 0 fees := incomingAmountMsat * channelFeePermyriad / 10_000 / 1_000 * 1_000
if incomingAmountMsat > channelFeeStartAmount {
fees += (incomingAmountMsat - channelFeeStartAmount) * channelFeeAmountNumerator / channelFeeAmountDenominator
}
if incomingAmountMsat-outgoingAmountMsat < fees { if incomingAmountMsat-outgoingAmountMsat < fees {
return fmt.Errorf("not enough fees") return fmt.Errorf("not enough fees")
} }
@@ -36,7 +33,7 @@ func checkPayment(incomingAmountMsat, outgoingAmountMsat int64) error {
} }
func openChannel(ctx context.Context, client lnrpc.LightningClient, paymentHash, destination []byte, incomingAmountMsat int64) ([]byte, uint32, error) { func openChannel(ctx context.Context, client lnrpc.LightningClient, paymentHash, destination []byte, incomingAmountMsat int64) ([]byte, uint32, error) {
capacity := incomingAmountMsat/1000 + channelFeeStartAmount capacity := incomingAmountMsat/1000 + additionalChannelCapacity
channelPoint, err := client.OpenChannelSync(ctx, &lnrpc.OpenChannelRequest{ channelPoint, err := client.OpenChannelSync(ctx, &lnrpc.OpenChannelRequest{
NodePubkey: destination, NodePubkey: destination,
LocalFundingAmount: capacity, LocalFundingAmount: capacity,

View File

@@ -86,13 +86,12 @@ type ChannelInformationReply struct {
TimeLockDelta uint32 `protobuf:"varint,8,opt,name=time_lock_delta,proto3" json:"time_lock_delta,omitempty"` TimeLockDelta uint32 `protobuf:"varint,8,opt,name=time_lock_delta,proto3" json:"time_lock_delta,omitempty"`
/// The minimum value in millisatoshi we will require for incoming HTLCs on /// The minimum value in millisatoshi we will require for incoming HTLCs on
/// the channel. /// the channel.
MinHtlcMsat int64 `protobuf:"varint,9,opt,name=min_htlc_msat,proto3" json:"min_htlc_msat,omitempty"` MinHtlcMsat int64 `protobuf:"varint,9,opt,name=min_htlc_msat,proto3" json:"min_htlc_msat,omitempty"`
ChannelFeeStartAmount int64 `protobuf:"varint,10,opt,name=channel_fee_start_amount,json=channelFeeStartAmount,proto3" json:"channel_fee_start_amount,omitempty"` ChannelFeePermyriad int64 `protobuf:"varint,10,opt,name=channel_fee_permyriad,json=channelFeePermyriad,proto3" json:"channel_fee_permyriad,omitempty"`
ChannelFeeRate float32 `protobuf:"fixed32,11,opt,name=channel_fee_rate,json=channelFeeRate,proto3" json:"channel_fee_rate,omitempty"` LspPubkey []byte `protobuf:"bytes,11,opt,name=lsp_pubkey,json=lspPubkey,proto3" json:"lsp_pubkey,omitempty"`
LspPubkey []byte `protobuf:"bytes,12,opt,name=lsp_pubkey,json=lspPubkey,proto3" json:"lsp_pubkey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"`
XXX_sizecache int32 `json:"-"`
} }
func (m *ChannelInformationReply) Reset() { *m = ChannelInformationReply{} } func (m *ChannelInformationReply) Reset() { *m = ChannelInformationReply{} }
@@ -183,16 +182,9 @@ func (m *ChannelInformationReply) GetMinHtlcMsat() int64 {
return 0 return 0
} }
func (m *ChannelInformationReply) GetChannelFeeStartAmount() int64 { func (m *ChannelInformationReply) GetChannelFeePermyriad() int64 {
if m != nil { if m != nil {
return m.ChannelFeeStartAmount return m.ChannelFeePermyriad
}
return 0
}
func (m *ChannelInformationReply) GetChannelFeeRate() float32 {
if m != nil {
return m.ChannelFeeRate
} }
return 0 return 0
} }
@@ -449,44 +441,43 @@ func init() {
} }
var fileDescriptor_c69a0f5a734bca26 = []byte{ var fileDescriptor_c69a0f5a734bca26 = []byte{
// 586 bytes of a gzipped FileDescriptorProto // 568 bytes of a gzipped FileDescri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 0xaa, 0xdd, 0x5f, 0x69, 0x1c, 0x4d, 0x76, 0xfc, 0xef, 0xe9, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff,
0xaa, 0xc9, 0xc8, 0xfc, 0xc4, 0x46, 0xc1, 0x78, 0xd7, 0xfe, 0xcd, 0xce, 0xff, 0x06, 0x00, 0x00, 0x41, 0x89, 0xc1, 0x2c, 0xac, 0x04, 0x00, 0x00,
0xff, 0xff, 0xd7, 0x15, 0xf2, 0x09, 0xdb, 0x04, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.

View File

@@ -45,10 +45,9 @@ message ChannelInformationReply {
/// the channel. /// the channel.
int64 min_htlc_msat = 9 [ json_name = "min_htlc_msat" ]; int64 min_htlc_msat = 9 [ json_name = "min_htlc_msat" ];
int64 channel_fee_start_amount = 10; int64 channel_fee_permyriad = 10;
float channel_fee_rate = 11;
bytes lsp_pubkey = 12; bytes lsp_pubkey = 11;
} }
message OpenChannelRequest { message OpenChannelRequest {

View File

@@ -29,15 +29,14 @@ import (
) )
const ( const (
channelAmount = 1_000_000 channelAmount = 1_000_000
targetConf = 1 targetConf = 1
minHtlcMsat = 600 minHtlcMsat = 600
baseFeeMsat = 1000 baseFeeMsat = 1000
feeRate = 0.000001 feeRate = 0.000001
timeLockDelta = 144 timeLockDelta = 144
channelFeeStartAmount = 100_000 channelFeePermyriad = 10
channelFeeAmountNumerator = 1 additionalChannelCapacity = 100_000
channelFeeAmountDenominator = 1000
) )
type server struct{} type server struct{}
@@ -54,18 +53,17 @@ var (
func (s *server) ChannelInformation(ctx context.Context, in *lspdrpc.ChannelInformationRequest) (*lspdrpc.ChannelInformationReply, error) { func (s *server) ChannelInformation(ctx context.Context, in *lspdrpc.ChannelInformationRequest) (*lspdrpc.ChannelInformationReply, error) {
return &lspdrpc.ChannelInformationReply{ return &lspdrpc.ChannelInformationReply{
Name: nodeName, Name: nodeName,
Pubkey: nodePubkey, Pubkey: nodePubkey,
Host: os.Getenv("NODE_HOST"), Host: os.Getenv("NODE_HOST"),
ChannelCapacity: channelAmount, ChannelCapacity: channelAmount,
TargetConf: targetConf, TargetConf: targetConf,
MinHtlcMsat: minHtlcMsat, MinHtlcMsat: minHtlcMsat,
BaseFeeMsat: baseFeeMsat, BaseFeeMsat: baseFeeMsat,
FeeRate: feeRate, FeeRate: feeRate,
TimeLockDelta: timeLockDelta, TimeLockDelta: timeLockDelta,
ChannelFeeStartAmount: channelFeeStartAmount, ChannelFeePermyriad: channelFeePermyriad,
ChannelFeeRate: 1.0 * channelFeeAmountNumerator / channelFeeAmountDenominator, LspPubkey: publicKey.SerializeCompressed(),
LspPubkey: publicKey.SerializeCompressed(),
}, nil }, nil
} }