applyFills() fixes

This commit is contained in:
Tim
2024-03-30 14:56:20 -04:00
parent aeb7a41e7d
commit 26736ad437
4 changed files with 15 additions and 6 deletions

View File

@@ -30,8 +30,7 @@ class RedisState (SeriesCollection):
async def clear(self):
log.debug('clearing memcache')
r = current_redis.get()
result = await r.delete(*[f'{current_chain.get().chain_id}|{k}' for k in ['latest_block', *self.datas.keys()]])
print(result)
await r.delete(*[f'{current_chain.get().chain_id}|{k}' for k in ['latest_block', *self.datas.keys()]])
async def init(self, state: BlockState):

View File

@@ -87,6 +87,7 @@ class Order:
Order.vault_open_orders.listappend(key.vault, key.order_index)
# Start with a filled value of 0 even if the chain says otherwise, because we will process the fill events later and add them in
tranche_filled = [Filled(0,0) for _ in range(len(status.trancheFilledIn))]
order_log.debug(f'initialized order_filled[{key}]')
Order.order_filled[key] = OrderFilled(Filled(0,0), tranche_filled)
order_log.debug(f'order created {key}')
return order
@@ -156,13 +157,16 @@ class Order:
def add_fill(self, tranche_index: int, filled_in: int, filled_out: int):
order_log.debug(f'tranche fill {self.key}|{tranche_index} in:{filled_in} out:{filled_out}')
old = Order.order_filled[self.key]
try:
old = Order.order_filled[self.key]
except KeyError:
raise
new = copy.deepcopy(old)
new.filled.filled_in += filled_in
new.filled.filled_out += filled_out
new.tranche_filled[tranche_index].filled_in += filled_in
new.tranche_filled[tranche_index].filled_out += filled_out
order_log.debug(f'post-fill order: {new}')
order_log.debug(f'updated order_filled: {new}')
Order.order_filled[self.key] = new
@@ -176,6 +180,7 @@ class Order:
Order.vault_open_orders.listremove(self.key.vault, self.key.order_index)
# set final fill values in the status
of = Order.order_filled[self.key]
order_log.debug(f'deleting order_filled[{self.key}]')
del Order.order_filled[self.key]
status.filledIn = of.filled.filled_in
status.filledOut = of.filled.filled_out
@@ -203,6 +208,7 @@ class Order:
@staticmethod
def pub_order_fills(_s, k, v):
log.debug(f'pub_order_fills {k} {v}')
# publish status updates (on placing and completion) to web clients
if v is DELETE:
return None

View File

@@ -255,7 +255,11 @@ class BlockStateRunner(BlockProgressor):
async def handle_head(self, chain, block, w3):
# todo refactor this to generate a fork from the latest block back to whatever ancestor it can find
log.debug(f'handle_head {block.height} {hexstr(block.hash)}')
if self.state and block.height <= self.state.root_block.height:
log.debug(f'ignoring old head')
return
session = None
batches = []
pubs = []
@@ -324,7 +328,7 @@ class BlockStateRunner(BlockProgressor):
# check for root promotion
confirm_offset = (config.confirms if config.confirms is not None else chain.confirms) - 1
promotion_height = latest_block.get().height - confirm_offset
promotion_height = latest_block.get().height - confirm_offset # todo latest_block should not be a ContextVar but a global dict by chain_id
new_root_fork = None
if fork.disjoint:
fork: DisjointFork

View File

@@ -124,7 +124,7 @@ class BlockWalker (BlockProgressor):
async def handle(self, from_height, to_height, *, chain=None, w3=None):
log.info(f'processing blocks {from_height} - {to_height}')
log.info(f'processing blocks {from_height} through {to_height}')
if chain is None:
chain = current_chain.get()
if w3 is None: