Race condition solved:
+ new SHA3Digest(256) - can't be shared, it's not a thread safe class
This commit is contained in:
parent
510baf5164
commit
899767affb
|
@ -53,9 +53,13 @@ public class Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getLastBlock() {
|
public Block getLastBlock() {
|
||||||
return lastBlock;
|
return lastBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastBlock(Block block){
|
||||||
|
lastBlock = block;
|
||||||
|
}
|
||||||
|
|
||||||
public int getSize(){
|
public int getSize(){
|
||||||
return index.size();
|
return index.size();
|
||||||
}
|
}
|
||||||
|
@ -111,8 +115,8 @@ public class Blockchain {
|
||||||
// on this price will use default 10000000000000
|
// on this price will use default 10000000000000
|
||||||
// todo: refactor this longValue some constant defaults class 10000000000000L
|
// todo: refactor this longValue some constant defaults class 10000000000000L
|
||||||
this.gasPrice = block.isGenesis() ? INITIAL_MIN_GAS_PRICE : block.getMinGasPrice();
|
this.gasPrice = block.isGenesis() ? INITIAL_MIN_GAS_PRICE : block.getMinGasPrice();
|
||||||
if(lastBlock == null || block.getNumber() > lastBlock.getNumber()){
|
if(getLastBlock() == null || block.getNumber() > getLastBlock().getNumber()){
|
||||||
this.lastBlock = block;
|
setLastBlock( block );
|
||||||
index.put(block.getNumber(), block.getParentHash());
|
index.put(block.getNumber(), block.getParentHash());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,10 +154,10 @@ public class Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getLatestBlockHash(){
|
public byte[] getLatestBlockHash(){
|
||||||
if (index.isEmpty())
|
if (index.isEmpty())
|
||||||
return StaticMessages.GENESIS_HASH;
|
return StaticMessages.GENESIS_HASH;
|
||||||
else
|
else
|
||||||
return lastBlock.getHash();
|
return getLastBlock().getHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadChain() {
|
public void loadChain() {
|
||||||
|
@ -171,8 +175,8 @@ public class Blockchain {
|
||||||
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
|
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
|
||||||
this.addBlock(new Block(db.get(parentHash)));
|
this.addBlock(new Block(db.get(parentHash)));
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("Block: " + lastBlock.getNumber() + " ---> " + lastBlock.toFlatString());
|
logger.debug("Block: " + getLastBlock().getNumber() + " ---> " + getLastBlock().toFlatString());
|
||||||
parentHash = lastBlock.getHash();
|
parentHash = getLastBlock().getHash();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -7,22 +7,20 @@ import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
public class SHA3Helper {
|
public class SHA3Helper {
|
||||||
|
|
||||||
private static SHA3Digest DEFAULT_DIGEST_256 = new SHA3Digest(256);
|
|
||||||
|
|
||||||
public static String sha3String(String message) {
|
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) {
|
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) {
|
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) {
|
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) {
|
protected static String sha3String(String message, Size bitSize) {
|
||||||
|
|
|
@ -256,8 +256,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
MainData.instance.getBlockchain().addBlocks(blockList);
|
MainData.instance.getBlockchain().addBlocks(blockList);
|
||||||
WorldManager.instance.applyBlockList(blockList);
|
WorldManager.instance.applyBlockList(blockList);
|
||||||
|
|
||||||
logger.info(blocksMessage.toString());
|
|
||||||
if (peerListener != null) peerListener.console(blocksMessage.toString());
|
if (peerListener != null) peerListener.console(blocksMessage.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ peer.discovery.port = 30303
|
||||||
# that is the peer through
|
# that is the peer through
|
||||||
# we get the chain: [54.201.28.117] port: [30303]
|
# we get the chain: [54.201.28.117] port: [30303]
|
||||||
# ZeroGox
|
# ZeroGox
|
||||||
#peer.active.ip = 54.204.10.41
|
peer.active.ip = 54.204.10.41
|
||||||
#peer.active.port = 30303
|
peer.active.port = 30303
|
||||||
|
|
||||||
# Some dude in Canada
|
# Some dude in Canada
|
||||||
#peer.active.ip = 131.104.247.135
|
#peer.active.ip = 131.104.247.135
|
||||||
|
@ -29,8 +29,8 @@ peer.discovery.port = 30303
|
||||||
|
|
||||||
|
|
||||||
# RomanJ general
|
# RomanJ general
|
||||||
peer.active.ip = 54.211.14.10
|
#peer.active.ip = 54.211.14.10
|
||||||
peer.active.port = 50505
|
#peer.active.port = 50505
|
||||||
|
|
||||||
#peer.active.ip = 151.64.223.120
|
#peer.active.ip = 151.64.223.120
|
||||||
#peer.active.port = 30304
|
#peer.active.port = 30304
|
||||||
|
|
Loading…
Reference in New Issue