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

fix: make boost detection more accurate #5369

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 state-chain/pallets/cf-ingress-egress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ pub mod pallet {
Ok(())
},
_ => {
// Don't apply the mutation. We expect the pre-witnessed/boosted
// Don't apply the mutation. We expect the pre-witnessed
// transaction to eventually be fully witnessed.
Err(())
},
Expand Down
69 changes: 69 additions & 0 deletions state-chain/pallets/cf-ingress-egress/src/tests/screening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@ fn only_broker_can_mark_transaction_as_tainted() {
});
}

#[test]
fn can_not_change_reported_status_if_already_prewitnessed() {
dandanlen marked this conversation as resolved.
Show resolved Hide resolved
new_test_ext().execute_with(|| {
assert_ok!(<MockAccountRoleRegistry as AccountRoleRegistry<Test>>::register_as_broker(
&BROKER,
));

let tx_id = Hash::random();

TaintedTransactions::<Test, ()>::insert(
BROKER,
tx_id,
TaintedTransactionStatus::Prewitnessed,
);

assert_noop!(
IngressEgress::mark_transaction_as_tainted(OriginTrait::signed(BROKER), tx_id,),
crate::Error::<Test, ()>::TransactionAlreadyPrewitnessed
);
});
}

#[test]
fn do_not_expire_tainted_transactions_if_prewitnessed() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -367,3 +389,50 @@ fn send_funds_back_after_they_have_been_rejected() {
);
});
}

#[test]
fn can_report_between_prewitness_and_witness_if_tx_was_not_boosted() {
new_test_ext().execute_with(|| {
let tx_id = Hash::random();
let deposit_details = helpers::generate_btc_deposit(tx_id);

assert_ok!(<MockAccountRoleRegistry as AccountRoleRegistry<Test>>::register_as_broker(
&BROKER,
));

let (_id, address, ..) = IngressEgress::request_liquidity_deposit_address(
BROKER,
btc::Asset::Btc,
0,
ForeignChainAddress::Btc(ScriptPubkey::P2SH(DEFAULT_BTC_ADDRESS)),
)
.unwrap();

let deposit_address = match address {
ForeignChainAddress::Btc(script_pubkey) => script_pubkey,
_ => unreachable!(),
};

let deposit_witnesses = vec![DepositWitness {
deposit_address,
asset: btc::Asset::Btc,
amount: DEFAULT_DEPOSIT_AMOUNT,
deposit_details,
}];

assert_ok!(IngressEgress::add_prewitnessed_deposits(deposit_witnesses.clone(), 10,));
assert_ok!(IngressEgress::mark_transaction_as_tainted(OriginTrait::signed(BROKER), tx_id,));
assert_ok!(IngressEgress::process_deposit_witnesses(deposit_witnesses, 10,));

assert_has_matching_event!(
Test,
RuntimeEvent::IngressEgress(crate::Event::DepositIgnored {
deposit_address: _,
asset: btc::Asset::Btc,
amount: DEFAULT_DEPOSIT_AMOUNT,
deposit_details: _,
reason: DepositIgnoredReason::TransactionTainted,
})
);
});
}
Loading