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 vmflags for witness generation 1934. #1961

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

bhartnett
Copy link
Contributor

@bhartnett bhartnett commented Jan 9, 2024

Changes included in this PR:

  • Fix issue where vmflags were being reset in the middle of processBlocksImpl. I needed these vmflags to work so I could enable witness generation in the test.
  • Turned on witness generation and verification in the test_blockchain_json test. The witness generation was previously disabled. Note that witnesses generation is still disabled by default (in production) but can be enabled by setting the GenerateWitness vmflag.
  • Fixed a minor issue where witness generation would fail for blocks with no transactions. The code has been updated to return an empty witness for a block that has no transactions. This should almost never happen in practice I'm guessing but probably a good idea to cover anyway.

if witness.len() == 0:
if vmState.stateDB.makeMultiKeys().keys.len() != 0:
raise newException(ValidationError, "Invalid trie generated from block witness")
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returning here because we can't validate an empty witness. The witness should only be empty if the multikeys are empty due to having no transactions in a block.

@@ -221,6 +227,7 @@ proc importBlock(ctx: var TestCtx, com: CommonRef,
com,
tracerInst,
)
ctx.vmState.generateWitness = true # Enable saving witness data
Copy link
Contributor Author

@bhartnett bhartnett Jan 9, 2024

Choose a reason for hiding this comment

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

I'm enabling this for all tests in this file. Will this be a problem because its not covering the default code path where witness generation is disabled? If so I can create a separate test which has the witness generation enabled and leave this one as is.

I guess it depends if there are already other tests covering this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming this is just an additional code path, and the default is still taken too?

But I don't know this code well at all, @jangko can probably answer better.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok. Like @kdeme said, the witness generation is is just additional code path. And test_blockchain_json actually don't care about block witness. I piggyback the block witness test in test_blockchain_json because the required code is simply there, instead of crafting another similar test code just to test block witness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thanks for the explanation. I'll leave it as is in that case.

@bhartnett bhartnett merged commit e60e580 into master Jan 9, 2024
7 checks passed
@bhartnett bhartnett deleted the fix-vmflags-for-witness-generation-1934 branch January 9, 2024 15:15
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.

3 participants