Skip to content

Commit

Permalink
Unnecessery clones + removed unused Enum value (paritytech#1557)
Browse files Browse the repository at this point in the history
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
  • Loading branch information
bkontur authored and serban300 committed Apr 9, 2024
1 parent 1b497fb commit 3a8350f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bridges/relays/client-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl TransactionSignScheme for Millau {

fn sign_transaction(param: SignParam<Self>) -> Result<Self::SignedTransaction, SubstrateError> {
let raw_payload = SignedPayload::from_raw(
param.unsigned.call.clone(),
param.unsigned.call,
(
frame_system::CheckNonZeroSender::<millau_runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<millau_runtime::Runtime>::new(),
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/client-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl TransactionSignScheme for Rialto {

fn sign_transaction(param: SignParam<Self>) -> Result<Self::SignedTransaction, SubstrateError> {
let raw_payload = SignedPayload::from_raw(
param.unsigned.call.clone(),
param.unsigned.call,
(
frame_system::CheckNonZeroSender::<rialto_runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<rialto_runtime::Runtime>::new(),
Expand Down
11 changes: 6 additions & 5 deletions bridges/relays/client-substrate/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct Client<C: Chain> {
/// Tokio runtime handle.
tokio: Arc<tokio::runtime::Runtime>,
/// Client connection params.
params: ConnectionParams,
params: Arc<ConnectionParams>,
/// Substrate RPC client.
client: Arc<RpcClient>,
/// Genesis block hash.
Expand All @@ -99,7 +99,7 @@ impl<C: Chain> relay_utils::relay_loop::Client for Client<C> {
type Error = Error;

async fn reconnect(&mut self) -> Result<()> {
let (tokio, client) = Self::build_client(self.params.clone()).await?;
let (tokio, client) = Self::build_client(&self.params).await?;
self.tokio = tokio;
self.client = client;
Ok(())
Expand Down Expand Up @@ -131,6 +131,7 @@ impl<C: Chain> Client<C> {
/// This function will keep connecting to given Substrate node until connection is established
/// and is functional. If attempt fail, it will wait for `RECONNECT_DELAY` and retry again.
pub async fn new(params: ConnectionParams) -> Self {
let params = Arc::new(params);
loop {
match Self::try_connect(params.clone()).await {
Ok(client) => return client,
Expand All @@ -149,8 +150,8 @@ impl<C: Chain> Client<C> {

/// Try to connect to Substrate node over websocket. Returns Substrate RPC client if connection
/// has been established or error otherwise.
pub async fn try_connect(params: ConnectionParams) -> Result<Self> {
let (tokio, client) = Self::build_client(params.clone()).await?;
pub async fn try_connect(params: Arc<ConnectionParams>) -> Result<Self> {
let (tokio, client) = Self::build_client(&params).await?;

let number: C::BlockNumber = Zero::zero();
let genesis_hash_client = client.clone();
Expand All @@ -173,7 +174,7 @@ impl<C: Chain> Client<C> {

/// Build client to use in connection.
async fn build_client(
params: ConnectionParams,
params: &ConnectionParams,
) -> Result<(Arc<tokio::runtime::Runtime>, Arc<RpcClient>)> {
let tokio = tokio::runtime::Runtime::new()?;
let uri = format!(
Expand Down
3 changes: 0 additions & 3 deletions bridges/relays/lib-substrate-relay/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ pub enum Error<Hash: Debug + MaybeDisplay, HeaderNumber: Debug + MaybeDisplay> {
/// Failed to retrieve header by the hash from the source chain.
#[error("Failed to retrieve {0} header with hash {1}: {:?}")]
RetrieveHeader(&'static str, Hash, client::Error),
/// Failed to retrieve best finalized source header hash from the target chain.
#[error("Failed to retrieve best finalized {0} header from the target chain: {1}")]
RetrieveBestFinalizedHeaderHash(&'static str, client::Error),
/// Failed to submit signed extrinsic from to the target chain.
#[error(
"Failed to retrieve `is_initialized` flag of the with-{0} finality pallet at {1}: {2:?}"
Expand Down

0 comments on commit 3a8350f

Please sign in to comment.