Skip to content

Add availability endpoint to axum API#4216

Merged
ss-es merged 34 commits intomainfrom
ss/axum-2
May 7, 2026
Merged

Add availability endpoint to axum API#4216
ss-es merged 34 commits intomainfrom
ss/axum-2

Conversation

@ss-es
Copy link
Copy Markdown
Contributor

@ss-es ss-es commented Apr 23, 2026

This PR migrates the availability endpoint to Axum, with a copy of the old endpoint served at v1/availability and newer protobuf-specified endpoints served at v2/data and v2/consensus.

You can skip test_api.rs (this is just to render an example UI without having to compile espresso-node) and espresso.api.v2.rs (this is automatically generated).

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request expands the Espresso API by implementing the Data and Consensus APIs for v2 and the Availability API for v1. These changes introduce endpoints for retrieving namespace proofs, incorrect encoding proofs, state certificates, and stake tables, along with their corresponding proto definitions and Axum routing logic. The review feedback identifies a critical recurring logic error across several new handlers in crates/espresso/node/src/api/state.rs, where the join! macro is used twice on the same set of futures. This pattern is invalid as the first join! resolves the futures, causing subsequent calls to with_timeout or a second join! to fail during compilation.

Comment thread crates/espresso/node/src/api/state.rs Outdated
Comment thread crates/espresso/node/src/api/state.rs Outdated
Comment thread crates/espresso/node/src/api/state.rs Outdated
Comment thread crates/espresso/node/src/api/state.rs Outdated
Comment thread crates/espresso/api/src/axum.rs Outdated
Comment thread crates/espresso/api/src/axum.rs Outdated
Comment thread crates/serialization/api/proto/v2/consensus.proto Outdated
Comment thread crates/serialization/api/proto/v2/consensus.proto Outdated
@github-actions
Copy link
Copy Markdown
Contributor

Unable to build without Cargo.lock file.

This means that after this change 3rd party projects may have
difficulties using crates in this repo as a dependency. If this
isn't easy to fix please open an issue so we can fix it later.

For the first failing build see: https://github.com/EspressoSystems/espresso-network/actions/runs/24975975015

To reproduce locally run

cargo generate-lockfile
cargo check --all-targets

This PR can still be merged.

.await
.map(Json)
.map_err(ApiError::Internal)
};
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.

this part here feels a bit verbose and could probably be condensed. exploring options in the next PR.


// Fetch block and VID common data
let ds = &*self.data_source;
let timeout = std::time::Duration::from_millis(500);
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.

this seems a bit weird, but the existing incorrect_encoding_proof path uses get_block_for_ns_proof which (I believe) does essentially the same thing

})?;

// Store the fetched certificate
ds.insert_state_cert(epoch, cert.clone()).await?;
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.

this mirrors the existing get_state_cert in espresso/node/src/api/endpoints/availability.rs, though maybe we should revisit the behaviour

@ss-es ss-es marked this pull request as ready for review April 27, 2026 06:42
Comment thread crates/espresso/api/src/axum/routes.rs Outdated
/// Get namespace proof by block height
/// Path: GET /v1/availability/namespace/{namespace}/block/{height}
pub const NAMESPACE_PROOF_BY_HEIGHT_ROUTE: &str =
"/v1/availability/namespace/{namespace}/block/{height}";
Copy link
Copy Markdown
Collaborator

@sveitser sveitser Apr 30, 2026

Choose a reason for hiding this comment

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

Is the change of parameter order intentional?

[route.getnamespaceproof]
PATH = [
"block/:height/namespace/:namespace",
"block/hash/:hash/namespace/:namespace",
"block/payload-hash/:payload-hash/namespace/:namespace",
]
":height" = "Integer"
":hash" = "TaggedBase64"
":payload-hash" = "TaggedBase64"
":namespace" = "Integer"

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.

no definitely not, very good catch!

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.

added tests to ensure this doesn't happen: 9d917b1

Comment thread crates/espresso/node/src/api/state.rs Outdated
.to_string();

Ok(v2::Transaction {
namespace: tx.namespace.0 as u32,
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.

It seems we have namespace ID as u64 and u32 in different places. Maybe a comment why this is fine here?

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 think u32 was how the old Tide API was casting it in some places. But u64 is the internal type, and I think this is actually better to just make a u64 for consistency (especially since it only eliminates conversions)

fixed: 6ad876c

Ok(proofs)
}

async fn get_incorrect_encoding_proof(
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'm confused. This function always returns an error.

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.

oops, fixed: 9864160

the code is a bit weird, but I think this follows the existing behaviour around line 413 in crates/espresso/node/src/api/endpoints/availability.rs. unfortunately I think this specific endpoint is hard to add to the test, we don't have any existing tests for it and I'm not sure if anyone is using this endpoint anyway

@sveitser
Copy link
Copy Markdown
Collaborator

This PR adds the axum migration for the espresso node availability API overlay but most of the availability API is from the hotshot query service. I think we can merge this first but just wanted to mention it, it kind of confused me at first.


// IP address (v4 or v6) with port
message InetAddr {
string ip = 1; // IP address string (e.g., "127.0.0.1" or "::1")
Copy link
Copy Markdown
Member

@Ayiga Ayiga May 1, 2026

Choose a reason for hiding this comment

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

Are we expecting to be able to concatenate the port and the ip without inspecting the ip value itself?

If so, then we may actually want to store [::1] instead of just ::1 for convenience.

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.

fixed here: 9864160

@ss-es ss-es changed the base branch from main to ss/axum-tests-1 May 4, 2026 05:32
@sveitser sveitser self-requested a review May 6, 2026 09:51
Copy link
Copy Markdown
Collaborator

@sveitser sveitser left a comment

Choose a reason for hiding this comment

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

I think this is fine but what about the query service availability API? The comment I left here: #4216 (comment)

Base automatically changed from ss/axum-tests-1 to main May 6, 2026 14:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Nextest failures (1) in this run

Test Attempts Time (s) Main history
hotshot-new-protocol::tests::restarts::late_start_one_node_with_epochs 1 55.12 passing

See the step summary for flaky tests and slowest tests.

@ss-es ss-es merged commit d015da3 into main May 7, 2026
169 of 175 checks passed
@ss-es ss-es deleted the ss/axum-2 branch May 7, 2026 17:13
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