diff --git a/README.md b/README.md index 0f30e9a..a5ef613 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,10 @@ Filter accounts: ```json { - "account": ["83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri", "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"] + "account": [ + "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri", + "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg" + ] } ``` diff --git a/config.json b/config.json index c3780d0..6cfe806 100644 --- a/config.json +++ b/config.json @@ -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>", diff --git a/src/config.rs b/src/config.rs index 9df0918..b6891c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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)] @@ -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>, @@ -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>, @@ -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() { diff --git a/src/filter.rs b/src/filter.rs index 126fa1c..dc51b38 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -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>>, @@ -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, @@ -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(), @@ -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>, diff --git a/src/sqs.rs b/src/sqs.rs index 89bdbe7..9cc7b99 100644 --- a/src/sqs.rs +++ b/src/sqs.rs @@ -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(); @@ -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");