Skip to content
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
26 changes: 26 additions & 0 deletions node/test_utxo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,32 @@ def _conn(self):
}, block_height=10)
self.assertFalse(ok)

def test_user_supplied_mining_reward_preserves_external_conn(self):
"""Rejected mint attempts must not close a caller-owned connection."""
conn = self.db._conn()
try:
conn.execute("BEGIN IMMEDIATE")
ok = self.db.apply_transaction({
'tx_type': 'mining_reward',
'inputs': [],
'outputs': [{'address': 'attacker', 'value_nrtc': 1 * UNIT}],
'fee_nrtc': 0,
'timestamp': int(time.time()),
}, block_height=10, conn=conn)
self.assertFalse(ok)

try:
self.assertEqual(conn.execute("SELECT 1").fetchone()[0], 1)
except Exception as exc:
self.fail(f"apply_transaction closed caller-owned conn: {exc}")
finally:
try:
if conn.in_transaction:
conn.execute("ROLLBACK")
conn.close()
except Exception:
pass

def test_mempool_empty_inputs_rejected_for_transfer(self):
"""Mempool must also reject non-minting txs with empty inputs."""
tx = {
Expand Down
2 changes: 0 additions & 2 deletions node/utxo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ def apply_transaction(self, tx: dict, block_height: int,
# Require _allow_minting=True (internal flag) to permit mining_reward.
MINTING_TX_TYPES = {'mining_reward'}
if tx_type in MINTING_TX_TYPES and not tx.get('_allow_minting'):
if conn:
conn.close()
return False
if own:
conn = self._conn()
Expand Down
Loading