Search in sources :

Example 1 with Bloom

use of org.aion.mcf.vm.types.Bloom in project aion by aionnetwork.

the class FltrLg method onBlock.

// -------------------------------------------------------------------------------
@Override
public boolean onBlock(IBlockSummary bs) {
    List<AionTxReceipt> receipts = ((AionBlockSummary) bs).getReceipts();
    IBlock blk = bs.getBlock();
    if (matchBloom(new Bloom(((IAionBlock) blk).getLogBloom()))) {
        int txIndex = 0;
        for (AionTxReceipt receipt : receipts) {
            ITransaction tx = receipt.getTransaction();
            if (matchesContractAddress(tx.getTo().toBytes())) {
                if (matchBloom(receipt.getBloomFilter())) {
                    int logIndex = 0;
                    for (Log logInfo : receipt.getLogInfoList()) {
                        if (matchBloom(logInfo.getBloom()) && 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.mcf.vm.types.Log) Bloom(org.aion.mcf.vm.types.Bloom) IAionBlock(org.aion.zero.types.IAionBlock) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Example 2 with Bloom

use of org.aion.mcf.vm.types.Bloom in project aion by aionnetwork.

the class FltrLg method onBlock.

// inelegant (distributing chain singleton ref. into here), tradeoff for efficiency and ease of impl.
// rationale: this way, we only retrieve logs from DB for transactions that the bloom
// filter gives a positive match for;
public boolean onBlock(IAionBlock blk, IAionBlockchain chain) {
    if (matchBloom(new Bloom(blk.getLogBloom()))) {
        int txIndex = 0;
        for (ITransaction txn : blk.getTransactionsList()) {
            if (matchesContractAddress(txn.getTo().toBytes())) {
                // now that we know that our filter might match with some logs in this transaction, go ahead
                // and retrieve the txReceipt from the chain
                AionTxInfo txInfo = chain.getTransactionInfo(txn.getHash());
                AionTxReceipt receipt = txInfo.getReceipt();
                if (matchBloom(receipt.getBloomFilter())) {
                    int logIndex = 0;
                    for (Log logInfo : receipt.getLogInfoList()) {
                        if (matchBloom(logInfo.getBloom()) && matchesExactly(logInfo)) {
                            add(new EvtLg(new TxRecptLg(logInfo, blk, txIndex, txn, logIndex, true)));
                        }
                        logIndex++;
                    }
                }
            }
            txIndex++;
        }
    }
    return true;
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) Log(org.aion.mcf.vm.types.Log) Bloom(org.aion.mcf.vm.types.Bloom) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Example 3 with Bloom

use of org.aion.mcf.vm.types.Bloom in project aion by aionnetwork.

the class AionTxExecSummaryTest method testRLPEncoding.

@Test
public void testRLPEncoding() {
    AionTransaction mockTx = new AionTransaction(BigInteger.ONE.toByteArray(), defaultAddress, defaultAddress, BigInteger.ONE.toByteArray(), HashUtil.EMPTY_DATA_HASH, 1L, 1L);
    AionTxReceipt txReceipt = new AionTxReceipt(HashUtil.EMPTY_TRIE_HASH, new Bloom(), Collections.EMPTY_LIST);
    txReceipt.setNrgUsed(1);
    txReceipt.setTransaction(mockTx);
    AionTxExecSummary.Builder builder = AionTxExecSummary.builderFor(txReceipt);
    builder.markAsFailed().result(new byte[0]);
    AionTxExecSummary summary = builder.build();
    byte[] encodedSummary = summary.getEncoded();
    AionTxExecSummary newSummary = new AionTxExecSummary(encodedSummary);
    newSummary.getReceipt().setTransaction(mockTx);
    assertThat(newSummary.getFee()).isEqualTo(BigInteger.ONE);
}
Also used : Bloom(org.aion.mcf.vm.types.Bloom) AionTxExecSummary(org.aion.zero.types.AionTxExecSummary) AionTransaction(org.aion.zero.types.AionTransaction) AionTxReceipt(org.aion.zero.types.AionTxReceipt) Test(org.junit.Test)

Example 4 with Bloom

use of org.aion.mcf.vm.types.Bloom in project aion by aionnetwork.

the class AionBlockchainImpl method createNewBlock.

public synchronized AionBlock createNewBlock(AionBlock parent, List<AionTransaction> txs, boolean waitUntilBlockTime) {
    long time = System.currentTimeMillis() / THOUSAND_MS;
    if (parent.getTimestamp() >= time) {
        time = parent.getTimestamp() + 1;
        while (waitUntilBlockTime && System.currentTimeMillis() / THOUSAND_MS <= time) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
    long energyLimit = this.chainConfiguration.calcEnergyLimit(parent.getHeader());
    A0BlockHeader.Builder headerBuilder = new A0BlockHeader.Builder();
    headerBuilder.withParentHash(parent.getHash()).withCoinbase(minerCoinbase).withNumber(parent.getNumber() + 1).withTimestamp(time).withExtraData(minerExtraData).withTxTrieRoot(calcTxTrie(txs)).withEnergyLimit(energyLimit);
    AionBlock block = new AionBlock(headerBuilder.build(), txs);
    block.getHeader().setDifficulty(ByteUtil.bigIntegerToBytes(this.chainConfiguration.getDifficultyCalculator().calculateDifficulty(block.getHeader(), parent.getHeader()), DIFFICULTY_BYTES));
    /*
         * Begin execution phase
         */
    pushState(parent.getHash());
    track = repository.startTracking();
    track.rollback();
    RetValidPreBlock preBlock = generatePreBlock(block);
    /*
         * Calculate the gas used for the included transactions
         */
    long totalEnergyUsed = 0;
    for (AionTxExecSummary summary : preBlock.summaries) {
        totalEnergyUsed = totalEnergyUsed + summary.getNrgUsed().longValueExact();
    }
    byte[] stateRoot = getRepository().getRoot();
    popState();
    /*
         * End execution phase
         */
    Bloom logBloom = new Bloom();
    for (AionTxReceipt receipt : preBlock.receipts) {
        logBloom.or(receipt.getBloomFilter());
    }
    block.seal(preBlock.txs, calcTxTrie(preBlock.txs), stateRoot, logBloom.getData(), calcReceiptsTrie(preBlock.receipts), totalEnergyUsed);
    return block;
}
Also used : RetValidPreBlock(org.aion.zero.impl.types.RetValidPreBlock) Bloom(org.aion.mcf.vm.types.Bloom) AionBlock(org.aion.zero.impl.types.AionBlock)

Aggregations

Bloom (org.aion.mcf.vm.types.Bloom)4 AionTxReceipt (org.aion.zero.types.AionTxReceipt)3 Log (org.aion.mcf.vm.types.Log)2 AionBlock (org.aion.zero.impl.types.AionBlock)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)1 RetValidPreBlock (org.aion.zero.impl.types.RetValidPreBlock)1 AionTransaction (org.aion.zero.types.AionTransaction)1 AionTxExecSummary (org.aion.zero.types.AionTxExecSummary)1 IAionBlock (org.aion.zero.types.IAionBlock)1 Test (org.junit.Test)1