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: update custom_rpc, runtime_api and broker api for broker level screening #5341

Merged

Conversation

MxmUrw
Copy link
Contributor

@MxmUrw MxmUrw commented Oct 21, 2024

Pull Request

Closes: PRO-1706

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

In this PR all changes to the broker API which are required for broker level screening are going to be merged. Currently based on @Janislav 's PR (#5310) (#5332) which implements the extrinsic for rejecting transactions.

Once that PR is merged, rebase this on main.

This PR includes the following changes:

  • Add new methods to custom_rpc:
    • cf_get_tainted_transaction_events which gets all events (for a given block) related with tainted transactions occuring in the ingress egress pallet.
    • cf_get_open_deposit_channels which returns all open channel addresses for a given account id.
  • These methods forward to corresponding implementations in the runtime api.
  • Changes to the broker API:
    • Add mark_transaction_as_tainted endpoint which submits the corresponding extrinsic.
    • Add get_open_deposit_channels method.
    • Add subscribe_tainted_btc_transaction_events method which creates a subscription for calling the cf_get_tainted_transaction_events custom rpc method.

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.

Base automatically changed from feature/pro-1664/close-deposit-channel to main October 24, 2024 13:07
@MxmUrw MxmUrw force-pushed the feature/PRO-1706/update-broker-api-for-broker-level-screening branch from af966d1 to a3835f1 Compare October 28, 2024 10:01
@MxmUrw MxmUrw changed the base branch from main to feature/pro-1712/reject-tx October 28, 2024 13:55
@MxmUrw MxmUrw changed the title feat: update broker api for broker level screening feat: update custom_rpc, runtime_api and broker api for broker level screening Oct 28, 2024
@MxmUrw MxmUrw marked this pull request as ready for review October 29, 2024 14:33
@MxmUrw MxmUrw requested a review from dandanlen as a code owner October 29, 2024 14:33
@MxmUrw
Copy link
Contributor Author

MxmUrw commented Oct 29, 2024

To be discussed: error handling in the subscription forwarding in the broker api (subscribe_tainted_btc_transaction_events). Currently a bit ad-hoc, forwarding a Result<_,String> whose error-variant is used for the case where the subscription message from the engine cannot be decoded.

Base automatically changed from feature/pro-1712/reject-tx to main October 29, 2024 16:47
@MxmUrw MxmUrw force-pushed the feature/PRO-1706/update-broker-api-for-broker-level-screening branch from 3166701 to e1a6006 Compare October 30, 2024 09:19
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 11.26761% with 63 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (adcf011) to head (d789177).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
state-chain/runtime/src/lib.rs 18% 0 Missing and 28 partials ⚠️
state-chain/runtime/src/runtime_apis.rs 12% 12 Missing and 3 partials ⚠️
api/lib/src/lib.rs 0% 14 Missing ⚠️
state-chain/custom-rpc/src/lib.rs 0% 6 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5341    +/-   ##
======================================
- Coverage     72%     71%    -0%     
======================================
  Files        495     496     +1     
  Lines      86276   86491   +215     
  Branches   86276   86491   +215     
======================================
- Hits       61713   61661    -52     
- Misses     21784   22001   +217     
- Partials    2779    2829    +50     

☔ 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.

Looking good - I have one larger (and very annoying) suggestion and some minor ones...

Comment on lines 37 to 38
sp-rpc = { workspace = true }
sc-rpc = { workspace = true, default-features = true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate 👀

FWIW I think sp-core should also have default-features=true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately one is sP- and the other sC-... The latter was required for the sc_rpc::utils::pipe_from_stream() utility.

I am not sure about the default-features though, I copied it from the custom_rpc lib. In fact it compiles if I remove the default-features=true for sc-rpc.

Should I enable default-features for all three of them anyways?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes we should enable it for all three - it might not be a problem now, but this kind of thing tends to cause problems unexpectedly.

api/bin/chainflip-broker-api/src/main.rs Outdated Show resolved Hide resolved
api/bin/chainflip-broker-api/src/main.rs Outdated Show resolved Hide resolved
api/lib/src/lib.rs Outdated Show resolved Hide resolved
state-chain/custom-rpc/src/lib.rs Outdated Show resolved Hide resolved
state-chain/runtime/src/runtime_apis.rs Outdated Show resolved Hide resolved
state-chain/runtime/src/lib.rs Outdated Show resolved Hide resolved
state-chain/runtime/src/lib.rs Show resolved Hide resolved
@MxmUrw MxmUrw requested a review from dandanlen October 30, 2024 15:48
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 final comments then we're good.

.filter(|channel_details| match channel_details.action {
ChannelAction::Swap {..} => true,
ChannelAction::CcmTransfer {..} => true,
ChannelAction::LiquidityProvision {..} => false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure there's a need for this filter - why ignore LiquidityProvision ?

Copy link
Contributor Author

@MxmUrw MxmUrw Oct 31, 2024

Choose a reason for hiding this comment

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

Talked with Martin: Currently we only implement the rejection of transactions which originate from swaps. The liquidity provision transactions would have to be monitored by members of the "whitelist" which are authorized to do so. We don't have the whitelist currently, so nobody monitors these transactions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes but this rpc is called cf_get_open_deposit_channels so it should probably return all of the open deposit channels for the given id.

If a broker submits this request via the broker api it will implicitly filter out an LP channels anyway. And later on when we want to be able to monitor all channels, we won't get any surprises in the behaviour of this rpc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, now don't distinguish between channelactions.

api/lib/src/lib.rs Outdated Show resolved Hide resolved
@MxmUrw MxmUrw force-pushed the feature/PRO-1706/update-broker-api-for-broker-level-screening branch from 6620ee8 to b7441df Compare November 1, 2024 13:42
@MxmUrw MxmUrw changed the base branch from main to fix/rpc-subscriptions November 1, 2024 13:43
@MxmUrw MxmUrw force-pushed the feature/PRO-1706/update-broker-api-for-broker-level-screening branch 2 times, most recently from d5ae794 to b191d52 Compare November 1, 2024 13:45
@dandanlen dandanlen force-pushed the fix/rpc-subscriptions branch from 2e5dae0 to 85a2689 Compare November 1, 2024 14:04
Base automatically changed from fix/rpc-subscriptions to main November 1, 2024 15:29
@dandanlen
Copy link
Collaborator

#5341 (comment)

☝️ disagree? Apart from this I think we're good to go.

commit 3166701
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 15:27:51 2024 +0100

    Add `subscribe_tainted_btc_transaction_events` method to Broker API.

    It which forwards the node subscription of the same name.

commit 010772d
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 13:56:07 2024 +0100

    Add `open_btc_deposit_channels` method to broker api.

commit 9ea7e6f
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 11:19:07 2024 +0100

    Add subscription endpoint for tainted transaction events.

commit e81028a
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 15:12:47 2024 +0100

    Implement `open_btc_deposit_channels`.

commit 439ddd1
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 14:51:22 2024 +0100

    Add boilerplate for `open_btc_deposit_channels`.

commit a3835f1
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 10:25:51 2024 +0100

    Add endpoint for marking btc tx as tainted.
We do not filter out `LiquidityProvision` channels anymore.
… from the node.

This is now the same as in the LP API binary. The previous version didn't
use finalized blocks and thus might not have been stable.

Theoretically it would be nice to be able to forward the subscription from the node,
see PRO-1768.
@MxmUrw MxmUrw force-pushed the feature/PRO-1706/update-broker-api-for-broker-level-screening branch from 50a1b15 to 636ddc8 Compare November 5, 2024 14:06
@MxmUrw MxmUrw requested review from dandanlen and kylezs November 5, 2024 14:27
Copy link
Contributor

@kylezs kylezs left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 would await Dan's review

state-chain/runtime/src/lib.rs Outdated Show resolved Hide resolved
state-chain/runtime/src/runtime_apis.rs Outdated Show resolved Hide resolved
state-chain/runtime/src/lib.rs Show resolved Hide resolved
@MxmUrw MxmUrw added this pull request to the merge queue Nov 6, 2024
Merged via the queue into main with commit 48ac666 Nov 6, 2024
48 of 49 checks passed
@MxmUrw MxmUrw deleted the feature/PRO-1706/update-broker-api-for-broker-level-screening branch November 6, 2024 15:00
dandanlen pushed a commit that referenced this pull request Nov 6, 2024
…screening (#5341)

* Squashed commit of the following:

commit 3166701
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 15:27:51 2024 +0100

    Add `subscribe_tainted_btc_transaction_events` method to Broker API.

    It which forwards the node subscription of the same name.

commit 010772d
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 13:56:07 2024 +0100

    Add `open_btc_deposit_channels` method to broker api.

commit 9ea7e6f
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 11:19:07 2024 +0100

    Add subscription endpoint for tainted transaction events.

commit e81028a
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 15:12:47 2024 +0100

    Implement `open_btc_deposit_channels`.

commit 439ddd1
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 14:51:22 2024 +0100

    Add boilerplate for `open_btc_deposit_channels`.

commit a3835f1
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 10:25:51 2024 +0100

    Add endpoint for marking btc tx as tainted.

* Apply suggestions from review.

* Return all channels for *all* channel actions.

We do not filter out `LiquidityProvision` channels anymore.

* Create tainted event subscription in broker API instead of forwarding from the node.

This is now the same as in the LP API binary. The previous version didn't
use finalized blocks and thus might not have been stable.

Theoretically it would be nice to be able to forward the subscription from the node,
see PRO-1768.

* Apply clippy suggestion.

* Remove now unused `tainted_transaction_events` subscription.

* Apply suggestions from @kylezs's review.
dandanlen pushed a commit that referenced this pull request Nov 6, 2024
…screening (#5341)

* Squashed commit of the following:

commit 3166701
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 15:27:51 2024 +0100

    Add `subscribe_tainted_btc_transaction_events` method to Broker API.

    It which forwards the node subscription of the same name.

commit 010772d
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 13:56:07 2024 +0100

    Add `open_btc_deposit_channels` method to broker api.

commit 9ea7e6f
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Tue Oct 29 11:19:07 2024 +0100

    Add subscription endpoint for tainted transaction events.

commit e81028a
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 15:12:47 2024 +0100

    Implement `open_btc_deposit_channels`.

commit 439ddd1
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 14:51:22 2024 +0100

    Add boilerplate for `open_btc_deposit_channels`.

commit a3835f1
Author: Maxim Urschumzew <maxu@chainflip.io>
Date:   Mon Oct 28 10:25:51 2024 +0100

    Add endpoint for marking btc tx as tainted.

* Apply suggestions from review.

* Return all channels for *all* channel actions.

We do not filter out `LiquidityProvision` channels anymore.

* Create tainted event subscription in broker API instead of forwarding from the node.

This is now the same as in the LP API binary. The previous version didn't
use finalized blocks and thus might not have been stable.

Theoretically it would be nice to be able to forward the subscription from the node,
see PRO-1768.

* Apply clippy suggestion.

* Remove now unused `tainted_transaction_events` subscription.

* Apply suggestions from @kylezs's review.
syan095 added a commit that referenced this pull request Nov 7, 2024
* origin/main:
  feat: add version and affiliates to UTXO encoding (#5385)
  chore: bump all versions to 1.8.0 and remove old migrations. (#5327)
  feat: update custom_rpc, runtime_api and broker api for broker level screening (#5341)
  tests: Bouncer test for broker level screening (#5377)
  Feat: Private Broker Channel Witnessing (#5383)

# Conflicts:
#	state-chain/runtime/src/lib.rs
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