diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java index 34a532e0..4dcb8e25 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java @@ -147,6 +147,20 @@ public class Blockchain { if (listener != null) listener.trace(String.format("Block chain size: [ %d ]", this.getSize())); + EthereumListener ethereumListener = WorldManager.getInstance().getListener(); + if (ethereumListener != null) + ethereumListener.onBlock(block); + +/* + if (lastBlock.getNumber() >= 30) { + System.out.println("** checkpoint **"); + + this.close(); + WorldManager.getInstance().getRepository().close(); + System.exit(1); + } +*/ + } public void processBlock(Block block) { diff --git a/ethereumj-core/src/main/java/org/ethereum/listener/EthereumListener.java b/ethereumj-core/src/main/java/org/ethereum/listener/EthereumListener.java index 0a0d3543..51f14985 100644 --- a/ethereumj-core/src/main/java/org/ethereum/listener/EthereumListener.java +++ b/ethereumj-core/src/main/java/org/ethereum/listener/EthereumListener.java @@ -1,5 +1,7 @@ package org.ethereum.listener; +import org.ethereum.core.Block; + /** * www.ethereumJ.com * @@ -10,4 +12,5 @@ package org.ethereum.listener; public interface EthereumListener { public void trace(String output); + public void onBlock(Block block); } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java index 50431bc3..682477c3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java @@ -66,6 +66,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { logger.info("Send: " + StaticMessages.HELLO_MESSAGE.toString()); msgQueue.sendMessage(StaticMessages.HELLO_MESSAGE); + sendPing(); // sample for pinging in background timer.scheduleAtFixedRate(new TimerTask() { @@ -249,6 +250,8 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { RLPList rlpList = RLP.decode2(payload); GetChainMessage getChainMessage = new GetChainMessage(rlpList); + + logger.info(getChainMessage.toString()); if (peerListener != null) peerListener.console(getChainMessage.toString()); } @@ -323,6 +326,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { SystemProperties.CONFIG.maxBlocksQueued()) return; Block lastBlock = WorldManager.getInstance().getBlockchain().getBlockQueue().getLast(); + if (lastBlock == null) return; byte[] hash = lastBlock.getHash(); GetChainMessage chainMessage =