Merge pull request #181 from cbeams/patch-1

This commit is contained in:
Chris Beams 2014-12-29 11:46:27 +01:00
commit 337ead1b9e
9 changed files with 77 additions and 68 deletions

View File

@ -70,7 +70,7 @@ javadoc {
options.author = true
options.header = project.name
options.addStringOption('Xdoclint:all,-missing', '-quiet')
options.encoding ="UTF-8"
options.encoding = "UTF-8"
options.links(
"http://docs.oracle.com/javase/8/docs/api/",
"http://netty.io/4.0/api/"

View File

@ -9,9 +9,12 @@ import org.ethereum.net.BlockQueue;
import org.ethereum.net.server.ChannelManager;
import org.ethereum.util.AdvancedDeviceUtils;
import org.ethereum.vm.ProgramInvokeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.FileSystemUtils;
@ -20,7 +23,9 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -162,14 +167,15 @@ public class BlockchainImpl implements Blockchain {
}
// cut on the chain got lastBlock + 1 > n
if (block.getNumber() > bestBlock.getNumber() + 1){
if (block.getNumber() > bestBlock.getNumber() + 1) {
channelManager.ethSync();
}
if (!hasParentOnTheChain(block) && block.getNumber() > bestBlock.getNumber()) {
if (!hasParentOnTheChain(block) && block.getNumber() > bestBlock.getNumber()){
if (1 == 1)
return; // todo: temporary cancel the rollback
if (1==1)return; // todo: temporary cancel the rollback
logger.info("*** Blockchain will rollback and resynchronise now ");
long rollbackIdx = bestBlock.getNumber() - 30;
@ -233,7 +239,6 @@ public class BlockchainImpl implements Blockchain {
logger.info("Sync done");
syncDoneCalled = true;
listener.onSyncDone();
}
}
@ -417,7 +422,6 @@ public class BlockchainImpl implements Blockchain {
logger.debug("block added to the blockChain: index: [{}]", block.getNumber());
if (block.getNumber() % 100 == 0)
logger.info("*** Last block added [ #{} ]", block.getNumber());
}

View File

@ -164,8 +164,6 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
}
}
private void processTransactions(TransactionsMessage msg) {
Set<Transaction> txSet = msg.getTransactions();
@ -249,9 +247,6 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
private void processBlockHashes(BlockHashesMessage blockHashesMessage) {
List<byte[]> receivedHashes = blockHashesMessage.getBlockHashes();
// receivedHashes.forEach(hash -> System.out.println(Hex.toHexString(hash)));
BlockQueue chainQueue = blockchain.getQueue();
// result is empty, peer has no more hashes
@ -285,7 +280,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
List<Block> blockList = blocksMessage.getBlocks();
if (!blockList.isEmpty()){
if (!blockList.isEmpty()) {
Block block = blockList.get(blockList.size()-1);
if (block.getNumber() > lastBlock.getNumber())
lastBlock = blockList.get(blockList.size()-1);
@ -513,7 +508,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
blockchain.getQueue().addHash(hash);
}
public void doSync(){
public void doSync() {
logger.info("Sync force activated, block: {}", lastBlock);
syncStatus = SyncSatus.HASH_RETRIEVING;
setBestHash(lastBlock.getHash());

View File

@ -5,7 +5,12 @@ import org.ethereum.crypto.HashUtil;
import org.ethereum.net.client.Capability;
import org.ethereum.net.eth.EthHandler;
import org.ethereum.net.eth.GetTransactionsMessage;
import org.ethereum.net.p2p.*;
import org.ethereum.net.p2p.DisconnectMessage;
import org.ethereum.net.p2p.GetPeersMessage;
import org.ethereum.net.p2p.HelloMessage;
import org.ethereum.net.p2p.P2pHandler;
import org.ethereum.net.p2p.PingMessage;
import org.ethereum.net.p2p.PongMessage;
import org.ethereum.net.shh.ShhHandler;
import org.spongycastle.util.encoders.Hex;

View File

@ -1,7 +1,5 @@
package org.ethereum.net.p2p;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.manager.WorldManager;
@ -16,19 +14,30 @@ import org.ethereum.net.message.StaticMessages;
import org.ethereum.net.peerdiscovery.PeerInfo;
import org.ethereum.net.shh.ShhHandler;
import org.ethereum.net.shh.ShhMessageCodes;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import static org.ethereum.net.message.StaticMessages.*;
/**
* Process the basic protocol messages between every peer on the network.
*
@ -277,8 +286,6 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
return handshakeHelloMessage;
}
private void startTimers() {
// sample for pinging in background

View File

@ -108,9 +108,7 @@ public class ChannelManager {
}
public void reconnect(){
for (Channel channel : channels){
channel.p2pHandler.sendDisconnect();
}
channels.forEach(c -> c.p2pHandler.sendDisconnect());
}
public void ethSync() {