Skip to content

feat: implement intoHeight trait#700

Open
varun-doshi wants to merge 3 commits intocelestiaorg:mainfrom
varun-doshi:varun/height
Open

feat: implement intoHeight trait#700
varun-doshi wants to merge 3 commits intocelestiaorg:mainfrom
varun-doshi:varun/height

Conversation

@varun-doshi
Copy link
Copy Markdown
Contributor

Fixes #693

@varun-doshi
Copy link
Copy Markdown
Contributor Author

@oblique i can switch out existing height assignments with trait based if you'd like. Anywhere specific to change?

Copy link
Copy Markdown
Collaborator

@zvolin zvolin left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the contribution. We were discussing this topic today and weren't sure which way to proceed with, so please give us some time to brainstorm that.

As to where to use it, I'd say in all celestia-rpc, celestia-grpc (and celestia-client when it's merged), and also on the lumina_node::Node` methods wherever height is required as an argument

types/src/lib.rs Outdated
mod extended_header;
pub mod fraud_proof;
pub mod hash;
pub mod height;
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.

let's make the mod private and re-export the trait down below

@@ -0,0 +1,47 @@
use tendermint::block::Height;

pub trait IntoHeight {
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 think since this can be fallible, we should rename it to TryIntoHeight and try_into_height respectively


// Error type for conversion failures
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HeightConversionError {
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.

We should also disallow 0 as height and have respective error

// Error type for conversion failures
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HeightConversionError {
NegativeValue,
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.

Suggested change
NegativeValue,
NegativeHeight,

}

// Error type for conversion failures
#[derive(Debug, Clone, PartialEq, Eq)]
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.

can you use thiserror for creating the error type? that's what we do for all other error types

@varun-doshi varun-doshi marked this pull request as ready for review August 5, 2025 07:06
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.

Create IntoHeight trait

2 participants