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

Block: Add test that double-spending blocks are rejected #254

Closed
wants to merge 2 commits into from

Conversation

Sword-Smith
Copy link
Member

@Sword-Smith Sword-Smith commented Nov 21, 2024

@aszepieniec Let me know if these small rewrites conflict with your current work.

TODO (for future commits, not for this PR): Block's is_valid function should return an error code indicating why the block was rejected. That would make negative tests of block validity much more robust. I'll add an issue to that effect.

Includes a rewrite of helper function for constructing a new block that makes it easier to create a new block from a BlockPrimitiveWitness. Specifically, a new function block_template_from_primitive_witness is added which is used in this test as well as in the call graph for creating a new block from a transaction and a predecessor.

Also adds an "unsafe" version of MutatorSetUpdate's "apply" function that allows the caller to calculate a new MS accumulator which ignores double spends. This was needed to allow the BlockPrimitiveWitness constructor to complete the construction of a block with a double- spending transaction.

Copy link
Contributor

@aszepieniec aszepieniec left a comment

Choose a reason for hiding this comment

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

To answer your question: no, I do not think it is in conflict with my branch. Please go ahead and merge. But before you do, please consider my suggestions.

src/models/blockchain/block/mutator_set_update.rs Outdated Show resolved Hide resolved
src/models/blockchain/block/validity/block_program.rs Outdated Show resolved Hide resolved
src/models/blockchain/block/validity/block_program.rs Outdated Show resolved Hide resolved
src/models/blockchain/block/mod.rs Outdated Show resolved Hide resolved
Includes a rewrite of helper function for constructing a new block that
makes it easier to create a new block from a BlockPrimitiveWitness.
Specifically, a new function `block_template_from_primitive_witness` is
added which is used in this test as well as in the call graph for
creating a new block from a transaction and a predecessor.

Also adds an "unsafe" version of MutatorSetUpdate's "apply" function
that allows the caller to calculate a new MS accumulator which ignores
double spends. This was needed to allow the BlockPrimitiveWitness
constructor to complete the construction of a block with a double-
spending transaction.

TODO in future commit: Add a test that verifies that double spend
*within* one block is also disallowed.

Co-authored-by: Alan Szepieniec <alan@neptune.cash>
@Sword-Smith
Copy link
Member Author

Merged in 4746a77

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.

2 participants