Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions ethexe/common/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct SimpleBlockData {
pub header: BlockHeader,
}

#[cfg_attr(feature = "serde", derive(Hash))]
#[cfg_attr(feature = "serde", derive(Hash, serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, derive_more::Display)]
#[display(
"Announce(block: {block_hash}, parent: {parent}, gas: {gas_allowance:?}, txs: {injected_transactions:?})"
Expand Down Expand Up @@ -140,7 +140,7 @@ pub enum PromisePolicy {
}

#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy, Default, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct StateHashWithQueueSize {
pub hash: H256,
pub canonical_queue_size: u8,
Expand Down
89 changes: 89 additions & 0 deletions ethexe/rpc/src/apis/announce.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This file is part of Gear.
//
// Copyright (C) 2026 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::{errors, utils};
use ethexe_common::{Announce, ProgramStates, db::AnnounceStorageRO, gear::StateTransition};
use ethexe_db::Database;
use jsonrpsee::{
core::{RpcResult, async_trait},
proc_macros::rpc,
};
use sp_core::H256;

#[cfg_attr(not(feature = "client"), rpc(server))]
#[cfg_attr(feature = "client", rpc(server, client))]
pub trait Announce {
#[method(name = "announce_by_hash")]
async fn announce(&self, announce_hash: Option<H256>) -> RpcResult<(H256, Announce)>;

#[method(name = "announce_outcome")]
async fn announce_outcome(
&self,
announce_hash: Option<H256>,
) -> RpcResult<Vec<StateTransition>>;

#[method(name = "announce_program_states")]
async fn announce_program_states(
&self,
announce_hash: Option<H256>,
) -> RpcResult<ProgramStates>;
}

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

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

#[async_trait]
impl AnnounceServer for AnnounceApi {
async fn announce(&self, announce_hash: Option<H256>) -> RpcResult<(H256, Announce)> {
let hash = utils::announce_at_or_latest_computed(&self.db, announce_hash)?;
let announce = self
.db
.announce(hash)
.ok_or_else(|| errors::db("Announce wasn't found"))?;

Ok((hash.inner(), announce))
}

async fn announce_outcome(
&self,
announce_hash: Option<H256>,
) -> RpcResult<Vec<StateTransition>> {
let hash = utils::announce_at_or_latest_computed(&self.db, announce_hash)?;
self.db
.announce_outcome(hash)
.ok_or_else(|| errors::db("Announce outcome wasn't found"))
}

async fn announce_program_states(
&self,
announce_hash: Option<H256>,
) -> RpcResult<ProgramStates> {
let hash = utils::announce_at_or_latest_computed(&self.db, announce_hash)?;
self.db
.announce_program_states(hash)
.ok_or_else(|| errors::db("Announce program states weren't found"))
}
}
Comment on lines +59 to +89
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new Announce RPC API introduces several new endpoints (announce_by_hash, announce_outcome, announce_program_states). However, there are no corresponding unit or integration tests added to verify the correctness and expected behavior of these new APIs. This is a violation of the repository's review priority on "Verification Expectations" (line 44 of the style guide), specifically "Behavior changes without tests". It is crucial to add tests to ensure the reliability and stability of these new RPC functionalities.

References
  1. Behavior changes without tests are a violation of verification expectations. (link)

5 changes: 4 additions & 1 deletion ethexe/rpc/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
// 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 announce;
mod block;
mod code;
mod injected;
mod program;

pub use announce::{AnnounceApi, AnnounceServer};
pub use block::{BlockApi, BlockServer};
pub use code::{CodeApi, CodeServer};
pub use injected::{InjectedApi, InjectedServer};
pub use program::{FullProgramState, ProgramApi, ProgramServer};

#[cfg(feature = "client")]
pub use crate::apis::{
block::BlockClient, code::CodeClient, injected::InjectedClient, program::ProgramClient,
announce::AnnounceClient, block::BlockClient, code::CodeClient, injected::InjectedClient,
program::ProgramClient,
};
13 changes: 10 additions & 3 deletions ethexe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#[cfg(feature = "client")]
pub use crate::apis::{BlockClient, CodeClient, FullProgramState, InjectedClient, ProgramClient};
pub use crate::apis::{
AnnounceClient, BlockClient, CodeClient, FullProgramState, InjectedClient, ProgramClient,
};

use anyhow::Result;
use apis::{
BlockApi, BlockServer, CodeApi, CodeServer, InjectedApi, InjectedServer, ProgramApi,
ProgramServer,
AnnounceApi, AnnounceServer, BlockApi, BlockServer, CodeApi, CodeServer, InjectedApi,
InjectedServer, ProgramApi, ProgramServer,
};
use ethexe_common::injected::{
AddressedInjectedTransaction, InjectedTransactionAcceptance, SignedPromise,
Expand Down Expand Up @@ -113,6 +115,7 @@ impl RpcServer {
let server_apis = RpcServerApis {
code: CodeApi::new(self.db.clone()),
block: BlockApi::new(self.db.clone()),
announce: AnnounceApi::new(self.db.clone()),
program: ProgramApi::new(self.db.clone(), processor, self.config.gas_allowance),
injected: InjectedApi::new(rpc_sender),
};
Expand Down Expand Up @@ -181,6 +184,7 @@ impl FusedStream for RpcService {

struct RpcServerApis {
pub block: BlockApi,
pub announce: AnnounceApi,
pub code: CodeApi,
pub injected: InjectedApi,
pub program: ProgramApi,
Expand All @@ -193,6 +197,9 @@ impl RpcServerApis {
module
.merge(BlockServer::into_rpc(self.block))
.expect("No conflicts");
module
.merge(AnnounceServer::into_rpc(self.announce))
.expect("No conflicts");
module
.merge(CodeServer::into_rpc(self.code))
.expect("No conflicts");
Expand Down
Loading