-
Notifications
You must be signed in to change notification settings - Fork 698
POC/WIP block simulate endpoint #6346
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
base: develop
Are you sure you want to change the base?
POC/WIP block simulate endpoint #6346
Conversation
return None; | ||
} | ||
Err(e) => { | ||
warn!("Failed to query for {}: {:?}", parent_block_id, &e); |
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.
So this doesn't work for Stacks 2.x replay?
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.
currently yes, but I would like to cover pre-nakamoto too
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.
You shouldn't need to touch the MARF at all. Just process the block, and roll back the Clarity transaction. Nothing hits the MARF until you call ClarityTx::precommit_to_block()
and PreCommitClarityBlock::commit()
. You can instead just call ClarityTx::rollback_block()
at the end of processing.
&parent_block_id, | ||
&block_id, | ||
|clarity_tx| { | ||
let (block_fees, txs_receipts) = |
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.
There's a lot more to processing a block than processing its transactions. Specifically, there's stuff in the block header that a transaction can access, so you'll need to do the relevant block-processing as well. Please see crate::net::api::postblock_proposal::NakamotoBlockProposal
for inspiration -- in particular, it uses a NakamotoBlockBuilder
to set up the ClarityTx
before processing transactions (and this code path uses the same code path that the consensus-critical block-processing logic uses).
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.
Yep, I can definitely reuse the BlockBuilder logic, but again, it interally calls inner_setup_block that calls begin_block that checks for the new block presence in the MARF
I am probably missing something, but when the clarity_tx starts, it calls begin_block then calls self.datastore.begin that finally calls self.storage.has_block for checking if the marf already has entries for the new block (and given this is a simulation for an already existent block in the chain, it always fails). |
Description
This POC tries to add the ability to re-run the transactions in a block in a sort of "simulation mode".
The trick used here is to temporarily remove references in the MARF of the currently simulated block, and re-run all of the transactions in the context of the parent block.
Note that the code still needs to be cleaned up (lot on unwrap() around)
The output of the (to be authenticated) endpoint /v3/blocks/simulate/index_block_hash is a handy json with a snapshot of the execution:
Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml