Skip to content

Conversation

@psibi
Copy link
Member

@psibi psibi commented Sep 26, 2025

No description provided.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 26, 2025

Deploying kolme with  Cloudflare Pages  Cloudflare Pages

Latest commit: e9fe810
Status: ✅  Deploy successful!
Preview URL: https://a1383ca1.kolme.pages.dev
Branch Preview URL: https://kolme-cli-chain-version.kolme.pages.dev

View logs

@psibi psibi requested a review from snoyberg September 26, 2025 06:34
}

#[derive(Deserialize, Copy, Clone, Debug)]
pub struct BlockHeight(pub u32);
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised you're defining your own type here instead of using the one in kolme itself, any motivation for that decision?

Copy link
Member Author

Choose a reason for hiding this comment

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

I completely missed that. Will fix that!

"Cannot compute middle since start_block is greater than end_block"
);

let middle = block_height
Copy link
Member

Choose a reason for hiding this comment

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

NIT: middle seems like a confusing name here, since it seems like the delta to the middle, not the midpoint itself.

}

/// Find an arbitrary block height with a particular chain version
async fn find_block_height(&self, chain_version: &str) -> Result<BlockResponse> {
Copy link
Member

Choose a reason for hiding this comment

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

Here's an idea... what about moving the logic for this entirely into the API server itself? It would require far less network traffic to pull off this search, likely speeding up the query significantly without any significant extra strain on the server (or, perhaps, even less strain on the server).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that would probably be more efficient than this client side binary search. I will shift this logic to server side, thanks!

// Search in the upper half.
start_block = middle_block.succ()?;
}
_ => bail!("Impossible case"),
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... strange case here. I'll understand better when I look at the version_compare module.

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea here is we are checking the three cases: Equal, Less than and greater than in the above cases. The remaining condition is impossible: Less than equal to, greater than equal to etc.

Copy link
Member

Choose a reason for hiding this comment

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

My guess is that this isn't actually an impossible case, instead it may be that there's a version format the crate doesn't support.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I got it right, this logic seems to assume that versions in the chain follow SemVer and are ordered that way.

That said:

Maybe we could consider letting the user provide a custom comparison function, in case they use a different versioning scheme.

Also, regardless of how the comparison is done, I think it might make sense to always enforce that versions increase.

},
/// Send a transaction via an API server.
SendTx(SendTxOpt),
/// Fork height information
Copy link
Member

Choose a reason for hiding this comment

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

Maybe clarify what the point of this a bit more, e.g.:

Suggested change
/// Fork height information
/// Find the first block that has the given chain version

serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
version-compare = "0.2.0"
Copy link
Member

Choose a reason for hiding this comment

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

Oh, interesting. From a quick review of the crate, seems like a reasonable set of assumptions.

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.

4 participants