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;
}
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;
}
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);
}
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;
}
Aggregations