Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 4248-refactor-tests…
Browse files Browse the repository at this point in the history
…-improve-ux-of-runtime-heuristics-tests
  • Loading branch information
Lazark0x committed Nov 5, 2024
2 parents e79d1fa + 712fc0d commit 773e82d
Show file tree
Hide file tree
Showing 40 changed files with 553 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/crates-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: llvm-tools
components: llvm-tools, rust-src

- name: "Publish packages (simulate)"
if: ${{ !inputs.publish }}
Expand Down
6 changes: 4 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",
]
1 change: 1 addition & 0 deletions core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use scale_info::{
/// `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(serde::Serialize, serde::Deserialize))]
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/message/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl Message {
TypeInfo,
derive_more::From,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum MessageDetails {
/// Reply details.
Reply(ReplyDetails),
Expand Down Expand Up @@ -228,6 +229,7 @@ impl MessageDetails {
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct ReplyDetails {
/// Message id, this message replies on.
to: MessageId,
Expand Down Expand Up @@ -261,6 +263,7 @@ impl ReplyDetails {
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct SignalDetails {
/// Message id, which issues signal.
to: MessageId,
Expand Down
1 change: 1 addition & 0 deletions core/src/message/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +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(serde::Serialize, serde::Deserialize))]
pub struct ContextStore {
outgoing: BTreeMap<u32, Option<Payload>>,
reply: Option<Payload>,
Expand Down
2 changes: 2 additions & 0 deletions core/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +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(serde::Serialize, serde::Deserialize))]
pub struct PayloadSizeError;

impl From<PayloadSizeError> for &str {
Expand Down Expand Up @@ -113,6 +114,7 @@ pub enum MessageWaitedType {
#[derive(
Copy, Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum DispatchKind {
/// Initialization.
Init,
Expand Down
1 change: 1 addition & 0 deletions core/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl<const SIZE: u32> PartialOrd<PagesAmount<SIZE>> for Page<SIZE> {
Default,
derive_more::Into,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct Page<const SIZE: u32>(u32);

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

impl MemoryInfix {
Expand Down
1 change: 1 addition & 0 deletions core/src/reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use scale_info::{
#[derive(
Clone, Copy, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Decode, Encode, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct ReservationNonce(u64);

impl From<&InnerNonce> for ReservationNonce {
Expand Down
4 changes: 2 additions & 2 deletions docker/runtime-fuzzer/scripts/fuzzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function start_container_post {
--workdir /gear/utils/runtime-fuzzer \
--name ${CONTAINER_NAME_GEAR} ${IMAGE} \
-c "cargo install cargo-binutils && \
rustup component add llvm-tools-preview && \
rustup component add --toolchain nightly llvm-tools-preview && \
rustup component add llvm-tools && \
rustup component add --toolchain nightly llvm-tools && \
cargo fuzz coverage --release --sanitizer=none main /corpus/main -- \
-rss_limit_mb=8192 -max_len=450000 -len_control=0 && \
cargo cov -- show target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/main \
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::{Deserialize, Serialize};

#[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, Deserialize)]
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::{Deserialize, Serialize};

/* Events section */

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

#[derive(Clone, Debug, Encode, Decode)]
#[derive(Clone, Debug, Encode, Decode, Serialize, Deserialize)]
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::{Deserialize, Serialize};

/* Storage related structures */

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

#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)]
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, Serialize, Deserialize)]
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::{Deserialize, Serialize};

/* Events section */

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

#[derive(Clone, Debug, Encode, Decode)]
#[derive(Clone, Debug, Encode, Decode, Serialize, Deserialize)]
pub enum RequestEvent {
Transfer {
/// Never router, wvara or zero address.
Expand Down
2 changes: 1 addition & 1 deletion ethexe/contracts/script/Deployment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MirrorProxy} from "../src/MirrorProxy.sol";
import {Router} from "../src/Router.sol";
import {WrappedVara} from "../src/WrappedVara.sol";

contract RouterScript is Script {
contract DeploymentScript is Script {
WrappedVara public wrappedVara;
Router public router;
Mirror public mirror;
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, features = ["std"] }
sp-core = { workspace = true, features = ["serde"] }
gear-core = { workspace = true, features = ["std"] }
serde = { workspace = true, features = ["std"] }
73 changes: 73 additions & 0 deletions ethexe/rpc/src/apis/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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 std::collections::VecDeque;

#[rpc(server)]
pub trait Block {
#[method(name = "block_header")]
async fn block_header(&self, hash: Option<H256>) -> RpcResult<(H256, BlockHeader)>;

#[method(name = "block_commitmentQueue")]
async fn block_commitment_queue(&self, hash: Option<H256>) -> RpcResult<VecDeque<H256>>;

#[method(name = "block_events")]
async fn block_events(&self, block_hash: Option<H256>) -> RpcResult<Vec<BlockRequestEvent>>;
}

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

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

#[async_trait]
impl BlockServer for BlockApi {
async fn block_header(&self, hash: Option<H256>) -> RpcResult<(H256, BlockHeader)> {
block_header_at_or_latest(&self.db, hash)
}

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

self.db
.block_commitment_queue(block_hash)
.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("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 773e82d

Please sign in to comment.