llamanodes / web3-proxy

Fast loadbalancing and caching proxy for Ethereum or chains with similar JSON-RPC methods
https://llamanodes.com
GNU General Public License v3.0
153 stars 34 forks source link

add bloom filter to payment received endpoint #110

Open yenicelik opened 1 year ago

yenicelik commented 1 year ago

A first version is already there, but it's not working properly. I'm actually unsure if bloom filters have a 100% search guarantee.


    let payment_factory_address = app
        .config
        .deposit_factory_contract
        .context("A deposit_contract must be provided in the config to parse payments")?;

    let payment_factory_contract =
        PaymentFactory::new(payment_factory_address, app.internal_provider().clone());

    // check bloom filter to be sure this transaction contains any relevant logs
    if let Some(ValueOrArray::Value(Some(x))) = payment_factory_contract
        .payment_received_filter()
        .filter
        .topics[0]
    {
        let bloom_input = BloomInput::Hash(x.as_fixed_bytes());

        // do a quick check that this transaction contains the required log
        if !transaction_receipt.logs_bloom.contains_input(bloom_input) {
            return Err(Web3ProxyError::BadRequest("no matching logs found".into()));
        }
    }
BlinkyStitt commented 1 year ago

There are false positives, but never false negatives

BlinkyStitt commented 1 year ago

We can save this for after launch