Survive oversized Electrum replies and ignore dust deposits (B-75, ELC-20, DEP-01, DAT-10)

A reply line over asyncio's default 64 KiB StreamReader limit raised out of
_read_loop and closed the only connection; the pool address's get_history passes
that after ~800 transactions, and dust sent to any public address does it on
purpose.

- ElectrumClient opens the stream with a 16 MiB limit and frames lines itself:
  an oversized line is discarded up to its newline, a non-JSON line is dropped,
  and the request whose id is readable in the first/last 256 bytes fails at once;
  the connection stays up either way.
- Coins below DUST_LIMIT_SATS are never offered as credit candidates, never
  credited, and select_utxos never selects them.
- Spec (ELC-20, DEP-01, DAT-10, ARC), storico, BUGS.md and test counts updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-10-14 12:14:12 +02:00
1 parent b424f670c5
commit daec4749c2
15 files changed
+245 -49

No files matched your search

+22
View File
@@ -207,3 +207,25 @@ async def test_find_new_credit_candidates_skips_unconfirmed_and_already_known(se
candidates = await find_new_credit_candidates(session, user_id, entries)
assert [(c["tx_hash"], c["tx_pos"]) for c in candidates] == [("cc" * 32, 1)]
# --- B-75 (DEP-01): coins below DUST_LIMIT_SATS are never credited -------------
async def test_dust_is_never_credited_nor_offered_as_a_candidate(session_factory, user_id):
"""DEP-01 / B-75: anyone can send dust to a public address."""
from app.deposits.service import find_new_credit_candidates
from app.wallet.psbt_builder import DUST_LIMIT_SATS
entries = [
{"tx_hash": "e1" * 32, "tx_pos": 0, "height": 100, "value": DUST_LIMIT_SATS - 1},
{"tx_hash": "e2" * 32, "tx_pos": 1, "height": 100, "value": DUST_LIMIT_SATS},
]
async with session_factory() as session:
candidates = await find_new_credit_candidates(session, user_id, entries)
assert [c["tx_hash"] for c in candidates] == ["e2" * 32]
assert await credit_confirmed_utxos(session, user_id, entries) == 1
user = await session.get(User, user_id)
assert user.cached_balance_sats == DUST_LIMIT_SATS
rows = (await session.scalars(select(UtxoEvent))).all()
assert [r.txid for r in rows] == ["e2" * 32]