Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ default-features = false

[workspace.dependencies.snarkvm]
#path = "../snarkVM"
git = "https://github.com/ProvableHQ/snarkVM.git"
rev = "b176b1409"
git = "https://github.com/ljedrz/snarkVM.git"
branch = "feat/record_queries"
#version = "=4.4.0"
default-features = false

Expand Down
2 changes: 2 additions & 0 deletions node/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
.route("/block/height/latest", get(Self::get_block_height_latest))
.route("/block/hash/latest", get(Self::get_block_hash_latest))
.route("/block/latest", get(Self::get_block_latest))
.route("/block/{height}/record_count", get(Self::get_number_of_block_records))
.route("/block/{height_or_hash}", get(Self::get_block))
// The path param here is actually only the height, but the name must match the route
// above, otherwise there'll be a conflict at runtime.
Expand Down Expand Up @@ -223,6 +224,7 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
// GET misc endpoints.
.route("/version", get(Self::get_version))
.route("/blocks", get(Self::get_blocks))
.route("/record_count", get(Self::get_number_of_records))
.route("/height/{hash}", get(Self::get_height))
.route("/memoryPool/transmissions", get(Self::get_memory_pool_transmissions))
.route("/memoryPool/solutions", get(Self::get_memory_pool_solutions))
Expand Down
17 changes: 17 additions & 0 deletions node/rest/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,4 +936,21 @@ impl<N: Network, C: ConsensusStorage<N>, R: Routing<N>> Rest<N, C, R> {
None => Err(RestError::service_unavailable(anyhow!("Route isn't available for this node type"))),
}
}

/// GET /{network}/record_count
pub(crate) async fn get_number_of_records(State(rest): State<Self>) -> ErasedJson {
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.

This endpoint will be quite expensive, can we put it behind auth to prevent DoSing nodes? - ProvableHQ/snarkVM#3047 (comment)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

as mentioned in the linked thread, this operation is in general less expensive than just obtaining a block; what should the criteria for auth-gating be? some fixed amount of time on reference hardware, or just algorithmic complexity (even if it's unlikely to be a concern until very large numbers are reached)?

let record_counts = rest.ledger.get_record_count();
ErasedJson::pretty(record_counts)
}

/// GET /{network}/{block}/record_count
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
/// GET /{network}/{block}/record_count
/// GET /{network}/block/{block}/record_count

pub(crate) async fn get_number_of_block_records(
State(rest): State<Self>,
Path(height): Path<u32>,
) -> Result<ErasedJson, RestError> {
match rest.ledger.get_num_block_records(height) {
Ok(record_counts) => Ok(ErasedJson::pretty(record_counts)),
Err(_) => Err(RestError::not_found(anyhow!("Records for block {height} couldn't be found"))),
}
}
}