Skip to content
Merged
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
2 changes: 1 addition & 1 deletion bootstrap/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{command, ArgAction, Parser};
use clap::{ArgAction, Parser};
use tracing::Level;

#[derive(Parser)]
Expand Down
2 changes: 1 addition & 1 deletion client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use avail_light_core::{
network::{AutoNatMode, Network},
types::{KademliaMode, NetworkMode},
};
use clap::{command, ArgAction, Parser};
use clap::{ArgAction, Parser};
use tracing::Level;

#[derive(Parser)]
Expand Down
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [1.2.13]

- Added verified cell count query API on light client
- Added put record duration histogram
- Added event source and name to event count metric
- Trigger maintenance on empty blocks
Expand Down
13 changes: 13 additions & 0 deletions core/src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ impl Reply for Version {
}
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CellCountResponse {
pub block_number: u32,
pub cell_count: u32,
}

#[cfg(not(target_arch = "wasm32"))]
impl Reply for CellCountResponse {
fn into_response(self) -> warp::reply::Response {
warp::reply::json(&self).into_response()
}
}

#[derive(Serialize, Deserialize)]
pub struct BlockRange {
pub first: u32,
Expand Down
32 changes: 31 additions & 1 deletion core/src/api/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,42 @@ Content-Type: application/json
```

If **block_status** is **incomplete**, data will be empty.
If **block_status** is not **“finished”**, or **app** mode is not enabled, data is not available and the response is:
If **block_status** is not **"finished"**, or **app** mode is not enabled, data is not available and the response is:

```yaml
HTTP/1.1 400 Bad Request
```

## **GET** `/v2/blocks/{block_number}/cell-count`

Gets the verified cell count for a specified block number. This endpoint returns the number of cells that have been successfully sampled and verified for data availability.

If the verified cell count is available (greater than zero), the response is:

```yaml
HTTP/1.1 200 OK
Content-Type: application/json

{
"block_number": {block-number},
"cell_count": {cell-count}
}
```

- **block_number** - the block number for which the cell count is requested
- **cell_count** - the number of cells that have been successfully sampled and verified for this block

If the verified cell count is zero or not available (sampling has not completed for this block), the response is:

```yaml
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"error": "Verified cell count is not available; sampling has not completed for this block"
}
```

## POST `/v2/submit`

Submits application data to the avail network.\
Expand Down
21 changes: 18 additions & 3 deletions core/src/api/v2/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{
api::{
configuration::SharedConfig,
types::{
block_status, filter_fields, Block, BlockStatus, DataQuery, DataResponse,
DataTransaction, Error, FieldsQueryParameter, Header, Status, SubmitResponse,
Subscription, SubscriptionId, Transaction, Version, WsClients,
block_status, filter_fields, Block, BlockStatus, CellCountResponse, DataQuery,
DataResponse, DataTransaction, Error, FieldsQueryParameter, Header, Status,
SubmitResponse, Subscription, SubscriptionId, Transaction, Version, WsClients,
},
},
data::{
Expand Down Expand Up @@ -172,3 +172,18 @@ pub async fn block_data(
data_transactions,
})
}

pub async fn cell_count(block_number: u32, db: impl Database + Clone) -> Result<impl Reply, Error> {
if let Some(count) = db.get(VerifiedCellCountKey(block_number)) {
if count > 0 {
return Ok(CellCountResponse {
block_number,
cell_count: count,
});
}
}

Err(Error::bad_request_unknown(
"Verified cell count is not available; sampling has not completed for this block",
))
}
1 change: 1 addition & 0 deletions core/src/api/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn routes(
.or(block_route(config.clone(), db.clone()))
.or(block_header_route(config.clone(), db.clone()))
.or(block_data_route(config.clone(), db.clone()))
.or(cell_count_route(db.clone()))
.or(subscriptions_route(ws_clients.clone()))
.or(submit_route(submitter.clone()))
.or(ws_route(ws_clients, version, config, submitter, db.clone()))
Expand Down
10 changes: 10 additions & 0 deletions core/src/api/v2/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ pub fn block_data_route(
.map(log_internal_server_error_v2)
}

pub fn cell_count_route(
db: impl Database + Clone + Send,
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
warp::path!("v2" / "blocks" / u32 / "cell-count")
.and(warp::get())
.and(with_db(db))
.then(handlers::cell_count)
.map(log_internal_server_error_v2)
}

pub fn submit_route(
submitter: Option<Arc<impl transactions::Submit + Clone + Send + Sync>>,
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
Expand Down
6 changes: 3 additions & 3 deletions core/src/network/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use tokio_retry::Retry;
#[cfg(not(target_arch = "wasm32"))]
use tokio_stream::Elapsed;
use tokio_stream::{StreamExt, StreamMap};
use tracing::{error, info, warn};
use tracing::{info, warn};

use super::{configuration::RetryConfig, Node, Nodes, Subscription, WrappedProof};
use crate::{
Expand Down Expand Up @@ -88,7 +88,7 @@ enum ClientCreationError {
#[error("Failed to connect to any RPC node")]
AllNodesFailed {
#[source]
last_error: Report,
_last_error: Report,
},

#[error("RPC function execution failed for host {host}: {error}")]
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<D: Database> Client<D> {
}

Err(Report::msg(ClientCreationError::AllNodesFailed {
last_error: last_error.unwrap_or_else(|| eyre!("No error recorded")),
_last_error: last_error.unwrap_or_else(|| eyre!("No error recorded")),
}))
}

Expand Down
2 changes: 1 addition & 1 deletion crawler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use avail_light_core::{
telemetry::otlp::OtelConfig,
types::{block_matrix_partition_format, tracing_level_format, Origin, PeerAddress},
};
use clap::{command, Parser};
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use kate_recovery::matrix::Partition;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion fat/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use avail_light_core::{
PeerAddress, SecretKey,
},
};
use clap::{command, Parser};
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use kate_recovery::matrix::Partition;
use serde::{Deserialize, Serialize};
Expand Down