Skip to content

Commit

Permalink
Enable and fix htlc for api server simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Oct 25, 2024
1 parent e7fbdfd commit ccf2065
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api-server/scanner-lib/src/blockchain_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1957,11 +1957,11 @@ fn get_tx_output_destination(txo: &TxOutput) -> Option<&Destination> {
| TxOutput::IssueNft(_, _, d)
| TxOutput::ProduceBlockFromStake(d, _) => Some(d),
TxOutput::CreateStakePool(_, data) => Some(data.decommission_key()),
TxOutput::Htlc(_, htlc) => Some(&htlc.spend_key),
TxOutput::IssueFungibleToken(_)
| TxOutput::Burn(_)
| TxOutput::DelegateStaking(_, _)
| TxOutput::DataDeposit(_)
| TxOutput::Htlc(_, _)
| TxOutput::CreateOrder(_) => None,
}
}
2 changes: 1 addition & 1 deletion api-server/scanner-lib/src/sync/tests/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ async fn simulation(
let mut block_builder = tf.make_pos_block_builder().with_random_staking_pool(&mut rng);

for _ in 0..rng.gen_range(10..max_tx_per_block) {
block_builder = block_builder.add_test_transaction(&mut rng, false, false);
block_builder = block_builder.add_test_transaction(&mut rng, false);
}

let block = block_builder.build(&mut rng);
Expand Down
2 changes: 0 additions & 2 deletions chainstate/test-framework/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ impl<'f> BlockBuilder<'f> {
pub fn add_test_transaction(
mut self,
rng: &mut (impl Rng + CryptoRng),
support_htlc: bool,
support_orders: bool,
) -> Self {
let utxo_set = self
Expand Down Expand Up @@ -169,7 +168,6 @@ impl<'f> BlockBuilder<'f> {
&self.orders_accounting_store,
None,
account_nonce_getter,
support_htlc,
support_orders,
)
.make(
Expand Down
2 changes: 0 additions & 2 deletions chainstate/test-framework/src/pos_block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ impl<'f> PoSBlockBuilder<'f> {
pub fn add_test_transaction(
mut self,
rng: &mut (impl Rng + CryptoRng),
support_htlc: bool,
support_orders: bool,
) -> Self {
let utxo_set = self
Expand Down Expand Up @@ -409,7 +408,6 @@ impl<'f> PoSBlockBuilder<'f> {
&self.orders_accounting_store,
self.staking_pool,
account_nonce_getter,
support_htlc,
support_orders,
)
.make(
Expand Down
34 changes: 12 additions & 22 deletions chainstate/test-framework/src/random_tx_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ pub struct RandomTxMaker<'a> {

account_command_used: bool,

support_htlc: bool,

// There can be only one Unmint operation per transaction.
// But it's unknown in advance which token burn would be utilized by unmint operation
// so we have to collect all burns for all tokens just in case.
Expand All @@ -219,7 +217,6 @@ impl<'a> RandomTxMaker<'a> {
orders_store: &'a InMemoryOrdersAccounting,
staking_pool: Option<PoolId>,
account_nonce_getter: Box<dyn Fn(AccountType) -> Option<AccountNonce> + 'a>,
support_htlc: bool, // TODO: remove this when api-server supports orders
support_orders: bool, // TODO: remove this when api-server supports orders
) -> Self {
Self {
Expand All @@ -236,7 +233,6 @@ impl<'a> RandomTxMaker<'a> {
stake_pool_can_be_created: true,
delegation_can_be_created: true,
account_command_used: false,
support_htlc,
unmint_for: None,
total_tokens_burned: BTreeMap::new(),
fee_input: None,
Expand Down Expand Up @@ -1107,24 +1103,18 @@ impl<'a> RandomTxMaker<'a> {
destination,
timelock,
),
1 => {
if self.support_htlc {
TxOutput::Htlc(
OutputValue::Coin(amount_to_spend),
Box::new(HashedTimelockContract {
secret_hash: HtlcSecretHash::zero(),
spend_key: destination,
refund_timelock: timelock,
refund_key: key_manager.new_2_of_2_multisig_destination(
self.chainstate.get_chain_config(),
rng,
),
}),
)
} else {
TxOutput::Transfer(OutputValue::Coin(amount_to_spend), destination)
}
}
1 => TxOutput::Htlc(
OutputValue::Coin(amount_to_spend),
Box::new(HashedTimelockContract {
secret_hash: HtlcSecretHash::zero(),
spend_key: destination,
refund_timelock: timelock,
refund_key: key_manager.new_2_of_2_multisig_destination(
self.chainstate.get_chain_config(),
rng,
),
}),
),
2..=4 => {
TxOutput::Transfer(OutputValue::Coin(amount_to_spend), destination)
}
Expand Down
4 changes: 2 additions & 2 deletions chainstate/test-suite/src/tests/tx_verification_simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn simulation(#[case] seed: Seed, #[case] max_blocks: usize, #[case] max_tx_per_
let mut block_builder = tf.make_pos_block_builder().with_random_staking_pool(&mut rng);

for _ in 0..rng.gen_range(10..max_tx_per_block) {
block_builder = block_builder.add_test_transaction(&mut rng, true, true);
block_builder = block_builder.add_test_transaction(&mut rng, true);
}

let block = block_builder.build(&mut rng);
Expand Down Expand Up @@ -152,7 +152,7 @@ fn simulation(#[case] seed: Seed, #[case] max_blocks: usize, #[case] max_tx_per_
let mut block_builder = tf2.make_pos_block_builder().with_random_staking_pool(&mut rng);

for _ in 0..rng.gen_range(10..max_tx_per_block) {
block_builder = block_builder.add_test_transaction(&mut rng, true, true);
block_builder = block_builder.add_test_transaction(&mut rng, true);
}

let block = block_builder.build(&mut rng);
Expand Down

0 comments on commit ccf2065

Please sign in to comment.