Conversation
51e74e4 to
6dd5f53
Compare
| // Encoded using [winter_utils::Serializable] implementation for | ||
| // [miden_protocol::transaction::proven_tx::ProvenTransaction]. | ||
| bytes encoded = 1; | ||
| message TransactionBatch { |
There was a problem hiding this comment.
The suggestion here I think was to re-add the proven_batch property, and have the others be optional so we can drop them at some point.
There was a problem hiding this comment.
This is probably fine for now, but in the next release, we'll need to change this to something like ProvenTransactionBatch which would contain the ProvenBatch struct + optional data that would allow us to re-execute all transactions in the batch and validate that the proven batch is correct (similar to how we do it for proven transactions).
There was a problem hiding this comment.
I've added it in now. Naming might still be off, e.g. TransactionBatch but I think maybe its more useful to end users than Batch.. maybe not though.
There was a problem hiding this comment.
@PhilippGackstatter if you could throw an eye on the process here to ensure I'm checking the correct things.
The state itself is checked in the mempool, so here we really just want to ensure that the batch and its transactions are valid and the reference block is correct iiuc.
There was a problem hiding this comment.
Looks good to me. I left another comment re batch expiration, but your call where/if to do that.
| &mut self, | ||
| txs: &[Arc<AuthenticatedTransaction>], | ||
| ) -> Result<BlockNumber, MempoolSubmissionError> { | ||
| assert!(!txs.is_empty(), "Cannot have a batch with no transactions"); |
There was a problem hiding this comment.
Just checking we want to crash here instead of return error
There was a problem hiding this comment.
I assumed that one cannot build a ProvenBatch without one, so this would indicate an internal bug somewhere. But maybe that's a poor assumption.
| } | ||
|
|
||
| pub fn select_batch(&mut self, budget: BatchBudget) -> Option<SelectedBatch> { | ||
| self.select_user_batch().or_else(|| self.select_conventional_batch(budget)) |
There was a problem hiding this comment.
Might want some doc comments to make it clear that budget is intended to only relevant for conventional batches.
There was a problem hiding this comment.
Also are we OK with user batches always taking priority over conventional here?
There was a problem hiding this comment.
Also wondering if we need to prevent user batches of size 1 (or some other limit). Unsure if that is relevant to this PR just a general thought.
There was a problem hiding this comment.
Also are we OK with user batches always taking priority over conventional here?
I'm unsure, but at the moment it doesn't matter much. If its a concern we can make it random -- I was thinking maybe that's best.
Also wondering if we need to prevent user batches of size 1 (or some other limit). Unsure if that is relevant to this PR just a general thought.
Good question. I'm unsure 😬 I wonder if that makes some user loop more difficult i.e. they always submit user batches, but sometimes they don't have many transactions to bundle..
Probably we would want some limit even in the future? cc @bobbinth
There was a problem hiding this comment.
Also are we OK with user batches always taking priority over conventional here?
Would having fees solve this?
There was a problem hiding this comment.
It would give us a strategy to use, so yes fees solve this imo. Though it will be potentially complex to implement.
igamigo
left a comment
There was a problem hiding this comment.
LGTM! I left some mostly minor, non-blocking comments. Not sure if you tested already but jsut in case, I'm going to run the client integration tests and report back.
| } | ||
|
|
||
| pub fn select_batch(&mut self, budget: BatchBudget) -> Option<SelectedBatch> { | ||
| self.select_user_batch().or_else(|| self.select_conventional_batch(budget)) |
There was a problem hiding this comment.
Also are we OK with user batches always taking priority over conventional here?
Would having fees solve this?
681eb87 to
a474113
Compare
| // Verify batch transaction proofs. | ||
| // | ||
| // Need to do this because ProvenBatch has no real kernel yet, so we can only | ||
| // really check that the calculated proof matches the one given in the request. | ||
| let expected_proof = LocalBatchProver::new(MIN_PROOF_SECURITY_LEVEL) | ||
| .prove(proposed_batch.clone()) | ||
| .map_err(|err| { | ||
| Status::invalid_argument(err.as_report_context("proposed block proof failed")) | ||
| })?; | ||
|
|
||
| if expected_proof != proven_batch { | ||
| return Err(Status::invalid_argument("batch proof did not match proposed batch")); | ||
| } |
There was a problem hiding this comment.
Is this the idea? I'm unsure on how else to align the proof with the batch.. unless I also compare headers and then just assume?
Can a proof differ based on some other variables e.g. time, rng? Or is this safe to do.
There was a problem hiding this comment.
That seems fine and sufficient. The "proof" (which is not a cryptographic one now anyway) should be deterministic based on the input (the proposed batch), since it's really just destructuring the proposed batch, verifying transaction proofs and constructing the proven batch.
1e09f16 to
e528296
Compare
| "batch reference commitment {} at block {} does not match canonical chain's commitment of {}", | ||
| expected_proof.reference_block_num(), | ||
| expected_proof.reference_block_commitment(), | ||
| reference_header.commitment() |
There was a problem hiding this comment.
| "batch reference commitment {} at block {} does not match canonical chain's commitment of {}", | |
| expected_proof.reference_block_num(), | |
| expected_proof.reference_block_commitment(), | |
| reference_header.commitment() | |
| "batch reference commitment {} at block {} does not match canonical chain's commitment of {}", | |
| expected_proof.reference_block_commitment(), | |
| expected_proof.reference_block_num(), | |
| reference_header.commitment() |
Nit: I think these need to be swapped
| } | ||
|
|
There was a problem hiding this comment.
Is the batch expiration deliberately not checked? This would also be a pretty cheap check, assuming the latest block is easily retrievable here. E.g. if the batch expiration is already older than the latest block, we should be able to discard it directly.
There was a problem hiding this comment.
Looks good to me. I left another comment re batch expiration, but your call where/if to do that.
This PR is the third and final part of the mempool refactoring PR stack. Part 1 (#1820) performs the broad mempool refactoring to simplify this PR. Builds on part 2 (#1832).
Batch submissions must include their transaction inputs since we currently require this for the validator to verify them before inclusion in a block. This PR abuses this by treating the batch as a set of normal transactions at the mempool level. This simplifies the mempool implementation, which is currently built around a DAG of transactions - so having to insert a batch directly would be more complex. This will need to change once we stop requiring transaction inputs as part of the validator; but it won't be too bad.
The way this is implemented here, is that the transaction DAG tracks user batches and ensures that when a batch is selected, that transactions from user batches are not mixed with conventional transactions. That is,
select_batchoutputs either a user batch, or a conventional batch.Effectively, the transaction DAG internally ensures that the user batch's transactions remain coherent even though the batch has been deconstructed into individual transactions. The benefit is that this doesn't require any major structural changes to the mempool. The rest of the mempool then treats the user batch as per normal.
Closes #1112 and closes #1859