-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: L2 network cannot filter transactions (#47)
- Loading branch information
Showing
22 changed files
with
323 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::{collections::HashSet, str::FromStr}; | ||
|
||
use serde::Deserialize; | ||
use zksync_basic_types::Address; | ||
|
||
#[derive(Debug, Deserialize, Clone, PartialEq)] | ||
pub struct TxSinkConfig { | ||
pub deny_list: Option<String>, | ||
} | ||
|
||
impl TxSinkConfig { | ||
pub fn deny_list(&self) -> Option<HashSet<Address>> { | ||
self.deny_list.as_ref().map(|list| { | ||
list.split(',') | ||
.map(|element| Address::from_str(element).unwrap()) | ||
.collect() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use zksync_config::configs::TxSinkConfig; | ||
|
||
use crate::{envy_load, FromEnv}; | ||
|
||
impl FromEnv for TxSinkConfig { | ||
fn from_env() -> anyhow::Result<Self> { | ||
envy_load("tx_sink", "TX_SINK_") | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::test_utils::EnvMutex; | ||
|
||
static MUTEX: EnvMutex = EnvMutex::new(); | ||
|
||
fn expected_config() -> TxSinkConfig { | ||
TxSinkConfig { | ||
deny_list: Some("0x1234567890abcdef".to_string()), | ||
} | ||
} | ||
|
||
#[test] | ||
fn from_env() { | ||
let mut lock = MUTEX.lock(); | ||
let config = r#" | ||
TX_SINK_DENY_LIST="0x1234567890abcdef" | ||
"#; | ||
lock.set_env(config); | ||
|
||
let actual = TxSinkConfig::from_env().unwrap(); | ||
assert_eq!(actual, expected_config()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
package zksync.config.tx_sink; | ||
|
||
message TxSink { | ||
optional string deny_list = 1; // optional | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use zksync_config::configs; | ||
use zksync_protobuf::repr::ProtoRepr; | ||
|
||
use crate::proto::tx_sink as proto; | ||
|
||
impl ProtoRepr for proto::TxSink { | ||
type Type = configs::tx_sink::TxSinkConfig; | ||
fn read(&self) -> anyhow::Result<Self::Type> { | ||
Ok(Self::Type { | ||
deny_list: self.deny_list.clone(), | ||
}) | ||
} | ||
|
||
fn build(this: &Self::Type) -> Self { | ||
Self { | ||
deny_list: this.deny_list.clone(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.