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: Witnesser dispatch call filter #4001

Merged
merged 8 commits into from Sep 21, 2023
Merged

feat: Witnesser dispatch call filter #4001

merged 8 commits into from Sep 21, 2023

Conversation

syan095
Copy link
Contributor

@syan095 syan095 commented Sep 14, 2023

Pull Request

Closes: PRO-478

Checklist

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

  • I am confident that the code works.
  • I have updated documentation where appropriate.

Summary

Add dispatch call filter for WItnesser pallet.
This is part of the Safe Mode for the witnessed pallet.
Only calls that passes the filter are dispatched. Others are kept in the Queue until full recovery.

Only calls that is allowed by the filter will be dispatched.
@linear
Copy link

linear bot commented Sep 14, 2023

PRO-478 Witnesser Safe Mode with advanced recovery

When we turn witnessing back on, it should be possible to filter against the calls we want to allow.

Not totally sure how to achieve this. Substrate has the FilterStack trait that might help here…

(Needs some research)

@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Merging #4001 (cc03851) into main (178df88) will decrease coverage by 0%.
Report is 1 commits behind head on main.
The diff coverage is 64%.

@@          Coverage Diff           @@
##            main   #4001    +/-   ##
======================================
- Coverage     72%     72%    -0%     
======================================
  Files        368     369     +1     
  Lines      58484   58591   +107     
  Branches   58484   58591   +107     
======================================
+ Hits       42327   42376    +49     
- Misses     14060   14112    +52     
- Partials    2097    2103     +6     
Files Changed Coverage Δ
...tate-chain/cf-integration-tests/src/authorities.rs 93% <ø> (ø)
state-chain/runtime/src/chainflip.rs 51% <ø> (-2%) ⬇️
state-chain/runtime/src/lib.rs 39% <ø> (ø)
state-chain/traits/src/lib.rs 51% <0%> (-1%) ⬇️
state-chain/runtime/src/safe_mode.rs 25% <25%> (ø)
state-chain/pallets/cf-witnesser/src/mock.rs 95% <87%> (-<1%) ⬇️
state-chain/pallets/cf-witnesser/src/lib.rs 80% <87%> (-2%) ⬇️
state-chain/pallets/cf-environment/src/lib.rs 75% <100%> (+1%) ⬆️
state-chain/pallets/cf-witnesser/src/tests.rs 100% <100%> (ø)

... and 4 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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.

Thanks for getting started on this @syan095.

I think the general approach of a top-level call filter is a good one.

However we can be more specific and narrow the filter down to only the calls that can be witnessed. There are some pallets in this implementation that don't have any witness calls (for example system), and others that are missing (funding for example).

The pallets that have witness origin calls are:

Non-instantiable:

  • Governance (1 Call)
  • Funding (3 Calls)
  • Swapping (2 Calls)

Instantiable:

  • Broadcast (1 Call)
  • Chain Tracking (1 Call)
  • Ingress/Egress (3 Calls)
  • Vaults (2 Calls)

Ideally I think we should be able to have as fine-grained control as possible.

For example, if we want to allow everything except bitcoin ingress, we should be able to configure this.

To start with, I think a per-pallet filter is enough.
Then we can add support for instantiable pallets.
Then we can add support for individual calls.

@syan095
Copy link
Contributor Author

syan095 commented Sep 14, 2023

Ideally I think we should be able to have as fine-grained control as possible.

Cool - good to know. I didn't go into too much details, I wanted to make sure the general approach was feasible at first.
I will proceed on this.

Added a unit test for the call filter system.
@syan095 syan095 marked this pull request as ready for review September 15, 2023 03:11
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.

LGTM - only minor I'd like to change is to put all the ChainflipCodeFilter code in its own module. The chainflip.rs file is already pretty crowded.

Thanks.

@@ -352,7 +376,7 @@ pub mod pallet {
if let Some(mut extra_data) = ExtraCallData::<T>::get(epoch_index, call_hash) {
call.combine_and_inject(&mut extra_data)
}
if T::SafeMode::get().witness_calls_enabled {
if T::CallDispatchFilter::should_dispatch(&call) {
Copy link
Collaborator

@dandanlen dandanlen Sep 19, 2023

Choose a reason for hiding this comment

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

This doesn't seem right - it ignores the safe mode?

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.

I think it makes sense to combine the WitnesserCallPermission and CallDispatchFilter.

If we change the trait definition to take &self, then we can impl CallDispatchFilter for WitnesserCallPermission, and we don't need to inject so many items via the witnesser config. I think this will make it a bit easier to follow.

@syan095
Copy link
Contributor Author

syan095 commented Sep 19, 2023

I think it makes sense to combine the WitnesserCallPermission and CallDispatchFilter.

Ahh good idea!

@dandanlen dandanlen changed the title Feat: Witnesser dispatch call filter feat: Witnesser dispatch call filter Sep 21, 2023
@dandanlen dandanlen enabled auto-merge (squash) September 21, 2023 12:56
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.

LGTM, thanks. I just added a small refactor, decoupling the WitnesserCallPermission from safe mode.

@dandanlen dandanlen merged commit 56083b8 into main Sep 21, 2023
43 of 44 checks passed
@dandanlen dandanlen deleted the feat/call-filter branch September 21, 2023 13:26
dandanlen added a commit that referenced this pull request Sep 26, 2023
Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
dandanlen added a commit that referenced this pull request Sep 26, 2023
Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
dandanlen added a commit that referenced this pull request Sep 28, 2023
Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
dandanlen added a commit that referenced this pull request Oct 9, 2023
Co-authored-by: Daniel <daniel@chainflip.io>
Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
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.

None yet

2 participants