Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

ProofRecorder: Implement transactional support #13769

Merged
merged 13 commits into from
Apr 5, 2023

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Mar 30, 2023

This implements transactional support for ProofRecorder. A transaction can be started with start_transaction and then later commited or rolled back. This is important for block producers to not include data from transactions that didn't make it to the block, because they e.g. panicked or similar.

Closes: #10222

@bkchr bkchr added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T0-node This PR/Issue is related to the topic “node”. labels Mar 30, 2023
@bkchr bkchr requested a review from a team March 30, 2023 14:19
Copy link
Contributor

@dmitry-markin dmitry-markin left a comment

Choose a reason for hiding this comment

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

I'm not familiar with this part of the codebase enough to approve, but left some comments.

primitives/trie/src/recorder.rs Outdated Show resolved Hide resolved
primitives/trie/src/recorder.rs Outdated Show resolved Hide resolved
@dmitry-markin dmitry-markin requested a review from a team March 31, 2023 08:10
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
primitives/trie/src/recorder.rs Outdated Show resolved Hide resolved

/// Rollback the latest transaction.
///
/// If there isn't any transaction, nothing gonna happen.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a log error message would be reasonable? Otherwise we can silently skip API misuses.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought of returning an error as well as we do it in OverlayedChanges. However, I'm not really sure that there is any benefit in it? Even if some calls all the time rollback, nothing breaks? No assumption is broken or similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about getting some information if higher level are not calling start and rollback/commit in pairs (e.g. due to some error in logic). W/o error message this case will be silently skipped (maybe making future debugging more tricky).

If this is a conscious design decision that rollback/commit can be called w/o matching start than it is also OK.

Logging error could be some compromise between silently ignoring this case and returning the error.

But maybe my reasoning is too defensive here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

pub fn start_transaction(&self) {
let mut inner = self.inner.lock();
inner.accessed_nodes_transactions.push(Default::default());
inner.recorded_keys_transactions.push(Default::default());
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an assumption that lenght of *_transactions are equal. How about adding assertion here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean both walk in lockstep, but there is no assumption that both have the same length? We never access anything from one to the other assuming that the same index exists there as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant silent assumption - at the end both vecs should have the length of number of transactions, it should never happen that one contains more then other. Assert would be more expressive way to indicate this bound. It would also help if some modifies the code (e.g. return early from rollback/commit_transaction).

Anyway, feel free to ignore it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@michalkucharczyk michalkucharczyk requested a review from a team March 31, 2023 15:48

next_key = next;
} else {
if panic_at_end {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this condition?
When execute ReadAndPanic(10) we expect to do 10 reads and then panic right? If we are only able to do 5 reads it looks from the outside as if everything is ok, but something unexpected happened.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we need this.

The docs explicitly mention this:

/// Read X times from the state some data and then panic!
///
/// Returns `Ok` if it didn't read anything.

The point is that you expect it to fail and if it doesn't fail, you know that something didn't work as expected.

primitives/trie/src/recorder.rs Show resolved Hide resolved
primitives/trie/src/recorder.rs Show resolved Hide resolved
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
@bkchr
Copy link
Member Author

bkchr commented Apr 3, 2023

bot fmt

@command-bot
Copy link

command-bot bot commented Apr 3, 2023

@bkchr https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2636246 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 46-2d311f98-9a7d-4a2c-aac2-43d00e1ad909 to cancel this command or bot cancel to cancel all commands in this pull request.

@bkchr bkchr requested a review from skunert April 3, 2023 20:27
@command-bot
Copy link

command-bot bot commented Apr 3, 2023

@bkchr Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2636246 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2636246/artifacts/download.

@bkchr
Copy link
Member Author

bkchr commented Apr 3, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

@bkchr
Copy link
Member Author

bkchr commented Apr 3, 2023

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot
Copy link

Merge cancelled due to error. Error: Statuses failed for f7e8b48

primitives/trie/src/recorder.rs Show resolved Hide resolved
primitives/trie/src/recorder.rs Outdated Show resolved Hide resolved
bkchr and others added 2 commits April 5, 2023 16:07
Co-authored-by: Anton <anton.kalyaev@gmail.com>
@bkchr
Copy link
Member Author

bkchr commented Apr 5, 2023

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 5601965 into master Apr 5, 2023
@paritytech-processbot paritytech-processbot bot deleted the bkchr-trie-recorder-transactions branch April 5, 2023 14:43
librelois pushed a commit to moonbeam-foundation/substrate that referenced this pull request Apr 19, 2023
* TrieRecorder: Start adding support for transactions

* Adds `transactions` functions and some test

* More tests

* Docs

* Ensure that we rollback failed transactions in the storage proof

* FMT

* Update primitives/trie/src/recorder.rs

Co-authored-by: Dmitry Markin <dmitry@markin.tech>

* Review comments

* Update primitives/trie/src/recorder.rs

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* For the holy clippy!

* Update primitives/trie/src/recorder.rs

Co-authored-by: Anton <anton.kalyaev@gmail.com>

---------

Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Anton <anton.kalyaev@gmail.com>
gpestana pushed a commit that referenced this pull request Apr 23, 2023
* TrieRecorder: Start adding support for transactions

* Adds `transactions` functions and some test

* More tests

* Docs

* Ensure that we rollback failed transactions in the storage proof

* FMT

* Update primitives/trie/src/recorder.rs

Co-authored-by: Dmitry Markin <dmitry@markin.tech>

* Review comments

* Update primitives/trie/src/recorder.rs

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* For the holy clippy!

* Update primitives/trie/src/recorder.rs

Co-authored-by: Anton <anton.kalyaev@gmail.com>

---------

Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Anton <anton.kalyaev@gmail.com>
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/april-updates-for-substrate-and-polkadot-devs/2764/1

nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* TrieRecorder: Start adding support for transactions

* Adds `transactions` functions and some test

* More tests

* Docs

* Ensure that we rollback failed transactions in the storage proof

* FMT

* Update primitives/trie/src/recorder.rs

Co-authored-by: Dmitry Markin <dmitry@markin.tech>

* Review comments

* Update primitives/trie/src/recorder.rs

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* For the holy clippy!

* Update primitives/trie/src/recorder.rs

Co-authored-by: Anton <anton.kalyaev@gmail.com>

---------

Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Anton <anton.kalyaev@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProofRecorder should support commited/uncommitted state
6 participants