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

Handle TxInCache #28

Merged
merged 1 commit into from
Jun 19, 2024
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
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
Loading