Skip to content

Commit

Permalink
Add config option for filters logging on startup (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid authored May 28, 2022
1 parent e00d213 commit a3737b3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ Filter accounts:

```json
{
"account": ["83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri", "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"]
"account": [
"83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri",
"vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"
]
}
```

Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"libpath": "libsolana_geyser_sqs.so",
"log": {
"level": "info"
"level": "info",
"filters": true
},
"sqs": {
"url": "https://sqs.us-east-2.amazonaws.com/<account_id>/<accounts_queue>",
Expand Down
15 changes: 9 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ impl Config {
#[serde(deny_unknown_fields)]
pub struct ConfigLog {
pub level: Option<String>,
/// Log filters on startup.
#[serde(default)]
pub filters: bool,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -108,8 +111,8 @@ pub struct ConfigSlots {

#[derive(Debug, Default, Clone)]
pub struct ConfigAccountsFilter {
pub owner: HashSet<Pubkey>,
pub account: HashSet<Pubkey>,
pub owner: HashSet<Pubkey>,
pub data_size: HashSet<usize>,
pub tokenkeg_owner: HashSet<Pubkey>,
pub tokenkeg_delegate: HashSet<Pubkey>,
Expand All @@ -123,8 +126,8 @@ impl<'de> Deserialize<'de> for ConfigAccountsFilter {
#[derive(Debug, Default, PartialEq, Eq, Deserialize)]
#[serde(default, deny_unknown_fields)]
struct ConfigAccountsFilterRaw {
owner: HashSet<String>,
account: HashSet<String>,
owner: HashSet<String>,
data_size: HashSet<usize>,
tokenkeg_owner: HashSet<String>,
tokenkeg_delegate: HashSet<String>,
Expand All @@ -142,14 +145,14 @@ impl<'de> Deserialize<'de> for ConfigAccountsFilter {
..Default::default()
};

for pubkey in raw.owner.into_iter() {
for pubkey in raw.account.into_iter() {
let pubkey = pubkey.parse().map_err(de::Error::custom)?;
filter.owner.insert(pubkey);
filter.account.insert(pubkey);
}

for pubkey in raw.account.into_iter() {
for pubkey in raw.owner.into_iter() {
let pubkey = pubkey.parse().map_err(de::Error::custom)?;
filter.account.insert(pubkey);
filter.owner.insert(pubkey);
}

for pubkey in raw.tokenkeg_owner.into_iter() {
Expand Down
20 changes: 10 additions & 10 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use {
#[derive(Debug, Default, Clone)]
pub struct AccountsFilter {
filters: Vec<String>,
owner: HashMap<Pubkey, HashSet<String>>,
owner_required: HashSet<String>,
account: HashMap<Pubkey, HashSet<String>>,
account_required: HashSet<String>,
owner: HashMap<Pubkey, HashSet<String>>,
owner_required: HashSet<String>,
data_size: HashMap<usize, HashSet<String>>,
data_size_required: HashSet<String>,
tokenkeg_owner: HashMap<Pubkey, HashSet<String>>,
Expand All @@ -33,18 +33,18 @@ impl AccountsFilter {
let mut this = Self::default();
for (name, filter) in filters {
this.filters.push(name.clone());
Self::set(
&mut this.owner,
&mut this.owner_required,
&name,
filter.owner,
);
Self::set(
&mut this.account,
&mut this.account_required,
&name,
filter.account,
);
Self::set(
&mut this.owner,
&mut this.owner_required,
&name,
filter.owner,
);
Self::set(
&mut this.data_size,
&mut this.data_size_required,
Expand Down Expand Up @@ -117,8 +117,8 @@ impl AccountsFilter {
pub fn create_match(&self) -> AccountsFilterMatch {
AccountsFilterMatch {
accounts_filter: self,
owner: HashSet::new(),
account: HashSet::new(),
owner: HashSet::new(),
data_size: HashSet::new(),
tokenkeg_owner: HashSet::new(),
tokenkeg_delegate: HashSet::new(),
Expand All @@ -129,8 +129,8 @@ impl AccountsFilter {
#[derive(Debug)]
pub struct AccountsFilterMatch<'a> {
accounts_filter: &'a AccountsFilter,
pub owner: HashSet<&'a str>,
pub account: HashSet<&'a str>,
pub owner: HashSet<&'a str>,
pub data_size: HashSet<&'a str>,
pub tokenkeg_owner: HashSet<&'a str>,
pub tokenkeg_delegate: HashSet<&'a str>,
Expand Down
13 changes: 8 additions & 5 deletions src/sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,12 @@ impl AwsSqsClient {
let (client, queue_url) = Self::create_sqs(config.sqs)?;
let is_slot_messages_enabled = config.slots.enabled;
let accounts_filter = AccountsFilter::new(config.accounts_filters);
log::info!("Sqs accounts filters: {:#?}", accounts_filter);
let transactions_filter = TransactionsFilter::new(config.transactions_filter);
log::info!("Sqs transactions filter: {:#?}", transactions_filter);
if config.log.filters {
log::info!("Sqs slots messages enabled: {}", is_slot_messages_enabled);
log::info!("Sqs accounts filters: {:#?}", accounts_filter);
log::info!("Sqs transactions filter: {:#?}", transactions_filter);
}

// Save required Tokenkeg Accounts
let mut tokenkeg_owner_accounts: HashMap<Pubkey, ReplicaAccountInfo> = HashMap::new();
Expand Down Expand Up @@ -471,15 +474,15 @@ impl AwsSqsClient {
for account in accounts {
let mut filters = accounts_filter.create_match();

filters
.account
.extend(accounts_filter.match_account(&account.pubkey).iter());
filters
.owner
.extend(accounts_filter.match_owner(&account.owner).iter());
filters
.data_size
.extend(accounts_filter.match_data_size(account.data.len()).iter());
filters
.account
.extend(accounts_filter.match_account(&account.pubkey).iter());

if accounts_filter.match_tokenkeg(account) {
let owner = account.token_owner().expect("valid tokenkeg");
Expand Down

0 comments on commit a3737b3

Please sign in to comment.