diff --git a/README.md b/README.md index ebcef43..f6c974d 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ This command runs the mint on your local computer. Skip this step if you want to ## Docker ``` -docker run -d -p 3338:3338 --name nutshell -e MINT_BACKEND_BOLT11_SAT=FakeWallet -e MINT_LISTEN_HOST=0.0.0.0 -e MINT_LISTEN_PORT=3338 -e MINT_PRIVATE_KEY=TEST_PRIVATE_KEY cashubtc/nutshell:0.18.0 poetry run mint +docker run -d -p 3338:3338 --name nutshell -e MINT_BACKEND_BOLT11_SAT=FakeWallet -e MINT_LISTEN_HOST=0.0.0.0 -e MINT_LISTEN_PORT=3338 -e MINT_PRIVATE_KEY=TEST_PRIVATE_KEY cashubtc/nutshell:0.18.1 poetry run mint ``` ## From this repository diff --git a/cashu/core/settings.py b/cashu/core/settings.py index cc5f2e5..cd0a11e 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -8,7 +8,7 @@ from pydantic import BaseSettings, Extra, Field env = Env() -VERSION = "0.18.0" +VERSION = "0.18.1" def find_env_file(): diff --git a/cashu/mint/migrations.py b/cashu/mint/migrations.py index 3ebfe12..433c3e1 100644 --- a/cashu/mint/migrations.py +++ b/cashu/mint/migrations.py @@ -1137,3 +1137,21 @@ async def m028_promises_c_allow_null_add_melt_quote(db: Database): # recreate the balance views await create_balance_views(db, conn) + + +async def m029_remove_overlong_witness_values(db: Database): + """ + Delete any witness values longer than 1024 characters in proofs tables. + """ + async with db.connect() as conn: + # Clean proofs_used + await conn.execute( + f"UPDATE {db.table_with_schema('proofs_used')} SET witness = NULL " + "WHERE witness IS NOT NULL AND LENGTH(witness) > 1024" + ) + + # Clean proofs_pending (column exists in newer schemas) + await conn.execute( + f"UPDATE {db.table_with_schema('proofs_pending')} SET witness = NULL " + "WHERE witness IS NOT NULL AND LENGTH(witness) > 1024" + ) diff --git a/pyproject.toml b/pyproject.toml index 20bec5c..f3c6c3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cashu" -version = "0.18.0" +version = "0.18.1" description = "Ecash wallet and mint" authors = ["calle "] license = "MIT" diff --git a/setup.py b/setup.py index af59b17..4bd51f6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli.cli:cli"]} setuptools.setup( name="cashu", - version="0.18.0", + version="0.18.1", description="Ecash wallet and mint", long_description=long_description, long_description_content_type="text/markdown", diff --git a/tests/mint/test_mint_migrations.py b/tests/mint/test_mint_migrations.py new file mode 100644 index 0000000..dd97d21 --- /dev/null +++ b/tests/mint/test_mint_migrations.py @@ -0,0 +1,74 @@ +import pytest + +from cashu.core.db import Database +from cashu.core.migrations import migrate_databases +from cashu.mint import migrations as mint_migrations + + +@pytest.mark.asyncio +async def test_m029_witness_cleanup(): + db = Database("mint", "./test_data/mig_witness_cleanup") + + # Ensure schema is at latest so tables exist + await migrate_databases(db, mint_migrations) + + long_witness = "a" * 1025 + short_witness = "b" * 10 + + async with db.connect() as conn: + # Insert into proofs_used + await conn.execute( + f""" + INSERT INTO {db.table_with_schema('proofs_used')} (amount, id, c, secret, y, witness, created, melt_quote) + VALUES (1, 'kid', 'c_used_long', 's_used_long', 'y_used_long', :w, {db.timestamp_now}, NULL) + """, + {"w": long_witness}, + ) + await conn.execute( + f""" + INSERT INTO {db.table_with_schema('proofs_used')} (amount, id, c, secret, y, witness, created, melt_quote) + VALUES (1, 'kid', 'c_used_short', 's_used_short', 'y_used_short', :w, {db.timestamp_now}, NULL) + """, + {"w": short_witness}, + ) + + # Insert into proofs_pending + await conn.execute( + f""" + INSERT INTO {db.table_with_schema('proofs_pending')} (amount, id, c, secret, y, witness, created, melt_quote) + VALUES (1, 'kid', 'c_pend_long', 's_pend_long', 'y_pend_long', :w, {db.timestamp_now}, NULL) + """, + {"w": long_witness}, + ) + await conn.execute( + f""" + INSERT INTO {db.table_with_schema('proofs_pending')} (amount, id, c, secret, y, witness, created, melt_quote) + VALUES (1, 'kid', 'c_pend_short', 's_pend_short', 'y_pend_short', :w, {db.timestamp_now}, NULL) + """, + {"w": short_witness}, + ) + + # Run the migration under test directly + await mint_migrations.m029_remove_overlong_witness_values(db) + + # Validate cleanup + async with db.connect() as conn: + row = await conn.fetchone( + f"SELECT witness FROM {db.table_with_schema('proofs_used')} WHERE secret = 's_used_long'" + ) + assert row["witness"] is None + + row = await conn.fetchone( + f"SELECT witness FROM {db.table_with_schema('proofs_used')} WHERE secret = 's_used_short'" + ) + assert row["witness"] == short_witness + + row = await conn.fetchone( + f"SELECT witness FROM {db.table_with_schema('proofs_pending')} WHERE secret = 's_pend_long'" + ) + assert row["witness"] is None + + row = await conn.fetchone( + f"SELECT witness FROM {db.table_with_schema('proofs_pending')} WHERE secret = 's_pend_short'" + ) + assert row["witness"] == short_witness