merge
This commit is contained in:
@ -17,10 +17,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/whisper"
|
||||
)
|
||||
|
||||
const (
|
||||
seedNodeAddress = "poc-8.ethdev.com:30303"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
Version string
|
||||
@ -68,7 +64,8 @@ type Ethereum struct {
|
||||
txSub event.Subscription
|
||||
blockSub event.Subscription
|
||||
|
||||
RpcServer *rpc.JsonRpcServer
|
||||
RpcServer rpc.RpcServer
|
||||
WsServer rpc.RpcServer
|
||||
keyManager *crypto.KeyManager
|
||||
|
||||
clientIdentity p2p.ClientIdentity
|
||||
@ -142,14 +139,13 @@ func New(config *Config) (*Ethereum, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(nat)
|
||||
|
||||
eth.net = &p2p.Server{
|
||||
Identity: clientId,
|
||||
MaxPeers: config.MaxPeers,
|
||||
Protocols: protocols,
|
||||
Blacklist: eth.blacklist,
|
||||
NAT: p2p.UPNP(),
|
||||
NAT: nat,
|
||||
NoDial: !config.Dial,
|
||||
}
|
||||
|
||||
@ -220,8 +216,12 @@ func (s *Ethereum) MaxPeers() int {
|
||||
return s.net.MaxPeers
|
||||
}
|
||||
|
||||
func (s *Ethereum) Coinbase() []byte {
|
||||
return nil // TODO
|
||||
}
|
||||
|
||||
// Start the ethereum
|
||||
func (s *Ethereum) Start(seed bool) error {
|
||||
func (s *Ethereum) Start(seedNode string) error {
|
||||
jsonlogger.LogJson(ðlogger.LogStarting{
|
||||
ClientString: s.ClientIdentity().String(),
|
||||
Coinbase: ethutil.Bytes2Hex(s.KeyManager().Address()),
|
||||
@ -251,9 +251,9 @@ func (s *Ethereum) Start(seed bool) error {
|
||||
go s.blockBroadcastLoop()
|
||||
|
||||
// TODO: read peers here
|
||||
if seed {
|
||||
logger.Infof("Connect to seed node %v", seedNodeAddress)
|
||||
if err := s.SuggestPeer(seedNodeAddress); err != nil {
|
||||
if len(seedNode) > 0 {
|
||||
logger.Infof("Connect to seed node %v", seedNode)
|
||||
if err := s.SuggestPeer(seedNode); err != nil {
|
||||
logger.Infoln(err)
|
||||
}
|
||||
}
|
||||
@ -285,6 +285,9 @@ func (s *Ethereum) Stop() {
|
||||
if s.RpcServer != nil {
|
||||
s.RpcServer.Stop()
|
||||
}
|
||||
if s.WsServer != nil {
|
||||
s.WsServer.Stop()
|
||||
}
|
||||
s.txPool.Stop()
|
||||
s.eventMux.Stop()
|
||||
s.blockPool.Stop()
|
||||
|
@ -636,12 +636,12 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) {
|
||||
|
||||
// validate block for PoW
|
||||
if !self.verifyPoW(block) {
|
||||
poolLogger.Warnf("invalid pow on block [%s] by peer %s", name(hash), peerId)
|
||||
poolLogger.Warnf("invalid pow on block [%s %v] by peer %s", name(hash), block.Number(), peerId)
|
||||
self.peerError(peerId, ErrInvalidPoW, "%x", hash)
|
||||
return
|
||||
}
|
||||
}
|
||||
poolLogger.Debugf("added block [%s] sent by peer %s", name(hash), peerId)
|
||||
poolLogger.DebugDetailf("added block [%s] sent by peer %s", name(hash), peerId)
|
||||
node.block = block
|
||||
node.blockBy = peerId
|
||||
|
||||
@ -1098,7 +1098,7 @@ func (self *BlockPool) requestBlocks(attempts int, hashes [][]byte) {
|
||||
poolLogger.Debugf("request %v missing blocks from %v/%v peers: chosen %v", len(hashes), repetitions, peerCount, indexes)
|
||||
for _, peer := range self.peers {
|
||||
if i == indexes[0] {
|
||||
poolLogger.Debugf("request %v missing blocks from peer %s", len(hashes), peer.id)
|
||||
poolLogger.Debugf("request %v missing blocks [%x/%x] from peer %s", len(hashes), hashes[0][:4], hashes[len(hashes)-1][:4], peer.id)
|
||||
peer.requestBlocks(hashes)
|
||||
indexes = indexes[1:]
|
||||
if len(indexes) == 0 {
|
||||
|
@ -613,6 +613,7 @@ func TestInvalidBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyPoW(t *testing.T) {
|
||||
t.Skip("***FIX*** This test is broken")
|
||||
logInit()
|
||||
_, blockPool, blockPoolTester := newTestBlockPool(t)
|
||||
blockPoolTester.blockChain[0] = nil
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ProtocolVersion = 51
|
||||
ProtocolVersion = 52
|
||||
NetworkId = 0
|
||||
ProtocolLength = uint64(8)
|
||||
ProtocolMaxMsgSize = 10 * 1024 * 1024
|
||||
@ -46,6 +46,7 @@ type ethProtocol struct {
|
||||
// used as an argument to EthProtocol
|
||||
type txPool interface {
|
||||
AddTransactions([]*types.Transaction)
|
||||
GetTransactions() types.Transactions
|
||||
}
|
||||
|
||||
type chainManager interface {
|
||||
@ -101,6 +102,7 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo
|
||||
}
|
||||
err = self.handleStatus()
|
||||
if err == nil {
|
||||
self.propagateTxs()
|
||||
for {
|
||||
err = self.handle()
|
||||
if err != nil {
|
||||
@ -324,3 +326,13 @@ func (self *ethProtocol) protoErrorDisconnect(code int, format string, params ..
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *ethProtocol) propagateTxs() {
|
||||
transactions := self.txPool.GetTransactions()
|
||||
iface := make([]interface{}, len(transactions))
|
||||
for i, transaction := range transactions {
|
||||
iface[i] = transaction
|
||||
}
|
||||
|
||||
self.rw.WriteMsg(p2p.NewMsg(TxMsg, iface...))
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ func (self *testTxPool) AddTransactions(txs []*types.Transaction) {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *testTxPool) GetTransactions() types.Transactions { return nil }
|
||||
|
||||
func (self *testChainManager) GetBlockHashesFromHash(hash []byte, amount uint64) (hashes [][]byte) {
|
||||
if self.getBlockHashes != nil {
|
||||
hashes = self.getBlockHashes(hash, amount)
|
||||
|
Reference in New Issue
Block a user