Skip to content

Commit

Permalink
Fix Informational Issues (#385)
Browse files Browse the repository at this point in the history
* SYT-03 | Unnecessary Variable

* STL-03 | Lack of Validation for `destination_address` on `send_payment_to_address()`

* SRL-01 | Usage of Hard-coded Strings

* PAL-03 | Usage of Magic Numbers

* PAL-02 | Unnecessary `Result<...>` Return Type

* CLI-02 | Typos

* 9B2-03 | Unused Errors

* code cleanup for PAL-03 | Usage of Magic Numbers

* code cleanup for PAL-02 | Unnecessary Result<...> Return Type

* partial of 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring;

partial of STL-03 | Lack of Validation for `destination_address` on `send_payment_to_address()`

* code cleanup

* #385 (comment),
#385 (comment),
#385 (comment),
#385 (comment),
#385 (comment),
#385 (comment),
#385 (comment),
#385 (comment)
https://github.com/pendulum-chain/spacewalk/actions/runs/5936258794/job/16098086016?pr=385#step:10:33

* #385 (comment)

* Use vault vs user wallet in integration tests

* fix Unable to get required collateral for amount issue

* #385 (comment)

* removing the "last_known_cursor" and let the CI run it

* https://github.com/pendulum-chain/spacewalk/actions/runs/5972713032/job/16203688884#step:9:144

* Fix `test_replace_succeeds` test case

* fix test case due to changed `HorizonSubmissionError`

* 257 FIx Informational Issues - Logic Should be Moved To an Separate Function - Refactoring (#388)

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - partial

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - for System's fn run_service()

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - fix from previous commit

* remove stray log

* remove extra space

* https://github.com/pendulum-chain/spacewalk/pull/388/files#r1312732850,
#388 (comment)

* 257 Fix informational issues part 3 (#390)

* IML-01 | Same Behavior Defined For Different Conditions

* LI7-05 | Mismatch in Variable Name and Pallet Name

* 9B2-02 | Inconsistent Comments

* PRF-01 | Unhandled Error

* LIH-03 | Values Length Not Validated in `feed_values` Function

* CLI-01 | Confusing Function Naming

* CLI-03 | Incorrect Error Type Thrown partial

* CLI-03 | Incorrect Error Type Thrown

* #390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
https://github.com/pendulum-chain/spacewalk/actions/runs/6048709746/job/16414585252?pr=390#step:12:38

* https://github.com/pendulum-chain/spacewalk/actions/runs/6069946336/job/16465120232?pr=390#step:11:1573

* fix rustfmt error: https://github.com/pendulum-chain/spacewalk/actions/runs/6072497871/job/16472578544?pr=390

* from https://github.com/pendulum-chain/spacewalk/pull/392/files#diff-0f76594421d4493b3bba1c9ed7864cdab7148f19c5d3a18a9bcc9a174bb85aa8

* from https://github.com/pendulum-chain/spacewalk/pull/392/files#diff-0f76594421d4493b3bba1c9ed7864cdab7148f19c5d3a18a9bcc9a174bb85aa8

* 257 fix informational issues part 4 (#393)

* partial of 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring;

partial of STL-03 | Lack of Validation for `destination_address` on `send_payment_to_address()`

* 257 FIx Informational Issues - Logic Should be Moved To an Separate Function - Refactoring (#388)

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - partial

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - for System's fn run_service()

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - fix from previous commit

* remove stray log

* remove extra space

* https://github.com/pendulum-chain/spacewalk/pull/388/files#r1312732850,
#388 (comment)

* 257 Fix informational issues part 3 (#390)

* IML-01 | Same Behavior Defined For Different Conditions

* LI7-05 | Mismatch in Variable Name and Pallet Name

* 9B2-02 | Inconsistent Comments

* PRF-01 | Unhandled Error

* LIH-03 | Values Length Not Validated in `feed_values` Function

* CLI-01 | Confusing Function Naming

* CLI-03 | Incorrect Error Type Thrown partial

* CLI-03 | Incorrect Error Type Thrown

* #390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
https://github.com/pendulum-chain/spacewalk/actions/runs/6048709746/job/16414585252?pr=390#step:12:38

* https://github.com/pendulum-chain/spacewalk/actions/runs/6069946336/job/16465120232?pr=390#step:11:1573

* fix rustfmt error: https://github.com/pendulum-chain/spacewalk/actions/runs/6072497871/job/16472578544?pr=390

* CLI-01 | Confusing Function Naming

* #390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
https://github.com/pendulum-chain/spacewalk/actions/runs/6048709746/job/16414585252?pr=390#step:12:38

* STL-02 | Code Duplication

* SRC-01 | Unused Methods and Storage

* 9B2-05 | Commented Out Code (partial)

* LBC-03 | Inconsistent `match` Expression

* LIY-03 | Reduce Using `unwrap()` and `expect()` in Production Codebase

* TYL-01 | Confusing Variable Naming

* put back the removed dependencies

* https://github.com/pendulum-chain/spacewalk/actions/runs/6095148657/job/16538119439?pr=393#step:11:91

* https://github.com/pendulum-chain/spacewalk/actions/runs/6096401270/job/16541879632#step:11:93

* https://github.com/pendulum-chain/spacewalk/actions/runs/6096401270/job/16541879632#step:11:93

* https://github.com/pendulum-chain/spacewalk/actions/runs/6097368982/job/16544863469?pr=393#step:11:94

* https://github.com/pendulum-chain/spacewalk/actions/runs/6098205449/job/16547533143?pr=393#step:13:19

* #393 (comment),
partly #393 (review)

* #393 (comment)

* #393 (comment),
#393 (review) for vault

* #393 (comment)

* fix https://github.com/pendulum-chain/spacewalk/actions/runs/6263576242/job/17008273208?pr=393#step:12:894

* https://github.com/pendulum-chain/spacewalk/actions/runs/6272775696/job/17034964214?pr=393#step:12:434

* https://github.com/pendulum-chain/spacewalk/actions/runs/6275148901/job/17041998689?pr=393#step:12:587

* https://github.com/pendulum-chain/spacewalk/actions/runs/6276542346/job/17091576766#step:12:476

* #393 (comment)

* #393 (comment) and fix rebase

* 401 fix issues of connecting to stellar overlay network on testnet (#414)

* a 3rd try of #409

* cargo fmt and fix warnings in
https://github.com/pendulum-chain/spacewalk/actions/runs/6459806136/job/17536291785?pr=414

* update the `substrate-stellar-sdk` version

* #414 (comment),
#414 (comment),
#414 (comment),
#414 (comment)

* LIL-01 Dead Code in execute_replace()
LIT-03 Panic can happen between correlated storage modifications

* LIL-01 Dead Code in execute_replace() add back the comment

* https://github.com/pendulum-chain/spacewalk/actions/runs/6482197215/job/17610217546?pr=385#step:12:560

* https://github.com/pendulum-chain/spacewalk/actions/runs/6491793772/job/17629635299?pr=385#step:11:58

* fix clippy issues

* cargo fmt --all

---------

Co-authored-by: Marcel Ebert <[email protected]>
  • Loading branch information
b-yap and ebma authored Oct 12, 2023
1 parent 31df183 commit 8bb0d63
Show file tree
Hide file tree
Showing 95 changed files with 3,893 additions and 2,962 deletions.
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

0 comments on commit 8bb0d63

Please sign in to comment.