Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Reject Internal MPP Melt Quote Requests #697

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,16 @@ async def melt_quote(
# and therefore respond with internal transaction fees (0 for now)
mint_quote = await self.crud.get_mint_quote(request=request, db=self.db)
if mint_quote and mint_quote.unit == melt_quote.unit:
# check if the melt quote is partial and error if it is.
# it's just not possible to handle this case
if melt_quote.is_mpp:
raise TransactionError("internal mpp not allowed.")
payment_quote = self.create_internal_melt_quote(mint_quote, melt_quote)
else:
# not internal
# verify that the backend supports mpp if the quote request has an amount
if melt_quote.is_mpp and not self.backends[method][unit].supports_mpp:
raise TransactionError("backend does not support mpp")
raise TransactionError("backend does not support mpp.")
# get payment quote by backend
payment_quote = await self.backends[method][unit].get_payment_quote(
melt_quote=melt_quote
Expand Down
17 changes: 17 additions & 0 deletions tests/test_wallet_regtest_mpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cashu.wallet.wallet import Wallet
from tests.conftest import SERVER_ENDPOINT
from tests.helpers import (
assert_err,
get_real_invoice,
is_fake,
partial_pay_real_invoice,
Expand Down Expand Up @@ -139,3 +140,19 @@ async def pay_mpp(amount: int, proofs: List[Proof], delay: float = 0.0):
await asyncio.sleep(2)

assert wallet.balance <= 384 - 64


@pytest.mark.asyncio
@pytest.mark.skipif(is_fake, reason="only regtest")
async def test_regtest_internal_mpp_melt_quotes(wallet: Wallet, ledger: Ledger):
# make sure that mpp is supported by the bolt11-sat backend
if not ledger.backends[Method["bolt11"]][wallet.unit].supports_mpp:
pytest.skip("backend does not support mpp")

# create a mint quote
mint_quote = await wallet.request_mint(128)

# try and create a multi-part melt quote
await assert_err(
wallet.melt_quote(mint_quote.request, 100), "internal mpp not allowed"
)
Loading