Skip to content

Commit

Permalink
Clean code base based on various pull request (#699)
Browse files Browse the repository at this point in the history
* clean code base based on various pull request

* fix ci
  • Loading branch information
Leouarz authored Dec 20, 2024
1 parent 2ead5eb commit c28470e
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
# We altered the path to avoid old actions to overwrite it
if [ ! -f ~/.cargo/bin/sccache ]; then
cargo install sccache \
rustup run stable cargo install sccache \
--git https://github.com/purestake/sccache.git \
--rev $CARGO_SCCACHE_COMMIT \
--force --no-default-features --features=dist-client
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
run: |
# We altered the path to avoid old actions to overwrite it
if [ ! -f ~/.cargo/bin/sccache ]; then
cargo install sccache \
rustup run stable cargo install sccache \
--git https://github.com/purestake/sccache.git \
--rev $CARGO_SCCACHE_COMMIT \
--force --no-default-features --features=dist-client
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
run: |
# We altered the path to avoid old actions to overwrite it
if [ ! -f ~/.cargo/bin/sccache ]; then
cargo install sccache \
rustup run stable cargo install sccache \
--git https://github.com/purestake/sccache.git \
--rev $CARGO_SCCACHE_COMMIT \
--force --no-default-features --features=dist-client
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
run: |
# We altered the path to avoid old actions to overwrite it
if [ ! -f ~/.cargo/bin/sccache ]; then
cargo install sccache \
rustup run stable cargo install sccache \
--git https://github.com/purestake/sccache.git \
--rev $CARGO_SCCACHE_COMMIT \
--force --no-default-features --features=dist-client
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: |
# We altered the path to avoid old actions to overwrite it
if [ ! -f ~/.cargo/bin/sccache ]; then
cargo install sccache \
rustup run stable cargo install sccache \
--git https://github.com/purestake/sccache.git \
--rev $CARGO_SCCACHE_COMMIT \
--force --no-default-features --features=dist-client
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
run: |
# We altered the path to avoid old actions to overwrite it
if [ ! -f ~/.cargo/bin/sccache ]; then
cargo install sccache \
rustup run stable cargo install sccache \
--git https://github.com/purestake/sccache.git \
--rev $CARGO_SCCACHE_COMMIT \
--force --no-default-features --features=dist-client
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Phase 1: Builder
# =========================
FROM debian:12.5-slim as builder
FROM debian:12.5-slim AS builder

# Install needed packages
RUN apt update -y && \
Expand Down
2 changes: 1 addition & 1 deletion LIBRARY_MATRIX.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#### Labels
- L1 - Available throught SDK as a function
- L1 - Available through SDK as a function
- L2 - Can be done but requires extra work

## Extrinsics
Expand Down
4 changes: 2 additions & 2 deletions avail-js/examples/next-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
[API routes](https://nextjs.org/docs/app/building-your-application/routing#api-routes) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/app/building-your-application/routing#api-routes) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

Expand Down
2 changes: 1 addition & 1 deletion avail-rust/DEV_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ How to build the API

and

Inisde `pub mod api { pub mod runtime_types { pub mod pallet_collective { pub mod pallet }}}` duplicate the whole `pub enum Call` enum and
Inside `pub mod api { pub mod runtime_types { pub mod pallet_collective { pub mod pallet }}}` duplicate the whole `pub enum Call` enum and
call it `pub enum Call2`. (Around line 30168)

Should look like this
Expand Down
6 changes: 1 addition & 5 deletions avail-rust/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ impl Account {
online_client: &AOnlineClient,
rpc_client: &RpcClient,
) -> Result<Vec<u32>, String> {
let keys = match self.get_app_keys(online_client, rpc_client).await {
Ok(k) => k,
Err(e) => return Err(e),
};

let keys = self.get_app_keys(online_client, rpc_client).await?;
Ok(keys.into_iter().map(|v| v.1).collect())
}
}
22 changes: 8 additions & 14 deletions avail-rust/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,10 @@ pub fn data_submissions_by_hash(
transactions: &AExtrinsics,
tx_hash: H256,
) -> Option<DataSubmission> {
let all_submissions: Vec<DataSubmission> =
transaction_by_hash_static::<DataAvailabilityCalls::SubmitData>(transactions, tx_hash)
.into_iter()
.map(|tx| DataSubmission::from_static(tx))
.collect();

all_submissions.into_iter().next()
transaction_by_hash_static::<DataAvailabilityCalls::SubmitData>(transactions, tx_hash)
.into_iter()
.map(|tx| DataSubmission::from_static(tx))
.next()
}

pub fn transaction_by_app_id(transactions: &AExtrinsics, app_id: u32) -> Vec<AExtrinsicDetails> {
Expand All @@ -334,13 +331,10 @@ pub fn data_submissions_by_app_id(
transactions: &AExtrinsics,
app_id: u32,
) -> Option<DataSubmission> {
let all_submissions: Vec<DataSubmission> =
transaction_by_app_id_static::<DataAvailabilityCalls::SubmitData>(transactions, app_id)
.into_iter()
.map(|tx| DataSubmission::from_static(tx))
.collect();

all_submissions.into_iter().next()
transaction_by_app_id_static::<DataAvailabilityCalls::SubmitData>(transactions, app_id)
.into_iter()
.map(|tx| DataSubmission::from_static(tx))
.next()
}

pub fn transaction_hash_to_index(transactions: &AExtrinsics, tx_hash: H256) -> Vec<u32> {
Expand Down
8 changes: 4 additions & 4 deletions benchmark-results/e2e.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| Sample 9 | 0.28 |
| Sample 10 | 0.22 |
| Total | 2.56 |
| Avgerage | 0.26 |
| Average | 0.26 |

### Query Data Proof
| Operation | Duration (ms) |
Expand All @@ -29,7 +29,7 @@
| Sample 9 | 4.13 |
| Sample 10 | 4.58 |
| Total | 44.77 |
| Avgerage | 4.48 |
| Average | 4.48 |

### Query Proof
| Operation | Duration (ms) |
Expand All @@ -45,7 +45,7 @@
| Sample 9 | 3550.53 |
| Sample 10 | 3579.67 |
| Total | 35487.70 |
| Avgerage | 3548.77 |
| Average | 3548.77 |

### Query Rows
| Operation | Duration (ms) |
Expand All @@ -61,4 +61,4 @@
| Sample 9 | 92.17 |
| Sample 10 | 88.14 |
| Total | 887.31 |
| Avgerage | 88.73 |
| Average | 88.73 |
18 changes: 8 additions & 10 deletions pallets/dactr/src/extensions/check_batch_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ where
[u8; 32]: From<<T as frame_system::Config>::AccountId>,
{
pub fn is_submit_data_call(&self) -> bool {
match self.0.is_sub_type() {
Some(DACall::<T>::submit_data { .. }) => true,
_ => false,
}
matches!(self.0.is_sub_type(), Some(DACall::<T>::submit_data { .. }))
}

pub fn is_send_message_call(&self) -> bool {
match self.0.is_sub_type() {
Some(VectorCall::<T>::send_message { .. }) => true,
_ => false,
}
matches!(
self.0.is_sub_type(),
Some(VectorCall::<T>::send_message { .. })
)
}

pub fn get_batch_call(&self) -> Option<&Vec<<T as UtilityConfig>::RuntimeCall>> {
Expand Down Expand Up @@ -67,6 +64,7 @@ where
IsSubType<DACall<T>> + IsSubType<UtilityCall<T>> + IsSubType<VectorCall<T>>,
[u8; 32]: From<<T as frame_system::Config>::AccountId>,
{
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(sp_std::marker::PhantomData)
}
Expand All @@ -84,7 +82,7 @@ where

Self::recursive_validate_call(calls, 0)?;

return Ok(ValidTransaction::default());
Ok(ValidTransaction::default())
}

fn recursive_validate_call(
Expand Down Expand Up @@ -117,7 +115,7 @@ where
Self::recursive_validate_call(calls, iteration + 1)?;
}

return Ok(ValidTransaction::default());
Ok(ValidTransaction::default())
}
}

Expand Down
6 changes: 2 additions & 4 deletions pallets/dactr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,8 @@ pub mod weight_helper {
pub fn submit_data<T: Config>(data_len: usize) -> Weight {
/* Compute regular substrate weight. */
let data_len: u32 = data_len.saturated_into();
let data_prefix_len: u32 = match compact_len(&data_len) {
Some(value) => value,
None => 4, // We imply the maximum
};
let data_prefix_len: u32 =
compact_len(&data_len).unwrap_or(4 /* We imply the maximum */);
// Get the encoded len.
let encoded_data_len: u32 = match data_len.checked_add(data_prefix_len) {
Some(l) => l,
Expand Down
2 changes: 1 addition & 1 deletion pallets/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ impl<T: Config> Pallet<T> {
}

/// True if the account has at least one provider reference and adding `amount` consumer
/// references would not take it above the the maximum.
/// references would not take it above the maximum.
pub fn can_accrue_consumers(who: &T::AccountId, amount: u32) -> bool {
let a = Account::<T>::get(who);
match a.consumers.checked_add(amount) {
Expand Down
2 changes: 1 addition & 1 deletion pallets/vector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ pub mod pallet {
},
};

let message_id = Self::fetch_curr_message_id().map_err(|e| e)?;
let message_id = Self::fetch_curr_message_id()?;

Self::deposit_event(Event::MessageSubmitted {
from: who,
Expand Down
4 changes: 1 addition & 3 deletions pallets/vector/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ impl VerifyingKeyJson {
delta_g2,
gamma_abc_g1,
}),
Err(_) => {
return Err(VerificationError::InvalidVK);
},
Err(_) => Err(VerificationError::InvalidVK),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/kate/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait HostedKate {
let proof = poly
.proof(srs, &cell)?
.to_bytes()
.map(|b| GProof(b))
.map(GProof)
.map_err(|_| Error::Proof)?;

Ok((data, proof))
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/arch.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is the first stage. Here we install all the dependencies that we need in order to build the Ternoa binary.
FROM registry.hub.docker.com/archlinux/archlinux:latest as builder
FROM registry.hub.docker.com/archlinux/archlinux:latest AS builder

# This installs all dependencies that we need (besides Rust).
RUN pacman -Syu --noconfirm git clang curl cmake make protobuf -y
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/debian-11.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:11.9-slim as builder
FROM debian:11.9-slim AS builder

# This installs all dependencies that we need (besides Rust).
RUN apt update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/debian-12.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:12.5-slim as builder
FROM debian:12.5-slim AS builder

# This installs all dependencies that we need (besides Rust).
RUN apt update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/fedora-39.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fedora:39 as builder
FROM fedora:39 AS builder

# This installs all dependencies that we need (besides Rust).
RUN dnf update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/fedora-40.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fedora:40 as builder
FROM fedora:40 AS builder

# This installs all dependencies that we need (besides Rust).
RUN dnf update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/ubuntu-2004.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04 as builder
FROM ubuntu:20.04 AS builder

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/ubuntu-2204.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 as builder
FROM ubuntu:22.04 AS builder

# This installs all dependencies that we need (besides Rust).
RUN apt update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/binaries/x86_64/ubuntu-2404.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:24.04 as builder
FROM ubuntu:24.04 AS builder

# This installs all dependencies that we need (besides Rust).
RUN apt update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/chainspec/mainnet/ubuntu-2204.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 as builder
FROM ubuntu:22.04 AS builder

# This installs all dependencies that we need (besides Rust).
RUN apt update -y && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/workflows/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 as builder
FROM ubuntu:22.04 AS builder

# This installs all dependencies that we need (besides Rust).
RUN apt update -y && \
Expand Down

0 comments on commit c28470e

Please sign in to comment.