Skip to content

Commit

Permalink
Merge branch 'main' into 383-add-rpc-function-to-query-exchange-rate-…
Browse files Browse the repository at this point in the history
…for-currency-to-oracle-pallet
  • Loading branch information
ebma authored Oct 12, 2023
2 parents d1431c0 + 8bb0d63 commit 1ba089f
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 1ba089f

Please sign in to comment.