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

Add AWM sign request #99

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add AWM sign request #99

wants to merge 3 commits into from

Conversation

shaokun11
Copy link

No description provided.

Copy link
Collaborator

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

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

Hey @shaokun11, your code looks pretty good at first glance! Could you run cargo fmt before I do a proper review though?

@shaokun11
Copy link
Author

Hey @shaokun11, your code looks pretty good at first glance! Could you run cargo fmt before I do a proper review though?

Just now I have do it, please review.

Copy link
Collaborator

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

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

I'm sorry, but I'm not sure that I agree with the approach here. Cloning the client every time you sign doesn't make sense.

The SignerClient_ trait provides little value too. The SignerClient<Channel> is a concrete type.

I think we need an example of actual usage as well. You might see that the need for traits completely disappears if you actually go to use the signer.

@@ -29,7 +29,7 @@ pub trait CommonVm: AppHandler + Connector + Checkable {
type ChainHandler: Handle;
type StaticHandler: Handle;
type ValidatorState: validators::State;

type WarpSigner: WarpSignerClient_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this type alias?

@@ -4,6 +4,7 @@ use std::{
time::{Duration, Instant},
};

use crate::warp::client::WarpSignerClient;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep imports merged.

@@ -1,5 +1,6 @@
use std::{collections::HashMap, io::Result};

use crate::warp::WarpSignerClient_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep imports merged.

Comment on lines 1 to 7
use std::io::{Error, ErrorKind, Read, Result};
use std::str::FromStr;

use crate::ids::Id;
use crate::proto::pb::warp::{signer_client, SignRequest, SignResponse};
use prost::bytes::Bytes;
use tonic::transport::Channel;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please merge all imports

Comment on lines 17 to 19
inner: signer_client::SignerClient::new(client_conn)
.max_decoding_message_size(usize::MAX)
.max_encoding_message_size(usize::MAX),
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are already the defaults

Suggested change
inner: signer_client::SignerClient::new(client_conn)
.max_decoding_message_size(usize::MAX)
.max_encoding_message_size(usize::MAX),
inner: signer_client::SignerClient::new(client_conn),

source_chain_id: &str,
payload: &[u8],
) -> Result<SignResponse> {
let mut client = self.inner.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

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

So you have to create a new signer client every time you need to sign? The clone here should be explicit by the user (or they can wrap their channel in some kind of lock). This masks the internal functionality and doesn't give users the option to do things more efficiently.

#[derive(Clone)]
pub struct WarpSignerClient {
inner: signer_client::SignerClient<Channel>,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the benefit of the wrapper here? Why not just use the SignerClient directly?

Comment on lines 16 to 33
pub trait CloneBox {
fn clone_box(&self) -> Box<dyn WarpSignerClient_ + Send + Sync>;
}

impl<T> CloneBox for T
where
T: 'static + WarpSignerClient_ + Clone + Send + Sync,
{
fn clone_box(&self) -> Box<dyn WarpSignerClient_ + Send + Sync> {
Box::new(self.clone())
}
}

impl Clone for Box<dyn WarpSignerClient_ + Send + Sync> {
fn clone(&self) -> Box<dyn WarpSignerClient_ + Send + Sync> {
self.clone_box()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

None of these are necessary:
https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#impl-Clone-for-Box%3CT,+A%3E

Why do you need the trait object to be Clone in the first place?

@@ -40,6 +40,7 @@ pub trait CommonVm: AppHandler + Connector + Checkable {
to_engine: Sender<Message>,
fxs: &[Fx],
app_sender: Self::AppSender,
warp_signer: Self::WarpSigner,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could just pass in the concrete type here. It's unclear if there would ever be any associated type other than SignerClient<Channel> that was ever used.

@shaokun11
Copy link
Author

@richardpringle Thank you for providing such a detailed review. I realize now that I was overthinking the problem, and now I have directly placed the signer_client into the context,how about it?

@richardpringle
Copy link
Collaborator

@richardpringle Thank you for providing such a detailed review. I realize now that I was overthinking the problem, and now I have directly placed the signer_client into the context,how about it?

That looks better!

Can we add an example of usage before we merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants