From 3b38e9cd9a87a2a20f284950f83f60a3bd473def Mon Sep 17 00:00:00 2001 From: nicksavers Date: Mon, 7 Jul 2014 23:43:22 +0200 Subject: [PATCH] Do state-test after adding block to blockchain --- .../src/main/java/org/ethereum/core/Blockchain.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 91807205..24cb8a7e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java @@ -110,6 +110,15 @@ public class Blockchain { } for (int i = blocks.size() - 1; i >= 0 ; --i) { this.addBlock(blocks.get(i)); + + /* Debug check to see if the state is still as expected */ + if(logger.isWarnEnabled()) { + String blockStateRootHash = Hex.toHexString(blocks.get(i).getStateRoot()); + String worldStateRootHash = Hex.toHexString(WorldManager.getInstance().getRepository().getWorldState().getRootHash()); + if(!blockStateRootHash.equals(worldStateRootHash)) + logger.warn("WARNING: STATE CONFLICT! worldstate {} mismatch", worldStateRootHash); + } + } // Remove all wallet transactions as they already approved by the net for (Block block : blocks) { @@ -135,7 +144,7 @@ public class Blockchain { this.updateGasPrice(block); this.setLastBlock(block); if (logger.isDebugEnabled()) - logger.debug("block added to the chain with hash: {}", Hex.toHexString(block.getHash())); + logger.debug("block added {}", block.toFlatString()); } else { logger.warn("Invalid block with nr: {}", block.getNumber()); }