diff --git a/proxy/indexer/blocks_db.py b/proxy/indexer/blocks_db.py index e12f1d678..9d554b656 100644 --- a/proxy/indexer/blocks_db.py +++ b/proxy/indexer/blocks_db.py @@ -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() diff --git a/proxy/indexer/indexer_db.py b/proxy/indexer/indexer_db.py index e83ec35e2..cdfd8b1ea 100644 --- a/proxy/indexer/indexer_db.py +++ b/proxy/indexer/indexer_db.py @@ -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__)) @@ -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 diff --git a/proxy/indexer/transactions_db.py b/proxy/indexer/transactions_db.py index 96294c597..479db09c6 100644 --- a/proxy/indexer/transactions_db.py +++ b/proxy/indexer/transactions_db.py @@ -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); @@ -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) diff --git a/proxy/run-proxy.sh b/proxy/run-proxy.sh index 2483136db..1bc0fe6e7 100755 --- a/proxy/run-proxy.sh +++ b/proxy/run-proxy.sh @@ -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 @@ -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