@@ -574,6 +574,8 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
574574
575575 satPerByte := cfg .SweepFeeRateLimit .FeePerKVByte () / 1000
576576
577+ totalRules := len (cfg .ChannelRules ) + len (cfg .PeerRules )
578+
577579 rpcCfg := & looprpc.LiquidityParameters {
578580 MaxMinerFeeSat : uint64 (cfg .MaximumMinerFee ),
579581 MaxSwapFeePpm : uint64 (cfg .MaximumSwapFeePPM ),
@@ -587,7 +589,7 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
587589 AutoloopBudgetSat : uint64 (cfg .AutoFeeBudget ),
588590 AutoMaxInFlight : uint64 (cfg .MaxAutoInFlight ),
589591 Rules : make (
590- []* looprpc.LiquidityRule , 0 , len ( cfg . ChannelRules ) ,
592+ []* looprpc.LiquidityRule , 0 , totalRules ,
591593 ),
592594 MinSwapAmount : uint64 (cfg .ClientRestrictions .Minimum ),
593595 MaxSwapAmount : uint64 (cfg .ClientRestrictions .Maximum ),
@@ -602,19 +604,30 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
602604 }
603605
604606 for channel , rule := range cfg .ChannelRules {
605- rpcRule := & looprpc.LiquidityRule {
606- ChannelId : channel .ToUint64 (),
607- Type : looprpc .LiquidityRuleType_THRESHOLD ,
608- IncomingThreshold : uint32 (rule .MinimumIncoming ),
609- OutgoingThreshold : uint32 (rule .MinimumOutgoing ),
610- }
607+ rpcRule := newRPCRule (channel .ToUint64 (), nil , rule )
608+ rpcCfg .Rules = append (rpcCfg .Rules , rpcRule )
609+ }
611610
611+ for peer , rule := range cfg .PeerRules {
612+ rpcRule := newRPCRule (0 , peer [:], rule )
612613 rpcCfg .Rules = append (rpcCfg .Rules , rpcRule )
613614 }
614615
615616 return rpcCfg , nil
616617}
617618
619+ func newRPCRule (channelID uint64 , peer []byte ,
620+ rule * liquidity.ThresholdRule ) * looprpc.LiquidityRule {
621+
622+ return & looprpc.LiquidityRule {
623+ ChannelId : channelID ,
624+ Pubkey : peer ,
625+ Type : looprpc .LiquidityRuleType_THRESHOLD ,
626+ IncomingThreshold : uint32 (rule .MinimumIncoming ),
627+ OutgoingThreshold : uint32 (rule .MinimumOutgoing ),
628+ }
629+ }
630+
618631// SetLiquidityParams attempts to set our current liquidity manager's
619632// parameters.
620633func (s * swapClientServer ) SetLiquidityParams (ctx context.Context ,
@@ -640,7 +653,9 @@ func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
640653 MaxAutoInFlight : int (in .Parameters .AutoMaxInFlight ),
641654 ChannelRules : make (
642655 map [lnwire.ShortChannelID ]* liquidity.ThresholdRule ,
643- len (in .Parameters .Rules ),
656+ ),
657+ PeerRules : make (
658+ map [route.Vertex ]* liquidity.ThresholdRule ,
644659 ),
645660 ClientRestrictions : liquidity.Restrictions {
646661 Minimum : btcutil .Amount (in .Parameters .MinSwapAmount ),
@@ -656,22 +671,47 @@ func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
656671 }
657672
658673 for _ , rule := range in .Parameters .Rules {
659- var (
660- shortID = lnwire .NewShortChanIDFromInt (rule .ChannelId )
661- err error
662- )
663-
664- // Make sure that there are not multiple rules set for a single
665- // channel.
666- if _ , ok := params .ChannelRules [shortID ]; ok {
667- return nil , fmt .Errorf ("multiple rules set for " +
668- "channel: %v" , shortID )
669- }
674+ peerRule := rule .Pubkey != nil
675+ chanRule := rule .ChannelId != 0
670676
671- params . ChannelRules [ shortID ] , err = rpcToRule (rule )
677+ liquidityRule , err : = rpcToRule (rule )
672678 if err != nil {
673679 return nil , err
674680 }
681+
682+ switch {
683+ case peerRule && chanRule :
684+ return nil , fmt .Errorf ("cannot set channel: %v and " +
685+ "peer: %v fields in rule" , rule .ChannelId ,
686+ rule .Pubkey )
687+
688+ case peerRule :
689+ pubkey , err := route .NewVertexFromBytes (rule .Pubkey )
690+ if err != nil {
691+ return nil , err
692+ }
693+
694+ if _ , ok := params .PeerRules [pubkey ]; ok {
695+ return nil , fmt .Errorf ("multiple rules set " +
696+ "for peer: %v" , pubkey )
697+ }
698+
699+ params .PeerRules [pubkey ] = liquidityRule
700+
701+ case chanRule :
702+ shortID := lnwire .NewShortChanIDFromInt (rule .ChannelId )
703+
704+ if _ , ok := params .ChannelRules [shortID ]; ok {
705+ return nil , fmt .Errorf ("multiple rules set " +
706+ "for channel: %v" , shortID )
707+ }
708+
709+ params .ChannelRules [shortID ] = liquidityRule
710+
711+ default :
712+ return nil , errors .New ("please set channel id or " +
713+ "pubkey for rule" )
714+ }
675715 }
676716
677717 if err := s .liquidityMgr .SetParameters (ctx , params ); err != nil {
@@ -743,6 +783,21 @@ func (s *swapClientServer) SuggestSwaps(ctx context.Context,
743783 Reason : autoloopReason ,
744784 ChannelId : id .ToUint64 (),
745785 }
786+
787+ disqualified = append (disqualified , exclChan )
788+ }
789+
790+ for pubkey , reason := range suggestions .DisqualifiedPeers {
791+ autoloopReason , err := rpcAutoloopReason (reason )
792+ if err != nil {
793+ return nil , err
794+ }
795+
796+ exclChan := & looprpc.Disqualified {
797+ Reason : autoloopReason ,
798+ Pubkey : pubkey [:],
799+ }
800+
746801 disqualified = append (disqualified , exclChan )
747802 }
748803
0 commit comments