Skip to content

Commit

Permalink
Merge pull request #28 from fpco/mempool-namespace
Browse files Browse the repository at this point in the history
Handle TxInCache
  • Loading branch information
snoyberg authored Jun 19, 2024
2 parents c309b64 + e193fca commit 038b66e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cosmos/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ impl TxBuilder {
// when using all-node broadcasting.
if !(self.skip_code_check
|| res.code == 0
|| (res.codespace == "sdk" && res.code == 19))
|| CosmosSdkError::from_code(res.code, &res.codespace).is_successful_broadcast())
{
return Err(crate::Error::TransactionFailed {
code: CosmosSdkError::from_code(res.code, &res.codespace),
Expand Down
29 changes: 24 additions & 5 deletions packages/cosmos/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ pub enum CosmosSdkError {
TxTimeoutHeight,
/// Code 32
IncorrectAccountSequence,
/// Codespace mempool, Code 3
TxInCache,
/// Some other error code
Other { code: u32, codespace: String },
}
Expand All @@ -451,6 +453,7 @@ impl Display for CosmosSdkError {
CosmosSdkError::OutOfGas => f.write_str("out of gas (11)"),
CosmosSdkError::InsufficientFee => f.write_str("insufficient fee (13)"),
CosmosSdkError::TxInMempool => f.write_str("tx already in mempool (19)"),
CosmosSdkError::TxInCache => f.write_str("tx already in cache (mempool:3)"),
CosmosSdkError::TxTooLarge => f.write_str("tx too large (21)"),
CosmosSdkError::InvalidChainId => f.write_str("invalid chain ID (28)"),
CosmosSdkError::TxTimeoutHeight => f.write_str("tx timeout height (30)"),
Expand Down Expand Up @@ -482,13 +485,34 @@ impl CosmosSdkError {
codespace: codespace.to_owned(),
},
}
} else if codespace == "mempool" && code == 3 {
Self::TxInCache
} else {
Self::Other {
code,
codespace: codespace.to_owned(),
}
}
}

/// Do we consider a broadcast successful?
pub(crate) fn is_successful_broadcast(&self) -> bool {
match self {
CosmosSdkError::TxInMempool | CosmosSdkError::TxInCache => true,
CosmosSdkError::Unauthorized
| CosmosSdkError::InsufficientFunds
| CosmosSdkError::OutOfGas
| CosmosSdkError::InsufficientFee
| CosmosSdkError::TxTooLarge
| CosmosSdkError::InvalidChainId
| CosmosSdkError::TxTimeoutHeight
| CosmosSdkError::IncorrectAccountSequence
| CosmosSdkError::Other {
code: _,
codespace: _,
} => false,
}
}
}

pub(crate) enum QueryErrorCategory {
Expand All @@ -514,11 +538,6 @@ impl QueryErrorDetails {
QueryErrorDetails::NotFound(_) => ConnectionIsFine,
QueryErrorDetails::CosmosSdk { error_code, .. } => {
match *error_code {
// tx already in mempool usually indicates some kind of a
// node sync issue is occurring, where the node isn't seeing
// new blocks already containing the transaction/sequence
// number.
CosmosSdkError::TxInMempool => NetworkIssue,
// Treat account sequence issue as a transitent issue
CosmosSdkError::IncorrectAccountSequence => ConnectionIsFine,
// Invalid chain ID, we should try a different node if possible
Expand Down

0 comments on commit 038b66e

Please sign in to comment.