aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-21 01:01:05 +0800
committerobscuren <geffobscura@gmail.com>2015-03-21 01:01:05 +0800
commitf4e9638867f5dab01eeb6db5fdbd85737a11fbd6 (patch)
tree8d8cbfeb2533a2b84e5f0927e9bfdd688cdffbb2 /eth
parent54dac59285ccc6a3af47201479ca556da2899e93 (diff)
parentecd10d2cf765072cd74347b9e0ca2bb85091450f (diff)
downloadgo-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.gz
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.bz2
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.lz
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.xz
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.zst
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.zip
Merge branch 'ethersphere-frontier/blockpool' into conversion
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go3
-rw-r--r--eth/protocol.go16
-rw-r--r--eth/protocol_test.go13
-rw-r--r--eth/wallet.go80
4 files changed, 15 insertions, 97 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 52f336c1d..b086d6a56 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -195,7 +195,8 @@ func New(config *Config) (*Ethereum, error) {
hasBlock := eth.chainManager.HasBlock
insertChain := eth.chainManager.InsertChain
- eth.blockPool = blockpool.New(hasBlock, insertChain, eth.pow.Verify)
+ td := eth.chainManager.Td()
+ eth.blockPool = blockpool.New(hasBlock, insertChain, eth.pow.Verify, eth.EventMux(), td)
netprv, err := config.nodeKey()
if err != nil {
diff --git a/eth/protocol.go b/eth/protocol.go
index 6d610a663..494c1c1bb 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -42,6 +42,7 @@ const (
ErrGenesisBlockMismatch
ErrNoStatusMsg
ErrExtraStatusMsg
+ ErrSuspendedPeer
)
var errorToString = map[int]string{
@@ -53,6 +54,7 @@ var errorToString = map[int]string{
ErrGenesisBlockMismatch: "Genesis block mismatch",
ErrNoStatusMsg: "No status message",
ErrExtraStatusMsg: "Extra status message",
+ ErrSuspendedPeer: "Suspended peer",
}
// ethProtocol represents the ethereum wire protocol
@@ -85,7 +87,7 @@ type chainManager interface {
type blockPool interface {
AddBlockHashes(next func() (common.Hash, bool), peerId string)
AddBlock(block *types.Block, peerId string)
- AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool)
+ AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool, suspended bool)
RemovePeer(peerId string)
}
@@ -211,8 +213,7 @@ func (self *ethProtocol) handle() error {
var i int
iter := func() (hash common.Hash, ok bool) {
- var h common.Hash
- err := msgStream.Decode(&h)
+ err := msgStream.Decode(&hash)
if err == rlp.EOL {
return common.Hash{}, false
} else if err != nil {
@@ -288,7 +289,7 @@ func (self *ethProtocol) handle() error {
// to simplify backend interface adding a new block
// uses AddPeer followed by AddBlock only if peer is the best peer
// (or selected as new best peer)
- if self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect) {
+ if best, _ := self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect); best {
self.blockPool.AddBlock(request.Block, self.id)
}
@@ -334,9 +335,12 @@ func (self *ethProtocol) handleStatus() error {
return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, self.protocolVersion)
}
- self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
+ _, suspended := self.blockPool.AddPeer(status.TD, status.CurrentBlock, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect)
+ if suspended {
+ return self.protoError(ErrSuspendedPeer, "")
+ }
- self.blockPool.AddPeer(status.TD, status.CurrentBlock, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect)
+ self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
return nil
}
diff --git a/eth/protocol_test.go b/eth/protocol_test.go
index 7620b3854..8ca6d1be6 100644
--- a/eth/protocol_test.go
+++ b/eth/protocol_test.go
@@ -41,17 +41,10 @@ type testChainManager struct {
type testBlockPool struct {
addBlockHashes func(next func() (common.Hash, bool), peerId string)
addBlock func(block *types.Block, peerId string) (err error)
- addPeer func(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool)
+ addPeer func(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool, suspended bool)
removePeer func(peerId string)
}
-// func (self *testTxPool) GetTransactions() (txs []*types.Transaction) {
-// if self.getTransactions != nil {
-// txs = self.getTransactions()
-// }
-// return
-// }
-
func (self *testTxPool) AddTransactions(txs []*types.Transaction) {
if self.addTransactions != nil {
self.addTransactions(txs)
@@ -93,9 +86,9 @@ func (self *testBlockPool) AddBlock(block *types.Block, peerId string) {
}
}
-func (self *testBlockPool) AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestBlockHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool) {
+func (self *testBlockPool) AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestBlockHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool, suspended bool) {
if self.addPeer != nil {
- best = self.addPeer(td, currentBlock, peerId, requestBlockHashes, requestBlocks, peerError)
+ best, suspended = self.addPeer(td, currentBlock, peerId, requestBlockHashes, requestBlocks, peerError)
}
return
}
diff --git a/eth/wallet.go b/eth/wallet.go
deleted file mode 100644
index 9ec834309..000000000
--- a/eth/wallet.go
+++ /dev/null
@@ -1,80 +0,0 @@
-package eth
-
-/*
-import (
- "crypto/ecdsa"
- "errors"
- "math/big"
-
- "github.com/ethereum/go-ethereum/core"
- "github.com/ethereum/go-ethereum/core/types"
-)
-
-type Account struct {
- w *Wallet
-}
-
-func (self *Account) Transact(to *Account, value, gas, price *big.Int, data []byte) error {
- return self.w.transact(self, to, value, gas, price, data)
-}
-
-func (self *Account) Address() []byte {
- return nil
-}
-
-func (self *Account) PrivateKey() *ecdsa.PrivateKey {
- return nil
-}
-
-type Wallet struct{}
-
-func NewWallet() *Wallet {
- return &Wallet{}
-}
-
-func (self *Wallet) GetAccount(i int) *Account {
-}
-
-func (self *Wallet) transact(from, to *Account, value, gas, price *big.Int, data []byte) error {
- if from.PrivateKey() == nil {
- return errors.New("accounts is not owned (no private key available)")
- }
-
- var createsContract bool
- if to == nil {
- createsContract = true
- }
-
- var msg *types.Transaction
- if contractCreation {
- msg = types.NewContractCreationTx(value, gas, price, data)
- } else {
- msg = types.NewTransactionMessage(to.Address(), value, gas, price, data)
- }
-
- state := self.chainManager.TransState()
- nonce := state.GetNonce(key.Address())
-
- msg.SetNonce(nonce)
- msg.SignECDSA(from.PriateKey())
-
- // Do some pre processing for our "pre" events and hooks
- block := self.chainManager.NewBlock(from.Address())
- coinbase := state.GetOrNewStateObject(from.Address())
- coinbase.SetGasPool(block.GasLimit())
- self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
-
- err := self.obj.TxPool().Add(tx)
- if err != nil {
- return nil, err
- }
- state.SetNonce(key.Address(), nonce+1)
-
- if contractCreation {
- addr := core.AddressFromMessage(tx)
- pipelogger.Infof("Contract addr %x\n", addr)
- }
-
- return tx, nil
-}
-*/