Skip to content

Commit

Permalink
Added CLI command for querying block/transaction/account details
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Jun 17, 2019
1 parent 36e98a2 commit e9c4546
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 65 deletions.
44 changes: 24 additions & 20 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,6 @@ public AionBlockSummary add(AionBlock block) {
}

public AionBlockSummary add(AionBlock block, boolean rebuild) {

if (!isValid(block)) {
LOG.error("Attempting to add {} block.", (block == null ? "NULL" : "INVALID"));
return null;
Expand All @@ -1057,9 +1056,9 @@ public AionBlockSummary add(AionBlock block, boolean rebuild) {
if (!Arrays.equals(receiptHash, receiptListHash)) {
if (LOG.isWarnEnabled()) {
LOG.warn(
"Block's given Receipt Hash doesn't match: {} != {}",
receiptHash,
receiptListHash);
"Block's given Receipt Hash doesn't match: {} != {}",
receiptHash,
receiptListHash);
LOG.warn("Calculated receipts: " + receipts);
}
track.rollback();
Expand All @@ -1072,9 +1071,9 @@ public AionBlockSummary add(AionBlock block, boolean rebuild) {
if (!Arrays.equals(logBloomHash, logBloomListHash)) {
if (LOG.isWarnEnabled())
LOG.warn(
"Block's given logBloom Hash doesn't match: {} != {}",
ByteUtil.toHexString(logBloomHash),
ByteUtil.toHexString(logBloomListHash));
"Block's given logBloom Hash doesn't match: {} != {}",
ByteUtil.toHexString(logBloomHash),
ByteUtil.toHexString(logBloomListHash));
track.rollback();
return null;
}
Expand All @@ -1086,9 +1085,9 @@ public AionBlockSummary add(AionBlock block, boolean rebuild) {
if (!Arrays.equals(blockStateRootHash, worldStateRootHash)) {

LOG.warn(
"BLOCK: State conflict or received invalid block. block: {} worldstate {} mismatch",
block.getNumber(),
worldStateRootHash);
"BLOCK: State conflict or received invalid block. block: {} worldstate {} mismatch",
block.getNumber(),
worldStateRootHash);
LOG.warn("Conflict block dump: {}", toHexString(block.getEncoded()));

track.rollback();
Expand All @@ -1107,12 +1106,12 @@ public AionBlockSummary add(AionBlock block, boolean rebuild) {
AionTransaction tx = receipt.getTransaction();
if (tx.isContractCreationTransaction() && receipt.isSuccessful()) {
repository.saveIndexedContractInformation(
tx.getContractAddress(),
block.getNumber(),
TransactionTypeRule.isValidAVMContractDeployment(tx.getTargetVM())
? InternalVmType.AVM
: InternalVmType.FVM,
true);
tx.getContractAddress(),
block.getNumber(),
TransactionTypeRule.isValidAVMContractDeployment(tx.getTargetVM())
? InternalVmType.AVM
: InternalVmType.FVM,
true);
}
}

Expand All @@ -1126,15 +1125,20 @@ public AionBlockSummary add(AionBlock block, boolean rebuild) {

if (LOG.isDebugEnabled())
LOG.debug(
"Block rebuilt: number: {}, hash: {}, TD: {}",
block.getNumber(),
block.getShortHash(),
getBlockStore().getTotalDifficulty());
"Block rebuilt: number: {}, hash: {}, TD: {}",
block.getNumber(),
block.getShortHash(),
getBlockStore().getTotalDifficulty());
}

return summary;
}

public AionBlockSummary addNoFlush(AionBlock block) {
track = repository.startTracking();
return processBlock(block);
}

@Override
public void flush() {
repository.flush();
Expand Down
6 changes: 3 additions & 3 deletions modAionImpl/src/org/aion/zero/impl/AionHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.aion.zero.impl.config.CfgAion;
import org.aion.zero.impl.core.IAionBlockchain;
import org.aion.zero.impl.db.AionRepositoryImpl;
import org.aion.zero.impl.db.RecoveryUtils;
import org.aion.zero.impl.db.DBUtils;
import org.aion.zero.impl.pow.AionPoW;
import org.aion.zero.impl.sync.SyncMgr;
import org.aion.zero.impl.sync.handler.BlockPropagationHandler;
Expand Down Expand Up @@ -348,10 +348,10 @@ private void loadBlockchain() {
genLOG.info("Rebuild state FAILED. Reverting to previous block.");

long blockNumber = bestBlock.getNumber() - 1;
RecoveryUtils.Status status = RecoveryUtils.revertTo(this.blockchain, blockNumber);
DBUtils.Status status = DBUtils.revertTo(this.blockchain, blockNumber);

recovered =
(status == RecoveryUtils.Status.SUCCESS)
(status == DBUtils.Status.SUCCESS)
&& this.repository.isValidRoot(
this.repository
.getBlockStore()
Expand Down
30 changes: 30 additions & 0 deletions modAionImpl/src/org/aion/zero/impl/cli/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ public class Arguments {
"drops all databases except for block and index when not given a parameter or starting from 0 and redoes import of all known main chain blocks")
private String redoImport = null;

// data query
@Option(
names = {"qb", "-q block", "--query block"},
arity = "1",
paramLabel = "<block_number>",
description = "retrieve block information")
private String blockDetails = null;

@Option(
names = {"qt", "-q tx", "--query tx"},
arity = "1",
paramLabel = "<transaction hash>",
description = "retrieve transaction information")
private String TransactionDetails = null;

@Option(
names = {"qa", "-q account", "--query account"},
arity = "1",
paramLabel = "<account address>",
description = "retrieve account information")
private String AccountDetails = null;

/** Compacts the account options into specific commands. */
public static String[] preProcess(String[] arguments) {
List<String> list = new ArrayList<>();
Expand Down Expand Up @@ -282,4 +304,12 @@ public boolean isDbCompact() {
public String isRedoImport() {
return redoImport;
}

public String getBlockDetails() { return blockDetails; }

public String getTransactionDetails() { return TransactionDetails; }

public String getAccountDetails() { return AccountDetails; }


}
Loading

0 comments on commit e9c4546

Please sign in to comment.