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

chore: upgrade error-stack version and remove deprecated dependencies #73

Merged
merged 8 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
185 changes: 74 additions & 111 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [

[workspace.dependencies]
connection-router = { version = "^0.1.0", path = "contracts/connection-router" }
error-stack = { version = "0.2.4", features = ["eyre"] }
error-stack = { version = "0.4.0", features = ["eyre"] }
events = { version = "^0.1.0", path = "packages/events" }
events-derive = { version = "^0.1.0", path = "packages/events-derive" }
axelar-wasm-std = { version = "^0.1.0", path = "packages/axelar-wasm-std" }
Expand All @@ -16,6 +16,7 @@ multisig = { version = "^0.1.0", path = "contracts/multisig" }
service-registry = { version = "^0.1.0", path = "contracts/service-registry" }
aggregate-verifier = { version = "^0.1.0", path = "contracts/aggregate-verifier" }
gateway = { version = "^0.1.0", path = "contracts/gateway" }
report = { version = "^0.1.0", path = "packages/report" }

[profile.release]
opt-level = 3
Expand Down
1 change: 1 addition & 0 deletions ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ k256 = { version = "0.13.1", features = ["ecdsa"] }
mockall = "0.11.3"
multisig = { workspace = true }
prost = "0.11.9"
report = { workspace = true }
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.89"
serde_with = "3.2.0"
Expand Down
22 changes: 8 additions & 14 deletions ampd/src/broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use cosmrs::tendermint::chain::Id;
use cosmrs::tx::{BodyBuilder, Fee, SignDoc, SignerInfo};
use cosmrs::{Coin, Gas};
use derive_builder::Builder;
use error_stack::{FutureExt, IntoReport, IntoReportCompat, Report, Result, ResultExt};
use error_stack::{FutureExt, Report, Result, ResultExt};
use futures::TryFutureExt;
use mockall::automock;
use report::ResultCompatExt;
use serde::Deserialize;
use thiserror::Error;
use tonic::Status;
Expand Down Expand Up @@ -159,8 +160,7 @@ where
response
.gas_info
.map(|info| info.gas_used)
.ok_or(Error::GasEstimation)
.into_report()
.ok_or(Error::GasEstimation.into())
})
.await
}
Expand All @@ -173,14 +173,12 @@ where
.msgs(msgs)
.finish()
.into_bytes()
.into_report()
.change_context(Error::TxMarshaling)?;

let auth_info_bytes =
SignerInfo::single_direct(Some(self.priv_key.public_key()), self.acc_sequence)
.auth_info(zero_fee())
.into_bytes()
.into_report()
.change_context(Error::TxMarshaling)?;

let raw = TxRaw {
Expand All @@ -190,9 +188,7 @@ where
signatures: vec![vec![0; 64]],
};

raw.to_bytes()
.into_report()
.change_context(Error::TxMarshaling)
raw.to_bytes().change_context(Error::TxMarshaling)
}

pub fn create_tx<M>(&self, msgs: M, fee: Fee) -> Result<BroadcastTxRequest, Error>
Expand All @@ -211,7 +207,6 @@ where
tx_bytes: tx,
mode: BroadcastMode::Sync as i32,
})
.into_report()
.change_context(Error::TxMarshaling)
}

Expand Down Expand Up @@ -241,7 +236,7 @@ where

return Ok(());
}
ConfirmationResult::Critical(err) => return Err(err).into_report(),
ConfirmationResult::Critical(err) => return Err(err.into()),
ConfirmationResult::Retriable(err) => {
if let Err(result) = result.as_mut() {
result.extend_one(err);
Expand Down Expand Up @@ -284,7 +279,6 @@ mod tests {
use cosmos_sdk_proto::cosmos::tx::v1beta1::{GetTxResponse, SimulateResponse};
use cosmos_sdk_proto::Any;
use cosmrs::{bank::MsgSend, tx::Msg, AccountId};
use error_stack::IntoReport;
use tokio::test;
use tonic::Status;

Expand All @@ -298,7 +292,7 @@ mod tests {
let mut client = MockBroadcastClient::new();
client
.expect_simulate()
.returning(|_| Err(Status::unavailable("unavailable service")).into_report());
.returning(|_| Err(Status::unavailable("unavailable service").into()));
let signer = MockEcdsaClient::new();

let priv_key = ECDSASigningKey::random();
Expand Down Expand Up @@ -375,7 +369,7 @@ mod tests {

client
.expect_broadcast_tx()
.returning(|_| Err(Status::aborted("failed")).into_report());
.returning(|_| Err(Status::aborted("failed").into()));
let signer = MockEcdsaClient::new();

let priv_key = ECDSASigningKey::random();
Expand Down Expand Up @@ -422,7 +416,7 @@ mod tests {
client
.expect_get_tx()
.times((Config::default().tx_fetch_max_retries + 1) as usize)
.returning(|_| Err(Status::deadline_exceeded("time out")).into_report());
.returning(|_| Err(Status::deadline_exceeded("time out").into()));
let signer = MockEcdsaClient::new();

let priv_key = ECDSASigningKey::random();
Expand Down
14 changes: 7 additions & 7 deletions ampd/src/broadcaster/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::broadcaster::clients::AccountQueryClient;
use crate::types::TMAddress;
use cosmos_sdk_proto::cosmos::auth::v1beta1::{BaseAccount, QueryAccountRequest};
use cosmos_sdk_proto::traits::Message;
use error_stack::{FutureExt, IntoReport, Result, ResultExt};
use error_stack::{FutureExt, Result, ResultExt};
use thiserror::Error;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -30,13 +30,14 @@ where

let account = response
.account
.ok_or_else(|| Error::AccountNotFound {
address: address.clone(),
.ok_or_else(|| {
Error::AccountNotFound {
address: address.clone(),
}
.into()
})
.into_report()
cgorenflo marked this conversation as resolved.
Show resolved Hide resolved
.and_then(|account| {
BaseAccount::decode(&account.value[..])
.into_report()
.change_context(Error::MalformedResponse)
.attach_printable_lazy(|| format!("{{ value = {:?} }}", account.value))
})?;
Expand All @@ -55,7 +56,6 @@ mod tests {
use cosmos_sdk_proto::cosmos::auth::v1beta1::QueryAccountResponse;
use cosmos_sdk_proto::traits::MessageExt;
use cosmrs::Any;
use error_stack::IntoReport;
use tokio::test;
use tonic::Status;

Expand All @@ -64,7 +64,7 @@ mod tests {
let mut client = MockAccountQueryClient::new();
client
.expect_account()
.returning(|_| Err(Status::aborted("aborted")).into_report());
.returning(|_| Err(Status::aborted("aborted").into()));

let address = ECDSASigningKey::random().address();

Expand Down
10 changes: 5 additions & 5 deletions ampd/src/broadcaster/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmos_sdk_proto::cosmos::tx::v1beta1::service_client::ServiceClient;
use cosmos_sdk_proto::cosmos::tx::v1beta1::{
BroadcastTxRequest, GetTxRequest, GetTxResponse, SimulateRequest, SimulateResponse,
};
use error_stack::{IntoReport, Result};
use error_stack::{Report, Result};
use mockall::automock;
use tonic::transport::Channel;

Expand All @@ -31,21 +31,21 @@ impl BroadcastClient for ServiceClient<Channel> {
.tx_response
.ok_or_else(|| Status::not_found("tx not found"))
})
.into_report()
.map_err(Report::from)
}

async fn simulate(&mut self, request: SimulateRequest) -> Result<SimulateResponse, Status> {
self.simulate(request)
.await
.map(Response::into_inner)
.into_report()
.map_err(Report::from)
}

async fn get_tx(&mut self, request: GetTxRequest) -> Result<GetTxResponse, Status> {
self.get_tx(request)
.await
.map(Response::into_inner)
.into_report()
.map_err(Report::from)
}
}

Expand All @@ -67,6 +67,6 @@ impl AccountQueryClient for QueryClient<Channel> {
self.account(request)
.await
.map(Response::into_inner)
.into_report()
.map_err(Report::from)
}
}
11 changes: 4 additions & 7 deletions ampd/src/broadcaster/dec_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::str::FromStr;
use std::{fmt, ops};

use cosmrs::proto;
use error_stack::{ensure, IntoReport, IntoReportCompat, Report, Result, ResultExt};
use error_stack::{ensure, Report, Result, ResultExt};
use report::ResultCompatExt;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::error;
Expand Down Expand Up @@ -93,10 +94,7 @@ impl FromStr for FiniteAmount {
type Err = Report<Error>;

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
let f = s
.parse::<f64>()
.into_report()
.change_context(ParsingFailed)?;
let f = s.parse::<f64>().change_context(ParsingFailed)?;
f.try_into()
}
}
Expand Down Expand Up @@ -139,8 +137,7 @@ impl FromStr for Denom {
type Err = Report<Error>;

fn from_str(denom: &str) -> std::result::Result<Self, Self::Err> {
let denom: cosmrs::Denom =
IntoReportCompat::into_report(denom.parse()).change_context(ParsingFailed)?;
let denom: cosmrs::Denom = ResultCompatExt::change_context(denom.parse(), ParsingFailed)?;
denom.try_into()
}
}
Expand Down
25 changes: 10 additions & 15 deletions ampd/src/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::pin::Pin;
use std::vec;

use async_trait::async_trait;
use error_stack::{Context, IntoReport, Result, ResultExt};
use error_stack::{Context, Result, ResultExt};
use events::Event;
use futures::{future::try_join_all, StreamExt};
use thiserror::Error;
Expand Down Expand Up @@ -41,6 +41,7 @@ fn consume_events<H, S, E>(event_stream: S, handler: H, token: CancellationToken
where
H: EventHandler + Send + Sync + 'static,
S: Stream<Item = Result<Event, E>> + Send + 'static,
E: Context,
{
let task = async move {
let mut event_stream = Box::pin(event_stream);
Expand Down Expand Up @@ -80,6 +81,7 @@ impl EventProcessor {
where
H: EventHandler + Send + Sync + 'static,
S: Stream<Item = Result<Event, E>> + Send + 'static,
E: Context,
{
self.tasks
.push(consume_events(event_stream, handler, self.token.child_token()).into());
Expand All @@ -91,7 +93,6 @@ impl EventProcessor {

try_join_all(handles)
.await
.into_report()
.change_context(EventProcessorError::EventHandlerError)?
.into_iter()
.find(Result::is_err)
Expand All @@ -103,12 +104,12 @@ impl EventProcessor {
mod tests {
use crate::event_processor::{EventHandler, EventProcessor};
use async_trait::async_trait;
use error_stack::{IntoReport, Result};
use error_stack::{Report, Result};
use futures::TryStreamExt;
use mockall::mock;
use thiserror::Error;
use tokio::{self, sync::broadcast};
use tokio_stream::wrappers::BroadcastStream;
use tokio_stream::StreamExt;
use tokio_util::sync::CancellationToken;

#[tokio::test]
Expand All @@ -130,10 +131,7 @@ mod tests {
}
});

processor.add_handler(
handler,
BroadcastStream::new(rx).map(IntoReport::into_report),
);
processor.add_handler(handler, BroadcastStream::new(rx).map_err(Report::from));
assert!(processor.run().await.is_ok());
}

Expand All @@ -146,17 +144,14 @@ mod tests {
let mut handler = MockEventHandler::new();
handler
.expect_handle()
.returning(|_| Err(EventHandlerError::Unknown).into_report())
.returning(|_| Err(EventHandlerError::Unknown.into()))
.once();

tokio::spawn(async move {
assert!(tx.send(events::Event::BlockEnd((10_u32).into())).is_ok());
});

processor.add_handler(
handler,
BroadcastStream::new(rx).map(IntoReport::into_report),
);
processor.add_handler(handler, BroadcastStream::new(rx).map_err(Report::from));
assert!(processor.run().await.is_err());
}

Expand All @@ -166,8 +161,8 @@ mod tests {
let (tx, rx) = broadcast::channel::<events::Event>(event_count);
let token = CancellationToken::new();
let mut processor = EventProcessor::new(token.child_token());
let stream = BroadcastStream::new(rx).map(IntoReport::into_report);
let another_stream = BroadcastStream::new(tx.subscribe()).map(IntoReport::into_report);
let stream = BroadcastStream::new(rx).map_err(Report::from);
let another_stream = BroadcastStream::new(tx.subscribe()).map_err(Report::from);

let mut handler = MockEventHandler::new();
handler
Expand Down
12 changes: 5 additions & 7 deletions ampd/src/event_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::convert::TryInto;
use std::iter;
use std::time::Duration;

use error_stack::{FutureExt, Result};
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use error_stack::{FutureExt, Report, Result};
use futures::TryStreamExt;
use tendermint::abci;
use tendermint::block;
use thiserror::Error;
Expand Down Expand Up @@ -53,7 +54,7 @@ impl<T: TmClient + Sync> EventSub<T> {
}

pub fn sub(&mut self) -> impl Stream<Item = Result<Event, BroadcastStreamRecvError>> {
BroadcastStream::new(self.tx.subscribe()).map(IntoReport::into_report)
BroadcastStream::new(self.tx.subscribe()).map_err(Report::from)
}

pub async fn run(mut self) -> Result<(), EventSubError> {
Expand Down Expand Up @@ -123,10 +124,7 @@ impl<T: TmClient + Sync> EventSub<T> {
.chain(iter::once(Event::BlockEnd(height)));

for event in events {
self.tx
.send(event)
.into_report()
.change_context(EventSubError::Publish)?;
self.tx.send(event).change_context(EventSubError::Publish)?;
}

Ok(())
Expand Down
Loading