use of org.aion.evtmgr.IEvent in project aion by aionnetwork.
the class AionBlockchainImpl method tryToConnect.
public synchronized ImportResult tryToConnect(final AionBlock block) {
long currentTimestamp = System.currentTimeMillis() / THOUSAND_MS;
if (block.getTimestamp() > (currentTimestamp + this.chainConfiguration.getConstants().getClockDriftBufferTime()))
return INVALID_BLOCK;
if (LOG.isDebugEnabled()) {
LOG.debug("Try connect block hash: {}, number: {}", Hex.toHexString(block.getHash()).substring(0, 6), block.getNumber());
}
if (getBlockStore().getMaxNumber() >= block.getNumber() && getBlockStore().isBlockExist(block.getHash())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Block already exist hash: {}, number: {}", Hex.toHexString(block.getHash()).substring(0, 6), block.getNumber());
}
// retry of well known block
return EXIST;
}
final ImportResult ret;
// The simple case got the block
// to connect to the main chain
final AionBlockSummary summary;
if (bestBlock.isParentOf(block)) {
summary = add(block);
ret = summary == null ? INVALID_BLOCK : IMPORTED_BEST;
} else {
if (getBlockStore().isBlockExist(block.getParentHash())) {
BigInteger oldTotalDiff = getTotalDifficulty();
summary = tryConnectAndFork(block);
ret = summary == null ? INVALID_BLOCK : (isMoreThan(getTotalDifficulty(), oldTotalDiff) ? IMPORTED_BEST : IMPORTED_NOT_BEST);
} else {
summary = null;
ret = NO_PARENT;
}
}
if (ret.isSuccessful()) {
if (this.evtMgr != null) {
IEvent evtOnBlock = new EventBlock(EventBlock.CALLBACK.ONBLOCK0);
evtOnBlock.setFuncArgs(Collections.singletonList(summary));
this.evtMgr.newEvent(evtOnBlock);
IEvent evtTrace = new EventBlock(EventBlock.CALLBACK.ONTRACE0);
String str = String.format("Block chain size: [ %d ]", this.getSizeInternal());
evtTrace.setFuncArgs(Collections.singletonList(str));
this.evtMgr.newEvent(evtTrace);
if (ret == IMPORTED_BEST) {
if (LOG.isTraceEnabled()) {
LOG.trace("IMPORTED_BEST");
}
IEvent evtOnBest = new EventBlock(EventBlock.CALLBACK.ONBEST0);
evtOnBest.setFuncArgs(Arrays.asList(block, summary.getReceipts()));
this.evtMgr.newEvent(evtOnBest);
}
}
}
return ret;
}
use of org.aion.evtmgr.IEvent in project aion by aionnetwork.
the class AionPendingStateImpl method fireTxUpdate.
private void fireTxUpdate(AionTxReceipt txReceipt, PendingTransactionState state, IAionBlock block) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("PendingTransactionUpdate: (Tot: %3s) %12s : %s %8s %s [%s]", getPendingTxSize(), state, txReceipt.getTransaction().getFrom().toString().substring(0, 8), ByteUtil.byteArrayToLong(txReceipt.getTransaction().getNonce()), block.getShortDescr(), txReceipt.getError()));
}
IEvent evt = new EventTx(EventTx.CALLBACK.PENDINGTXUPDATE0);
List<Object> args = new ArrayList<>();
args.add(txReceipt);
args.add(state.getValue());
args.add(block);
evt.setFuncArgs(args);
this.evtMgr.newEvent(evt);
}
use of org.aion.evtmgr.IEvent in project aion by aionnetwork.
the class AionPoW method setupHandler.
/**
* Sets up the consensus event handler.
*/
private void setupHandler() {
List<IEvent> txEvts = new ArrayList<>();
txEvts.add(new EventTx(EventTx.CALLBACK.PENDINGTXRECEIVED0));
txEvts.add(new EventTx(EventTx.CALLBACK.PENDINGTXUPDATE0));
txEvts.add(new EventTx(EventTx.CALLBACK.PENDINGTXSTATECHANGE0));
eventMgr.registerEvent(txEvts);
List<IEvent> events = new ArrayList<>();
events.add(new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE));
events.add(new EventConsensus(EventConsensus.CALLBACK.ON_SOLUTION));
eventMgr.registerEvent(events);
}
Aggregations