mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-24 03:54:21 +01:00
Mint: table locks (#566)
* clean up db * db: table lock * db.table_with_schema * fix encrypt.py * postgres nowait * add timeout to lock * melt quote state in db * kinda working * kinda working with postgres * remove dispose * getting there * porperly clean up db for tests * faster tests * configure connection pooling * try github with connection pool * invoice dispatcher does not lock db * fakewallet: pay_if_regtest waits * pay fakewallet invoices * add more * faster * slower * pay_if_regtest async * do not lock the invoice dispatcher * test: do I get disk I/O errors if we disable the invoice_callback_dispatcher? * fix fake so it workss without a callback dispatchert * test on github * readd tasks * refactor * increase time for lock invoice disatcher * try avoiding a race * remove task * github actions: test regtest with postgres * mint per module * no connection pool for testing * enable pool * do not resend paid event * reuse connection * close db connections * sessions * enable debug * dispose engine * disable connection pool for tests * enable connection pool for postgres only * clean up shutdown routine * remove wait for lightning fakewallet lightning invoice * cancel invoice listener tasks on shutdown * fakewallet conftest: decrease outgoing delay * delay payment and set postgres only if needed * disable fail fast for regtest * clean up regtest.yml * change order of tests_db.py * row-specific mint_quote locking * refactor * fix lock statement * refactor swap * refactor * remove psycopg2 * add connection string example to .env.example * remove unnecessary pay * shorter sleep in test_wallet_subscription_swap
This commit is contained in:
@@ -344,11 +344,13 @@ class MeltQuote(LedgerEvent):
|
||||
def __setattr__(self, name, value):
|
||||
# an unpaid quote can only be set to pending or paid
|
||||
if name == "state" and self.state == MeltQuoteState.unpaid:
|
||||
if value != MeltQuoteState.pending and value != MeltQuoteState.paid:
|
||||
raise Exception("Cannot change state of an unpaid quote.")
|
||||
if value not in [MeltQuoteState.pending, MeltQuoteState.paid]:
|
||||
raise Exception(
|
||||
f"Cannot change state of an unpaid melt quote to {value}."
|
||||
)
|
||||
# a paid quote can not be changed
|
||||
if name == "state" and self.state == MeltQuoteState.paid:
|
||||
raise Exception("Cannot change state of a paid quote.")
|
||||
raise Exception("Cannot change state of a paid melt quote.")
|
||||
super().__setattr__(name, value)
|
||||
|
||||
|
||||
@@ -415,18 +417,20 @@ class MintQuote(LedgerEvent):
|
||||
# un unpaid quote can only be set to paid
|
||||
if name == "state" and self.state == MintQuoteState.unpaid:
|
||||
if value != MintQuoteState.paid:
|
||||
raise Exception("Cannot change state of an unpaid quote.")
|
||||
raise Exception(
|
||||
f"Cannot change state of an unpaid mint quote to {value}."
|
||||
)
|
||||
# a paid quote can only be set to pending or issued
|
||||
if name == "state" and self.state == MintQuoteState.paid:
|
||||
if value != MintQuoteState.pending and value != MintQuoteState.issued:
|
||||
raise Exception(f"Cannot change state of a paid quote to {value}.")
|
||||
raise Exception(f"Cannot change state of a paid mint quote to {value}.")
|
||||
# a pending quote can only be set to paid or issued
|
||||
if name == "state" and self.state == MintQuoteState.pending:
|
||||
if value not in [MintQuoteState.paid, MintQuoteState.issued]:
|
||||
raise Exception("Cannot change state of a pending quote.")
|
||||
raise Exception("Cannot change state of a pending mint quote.")
|
||||
# an issued quote cannot be changed
|
||||
if name == "state" and self.state == MintQuoteState.issued:
|
||||
raise Exception("Cannot change state of an issued quote.")
|
||||
raise Exception("Cannot change state of an issued mint quote.")
|
||||
super().__setattr__(name, value)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user