mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-19 18:14:19 +01:00
Mint: migration to clean up overly large witnesses (#817)
* add migration to clean up overly large witnesses * bump to 0.18.1
This commit is contained in:
@@ -177,7 +177,7 @@ This command runs the mint on your local computer. Skip this step if you want to
|
|||||||
## Docker
|
## 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
|
## From this repository
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from pydantic import BaseSettings, Extra, Field
|
|||||||
|
|
||||||
env = Env()
|
env = Env()
|
||||||
|
|
||||||
VERSION = "0.18.0"
|
VERSION = "0.18.1"
|
||||||
|
|
||||||
|
|
||||||
def find_env_file():
|
def find_env_file():
|
||||||
|
|||||||
@@ -1137,3 +1137,21 @@ async def m028_promises_c_allow_null_add_melt_quote(db: Database):
|
|||||||
|
|
||||||
# recreate the balance views
|
# recreate the balance views
|
||||||
await create_balance_views(db, conn)
|
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"
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "cashu"
|
name = "cashu"
|
||||||
version = "0.18.0"
|
version = "0.18.1"
|
||||||
description = "Ecash wallet and mint"
|
description = "Ecash wallet and mint"
|
||||||
authors = ["calle <callebtc@protonmail.com>"]
|
authors = ["calle <callebtc@protonmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli.cli:cli"]}
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="cashu",
|
name="cashu",
|
||||||
version="0.18.0",
|
version="0.18.1",
|
||||||
description="Ecash wallet and mint",
|
description="Ecash wallet and mint",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|||||||
74
tests/mint/test_mint_migrations.py
Normal file
74
tests/mint/test_mint_migrations.py
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user