-
Notifications
You must be signed in to change notification settings - Fork 1
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 /relay_tx
endpoint
#1050
Add /relay_tx
endpoint
#1050
Changes from all commits
26e1519
0c33812
2b2594e
8150b14
350e9c0
51b3353
abe8958
75a1721
6256782
f238480
e8c4858
0c17e6e
feef814
411b0cb
8ab7646
c89d04b
f25e7a4
2d40885
5d96f9d
352f90b
4739610
0216957
5f9745d
0074333
0259ec5
961ae6a
f6dc78a
333427c
74796ee
13a3511
dbed146
f8a7a72
d545ecf
f862b6e
d59d6a0
31afe48
f57a5b2
3d7cec4
59906f7
d423fee
57485d8
826af21
6682807
13eced6
9abc957
0f68423
2374b32
e07904e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,6 @@ pub struct UserSignatureRequest { | |
pub message: String, | ||
/// Hex-encoded auxilary data for program evaluation, will not be signed (eg. zero-knowledge proof, serialized struct, etc) | ||
pub auxilary_data: Option<Vec<Option<String>>>, | ||
/// Information from the validators in signing party | ||
pub validators_info: Vec<ValidatorInfo>, | ||
/// When the message was created and signed | ||
pub block_number: BlockNumber, | ||
/// Hashing algorithm to be used for signing | ||
|
@@ -40,24 +38,32 @@ pub struct UserSignatureRequest { | |
pub signature_verifying_key: Vec<u8>, | ||
} | ||
|
||
pub async fn get_signers_from_chain( | ||
/// Represents an unparsed transaction request coming from a relayer to a signer. | ||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct RelayerSignatureRequest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably just have this in the body of pub struct UserSignatureRequest {
pub request: RelayerSignatureRequest,
pub validators_info: Vec<ValidatorInfo>,
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes but opposite |
||
// Request relayed from user to signer | ||
pub user_signature_request: UserSignatureRequest, | ||
/// Information for the validators in the signing party | ||
pub validators_info: Vec<ValidatorInfo>, | ||
} | ||
|
||
/// Gets a validator from chain to relay a message to the signers | ||
/// Filters out all signers | ||
pub async fn get_validators_not_signer_for_relay( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
) -> Result<Vec<ValidatorInfo>, SubgroupGetError> { | ||
let signer_query = entropy::storage().staking_extension().signers(); | ||
let mut validators = query_chain(api, rpc, signer_query, None) | ||
let signers = query_chain(api, rpc, signer_query, None) | ||
.await? | ||
.ok_or_else(|| SubgroupGetError::ChainFetch("Get all validators error"))?; | ||
|
||
let key_info_query = entropy::storage().parameters().signers_info(); | ||
let threshold = query_chain(api, rpc, key_info_query, None) | ||
let validators_query = entropy::storage().session().validators(); | ||
let mut validators = query_chain(api, rpc, validators_query, None) | ||
.await? | ||
.ok_or_else(|| SubgroupGetError::ChainFetch("Failed to get signers info"))? | ||
.threshold; | ||
|
||
// TODO #899 For now we just take the first t validators as the ones to perform signing | ||
validators.truncate(threshold as usize); | ||
.ok_or_else(|| SubgroupGetError::ChainFetch("Error getting validators"))?; | ||
|
||
validators.retain(|validator| !signers.contains(validator)); | ||
let block_hash = rpc.chain_get_block_hash(None).await?; | ||
let mut handles = Vec::new(); | ||
|
||
|
@@ -85,6 +91,51 @@ pub async fn get_signers_from_chain( | |
handles.push(handle); | ||
} | ||
|
||
let mut all_validators: Vec<ValidatorInfo> = vec![]; | ||
for handle in handles { | ||
all_validators.push(handle.await??); | ||
} | ||
|
||
Ok(all_validators) | ||
} | ||
|
||
/// Gets all signers from chain | ||
pub async fn get_all_signers_from_chain( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
) -> Result<Vec<ValidatorInfo>, SubgroupGetError> { | ||
let signer_query = entropy::storage().staking_extension().signers(); | ||
let signers = query_chain(api, rpc, signer_query, None) | ||
.await? | ||
.ok_or_else(|| SubgroupGetError::ChainFetch("Get all validators error"))?; | ||
|
||
let block_hash = rpc.chain_get_block_hash(None).await?; | ||
let mut handles = Vec::new(); | ||
|
||
for signer in signers { | ||
let handle: tokio::task::JoinHandle<Result<ValidatorInfo, SubgroupGetError>> = | ||
tokio::task::spawn({ | ||
let api = api.clone(); | ||
let rpc = rpc.clone(); | ||
async move { | ||
let threshold_address_query = | ||
entropy::storage().staking_extension().threshold_servers(signer); | ||
let server_info = query_chain(&api, &rpc, threshold_address_query, block_hash) | ||
.await? | ||
.ok_or_else(|| { | ||
SubgroupGetError::ChainFetch("threshold_servers query error") | ||
})?; | ||
Ok(ValidatorInfo { | ||
x25519_public_key: server_info.x25519_public_key, | ||
ip_address: std::str::from_utf8(&server_info.endpoint)?.to_string(), | ||
tss_account: server_info.tss_account, | ||
}) | ||
} | ||
}); | ||
|
||
handles.push(handle); | ||
} | ||
|
||
let mut all_signers: Vec<ValidatorInfo> = vec![]; | ||
for handle in handles { | ||
all_signers.push(handle.await??); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this ever happens, how can you tell who the bad guy was? Why not bail earlier, when you're collecting the verification results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya I mean this relates to peg's earlier comment, I will open an issue in a bit and link it, pretty much how we return the results im open to discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1062