Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#455 rewrite transaction reciept with finalized data #465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion proxy/indexer/blocks_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def get_block_by_height(self, block_num) -> SolanaBlockDBInfo:
self._fetchone(self._column_lst, [('height', block_num)], ['finalized desc']))

def get_latest_block_height(self) -> int:
return self._fetchone(['height'], [], ['height desc'])[0]
result = self._fetchone(['height'], [], ['height desc'])
if result:
return result[0]
return 0

def set_block(self, block: SolanaBlockDBInfo):
cursor = self._conn.cursor()
Expand Down
3 changes: 2 additions & 1 deletion proxy/indexer/indexer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ 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__))
Expand All @@ -59,7 +60,7 @@ 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 = block.finalized if block.finalized else ("confirmed" == FINALIZED)
self.debug(f'{block}')
self._blocks_db.set_block(block)
return block
Expand Down
15 changes: 9 additions & 6 deletions proxy/indexer/transactions_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _create_table_sql(self) -> str:
calldata TEXT,
logs BYTEA,

UNIQUE(neon_sign, finalized),
UNIQUE(neon_sign),
UNIQUE(sol_sign, idx)
);
CREATE INDEX IF NOT EXISTS {self._table_name}_finalized ON {self._table_name}(slot, finalized);
Expand Down Expand Up @@ -136,11 +136,14 @@ def set_tx(self, tx: NeonTxDBInfo):

cursor = self._conn.cursor()
cursor.execute(f'''
INSERT INTO {self._table_name}
({', '.join(self._column_lst)})
VALUES
({', '.join(['%s' for _ in range(len(self._column_lst))])})
ON CONFLICT DO NOTHING
INSERT INTO {self._table_name}
({', '.join(self._column_lst)})
VALUES
({', '.join(['%s' for _ in range(len(self._column_lst))])})
ON CONFLICT (neon_sign)
DO UPDATE SET
{', '.join([col+'=EXCLUDED.'+col for col in self._column_lst])}
WHERE {self._table_name}.finalized=False AND EXCLUDED.finalized=True;
''',
row)

Expand Down
4 changes: 2 additions & 2 deletions proxy/run-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$CONFIG" == "ci" ]; then
[[ -z "$CANCEL_TIMEOUT" ]] && export CANCEL_TIMEOUT=10
[[ -z "$RETRY_ON_BLOCKED" ]] && export RETRY_ON_BLOCKED=32
[[ -z "$RETRY_ON_FAIL" ]] && export RETRY_ON_FAIL=10
[[ -z "$FINALIZED" ]] && export FINALIZED="confirmed"
[[ -z "$FINALIZED" ]] && export FINALIZED="finalized"
elif [ "$CONFIG" == "local" ]; then
[[ -z "$SOLANA_URL" ]] && export SOLANA_URL="http://localhost:8899"
[[ -z "$EXTRA_GAS" ]] && export EXTRA_GAS=0
Expand All @@ -24,7 +24,7 @@ elif [ "$CONFIG" == "local" ]; then
[[ -z "$CANCEL_TIMEOUT" ]] && export CANCEL_TIMEOUT=10
[[ -z "$RETRY_ON_BLOCKED" ]] && export RETRY_ON_BLOCKED=32
[[ -z "$RETRY_ON_FAIL" ]] && export RETRY_ON_FAIL=10
[[ -z "$FINALIZED" ]] && export FINALIZED="confirmed"
[[ -z "$FINALIZED" ]] && export FINALIZED="finalized"
elif [ "$CONFIG" == "devnet" ]; then
[[ -z "$SOLANA_URL" ]] && export SOLANA_URL="https://api.devnet.solana.com"
[[ -z "$EVM_LOADER" ]] && export EVM_LOADER=eeLSJgWzzxrqKv1UxtRVVH8FX3qCQWUs9QuAjJpETGU
Expand Down