aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-13 22:05:56 +0800
committerobscuren <geffobscura@gmail.com>2015-02-13 22:05:56 +0800
commita5ea21cd85530eee6eb1bb83c37c20d009f11f74 (patch)
treee5be5bd595139ff7dfbe6261e1e659d8e7dd6f9c /eth
parentdb24fb792cf0dab91bc85e79aecf6758349002a4 (diff)
parent38faf2c51a1e4a86cda5dfa1b4f7fdae4fd7f58d (diff)
downloadgo-tangerine-a5ea21cd85530eee6eb1bb83c37c20d009f11f74.tar.gz
go-tangerine-a5ea21cd85530eee6eb1bb83c37c20d009f11f74.tar.zst
go-tangerine-a5ea21cd85530eee6eb1bb83c37c20d009f11f74.zip
merge
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go25
-rw-r--r--eth/block_pool.go6
-rw-r--r--eth/block_pool_test.go1
-rw-r--r--eth/protocol.go14
-rw-r--r--eth/protocol_test.go2
5 files changed, 33 insertions, 15 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 677b5d8e3..ab348afe5 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -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(&ethlogger.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()
diff --git a/eth/block_pool.go b/eth/block_pool.go
index b624d064a..13016c694 100644
--- a/eth/block_pool.go
+++ b/eth/block_pool.go
@@ -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 {
diff --git a/eth/block_pool_test.go b/eth/block_pool_test.go
index 94c3b43d2..331dbe504 100644
--- a/eth/block_pool_test.go
+++ b/eth/block_pool_test.go
@@ -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
diff --git a/eth/protocol.go b/eth/protocol.go
index 24a0f0a8e..d7a7fa910 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -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...))
+}
diff --git a/eth/protocol_test.go b/eth/protocol_test.go
index 224b59abd..1fe6d8f6b 100644
--- a/eth/protocol_test.go
+++ b/eth/protocol_test.go
@@ -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)