Race condition solved:

+  new SHA3Digest(256) - can't be shared, it's not a thread safe class
This commit is contained in:
romanman 2014-06-09 11:21:47 +01:00
parent 510baf5164
commit 899767affb
4 changed files with 21 additions and 21 deletions

View File

@ -53,9 +53,13 @@ public class Blockchain {
}
public Block getLastBlock() {
return lastBlock;
return lastBlock;
}
public void setLastBlock(Block block){
lastBlock = block;
}
public int getSize(){
return index.size();
}
@ -111,8 +115,8 @@ public class Blockchain {
// on this price will use default 10000000000000
// todo: refactor this longValue some constant defaults class 10000000000000L
this.gasPrice = block.isGenesis() ? INITIAL_MIN_GAS_PRICE : block.getMinGasPrice();
if(lastBlock == null || block.getNumber() > lastBlock.getNumber()){
this.lastBlock = block;
if(getLastBlock() == null || block.getNumber() > getLastBlock().getNumber()){
setLastBlock( block );
index.put(block.getNumber(), block.getParentHash());
}
}
@ -150,10 +154,10 @@ public class Blockchain {
}
public byte[] getLatestBlockHash(){
if (index.isEmpty())
return StaticMessages.GENESIS_HASH;
else
return lastBlock.getHash();
if (index.isEmpty())
return StaticMessages.GENESIS_HASH;
else
return getLastBlock().getHash();
}
public void loadChain() {
@ -171,8 +175,8 @@ public class Blockchain {
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
this.addBlock(new Block(db.get(parentHash)));
if (logger.isDebugEnabled())
logger.debug("Block: " + lastBlock.getNumber() + " ---> " + lastBlock.toFlatString());
parentHash = lastBlock.getHash();
logger.debug("Block: " + getLastBlock().getNumber() + " ---> " + getLastBlock().toFlatString());
parentHash = getLastBlock().getHash();
}
}
} finally {

View File

@ -7,22 +7,20 @@ import org.spongycastle.util.encoders.Hex;
public class SHA3Helper {
private static SHA3Digest DEFAULT_DIGEST_256 = new SHA3Digest(256);
public static String sha3String(String message) {
return sha3String(message, DEFAULT_DIGEST_256, true);
return sha3String(message, new SHA3Digest(256), true);
}
public static String sha3String(byte[] message) {
return sha3String(message, DEFAULT_DIGEST_256, true);
return sha3String(message, new SHA3Digest(256), true);
}
public static byte[] sha3(String message) {
return sha3(Hex.decode(message), DEFAULT_DIGEST_256, true);
return sha3(Hex.decode(message), new SHA3Digest(256), true);
}
public static byte[] sha3(byte[] message) {
return sha3(message, DEFAULT_DIGEST_256, true);
return sha3(message, new SHA3Digest(256), true);
}
protected static String sha3String(String message, Size bitSize) {

View File

@ -256,8 +256,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
MainData.instance.getBlockchain().addBlocks(blockList);
WorldManager.instance.applyBlockList(blockList);
logger.info(blocksMessage.toString());
if (peerListener != null) peerListener.console(blocksMessage.toString());
}

View File

@ -16,8 +16,8 @@ peer.discovery.port = 30303
# that is the peer through
# we get the chain: [54.201.28.117] port: [30303]
# ZeroGox
#peer.active.ip = 54.204.10.41
#peer.active.port = 30303
peer.active.ip = 54.204.10.41
peer.active.port = 30303
# Some dude in Canada
#peer.active.ip = 131.104.247.135
@ -29,8 +29,8 @@ peer.discovery.port = 30303
# RomanJ general
peer.active.ip = 54.211.14.10
peer.active.port = 50505
#peer.active.ip = 54.211.14.10
#peer.active.port = 50505
#peer.active.ip = 151.64.223.120
#peer.active.port = 30304