-
Notifications
You must be signed in to change notification settings - Fork 292
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: transaction filter in runtime config #1590
feat: transaction filter in runtime config #1590
Conversation
I have some doubts in the design.
|
No, because it wasn't the case before. But it could be used easily.
pub trait TransactionFilter<T> {
fn filter(transaction: &T) -> bool;
}
impl<T> TransactionFilter<T> for () {
fn filter(_transaction: &T) -> bool {
true
}
}
pub struct BanInvokeV0TransactionRule;
impl TransactionFilter<InvokeTransaction> for BanInvokeV0TransactionRule {
fn filter(transaction: &InvokeTransaction) -> bool {
match transaction.tx {
starknet_api::transaction::InvokeTransaction::V0(_) => false,
_ => true,
}
}
}
pub struct BanTxFrom0x0TransactionRule;
impl TransactionFilter<InvokeTransaction> for BanTxFrom0x0TransactionRule {
fn filter(transaction: &InvokeTransaction) -> bool {
transaction.sender_address().0.0 != StarkFelt::ZERO
}
}
pub struct MyFilterForInvokeTransaction;
impl TransactionFilter<InvokeTransaction> for MyFilterForInvokeTransaction {
fn filter(transaction: &InvokeTransaction) -> bool {
BanInvokeV0TransactionRule::filter(transaction) && BanTxFrom0x0TransactionRule::filter(transaction)
}
} |
Understood, this way we'll have one master filter for all transaction types. Do you think it makes sense to embed this master filter into each transaction (like explicitly state in code that there's ONE master filter)? Like have a trait called |
I don't understand what you mean here The way we execute tx require having a Filter type by TxType (Declare/Deploy/Invoke) if we want to use the trait. |
Ya sure,
and inside
|
The problem is that the pallet config receives a type. #[pallet::config]
pub trait Config: frame_system::Config {
type InvokeTransactionFilterType: TransactionFilter<InvokeTransaction>;
#[pallet::constant]
type InvokeTransactionFilter: Get<Self::InvokeTransactionFilter>;
} And now you can do: pub struct BlacklistedAddresses(HashSet<ContractAddress>)
impl TransactionFilter<InvokeTransaction> for BlacklistedAddresses {
fn filter(transaction: &InvokeTransaction) -> bool {
!self.0.contains(transaction.sender_address())
}
} Once again, in order to change the list of blacklisted addresses, you will have to run a runtime upgrade |
I didn't understand this part #[pallet::constant]
type InvokeTransactionFilter: Get<Self::InvokeTransactionFilter>; should this be type InvokeTransactionFilter: Get<BlacklistedAddresses>; Also, is this contrary to the |
Mean that the pallet (a lib) only accept one type of |
@apoorvsadana @EvolveArt do you agree on this design? |
Sorry for the late reply. Ya overall the design looks good to me and I think we should proceed. I still have a few questions
|
|
|
8e464bb
to
71d0920
Compare
71d0920
to
1f2519d
Compare
type InvokeTransactionFilter = (); | ||
type DeclareTransactionFilter = (); | ||
type DeployAccountTransactionFilter = (); |
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.
so we don't add the rules here by default?
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.
By default we want our Madara to be as extensive as possible: support all tx versions, all contract classes, etc.
Then other chains can use it to "do less", but we should still cover as much surface area as possible ourselves
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.
Got it, although, by default do we not want it to replicate Starknet Mainent (no V0 txs)
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.
Good question. I would say no on this specific point. But that's debatable.
In any case we made clear that Madara should not be used as it is and require a bit of customization
No description provided.