Mint: adjust mint melt settings (#764)

* adjust mint melt settings

* .env.example

* ge=0, closes #756
This commit is contained in:
callebtc
2025-06-01 12:24:37 +02:00
committed by GitHub
parent 67b7ea6b72
commit 48823d673d
5 changed files with 68 additions and 36 deletions

View File

@@ -121,11 +121,13 @@ LIGHTNING_RESERVE_FEE_MIN=2000
# Max mint balance in satoshis
# MINT_MAX_BALANCE=1000000
# Max peg-in amount in satoshis
# MINT_MAX_PEG_IN=100000
# MINT_MAX_MINT_BOLT11_SAT=100000
# Max peg-out amount in satoshis
# MINT_MAX_PEG_OUT=100000
# Use to allow only peg-out to LN
# MINT_PEG_OUT_ONLY=FALSE
# MINT_MAX_MELT_BOLT11_SAT=100000
# Disable minting of BOLT11 invoices
# MINT_BOLT11_DISABLE_MINT=FALSE
# Disable melting of BOLT11 invoices
# MINT_BOLT11_DISABLE_MELT=FALSE
# Rate limit requests to mint. Make sure that you can see request IPs in the logs.
# You may need to adjust your reverse proxy if you only see requests originating from 127.0.0.1

View File

@@ -125,26 +125,49 @@ class MintLimits(MintSettings):
description="Maximum length of REST API request arrays.",
)
mint_peg_out_only: bool = Field(
mint_peg_out_only: bool = Field( # deprecated for mint_bolt11_disable_mint
default=False,
title="Peg-out only",
description="Mint allows no mint operations.",
title="Disable minting tokens with bolt11",
description="Mint allows no bolt11 minting operations.",
)
mint_max_peg_in: int = Field(
mint_bolt11_disable_mint: bool = Field(
default=False,
title="Disable minting tokens with bolt11",
description="Mint allows no bolt11 minting operations.",
)
mint_bolt11_disable_melt: bool = Field(
default=False,
title="Disable melting tokens with bolt11",
description="Mint allows no bolt11 melting operations.",
)
mint_max_peg_in: int = Field( # deprecated for mint_max_mint_bolt11_sat
default=None,
gt=0,
ge=0,
title="Maximum peg-in",
description="Maximum amount for a mint operation.",
)
mint_max_peg_out: int = Field(
mint_max_peg_out: int = Field( # deprecated for mint_max_melt_bolt11_sat
default=None,
gt=0,
ge=0,
title="Maximum peg-out",
description="Maximum amount for a melt operation.",
)
mint_max_mint_bolt11_sat: int = Field(
default=None,
ge=0,
title="Maximum mint amount for bolt11 in satoshis",
description="Maximum amount for a bolt11 mint operation in satoshis.",
)
mint_max_melt_bolt11_sat: int = Field(
default=None,
ge=0,
title="Maximum melt amount for bolt11 in satoshis",
description="Maximum amount for a bolt11 melt operation in satoshis.",
)
mint_max_balance: int = Field(
default=None,
gt=0,
ge=0,
title="Maximum mint balance",
description="Maximum mint balance.",
)
@@ -339,5 +362,15 @@ def startup_settings_tasks():
if settings.mint_lightning_backend:
settings.mint_backend_bolt11_sat = settings.mint_lightning_backend
# backwards compatibility: mint_max_peg_in and mint_max_peg_out to mint_max_mint_bolt11_sat and mint_max_melt_bolt11_sat
if settings.mint_max_peg_in:
settings.mint_max_mint_bolt11_sat = settings.mint_max_peg_in
if settings.mint_max_peg_out:
settings.mint_max_melt_bolt11_sat = settings.mint_max_peg_out
# backwards compatibility: set mint_bolt11_disable_mint from mint_peg_out_only
if settings.mint_peg_out_only:
settings.mint_bolt11_disable_mint = True
startup_settings_tasks()

View File

@@ -81,8 +81,8 @@ class LedgerFeatures(SupportsBackends, SupportsPubkey):
for method, unit_dict in self.backends.items():
for unit in unit_dict.keys():
mint_setting = MintMethodSetting(method=method.name, unit=unit.name)
if settings.mint_max_peg_in:
mint_setting.max_amount = settings.mint_max_peg_in
if settings.mint_max_mint_bolt11_sat:
mint_setting.max_amount = settings.mint_max_mint_bolt11_sat
mint_setting.min_amount = 0
mint_method_settings.append(mint_setting)
mint_setting.description = unit_dict[unit].supports_description
@@ -90,19 +90,19 @@ class LedgerFeatures(SupportsBackends, SupportsPubkey):
for method, unit_dict in self.backends.items():
for unit in unit_dict.keys():
melt_setting = MeltMethodSetting(method=method.name, unit=unit.name)
if settings.mint_max_peg_out:
melt_setting.max_amount = settings.mint_max_peg_out
if settings.mint_max_melt_bolt11_sat:
melt_setting.max_amount = settings.mint_max_melt_bolt11_sat
melt_setting.min_amount = 0
melt_method_settings.append(melt_setting)
mint_features: Dict[int, Union[List[Any], Dict[str, Any]]] = {
MINT_NUT: dict(
methods=mint_method_settings,
disabled=settings.mint_peg_out_only,
disabled=settings.mint_bolt11_disable_mint,
),
MELT_NUT: dict(
methods=melt_method_settings,
disabled=False,
disabled=settings.mint_bolt11_disable_melt,
),
}
return mint_features

View File

@@ -325,12 +325,15 @@ class Ledger(
logger.trace("called request_mint")
if not quote_request.amount > 0:
raise TransactionError("amount must be positive")
if settings.mint_max_peg_in and quote_request.amount > settings.mint_max_peg_in:
if (
settings.mint_max_mint_bolt11_sat
and quote_request.amount > settings.mint_max_mint_bolt11_sat
):
raise TransactionAmountExceedsLimitError(
f"Maximum mint amount is {settings.mint_max_peg_in} sat."
f"Maximum mint amount is {settings.mint_max_mint_bolt11_sat} sat."
)
if settings.mint_peg_out_only:
raise NotAllowedError("Mint does not allow minting new tokens.")
if settings.mint_bolt11_disable_mint:
raise NotAllowedError("Minting with bol11 is disabled.")
unit, method = self._verify_and_get_unit_method(
quote_request.unit, Method.bolt11.name
@@ -585,6 +588,9 @@ class Ledger(
Returns:
PostMeltQuoteResponse: Melt quote response.
"""
if settings.mint_bolt11_disable_melt:
raise NotAllowedError("Melting with bol11 is disabled.")
unit, method = self._verify_and_get_unit_method(
melt_quote.unit, Method.bolt11.name
)
@@ -617,11 +623,11 @@ class Ledger(
# verify that the amount of the proofs is not larger than the maximum allowed
if (
settings.mint_max_peg_out
and payment_quote.amount.to(unit).amount > settings.mint_max_peg_out
settings.mint_max_melt_bolt11_sat
and payment_quote.amount.to(unit).amount > settings.mint_max_melt_bolt11_sat
):
raise NotAllowedError(
f"Maximum melt amount is {settings.mint_max_peg_out} sat."
f"Maximum melt amount is {settings.mint_max_melt_bolt11_sat} sat."
)
# We assume that the request is a bolt11 invoice, this works since we
@@ -890,11 +896,7 @@ class Ledger(
raise TransactionError(
f"not enough fee reserve provided for melt. Provided fee reserve: {fee_reserve_provided}, needed: {melt_quote.fee_reserve}"
)
# verify that the amount of the proofs is not larger than the maximum allowed
if settings.mint_max_peg_out and total_provided > settings.mint_max_peg_out:
raise NotAllowedError(
f"Maximum melt amount is {settings.mint_max_peg_out} sat."
)
# verify inputs and their spending conditions
# note, we do not verify outputs here, as they are only used for returning overpaid fees
# We must have called _verify_outputs here already! (see above)

View File

@@ -52,11 +52,6 @@ async def info() -> GetInfoResponse_deprecated:
contact=settings.mint_info_contact,
nuts=["NUT-07", "NUT-08", "NUT-09"],
motd=settings.mint_info_motd,
parameter={
"max_peg_in": settings.mint_max_peg_in,
"max_peg_out": settings.mint_max_peg_out,
"peg_out_only": settings.mint_peg_out_only,
},
)
@@ -143,7 +138,7 @@ async def request_mint_deprecated(
logger.trace(f"> GET /mint: amount={amount}")
if amount > 21_000_000 * 100_000_000 or amount <= 0:
raise CashuError(code=0, detail="Amount must be a valid amount of sat.")
if settings.mint_peg_out_only:
if settings.mint_bolt11_disable_mint:
raise CashuError(code=0, detail="Mint does not allow minting new tokens.")
quote = await ledger.mint_quote(PostMintQuoteRequest(amount=amount, unit="sat"))
resp = GetMintResponse_deprecated(pr=quote.request, hash=quote.quote)