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

Fix/utxo chaining #3110

Merged
merged 18 commits into from
Apr 27, 2022
Merged

Fix/utxo chaining #3110

merged 18 commits into from
Apr 27, 2022

Conversation

jcnelson
Copy link
Member

This fixes miner UTXO chaining (#2358), and adds unit tests and integration tests to verify that missed block commits are now included in a miner's UTXO chain when determining its sortition weight.

Nearly all of this new code is tests and test infrastructure. The change itself is less than 20 lines long.

…set of epochs, and make it so that we store the sortition burn sample data if the `testing` feature is enabled (so we can query it from integration tests)
…each missed block commit's intended sortition, instead of failing to find the sortition.
…n `stacks`, `clarity`, and `stacks_common`
…y flag for enabling/disabling RBF. If RBF is disabled, then query "unsafe" UTXOs (i.e. those with 0 confirmations) so we can have the test miner send multiple txs per block
…se it, set the `STX_TEST_LATE_BLOCK_COMMIT` environ to the height at which a block-commit should be bumped by one Bitcoin block. When one Bitcoin block has passed, broadcast it late. Note that RBF must be disabled to do this, so we can query 0-conf UTXOs in order to send concurrent block-commits that are not late.
@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #3110 (e9f7949) into next (b5f7a98) will increase coverage by 2.68%.
The diff coverage is 86.71%.

@@            Coverage Diff             @@
##             next    #3110      +/-   ##
==========================================
+ Coverage   81.28%   83.97%   +2.68%     
==========================================
  Files         190      265      +75     
  Lines      145162   207719   +62557     
==========================================
+ Hits       117996   174426   +56430     
- Misses      27166    33293    +6127     
Impacted Files Coverage Δ
clarity/src/vm/analysis/errors.rs 70.00% <0.00%> (ø)
clarity/src/vm/analysis/tests/mod.rs 100.00% <ø> (ø)
clarity/src/vm/analysis/trait_checker/mod.rs 100.00% <ø> (ø)
clarity/src/vm/analysis/type_checker/contexts.rs 98.91% <ø> (ø)
...arity/src/vm/analysis/type_checker/natives/maps.rs 94.25% <ø> (ø)
...ty/src/vm/analysis/type_checker/natives/options.rs 99.01% <ø> (ø)
clarity/src/vm/ast/errors.rs 57.37% <0.00%> (ø)
clarity/src/vm/ast/expression_identifier/mod.rs 95.65% <ø> (ø)
clarity/src/vm/ast/types.rs 90.90% <ø> (ø)
clarity/src/vm/coverage.rs 0.00% <0.00%> (ø)
... and 404 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 0fe97f5...e9f7949. 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.

one idea to consider but otherwise LGTM if the calculations are really correct :)

} else {
debug!("Mock-mining enabled; not sending Bitcoin transaction");
let mut send_tx = true;
if cfg!(test) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this function is already doing a lot for the reader to follow, and they will now have to keep track of a new long cryptic cfg!(test) block.

any way to inject from the outside without putting it into the prod code using some kind of "for test" version of an interface?

an alternative would be to make a function in this file called maybe_test_late_block_commit.

at the end of the day if that's not worth it and you want to check this in it's fine with me.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this -- this function is already quite complex, and it seems like this is something that would be pretty easy to at split out to another function:

#[cfg(test)]
fn test_commit_fault_injection(op, op_signer, attempt, bitcoin_controller, block_height) -> bool {
...
}
#[cfg(not(test))]
fn test_commit_fault_injection(op, op_signer, attempt, bitcoin_controller, block_height) -> bool {
   true
}
...
let send_commit = test_commit_fault_injection(op, op_signer, attempt, bitcoin_controller, block_height);
if send_commit {
...
}
...

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

.ok_or_else(|| op_error::BlockCommitNoParent)?;
let intended_sortition = match epoch.epoch_id {
StacksEpochId::Epoch21 => {
// correct behavior
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe "correct behavior, fixes issues/2358"

Comment on lines 694 to 699
if self.block_height < burnchain.first_block_height {
return Err(op_error::BlockCommitPredatesGenesis);
}
let sortition_height = self
.block_height
.saturating_sub(burnchain.first_block_height);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if self.block_height < burnchain.first_block_height {
return Err(op_error::BlockCommitPredatesGenesis);
}
let sortition_height = self
.block_height
.saturating_sub(burnchain.first_block_height);
let sortition_height = self
.block_height
.checked_sub(burnchain.first_block_height)
.ok_or_else(|| op_error::BlockCommitPredatesGenesis)?;

Using checked_sub is more idiomatic than a manual check + saturating sub.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

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.

This LGTM, just some superficial comments.

@jcnelson jcnelson changed the base branch from chore/merge-develop-to-next to next April 26, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants