Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ethexe/rpc): implement rpc methods #4299

Merged
merged 11 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ numerated = { workspace = true, features = ["mock"] }
[features]
default = []
strict = []
std = ["serde/std", "dep:impl-serde", "wasmparser/std", "gear-core-errors/serde"]
std = [
"serde/std",
"dep:impl-serde",
"wasmparser/std",
"gear-core-errors/serde",
"gprimitives/serde",
]
3 changes: 3 additions & 0 deletions core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;
osipov-mit marked this conversation as resolved.
Show resolved Hide resolved

/// 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))]
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: 3 additions & 0 deletions core/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ 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 @@ -111,6 +113,7 @@ 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
5 changes: 5 additions & 0 deletions core/src/message/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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 @@ -179,6 +181,7 @@ impl Message {
TypeInfo,
derive_more::From,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
pub enum MessageDetails {
/// Reply details.
Reply(ReplyDetails),
Expand Down Expand Up @@ -228,6 +231,7 @@ impl MessageDetails {
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
pub struct ReplyDetails {
/// Message id, this message replies on.
to: MessageId,
Expand Down Expand Up @@ -261,6 +265,7 @@ impl ReplyDetails {
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
pub struct SignalDetails {
/// Message id, which issues signal.
to: MessageId,
Expand Down
3 changes: 3 additions & 0 deletions core/src/message/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};
#[cfg(feature = "std")]
use serde::Serialize;

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

Expand Down Expand Up @@ -144,6 +146,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))]
pub struct ContextStore {
outgoing: BTreeMap<u32, Option<Payload>>,
reply: Option<Payload>,
Expand Down
4 changes: 4 additions & 0 deletions core/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ 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 @@ -60,6 +62,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))]
pub struct PayloadSizeError;

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

pub use numerated::{self, num_traits};

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

impl<const SIZE: u32> Page<SIZE> {
Expand Down
3 changes: 3 additions & 0 deletions core/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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 @@ -124,6 +126,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))]
pub struct MemoryInfix(u32);

impl MemoryInfix {
Expand Down
3 changes: 3 additions & 0 deletions core/src/reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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 @@ -40,6 +42,7 @@ use scale_info::{
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Serialize))]
pub struct ReservationNonce(u64);

impl From<&InnerNonce> for ReservationNonce {
Expand Down
3 changes: 2 additions & 1 deletion ethexe/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub use gprimitives;

use gprimitives::ActorId;
use parity_scale_codec::{Decode, Encode};
use serde::Serialize;
osipov-mit marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Clone, Debug, Encode, Decode)]
pub enum BlockEvent {
Expand Down Expand Up @@ -61,7 +62,7 @@ impl From<wvara::Event> for BlockEvent {
}
}

#[derive(Clone, Debug, Encode, Decode)]
#[derive(Clone, Debug, Encode, Decode, Serialize)]
pub enum BlockRequestEvent {
Router(router::RequestEvent),
Mirror {
Expand Down
3 changes: 2 additions & 1 deletion ethexe/common/src/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use alloc::vec::Vec;
use gear_core::message::ReplyCode;
use gprimitives::{ActorId, MessageId, H256};
use parity_scale_codec::{Decode, Encode};
use serde::Serialize;

/* Events section */

Expand Down Expand Up @@ -104,7 +105,7 @@ impl Event {
}
}

#[derive(Clone, Debug, Encode, Decode)]
#[derive(Clone, Debug, Encode, Decode, Serialize)]
pub enum RequestEvent {
ExecutableBalanceTopUpRequested {
value: u128,
Expand Down
3 changes: 2 additions & 1 deletion ethexe/common/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use alloc::vec::Vec;
use gear_core::message::{Message, ReplyDetails};
use gprimitives::{ActorId, CodeId, MessageId, H256};
use parity_scale_codec::{Decode, Encode};
use serde::Serialize;

/* Storage related structures */

Expand Down Expand Up @@ -141,7 +142,7 @@ impl Event {
}
}

#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)]
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, Serialize)]
pub enum RequestEvent {
BaseWeightChanged {
base_weight: u64,
Expand Down
3 changes: 2 additions & 1 deletion ethexe/common/src/wvara.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use gprimitives::{ActorId, U256};
use parity_scale_codec::{Decode, Encode};
use serde::Serialize;

/* Events section */

Expand All @@ -44,7 +45,7 @@ impl Event {
}
}

#[derive(Clone, Debug, Encode, Decode)]
#[derive(Clone, Debug, Encode, Decode, Serialize)]
pub enum RequestEvent {
Transfer {
/// Never router, wvara or zero address.
Expand Down
4 changes: 3 additions & 1 deletion ethexe/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository.workspace = true
tokio = { workspace = true }
anyhow.workspace = true
futures.workspace = true
gprimitives.workspace = true
gprimitives = { workspace = true, features = ["serde"] }
ethexe-db.workspace = true
ethexe-processor.workspace = true
jsonrpsee = { version = "0.24", features = ["server", "macros"] }
Expand All @@ -23,5 +23,7 @@ log.workspace = true
parity-scale-codec.workspace = true
hex.workspace = true
ethexe-common.workspace = true
ethexe-runtime-common.workspace = true
sp-core = { workspace = true, features = ["serde"] }
gear-core = { workspace = true, features = ["std"] }
serde.workspace = true
13 changes: 13 additions & 0 deletions ethexe/rpc/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use jsonrpsee::types::ErrorObject;
osipov-mit marked this conversation as resolved.
Show resolved Hide resolved

pub fn db_err(err: &'static str) -> ErrorObject<'static> {
ErrorObject::owned(8000, "Database error", Some(err))
}

pub fn runtime_err(err: anyhow::Error) -> ErrorObject<'static> {
ErrorObject::owned(8000, "Runtime error", Some(format!("{err}")))
}

pub fn internal() -> ErrorObject<'static> {
ErrorObject::owned(8000, "Internal error", None::<&str>)
}
Loading
Loading