Skip to content

Commit

Permalink
Batch rows RPC requests
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Feb 6, 2025
1 parent c9a413a commit 9e98b10
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.12.6

- Update `avail-light-core` to 1.2.1

## [1.12.5](https://github.com/availproject/avail-light/releases/tag/avail-light-client-v1.12.5) - 2025-01-23

- Update `avail-light-core` to 1.2.0
Expand Down
6 changes: 4 additions & 2 deletions compatibility-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use avail_light_core::{
},
shutdown::Controller,
};
use avail_rust::kate_recovery::matrix::Position;
use avail_rust::{kate_recovery::matrix::Position, primitives::kate::Rows};
use clap::Parser;
use color_eyre::Result;
use std::time::Duration;
Expand Down Expand Up @@ -111,7 +111,9 @@ async fn main() -> Result<()> {
res_helper(&res, &mut correct);

print!("Testing get_kate_row for row 0... ");
let res = rpc_client.request_kate_rows(vec![0], hash).await;
let res = rpc_client
.request_kate_rows(Rows::try_from(vec![0]).unwrap(), hash)
.await;
res_helper(&res, &mut correct);

println!("Done");
Expand Down
4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.1

- Batch rows RPC requests

## [1.2.0](https://github.com/availproject/avail-light/tree/avail-light-core-v1.2.0) - 2025-02-06

- Remove multiaddress metric attribute
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "avail-light-core"
version = "1.2.0"
version = "1.2.1"
edition = "2021"
description = "Avail Light core driving library"

Expand Down
19 changes: 13 additions & 6 deletions core/src/app_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use avail_rust::{
data::{Cell, DataCell},
matrix::{Dimensions, Position},
},
primitives::kate::{MaxRows, Rows},
sp_core::Get,
H256,
};
use color_eyre::{
Expand Down Expand Up @@ -200,14 +202,19 @@ impl<T: Database + Sync> Client for AppClient<T> {
dimensions: Dimensions,
block_hash: H256,
) -> Result<Vec<Option<Vec<u8>>>> {
let rows = rows
.clone()
.into_iter()
.zip(self.rpc_client.request_kate_rows(rows, block_hash).await?);
let max_rows = <MaxRows as Get<u32>>::get() as usize;
let expect_message = format!("Rows count is less or equal to {max_rows}");

let mut result = vec![None; dimensions.extended_rows() as usize];
for (i, row) in rows {
result[i as usize] = Some(row);
for chunk in rows.chunks(max_rows) {
let rows = Rows::try_from(chunk.to_vec()).expect(&expect_message);
debug!("Requesting rows: {chunk:?}");
let rpc_result = self.rpc_client.request_kate_rows(rows, block_hash).await?;
for (&i, row) in chunk.iter().zip(rpc_result) {
result[i as usize] = Some(row);
}
}

Ok(result)
}
}
Expand Down
7 changes: 1 addition & 6 deletions core/src/network/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,7 @@ impl<D: Database> Client<D> {
self.get_header_by_hash(finalized_hash).await
}

pub async fn request_kate_rows(
&self,
rows: Vec<u32>,
block_hash: H256,
) -> Result<Vec<Vec<u8>>> {
let rows = Rows::try_from(rows).unwrap();
pub async fn request_kate_rows(&self, rows: Rows, block_hash: H256) -> Result<Vec<Vec<u8>>> {
self.with_retries(|client| {
let rows = rows.clone();
async move {
Expand Down

0 comments on commit 9e98b10

Please sign in to comment.