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 all 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: 7 additions & 15 deletions ampd/src/broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cosmrs::tendermint::chain::Id;
use cosmrs::tx::Fee;
use cosmrs::{Coin, Gas};
use derive_builder::Builder;
use error_stack::{FutureExt, IntoReport, Report, Result, ResultExt};
use error_stack::{FutureExt, Report, Result, ResultExt};
use futures::TryFutureExt;
use k256::sha2::{Digest, Sha256};
use mockall::automock;
Expand Down Expand Up @@ -107,7 +107,6 @@ where
.pub_key(self.pub_key.1)
.acc_sequence(self.acc_sequence)
.build()
.into_report()
.change_context(Error::TxBuilding)?
.sign_with(&self.config.chain_id, self.acc_number, |sign_doc| {
let mut hasher = Sha256::new();
Expand All @@ -126,10 +125,7 @@ where
.change_context(Error::TxBuilding)?;

let tx = BroadcastTxRequest {
tx_bytes: tx
.to_bytes()
.into_report()
.change_context(Error::TxBuilding)?,
tx_bytes: tx.to_bytes().change_context(Error::TxBuilding)?,
mode: BroadcastMode::Sync as i32,
};

Expand Down Expand Up @@ -161,13 +157,11 @@ where
.pub_key(self.pub_key.1)
.acc_sequence(self.acc_sequence)
.build()
.into_report()
.change_context(Error::TxBuilding)?
.with_dummy_sig()
.await
.change_context(Error::TxBuilding)?
.to_bytes()
.into_report()
.change_context(Error::TxBuilding)?;

self.estimate_gas(sim_tx).await.map(|gas| {
Expand Down Expand Up @@ -197,8 +191,7 @@ where
response
.gas_info
.map(|info| info.gas_used)
.ok_or(Error::GasEstimation)
.into_report()
.ok_or(Error::GasEstimation.into())
})
.await
}
Expand Down Expand Up @@ -229,7 +222,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 @@ -273,7 +266,6 @@ mod tests {
use cosmos_sdk_proto::Any;
use cosmrs::{bank::MsgSend, tx::Msg, AccountId};
use ecdsa::SigningKey;
use error_stack::IntoReport;
use rand::rngs::OsRng;
use tokio::test;
use tonic::Status;
Expand All @@ -292,7 +284,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();

Expand Down Expand Up @@ -370,7 +362,7 @@ mod tests {
});
client
.expect_broadcast_tx()
.returning(|_| Err(Status::aborted("failed")).into_report());
.returning(|_| Err(Status::aborted("failed").into()));

let mut signer = MockEcdsaClient::new();
signer
Expand Down Expand Up @@ -429,7 +421,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 mut signer = MockEcdsaClient::new();
signer
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 @@ -51,7 +52,6 @@ mod tests {
use cosmos_sdk_proto::traits::MessageExt;
use cosmrs::Any;
use ecdsa::SigningKey;
use error_stack::IntoReport;
use rand::rngs::OsRng;
use tokio::test;
use tonic::Status;
Expand All @@ -67,7 +67,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 = rand_tm_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
17 changes: 9 additions & 8 deletions ampd/src/broadcaster/tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::fmt::Debug;
use std::future::Future;

use cosmrs::tendermint::chain::Id;
use cosmrs::{
Expand All @@ -7,8 +8,8 @@ use cosmrs::{
Any, Coin,
};
use derive_builder::Builder;
use error_stack::{IntoReport, IntoReportCompat, Result, ResultExt};
use futures::Future;
use error_stack::{Context, Result, ResultExt};
use report::ResultCompatExt;
use thiserror::Error;

use crate::types::PublicKey;
Expand Down Expand Up @@ -63,19 +64,18 @@ where
where
F: Fn(Vec<u8>) -> Fut,
Fut: Future<Output = Result<Vec<u8>, Err>>,
Err: Context,
{
let body = BodyBuilder::new().msgs(self.msgs).finish();
let auth_info =
SignerInfo::single_direct(Some(self.pub_key), self.acc_sequence).auth_info(self.fee);
let sign_doc = SignDoc::new(&body, &auth_info, chain_id, acc_number)
.into_report()
.change_context(Error::Marshaling)?;

let signature = sign(
sign_doc
.clone()
.into_bytes()
.into_report()
.change_context(Error::Marshaling)?,
)
.await
Expand All @@ -94,7 +94,7 @@ where
.parse()
.expect("the dummy chain id must be valid"),
DUMMY_ACC_NUMBER,
|_| async { std::result::Result::<_, Error>::Ok(vec![0; 64]).into_report() },
|_| async { Result::<_, Error>::Ok(vec![0; 64]) },
)
.await
}
Expand All @@ -112,14 +112,15 @@ mod tests {
tx::{BodyBuilder, Fee, Msg, SignDoc, SignerInfo},
AccountId, Coin,
};
use error_stack::IntoReport;
use error_stack::Result;
use k256::ecdsa;
use k256::sha2::{Digest, Sha256};
use tokio::test;

use super::{Error, TxBuilder, DUMMY_CHAIN_ID};
use crate::types::PublicKey;

use super::{Error, TxBuilder, DUMMY_CHAIN_ID};

#[test]
async fn sign_with_should_produce_the_correct_tx() {
let priv_key = ecdsa::SigningKey::random(&mut OsRng);
Expand All @@ -145,7 +146,7 @@ mod tests {
let priv_key = ecdsa::SigningKey::from_bytes(&priv_key_bytes).unwrap();
let (signature, _) = priv_key.sign_prehash_recoverable(&hash.to_vec()).unwrap();

std::result::Result::<_, Error>::Ok(signature.to_vec()).into_report()
Result::<_, Error>::Ok(signature.to_vec())
})
.await
.unwrap();
Expand Down
Loading
Loading