Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Mar 5, 2025
1 parent 461b8fa commit b558f29
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 75 deletions.
2 changes: 1 addition & 1 deletion chainstate/src/detail/ban_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl BanScore for ConnectTransactionError {
ConnectTransactionError::InputCheck(e) => e.ban_score(),
ConnectTransactionError::OrdersAccountingError(err) => err.ban_score(),
ConnectTransactionError::AttemptToCreateOrderFromAccounts => 100,
ConnectTransactionError::ConcludeInputAmountsDoesntMatch(_, _) => 100,
ConnectTransactionError::ConcludeInputAmountsDontMatch(_, _) => 100,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion chainstate/src/detail/error_classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl BlockProcessingErrorClassification for ConnectTransactionError {
| ConnectTransactionError::TotalFeeRequiredOverflow
| ConnectTransactionError::InsufficientCoinsFee(_, _)
| ConnectTransactionError::AttemptToSpendFrozenToken(_)
| ConnectTransactionError::ConcludeInputAmountsDoesntMatch(_, _) => {
| ConnectTransactionError::ConcludeInputAmountsDontMatch(_, _) => {
BlockProcessingErrorClass::BadBlock
}

Expand Down
4 changes: 2 additions & 2 deletions chainstate/tx-verifier/src/transaction_verifier/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub enum ConnectTransactionError {
OrdersAccountingError(#[from] orders_accounting::Error),
#[error(transparent)]
InputCheck(#[from] InputCheckError),
#[error("Transaction {0} has conclude order input {1} with amounts that doesn't match the db")]
ConcludeInputAmountsDoesntMatch(Id<Transaction>, OrderId),
#[error("Transaction {0} has conclude order input {1} with amounts that don't match the db")]
ConcludeInputAmountsDontMatch(Id<Transaction>, OrderId),
}

impl From<std::convert::Infallible> for ConnectTransactionError {
Expand Down
6 changes: 3 additions & 3 deletions chainstate/tx-verifier/src/transaction_verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,18 +852,18 @@ where
};
let current_ask_balance = view.get_ask_balance(&order_id)?;
let expected_filled_amount = (original_ask_balance - current_ask_balance).ok_or(
ConnectTransactionError::ConcludeInputAmountsDoesntMatch(tx_id, order_id),
ConnectTransactionError::ConcludeInputAmountsDontMatch(tx_id, order_id),
)?;

ensure!(
filled_amount == expected_filled_amount,
ConnectTransactionError::ConcludeInputAmountsDoesntMatch(tx_id, order_id)
ConnectTransactionError::ConcludeInputAmountsDontMatch(tx_id, order_id)
);

let current_give_balance = view.get_give_balance(&order_id)?;
ensure!(
current_give_balance == remaining_give_amount,
ConnectTransactionError::ConcludeInputAmountsDoesntMatch(tx_id, order_id)
ConnectTransactionError::ConcludeInputAmountsDontMatch(tx_id, order_id)
);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion common/src/chain/upgrades/chainstate_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub enum FrozenTokensValidationVersion {
pub enum OrdersVersion {
/// Initial orders implementation
V0,
/// Calculate fill amount based on original balances; ignore nonce for fill operations
/// Calculate fill amount based on original balances; ignore nonce for order operations
V1,
}

Expand Down
2 changes: 1 addition & 1 deletion mempool/src/error/ban_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl MempoolBanScore for ConnectTransactionError {
ConnectTransactionError::MissingTxUndo(_) => 0,
ConnectTransactionError::MissingTransactionNonce(_) => 0,
ConnectTransactionError::FailedToIncrementAccountNonce => 0,
ConnectTransactionError::ConcludeInputAmountsDoesntMatch(_, _) => 0,
ConnectTransactionError::ConcludeInputAmountsDontMatch(_, _) => 0,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mempool/src/pool/orphans/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl OrphanType {
| CTE::CheckTransactionError(_)
| CTE::OrdersAccountingError(_)
| CTE::AttemptToCreateOrderFromAccounts
| CTE::ConcludeInputAmountsDoesntMatch(_, _)
| CTE::ConcludeInputAmountsDontMatch(_, _)
| CTE::IOPolicyError(_, _) => Err(err),
}
}
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/account/output_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ impl OutputCache {
})
}
},
TxInput::Account(_) => false,
TxInput::OrderAccountCommand(cmd) => match cmd {
OrderAccountCommand::FillOrder(order_id, _, _)
| OrderAccountCommand::ConcludeOrder {
Expand All @@ -846,6 +845,7 @@ impl OutputCache {
})
}),
},
TxInput::Account(_) => false,
})
}

Expand Down
68 changes: 4 additions & 64 deletions wallet/src/wallet/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use common::{
address::pubkeyhash::PublicKeyHash,
chain::{
block::{consensus_data::PoSData, timestamp::BlockTimestamp, BlockReward, ConsensusData},
config::{
create_mainnet, create_regtest, create_unit_test_config,
create_unit_test_config_builder, Builder, ChainType,
},
config::{create_mainnet, create_regtest, create_unit_test_config, Builder, ChainType},
output_value::{OutputValue, RpcOutputValue},
signature::inputsig::InputWitness,
stakelock::StakePoolData,
Expand Down Expand Up @@ -5666,26 +5663,7 @@ fn create_order(#[case] seed: Seed) {
#[case(Seed::from_entropy())]
fn create_order_and_conclude(#[case] seed: Seed) {
let mut rng = make_seedable_rng(seed);
let chain_config = create_unit_test_config_builder()
.chainstate_upgrades(
common::chain::NetUpgrades::initialize(vec![(
BlockHeight::zero(),
common::chain::ChainstateUpgrade::new(
common::chain::TokenIssuanceVersion::V1,
common::chain::RewardDistributionVersion::V1,
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::Yes,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::Yes,
common::chain::OrdersActivated::Yes,
common::chain::OrdersVersion::V0,
),
)])
.expect("cannot fail"),
)
.build();
let chain_config = Arc::new(chain_config);
let chain_config = Arc::new(create_unit_test_config());

let mut wallet = create_wallet(chain_config.clone());

Expand Down Expand Up @@ -5858,26 +5836,7 @@ fn create_order_and_conclude(#[case] seed: Seed) {
#[case(Seed::from_entropy())]
fn create_order_fill_completely_conclude(#[case] seed: Seed) {
let mut rng = make_seedable_rng(seed);
let chain_config = create_unit_test_config_builder()
.chainstate_upgrades(
common::chain::NetUpgrades::initialize(vec![(
BlockHeight::zero(),
common::chain::ChainstateUpgrade::new(
common::chain::TokenIssuanceVersion::V1,
common::chain::RewardDistributionVersion::V1,
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::Yes,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::Yes,
common::chain::OrdersActivated::Yes,
common::chain::OrdersVersion::V0,
),
)])
.expect("cannot fail"),
)
.build();
let chain_config = Arc::new(chain_config);
let chain_config = Arc::new(create_unit_test_config());

let mut wallet1 = create_wallet_with_mnemonic(chain_config.clone(), MNEMONIC);
let mut wallet2 = create_wallet_with_mnemonic(chain_config.clone(), MNEMONIC2);
Expand Down Expand Up @@ -6214,26 +6173,7 @@ fn create_order_fill_completely_conclude(#[case] seed: Seed) {
#[case(Seed::from_entropy())]
fn create_order_fill_partially_conclude(#[case] seed: Seed) {
let mut rng = make_seedable_rng(seed);
let chain_config = create_unit_test_config_builder()
.chainstate_upgrades(
common::chain::NetUpgrades::initialize(vec![(
BlockHeight::zero(),
common::chain::ChainstateUpgrade::new(
common::chain::TokenIssuanceVersion::V1,
common::chain::RewardDistributionVersion::V1,
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::Yes,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::Yes,
common::chain::OrdersActivated::Yes,
common::chain::OrdersVersion::V0,
),
)])
.expect("cannot fail"),
)
.build();
let chain_config = Arc::new(chain_config);
let chain_config = Arc::new(create_unit_test_config());

let mut wallet1 = create_wallet_with_mnemonic(chain_config.clone(), MNEMONIC);
let mut wallet2 = create_wallet_with_mnemonic(chain_config.clone(), MNEMONIC2);
Expand Down

0 comments on commit b558f29

Please sign in to comment.