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

Fix Informational Issues #385

Merged
merged 29 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0efabd1
SYT-03 | Unnecessary Variable
b-yap Aug 9, 2023
f9adcac
STL-03 | Lack of Validation for `destination_address` on `send_paymen…
b-yap Aug 9, 2023
3f58084
SRL-01 | Usage of Hard-coded Strings
b-yap Aug 10, 2023
5eec0fa
PAL-03 | Usage of Magic Numbers
b-yap Aug 11, 2023
9d65f64
PAL-02 | Unnecessary `Result<...>` Return Type
b-yap Aug 14, 2023
e609b4d
CLI-02 | Typos
b-yap Aug 14, 2023
7f0c221
9B2-03 | Unused Errors
b-yap Aug 15, 2023
707f706
code cleanup for PAL-03 | Usage of Magic Numbers
b-yap Aug 17, 2023
06a71e8
code cleanup for PAL-02 | Unnecessary Result<...> Return Type
b-yap Aug 17, 2023
4b371b0
partial of 9B2-04 | Logic Should be Moved To an Separate Function - R…
b-yap Aug 22, 2023
1883217
code cleanup
b-yap Aug 22, 2023
b8c5852
https://github.com/pendulum-chain/spacewalk/pull/385#discussion_r1301…
b-yap Aug 23, 2023
ee53122
https://github.com/pendulum-chain/spacewalk/pull/385#discussion_r1301…
b-yap Aug 23, 2023
5526e5d
Use vault vs user wallet in integration tests
ebma Aug 23, 2023
c77a9c0
fix Unable to get required collateral for amount issue
b-yap Aug 24, 2023
229a647
https://github.com/pendulum-chain/spacewalk/pull/385#discussion_r1303…
b-yap Aug 24, 2023
9479d25
removing the "last_known_cursor" and let the CI run it
b-yap Aug 25, 2023
ea2f489
https://github.com/pendulum-chain/spacewalk/actions/runs/5972713032/j…
b-yap Aug 25, 2023
a17d0b1
Fix `test_replace_succeeds` test case
ebma Aug 31, 2023
0b43167
fix test case due to changed `HorizonSubmissionError`
b-yap Sep 1, 2023
ba47b68
257 FIx Informational Issues - Logic Should be Moved To an Separate F…
b-yap Sep 1, 2023
415542f
257 Fix informational issues part 3 (#390)
b-yap Sep 5, 2023
f21b5df
from https://github.com/pendulum-chain/spacewalk/pull/392/files#diff-…
b-yap Sep 26, 2023
8e58b63
from https://github.com/pendulum-chain/spacewalk/pull/392/files#diff-…
b-yap Sep 27, 2023
7589b69
257 fix informational issues part 4 (#393)
b-yap Oct 11, 2023
c51d07b
https://github.com/pendulum-chain/spacewalk/actions/runs/6482197215/j…
b-yap Oct 12, 2023
b443b87
https://github.com/pendulum-chain/spacewalk/actions/runs/6491793772/j…
b-yap Oct 12, 2023
611cc5f
fix clippy issues
b-yap Oct 12, 2023
b57ca7b
cargo fmt --all
b-yap Oct 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/runtime/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ thiserror = "1.0.23"

subxt = "0.25.0"

sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" }
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false }
Binary file modified clients/runtime/metadata-standalone.scale
Binary file not shown.
2 changes: 2 additions & 0 deletions clients/runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use prometheus::Error as PrometheusError;
pub enum Error {
#[error("Could not get exchange rate info")]
ExchangeRateInfo,
#[error("The list is empty. At least one element is required.")]
FeedingEmptyList,
#[error("Could not get issue id")]
RequestIssueIDNotFound,
#[error("Could not get redeem id")]
Expand Down
5 changes: 4 additions & 1 deletion clients/runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl SpacewalkParachain {
connection_timeout,
)
.await?;
// let ws_client = new_websocket_client(url, None, None).await?;
Self::new(ws_client, signer, shutdown_tx).await
}

Expand Down Expand Up @@ -870,6 +869,10 @@ impl OraclePallet for SpacewalkParachain {
/// # Arguments
/// * `value` - the current exchange rate
async fn feed_values(&self, values: Vec<((Vec<u8>, Vec<u8>), FixedU128)>) -> Result<(), Error> {
if values.is_empty() {
return Err(Error::FeedingEmptyList)
}

use crate::metadata::runtime_types::dia_oracle::dia::CoinInfo;

let now = std::time::SystemTime::now();
Expand Down
2 changes: 1 addition & 1 deletion clients/runtime/src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock};

use tokio::sync::broadcast::error::{RecvError, SendError};

/// A wrapper arround a tokio broadcast channel that makes sure that
/// A wrapper around a tokio broadcast channel that makes sure that
/// listeners created after a shutdown signal has already been sent
/// also receive the shutdown signal.
#[derive(Clone)]
Expand Down
7 changes: 6 additions & 1 deletion clients/stellar-relay-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ tokio = { version = "1.0", features = [
] }

[features]
default = []
std = [
"substrate-stellar-sdk/std"
]
default = [
"std"
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"port": 11625
},
"node_info": {
"ledger_version": 19,
"overlay_version": 28,
"ledger_version": 20,
"overlay_version": 30,
"overlay_min_version": 27,
"version_str": "stellar-core 19.12.0.rc2 (2109a168a895349f87b502ae3d182380b378fa47)",
"version_str": "stellar-core 20.0.0.rc1 (ecb24df104c2453a00fa5097d2e879d7731b9596)",
"is_pub_net": false
},
"stellar_history_archive_urls": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"port": 11625
},
"node_info": {
"ledger_version": 19,
"overlay_version": 28,
"ledger_version": 20,
"overlay_version": 30,
"overlay_min_version": 27,
"version_str": "stellar-core 19.12.0.rc2 (2109a168a895349f87b502ae3d182380b378fa47)",
"version_str": "stellar-core 20.0.0.rc1 (ecb24df104c2453a00fa5097d2e879d7731b9596)",
"is_pub_net": false
},
"stellar_history_archive_urls": []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"connection_info": {
"address": "3.239.7.78",
"port": 11625
},
"node_info": {
"ledger_version": 20,
"overlay_version": 30,
"overlay_min_version": 27,
"version_str": "stellar-core 20.0.0.rc1 (ecb24df104c2453a00fa5097d2e879d7731b9596)",
"is_pub_net": false
},
"stellar_history_archive_urls": []
}
25 changes: 5 additions & 20 deletions clients/stellar-relay-lib/src/connection/helper.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use rand::Rng;
use sha2::{Digest, Sha256};
use std::time::{SystemTime, UNIX_EPOCH};
use substrate_stellar_sdk::{
types::{TransactionSet, Uint256},
SecretKey, XdrCodec,
};
use substrate_stellar_sdk::{types::Uint256, SecretKey};

/// a helpful macro to unwrap an `Ok` or return immediately.
/// a helpful macro to log an error (if it occurs) and return immediately.
macro_rules! log_error {
// expression, return value, extra log
($res:expr, $log:expr) => {
$res.map_err(|e| {
if let Err(e) = $res {
log::error!("{:?}: {e:?}", $log);
e
})?;
return
}
};
}

Expand Down Expand Up @@ -41,15 +38,3 @@ pub fn time_now() -> u64 {
u64::MAX
})
}

//todo: this has to be moved somewhere.
pub fn compute_non_generic_tx_set_content_hash(tx_set: &TransactionSet) -> [u8; 32] {
let mut hasher = Sha256::new();
hasher.update(tx_set.previous_ledger_hash);

tx_set.txes.get_vec().iter().for_each(|envlp| {
hasher.update(envlp.to_xdr());
});

hasher.finalize().as_slice().try_into().unwrap()
}
56 changes: 27 additions & 29 deletions clients/stellar-relay-lib/src/connection/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) async fn receiving_service(
actions_sender: mpsc::Sender<ConnectorActions>,
timeout_in_secs: u64,
retries: u8,
) -> Result<(), Error> {
) {
let mut retry = 0;
let mut retry_read = 0;
let mut proc_id = 0;
Expand All @@ -171,9 +171,8 @@ pub(crate) async fn receiving_service(
{
Ok(Ok(0)) => {
if retry_read >= retries {
return Err(Error::ReadFailed(format!(
"Failed to read messages from the stream. Received 0 size more than {retries} times"
)))
log::error!("proc_id: {proc_id}. Failed to read messages from the stream. Received 0 size more than {retries} times");
return
}
retry_read += 1;
},
Expand Down Expand Up @@ -213,18 +212,20 @@ pub(crate) async fn receiving_service(
retry = 0;
retry_read = 0;
// let's read the continuation number of bytes from the previous message.
read_unfinished_message(
&mut r_stream,
&actions_sender,
&mut lack_bytes_from_prev,
&mut proc_id,
&mut readbuf,
)
.await?;
log_error!(
read_unfinished_message(
&mut r_stream,
&actions_sender,
&mut lack_bytes_from_prev,
&mut proc_id,
&mut readbuf,
).await,
format!("proc_id:{proc_id}. Error occurred while reading unfinished stellar message")
);
},
Ok(Err(e)) => {
log::error!("proc_id: {proc_id}. Error occurred while reading the stream: {e:?}");
return Err(Error::ConnectionFailed(e.to_string()))
return
},
Err(elapsed) => {
log::error!(
Expand All @@ -233,9 +234,8 @@ pub(crate) async fn receiving_service(
);

if retry >= retries {
return Err(Error::ConnectionFailed(
"TIMED OUT reading for messages from the stream".to_string(),
))
log::error!("proc_id: {proc_id}. Exhausted maximum retries for reading messages from Stellar Node.");
return
}
retry += 1;
},
Expand Down Expand Up @@ -285,21 +285,19 @@ pub(crate) async fn connection_handler(
mut connector: Connector,
mut actions_receiver: mpsc::Receiver<ConnectorActions>,
mut w_stream: tcp::OwnedWriteHalf,
) -> Result<(), Error> {
) {
let mut timeout_counter = 0;
loop {
match timeout(Duration::from_secs(connector.timeout_in_secs), actions_receiver.recv()).await
{
Ok(Some(ConnectorActions::Disconnect)) => {
w_stream.shutdown().await.map_err(|e| {
log::error!("Failed to shutdown write half of stream: {:?}", e);

Error::ConnectionFailed("Failed to disconnect tcp stream".to_string())
})?;

log_error!(
w_stream.shutdown().await,
format!("Failed to shutdown write half of stream:")
);
drop(connector);
drop(actions_receiver);
return Ok(())
return
},

Ok(Some(action)) => {
Expand All @@ -317,11 +315,11 @@ pub(crate) async fn connection_handler(
Err(elapsed) => {
log::error!("Connection timed out after {} seconds", elapsed.to_string());
if timeout_counter >= connector.retries {
connector.send_to_user(StellarRelayMessage::Timeout).await?;
return Err(Error::ConnectionFailed(format!(
"Timed out! elapsed time: {:?}",
elapsed.to_string()
)))
log_error!(
connector.send_to_user(StellarRelayMessage::Timeout).await,
format!("Connection Timed out:")
);
return
}
timeout_counter += 1;
},
Expand Down
1 change: 1 addition & 0 deletions clients/stellar-relay-lib/src/connection/xdr_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) fn from_authenticated_message(message: &AuthenticatedMessage) -> Resu
message_to_bytes(message)
}

// todo: move to substrate-stellar-sdk
/// To easily convert any bytes to a Stellar type.
///
/// # Examples
Expand Down
Loading
Loading