Skip to content

refactor: Simplify batch metadata and related types#1170

Open
kostia244 wants to merge 11 commits intomainfrom
kos/batch-metadata
Open

refactor: Simplify batch metadata and related types#1170
kostia244 wants to merge 11 commits intomainfrom
kos/batch-metadata

Conversation

@kostia244
Copy link
Copy Markdown
Contributor

Summary

Main points:

  • Remove unused fields from BatchMetadata.
  • Get rid of BatchInfo.
  • Rename & move CommittedBatch to batcher_types.

Justification

BatchInfo makes little sense to me as a data structure. It has a couple useful functions but the data flow is not right: most of the fields act like BatchMetadata members instead.

As for the functions, into_stored() was really made for CommittedBatch so it makes sense to move it there.

@kostia244 kostia244 changed the title refactor:Simplify batch metadata and related types refactor: Simplify batch metadata and related types Apr 14, 2026
#[serde(rename = "commit_batch_info")]
pub batch_info: BatchInfo,
pub batch_info: CommitBatchInfoExt,
pub chain_address: Address,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping it here only because of senders -- I could pass it to sol_cal but then the argument list gets bloated, it's a separate issue IMO.

// backwards-compatibility.
#[serde(rename = "commit_batch_info")]
pub batch_info: BatchInfo,
pub batch_info: CommitBatchInfoExt,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should I implement deref to make access easier?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd implement Deref yeah

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bikeshedding: Personally, I agree with Rust API Guidelines that Deref / DerefMut should be implemented for smart pointers only, since otherwise, reasoning about field accesses / method calls quickly becomes a mess. But this rule is already violated in the codebase, so 🤷

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, I did not realize guidelines have such a strong wording on this. I have this pattern be used in a few codebases, interesting. I would not do that then, yeah

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

Test results

291 tests   291 ✅  22m 24s ⏱️
 23 suites    0 💤
  1 files      0 ❌

Results for commit 9bdea28.

♻️ This comment has been updated with latest results.

Comment on lines 15 to 16
// todo: these models are used throughout the batcher subsystem - not only l1 sender
// we will move them to `types` or `batcher_types` when an analogous crate is created in `zksync-os`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this fully, is it already time to move it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, the comment was written loooong before batch_types crate was even a thing. Let's move it there if possible.

Copy link
Copy Markdown
Collaborator

@itegulov itegulov left a comment

Choose a reason for hiding this comment

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

LGTM overall

// backwards-compatibility.
#[serde(rename = "commit_batch_info")]
pub batch_info: BatchInfo,
pub batch_info: CommitBatchInfoExt,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd implement Deref yeah

Comment on lines 15 to 16
// todo: these models are used throughout the batcher subsystem - not only l1 sender
// we will move them to `types` or `batcher_types` when an analogous crate is created in `zksync-os`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, the comment was written loooong before batch_types crate was even a thing. Let's move it there if possible.

/// todo: these fields should be a part of `CommitBatchInfo` but needs to be changed on L1 contracts' side first
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct BatchInfo {
pub struct CommitBatchInfoExt {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bikeshedding: _Ext suffix makes it look this is an extension trait. Maybe, use ExtendedCommitBatchInfo?

// backwards-compatibility.
#[serde(rename = "commit_batch_info")]
pub batch_info: BatchInfo,
pub batch_info: CommitBatchInfoExt,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bikeshedding: Personally, I agree with Rust API Guidelines that Deref / DerefMut should be implemented for smart pointers only, since otherwise, reasoning about field accesses / method calls quickly becomes a mess. But this rule is already violated in the codebase, so 🤷

Comment on lines 34 to 39
blocks: Vec<(
&BlockOutput,
&BlockContext,
&[ZkTransaction],
&zksync_os_merkle_tree::TreeBatchOutput,
)>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure whether this is in the scope of the PR, but this looks like too much data supplied, since BlockContext and TreeBatchOutput are only read for the last block.

Comment on lines +149 to +154
self.batches
.first()
.unwrap()
.batch
.batch_info
.protocol_version
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Micro-nit: You can extract this to a local var to use in the matched expression so that it doesn't need to be duplicated here.

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