aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-21 00:42:25 +0800
committerobscuren <geffobscura@gmail.com>2015-03-21 00:42:25 +0800
commit1821d1af48e5fa11eb81fe7f6e5372737bb36ec9 (patch)
treed534f2059f6c14ac7f2dd1ab9996ef0cd4c34b95 /eth
parenta59bb053f4d2a4a28341c645c051c4c323581a1b (diff)
parent66b29899c474abeab6c66060c9ea5bbff85b9efb (diff)
downloadgo-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar
go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.gz
go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.bz2
go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.lz
go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.xz
go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.zst
go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.zip
Merge branch 'frontier/blockpool' of https://github.com/ethersphere/go-ethereum into ethersphere-frontier/blockpool
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go3
-rw-r--r--eth/protocol.go13
-rw-r--r--eth/protocol_test.go13
-rw-r--r--eth/wallet.go80
4 files changed, 14 insertions, 95 deletions
diff --git a/eth/backend.go b/eth/backend.go
index afe314d74..141c6c605 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..1999d9807 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)
}
@@ -288,7 +290,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 +336,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
-}
-*/