-
Notifications
You must be signed in to change notification settings - Fork 679
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
Refactor: merge block assembly paths for follower and miner #2946
Conversation
WIP - need to remove double mutable borrow of chainstate Factored out setup_block Renamed block finishing function and added function comment
Codecov Report
@@ Coverage Diff @@
## develop #2946 +/- ##
===========================================
+ Coverage 82.15% 82.91% +0.76%
===========================================
Files 235 235
Lines 189697 189778 +81
===========================================
+ Hits 155837 157351 +1514
+ Misses 33860 32427 -1433
Continue to review full report at Codecov.
|
Thanks @pavitthrap ! I'll try to review this PR this week, but I think, given the timing of the 2.05.0.0.0 rc and release, we shouldn't merge this into that release, and wait to merge until the subsequent point release. |
/// of the burn tip, burn tip height + 1, the parent microblock stream, | ||
/// the parent consensus hash, the parent header hash, and a bool | ||
/// representing whether the network is mainnet or not. | ||
pub fn pre_epoch_begin<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hard time understanding why the pre_epoch_begin
and epoch_begin
split needs to exist. It seems like the bulk of the refactoring work here is in creating the StacksChainState::setup_block()
method. Is there a compelling reason why the miner can't keep a single epoch_begin()
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also wondering this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure that this is necessary for the borrow-checker/ownership checks: something higher than the scope of epoch_begin
needs to own the returned ChainstateTx
and ClarityInstance
(returned by chainstate.chainstate_tx_begin()?;
), so this code cannot all live in epoch_begin
. And that line cannot be called by itself, because a lot of the setup work in pre_epoch_begin
needs reference the StacksChainState
, which cannot be used while the ChainstateTx
and ClarityInstance
are alive (because their lifetimes are bound to a mutable reference to the StacksChainState
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like it should be possible to expand the definition of epoch_begin
to allow all of this.
But, I also don't feel that strongly, so I am OK with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure that this is necessary for the borrow-checker/ownership checks:
Yeah I see that now.
@pavitthrap Can we call this something more informative, in order to communicate this? Perhaps epoch_setup()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Overall looks like it helps remove code duplication.
I had a few questions.
"Invalid Stacks microblocks {},{} (offender {}): {:?}", | ||
parent_consensus_hash, parent_header_hash, mblock_header_hash, &e | ||
); | ||
warn!("{}", &msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ti's easier to read if you put the format in thw warn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require a needless clone()
-- you'd have to build the string once for the warn!
, and once for the InvalidStacksMicroblock
error constructor. The code pattern here is used elsewhere, and is fine by me.
/// of the burn tip, burn tip height + 1, the parent microblock stream, | ||
/// the parent consensus hash, the parent header hash, and a bool | ||
/// representing whether the network is mainnet or not. | ||
pub fn pre_epoch_begin<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also wondering this.
I think this change looks good.. the only thing is I think there is some debate about whether |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @pavitthrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fixes #2914
Added
setup_block
andfinish_block
to consolidate some logic in block assembly.Refactored following functions:
epoch_begin
inminer.rs
append_block
inchainstate/stacks/db/blocks.rs
Reviewer notes:
get_stacks_block_anchored_cost
fails (when getting the parent execution cost). The code now returns an error. I can make this panic if need be.To review this, I went through the code paths of both the follower and miner and ensured all the logic was being executed.
append_block
are still being called (and in a order that still makes sense).epoch_begin
andmine_anchored_block
is preserved.Tests:
Since this was a refactor, no new tests were added.