-
Notifications
You must be signed in to change notification settings - Fork 2
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
Report unstable peers from TSS #1228
Changes from 32 commits
51ebc94
8541cb0
5be281c
ae0640e
71ffda7
031a741
257b29a
0c88996
a675856
2f6b7b5
8a9c9de
e024127
299df21
94973c7
604d613
c004741
fdd9a23
0914a1e
9287f7c
a65103b
1abd6dd
06e2115
2d82e01
e175082
4c5483a
058ede6
367e846
607570b
c5d6053
3dfa5db
42935bc
70a76db
8362290
251e422
62060dc
b2c1852
7853f62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ use x25519_dalek::StaticSecret; | |
|
||
use super::UserErr; | ||
use crate::chain_api::entropy::runtime_types::pallet_registry::pallet::RegisteredInfo; | ||
use crate::signing_client::ProtocolErr; | ||
use crate::{ | ||
chain_api::{entropy, get_api, get_rpc, EntropyConfig}, | ||
helpers::{ | ||
|
@@ -351,14 +352,15 @@ pub async fn sign_tx( | |
request_limit, | ||
derivation_path, | ||
) | ||
.await | ||
.map(|signature| { | ||
( | ||
.await; | ||
|
||
let signing_protocol_output = match signing_protocol_output { | ||
Ok(signature) => Ok(( | ||
BASE64_STANDARD.encode(signature.to_rsv_bytes()), | ||
signer.signer().sign(&signature.to_rsv_bytes()), | ||
) | ||
}) | ||
.map_err(|error| error.to_string()); | ||
)), | ||
Err(e) => Err(handle_protocol_errors(&api, &rpc, &signer, e).await.unwrap_err()), | ||
}; | ||
|
||
// This response chunk is sent later with the result of the signing protocol | ||
if response_tx.try_send(serde_json::to_string(&signing_protocol_output)).is_err() { | ||
|
@@ -370,6 +372,56 @@ pub async fn sign_tx( | |
Ok((StatusCode::OK, Body::from_stream(response_rx))) | ||
} | ||
|
||
/// Helper for handling different protocol errors. | ||
/// | ||
/// If the error is of the reportable type (e.g an offence from another peer) it will be reported | ||
/// on-chain by this helper. | ||
async fn handle_protocol_errors( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
signer: &PairSigner<EntropyConfig, sr25519::Pair>, | ||
error: ProtocolErr, | ||
) -> Result<(), String> { | ||
let peers_to_report: Vec<SubxtAccountId32> = match &error { | ||
ProtocolErr::ConnectionError { account_id, .. } | ||
| ProtocolErr::EncryptedConnection { account_id, .. } | ||
| ProtocolErr::BadSubscribeMessage { account_id, .. } | ||
| ProtocolErr::Subscribe { account_id, .. } => vec![account_id.clone()], | ||
|
||
ProtocolErr::Timeout { inactive_peers, .. } => inactive_peers.clone(), | ||
_ => vec![], | ||
}; | ||
|
||
// This is a non-reportable error, so we don't do any further processing with the error | ||
if peers_to_report.is_empty() { | ||
return Err(error.to_string()); | ||
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. as for the response here shouldn't this be Ok() as in the function here did not error out, everything progressed normally within the context of this function 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. I do agree with you - but if we change this to an We also don't do any extra processing with the |
||
} | ||
|
||
tracing::debug!("Reporting `{:?}` for `{}`", peers_to_report.clone(), error.to_string()); | ||
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. In the logs these (and basically all the other 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. +1 for being consistent everywhere. if i remember right subxt doesn't have the ss58 codec but sp-core does. At one point this was an issue as in some places we didn't have sp-core, but im pretty sure we sorted that and all our crates which would need to log something have it now. 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. Opened #1271. Could be a Friday activity for someone lol |
||
|
||
let mut failed_reports = Vec::new(); | ||
for peer in peers_to_report { | ||
let report_unstable_peer_tx = | ||
entropy::tx().staking_extension().report_unstable_peer(peer.clone()); | ||
|
||
if let Err(tx_error) = | ||
submit_transaction(api, rpc, signer, &report_unstable_peer_tx, None).await | ||
{ | ||
failed_reports.push(format!("{}", tx_error)); | ||
} | ||
} | ||
|
||
if failed_reports.is_empty() { | ||
Err(error.to_string()) | ||
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. same here |
||
} else { | ||
Err(format!( | ||
"Failed to report peers for `{}` due to `{}`)", | ||
error, | ||
failed_reports.join(", ") | ||
)) | ||
} | ||
} | ||
|
||
/// HTTP POST endpoint called by the off-chain worker (Propagation pallet) during the network | ||
/// jumpstart. | ||
/// | ||
|
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.
Why do we need to map the error here? Aren't we mapping it to what it already was? or am i missing something.
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.
There are two
unsubscribed_peers()
methods - the one onListenerState
(which is what's used) here returns aSubscribeErr
so we have to map it.The one on
AppState
returns aProtocolErr
but we don't have access to that here