use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class BlockPropagationHandler method processIncomingBlock.
public PropStatus processIncomingBlock(final int nodeId, final AionBlock block) {
if (block == null)
return PropStatus.DROPPED;
ByteArrayWrapper hashWrapped = new ByteArrayWrapper(block.getHash());
if (!this.blockHeaderValidator.validate(block.getHeader(), log))
return PropStatus.DROPPED;
// guarantees if multiple requests of same block appears, only one goes through
synchronized (this.cacheMap) {
if (this.cacheMap.containsKey(hashWrapped))
return PropStatus.DROPPED;
// regardless if block processing is successful, place into cache
this.cacheMap.put(hashWrapped, true);
}
AionBlock bestBlock = this.blockchain.getBestBlock();
// assumption is that we are on the correct chain
if (bestBlock.getNumber() > block.getNumber())
return PropStatus.DROPPED;
// this implies we only propagate blocks from our own chain
if (!bestBlock.isParentOf(block))
return PropStatus.DROPPED;
// send
boolean sent = send(block, nodeId);
// process
ImportResult result = this.blockchain.tryToConnect(block);
// process resulting state
if (sent && result.isSuccessful())
return PropStatus.PROP_CONNECTED;
if (result.isSuccessful())
return PropStatus.CONNECTED;
if (sent)
return PropStatus.PROPAGATED;
// should never reach here, but just in case
return PropStatus.DROPPED;
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method submitBlock.
// AION Mining Pool
// TODO Test multiple threads submitting blocks
synchronized boolean submitBlock(Solution solution) {
AionBlock block = (AionBlock) solution.getBlock();
// set the nonce and solution
block.getHeader().setNonce(solution.getNonce());
block.getHeader().setSolution(solution.getSolution());
block.getHeader().setTimestamp(solution.getTimeStamp());
// This can be improved
return (AionImpl.inst().addNewMinedBlock(block)).isSuccessful();
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getTransactionByHash.
public Object eth_getTransactionByHash(String _txHash) {
byte[] txHash = ByteUtil.hexStringToBytes(_txHash);
if (_txHash == null || txHash == null)
return null;
AionTxInfo txInfo = this.ac.getAionHub().getBlockchain().getTransactionInfo(txHash);
if (txInfo == null)
return null;
AionBlock b = this.ac.getBlockchain().getBlockByHash(txInfo.getBlockHash());
if (b == null)
return null;
return Tx.InfoToJSON(txInfo, b);
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getBlockByNumber.
public Object eth_getBlockByNumber(String _bnOrId, boolean _fullTx) {
Long bn = this.parseBnOrId(_bnOrId);
if (bn == null || bn < 0)
return null;
AionBlock nb = this.ac.getBlockchain().getBlockByNumber(bn);
if (nb == null) {
LOG.debug("<get-block bn={} err=not-found>");
return null;
} else {
BigInteger totalDiff = this.ac.getAionHub().getBlockStore().getTotalDifficultyForHash(nb.getHash());
return Blk.AionBlockToJson(nb, totalDiff, _fullTx);
}
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getBlockByHash.
public Object eth_getBlockByHash(String _hashString, boolean _fullTx) {
byte[] hash = ByteUtil.hexStringToBytes(_hashString);
AionBlock block = this.ac.getBlockchain().getBlockByHash(hash);
BigInteger totalDiff = this.ac.getAionHub().getBlockStore().getTotalDifficultyForHash(hash);
if (block == null) {
LOG.debug("<get-block bn={} err=not-found>");
return null;
} else {
try {
return Blk.AionBlockToJson(block, totalDiff, _fullTx);
} catch (Exception ex) {
if (LOG.isDebugEnabled())
LOG.debug("<get-block bh={} err=exception>", _hashString);
return null;
}
}
}
Aggregations