Skip to content

Commit

Permalink
Fix underbidding in simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Mar 6, 2025
1 parent 816b30b commit 5cbdb16
Showing 1 changed file with 51 additions and 36 deletions.
87 changes: 51 additions & 36 deletions chainstate/test-framework/src/random_tx_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,25 +1009,30 @@ impl<'a> RandomTxMaker<'a> {
let filled_value =
calculate_filled_order_value(&orders_cache, order_id, amount_to_spend);

if !is_frozen_token(&filled_value, tokens_cache) {
let input = TxInput::OrderAccountCommand(OrderAccountCommand::FillOrder(
order_id,
amount_to_spend,
key_manager.new_destination(self.chainstate.get_chain_config(), rng),
));
if let Some(filled_value) = filled_value {
if !is_frozen_token(&filled_value, tokens_cache) {
let input =
TxInput::OrderAccountCommand(OrderAccountCommand::FillOrder(
order_id,
amount_to_spend,
key_manager
.new_destination(self.chainstate.get_chain_config(), rng),
));

let output = TxOutput::Transfer(
filled_value,
key_manager.new_destination(self.chainstate.get_chain_config(), rng),
);
let output = TxOutput::Transfer(
filled_value,
key_manager
.new_destination(self.chainstate.get_chain_config(), rng),
);

let _ = orders_cache
.fill_order(order_id, amount_to_spend, OrdersVersion::V1)
.unwrap();
self.account_command_used = true;
let _ = orders_cache
.fill_order(order_id, amount_to_spend, OrdersVersion::V1)
.unwrap();
self.account_command_used = true;

result_inputs.push(input);
result_outputs.push(output);
result_inputs.push(input);
result_outputs.push(output);
}
}
}
} else if switch == 6 {
Expand Down Expand Up @@ -1230,26 +1235,34 @@ impl<'a> RandomTxMaker<'a> {
Amount::from_atoms(atoms),
);

if !is_frozen_token(&filled_value, tokens_cache) {
result_outputs.push(TxOutput::Transfer(
filled_value,
key_manager
.new_destination(self.chainstate.get_chain_config(), rng),
));

result_inputs.push(TxInput::OrderAccountCommand(
OrderAccountCommand::FillOrder(
order_id,
Amount::from_atoms(atoms),
if let Some(filled_value) = filled_value {
if !is_frozen_token(&filled_value, tokens_cache) {
result_outputs.push(TxOutput::Transfer(
filled_value,
key_manager
.new_destination(self.chainstate.get_chain_config(), rng),
),
));

let _ = orders_cache
.fill_order(order_id, Amount::from_atoms(atoms), OrdersVersion::V1)
.unwrap();
self.account_command_used = true;
));

result_inputs.push(TxInput::OrderAccountCommand(
OrderAccountCommand::FillOrder(
order_id,
Amount::from_atoms(atoms),
key_manager.new_destination(
self.chainstate.get_chain_config(),
rng,
),
),
));

let _ = orders_cache
.fill_order(
order_id,
Amount::from_atoms(atoms),
OrdersVersion::V1,
)
.unwrap();
self.account_command_used = true;
}
}
}
}
Expand Down Expand Up @@ -1470,11 +1483,13 @@ fn calculate_filled_order_value(
view: &impl OrdersAccountingView,
order_id: OrderId,
fill: Amount,
) -> OutputValue {
) -> Option<OutputValue> {
let order_data = view.get_order_data(&order_id).unwrap().unwrap();

let filled_amount =
orders_accounting::calculate_fill_order(view, order_id, fill, OrdersVersion::V1).unwrap();

output_value_with_amount(order_data.give(), filled_amount)
// Filling zero amount would result in Underbid error
(filled_amount > Amount::ZERO)
.then(|| output_value_with_amount(order_data.give(), filled_amount))
}

0 comments on commit 5cbdb16

Please sign in to comment.