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

feat: implement post-state-root chunk production #9537

Merged
merged 3 commits into from
Oct 3, 2023

Conversation

pugachAG
Copy link
Contributor

@pugachAG pugachAG commented Sep 19, 2023

This PR adds chunk production with post-state-root. This means applying transactions and receipts before producing the chunk and including the necessary fields in the header.

The code is not used anywhere yet, that will be implemented as a separate PR. The issues marked with TODO(post-state-root) will be resolved separately.

Part of #9450.

@pugachAG pugachAG changed the title WIP post-state-root produce block wip: post-state-root produce block Sep 19, 2023
@pugachAG pugachAG force-pushed the post-state-root-produce-block branch 3 times, most recently from 0a7edd0 to 5315641 Compare September 27, 2023 13:55
@pugachAG pugachAG force-pushed the post-state-root-produce-block branch 4 times, most recently from 3d95429 to d15674a Compare September 29, 2023 12:47
@pugachAG pugachAG changed the title wip: post-state-root produce block feat: implement post-state-root chunk production Sep 29, 2023
@pugachAG pugachAG force-pushed the post-state-root-produce-block branch 3 times, most recently from 5f4f692 to 596e025 Compare October 2, 2023 11:03
@pugachAG pugachAG force-pushed the post-state-root-produce-block branch from 596e025 to 8012638 Compare October 2, 2023 11:32
@pugachAG pugachAG marked this pull request as ready for review October 2, 2023 11:32
@pugachAG pugachAG requested a review from a team as a code owner October 2, 2023 11:32
@pugachAG pugachAG requested review from nikurt, Longarithm and robin-near and removed request for nikurt October 2, 2023 11:32
Copy link
Member

@Longarithm Longarithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Leaving several suggestions and questions.

chain/client/src/client.rs Outdated Show resolved Hide resolved
Comment on lines 1002 to 1013
// Receipts proofs root is calculating here
//
// For each subset of incoming_receipts_into_shard_i_from_the_current_one
// we calculate hash here and save it
// and then hash all of them into a single receipts root
//
// We check validity in two ways:
// 1. someone who cares about shard will download all the receipts
// and checks that receipts_root equals to all receipts hashed
// 2. anyone who just asks for one's incoming receipts
// will receive a piece of incoming receipts only
// with merkle receipts proofs which can be checked locally
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this comment belongs to calculate_receipts_root. Could you move it there and remove it from produce_pre_state_root_chunk as well? I'd appreciate if you prettify it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I was too lazy to actually read it, so I just assumed that it corresponds to the piece of code below 😄
I've moved it as a rustdoc to calculate_receipts_root and tried to improve both formating and wording there, please take a look.

Comment on lines 853 to 858
// TODO(post-state-root): this misses outgoing receipts from the last block before
// the switch to post-state-root. Incoming receipts for that block corresponds to the
// outgoing receipts from the previous block, but incoming receipts for the next block
// include outgoing receipts for that block. These receipts can be obtained from the db
// using get_outgoing_receipts_for_shard since we currently track all shard. This will
// be implemented later along with an intergation test to reproduce the issue.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though you explained it to me previously, it was hard to understand this by the comment. I came up with some reformulation which worked better for me - WDYT?

Suggested change
// TODO(post-state-root): this misses outgoing receipts from the last block before
// the switch to post-state-root. Incoming receipts for that block corresponds to the
// outgoing receipts from the previous block, but incoming receipts for the next block
// include outgoing receipts for that block. These receipts can be obtained from the db
// using get_outgoing_receipts_for_shard since we currently track all shard. This will
// be implemented later along with an intergation test to reproduce the issue.
// TODO(post-state-root): this is NOT correct for chunks ONLY for the first block B after
// switching to post-state-root. In general case incoming receipts for post-state-root
// chunks are derived from outgoing receipts for chunks in the previous block. However,
// the previous block for B has only incoming receipts, as required by pre-state-root
// logic.
// To get incoming receipts in this edge case we can call get_outgoing_receipts_for_shard
// which obtains receipts from DB directly. This is enough because currently each node
// tracks all shards.
// This will be implemented later along with an integration test to reproduce the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the suggestion, I've tried to make it more detailed, please let me know if that looks more understandable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had an offline chat. Got ideas to

  • point out that we talk about DBCol::IncomingReceipts population and remind its definition which is ~ receipts TO execute which node received at the block B. So, for pre-state-root, when we receive block B, it gives us outgoing receipts from B-1 ("prev"). For post-state-root, chunk at block B stores outgoing receipts caused by itself, so they go to B as well.
  • reverse direction of arrow :)

@pugachAG pugachAG force-pushed the post-state-root-produce-block branch 5 times, most recently from ec2280f to 34ba52f Compare October 3, 2023 10:05
@pugachAG pugachAG force-pushed the post-state-root-produce-block branch from 34ba52f to 039527d Compare October 3, 2023 11:14
@pugachAG pugachAG added the A-chain Area: Chain, client & related label Oct 3, 2023
@pugachAG pugachAG added this pull request to the merge queue Oct 3, 2023
Merged via the queue into near:master with commit a27075f Oct 3, 2023
@pugachAG pugachAG deleted the post-state-root-produce-block branch October 3, 2023 12:00
nikurt pushed a commit that referenced this pull request Oct 11, 2023
This PR adds chunk production with post-state-root. This means applying
transactions and receipts before producing the chunk and including the
necessary fields in the header.

The code is not used anywhere yet, that will be implemented as a
separate PR. The issues marked with `TODO(post-state-root)` will be
resolved separately.

Part of #9450.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-chain Area: Chain, client & related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants