github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/config/flags_payments.go (about)

     1  /*
     2   * Copyright (C) 2019 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package config
    19  
    20  import (
    21  	"time"
    22  
    23  	"github.com/urfave/cli/v2"
    24  
    25  	"github.com/mysteriumnetwork/node/metadata"
    26  )
    27  
    28  var (
    29  	// FlagPaymentsMaxHermesFee represents the max hermes fee.
    30  	FlagPaymentsMaxHermesFee = cli.IntFlag{
    31  		Name:  "payments.hermes.max.fee",
    32  		Value: 3000,
    33  		Usage: "The max fee that we'll accept from an hermes. In percentiles. 3000 means 30%",
    34  	}
    35  	// FlagPaymentsBCTimeout represents the BC call timeout.
    36  	FlagPaymentsBCTimeout = cli.DurationFlag{
    37  		Name:  "payments.bc.timeout",
    38  		Value: time.Second * 30,
    39  		Usage: "The duration we'll wait before timing out BC calls.",
    40  	}
    41  	// FlagPaymentsHermesPromiseSettleThreshold represents the percentage of balance left when we go for promise settling.
    42  	FlagPaymentsHermesPromiseSettleThreshold = cli.Float64Flag{
    43  		Name:  "payments.hermes.promise.threshold",
    44  		Value: 0.1,
    45  		Usage: "The percentage of balance before we settle promises",
    46  	}
    47  	// FlagPaymentsHermesPromiseSettleTimeout represents the time we wait for confirmation of the promise settlement.
    48  	FlagPaymentsHermesPromiseSettleTimeout = cli.DurationFlag{
    49  		Name:   "payments.hermes.settle.timeout",
    50  		Value:  time.Minute * 3,
    51  		Usage:  "The duration we'll wait before timing out our wait for promise settle.",
    52  		Hidden: true,
    53  	}
    54  	// FlagPaymentsHermesPromiseSettleCheckInterval represents the time for polling for confirmation of the promise settlement.
    55  	FlagPaymentsHermesPromiseSettleCheckInterval = cli.DurationFlag{
    56  		Name:   "payments.hermes.settle.check-interval",
    57  		Value:  time.Second * 30,
    58  		Usage:  "The duration we'll wait before trying to fetch new events.",
    59  		Hidden: true,
    60  	}
    61  	// FlagPaymentsLongBalancePollInterval determines how often we resync balance on chain.
    62  	FlagPaymentsLongBalancePollInterval = cli.DurationFlag{
    63  		Name:   "payments.balance-long-poll.interval",
    64  		Value:  time.Hour * 1,
    65  		Usage:  "The duration we'll wait before trying to fetch new balance.",
    66  		Hidden: true,
    67  	}
    68  	// FlagPaymentsFastBalancePollInterval determines how often we resync balance on chain after on chain events.
    69  	FlagPaymentsFastBalancePollInterval = cli.DurationFlag{
    70  		Name:   "payments.balance-short-poll.interval",
    71  		Value:  time.Minute,
    72  		Usage:  "The duration we'll wait before trying to fetch new balance.",
    73  		Hidden: true,
    74  	}
    75  	// FlagPaymentsFastBalancePollTimeout determines how long we try to resync balance on chain after on chain events.
    76  	FlagPaymentsFastBalancePollTimeout = cli.DurationFlag{
    77  		Name:   "payments.balance-short-poll.timeout",
    78  		Value:  time.Minute * 10,
    79  		Usage:  "The duration we'll wait before giving up trying to fetch new balance.",
    80  		Hidden: true,
    81  	}
    82  	// FlagPaymentsZeroStakeUnsettledAmount determines the minimum amount of myst that we will settle automatically if zero stake is used.
    83  	FlagPaymentsZeroStakeUnsettledAmount = cli.Float64Flag{
    84  		Name:  "payments.zero-stake-unsettled-amount",
    85  		Value: 5.0,
    86  		Usage: "The settling threshold if provider uses a zero stake",
    87  	}
    88  	// FlagPaymentsPromiseSettleMaxFeeThreshold represents the max percentage of the settlement that will be acceptable to pay in transaction fees.
    89  	FlagPaymentsPromiseSettleMaxFeeThreshold = cli.Float64Flag{
    90  		Name:  "payments.settle.max-fee-percentage",
    91  		Value: 0.05,
    92  		Usage: "The max percentage we allow to pay in fees when automatically settling promises.",
    93  	}
    94  	// FlagPaymentsUnsettledMaxAmount determines the maximum amount of myst for which we will consider the fee threshold.
    95  	FlagPaymentsUnsettledMaxAmount = cli.Float64Flag{
    96  		Name:  "payments.unsettled.max-amount",
    97  		Value: 20.0,
    98  		Usage: "The maximum amount of unsettled myst, after that we will always try to settle.",
    99  	}
   100  	// FlagPaymentsRegistryTransactorPollInterval The duration we'll wait before calling transactor to check for new status updates.
   101  	FlagPaymentsRegistryTransactorPollInterval = cli.DurationFlag{
   102  		Name:   "payments.registry-transactor-poll.interval",
   103  		Value:  time.Second * 20,
   104  		Usage:  "The duration we'll wait before calling transactor to check for new status updates",
   105  		Hidden: true,
   106  	}
   107  	// FlagPaymentsRegistryTransactorPollTimeout The duration we'll wait before polling up the transactors registration status again.
   108  	FlagPaymentsRegistryTransactorPollTimeout = cli.DurationFlag{
   109  		Name:   "payments.registry-transactor-poll.timeout",
   110  		Value:  time.Minute * 20,
   111  		Usage:  "The duration we'll wait before giving up on transactors registration status",
   112  		Hidden: true,
   113  	}
   114  	// FlagPaymentsConsumerDataLeewayMegabytes sets the data amount the consumer agrees to pay before establishing a session
   115  	FlagPaymentsConsumerDataLeewayMegabytes = cli.Uint64Flag{
   116  		Name:  metadata.FlagNames.PaymentsDataLeewayMegabytes,
   117  		Usage: "sets the data amount the consumer agrees to pay before establishing a session",
   118  		Value: metadata.MainnetDefinition.Payments.DataLeewayMegabytes,
   119  	}
   120  	// FlagPaymentsHermesStatusRecheckInterval sets how often we re-check the hermes status on bc. Higher values allow for less bc lookups but increase the risk for provider.
   121  	FlagPaymentsHermesStatusRecheckInterval = cli.DurationFlag{
   122  		Hidden: true,
   123  		Name:   "payments.provider.hermes-status-recheck-interval",
   124  		Usage:  "sets the hermes status recheck interval. Setting this to a lower value will decrease potential loss in case of Hermes getting locked.",
   125  		Value:  time.Hour * 2,
   126  	}
   127  	// FlagOffchainBalanceExpiration sets how often we re-check offchain balance on hermes when balance is depleting
   128  	FlagOffchainBalanceExpiration = cli.DurationFlag{
   129  		Hidden: true,
   130  		Name:   "payments.consumer.offchain-expiration",
   131  		Usage:  "after syncing offchain balance, how long should node wait for next check to occur",
   132  		Value:  time.Minute * 30,
   133  	}
   134  	// FlagPaymentsDuringSessionDebug sets if we're in debug more for the payments done in a VPN session.
   135  	FlagPaymentsDuringSessionDebug = cli.BoolFlag{
   136  		Name:   "payments.during-session-debug",
   137  		Usage:  "Set debug mode for payments made during a session, it will bypass any price validation and allow absurd prices during sessions",
   138  		Value:  false,
   139  		Hidden: true,
   140  	}
   141  	// FlagPaymentsAmountDuringSessionDebug sets the amount of MYST sent during session debug
   142  	FlagPaymentsAmountDuringSessionDebug = cli.Uint64Flag{
   143  		Name:   "payments.amount-during-session-debug-amount",
   144  		Usage:  "Set amount to pay during session debug",
   145  		Value:  5000000000000000000,
   146  		Hidden: true,
   147  	}
   148  
   149  	// FlagObserverAddress address of Observer service.
   150  	FlagObserverAddress = cli.StringFlag{
   151  		Name:  metadata.FlagNames.ObserverAddress,
   152  		Usage: "full address of the observer service",
   153  		Value: metadata.DefaultNetwork.ObserverAddress,
   154  	}
   155  
   156  	// FlagPaymentsLimitUnpaidInvoiceValue sets the upper limit of session payment value before forcing an invoice
   157  	FlagPaymentsLimitUnpaidInvoiceValue = cli.StringFlag{
   158  		Name:  "payments.provider.max-unpaid-invoice-value-limit",
   159  		Usage: "sets the max upper limit of session payment value before forcing an invoice. If this value is exceeded before a payment interval is reached, an invoice is sent.",
   160  		Value: "30000000000000000",
   161  	}
   162  
   163  	// FlagPaymentsUnpaidInvoiceValue sets the starting max limit of session payment value before forcing an invoice
   164  	FlagPaymentsUnpaidInvoiceValue = cli.StringFlag{
   165  		Name:   "payments.provider.max-unpaid-invoice-value",
   166  		Usage:  "sets the starting upper limit of session payment value before forcing an invoice. If this value is exceeded before a payment interval is reached, an invoice is sent.",
   167  		Value:  "3000000000000000",
   168  		Hidden: true,
   169  	}
   170  
   171  	// FlagPaymentsProviderInvoiceFrequency determines how often the provider sends invoices.
   172  	FlagPaymentsProviderInvoiceFrequency = cli.DurationFlag{
   173  		Name:   "payments.provider.invoice-frequency",
   174  		Value:  time.Second * 5,
   175  		Usage:  "Determines how often the provider sends invoices.",
   176  		Hidden: true,
   177  	}
   178  
   179  	// FlagPaymentsLimitProviderInvoiceFrequency determines how often the provider sends invoices.
   180  	FlagPaymentsLimitProviderInvoiceFrequency = cli.DurationFlag{
   181  		Name:  "payments.provider.invoice-frequency-limit",
   182  		Value: time.Minute * 5,
   183  		Usage: "Determines how often the provider sends invoices.",
   184  	}
   185  )
   186  
   187  // RegisterFlagsPayments function register payments flags to flag list.
   188  func RegisterFlagsPayments(flags *[]cli.Flag) {
   189  	*flags = append(
   190  		*flags,
   191  		&FlagPaymentsMaxHermesFee,
   192  		&FlagPaymentsBCTimeout,
   193  		&FlagPaymentsHermesPromiseSettleThreshold,
   194  		&FlagPaymentsPromiseSettleMaxFeeThreshold,
   195  		&FlagPaymentsUnsettledMaxAmount,
   196  		&FlagPaymentsHermesPromiseSettleTimeout,
   197  		&FlagPaymentsHermesPromiseSettleCheckInterval,
   198  		&FlagPaymentsLongBalancePollInterval,
   199  		&FlagPaymentsFastBalancePollInterval,
   200  		&FlagPaymentsFastBalancePollTimeout,
   201  		&FlagPaymentsRegistryTransactorPollTimeout,
   202  		&FlagPaymentsRegistryTransactorPollInterval,
   203  		&FlagPaymentsConsumerDataLeewayMegabytes,
   204  		&FlagPaymentsHermesStatusRecheckInterval,
   205  		&FlagOffchainBalanceExpiration,
   206  		&FlagPaymentsZeroStakeUnsettledAmount,
   207  		&FlagPaymentsDuringSessionDebug,
   208  		&FlagPaymentsAmountDuringSessionDebug,
   209  		&FlagObserverAddress,
   210  
   211  		&FlagPaymentsProviderInvoiceFrequency,
   212  		&FlagPaymentsLimitProviderInvoiceFrequency,
   213  
   214  		&FlagPaymentsUnpaidInvoiceValue,
   215  		&FlagPaymentsLimitUnpaidInvoiceValue,
   216  	)
   217  }
   218  
   219  // ParseFlagsPayments function fills in payments options from CLI context.
   220  func ParseFlagsPayments(ctx *cli.Context) {
   221  	Current.ParseIntFlag(ctx, FlagPaymentsMaxHermesFee)
   222  	Current.ParseDurationFlag(ctx, FlagPaymentsBCTimeout)
   223  	Current.ParseFloat64Flag(ctx, FlagPaymentsHermesPromiseSettleThreshold)
   224  	Current.ParseFloat64Flag(ctx, FlagPaymentsPromiseSettleMaxFeeThreshold)
   225  	Current.ParseFloat64Flag(ctx, FlagPaymentsUnsettledMaxAmount)
   226  	Current.ParseDurationFlag(ctx, FlagPaymentsHermesPromiseSettleTimeout)
   227  	Current.ParseDurationFlag(ctx, FlagPaymentsHermesPromiseSettleCheckInterval)
   228  	Current.ParseDurationFlag(ctx, FlagPaymentsFastBalancePollInterval)
   229  	Current.ParseDurationFlag(ctx, FlagPaymentsFastBalancePollTimeout)
   230  	Current.ParseDurationFlag(ctx, FlagPaymentsLongBalancePollInterval)
   231  	Current.ParseDurationFlag(ctx, FlagPaymentsLongBalancePollInterval)
   232  	Current.ParseDurationFlag(ctx, FlagPaymentsRegistryTransactorPollInterval)
   233  	Current.ParseDurationFlag(ctx, FlagPaymentsRegistryTransactorPollTimeout)
   234  	Current.ParseUInt64Flag(ctx, FlagPaymentsConsumerDataLeewayMegabytes)
   235  	Current.ParseDurationFlag(ctx, FlagPaymentsHermesStatusRecheckInterval)
   236  	Current.ParseDurationFlag(ctx, FlagOffchainBalanceExpiration)
   237  	Current.ParseFloat64Flag(ctx, FlagPaymentsZeroStakeUnsettledAmount)
   238  	Current.ParseBoolFlag(ctx, FlagPaymentsDuringSessionDebug)
   239  	Current.ParseUInt64Flag(ctx, FlagPaymentsAmountDuringSessionDebug)
   240  	Current.ParseStringFlag(ctx, FlagObserverAddress)
   241  
   242  	Current.ParseDurationFlag(ctx, FlagPaymentsProviderInvoiceFrequency)
   243  	Current.ParseDurationFlag(ctx, FlagPaymentsLimitProviderInvoiceFrequency)
   244  
   245  	Current.ParseStringFlag(ctx, FlagPaymentsLimitUnpaidInvoiceValue)
   246  	Current.ParseStringFlag(ctx, FlagPaymentsUnpaidInvoiceValue)
   247  }