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
#455 set commitment of requested blocks
  • Loading branch information
otselnik committed Jan 20, 2022
commit 9e3e1e479cd892b76aa5c8562438c1bead7486de
1 change: 1 addition & 0 deletions proxy/indexer/blocks_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def set_block(self, block: SolanaBlockDBInfo):
parent_hash=EXCLUDED.parent_hash,
blocktime=EXCLUDED.blocktime,
signatures=EXCLUDED.signatures
WHERE {self._table_name}.finalized=False AND EXCLUDED.finalized=True;
''',
(block.slot, block.finalized, block.height, block.hash,
block.parent_hash, block.time, self.encode_list(block.signs)))
Expand Down
2 changes: 1 addition & 1 deletion proxy/indexer/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def complete_done_txs(self):
for tx in self._done_tx_list:
self.unmark_ix_used(tx)
if tx.neon_tx.is_valid() and tx.neon_res.is_valid():
self._db.submit_transaction(tx.neon_tx, tx.neon_res, tx.used_ixs)
self._db.submit_transaction(tx.neon_tx, tx.neon_res, tx.used_ixs, commitment=FINALIZED)
self.del_tx(tx)
self._done_tx_list.clear()

Expand Down
27 changes: 14 additions & 13 deletions proxy/indexer/indexer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def __init__(self, client):
if k not in self._constants:
self._constants[k] = 0

def submit_transaction(self, neon_tx: NeonTxInfo, neon_res: NeonTxResultInfo, used_ixs: [SolanaIxSignInfo]):
def submit_transaction(self, neon_tx: NeonTxInfo, neon_res: NeonTxResultInfo, used_ixs: [SolanaIxSignInfo], commitment):
try:
block = self.get_block_by_slot(neon_res.slot)
block = self.get_block_by_slot(neon_res.slot, commitment)
if block.hash is None:
self.critical(f'Unable to submit transaction {neon_tx.sign} because slot {neon_res.slot} not found')
return
Expand All @@ -41,14 +41,15 @@ def submit_transaction(self, neon_tx: NeonTxInfo, neon_res: NeonTxResultInfo, us
rec['blockNumber'] = hex(block.height)
self._logs_db.push_logs(neon_res.logs, block)
tx = NeonTxDBInfo(neon_tx=neon_tx, neon_res=neon_res, block=block, used_ixs=used_ixs)
self.debug(f'submit_transaction NeonTxDBInfo {tx}')
self._txs_db.set_tx(tx)
except Exception as err:
err_tb = "".join(traceback.format_tb(err.__traceback__))
self.warning('Exception on submitting transaction. ' +
f'Type(err): {type(err)}, Error: {err}, Traceback: {err_tb}')

def _fill_block_from_net(self, block: SolanaBlockDBInfo):
opts = {"commitment": "confirmed", "transactionDetails": "signatures", "rewards": False}
def _fill_block_from_net(self, block: SolanaBlockDBInfo, commitment):
opts = {"commitment": commitment, "transactionDetails": "signatures", "rewards": False}
net_block = self._client._provider.make_request("getBlock", block.slot, opts)
if (not net_block) or ('result' not in net_block):
return block
Expand All @@ -59,21 +60,21 @@ def _fill_block_from_net(self, block: SolanaBlockDBInfo):
block.signs = net_block['signatures']
block.parent_hash = '0x' + base58.b58decode(net_block['previousBlockhash']).hex()
block.time = net_block['blockTime']
block.finalized = ("confirmed" == FINALIZED)
block.finalized = (commitment == FINALIZED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error in this place.
The block can be loaded from DB with the finalized status, but here it is overwritten.

Here should be:
block.finalized = block.finalized or ('confirmed' == FINALIZED)

In this case:

  • Indexer saves blocks and txs with finalized status
  • Sender saves blocks and txs with confirmed status

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

self.debug(f'{block}')
self._blocks_db.set_block(block)
return block

def get_block_by_slot(self, slot) -> SolanaBlockDBInfo:
def get_block_by_slot(self, slot, commitment) -> SolanaBlockDBInfo:
block = self._blocks_db.get_block_by_slot(slot)
if not block.hash:
self._fill_block_from_net(block)
self._fill_block_from_net(block, commitment)
return block

def get_full_block_by_slot(self, slot) -> SolanaBlockDBInfo:
def get_full_block_by_slot(self, slot, commitment) -> SolanaBlockDBInfo:
block = self._blocks_db.get_full_block_by_slot(slot)
if not block.parent_hash:
self._fill_block_from_net(block)
self._fill_block_from_net(block, commitment)
return block

def get_last_block_slot(self):
Expand Down Expand Up @@ -107,16 +108,16 @@ def get_block_by_hash(self, block_hash):
def get_block_by_height(self, block_height):
return self._blocks_db.get_block_by_height(block_height)

def get_tx_by_sol_sign(self, sol_sign):
def get_tx_by_sol_sign(self, sol_sign, commitment):
tx = self._txs_db.get_tx_by_sol_sign(sol_sign)
if tx:
tx.block = self.get_block_by_slot(tx.neon_res.slot)
tx.block = self.get_block_by_slot(tx.neon_res.slot, commitment)
return tx

def get_tx_by_neon_sign(self, neon_sign) -> NeonTxDBInfo:
def get_tx_by_neon_sign(self, neon_sign, commitment) -> NeonTxDBInfo:
tx = self._txs_db.get_tx_by_neon_sign(neon_sign)
if tx:
tx.block = self.get_block_by_slot(tx.neon_res.slot)
tx.block = self.get_block_by_slot(tx.neon_res.slot, commitment)
return tx

def del_not_finalized(self, from_slot: int, to_slot: int):
Expand Down
8 changes: 4 additions & 4 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ def eth_getLogs(self, obj):
return self.db.get_logs(fromBlock, toBlock, address, topics, blockHash)

def getBlockBySlot(self, slot, full):
block = self.db.get_full_block_by_slot(slot)
block = self.db.get_full_block_by_slot(slot, commitment='confirmed')
if block.slot is None:
return None

transactions = []
gasUsed = 0
trx_index = 0
for signature in block.signs:
tx = self.db.get_tx_by_sol_sign(signature)
tx = self.db.get_tx_by_sol_sign(signature, commitment='confirmed')
if not tx:
continue

Expand Down Expand Up @@ -308,7 +308,7 @@ def eth_getTransactionReceipt(self, trxId):
self.debug('eth_getTransactionReceipt: %s', trxId)

neon_sign = trxId.lower()
tx = self.db.get_tx_by_neon_sign(neon_sign)
tx = self.db.get_tx_by_neon_sign(neon_sign, commitment='confirmed')
if not tx:
self.debug("Not found receipt")
return None
Expand Down Expand Up @@ -388,7 +388,7 @@ def eth_sendRawTransaction(self, rawTrx):
self.debug('Transaction signature: %s %s', signature, eth_signature)
neon_tx = NeonTxInfo()
neon_tx.init_from_eth_tx(trx)
self.db.submit_transaction(neon_tx, neon_res, [])
self.db.submit_transaction(neon_tx, neon_res, [], commitment='confirmed')
return eth_signature

except SolanaTrxError as err:
Expand Down