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 fix commitment
  • Loading branch information
otselnik committed Jan 21, 2022
commit 532d37c19f169a90387faf8d82874dc06d22c8c6
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, commitment=FINALIZED)
self._db.submit_transaction(tx.neon_tx, tx.neon_res, tx.used_ixs)
self.del_tx(tx)
self._done_tx_list.clear()

Expand Down
26 changes: 13 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], commitment):
def submit_transaction(self, neon_tx: NeonTxInfo, neon_res: NeonTxResultInfo, used_ixs: [SolanaIxSignInfo]):
try:
block = self.get_block_by_slot(neon_res.slot, commitment)
block = self.get_block_by_slot(neon_res.slot)
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 @@ -48,8 +48,8 @@ def submit_transaction(self, neon_tx: NeonTxInfo, neon_res: NeonTxResultInfo, us
self.warning('Exception on submitting transaction. ' +
f'Type(err): {type(err)}, Error: {err}, Traceback: {err_tb}')

def _fill_block_from_net(self, block: SolanaBlockDBInfo, commitment):
opts = {"commitment": commitment, "transactionDetails": "signatures", "rewards": False}
def _fill_block_from_net(self, block: SolanaBlockDBInfo):
opts = {"commitment": "confirmed", "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 @@ -60,21 +60,21 @@ def _fill_block_from_net(self, block: SolanaBlockDBInfo, commitment):
block.signs = net_block['signatures']
block.parent_hash = '0x' + base58.b58decode(net_block['previousBlockhash']).hex()
block.time = net_block['blockTime']
block.finalized = (commitment == FINALIZED)
block.finalized = block.finalized if block.finalized else ("confirmed" == FINALIZED)
self.debug(f'{block}')
self._blocks_db.set_block(block)
return block

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

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

def get_last_block_slot(self):
Expand Down Expand Up @@ -108,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, commitment):
def get_tx_by_sol_sign(self, sol_sign):
tx = self._txs_db.get_tx_by_sol_sign(sol_sign)
if tx:
tx.block = self.get_block_by_slot(tx.neon_res.slot, commitment)
tx.block = self.get_block_by_slot(tx.neon_res.slot)
return tx

def get_tx_by_neon_sign(self, neon_sign, commitment) -> NeonTxDBInfo:
def get_tx_by_neon_sign(self, neon_sign) -> 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, commitment)
tx.block = self.get_block_by_slot(tx.neon_res.slot)
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, commitment='confirmed')
block = self.db.get_full_block_by_slot(slot)
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, commitment='confirmed')
tx = self.db.get_tx_by_sol_sign(signature)
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, commitment='confirmed')
tx = self.db.get_tx_by_neon_sign(neon_sign)
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, [], commitment='confirmed')
self.db.submit_transaction(neon_tx, neon_res, [])
return eth_signature

except SolanaTrxError as err:
Expand Down