near / near-indexer-for-explorer

Watch NEAR network and store all the data from NEAR blockchain to PostgreSQL database
https://near-indexers.io/docs/projects/near-indexer-for-explorer
GNU General Public License v3.0
123 stars 56 forks source link

Error recovering account from passphrase in Kurtosis #323

Closed gbouv closed 1 year ago

gbouv commented 1 year ago

There's an issue when trying to recover an account from a passphrase for a NEAR network running in Kurtosis.

After investigating with Andy on the near contract helper, it seems the root cause is from the indexer.

In particular, when I create a new account, I see those errors in the logs:

2022-12-01 10:04:41 Dec 01 09:04:41.380 ERROR indexer_for_explorer: Error occurred during DatabaseError(ForeignKeyViolation, "insert or update on table \"receipts\" violates foreign key constraint \"tx_receipt_fk\""): 2022-12-01 10:04:41 "Receipts were stored in database" 2022-12-01 10:04:41 [ 2022-12-01 10:04:41 Receipt

{ 2022-12-01 10:04:41 receipt_id: "9dk6TZzwvGDTJcfDvHBDDnTLYkE5HYRW8uED3Ky2812T", 2022-12-01 10:04:41 included_in_block_hash: "AHp4AkwV4Ypw6D57114U8U7mor2ASgt6qrhzbHXUyPQi", 2022-12-01 10:04:41 included_in_chunk_hash: "AQz8tjtxpTtccfniqvhHE7fok3SJtg3N9yUR132EEoAx", 2022-12-01 10:04:41 index_in_chunk: 0, 2022-12-01 10:04:41 included_in_block_timestamp: BigDecimal("1669885479850235921"), 2022-12-01 10:04:41 predecessor_account_id: "guillaume.test.near", 2022-12-01 10:04:41 receiver_account_id: "guillaume.test.near", 2022-12-01 10:04:41 receipt_kind: Action, 2022-12-01 10:04:41 originated_from_transaction_hash: "6SSCzES4U2o4yAov78DmfhiCZ6tjYB7yye6umLpPjDb8", 2022-12-01 10:04:41 }

, 2022-12-01 10:04:41 ] 2022-12-01 10:04:41 Retrying in 100 milliseconds... Then I tried creating a different account again:

2022-12-01 10:06:19 Dec 01 09:06:19.333 ERROR indexer_for_explorer: Error occurred during DatabaseError(ForeignKeyViolation, "insert or update on table \"account_changes\" violates foreign key constraint \"account_id_fk\""): 2022-12-01 10:06:19 "AccountChanges were stored in database" 2022-12-01 10:06:19 [ 2022-12-01 10:06:19 AccountChange

{ 2022-12-01 10:06:19 affected_account_id: "guillaume2.test.near", 2022-12-01 10:06:19 changed_in_block_timestamp: BigDecimal("1669885577790718174"), 2022-12-01 10:06:19 changed_in_block_hash: "BNetnquT3hHkMa9YWRgsNmjdD6FMheAR6dbda2FhGo6e", 2022-12-01 10:06:19 caused_by_transaction_hash: None, 2022-12-01 10:06:19 caused_by_receipt_id: Some( 2022-12-01 10:06:19 "D2owzubEEmCgFki3pRm5cqS5Uq5fGjxHYjFpF2Yt1aw7", 2022-12-01 10:06:19 ), 2022-12-01 10:06:19 update_reason: ReceiptProcessing, 2022-12-01 10:06:19 affected_account_nonstaked_balance: BigDecimal("10000000000000000000000000"), 2022-12-01 10:06:19 affected_account_staked_balance: BigDecimal("0"), 2022-12-01 10:06:19 affected_account_storage_usage: BigDecimal("182"), 2022-12-01 10:06:19 index_in_block: 0, 2022-12-01 10:06:19 }

, 2022-12-01 10:06:19 ] 2022-12-01 10:06:19 Retrying in 100 milliseconds...

... SOME UNRELATED INFO LOGS ...

2022-12-01 10:06:21 Dec 01 09:06:21.855 ERROR indexer_for_explorer: Error occurred during DatabaseError(ForeignKeyViolation, "insert or update on table \"receipts\" violates foreign key constraint \"tx_receipt_fk\""): 2022-12-01 10:06:21 "Receipts were stored in database" 2022-12-01 10:06:21 [ 2022-12-01 10:06:21 Receipt

{ 2022-12-01 10:06:21 receipt_id: "BpawQ5uVJghJRVcmMCKhpUqfY4LAgKmkRhRFNEwuMDAs", 2022-12-01 10:06:21 included_in_block_hash: "HbKQbHFuYwoPxaZaWQM33ZUbL4Nty9s2tcp2YDEnT4JC", 2022-12-01 10:06:21 included_in_chunk_hash: "5CchyY7iyYhC6nCPmfBW88dZ9HPe8miV9yU87jJKgMi7", 2022-12-01 10:06:21 index_in_chunk: 0, 2022-12-01 10:06:21 included_in_block_timestamp: BigDecimal("1669885580256394884"), 2022-12-01 10:06:21 predecessor_account_id: "guillaume2.test.near", 2022-12-01 10:06:21 receiver_account_id: "guillaume2.test.near", 2022-12-01 10:06:21 receipt_kind: Action, 2022-12-01 10:06:21 originated_from_transaction_hash: "Gx5xyG82NPoL72Kjj4gqr7282MuB6EkVxNnyHY8gGr4p", 2022-12-01 10:06:21 }

, 2022-12-01 10:06:21 ] 2022-12-01 10:06:21 Retrying in 100 milliseconds...

Do you have an idea of where this might be coming from?

telezhnaya commented 1 year ago

Hey @gbouv! Could you please provide some more information? Is it the localnet? How do you create the new account?

recover an account from a passphrase

I also don't understand what do you mean by recovering the account

gbouv commented 1 year ago

Hey @telezhnaya ! Oh sorry I meant to add the link to the upstream issue but I forgot. Do you mind taking a quick look at https://github.com/near/near-contract-helper/issues/657? It contains all the details you mention above.

telezhnaya commented 1 year ago

As far as I see now, I don't think the issue is on the indexer side. We just see the inconsistency and highlight it, but the real problem was somewhere earlier.

I suggest you to re-run the same process and check each step carefully. It looks like you create the transaction that is broken somehow, it's not appeared in the DB, and after it produces the receipt which we can't save to the DB because we can't find the corresponding parent transaction. (insert or update on table \"receipts\" violates foreign key constraint \"tx_receipt_fk\")

So, at first, we need to find out what's wrong with the transaction. It's not fully broken, because we create receipt from it. My only guess here is that transaction hash is duplicated. Unfortunately, we've seen such problem before (I haven't find nearcore issue, but I've found this thread https://github.com/near/near-indexer-for-explorer/issues/84) That explains why this transaction is not collected to the DB. Can you check existing hashes in your network and check whether the new transaction (potentially the broken one) uses duplicated tx hash? If so, this is the bug for nearcore https://github.com/near/nearcore/issues