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

Container candidates in dev service #747

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions solo-chains/node/tanssi-relay-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sp-api = { workspace = true }
sp-authority-discovery = { workspace = true }
sp-block-builder = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-core = { workspace = true, features = [ "std" ] }
sp-inherents = { workspace = true, features = [ "std" ] }
Expand Down Expand Up @@ -81,6 +82,7 @@ async-io = { workspace = true }
async-trait = { workspace = true }
bitvec = { workspace = true, optional = true }
codec = { workspace = true }
flume = { workspace = true }
futures = { workspace = true }
gum = { workspace = true }
hex-literal = { workspace = true }
Expand Down
83 changes: 83 additions & 0 deletions solo-chains/node/tanssi-relay-service/src/dev_rpcs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi 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.

// Tanssi 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 Tanssi. If not, see <http://www.gnu.org/licenses/>

//! Development Polkadot service. Adapted from `polkadot_service` crate
//! and removed un-necessary components which are not required in dev node.

use codec::Encode;
use jsonrpsee::{
core::RpcResult,
proc_macros::rpc,
types::{
error::{INTERNAL_ERROR_CODE, INTERNAL_ERROR_MSG},
ErrorObjectOwned,
},
};

/// This RPC interface is used to provide methods in dev mode only
#[rpc(server)]
#[jsonrpsee::core::async_trait]
pub trait DevApi {
/// Indicate the mock parachain candidate insertion to be active
#[method(name = "mock_enableParaInherentCandidate")]
async fn enable_para_inherent_candidate(&self) -> RpcResult<()>;

/// Indicate the mock parachain candidate insertion to be disabled
#[method(name = "mock_disableParaInherentCandidate")]
async fn disable_para_inherent_candidate(&self) -> RpcResult<()>;
}

pub struct DevRpc {
pub mock_para_inherent_channel: flume::Sender<Vec<u8>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why does this need to be a channel, I would simply use an AtomicBool, or if you need to clone it Arc<AtomicBool>

Suggested change
pub mock_para_inherent_channel: flume::Sender<Vec<u8>>,
pub mock_para_inherent_enabled: AtomicBool,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The intention of this channel is to not write to the storage item every block, but rather only when the user requests it through the rpc. hence the channel

}

#[jsonrpsee::core::async_trait]
impl DevApiServer for DevRpc {
async fn enable_para_inherent_candidate(&self) -> RpcResult<()> {
log::info!("entering here");
let mock_para_inherent_channel = self.mock_para_inherent_channel.clone();
// Push the message to the shared channel where it will be queued up
// to be injected in to an upcoming block.
mock_para_inherent_channel
.send_async(true.encode())
.await
.map_err(|err| internal_err(err.to_string()))?;

log::info!("SENEDING ENABLE");
Ok(())
}

async fn disable_para_inherent_candidate(&self) -> RpcResult<()> {
let mock_para_inherent_channel = self.mock_para_inherent_channel.clone();
// Push the message to the shared channel where it will be queued up
// to be injected in to an upcoming block.
mock_para_inherent_channel
.send_async(false.encode())
.await
.map_err(|err| internal_err(err.to_string()))?;

Ok(())
}
}

// This bit cribbed from frontier.
pub fn internal_err<T: ToString>(message: T) -> ErrorObjectOwned {
ErrorObjectOwned::owned(
INTERNAL_ERROR_CODE,
INTERNAL_ERROR_MSG,
Some(message.to_string()),
)
}
Loading
Loading