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

feat: tainted transaction reporting #5310

Merged
merged 51 commits into from
Oct 24, 2024

Conversation

Janislav
Copy link
Contributor

@Janislav Janislav commented Oct 2, 2024

Pull Request

Closes: PRO-1664

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

  • Added the functionality to mark a transaction as tainted as a broker or LP.
  • Check transactions when we process the ingress and stop if the channel is marked as tainted.
  • Saving tainted transaction details to refund it later.

Non-Breaking changes

If this PR includes non-breaking changes, select the non-breaking label. On merge, CI will automatically cherry-pick the commit to a PR against the release branch.

- Extended DepositChannelDetails with owner field
- Added extrinsic to mark transaction as tainted
- Handling deposit and save details for a refund if tx is tainted
- Added tests to verify that tainted transactions can get detected for all possible swap types
- Added tests  to check that txs marked by other brokers are getting ignored
Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 86.78261% with 76 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (df8771a) to head (c45ec0f).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...ess/src/migrations/add_owner_to_channel_details.rs 65% 41 Missing ⚠️
state-chain/pallets/cf-ingress-egress/src/lib.rs 82% 12 Missing and 4 partials ⚠️
...ate-chain/pallets/cf-ingress-egress/src/weights.rs 0% 14 Missing ⚠️
state-chain/runtime/src/chainflip.rs 0% 4 Missing ⚠️
state-chain/pallets/cf-lp/src/lib.rs 94% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5310    +/-   ##
======================================
  Coverage     71%     71%            
======================================
  Files        492     495     +3     
  Lines      85750   86168   +418     
  Branches   85750   86168   +418     
======================================
+ Hits       61107   61423   +316     
- Misses     21908   22002    +94     
- Partials    2735    2743     +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some early comments.

Comment on lines 546 to 547
<T::TargetChain as Chain>::DepositDetails,
TaintedTransactionDetails<T::AccountId>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider what happens if same tx is reported twice by different parties.

I think we might need a double-map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/traits/src/liquidity.rs Outdated Show resolved Hide resolved
- Taking refund address if we open a deposit channel as lp
- Extended ChannelAction to take an optional refund address
- Removed all dependencies regarding the LpRegistration trait (added last commit)
- Refactored tests, benchmarks, etc
@Janislav Janislav marked this pull request as ready for review October 7, 2024 11:12
@Janislav Janislav requested a review from kylezs as a code owner October 7, 2024 11:12
@Janislav
Copy link
Contributor Author

Janislav commented Oct 7, 2024

Still working on the benchmark. It's written, but there is something odd with the way we generate the weights.

state-chain/traits/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-lp/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
@dandanlen
Copy link
Collaborator

Also please remember to rebase against main to pick up the new compiler version.

@msgmaxim
Copy link
Contributor

I took the liberty to push a commit with some updates to comments (a few things weren't quite right, and I thought it would help if I did it myself). Feel free to revert @Janislav.

@@ -752,6 +810,26 @@ pub mod pallet {
Self::recycle_channel(&mut used_weight, address);
}
}

// A report gets cleaned up after approx 1 hour and needs to be re-reported by the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the broker re-reports? Would it then overwrite the BoostRejected record? (This would be problematic.)

@dandanlen dandanlen changed the title Mark transaction as tainted feat: tainted transaction reporting Oct 22, 2024
Janislav and others added 2 commits October 22, 2024 13:41
- mark boosted transactions as boosted instead of using channel status
- allow pallet config instead of relying on chain
- add event for tx reports
- only allow reporting of unseen transactions
- add doc comments
- renaming of types/events
- remove unused error
@dandanlen
Copy link
Collaborator

I added some changes (From the commit description):

  • mark boosted transactions as boosted instead of using channel status
  • allow pallet config instead of relying on chain
  • add event for tx reports
  • only allow reporting of unseen transactions
  • add doc comments
  • renaming of types/events
  • remove unused error

The main one is that I added a Boosted variant (and renamed) to the transaction report enum. I think this makes everything a bit clearer, in particular avoids having to rely on the channel status to know if a deposit has been boosted: now we just look up the tx_id.

@dandanlen dandanlen added this pull request to the merge queue Oct 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 23, 2024
@Janislav Janislav added this pull request to the merge queue Oct 23, 2024
@Janislav Janislav removed this pull request from the merge queue due to a manual request Oct 23, 2024
@Janislav
Copy link
Contributor Author

Somehow, the storage of the old DepositChannelDetails is not decodable during migration. No idea why yet.

@dandanlen dandanlen added this pull request to the merge queue Oct 24, 2024
Merged via the queue into main with commit dc8bf3e Oct 24, 2024
48 of 49 checks passed
@dandanlen dandanlen deleted the feature/pro-1664/close-deposit-channel branch October 24, 2024 13:07
syan095 added a commit that referenced this pull request Oct 29, 2024
…waps-close-accounts

* origin/main: (44 commits)
  fix: expire all previous epochs (#5279)
  feat: add/update contract swaps parameters (#5343)
  chore: add address to solana logging (#5353)
  fix: ignore dust underflows in order fills rpc (#5352)
  chore: consistent naming prewitnessed (#5351)
  feat: engine-runner verifies gpg signature of old dylib when downloaded (#5339)
  feat: tainted transaction reporting (#5310)
  bug: change_utxo not always present (#5340)
  feat: structured error return types for rpcs (#5346)
  chore: unify dependencies to root cargo.toml (#5333)
  feat: Submit a slot number alongside nonce (#5297)
  chore: use node version from `.nvmrc` 📌 (#5336)
  chore: add engine account_info logging (#5347)
  chore: replace manual scale encoding for ts-scale (#5335)
  chore: more consistent params in Broker API (#5342)
  feat: broker can encode btc smart contract call (#5329)
  chore: localnet recreate script can use defaults (#5338)
  feat: witnessing btc smart contract swaps (#5331)
  feat: Solana CCM fallback (#5316)
  fix: scale types for pending ceremonies (#5286)
  ...

# Conflicts:
#	Cargo.lock
#	state-chain/chains/src/sol/api.rs
#	state-chain/pallets/cf-broadcast/src/migrations.rs
#	state-chain/pallets/cf-environment/Cargo.toml
dandanlen added a commit that referenced this pull request Oct 30, 2024
* feat: Handling of tainted transactions

- Extended DepositChannelDetails with owner field
- Added extrinsic to mark transaction as tainted
- Handling deposit and save details for a refund if tx is tainted

* tests: Added tests

- Added tests to verify that tainted transactions can get detected for all possible swap types
- Added tests  to check that txs marked by other brokers are getting ignored

* chore: Extended LpRegistration trait + Added to Ingress/Egress config

* feat: Getting LP refund address

* feature: ensure by lp and broker + added more tests

* refactor: Don't error if tx is tainted

* refactor: Using DoubleMap instead of Map

* refactor: Using BadOrigin + Added unit test

* refactor: Inline code + Add Deposit Witness to struct

* refactor: Extended lp deposit with refund address

- Taking refund address if we open a deposit channel as lp
- Extended ChannelAction to take an optional refund address
- Removed all dependencies regarding the LpRegistration trait (added last commit)
- Refactored tests, benchmarks, etc

* feature: Added benchmark

* chore: Changes to benchmark

* chore: generated mock weights

* chore: only allow mark transactions for BTC

* feature: expire tainted transaction

* test: refactored tests

* chore: Removed unused events

* chore: Ensure only by broker

* chore: removed broker from tainted tx struct

* chore: Only clone owner

* chore: Moved tx tainted check

* feature: Added migration for DepositChannelLookup

* refactor: Changed data structure + fixed migrations

* chore: Handle LP refund address as requirement

* chore: Made clippy happy 🙂

* chore: don't manipulate storage in place in iteration 🙅‍♂️

* test: Added migration test 🧪

* chore: changed pallet storage version 📀

* chore: bumped pallet storage version (again)

* refactor: Changed accounting of expired transactions

* refactor: using translate for migration

* refactor: using append, refactored test

* feature: Added handling of boost channels

* feature: Marking txs when prewitness and reject when we process the depo

* feat: pre-witnessed rejection handling

* chore: Fixed logic + added tests

* tests: Refactor/Rearranged tests

* chore: Using SECONDS_PER_BLOCK instead of static block seconds

* chore: Addressed comments

* chore: Fixed clippy in CI

* chore: update comments

* fix: don't allow report overwrite

* chore: Renamed event

* feat: improvements:

- mark boosted transactions as boosted instead of using channel status
- allow pallet config instead of relying on chain
- add event for tx reports
- only allow reporting of unseen transactions
- add doc comments
- renaming of types/events
- remove unused error

* fix: migration

* fix: made clippy happy

---------

Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: Maxim Shishmarev <maxim@chainflip.io>
dandanlen added a commit that referenced this pull request Oct 30, 2024
* feat: Handling of tainted transactions

- Extended DepositChannelDetails with owner field
- Added extrinsic to mark transaction as tainted
- Handling deposit and save details for a refund if tx is tainted

* tests: Added tests

- Added tests to verify that tainted transactions can get detected for all possible swap types
- Added tests  to check that txs marked by other brokers are getting ignored

* chore: Extended LpRegistration trait + Added to Ingress/Egress config

* feat: Getting LP refund address

* feature: ensure by lp and broker + added more tests

* refactor: Don't error if tx is tainted

* refactor: Using DoubleMap instead of Map

* refactor: Using BadOrigin + Added unit test

* refactor: Inline code + Add Deposit Witness to struct

* refactor: Extended lp deposit with refund address

- Taking refund address if we open a deposit channel as lp
- Extended ChannelAction to take an optional refund address
- Removed all dependencies regarding the LpRegistration trait (added last commit)
- Refactored tests, benchmarks, etc

* feature: Added benchmark

* chore: Changes to benchmark

* chore: generated mock weights

* chore: only allow mark transactions for BTC

* feature: expire tainted transaction

* test: refactored tests

* chore: Removed unused events

* chore: Ensure only by broker

* chore: removed broker from tainted tx struct

* chore: Only clone owner

* chore: Moved tx tainted check

* feature: Added migration for DepositChannelLookup

* refactor: Changed data structure + fixed migrations

* chore: Handle LP refund address as requirement

* chore: Made clippy happy 🙂

* chore: don't manipulate storage in place in iteration 🙅‍♂️

* test: Added migration test 🧪

* chore: changed pallet storage version 📀

* chore: bumped pallet storage version (again)

* refactor: Changed accounting of expired transactions

* refactor: using translate for migration

* refactor: using append, refactored test

* feature: Added handling of boost channels

* feature: Marking txs when prewitness and reject when we process the depo

* feat: pre-witnessed rejection handling

* chore: Fixed logic + added tests

* tests: Refactor/Rearranged tests

* chore: Using SECONDS_PER_BLOCK instead of static block seconds

* chore: Addressed comments

* chore: Fixed clippy in CI

* chore: update comments

* fix: don't allow report overwrite

* chore: Renamed event

* feat: improvements:

- mark boosted transactions as boosted instead of using channel status
- allow pallet config instead of relying on chain
- add event for tx reports
- only allow reporting of unseen transactions
- add doc comments
- renaming of types/events
- remove unused error

* fix: migration

* fix: made clippy happy

---------

Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: Maxim Shishmarev <maxim@chainflip.io>
dandanlen added a commit that referenced this pull request Oct 31, 2024
* feat: Handling of tainted transactions

- Extended DepositChannelDetails with owner field
- Added extrinsic to mark transaction as tainted
- Handling deposit and save details for a refund if tx is tainted

* tests: Added tests

- Added tests to verify that tainted transactions can get detected for all possible swap types
- Added tests  to check that txs marked by other brokers are getting ignored

* chore: Extended LpRegistration trait + Added to Ingress/Egress config

* feat: Getting LP refund address

* feature: ensure by lp and broker + added more tests

* refactor: Don't error if tx is tainted

* refactor: Using DoubleMap instead of Map

* refactor: Using BadOrigin + Added unit test

* refactor: Inline code + Add Deposit Witness to struct

* refactor: Extended lp deposit with refund address

- Taking refund address if we open a deposit channel as lp
- Extended ChannelAction to take an optional refund address
- Removed all dependencies regarding the LpRegistration trait (added last commit)
- Refactored tests, benchmarks, etc

* feature: Added benchmark

* chore: Changes to benchmark

* chore: generated mock weights

* chore: only allow mark transactions for BTC

* feature: expire tainted transaction

* test: refactored tests

* chore: Removed unused events

* chore: Ensure only by broker

* chore: removed broker from tainted tx struct

* chore: Only clone owner

* chore: Moved tx tainted check

* feature: Added migration for DepositChannelLookup

* refactor: Changed data structure + fixed migrations

* chore: Handle LP refund address as requirement

* chore: Made clippy happy 🙂

* chore: don't manipulate storage in place in iteration 🙅‍♂️

* test: Added migration test 🧪

* chore: changed pallet storage version 📀

* chore: bumped pallet storage version (again)

* refactor: Changed accounting of expired transactions

* refactor: using translate for migration

* refactor: using append, refactored test

* feature: Added handling of boost channels

* feature: Marking txs when prewitness and reject when we process the depo

* feat: pre-witnessed rejection handling

* chore: Fixed logic + added tests

* tests: Refactor/Rearranged tests

* chore: Using SECONDS_PER_BLOCK instead of static block seconds

* chore: Addressed comments

* chore: Fixed clippy in CI

* chore: update comments

* fix: don't allow report overwrite

* chore: Renamed event

* feat: improvements:

- mark boosted transactions as boosted instead of using channel status
- allow pallet config instead of relying on chain
- add event for tx reports
- only allow reporting of unseen transactions
- add doc comments
- renaming of types/events
- remove unused error

* fix: migration

* fix: made clippy happy

---------

Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: Maxim Shishmarev <maxim@chainflip.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants