@@ -664,17 +664,29 @@ func (r *rpcServer) MintAsset(ctx context.Context,
664664
665665// checkFeeRateSanity ensures that the provided fee rate, in sat/kw, is above
666666// the same minimum fee used as a floor in the fee estimator.
667- func checkFeeRateSanity (rpcFeeRate uint32 ) (* chainfee.SatPerKWeight , error ) {
668- feeFloor := uint32 (chainfee .FeePerKwFloor )
667+ func checkFeeRateSanity (ctx context.Context , rpcFeeRate chainfee.SatPerKWeight ,
668+ lndWallet lndclient.WalletKitClient ) (* chainfee.SatPerKWeight , error ) {
669+
670+ feeFloor := chainfee .FeePerKwFloor
671+ minRelayFee , err := lndWallet .MinRelayFee (ctx )
672+ if err != nil {
673+ return nil , err
674+ }
669675 switch {
670676 // No manual fee rate was set, which is the default.
671- case rpcFeeRate == 0 :
677+ case rpcFeeRate == chainfee . SatPerKWeight ( 0 ) :
672678 return nil , nil
673679
674- // A manual fee was set but is below a reasonable floor.
675- case rpcFeeRate < feeFloor :
676- return nil , fmt .Errorf ("manual fee rate below floor: " +
677- "(fee_rate=%d, floor=%d sat/kw)" , rpcFeeRate , feeFloor )
680+ // A manual fee was set but is below a reasonable floor or minRelayFee.
681+ case rpcFeeRate < feeFloor || rpcFeeRate < minRelayFee :
682+ if rpcFeeRate < feeFloor {
683+ return nil , fmt .Errorf ("manual fee rate below floor: " +
684+ "(fee_rate=%s, floor=%s)" , rpcFeeRate .String (),
685+ feeFloor .String ())
686+ }
687+ return nil , fmt .Errorf ("feerate does not meet minrelayfee: " +
688+ "(fee_rate=%s, minrelayfee=%s)" , rpcFeeRate .String (),
689+ minRelayFee .String ())
678690
679691 // Set the fee rate for this transaction.
680692 default :
@@ -683,10 +695,12 @@ func checkFeeRateSanity(rpcFeeRate uint32) (*chainfee.SatPerKWeight, error) {
683695}
684696
685697// FundBatch attempts to fund the current pending batch.
686- func (r * rpcServer ) FundBatch (_ context.Context ,
698+ func (r * rpcServer ) FundBatch (ctx context.Context ,
687699 req * mintrpc.FundBatchRequest ) (* mintrpc.FundBatchResponse , error ) {
688700
689- feeRate , err := checkFeeRateSanity (req .FeeRate )
701+ feeRate , err := checkFeeRateSanity (
702+ ctx , chainfee .SatPerKWeight (req .FeeRate ), r .cfg .Lnd .WalletKit ,
703+ )
690704 if err != nil {
691705 return nil , err
692706 }
@@ -759,11 +773,13 @@ func (r *rpcServer) SealBatch(ctx context.Context,
759773}
760774
761775// FinalizeBatch attempts to finalize the current pending batch.
762- func (r * rpcServer ) FinalizeBatch (_ context.Context ,
776+ func (r * rpcServer ) FinalizeBatch (ctx context.Context ,
763777 req * mintrpc.FinalizeBatchRequest ) (* mintrpc.FinalizeBatchResponse ,
764778 error ) {
765779
766- feeRate , err := checkFeeRateSanity (req .FeeRate )
780+ feeRate , err := checkFeeRateSanity (
781+ ctx , chainfee .SatPerKWeight (req .FeeRate ), r .cfg .Lnd .WalletKit ,
782+ )
767783 if err != nil {
768784 return nil , err
769785 }
@@ -3117,7 +3133,7 @@ func marshalAddrEventStatus(status address.Status) (taprpc.AddrEventStatus,
31173133// complete an asset send. The method returns information w.r.t the on chain
31183134// send, as well as the proof file information the receiver needs to fully
31193135// receive the asset.
3120- func (r * rpcServer ) SendAsset (_ context.Context ,
3136+ func (r * rpcServer ) SendAsset (ctx context.Context ,
31213137 req * taprpc.SendAssetRequest ) (* taprpc.SendAssetResponse , error ) {
31223138
31233139 if len (req .TapAddrs ) == 0 {
@@ -3164,7 +3180,9 @@ func (r *rpcServer) SendAsset(_ context.Context,
31643180 }
31653181 }
31663182
3167- feeRate , err := checkFeeRateSanity (req .FeeRate )
3183+ feeRate , err := checkFeeRateSanity (
3184+ ctx , chainfee .SatPerKWeight (req .FeeRate ), r .cfg .Lnd .WalletKit ,
3185+ )
31683186 if err != nil {
31693187 return nil , err
31703188 }
0 commit comments