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(cosmos): fix tx broadcasting error #2238

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
162 changes: 74 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cfg-if = "1.0"
chain = { path = "../mm2_bitcoin/chain" }
chrono = { version = "0.4.23", "features" = ["serde"] }
common = { path = "../common" }
cosmrs = { version = "0.14.0", default-features = false }
cosmrs = { version = "0.15", default-features = false }
crossbeam = "0.8"
crypto = { path = "../crypto" }
db_common = { path = "../db_common" }
Expand Down Expand Up @@ -86,7 +86,7 @@ mocktopus = "0.8.0"
num-traits = "0.2"
parking_lot = { version = "0.12.0", features = ["nightly"] }
primitives = { path = "../mm2_bitcoin/primitives" }
prost = "0.11"
prost = "0.12"
protobuf = "2.20"
proxy_signature = { path = "../proxy_signature" }
rand = { version = "0.7", features = ["std", "small_rng"] }
Expand All @@ -113,7 +113,7 @@ sha2 = "0.10"
sha3 = "0.9"
utxo_signer = { path = "utxo_signer" }
# using the same version as cosmrs
tendermint-rpc = { version = "0.32.0", default-features = false }
tendermint-rpc = { version = "0.34", default-features = false }
tokio-tungstenite-wasm = { git = "https://github.com/KomodoPlatform/tokio-tungstenite-wasm", rev = "d20abdb", features = ["rustls-tls-native-roots"]}
url = { version = "2.2.2", features = ["serde"] }
uuid = { version = "1.2.2", features = ["fast-rng", "serde", "v4"] }
Expand Down Expand Up @@ -145,7 +145,7 @@ mm2_db = { path = "../mm2_db" }
mm2_metamask = { path = "../mm2_metamask" }
mm2_test_helpers = { path = "../mm2_test_helpers" }
time = { version = "0.3.20", features = ["wasm-bindgen"] }
tonic = { version = "0.9", default-features = false, features = ["prost", "codegen", "gzip"] }
tonic = { version = "0.10", default-features = false, features = ["prost", "codegen", "gzip"] }
tower-service = "0.3"
wasm-bindgen = "0.2.86"
wasm-bindgen-futures = { version = "0.4.1" }
Expand All @@ -170,7 +170,7 @@ rustls = { version = "0.21", features = ["dangerous_configuration"] }
secp256k1v24 = { version = "0.24", package = "secp256k1" }
tokio = { version = "1.20" }
tokio-rustls = { version = "0.24" }
tonic = { version = "0.9", features = ["tls", "tls-webpki-roots", "gzip"] }
tonic = { version = "0.10", features = ["tls", "tls-webpki-roots", "gzip"] }
webpki-roots = { version = "0.25" }
zcash_client_sqlite = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1" }
zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.4.1", default-features = false, features = ["local-prover", "multicore"] }
Expand All @@ -185,5 +185,5 @@ mm2_test_helpers = { path = "../mm2_test_helpers" }
wagyu-zcash-parameters = { version = "0.2" }

[build-dependencies]
prost-build = { version = "0.11", default-features = false }
tonic-build = { version = "0.9", default-features = false, features = ["prost"] }
prost-build = { version = "0.12", default-features = false }
tonic-build = { version = "0.10", default-features = false, features = ["prost"] }
15 changes: 7 additions & 8 deletions mm2src/coins/tendermint/htlc/iris/htlc.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use super::htlc_proto::{IrisClaimHtlcProto, IrisCreateHtlcProto};

use cosmrs::proto::traits::TypeUrl;
use cosmrs::proto::traits::Name;
use cosmrs::{tx::Msg, AccountId, Coin, ErrorReport};
use std::convert::TryFrom;

pub(crate) const IRIS_CREATE_HTLC_TYPE_URL: &str = "/irismod.htlc.MsgCreateHTLC";
pub(crate) const IRIS_CLAIM_HTLC_TYPE_URL: &str = "/irismod.htlc.MsgClaimHTLC";

#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct IrisCreateHtlcMsg {
/// Sender's address.
Expand Down Expand Up @@ -87,8 +84,9 @@ impl From<&IrisCreateHtlcMsg> for IrisCreateHtlcProto {
}
}

impl TypeUrl for IrisCreateHtlcProto {
const TYPE_URL: &'static str = IRIS_CREATE_HTLC_TYPE_URL;
impl Name for IrisCreateHtlcProto {
const NAME: &'static str = "MsgCreateHTLC";
const PACKAGE: &'static str = "irismod.htlc";
}

#[derive(Clone)]
Expand Down Expand Up @@ -141,6 +139,7 @@ impl From<&IrisClaimHtlcMsg> for IrisClaimHtlcProto {
}
}

impl TypeUrl for IrisClaimHtlcProto {
const TYPE_URL: &'static str = IRIS_CLAIM_HTLC_TYPE_URL;
impl Name for IrisClaimHtlcProto {
const NAME: &'static str = "MsgClaimHTLC";
const PACKAGE: &'static str = "irismod.htlc";
}
15 changes: 7 additions & 8 deletions mm2src/coins/tendermint/htlc/nucleus/htlc.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use super::htlc_proto::{NucleusClaimHtlcProto, NucleusCreateHtlcProto};

use cosmrs::proto::traits::TypeUrl;
use cosmrs::proto::traits::Name;
use cosmrs::{tx::Msg, AccountId, Coin, ErrorReport};
use std::convert::TryFrom;

pub(crate) const NUCLEUS_CREATE_HTLC_TYPE_URL: &str = "/nucleus.htlc.MsgCreateHTLC";
pub(crate) const NUCLEUS_CLAIM_HTLC_TYPE_URL: &str = "/nucleus.htlc.MsgClaimHTLC";

#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct NucleusCreateHtlcMsg {
/// Sender's address.
Expand Down Expand Up @@ -72,8 +69,9 @@ impl From<&NucleusCreateHtlcMsg> for NucleusCreateHtlcProto {
}
}

impl TypeUrl for NucleusCreateHtlcProto {
const TYPE_URL: &'static str = NUCLEUS_CREATE_HTLC_TYPE_URL;
impl Name for NucleusCreateHtlcProto {
const NAME: &'static str = "MsgCreateHTLC";
const PACKAGE: &'static str = "nucleus.htlc";
}

#[derive(Clone)]
Expand Down Expand Up @@ -126,6 +124,7 @@ impl From<&NucleusClaimHtlcMsg> for NucleusClaimHtlcProto {
}
}

impl TypeUrl for NucleusClaimHtlcProto {
const TYPE_URL: &'static str = NUCLEUS_CLAIM_HTLC_TYPE_URL;
impl Name for NucleusClaimHtlcProto {
const NAME: &'static str = "MsgClaimHTLC";
const PACKAGE: &'static str = "nucleus.htlc";
}
1 change: 0 additions & 1 deletion mm2src/coins/tendermint/ibc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod ibc_proto;
pub(crate) mod transfer_v1;

pub(crate) const IBC_TRANSFER_TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
pub(crate) const IBC_OUT_SOURCE_PORT: &str = "transfer";
pub(crate) const IBC_OUT_TIMEOUT_IN_NANOS: u64 = 60000000000 * 15; // 15 minutes
pub(crate) const IBC_GAS_LIMIT_DEFAULT: u64 = 150_000;
8 changes: 4 additions & 4 deletions mm2src/coins/tendermint/ibc/transfer_v1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{ibc_proto::IBCTransferV1Proto, IBC_OUT_SOURCE_PORT, IBC_OUT_TIMEOUT_IN_NANOS};
use crate::tendermint::ibc::IBC_TRANSFER_TYPE_URL;
use cosmrs::proto::traits::TypeUrl;
use cosmrs::proto::traits::Name;
use cosmrs::{tx::Msg, AccountId, Coin, ErrorReport};
use std::convert::TryFrom;

Expand Down Expand Up @@ -99,6 +98,7 @@ impl From<&MsgTransfer> for IBCTransferV1Proto {
}
}

impl TypeUrl for IBCTransferV1Proto {
const TYPE_URL: &'static str = IBC_TRANSFER_TYPE_URL;
impl Name for IBCTransferV1Proto {
const NAME: &'static str = "MsgTransfer";
const PACKAGE: &'static str = "ibc.applications.transfer.v1";
}
8 changes: 4 additions & 4 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2531,22 +2531,22 @@ impl MarketCoinOps for TendermintCoin {
let broadcast_res = try_s!(try_s!(coin.rpc_client().await).broadcast_tx_commit(tx_bytes).await);

if broadcast_res.check_tx.log.contains(ACCOUNT_SEQUENCE_ERR)
|| broadcast_res.deliver_tx.log.contains(ACCOUNT_SEQUENCE_ERR)
|| broadcast_res.tx_result.log.contains(ACCOUNT_SEQUENCE_ERR)
{
return ERR!(
"{}. check_tx log: {}, deliver_tx log: {}",
ACCOUNT_SEQUENCE_ERR,
broadcast_res.check_tx.log,
broadcast_res.deliver_tx.log
broadcast_res.tx_result.log
);
}

if !broadcast_res.check_tx.code.is_ok() {
return ERR!("Tx check failed {:?}", broadcast_res.check_tx);
}

if !broadcast_res.deliver_tx.code.is_ok() {
return ERR!("Tx deliver failed {:?}", broadcast_res.deliver_tx);
if !broadcast_res.tx_result.code.is_ok() {
return ERR!("Tx deliver failed {:?}", broadcast_res.tx_result);
}
Ok(broadcast_res.hash.to_string())
};
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/utxo/pb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetMempoolInfoRequest {}
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ num-traits = "0.2"
parity-util-mem = "0.11"
parking_lot = { version = "0.12.0", features = ["nightly"] }
primitives = { path = "../mm2_bitcoin/primitives" }
prost = "0.11"
prost = "0.12"
rand = { version = "0.7", features = ["std", "small_rng"] }
rand6 = { version = "0.6", package = "rand" }
rmp-serde = "0.14.3"
Expand Down Expand Up @@ -136,5 +136,5 @@ url = { version = "2.2.2", features = ["serde"] }
[build-dependencies]
chrono = "0.4"
gstuff = { version = "0.7", features = ["nightly"] }
prost-build = { version = "0.11", default-features = false }
prost-build = { version = "0.12", default-features = false }
regex = "1"
1 change: 1 addition & 0 deletions mm2src/mm2_main/src/lp_swap/komodefi.swap_v2.pb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SignedMessage {
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mm2_err_handle = { path = "../mm2_err_handle" }
mm2_event_stream = { path = "../mm2_event_stream", optional = true }
mm2-libp2p = { path = "../mm2_p2p", package = "mm2_p2p", optional = true }
parking_lot = { version = "0.12.0", features = ["nightly"], optional = true }
prost = "0.11"
prost = "0.12"
rand = { version = "0.7", features = ["std", "small_rng", "wasm-bindgen"] }
serde = "1"
serde_json = { version = "1", features = ["preserve_order", "raw_value"] }
Expand All @@ -41,7 +41,7 @@ http-body = "0.4"
httparse = "1.8.0"
js-sys = "0.3.27"
pin-project = "1.1.2"
tonic = { version = "0.9", default-features = false, features = ["prost", "codegen"] }
tonic = { version = "0.10", default-features = false, features = ["prost", "codegen"] }
tower-service = "0.3"
wasm-bindgen = "0.2.86"
wasm-bindgen-test = { version = "0.3.2" }
Expand Down
2 changes: 1 addition & 1 deletion mm2src/trezor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ derive_more = "0.99"
futures = { version = "0.3", package = "futures", features = ["compat", "async-await"] }
hw_common = { path = "../hw_common" }
mm2_err_handle = { path = "../mm2_err_handle" }
prost = "0.11"
prost = "0.12"
rand = { version = "0.7", features = ["std", "wasm-bindgen"] }
rpc_task = { path = "../rpc_task" }
serde = "1.0"
Expand Down
4 changes: 3 additions & 1 deletion mm2src/trezor/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::convert::TryFrom;

use crate::proto::messages::MessageType;
use crate::proto::messages_common::{failure::FailureType, Failure};
use crate::user_interaction::TrezorUserInteraction;
Expand Down Expand Up @@ -57,7 +59,7 @@ pub enum OperationFailure {

impl From<Failure> for OperationFailure {
fn from(failure: Failure) -> Self {
match failure.code.and_then(FailureType::from_i32) {
match failure.code.and_then(|t| FailureType::try_from(t).ok()) {
Some(FailureType::FailurePinInvalid) | Some(FailureType::FailurePinMismatch) => {
OperationFailure::InvalidPin
},
Expand Down
9 changes: 7 additions & 2 deletions mm2src/trezor/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{TrezorError, TrezorResult};
use async_trait::async_trait;
use mm2_err_handle::prelude::*;
use rpc_task::RpcTaskError;
use std::convert::TryFrom;
use std::fmt;
use std::sync::Arc;

Expand Down Expand Up @@ -150,7 +151,10 @@ impl<'a, 'b, T> fmt::Debug for ButtonRequest<'a, 'b, T> {

impl<'a, 'b, T: 'static> ButtonRequest<'a, 'b, T> {
/// The type of button request.
pub fn request_type(&self) -> Option<ButtonRequestType> { self.message.code.and_then(ButtonRequestType::from_i32) }
#[inline(always)]
pub fn request_type(&self) -> Option<ButtonRequestType> {
self.message.code.and_then(|t| ButtonRequestType::try_from(t).ok())
}

/// Ack the request and get the next message from the device.
pub async fn ack(self) -> TrezorResult<TrezorResponse<'a, 'b, T>> {
Expand All @@ -174,8 +178,9 @@ impl<'a, 'b, T> fmt::Debug for PinMatrixRequest<'a, 'b, T> {

impl<'a, 'b, T: 'static> PinMatrixRequest<'a, 'b, T> {
/// The type of PIN matrix request.
#[inline(always)]
pub fn request_type(&self) -> Option<PinMatrixRequestType> {
self.message.r#type.and_then(PinMatrixRequestType::from_i32)
self.message.r#type.and_then(|t| PinMatrixRequestType::try_from(t).ok())
}

/// Ack the request with a PIN and get the next message from the device.
Expand Down
9 changes: 6 additions & 3 deletions mm2src/trezor/src/transport/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! This file is inspired by https://github.com/tezedge/tezedge-client/blob/master/trezor_api/src/transport/protocol.rs

use std::convert::TryFrom;

use crate::proto::messages::MessageType;
use crate::proto::ProtoMessage;
use crate::{TrezorError, TrezorResult};
Expand Down Expand Up @@ -85,9 +87,10 @@ impl<L: Link + Send> Protocol for ProtocolV1<L> {
);
return MmError::err(TrezorError::ProtocolError(error));
}
let message_type_id = BigEndian::read_u16(&chunk[3..5]) as u32;
let message_type = MessageType::from_i32(message_type_id as i32)
.or_mm_err(|| TrezorError::ProtocolError(format!("Invalid message type: {}", message_type_id)))?;
let message_type_id = BigEndian::read_u16(&chunk[3..5]) as i32;
let message_type = MessageType::try_from(message_type_id).map_err(|e| {
TrezorError::ProtocolError(format!("Invalid message type: {}, Error: {}", message_type_id, e))
})?;
let data_length = BigEndian::read_u32(&chunk[5..9]) as usize;
let mut data: Vec<u8> = chunk[9..].into();

Expand Down
6 changes: 5 additions & 1 deletion mm2src/trezor/src/utxo/sign_utxo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::convert::TryFrom;

use crate::proto::messages_bitcoin as proto_bitcoin;
use crate::result_handler::ResultHandler;
use crate::utxo::unsigned_tx::UnsignedUtxoTx;
Expand Down Expand Up @@ -61,7 +63,9 @@ impl<'a> TrezorSession<'a> {
loop {
extract_serialized_data(&tx_request, &mut result)?;

let request_type = tx_request.request_type.and_then(ProtoTxRequestType::from_i32);
let request_type = tx_request
.request_type
.and_then(|t| ProtoTxRequestType::try_from(t).ok());
let request_type = match request_type {
Some(ProtoTxRequestType::Txfinished) => return Ok(result),
Some(req_type) => req_type,
Expand Down
Loading