Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Oct 21, 2024
1 parent 9c44aa9 commit 27a8e0b
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 92 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

/// Limited len vector.
/// `T` is data type.
/// `E` is overflow error type.
/// `N` is max len which a vector can have.
#[derive(Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct LimitedVec<T, E, const N: usize>(Vec<T>, PhantomData<E>);

/// Formatter for [`LimitedVec`] will print to precision of 8 by default, to print the whole data, use `{:+}`.
Expand Down
3 changes: 0 additions & 3 deletions core/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ use scale_info::{
scale::{self, Decode, Encode, EncodeLike, Input, Output},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

/// Interval in wasm program memory.
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
Expand Down Expand Up @@ -113,7 +111,6 @@ pub type PageBufInner = LimitedVec<u8, IntoPageBufError, { GearPage::SIZE as usi

/// Buffer for gear page data.
#[derive(Clone, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize))]
pub struct PageBuf(PageBufInner);

// These traits are implemented intentionally by hand to achieve two goals:
Expand Down
8 changes: 3 additions & 5 deletions core/src/message/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

/// An entity that is used for interaction between actors.
/// Can transfer value and executes by programs in corresponding function: init, handle or handle_reply.
Expand Down Expand Up @@ -181,7 +179,7 @@ impl Message {
TypeInfo,
derive_more::From,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub enum MessageDetails {
/// Reply details.
Reply(ReplyDetails),
Expand Down Expand Up @@ -231,7 +229,7 @@ impl MessageDetails {
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct ReplyDetails {
/// Message id, this message replies on.
to: MessageId,
Expand Down Expand Up @@ -265,7 +263,7 @@ impl ReplyDetails {
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct SignalDetails {
/// Message id, which issues signal.
to: MessageId,
Expand Down
4 changes: 1 addition & 3 deletions core/src/message/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

use super::{DispatchKind, IncomingDispatch, Packet};

Expand Down Expand Up @@ -146,7 +144,7 @@ impl ContextOutcome {

/// Store of previous message execution context.
#[derive(Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct ContextStore {
outgoing: BTreeMap<u32, Option<Payload>>,
reply: Option<Payload>,
Expand Down
6 changes: 2 additions & 4 deletions core/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

/// Max payload size which one message can have (8 MiB).
pub const MAX_PAYLOAD_SIZE: usize = 8 * 1024 * 1024;
Expand All @@ -62,7 +60,7 @@ const _: () = assert!(MAX_PAYLOAD_SIZE <= u32::MAX as usize);
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct PayloadSizeError;

impl From<PayloadSizeError> for &str {
Expand Down Expand Up @@ -116,7 +114,7 @@ pub enum MessageWaitedType {
#[derive(
Copy, Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub enum DispatchKind {
/// Initialization.
Init,
Expand Down
4 changes: 1 addition & 3 deletions core/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

pub use numerated::{self, num_traits};

Expand Down Expand Up @@ -197,7 +195,7 @@ impl<const SIZE: u32> PartialOrd<PagesAmount<SIZE>> for Page<SIZE> {
Default,
derive_more::Into,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct Page<const SIZE: u32>(u32);

impl<const SIZE: u32> Page<SIZE> {
Expand Down
4 changes: 1 addition & 3 deletions core/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

/// Program in different states in storage.
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, TypeInfo)]
Expand Down Expand Up @@ -126,7 +124,7 @@ pub enum ProgramState {

/// Struct defines infix of memory pages storage.
#[derive(Clone, Copy, Debug, Default, Decode, Encode, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct MemoryInfix(u32);

impl MemoryInfix {
Expand Down
4 changes: 1 addition & 3 deletions core/src/reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

/// An unchangeable wrapper over u64 value, which is required
/// to be used as a "view-only" reservations nonce in a message
Expand All @@ -42,7 +40,7 @@ use serde::Serialize;
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct ReservationNonce(u64);

impl From<&InnerNonce> for ReservationNonce {
Expand Down
46 changes: 24 additions & 22 deletions ethexe/rpc/src/modules/block.rs → ethexe/rpc/src/apis/block.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
use std::collections::VecDeque;
// This file is part of Gear.
//
// Copyright (C) 2024 Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{common::block_header_at_or_latest, errors};
use ethexe_common::BlockRequestEvent;
use ethexe_db::{BlockHeader, BlockMetaStorage, Database};
use gprimitives::H256;
use jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
};

use crate::errors;

pub fn block_header_at_or_latest(
db: &Database,
at: impl Into<Option<H256>>,
) -> RpcResult<(H256, BlockHeader)> {
if let Some(hash) = at.into() {
db.block_header(hash)
.map(|header| (hash, header))
.ok_or_else(|| errors::db_err("Block header for requested hash wasn't found"))
} else {
db.latest_valid_block()
.ok_or_else(|| errors::db_err("Latest block header wasn't found"))
}
}
use std::collections::VecDeque;

#[rpc(server)]
pub trait Block {
Expand All @@ -37,18 +39,18 @@ pub trait Block {
}

#[derive(Clone)]
pub struct BlockApiModule {
pub struct BlockApi {
db: Database,
}

impl BlockApiModule {
impl BlockApi {
pub fn new(db: Database) -> Self {
Self { db }
}
}

#[async_trait]
impl BlockServer for BlockApiModule {
impl BlockServer for BlockApi {
async fn block_header(&self, hash: Option<H256>) -> RpcResult<(H256, BlockHeader)> {
block_header_at_or_latest(&self.db, hash)
}
Expand All @@ -58,14 +60,14 @@ impl BlockServer for BlockApiModule {

self.db
.block_commitment_queue(block_hash)
.ok_or_else(|| errors::db_err("Block commitment queue wasn't found"))
.ok_or_else(|| errors::db("Block commitment queue wasn't found"))
}

async fn block_events(&self, hash: Option<H256>) -> RpcResult<Vec<BlockRequestEvent>> {
let block_hash = block_header_at_or_latest(&self.db, hash)?.0;

self.db
.block_events(block_hash)
.ok_or_else(|| errors::db_err("Block events weren't found"))
.ok_or_else(|| errors::db("Block events weren't found"))
}
}
23 changes: 23 additions & 0 deletions ethexe/rpc/src/apis/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This file is part of Gear.
//
// Copyright (C) 2024 Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

mod block;
mod program;

pub use block::{BlockApi, BlockServer};
pub use program::{ProgramApi, ProgramServer};
Loading

0 comments on commit 27a8e0b

Please sign in to comment.