-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Allow filtering incoming messages by application. #4989
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
Changes from 2 commits
a7593d0
ce63851
f7f5c0c
4e5fc48
9d53a2d
c6d495f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,6 +169,8 @@ Client implementation and command-line tool for the Linera blockchain | |
| Don't include any messages in blocks, and don't make any decision whether to accept or reject | ||
|
|
||
| * `--restrict-chain-ids-to <RESTRICT_CHAIN_IDS_TO>` — A set of chains to restrict incoming messages from. By default, messages from all chains are accepted. To reject messages from all chains, specify an empty string | ||
| * `--accept-messages-with-application-ids <ACCEPT_MESSAGES_WITH_APPLICATION_IDS>` — A set of application IDs. If specified, only bundles with at least one message from one of these applications will be accepted | ||
| * `--reject-messages-with-other-application-ids <REJECT_MESSAGES_WITH_OTHER_APPLICATION_IDS>` — A set of application IDs. If specified, only bundles where all messages are from one of these applications will be accepted | ||
|
||
| * `--timings` — Enable timing reports during operations | ||
| * `--timing-interval <TIMING_INTERVAL>` — Interval in seconds between timing reports (defaults to 5) | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ use linera_base::{ | |
| crypto::{CryptoHash, Signer, ValidatorPublicKey}, | ||
| data_types::{ArithmeticError, Blob, BlockHeight, ChainDescription, Epoch}, | ||
| ensure, | ||
| identifiers::{AccountOwner, BlobId, BlobType, ChainId, StreamId}, | ||
| identifiers::{AccountOwner, BlobId, BlobType, ChainId, GenericApplicationId, StreamId}, | ||
| time::Duration, | ||
| }; | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
|
|
@@ -139,6 +139,10 @@ pub struct MessagePolicy { | |
| /// accepted. `Option::None` means that messages from all chains are accepted. An empty | ||
| /// `HashSet` denotes that messages from no chains are accepted. | ||
| restrict_chain_ids_to: Option<HashSet<ChainId>>, | ||
| /// A collection of applications: If `Some`, only bundles with at least one message by any | ||
| /// of these applications will be accepted. | ||
| accept_messages_with_application_ids: Option<HashSet<GenericApplicationId>>, | ||
| reject_messages_with_other_application_ids: Option<HashSet<GenericApplicationId>>, | ||
|
||
| } | ||
|
|
||
| #[derive(Copy, Clone, Debug, clap::ValueEnum)] | ||
|
|
@@ -157,10 +161,14 @@ impl MessagePolicy { | |
| pub fn new( | ||
| blanket: BlanketMessagePolicy, | ||
| restrict_chain_ids_to: Option<HashSet<ChainId>>, | ||
| accept_messages_with_application_ids: Option<HashSet<GenericApplicationId>>, | ||
| reject_messages_with_other_application_ids: Option<HashSet<GenericApplicationId>>, | ||
| ) -> Self { | ||
| Self { | ||
| blanket, | ||
| restrict_chain_ids_to, | ||
| accept_messages_with_application_ids, | ||
| reject_messages_with_other_application_ids, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -169,22 +177,42 @@ impl MessagePolicy { | |
| Self { | ||
| blanket: BlanketMessagePolicy::Accept, | ||
| restrict_chain_ids_to: None, | ||
| accept_messages_with_application_ids: None, | ||
| reject_messages_with_other_application_ids: None, | ||
| } | ||
| } | ||
|
|
||
| #[instrument(level = "trace", skip(self))] | ||
| fn must_handle(&self, bundle: &mut IncomingBundle) -> bool { | ||
| fn apply(&self, mut bundle: IncomingBundle) -> Option<IncomingBundle> { | ||
| if let Some(chain_ids) = &self.restrict_chain_ids_to { | ||
| if !chain_ids.contains(&bundle.origin) { | ||
| return None; | ||
| } | ||
| } | ||
| if let Some(app_ids) = &self.accept_messages_with_application_ids { | ||
| if !bundle | ||
| .messages() | ||
| .any(|posted_msg| app_ids.contains(&posted_msg.message.application_id())) | ||
| { | ||
| return None; | ||
| } | ||
| } | ||
| if let Some(app_ids) = &self.reject_messages_with_other_application_ids { | ||
| if !bundle | ||
| .messages() | ||
| .all(|posted_msg| app_ids.contains(&posted_msg.message.application_id())) | ||
| { | ||
| return None; | ||
| } | ||
| } | ||
| if self.is_reject() { | ||
| if bundle.bundle.is_skippable() { | ||
| return false; | ||
| return None; | ||
| } else if !bundle.bundle.is_protected() { | ||
| bundle.action = MessageAction::Reject; | ||
| } | ||
| } | ||
| match &self.restrict_chain_ids_to { | ||
| None => true, | ||
| Some(chains) => chains.contains(&bundle.origin), | ||
| } | ||
| Some(bundle) | ||
| } | ||
|
|
||
| #[instrument(level = "trace", skip(self))] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and if the same application ID is in both sets? Then the
REJECT_MESSAGES_WITH_OTHER_APPLICATION_IDStakes precedence?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly: both filters are applied, and the stricter one wins.