Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Store min parsed slot for receipts
  • Loading branch information
afalaleev committed Jan 11, 2022
commit da46dee945b53134cf92ae8c855043cfa356918c
22 changes: 21 additions & 1 deletion proxy/indexer/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,34 @@ def __init__(self, db: IndexerDB, client):
self._tx_table = {}
self._done_tx_list = []
self._used_ixs = set()
self._used_slots = {}
self.ix = NeonIxInfo(sign=bytes(), slot=-1, tx=None)

def set_ix(self, ix_info: NeonIxInfo):
self.ix = ix_info

def mark_ix_used(self):
if self.ix.sign in self._used_ixs:
return
if self.ix.sign.slot not in self._used_slots:
self._used_slots[self.ix.sign.slot] = 1
else:
self._used_slots[self.ix.sign.slot] += 1
self._used_ixs.add(self.ix.sign.copy())

def unmark_ix_used(self, obj: BaseEvmObject):
for ix in obj.used_ixs:
if ix.slot in self._used_slots:
self._used_slots[ix.slot] -= 1
if self._used_slots[ix.slot] == 0:
del self._used_slots[ix.slot]
self._used_ixs.difference_update(obj.used_ixs)

def find_min_used_slot(self, min_slot):
if len(self._used_slots) > 0:
min_slot = min(self._used_slots.keys())
return min_slot

def get_holder(self, account: str) -> Optional[NeonHolderObject]:
return self._holder_table.get(account)

Expand Down Expand Up @@ -644,7 +661,8 @@ def __init__(self,
self.db = IndexerDB()
self.canceller = Canceller()
self.blocked_storages = {}
self.processed_slot = 0
self.processed_slot = self.db.get_min_receipt_slot()
logger.debug(f'Minimum receipt slot: {self.processed_slot}')

def process_functions(self):
IndexerBase.process_functions(self)
Expand Down Expand Up @@ -705,6 +723,8 @@ def process_receipts(self):

self.processed_slot = max(self.processed_slot, max_slot + 1)

self.db.set_min_receipt_slot(state.find_min_used_slot(self.processed_slot))

process_receipts_ms = (time.time() - start_time) * 1000 # convert this into milliseconds
logger.debug(f"process_receipts_ms: {process_receipts_ms} transaction_receipts.len: {self.transaction_receipts.size()} from {self.processed_slot} to {self.current_slot} slots")

Expand Down
15 changes: 10 additions & 5 deletions proxy/indexer/indexer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def __init__(self):
self.eth_sol_trx = SQLDict(tablename="ethereum_solana_transactions")
self.sol_eth_trx = SQLDict(tablename="solana_ethereum_transactions")
self.constants = SQLDict(tablename="constants")
if 'last_block_slot' not in self.constants:
self.constants['last_block_slot'] = 0
self.constants['last_block_height'] = 0

for k in ['last_block_slot', 'last_block_height', 'min_receipt_slot']:
if k not in self.constants:
self.constants[k] = 0

def submit_transaction(self, client, neon_tx, neon_res, used_ixs):
try:
Expand Down Expand Up @@ -70,7 +69,7 @@ def get_block_info(self, client, slot):
block = self.blocks.get(slot, None)
if block is None:
block = client._provider.make_request("getBlock", slot, {"commitment":"confirmed", "transactionDetails":"signatures", "rewards":False})
if block is None:
if (not block) or ('result' not in block):
return None
block = block['result']
block_hash = '0x' + base58.b58decode(block['blockhash']).hex()
Expand Down Expand Up @@ -98,6 +97,12 @@ def fill_block_height(self, height, slots):
self.blocks_height_slot[height] = slot
height += 1

def get_min_receipt_slot(self):
return self.constants['min_receipt_slot']

def set_min_receipt_slot(self, slot):
self.constants['min_receipt_slot'] = slot

def get_logs(self, fromBlock, toBlock, address, topics, blockHash):
return self.logs_db.get_logs(fromBlock, toBlock, address, topics, blockHash)

Expand Down