accounting table locks

This commit is contained in:
tim
2025-02-05 10:19:19 -04:00
parent cda2446c0e
commit 3bec4b8611
4 changed files with 19 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
import asyncio
import logging
from sqlalchemy import select, func
from sqlalchemy import select, func, text
from typing_extensions import Optional
from web3.exceptions import ContractLogicError
from web3.types import EventData
@@ -212,6 +212,9 @@ async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=Acc
async def reconcile(account: DbAccount, block_id: Optional[str] = None, last_accounting_row_id: Optional[int] = None):
# First we lock all the relevant tables to ensure consistency
db.session.execute(text("LOCK TABLE account, accounting, reconciliation IN EXCLUSIVE MODE"))
# Fetch the latest reconciliation for the account
latest_recon = db.session.execute(
select(Reconciliation).where(

View File

@@ -0,0 +1,12 @@
import logging
from dexorder.bin.executable import execute
log = logging.getLogger(__name__)
async def main():
pass
if __name__ == '__main__':
execute(main())

View File

@@ -51,3 +51,6 @@ class Config:
stablecoins: list[str] = field(default_factory=list) # primary stablecoins which are marked to $1
quotecoins: list[str] = field(default_factory=list) # quote tokens like WETH that have stablecoin markets
nativecoin: Optional[str] = None # used for accounting of native values. e.g. address of WETH
# account: target_balance
refill: dict[str,str] = field(default_factory=dict)

View File

@@ -195,8 +195,6 @@ async def mark_to_market_adj_dec(token: str, amount: dec, adjust_decimals=True)
"""
Returns the current USD value for the amount of token.
"""
if not accounting_initialized:
await initialize_accounting()
if adjust_decimals:
amount = await adj_dec(token, amount)
return mark_to_market(token, amount)