Skip to content

Commit

Permalink
Improve dev_rpc_data type
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Dec 31, 2024
1 parent 20922ff commit f682750
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
1 change: 1 addition & 0 deletions solo-chains/node/tanssi-relay-service/src/dev_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub trait DevApi {
async fn inject_upward_message(&self, message: Vec<u8>) -> RpcResult<()>;
}

#[derive(Clone)]
pub struct DevRpc {
pub mock_para_inherent_channel: flume::Sender<Vec<u8>>,
pub upward_message_channel: flume::Sender<Vec<u8>>,
Expand Down
36 changes: 11 additions & 25 deletions solo-chains/node/tanssi-relay-service/src/dev_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,16 @@ struct DevDeps<C, P> {
pub pool: Arc<P>,
/// Manual seal command sink
pub command_sink: Option<futures::channel::mpsc::Sender<EngineCommand<Hash>>>,
/// Channels for dev rpcs
pub dev_rpc_data: (
Option<flume::Sender<Vec<u8>>>, //downward
Option<flume::Sender<Vec<u8>>>, //upward
),
/// Dev rpcs
pub dev_rpc: Option<DevRpc>,
}

fn create_dev_rpc_extension<C, P>(
DevDeps {
client,
pool,
command_sink: maybe_command_sink,
dev_rpc_data: maybe_dev_rpc_data,
dev_rpc: maybe_dev_rpc,
}: DevDeps<C, P>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
Expand Down Expand Up @@ -149,14 +146,8 @@ where
io.merge(ManualSeal::new(command_sink).into_rpc())?;
}

if let Some(mock_para_inherent_channel) = maybe_dev_rpc_data.0 {
io.merge(
DevRpc {
mock_para_inherent_channel,
upward_message_channel: maybe_dev_rpc_data.1.unwrap(),
}
.into_rpc(),
)?;
if let Some(dev_rpc_data) = maybe_dev_rpc {
io.merge(dev_rpc_data.into_rpc())?;
}

Ok(io)
Expand Down Expand Up @@ -770,16 +761,11 @@ fn new_full<
);
}

// We dont need the flume receiver if we are not a validator
let inherent_dev_rpc_data = if role.clone().is_authority() {
Some(downward_mock_para_inherent_sender)
} else {
None
};

// TODO: recheck if we need it to be a validator
let upm_dev_rpc_data = if role.clone().is_authority() {
Some(upward_mock_sender)
let dev_rpc = if role.clone().is_authority() {
Some(DevRpc {
mock_para_inherent_channel: downward_mock_para_inherent_sender,
upward_message_channel: upward_mock_sender,
})
} else {
None
};
Expand All @@ -794,7 +780,7 @@ fn new_full<
client: client.clone(),
pool: transaction_pool.clone(),
command_sink: command_sink.clone(),
dev_rpc_data: (inherent_dev_rpc_data.clone(), upm_dev_rpc_data.clone()),
dev_rpc: dev_rpc.clone(),
};

create_dev_rpc_extension(deps).map_err(Into::into)
Expand Down

0 comments on commit f682750

Please sign in to comment.