Search in sources :

Example 1 with Bloom

use of org.aion.base.Bloom in project aion by aionnetwork.

the class BlockUtil method calcLogBloom.

public static byte[] calcLogBloom(List<AionTxReceipt> receipts) {
    Objects.requireNonNull(receipts);
    if (receipts.isEmpty()) {
        return new byte[Bloom.SIZE];
    }
    Bloom retBloomFilter = new Bloom();
    for (AionTxReceipt receipt : receipts) {
        retBloomFilter.or(receipt.getBloomFilter());
    }
    return retBloomFilter.getBloomFilterBytes();
}
Also used : Bloom(org.aion.base.Bloom) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 2 with Bloom

use of org.aion.base.Bloom in project aion by aionnetwork.

the class BloomFilterTest method testCompositeBloomFiltering.

@Test
public void testCompositeBloomFiltering() {
    AionAddress addr = AddressUtils.wrapAddress("BEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEFFFF");
    byte[] someEvent = HashUtil.h256(BigInteger.ONE.toByteArray());
    byte[] anotherEvent = HashUtil.h256(BigInteger.TWO.toByteArray());
    Bloom bloom = BloomFilter.create(addr.toByteArray(), someEvent, anotherEvent);
    assertThat(BloomFilter.containsAddress(bloom, addr)).isTrue();
    assertThat(BloomFilter.containsEvent(bloom, someEvent)).isTrue();
    // test filtering composite
    Bloom compositeTargetBloom = BloomFilter.create(someEvent, anotherEvent);
    assertThat(BloomFilter.contains(bloom, compositeTargetBloom)).isTrue();
}
Also used : AionAddress(org.aion.types.AionAddress) Bloom(org.aion.base.Bloom) Test(org.junit.Test) BlockchainIntegrationTest(org.aion.zero.impl.blockchain.BlockchainIntegrationTest)

Example 3 with Bloom

use of org.aion.base.Bloom in project aion by aionnetwork.

the class BloomFilterTest method testContainsEvent.

@Test
public void testContainsEvent() {
    byte[] someEvent = HashUtil.h256(BigInteger.TEN.toByteArray());
    Bloom bloom = BloomFilter.create(someEvent);
    assertThat(BloomFilter.containsEvent(bloom, someEvent)).isTrue();
}
Also used : Bloom(org.aion.base.Bloom) Test(org.junit.Test) BlockchainIntegrationTest(org.aion.zero.impl.blockchain.BlockchainIntegrationTest)

Example 4 with Bloom

use of org.aion.base.Bloom in project aion by aionnetwork.

the class FltrLg method onBlock.

// -------------------------------------------------------------------------------
@Override
public boolean onBlock(BlockSummary bs) {
    List<AionTxReceipt> receipts = ((AionBlockSummary) bs).getReceipts();
    Block blk = bs.getBlock();
    if (matchBloom(new Bloom(blk.getLogBloom()))) {
        int txIndex = 0;
        for (AionTxReceipt receipt : receipts) {
            AionTransaction tx = receipt.getTransaction();
            // The if condition checks the contract create and call transactions
            if ((tx.getDestinationAddress() != null && matchesContractAddress(tx.getDestinationAddress().toByteArray())) || tx.isContractCreationTransaction()) {
                if (matchBloom(receipt.getBloomFilter())) {
                    int logIndex = 0;
                    for (Log logInfo : receipt.getLogInfoList()) {
                        if (matchBloom(LogUtility.createBloomFilterForLog(logInfo)) && matchesExactly(logInfo)) {
                            add(new EvtLg(new TxRecptLg(logInfo, blk, txIndex, receipt.getTransaction(), logIndex, true)));
                        }
                        logIndex++;
                    }
                }
            }
            txIndex++;
        }
    }
    return true;
}
Also used : AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.types.Log) Bloom(org.aion.base.Bloom) Block(org.aion.zero.impl.types.Block) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 5 with Bloom

use of org.aion.base.Bloom in project aion by aionnetwork.

the class FltrLg method initBlooms.

// -------------------------------------------------------------------------------
private void initBlooms() {
    if (filterBlooms != null)
        return;
    List<byte[][]> addrAndTopics = new ArrayList<>(topics);
    addrAndTopics.add(contractAddresses);
    filterBlooms = new Bloom[addrAndTopics.size()][];
    for (int i = 0; i < addrAndTopics.size(); i++) {
        byte[][] orTopics = addrAndTopics.get(i);
        if (orTopics == null || orTopics.length == 0) {
            // always matches
            filterBlooms[i] = new Bloom[] { new Bloom() };
        } else {
            filterBlooms[i] = new Bloom[orTopics.length];
            for (int j = 0; j < orTopics.length; j++) {
                filterBlooms[i][j] = BloomFilter.create(orTopics[j]);
            }
        }
    }
}
Also used : Bloom(org.aion.base.Bloom) ArrayList(java.util.ArrayList)

Aggregations

Bloom (org.aion.base.Bloom)14 Test (org.junit.Test)9 AionTxReceipt (org.aion.base.AionTxReceipt)8 ArrayList (java.util.ArrayList)5 AionTxExecSummary (org.aion.base.AionTxExecSummary)5 BlockchainIntegrationTest (org.aion.zero.impl.blockchain.BlockchainIntegrationTest)5 AionTransaction (org.aion.base.AionTransaction)2 AionAddress (org.aion.types.AionAddress)2 Log (org.aion.types.Log)2 BigInteger (java.math.BigInteger)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)1 Block (org.aion.zero.impl.types.Block)1 RetValidPreBlock (org.aion.zero.impl.types.RetValidPreBlock)1