diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java index 972c2744..93b68e9a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java @@ -5,6 +5,7 @@ import org.ethereum.db.BlockStore; import org.ethereum.facade.Blockchain; import org.ethereum.facade.Repository; import org.ethereum.listener.EthereumListener; +import org.ethereum.manager.AdminInfo; import org.ethereum.manager.WorldManager; import org.ethereum.net.BlockQueue; import org.ethereum.net.server.ChannelManager; @@ -96,6 +97,9 @@ public class BlockchainImpl implements Blockchain { @Autowired ProgramInvokeFactory programInvokeFactory; + @Autowired + private AdminInfo adminInfo; + private List altChains = new ArrayList<>(); private List garbage = new ArrayList<>(); @@ -381,6 +385,7 @@ public class BlockchainImpl implements Blockchain { if(!blockStateRootHash.equals(worldStateRootHash)){ stateLogger.warn("BLOCK: STATE CONFLICT! block: {} worldstate {} mismatch", block.getNumber(), worldStateRootHash); + adminInfo.lostConsensus(); // in case of rollback hard move the root // Block parentBlock = blockStore.getBlockByHash(block.getParentHash()); @@ -583,8 +588,9 @@ public class BlockchainImpl implements Blockchain { byte[] contractAddress, byte[] coinbase, boolean initResults) { if (result.getException() != null) { - stateLogger.debug("contract run halted by OutOfGas: contract={}", - Hex.toHexString(contractAddress)); + stateLogger.debug("contract run halted by Exception: contract: [{}], exception: [{}]", + Hex.toHexString(contractAddress), + result.getException()); throw result.getException(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/facade/Ethereum.java b/ethereumj-core/src/main/java/org/ethereum/facade/Ethereum.java index 635b123a..9033421c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/facade/Ethereum.java +++ b/ethereumj-core/src/main/java/org/ethereum/facade/Ethereum.java @@ -3,8 +3,10 @@ package org.ethereum.facade; import org.ethereum.core.Transaction; import org.ethereum.core.Wallet; import org.ethereum.listener.EthereumListener; +import org.ethereum.manager.AdminInfo; import org.ethereum.net.client.PeerClient; import org.ethereum.net.peerdiscovery.PeerInfo; +import org.ethereum.net.server.ChannelManager; import java.math.BigInteger; import java.net.InetAddress; @@ -128,6 +130,8 @@ public interface Ethereum { public void init(); // 2. // is blockchain still loading - if buffer is not empty + public AdminInfo getAdminInfo(); + public ChannelManager getChannelManager(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java index 4a63481b..d1fc4593 100644 --- a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java @@ -11,9 +11,11 @@ import org.ethereum.config.SystemProperties; import org.ethereum.core.Transaction; import org.ethereum.core.Wallet; import org.ethereum.listener.EthereumListener; +import org.ethereum.manager.AdminInfo; import org.ethereum.manager.WorldManager; import org.ethereum.net.client.PeerClient; import org.ethereum.net.peerdiscovery.PeerInfo; +import org.ethereum.net.server.ChannelManager; import org.ethereum.net.server.PeerServer; import org.ethereum.net.submit.TransactionExecutor; import org.ethereum.net.submit.TransactionTask; @@ -42,6 +44,12 @@ public class EthereumImpl implements Ethereum { @Autowired WorldManager worldManager; + @Autowired + AdminInfo adminInfo; + + @Autowired + ChannelManager channelManager; + @Autowired PeerServer peerServer; @@ -227,6 +235,13 @@ public class EthereumImpl implements Ethereum { return worldManager.getRepository(); } + @Override + public AdminInfo getAdminInfo() { + return adminInfo; + } - + @Override + public ChannelManager getChannelManager() { + return channelManager; + } } diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java b/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java new file mode 100644 index 00000000..30620ca2 --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java @@ -0,0 +1,37 @@ +package org.ethereum.manager; + +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +/** + * www.ethergit.com + * + * @author: Roman Mandeleil + * Created on: 11/12/2014 11:24 + */ +@Component +public class AdminInfo { + + + private long startupTimeStamp; + private boolean consensus = true; + + + @PostConstruct + public void init() { + startupTimeStamp = System.currentTimeMillis(); + } + + public long getStartupTimeStamp() { + return startupTimeStamp; + } + + public boolean isConsensus() { + return consensus; + } + + public void lostConsensus(){ + consensus = false; + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java b/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java index ea481f3e..2e1bcefc 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/WorldManager.java @@ -54,6 +54,9 @@ public class WorldManager { @Autowired private ChannelManager channelManager; + + @Autowired + private AdminInfo adminInfo; private final Set pendingTransactions = Collections.synchronizedSet(new HashSet()); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/server/Channel.java b/ethereumj-core/src/main/java/org/ethereum/net/server/Channel.java index 0341bea3..adee1c27 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/server/Channel.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/server/Channel.java @@ -46,6 +46,7 @@ public class Channel { MessageEncoder messageEncoder; + private long startupTS; public Channel() { @@ -55,6 +56,8 @@ public class Channel { p2pHandler.setMsgQueue(msgQueue); ethHandler.setMsgQueue(msgQueue); shhHandler.setMsgQueue(msgQueue); + + startupTS = System.currentTimeMillis(); } public P2pHandler getP2pHandler() { @@ -101,4 +104,7 @@ public class Channel { ethHandler.doSync(); } + public long getStartupTS() { + return startupTS; + } } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/server/ChannelManager.java b/ethereumj-core/src/main/java/org/ethereum/net/server/ChannelManager.java index 6e55923c..56adc75c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/server/ChannelManager.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/server/ChannelManager.java @@ -111,4 +111,8 @@ public class ChannelManager { } bestChannel.ethSync(); } + + public List getChannels() { + return channels; + } } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java index eb11c6f9..2bfe5f2d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java @@ -343,7 +343,10 @@ public class Program { if (result != null && result.getException() != null && result.getException() instanceof Program.OutOfGasException) { - logger.info("contract run halted by OutOfGas: new contract init ={}" , Hex.toHexString(newAddress)); + logger.debug("contract run halted by Exception: contract: [{}], exception: [{}]", + Hex.toHexString(newAddress), + result.getException()); + track.rollback(); stackPushZero(); @@ -443,7 +446,10 @@ public class Program { if (result != null && result.getException() != null && result.getException() instanceof Program.OutOfGasException) { - gasLogger.info("contract run halted by OutOfGas: contract={}" , Hex.toHexString(contextAddress)); + gasLogger.debug("contract run halted by Exception: contract: [{}], exception: [{}]", + Hex.toHexString(contextAddress), + result.getException()); + trackRepository.rollback(); stackPushZero();