51b511b27e
WIP; rebasing Another branch squash Squashing the v3 branch changing min pledge amounts logic for adding new nymnode into the contract converting mixnode/gateway bonding into nym-node bonding logic for migrating gateways into nymnodes ibid for mixnodes further nym-node work + fixed most existing unit tests forbid nymnode migration with pending cost params changes preassign nodeid for gateways changing role assignment and epoch progression changing role assignment and epoch progression optional custom http port logic for unbonding a nym-node updating Delegation struct logic for increasing pledge of either mixnode or nymnode logic for decreasing pledge of either mixnode or a nym node logic for changing cost params of either mixnode or a nym node wip initialise nymnodes storage fixing transaction tests fixed naive family tests reward-compatibility related works resolving delegation events introduced rewarded set metadata another iteration of restoring old tests updated rewarding part of nym-api parking the branch unparking the branch wip purged families added 'ExitGateway' role passing explicit work factor for rewarding function remove legacy layers storage wip: node description queries added announced ports to self-described api step1 in gruelling journey of adding node_id to gateways ensure epoch work never goes above 1.0 changed active set to contain role distribution [theoretically] sending rewarding messages for the new rewarded set [theoretically] assigning new rewarded set reimplementing more nym-api features remove legacy types re-implement legacy network monitor restoring further routes + minor refactor of NodeStatusCache skimmed routes now return legacy nodes alongside nym-nodes seemingly restored all functionalities in nym-api removing more legacy things from the contract initial contract cleanup added nym-api endpoints to return generic annotations regardless of type updated simulator to use new rewarding parameters more contract cleanup made existing mixnet contract tests compile extra validation of nym-node bonding parameters fixed additional compilation issues fixed nym-api v3 database migration failure added additional nym-node contract queries updated the schema made additional delegation/rewards queries compatible with both legacy mixnodes and nym-nodes fixing existing unit tests in mixnet contract wip resolved first batch of 500 compiler errors re-deprecating routes making wallet's rust backend compile fixed non-determinism in contract + nym-api build fixes to the build populating cotracts-cache with nym-nodes data more missing nymnodes queries temp mixnet contract methods + restored result submission in nym-api allow deprecated routes submitting correct results for mixnode results removed deprecated re-export of AxumAppState and removed smurf naming moved axum modules into support::http cleaning up nym-api warnings determine entry gateways before exits exposed transaction to update nym-node config missing memo for updating node config new routes added routes to swagger and fixed relative paths fixed some macro derivations added nym-node commands to nym-cli
255 lines
9.0 KiB
Rust
255 lines
9.0 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::nyxd::cosmwasm_client::types::ContractCodeId;
|
|
use crate::signing::direct_wallet::DirectSecp256k1HdWalletError;
|
|
use cosmrs::tendermint::Hash;
|
|
use cosmrs::{
|
|
tendermint::{abci::Code as AbciCode, block},
|
|
AccountId,
|
|
};
|
|
use std::{io, time::Duration};
|
|
use tendermint_rpc::endpoint::abci_query::AbciQuery;
|
|
use thiserror::Error;
|
|
|
|
pub use cosmrs::tendermint::error::Error as TendermintError;
|
|
pub use tendermint_rpc::{
|
|
error::{Error as TendermintRpcError, ErrorDetail as TendermintRpcErrorDetail},
|
|
response_error::{Code, ResponseError},
|
|
};
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum NyxdError {
|
|
#[error("No contract address is available to perform the call: {0}")]
|
|
NoContractAddressAvailable(String),
|
|
|
|
#[error(transparent)]
|
|
WalletError(#[from] DirectSecp256k1HdWalletError),
|
|
|
|
#[error("There was an issue on the cosmrs side: {0}")]
|
|
CosmrsError(#[from] cosmrs::Error),
|
|
|
|
#[error("There was an issue on the cosmrs side: {0}")]
|
|
CosmrsErrorReport(#[from] cosmrs::ErrorReport),
|
|
|
|
#[error("cosmwasm event not found")]
|
|
ComswasmEventNotFound,
|
|
|
|
#[error("cosmwasm attribute not found")]
|
|
ComswasmAttributeNotFound,
|
|
|
|
#[error("Failed to derive account address")]
|
|
AccountDerivationError,
|
|
|
|
#[error("Address {0} was not found in the wallet")]
|
|
SigningAccountNotFound(AccountId),
|
|
|
|
#[error("Failed to sign raw transaction")]
|
|
SigningFailure,
|
|
|
|
#[error("{0} is not a valid tx hash")]
|
|
InvalidTxHash(String),
|
|
|
|
#[error("Tendermint RPC request failed - {0}")]
|
|
TendermintErrorRpc(#[from] TendermintRpcError),
|
|
|
|
#[error("tendermint library failure: {0}")]
|
|
TendermintError(#[from] TendermintError),
|
|
|
|
#[error("Failed when attempting to serialize data ({0})")]
|
|
SerializationError(String),
|
|
|
|
#[error("Failed when attempting to deserialize data ({0})")]
|
|
DeserializationError(String),
|
|
|
|
#[error("Failed when attempting to encode our protobuf data - {0}")]
|
|
ProtobufEncodingError(#[from] prost::EncodeError),
|
|
|
|
#[error("Failed to decode our protobuf data - {0}")]
|
|
ProtobufDecodingError(#[from] prost::DecodeError),
|
|
|
|
#[error("Account {0} does not exist on the chain")]
|
|
NonExistentAccountError(AccountId),
|
|
|
|
#[error("Failed on json serialization/deserialization - {0}")]
|
|
SerdeJsonError(#[from] serde_json::Error),
|
|
|
|
#[error("Account {0} is not a valid account address")]
|
|
MalformedAccountAddress(String),
|
|
|
|
#[error("Account {0} has an invalid associated public key")]
|
|
InvalidPublicKey(AccountId),
|
|
|
|
#[error("Queried contract (code_id: {0}) did not have any code information attached")]
|
|
NoCodeInformation(ContractCodeId),
|
|
|
|
#[error("Queried contract (address: {0}) did not have any contract information attached")]
|
|
NoContractInformation(AccountId),
|
|
|
|
#[error("Contract contains invalid operations in its history")]
|
|
InvalidContractHistoryOperation,
|
|
|
|
#[error("Block has an invalid height (either negative or larger than i64::MAX")]
|
|
InvalidHeight,
|
|
|
|
#[error("Failed to compress provided wasm code - {0}")]
|
|
WasmCompressionError(io::Error),
|
|
|
|
#[error("Logs returned from the validator were malformed")]
|
|
MalformedLogString,
|
|
|
|
#[error(
|
|
"Error when broadcasting tx {hash} at height {height:?}. Error occurred during CheckTx phase. Code: {code}; Raw log: {raw_log}"
|
|
)]
|
|
BroadcastTxErrorCheckTx {
|
|
hash: Hash,
|
|
height: Option<block::Height>,
|
|
code: u32,
|
|
raw_log: String,
|
|
},
|
|
|
|
#[error(
|
|
"Error when broadcasting tx {hash} at height {height:?}. Error occurred during DeliverTx phase. Code: {code}; Raw log: {raw_log}"
|
|
)]
|
|
BroadcastTxErrorDeliverTx {
|
|
hash: Hash,
|
|
height: Option<block::Height>,
|
|
code: u32,
|
|
raw_log: String,
|
|
},
|
|
|
|
#[error("The provided gas price is malformed")]
|
|
MalformedGasPrice,
|
|
|
|
#[error("Failed to estimate gas price for the transaction")]
|
|
GasEstimationFailure,
|
|
|
|
#[error("Abci query failed with code {code} - {log}")]
|
|
AbciError {
|
|
code: u32,
|
|
log: String,
|
|
pretty_log: Option<String>,
|
|
},
|
|
|
|
#[error("Unsupported account type: {type_url}")]
|
|
UnsupportedAccountType { type_url: String },
|
|
|
|
#[error("{coin_representation} is not a valid Cosmos Coin")]
|
|
MalformedCoin { coin_representation: String },
|
|
|
|
#[error("This account does not have BaseAccount information available to it")]
|
|
NoBaseAccountInformationAvailable,
|
|
|
|
#[error("Transaction with ID {hash} has been submitted but not yet found on the chain. You might want to check for it later. There was a total wait of {} seconds", .timeout.as_secs())]
|
|
BroadcastTimeout { hash: Hash, timeout: Duration },
|
|
|
|
#[error("Cosmwasm std error: {0}")]
|
|
CosmwasmStdError(#[from] cosmwasm_std::StdError),
|
|
|
|
#[error("Account had an unexpected bech32 prefix. Expected: {expected}, got: {got}")]
|
|
UnexpectedBech32Prefix { got: String, expected: String },
|
|
|
|
#[error("the transaction returned unexpected, {got}, number of MsgResponse. Expected to receive a single one")]
|
|
UnexpectedNumberOfMsgResponses { got: usize },
|
|
|
|
#[error("the response data has invalid size. got {got} bytes, but expected {expected} bytes instead")]
|
|
MalformedResponseData { got: usize, expected: usize },
|
|
|
|
#[error(
|
|
"one of the extension query for {contract} failed with the following message: {message}"
|
|
)]
|
|
ExtensionQueryFailure { contract: String, message: String },
|
|
}
|
|
|
|
impl NyxdError {
|
|
pub fn extension_query_failure(
|
|
contract: impl Into<String>,
|
|
message: impl Into<String>,
|
|
) -> Self {
|
|
NyxdError::ExtensionQueryFailure {
|
|
contract: contract.into(),
|
|
message: message.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
// The purpose of parsing the abci query result is that we want to generate the `pretty_log` if
|
|
// possible.
|
|
pub fn parse_abci_query_result(query_result: AbciQuery) -> Result<AbciQuery, NyxdError> {
|
|
match query_result.code {
|
|
AbciCode::Ok => Ok(query_result),
|
|
AbciCode::Err(code) => Err(NyxdError::AbciError {
|
|
code: code.into(),
|
|
log: query_result.log.clone(),
|
|
pretty_log: try_parse_abci_log(&query_result.log),
|
|
}),
|
|
}
|
|
}
|
|
|
|
// Some of the error strings returned by the query are a bit too technical to present to the
|
|
// enduser. So we special case some commonly encountered errors.
|
|
fn try_parse_abci_log(log: &str) -> Option<String> {
|
|
if log.contains("Maximum amount of locked coins has already been pledged") {
|
|
Some("Maximum amount of locked tokens has already been used. You can only use up to 10% of your locked tokens for bonding and delegating.".to_string())
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
impl NyxdError {
|
|
pub fn is_tendermint_response_timeout(&self) -> bool {
|
|
match &self {
|
|
NyxdError::TendermintErrorRpc(TendermintRpcError(
|
|
TendermintRpcErrorDetail::Response(err),
|
|
_,
|
|
)) => {
|
|
let response = &err.source;
|
|
if response.code() == Code::InternalError {
|
|
// 0.34 (and earlier) versions of tendermint seemed to be using phrase "timed out waiting ..."
|
|
// (https://github.com/tendermint/tendermint/blob/v0.34.13/rpc/core/mempool.go#L124)
|
|
// while 0.35+ has "timeout waiting for ..."
|
|
// https://github.com/tendermint/tendermint/blob/v0.35.0-rc3/internal/rpc/core/mempool.go#L99
|
|
// note that as of the time of writing this comment (08.10.2021), the most recent version
|
|
// of cosmos-sdk (v0.44.1) uses tendermint 0.34.13
|
|
if let Some(data) = response.data() {
|
|
data.contains("timed out") || data.contains("timeout")
|
|
} else {
|
|
false
|
|
}
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
pub fn is_tendermint_response_duplicate(&self) -> bool {
|
|
match &self {
|
|
NyxdError::TendermintErrorRpc(TendermintRpcError(
|
|
TendermintRpcErrorDetail::Response(err),
|
|
_,
|
|
)) => {
|
|
let response = &err.source;
|
|
if response.code() == Code::InternalError {
|
|
// this particular error message seems to be unchanged between 0.34 and newer versions
|
|
// https://github.com/tendermint/tendermint/blob/v0.34.13/mempool/errors.go#L10
|
|
// https://github.com/tendermint/tendermint/blob/v0.35.0-rc3/types/mempool.go#L10
|
|
if let Some(data) = response.data() {
|
|
data.contains("tx already exists in cache")
|
|
} else {
|
|
false
|
|
}
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
pub fn unavailable_contract_address<S: Into<String>>(contract_type: S) -> Self {
|
|
NyxdError::NoContractAddressAvailable(contract_type.into())
|
|
}
|
|
}
|