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/miner structured logging #2975

Merged
merged 7 commits into from
Jan 10, 2022
Merged

Conversation

pavitthrap
Copy link
Contributor

Description

Re-implements #2821: This PR adds the type TransactionResult, which is used to track outcomes of transaction inclusion by miners in both blocks and microblocks.
There are three result types for a transactions:

  • Success - the tx is included in the (micro)block being mined
  • Skipped - the tx is skipped over (this could be due to space constraints, or the tx might be invalid)
  • ProcessingError - the miner attempt to process the tx for inclusion in the block, but there was an error

Moreover, this PR updates the mined_blocks event and adds the mined_microblocks event. Each of these events has a field tx_events, which is a list of TransactionEvents (which are constructed from TransactionResults; they contain a subset of that data)

Areas for Feedback

  • The event dispatcher uses the set miner_observers_lookup to determine which observers to send mined_blocks events too. Instead of using this set, I created another set, mined_microblocks_observers_lookup for the new mined_microblocks event. I could:
    • remove mined_microblocks_observers_lookup and just use miner_observers_lookup for both mined_blocks and mined_microblocks events
    • update the name of miner_observers_lookup to be mined_blocks_observers_lookup
    • have three categories, miner_observers_lookup, mined_blocks_observers_lookup and mined_microblocks_observers_lookup. The first group miner_observers_lookup would subscribe to both the mined_blocks and mined_microblocks events
  • Can use feedback on the payload for the following types (do we want any more data transmitted for the tx event?):
    • TransactionSuccessEvent
    • MinedMicroblockEvent

Testing

Added mining_events_integration_test to neon_integrations

@codecov
Copy link

codecov bot commented Dec 16, 2021

Codecov Report

Merging #2975 (3de33b4) into develop (8750b69) will increase coverage by 0.02%.
The diff coverage is 86.08%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2975      +/-   ##
===========================================
+ Coverage    82.63%   82.65%   +0.02%     
===========================================
  Files          237      237              
  Lines       193149   193607     +458     
===========================================
+ Hits        159616   160035     +419     
- Misses       33533    33572      +39     
Impacted Files Coverage Δ
src/core/mempool.rs 84.74% <ø> (ø)
testnet/stacks-node/src/config.rs 49.20% <ø> (ø)
src/chainstate/stacks/mod.rs 75.86% <75.00%> (+0.72%) ⬆️
src/chainstate/stacks/miner.rs 93.86% <77.38%> (-0.43%) ⬇️
testnet/stacks-node/src/tests/neon_integrations.rs 87.45% <96.11%> (+0.36%) ⬆️
testnet/stacks-node/src/event_dispatcher.rs 86.27% <100.00%> (+1.10%) ⬆️
testnet/stacks-node/src/neon_node.rs 83.46% <100.00%> (-0.14%) ⬇️
src/deps/bitcoin/network/serialize.rs 43.00% <0.00%> (-5.00%) ⬇️
src/burnchains/bitcoin/mod.rs 37.68% <0.00%> (-1.45%) ⬇️
src/burnchains/bitcoin/indexer.rs 83.33% <0.00%> (-1.11%) ⬇️
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98cdf3d...3de33b4. Read the comment docs.

Copy link
Contributor

@gregorycoppola gregorycoppola left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up and careful thought about it.

I just had a few questions about the control flow and comments.

src/chainstate/stacks/miner.rs Outdated Show resolved Hide resolved
@@ -445,23 +726,21 @@ impl<'a> StacksMicroblockBuilder<'a> {
self.runtime.num_mined = num_txs;

match result {
Err(Error::BlockTooBigError) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this code block to the ProcessingError branch of the match just above.
This piece of code was actually never executed before, because mine_next_transaction never returned an Err.

src/chainstate/stacks/miner.rs Outdated Show resolved Hide resolved
src/chainstate/stacks/miner.rs Show resolved Hide resolved
src/chainstate/stacks/miner.rs Outdated Show resolved Hide resolved
submit_tx(&http_origin, &tx); // should succeed
submit_tx(&http_origin, &tx_2); // should fail since it tries to publish contract with same name
submit_tx(&http_origin, &mb_tx); // should be in microblock bc it is microblock only
sleep_ms(20_000);
Copy link
Contributor

Choose a reason for hiding this comment

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

is the sleep needed? is next_block_and_wait enough?

// second block will be the first mined Stacks block
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

let account = get_account(&http_origin, &miner_account);
Copy link
Contributor

Choose a reason for hiding this comment

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

we copy these "get_account" checks around but i don't think it's needed for the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True... but I guess it doesn't hurt to ensure that the starting state of all the relevant accounts are what you expect them to be? Let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally think it's distracting to check things that aren't part of the test. There's an infinite number of things we could assert about the program at any given time.

We presumably have other tests that cover things that are not under test.

It obscures what is being tested to have extra asserts.

@gregorycoppola
Copy link
Contributor

@kantai @jcnelson is there an "ontology" of different error subtypes in the transaction processor?

How do we know which errors would cause a block to stop processing (ie break) vs keep going with the block ( ie continue?

Do we basically always continue if the block isn't full?

Are we panicking on all unrecoverable errors so that any Err error is recoverable?

@gregorycoppola
Copy link
Contributor

If we're able to change in the production code "whether or not an error-like event aborts processing for the batch", and not break any tests, then it would probably add a lot of value to add some integration tests that would capture that.

I.e., the test would break if we changed the error class of each error event.

Probably that's a big thing to ask but eventually would be very useful. This is really a key component of the blockchain flow.

src/core/mempool.rs Outdated Show resolved Hide resolved
@gregorycoppola
Copy link
Contributor

Thanks again for doing a fast job on this, @pavitthrap .

Part of the goal of making this PR was to discover an error ontology by trying this change and having it reviewed. So, hopefully doesn't seem like a drag to be iterating on the solution.

We're clarifying the API a lot and also got the events out of it.

Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

These changes look good to me, thanks @pavitthrap! Just had a few comments about the TransactionResult handling in the miner.

@gregorycoppola
Copy link
Contributor

Thanks for the help finishing this, @kantai .

Copy link
Contributor

@gregorycoppola gregorycoppola left a comment

Choose a reason for hiding this comment

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

Eagerly awaiting the landing of this PR.

I just had a few very small points and I am LGTM.

However, with so little test coverage in the area, I leave it up Aaron and Pavitthra's knowledge of the code paths and ability to read code carefully in order to ensure we don't break existing logic/consensus.

src/chainstate/stacks/miner.rs Outdated Show resolved Hide resolved
src/chainstate/stacks/miner.rs Show resolved Hide resolved
// second block will be the first mined Stacks block
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

let account = get_account(&http_origin, &miner_account);
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally think it's distracting to check things that aren't part of the test. There's an infinite number of things we could assert about the program at any given time.

We presumably have other tests that cover things that are not under test.

It obscures what is being tested to have extra asserts.

src/core/mempool.rs Outdated Show resolved Hide resolved
Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @pavitthrap!

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

Successfully merging this pull request may close these issues.

4 participants