Skip to content

refactor: ownership/from traits in e2store#1730

Merged
njgheorghita merged 2 commits into
ethereum:masterfrom
njgheorghita:e2-fixes
Mar 27, 2025
Merged

refactor: ownership/from traits in e2store#1730
njgheorghita merged 2 commits into
ethereum:masterfrom
njgheorghita:e2-fixes

Conversation

@njgheorghita
Copy link
Copy Markdown
Contributor

@njgheorghita njgheorghita commented Mar 26, 2025

What was wrong?

Addressed some remaining comments from #1727 related to ownership patterns we use in e2store

How was it fixed?

  • removed some clones & updated ownership in conversion traits

To-Do

@njgheorghita njgheorghita marked this pull request as ready for review March 26, 2025 21:14
Copy link
Copy Markdown
Member

@KolbyML KolbyML left a comment

Choose a reason for hiding this comment

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

:shipit: looks good

Copy link
Copy Markdown
Collaborator

@morph-dev morph-dev left a comment

Choose a reason for hiding this comment

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

I found several places where we use impl TryFrom<& X > for Entry, but conversion never fails. I know that this is similar to original implementation (using TryInto), and not something that you introduced.

I would say we should use impl From<& X > for Entry whenever we can.

Looking into other types and their conversion into Entry, it seems that error can happen only during snappy encoding. But since we are always writing to Vec, I think even that can't fail, and I wouldn't be against just using .expect in that case. But I'm not going to insist on this as it's cleaner to return Error if it can fail, but I would maybe change error type to std::io::Error in that case (instead of generic anyhow::Error).

Comment thread crates/e2store/src/e2hs.rs Outdated
}

impl TryInto<Entry> for E2HSBlockIndexEntry {
impl TryFrom<&E2HSBlockIndexEntry> for Entry {
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.

If I'm not mistaken, this conversion can't fail. So I would just implement From<&E2HSBlockIndexEntry> instead.

Comment thread crates/e2store/src/era.rs Outdated
}

impl TryInto<Entry> for SlotIndexBlockEntry {
impl TryFrom<&SlotIndexBlockEntry> for Entry {
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.

Also here, maybe just do impl From<&SlotIndexBlockEntry>

Comment thread crates/e2store/src/era.rs Outdated
}

impl TryInto<Entry> for SlotIndexStateEntry {
impl TryFrom<&SlotIndexStateEntry> for Entry {
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.

And here

Comment thread crates/e2store/src/era1.rs Outdated
}

impl TryInto<Entry> for TotalDifficultyEntry {
impl TryFrom<&TotalDifficultyEntry> for Entry {
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.

And here.

Comment thread crates/e2store/src/era1.rs Outdated
}

impl TryInto<Entry> for AccumulatorEntry {
impl TryFrom<&AccumulatorEntry> for Entry {
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.

And here

Comment thread crates/e2store/src/era1.rs Outdated
}

impl TryInto<Entry> for Era1BlockIndexEntry {
impl TryFrom<&Era1BlockIndexEntry> for Entry {
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.

And here.

@njgheorghita njgheorghita merged commit a8af3cf into ethereum:master Mar 27, 2025
@njgheorghita njgheorghita deleted the e2-fixes branch March 27, 2025 15:48
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