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

State-provisioning must flush parentchain import queue and set last imported parentchain header #1366

Closed
clangenb opened this issue Jun 15, 2023 · 3 comments

Comments

@clangenb
Copy link
Contributor

clangenb commented Jun 15, 2023

I have yet to conclude my analysis, but I think I found the cause of the failing integration tests in #1337.

As noted in #1337 (comment), w2 imports some missing parentchain blocks before importing the sidechain block. However, the imported blocks are [0...=n], where n is the layer_one_head denoted in the to be imported sidechain block.

This means, we import blocks that are already included in the provisioned sidechain state, and re-apply them. My current guess is that by chance this did not lead to state transitions pre polkadot-0.9.42 such that we did not note that bug before.

Logs observed on #1337 with the following log-levels:

'itp_stf_state_handler=debug,'
'its_consensus_common=debug,'
'its_consensus_aura=trace,'
'itc_parentchain_block_importer=debug,'
[Attempting to import sidechain block (number: 36, hash: 0xaf8bb6dbed80fd8cef2471b0e8d263c567b1285be4591097137c9a2944d98501, parentchain hash: 0x56fc141a2895a1cc2c738193cc13714dfe8ee5913b03ed889cdc0134df72b3ef)
[2023-06-15T14:32:14Z [DEBUG its_consensus_aura::block_importer] Peeking parentchain header
[2023-06-15T14:32:14Z [DEBUG its_consensus_aura::block_importer] sidechain block parentchain head: 0x56fc…b3ef
[2023-06-15T14:32:14Z [DEBUG its_consensus_aura::block_importer] last imported head: 0xc0f2…4314, number: 0, parenthash: 0x0000…0000
[2023-06-15T14:32:14Z [WARN  its_consensus_common::peer_block_sync] Got ancestry mismatch error upon block import. Attempting to fetch missing blocks from peer
[2023-06-15T14:32:14Z [INFO  its_consensus_common::peer_block_sync] Initiating fetch blocks from peer, last imported block hash: 0xb529cac5cec61d2e5281457c5ebd2edc350f03d1bd0914016a89e9454474f4db, until block hash: 0xaf8bb6dbed80fd8cef2471b0e8d263c567b1285be4591097137c9a2944d98501
[2023-06-15T14:32:14Z [INFO  its_consensus_common::peer_block_sync] Fetched 20 blocks from peer to import
[2023-06-15T14:32:14Z [DEBUG its_consensus_common::block_import] Attempting to import sidechain block (number: 16, hash: 0x95f38e6d6f1ff7d3a237562721828df06bced3e3ec8d14ad3db6ab2824814059, parentchain hash: 0x598897bfe33c9fdf5d9d3e9386121f7ec6476b7b6f3374b51469a1c3485a6c86)
[2023-06-15T14:32:14Z [DEBUG its_consensus_aura::block_importer] Peeking parentchain header
[2023-06-15T14:32:14Z [DEBUG its_consensus_aura::block_importer] sidechain block parentchain head: 0x5988…6c86
[2023-06-15T14:32:14Z [DEBUG its_consensus_aura::block_importer] last imported head: 0xc0f2…4314, number: 0, parenthash: 0x0000…0000
[2023-06-15T14:32:14Z [DEBUG itc_parentchain_block_importer::block_importer]Import blocks to light-client!
[2023-06-15T14:32:14Z [DEBUG itp_stf_state_handler::state_handler] Writing state
[2023-06-15T14:32:14Z [INFO  itc_parentchain_block_importer::block_importer] Successfully imported parentchain block (number: 1, hash: 0xfa79…7982)
[2023-06-15T14:32:14Z [DEBUG itp_stf_state_handler::state_handler] Writing state
[2023-06-15T14:32:14Z [INFO  itc_parentchain_block_importer::block_importer] Successfully imported parentchain block (number: 2, hash: 0xbe75…c85e)
[2023-06-15T14:32:14Z [DEBUG itp_stf_state_handler::state_handler] Writing state
[2023-06-15T14:32:14Z [INFO  itc_parentchain_block_importer::block_importer] Successfully imported parentchain block (number: 3, hash: 0x5776…8966)
[2023-06-15T14:32:14Z [DEBUG itp_stf_state_handler::state_handler] Writing state
[2023-06-15T14:32:14Z [INFO  itc_parentchain_block_importer::block_importer] Successfully imported parentchain block (number: 4, hash: 0x5988…6c86)
[2023-06-15T14:32:14Z [INFO  its_consensus_common::block_import] Applying state diff for block 16 of size 219 bytes
[2023-06-15T14:32:14Z [ERROR its_consensus_common::peer_block_sync] Failed to import sidechain block that was fetched from peer: Other(InvalidAprioriHash)
[2023-06-15T14:32:14Z enclave_runtime::error] Returning error Consensus(Other(InvalidAprioriHash)) as sgx unexpected.
@clangenb clangenb mentioned this issue Jun 15, 2023
3 tasks
@clangenb
Copy link
Contributor Author

clangenb commented Jun 15, 2023

To be precise, I see two potential causes for the bug #1337:

  1. The parentchain block imports did not lead to any additional state transition pre-polkadot-0.9.42, hence these unwanted imports were noops, which did not change our apriori hash.
  2. 0.9.42 bricked some mechanism that already implemented what I suggest here, but I don't see yet where this mechanism could be in our codebase.

TBH, to me both seem unlikely, but I deem the first one more plausible.

@clangenb
Copy link
Contributor Author

clangenb commented Jun 16, 2023

To be precise, I see two potential causes for the bug #1337:

1. The parentchain block imports did not lead to any additional state transition pre-polkadot-0.9.42, hence these unwanted imports were noops, which did not change our apriori hash.

2. 0.9.42 bricked some mechanism that already implemented what I suggest here, but I don't see yet where this mechanism could be in our codebase.

TBH, to me both seem unlikely, but I deem the first one more plausible.

It is definitely 1.

@clangenb
Copy link
Contributor Author

The parentchain import queue is not populated at that step, as the parentchain light-client is not even initialized. Hence, the solution will be to provision the current light-client state together with the state-key and the state. Therefore this is superseded by #1370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant