Merge branch 'ethersphere-frontier/blockpool' into conversion
This commit is contained in:
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
*/
|
Reference in New Issue
Block a user