mirror of https://github.com/status-im/op-geth.git
eth: clean out light node notions from eth
This commit is contained in:
parent
a9d8dfc8e7
commit
aa0538db0b
|
@ -304,8 +304,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
||||||
utils.DataDirFlag,
|
utils.DataDirFlag,
|
||||||
utils.BlockchainVersionFlag,
|
utils.BlockchainVersionFlag,
|
||||||
utils.OlympicFlag,
|
utils.OlympicFlag,
|
||||||
utils.EthModeFlag,
|
utils.FastSyncFlag,
|
||||||
utils.EthVersionFlag,
|
|
||||||
utils.CacheFlag,
|
utils.CacheFlag,
|
||||||
utils.JSpathFlag,
|
utils.JSpathFlag,
|
||||||
utils.ListenPortFlag,
|
utils.ListenPortFlag,
|
||||||
|
@ -361,7 +360,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
||||||
utils.SetupLogger(ctx)
|
utils.SetupLogger(ctx)
|
||||||
utils.SetupNetwork(ctx)
|
utils.SetupNetwork(ctx)
|
||||||
utils.SetupVM(ctx)
|
utils.SetupVM(ctx)
|
||||||
utils.SetupEth(ctx)
|
|
||||||
if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
|
if ctx.GlobalBool(utils.PProfEanbledFlag.Name) {
|
||||||
utils.StartPProf(ctx)
|
utils.StartPProf(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/ethereum/ethash"
|
"github.com/ethereum/ethash"
|
||||||
|
@ -149,15 +148,9 @@ var (
|
||||||
Name: "olympic",
|
Name: "olympic",
|
||||||
Usage: "Use olympic style protocol",
|
Usage: "Use olympic style protocol",
|
||||||
}
|
}
|
||||||
EthModeFlag = cli.StringFlag{
|
FastSyncFlag = cli.BoolFlag{
|
||||||
Name: "mode",
|
Name: "fast",
|
||||||
Value: "archive",
|
Usage: "Enables fast syncing through state downloads",
|
||||||
Usage: "Client mode of operation (archive, full, light)",
|
|
||||||
}
|
|
||||||
EthVersionFlag = cli.IntFlag{
|
|
||||||
Name: "eth",
|
|
||||||
Value: 63,
|
|
||||||
Usage: "Highest eth protocol to advertise (temporary, dev option)",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// miner settings
|
// miner settings
|
||||||
|
@ -431,25 +424,13 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
|
glog.V(logger.Error).Infoln("WARNING: No etherbase set and no accounts found as default")
|
||||||
}
|
}
|
||||||
// Resolve the mode of opeation from the string flag
|
|
||||||
var clientMode eth.Mode
|
|
||||||
switch strings.ToLower(ctx.GlobalString(EthModeFlag.Name)) {
|
|
||||||
case "archive":
|
|
||||||
clientMode = eth.ArchiveMode
|
|
||||||
case "full":
|
|
||||||
clientMode = eth.FullMode
|
|
||||||
case "light":
|
|
||||||
clientMode = eth.LightMode
|
|
||||||
default:
|
|
||||||
glog.Fatalf("Unknown node type requested: %s", ctx.GlobalString(EthModeFlag.Name))
|
|
||||||
}
|
|
||||||
// Assemble the entire eth configuration and return
|
// Assemble the entire eth configuration and return
|
||||||
cfg := ð.Config{
|
cfg := ð.Config{
|
||||||
Name: common.MakeName(clientID, version),
|
Name: common.MakeName(clientID, version),
|
||||||
DataDir: MustDataDir(ctx),
|
DataDir: MustDataDir(ctx),
|
||||||
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
|
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
|
||||||
GenesisFile: ctx.GlobalString(GenesisFileFlag.Name),
|
GenesisFile: ctx.GlobalString(GenesisFileFlag.Name),
|
||||||
Mode: clientMode,
|
FastSync: ctx.GlobalBool(FastSyncFlag.Name),
|
||||||
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
|
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
|
||||||
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
|
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
|
||||||
SkipBcVersionCheck: false,
|
SkipBcVersionCheck: false,
|
||||||
|
@ -550,18 +531,6 @@ func SetupVM(ctx *cli.Context) {
|
||||||
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
|
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupEth configures the eth packages global settings
|
|
||||||
func SetupEth(ctx *cli.Context) {
|
|
||||||
version := ctx.GlobalInt(EthVersionFlag.Name)
|
|
||||||
for len(eth.ProtocolVersions) > 0 && eth.ProtocolVersions[0] > uint(version) {
|
|
||||||
eth.ProtocolVersions = eth.ProtocolVersions[1:]
|
|
||||||
eth.ProtocolLengths = eth.ProtocolLengths[1:]
|
|
||||||
}
|
|
||||||
if len(eth.ProtocolVersions) == 0 {
|
|
||||||
Fatalf("No valid eth protocols remaining")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MakeChain creates a chain manager from set command line flags.
|
// MakeChain creates a chain manager from set command line flags.
|
||||||
func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database) {
|
func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database) {
|
||||||
datadir := MustDataDir(ctx)
|
datadir := MustDataDir(ctx)
|
||||||
|
|
|
@ -88,8 +88,8 @@ type Config struct {
|
||||||
GenesisNonce int
|
GenesisNonce int
|
||||||
GenesisFile string
|
GenesisFile string
|
||||||
GenesisBlock *types.Block // used by block tests
|
GenesisBlock *types.Block // used by block tests
|
||||||
|
FastSync bool
|
||||||
Olympic bool
|
Olympic bool
|
||||||
Mode Mode
|
|
||||||
|
|
||||||
BlockChainVersion int
|
BlockChainVersion int
|
||||||
SkipBcVersionCheck bool // e.g. blockchain export
|
SkipBcVersionCheck bool // e.g. blockchain export
|
||||||
|
@ -399,7 +399,7 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
|
|
||||||
eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.blockchain, eth.EventMux())
|
eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.blockchain, eth.EventMux())
|
||||||
eth.blockchain.SetProcessor(eth.blockProcessor)
|
eth.blockchain.SetProcessor(eth.blockProcessor)
|
||||||
if eth.protocolManager, err = NewProtocolManager(config.Mode, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil {
|
if eth.protocolManager, err = NewProtocolManager(config.FastSync, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.blockchain, chainDb); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eth.miner = miner.New(eth, eth.EventMux(), eth.pow)
|
eth.miner = miner.New(eth, eth.EventMux(), eth.pow)
|
||||||
|
|
|
@ -422,12 +422,14 @@ func (q *queue) ReserveNodeData(p *peer, count int) *fetchRequest {
|
||||||
q.stateSchedLock.Lock()
|
q.stateSchedLock.Lock()
|
||||||
defer q.stateSchedLock.Unlock()
|
defer q.stateSchedLock.Unlock()
|
||||||
|
|
||||||
|
if q.stateScheduler != nil {
|
||||||
for _, hash := range q.stateScheduler.Missing(max) {
|
for _, hash := range q.stateScheduler.Missing(max) {
|
||||||
q.stateTaskPool[hash] = q.stateTaskIndex
|
q.stateTaskPool[hash] = q.stateTaskIndex
|
||||||
q.stateTaskQueue.Push(hash, -float32(q.stateTaskIndex))
|
q.stateTaskQueue.Push(hash, -float32(q.stateTaskIndex))
|
||||||
q.stateTaskIndex++
|
q.stateTaskIndex++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return q.reserveHashes(p, count, q.stateTaskQueue, generator, q.statePendPool, count)
|
return q.reserveHashes(p, count, q.stateTaskQueue, generator, q.statePendPool, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ type hashFetcherFn func(common.Hash) error
|
||||||
type blockFetcherFn func([]common.Hash) error
|
type blockFetcherFn func([]common.Hash) error
|
||||||
|
|
||||||
type ProtocolManager struct {
|
type ProtocolManager struct {
|
||||||
mode Mode
|
fastSync bool
|
||||||
txpool txPool
|
txpool txPool
|
||||||
blockchain *core.BlockChain
|
blockchain *core.BlockChain
|
||||||
chaindb ethdb.Database
|
chaindb ethdb.Database
|
||||||
|
@ -83,10 +83,10 @@ type ProtocolManager struct {
|
||||||
|
|
||||||
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
|
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
|
||||||
// with the ethereum network.
|
// with the ethereum network.
|
||||||
func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
|
func NewProtocolManager(fastSync bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
|
||||||
// Create the protocol manager with the base fields
|
// Create the protocol manager with the base fields
|
||||||
manager := &ProtocolManager{
|
manager := &ProtocolManager{
|
||||||
mode: mode,
|
fastSync: fastSync,
|
||||||
eventMux: mux,
|
eventMux: mux,
|
||||||
txpool: txpool,
|
txpool: txpool,
|
||||||
blockchain: blockchain,
|
blockchain: blockchain,
|
||||||
|
@ -100,7 +100,7 @@ func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txP
|
||||||
manager.SubProtocols = make([]p2p.Protocol, 0, len(ProtocolVersions))
|
manager.SubProtocols = make([]p2p.Protocol, 0, len(ProtocolVersions))
|
||||||
for i, version := range ProtocolVersions {
|
for i, version := range ProtocolVersions {
|
||||||
// Skip protocol version if incompatible with the mode of operation
|
// Skip protocol version if incompatible with the mode of operation
|
||||||
if minimumProtocolVersion[mode] > version {
|
if fastSync && version < eth63 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Compatible, initialize the sub-protocol
|
// Compatible, initialize the sub-protocol
|
||||||
|
@ -120,14 +120,9 @@ func NewProtocolManager(mode Mode, networkId int, mux *event.TypeMux, txpool txP
|
||||||
return nil, errIncompatibleConfig
|
return nil, errIncompatibleConfig
|
||||||
}
|
}
|
||||||
// Construct the different synchronisation mechanisms
|
// Construct the different synchronisation mechanisms
|
||||||
var syncMode downloader.SyncMode
|
syncMode := downloader.FullSync
|
||||||
switch mode {
|
if fastSync {
|
||||||
case ArchiveMode:
|
|
||||||
syncMode = downloader.FullSync
|
|
||||||
case FullMode:
|
|
||||||
syncMode = downloader.FastSync
|
syncMode = downloader.FastSync
|
||||||
case LightMode:
|
|
||||||
syncMode = downloader.LightSync
|
|
||||||
}
|
}
|
||||||
manager.downloader = downloader.New(syncMode, chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlock, blockchain.GetHeader,
|
manager.downloader = downloader.New(syncMode, chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlock, blockchain.GetHeader,
|
||||||
blockchain.GetBlock, blockchain.CurrentHeader, blockchain.CurrentBlock, blockchain.CurrentFastBlock, blockchain.FastSyncCommitHead,
|
blockchain.GetBlock, blockchain.CurrentHeader, blockchain.CurrentBlock, blockchain.CurrentFastBlock, blockchain.FastSyncCommitHead,
|
||||||
|
|
|
@ -22,12 +22,11 @@ func TestProtocolCompatibility(t *testing.T) {
|
||||||
// Define the compatibility chart
|
// Define the compatibility chart
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
version uint
|
version uint
|
||||||
mode Mode
|
fastSync bool
|
||||||
compatible bool
|
compatible bool
|
||||||
}{
|
}{
|
||||||
{61, ArchiveMode, true}, {62, ArchiveMode, true}, {63, ArchiveMode, true}, {64, ArchiveMode, true},
|
{61, false, true}, {62, false, true}, {63, false, true},
|
||||||
{61, FullMode, false}, {62, FullMode, false}, {63, FullMode, true}, {64, FullMode, true},
|
{61, true, false}, {62, true, false}, {63, true, true},
|
||||||
{61, LightMode, false}, {62, LightMode, false}, {63, LightMode, false}, {64, LightMode, true},
|
|
||||||
}
|
}
|
||||||
// Make sure anything we screw up is restored
|
// Make sure anything we screw up is restored
|
||||||
backup := ProtocolVersions
|
backup := ProtocolVersions
|
||||||
|
@ -37,7 +36,7 @@ func TestProtocolCompatibility(t *testing.T) {
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
ProtocolVersions = []uint{tt.version}
|
ProtocolVersions = []uint{tt.version}
|
||||||
|
|
||||||
pm, err := newTestProtocolManager(tt.mode, 0, nil, nil)
|
pm, err := newTestProtocolManager(tt.fastSync, 0, nil, nil)
|
||||||
if pm != nil {
|
if pm != nil {
|
||||||
defer pm.Stop()
|
defer pm.Stop()
|
||||||
}
|
}
|
||||||
|
@ -52,7 +51,7 @@ func TestProtocolCompatibility(t *testing.T) {
|
||||||
func TestGetBlockHashes61(t *testing.T) { testGetBlockHashes(t, 61) }
|
func TestGetBlockHashes61(t *testing.T) { testGetBlockHashes(t, 61) }
|
||||||
|
|
||||||
func testGetBlockHashes(t *testing.T, protocol int) {
|
func testGetBlockHashes(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
@ -95,7 +94,7 @@ func testGetBlockHashes(t *testing.T, protocol int) {
|
||||||
func TestGetBlockHashesFromNumber61(t *testing.T) { testGetBlockHashesFromNumber(t, 61) }
|
func TestGetBlockHashesFromNumber61(t *testing.T) { testGetBlockHashesFromNumber(t, 61) }
|
||||||
|
|
||||||
func testGetBlockHashesFromNumber(t *testing.T, protocol int) {
|
func testGetBlockHashesFromNumber(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ func testGetBlockHashesFromNumber(t *testing.T, protocol int) {
|
||||||
func TestGetBlocks61(t *testing.T) { testGetBlocks(t, 61) }
|
func TestGetBlocks61(t *testing.T) { testGetBlocks(t, 61) }
|
||||||
|
|
||||||
func testGetBlocks(t *testing.T, protocol int) {
|
func testGetBlocks(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
@ -204,10 +203,9 @@ func testGetBlocks(t *testing.T, protocol int) {
|
||||||
// Tests that block headers can be retrieved from a remote chain based on user queries.
|
// Tests that block headers can be retrieved from a remote chain based on user queries.
|
||||||
func TestGetBlockHeaders62(t *testing.T) { testGetBlockHeaders(t, 62) }
|
func TestGetBlockHeaders62(t *testing.T) { testGetBlockHeaders(t, 62) }
|
||||||
func TestGetBlockHeaders63(t *testing.T) { testGetBlockHeaders(t, 63) }
|
func TestGetBlockHeaders63(t *testing.T) { testGetBlockHeaders(t, 63) }
|
||||||
func TestGetBlockHeaders64(t *testing.T) { testGetBlockHeaders(t, 64) }
|
|
||||||
|
|
||||||
func testGetBlockHeaders(t *testing.T, protocol int) {
|
func testGetBlockHeaders(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxHashFetch+15, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, downloader.MaxHashFetch+15, nil, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
@ -330,10 +328,9 @@ func testGetBlockHeaders(t *testing.T, protocol int) {
|
||||||
// Tests that block contents can be retrieved from a remote chain based on their hashes.
|
// Tests that block contents can be retrieved from a remote chain based on their hashes.
|
||||||
func TestGetBlockBodies62(t *testing.T) { testGetBlockBodies(t, 62) }
|
func TestGetBlockBodies62(t *testing.T) { testGetBlockBodies(t, 62) }
|
||||||
func TestGetBlockBodies63(t *testing.T) { testGetBlockBodies(t, 63) }
|
func TestGetBlockBodies63(t *testing.T) { testGetBlockBodies(t, 63) }
|
||||||
func TestGetBlockBodies64(t *testing.T) { testGetBlockBodies(t, 64) }
|
|
||||||
|
|
||||||
func testGetBlockBodies(t *testing.T, protocol int) {
|
func testGetBlockBodies(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, downloader.MaxBlockFetch+15, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, downloader.MaxBlockFetch+15, nil, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
@ -402,7 +399,6 @@ func testGetBlockBodies(t *testing.T, protocol int) {
|
||||||
|
|
||||||
// Tests that the node state database can be retrieved based on hashes.
|
// Tests that the node state database can be retrieved based on hashes.
|
||||||
func TestGetNodeData63(t *testing.T) { testGetNodeData(t, 63) }
|
func TestGetNodeData63(t *testing.T) { testGetNodeData(t, 63) }
|
||||||
func TestGetNodeData64(t *testing.T) { testGetNodeData(t, 64) }
|
|
||||||
|
|
||||||
func testGetNodeData(t *testing.T, protocol int) {
|
func testGetNodeData(t *testing.T, protocol int) {
|
||||||
// Define three accounts to simulate transactions with
|
// Define three accounts to simulate transactions with
|
||||||
|
@ -440,7 +436,7 @@ func testGetNodeData(t *testing.T, protocol int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assemble the test environment
|
// Assemble the test environment
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, 4, generator, nil)
|
pm := newTestProtocolManagerMust(t, false, 4, generator, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
@ -492,7 +488,6 @@ func testGetNodeData(t *testing.T, protocol int) {
|
||||||
|
|
||||||
// Tests that the transaction receipts can be retrieved based on hashes.
|
// Tests that the transaction receipts can be retrieved based on hashes.
|
||||||
func TestGetReceipt63(t *testing.T) { testGetReceipt(t, 63) }
|
func TestGetReceipt63(t *testing.T) { testGetReceipt(t, 63) }
|
||||||
func TestGetReceipt64(t *testing.T) { testGetReceipt(t, 64) }
|
|
||||||
|
|
||||||
func testGetReceipt(t *testing.T, protocol int) {
|
func testGetReceipt(t *testing.T, protocol int) {
|
||||||
// Define three accounts to simulate transactions with
|
// Define three accounts to simulate transactions with
|
||||||
|
@ -530,7 +525,7 @@ func testGetReceipt(t *testing.T, protocol int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assemble the test environment
|
// Assemble the test environment
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, 4, generator, nil)
|
pm := newTestProtocolManagerMust(t, false, 4, generator, nil)
|
||||||
peer, _ := newTestPeer("peer", protocol, pm, true)
|
peer, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ var (
|
||||||
// newTestProtocolManager creates a new protocol manager for testing purposes,
|
// newTestProtocolManager creates a new protocol manager for testing purposes,
|
||||||
// with the given number of blocks already known, and potential notification
|
// with the given number of blocks already known, and potential notification
|
||||||
// channels for different events.
|
// channels for different events.
|
||||||
func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) (*ProtocolManager, error) {
|
func newTestProtocolManager(fastSync bool, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) (*ProtocolManager, error) {
|
||||||
var (
|
var (
|
||||||
evmux = new(event.TypeMux)
|
evmux = new(event.TypeMux)
|
||||||
pow = new(core.FakePow)
|
pow = new(core.FakePow)
|
||||||
|
@ -42,7 +42,7 @@ func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.Blo
|
||||||
if _, err := blockchain.InsertChain(chain); err != nil {
|
if _, err := blockchain.InsertChain(chain); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
pm, err := NewProtocolManager(mode, NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)
|
pm, err := NewProtocolManager(fastSync, NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ func newTestProtocolManager(mode Mode, blocks int, generator func(int, *core.Blo
|
||||||
// with the given number of blocks already known, and potential notification
|
// with the given number of blocks already known, and potential notification
|
||||||
// channels for different events. In case of an error, the constructor force-
|
// channels for different events. In case of an error, the constructor force-
|
||||||
// fails the test.
|
// fails the test.
|
||||||
func newTestProtocolManagerMust(t *testing.T, mode Mode, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) *ProtocolManager {
|
func newTestProtocolManagerMust(t *testing.T, fastSync bool, blocks int, generator func(int, *core.BlockGen), newtx chan<- []*types.Transaction) *ProtocolManager {
|
||||||
pm, err := newTestProtocolManager(mode, blocks, generator, newtx)
|
pm, err := newTestProtocolManager(fastSync, blocks, generator, newtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create protocol manager: %v", err)
|
t.Fatalf("Failed to create protocol manager: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,36 +26,18 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mode represents the mode of operation of the eth client.
|
|
||||||
type Mode int
|
|
||||||
|
|
||||||
const (
|
|
||||||
ArchiveMode Mode = iota // Maintain the entire blockchain history
|
|
||||||
FullMode // Maintain only a recent view of the blockchain
|
|
||||||
LightMode // Don't maintain any history, rather fetch on demand
|
|
||||||
)
|
|
||||||
|
|
||||||
// Constants to match up protocol versions and messages
|
// Constants to match up protocol versions and messages
|
||||||
const (
|
const (
|
||||||
eth61 = 61
|
eth61 = 61
|
||||||
eth62 = 62
|
eth62 = 62
|
||||||
eth63 = 63
|
eth63 = 63
|
||||||
eth64 = 64
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// minimumProtocolVersion is the minimum version of the protocol eth must run to
|
|
||||||
// support the desired mode of operation.
|
|
||||||
var minimumProtocolVersion = map[Mode]uint{
|
|
||||||
ArchiveMode: eth61,
|
|
||||||
FullMode: eth63,
|
|
||||||
LightMode: eth64,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supported versions of the eth protocol (first is primary).
|
// Supported versions of the eth protocol (first is primary).
|
||||||
var ProtocolVersions = []uint{eth64, eth63, eth62, eth61}
|
var ProtocolVersions = []uint{eth63, eth62, eth61}
|
||||||
|
|
||||||
// Number of implemented message corresponding to different protocol versions.
|
// Number of implemented message corresponding to different protocol versions.
|
||||||
var ProtocolLengths = []uint64{19, 17, 8, 9}
|
var ProtocolLengths = []uint64{17, 8, 9}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NetworkId = 1
|
NetworkId = 1
|
||||||
|
@ -90,11 +72,6 @@ const (
|
||||||
NodeDataMsg = 0x0e
|
NodeDataMsg = 0x0e
|
||||||
GetReceiptsMsg = 0x0f
|
GetReceiptsMsg = 0x0f
|
||||||
ReceiptsMsg = 0x10
|
ReceiptsMsg = 0x10
|
||||||
|
|
||||||
// Protocol messages belonging to eth/64
|
|
||||||
GetAcctProofMsg = 0x11
|
|
||||||
GetStorageDataProof = 0x12
|
|
||||||
Proof = 0x13
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type errCode int
|
type errCode int
|
||||||
|
|
|
@ -41,10 +41,9 @@ var testAccount = crypto.NewKey(rand.Reader)
|
||||||
func TestStatusMsgErrors61(t *testing.T) { testStatusMsgErrors(t, 61) }
|
func TestStatusMsgErrors61(t *testing.T) { testStatusMsgErrors(t, 61) }
|
||||||
func TestStatusMsgErrors62(t *testing.T) { testStatusMsgErrors(t, 62) }
|
func TestStatusMsgErrors62(t *testing.T) { testStatusMsgErrors(t, 62) }
|
||||||
func TestStatusMsgErrors63(t *testing.T) { testStatusMsgErrors(t, 63) }
|
func TestStatusMsgErrors63(t *testing.T) { testStatusMsgErrors(t, 63) }
|
||||||
func TestStatusMsgErrors64(t *testing.T) { testStatusMsgErrors(t, 64) }
|
|
||||||
|
|
||||||
func testStatusMsgErrors(t *testing.T, protocol int) {
|
func testStatusMsgErrors(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, 0, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, 0, nil, nil)
|
||||||
td, currentBlock, genesis := pm.blockchain.Status()
|
td, currentBlock, genesis := pm.blockchain.Status()
|
||||||
defer pm.Stop()
|
defer pm.Stop()
|
||||||
|
|
||||||
|
@ -95,11 +94,10 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
|
||||||
func TestRecvTransactions61(t *testing.T) { testRecvTransactions(t, 61) }
|
func TestRecvTransactions61(t *testing.T) { testRecvTransactions(t, 61) }
|
||||||
func TestRecvTransactions62(t *testing.T) { testRecvTransactions(t, 62) }
|
func TestRecvTransactions62(t *testing.T) { testRecvTransactions(t, 62) }
|
||||||
func TestRecvTransactions63(t *testing.T) { testRecvTransactions(t, 63) }
|
func TestRecvTransactions63(t *testing.T) { testRecvTransactions(t, 63) }
|
||||||
func TestRecvTransactions64(t *testing.T) { testRecvTransactions(t, 64) }
|
|
||||||
|
|
||||||
func testRecvTransactions(t *testing.T, protocol int) {
|
func testRecvTransactions(t *testing.T, protocol int) {
|
||||||
txAdded := make(chan []*types.Transaction)
|
txAdded := make(chan []*types.Transaction)
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, 0, nil, txAdded)
|
pm := newTestProtocolManagerMust(t, false, 0, nil, txAdded)
|
||||||
p, _ := newTestPeer("peer", protocol, pm, true)
|
p, _ := newTestPeer("peer", protocol, pm, true)
|
||||||
defer pm.Stop()
|
defer pm.Stop()
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
@ -124,10 +122,9 @@ func testRecvTransactions(t *testing.T, protocol int) {
|
||||||
func TestSendTransactions61(t *testing.T) { testSendTransactions(t, 61) }
|
func TestSendTransactions61(t *testing.T) { testSendTransactions(t, 61) }
|
||||||
func TestSendTransactions62(t *testing.T) { testSendTransactions(t, 62) }
|
func TestSendTransactions62(t *testing.T) { testSendTransactions(t, 62) }
|
||||||
func TestSendTransactions63(t *testing.T) { testSendTransactions(t, 63) }
|
func TestSendTransactions63(t *testing.T) { testSendTransactions(t, 63) }
|
||||||
func TestSendTransactions64(t *testing.T) { testSendTransactions(t, 64) }
|
|
||||||
|
|
||||||
func testSendTransactions(t *testing.T, protocol int) {
|
func testSendTransactions(t *testing.T, protocol int) {
|
||||||
pm := newTestProtocolManagerMust(t, ArchiveMode, 0, nil, nil)
|
pm := newTestProtocolManagerMust(t, false, 0, nil, nil)
|
||||||
defer pm.Stop()
|
defer pm.Stop()
|
||||||
|
|
||||||
// Fill the pool with big transactions.
|
// Fill the pool with big transactions.
|
||||||
|
|
Loading…
Reference in New Issue