Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up #953

Merged
merged 6 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions modAion/src/org/aion/zero/types/AionTxReceipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import static org.apache.commons.lang3.ArrayUtils.nullToEmpty;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.aion.mcf.types.AbstractTxReceipt;
import org.aion.base.AionTransaction;
import org.aion.mcf.tx.TxReceipt;
import org.aion.mcf.vm.types.Bloom;
import org.aion.mcf.vm.types.LogUtility;
import org.aion.rlp.RLP;
Expand All @@ -17,9 +19,21 @@
import org.aion.types.Log;
import org.aion.util.bytes.ByteUtil;
import org.aion.util.conversions.Hex;
import org.aion.util.types.Bytesable;

/** aion transaction receipt class. */
public class AionTxReceipt extends AbstractTxReceipt {
public class AionTxReceipt implements Bytesable<Object>, TxReceipt<Log> {
private AionTransaction transaction;

private byte[] postTxState = EMPTY_BYTE_ARRAY;

private Bloom bloomFilter = new Bloom();
private List<Log> logInfoList = new ArrayList<>();

private byte[] executionResult = EMPTY_BYTE_ARRAY;
private String error = "";
/* TX Receipt in encoded form */
private byte[] rlpEncoded;

private long energyUsed;

Expand Down Expand Up @@ -64,6 +78,74 @@ public AionTxReceipt(byte[] postTxState, Bloom bloomFilter, List<Log> logInfoLis
this.logInfoList = logInfoList;
}

public byte[] getPostTxState() {
return postTxState;
}

public byte[] getTransactionOutput() {
return executionResult;
}

public Bloom getBloomFilter() {
return bloomFilter;
}

public List<Log> getLogInfoList() {
return logInfoList;
}

public boolean isSuccessful() {
return error.isEmpty();
}

public String getError() {
return error;
}

public void setPostTxState(byte[] postTxState) {
this.postTxState = postTxState;
rlpEncoded = null;
}

public void setExecutionResult(byte[] executionResult) {
this.executionResult = executionResult;
rlpEncoded = null;
}

/**
* TX recepit 's error is empty when constructed. it use empty to identify if there are error
* msgs instead of null.
*/
public void setError(String error) {
if (error == null) {
return;
}
this.error = error;
}

public void setLogs(List<Log> logInfoList) {
if (logInfoList == null) {
return;
}
this.logInfoList = logInfoList;

for (Log loginfo : logInfoList) {
bloomFilter.or(LogUtility.createBloomFilterForLog(loginfo));
}
rlpEncoded = null;
}

public void setTransaction(AionTransaction transaction) {
this.transaction = transaction;
}

public AionTransaction getTransaction() {
if (transaction == null) {
throw new NullPointerException(
"Transaction is not initialized. Use TransactionInfo and BlockStore to setup Transaction instance");
}
return transaction;
}
/**
* Used for Receipt trie hash calculation. Should contain only the following items encoded:
* [postTxState, bloomFilter, logInfoList]
Expand Down
20 changes: 7 additions & 13 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.aion.base.AionTransaction;
import org.aion.base.TxUtil;
import org.aion.crypto.HashUtil;
import org.aion.equihash.EquihashMiner;
import org.aion.evtmgr.IEvent;
Expand All @@ -47,7 +46,7 @@
import org.aion.mcf.db.IBlockStorePow;
import org.aion.mcf.db.Repository;
import org.aion.mcf.db.RepositoryCache;
import org.aion.mcf.db.TransactionStore;
import org.aion.zero.impl.db.TransactionStore;
import org.aion.mcf.manager.ChainStatistics;
import org.aion.mcf.trie.Trie;
import org.aion.mcf.trie.TrieImpl;
Expand Down Expand Up @@ -132,7 +131,7 @@ public class AionBlockchainImpl implements IAionBlockchain {
private long exitOn = Long.MAX_VALUE;
private AionRepositoryImpl repository;
private RepositoryCache<AccountState, IBlockStoreBase> track;
private TransactionStore<AionTxReceipt, org.aion.zero.impl.types.AionTxInfo> transactionStore;
private TransactionStore transactionStore;
private Block bestBlock;
/**
* This version of the bestBlock is only used for external reference (ex. through {@link
Expand Down Expand Up @@ -451,9 +450,7 @@ public List<Block> getBlocksByRange(long first, long last) {
}

@Override
/* NOTE: only returns receipts from the main chain
*/
@SuppressWarnings("Duplicates")
/* NOTE: only returns receipts from the main chain */
public AionTxInfo getTransactionInfo(byte[] hash) {

List<AionTxInfo> infos = transactionStore.get(hash);
Expand Down Expand Up @@ -493,7 +490,6 @@ public AionTxInfo getTransactionInfo(byte[] hash) {
return txInfo;
}

@SuppressWarnings("Duplicates")
// returns transaction info (tx receipt) without the transaction embedded in it.
// saves on db reads for api when processing large transactions
public AionTxInfo getTransactionInfoLite(byte[] txHash, byte[] blockHash) {
Expand Down Expand Up @@ -1075,8 +1071,7 @@ BlockContext createNewBlockInternal(
return new BlockContext(block, baseBlockReward, totalTransactionFee);
}

@Override
public AionBlockSummary add(Block block) {
private AionBlockSummary add(Block block) {
// typical use without rebuild
AionBlockSummary summary = add(block, false);

Expand All @@ -1094,7 +1089,7 @@ public AionBlockSummary add(Block block) {
return summary;
}

public AionBlockSummary add(Block block, boolean rebuild) {
private AionBlockSummary add(Block block, boolean rebuild) {
return add(block, rebuild, true).getLeft();
}

Expand Down Expand Up @@ -1503,8 +1498,7 @@ public ChainConfiguration getChainConfiguration() {
return chainConfiguration;
}

@Override
public synchronized void storeBlock(Block block, List<AionTxReceipt> receipts) {
private void storeBlock(Block block, List<AionTxReceipt> receipts) {

if (fork) {
getBlockStore().saveBlock(block, totalDifficulty, false);
Expand Down Expand Up @@ -1593,7 +1587,7 @@ public boolean hasParentOnTheChain(Block block) {
return getParent(block.getHeader()) != null;
}

public TransactionStore<AionTxReceipt, AionTxInfo> getTransactionStore() {
public TransactionStore getTransactionStore() {
return transactionStore;
}

Expand Down
6 changes: 2 additions & 4 deletions modAionImpl/src/org/aion/zero/impl/AionHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import org.aion.zero.impl.sync.handler.ResBlocksBodiesHandler;
import org.aion.zero.impl.sync.handler.ResBlocksHeadersHandler;
import org.aion.zero.impl.sync.handler.ResStatusHandler;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.types.A0BlockHeader;
import org.slf4j.Logger;

public class AionHub {
Expand All @@ -60,7 +58,7 @@ public class AionHub {

private BlockPropagationHandler propHandler;

private IPendingStateInternal<AionBlock> mempool;
private IPendingStateInternal mempool;

private IAionBlockchain blockchain;

Expand Down Expand Up @@ -278,7 +276,7 @@ public IBlockStorePow getBlockStore() {
return this.repository.getBlockStore();
}

public IPendingStateInternal<AionBlock> getPendingState() {
public IPendingStateInternal getPendingState() {
return mempool;
}

Expand Down
3 changes: 1 addition & 2 deletions modAionImpl/src/org/aion/zero/impl/blockchain/AionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;
import java.util.Optional;
import org.aion.base.AionTransaction;
import org.aion.base.TxUtil;
import org.aion.crypto.ECKey;
import org.aion.crypto.ECKeyFac;
import org.aion.equihash.EquihashMiner;
Expand Down Expand Up @@ -220,7 +219,7 @@ public AionHub getAionHub() {
return aionHub;
}

private IPendingStateInternal<?> getIPendingStateInternal() {
private IPendingStateInternal getIPendingStateInternal() {
return this.aionHub.getPendingState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.aion.mcf.db.IBlockStoreBase;
import org.aion.mcf.db.Repository;
import org.aion.mcf.db.RepositoryCache;
import org.aion.mcf.db.TransactionStore;
import org.aion.mcf.evt.IListenerBase.PendingTransactionState;
import org.aion.mcf.types.PendingTransactionState;
import org.aion.zero.impl.db.TransactionStore;
import org.aion.mcf.valid.TransactionTypeRule;
import org.aion.mcf.valid.TxNrgRule;
import org.aion.p2p.INode;
Expand All @@ -69,7 +69,7 @@
import org.aion.zero.types.AionTxReceipt;
import org.slf4j.Logger;

public class AionPendingStateImpl implements IPendingStateInternal<AionBlock> {
public class AionPendingStateImpl implements IPendingStateInternal {

private static final Logger LOGGER_TX = AionLoggerFactory.getLogger(LogEnum.TX.toString());
private static final Logger LOGGER_VM = AionLoggerFactory.getLogger(LogEnum.VM.toString());
Expand Down Expand Up @@ -101,7 +101,7 @@ public TransactionSortedSet() {

private IAionBlockchain blockchain;

private TransactionStore<AionTxReceipt, AionTxInfo> transactionStore;
private TransactionStore transactionStore;

private Repository repository;

Expand Down Expand Up @@ -815,7 +815,6 @@ private Block findCommonAncestor(Block b1, Block b2) {
return b1;
}

@Override
public synchronized void processBest(AionBlock newBlock, List receipts) {

if (isSeed) {
Expand Down
9 changes: 4 additions & 5 deletions modAionImpl/src/org/aion/zero/impl/core/IAionBlockchain.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import org.aion.util.types.ByteArrayWrapper;
import org.aion.zero.impl.BlockContext;
import org.aion.zero.impl.sync.DatabaseType;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionBlockSummary;
import org.aion.zero.impl.types.AionTxInfo;
import org.aion.zero.types.A0BlockHeader;
import org.aion.zero.types.AionTxReceipt;

/** aion blockchain interface. */
public interface IAionBlockchain
extends IBlockchain<AionTxReceipt, AionTxInfo> {
public interface IAionBlockchain extends IBlockchain {

AionTxInfo getTransactionInfo(byte[] hash);

Block createNewBlock(
Block parent, List<AionTransaction> transactions, boolean waitUntilBlockTime);
Expand Down
9 changes: 3 additions & 6 deletions modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.aion.mcf.db.Repository;
import org.aion.mcf.db.RepositoryCache;
import org.aion.mcf.db.RepositoryConfig;
import org.aion.mcf.db.TransactionStore;
import org.aion.mcf.ds.ObjectDataSource;
import org.aion.mcf.ds.XorDataSource;
import org.aion.mcf.trie.SecureTrie;
Expand All @@ -46,15 +45,13 @@
import org.aion.zero.impl.SystemExitCodes;
import org.aion.zero.impl.config.CfgAion;
import org.aion.zero.impl.sync.DatabaseType;
import org.aion.zero.impl.types.AionTxInfo;
import org.aion.zero.types.AionTxReceipt;
import org.apache.commons.lang3.tuple.Pair;

/** Has direct database connection. */
public class AionRepositoryImpl
extends AbstractRepository<AionBlockStore> {

private TransactionStore<AionTxReceipt, AionTxInfo> transactionStore;
private TransactionStore transactionStore;

// pending block store
private PendingBlockStore pendingStore;
Expand Down Expand Up @@ -89,7 +86,7 @@ private void init() {

// Setup the cache for transaction data source.
this.transactionStore =
new TransactionStore<>(
new TransactionStore(
transactionDatabase, AionTransactionStoreSerializer.serializer);

// Setup block store.
Expand All @@ -115,7 +112,7 @@ public PendingBlockStore getPendingBlockStore() {
}

/** @implNote The transaction store is not locked within the repository implementation. */
public TransactionStore<AionTxReceipt, AionTxInfo> getTransactionStore() {
public TransactionStore getTransactionStore() {
return this.transactionStore;
}

Expand Down
Loading