diff options
Diffstat (limited to 'eth')
-rw-r--r-- | eth/backend.go | 219 | ||||
-rw-r--r-- | eth/downloader/downloader.go | 42 | ||||
-rw-r--r-- | eth/downloader/downloader_test.go | 84 | ||||
-rw-r--r-- | eth/downloader/events.go | 10 | ||||
-rw-r--r-- | eth/downloader/peer.go | 10 | ||||
-rw-r--r-- | eth/downloader/queue.go | 10 | ||||
-rw-r--r-- | eth/fetcher/fetcher.go | 10 | ||||
-rw-r--r-- | eth/fetcher/fetcher_test.go | 13 | ||||
-rw-r--r-- | eth/fetcher/metrics.go | 10 | ||||
-rw-r--r-- | eth/gasprice.go | 10 | ||||
-rw-r--r-- | eth/handler.go | 11 | ||||
-rw-r--r-- | eth/metrics.go | 10 | ||||
-rw-r--r-- | eth/peer.go | 10 | ||||
-rw-r--r-- | eth/protocol.go | 12 | ||||
-rw-r--r-- | eth/protocol_test.go | 18 | ||||
-rw-r--r-- | eth/sync.go | 12 |
16 files changed, 289 insertions, 202 deletions
diff --git a/eth/backend.go b/eth/backend.go index e7250c019..c9b71803f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -1,18 +1,18 @@ // Copyright 2014 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // Package eth implements the Ethereum protocol. package eth @@ -45,6 +45,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/nat" + "github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/whisper" ) @@ -77,9 +78,11 @@ type Config struct { GenesisNonce int GenesisFile string GenesisBlock *types.Block // used by block tests + Olympic bool BlockChainVersion int SkipBcVersionCheck bool // e.g. blockchain export + DatabaseCache int DataDir string LogFile string @@ -89,6 +92,7 @@ type Config struct { NatSpec bool AutoDAG bool PowTest bool + ExtraData []byte MaxPeers int MaxPendingPeers int @@ -203,9 +207,8 @@ type Ethereum struct { shutdownChan chan bool // DB interfaces - blockDb common.Database // Block chain database - stateDb common.Database // State changes database - extraDb common.Database // Extra database (txs, etc) + chainDb common.Database // Block chain databe + dappDb common.Database // Dapp database // Closed when databases are flushed and closed databasesClosed chan bool @@ -261,29 +264,29 @@ func New(config *Config) (*Ethereum, error) { newdb := config.NewDB if newdb == nil { - newdb = func(path string) (common.Database, error) { return ethdb.NewLDBDatabase(path) } + newdb = func(path string) (common.Database, error) { return ethdb.NewLDBDatabase(path, config.DatabaseCache) } } - blockDb, err := newdb(filepath.Join(config.DataDir, "blockchain")) - if err != nil { - return nil, fmt.Errorf("blockchain db err: %v", err) - } - if db, ok := blockDb.(*ethdb.LDBDatabase); ok { - db.Meter("eth/db/block/") + + // attempt to merge database together, upgrading from an old version + if err := mergeDatabases(config.DataDir, newdb); err != nil { + return nil, err } - stateDb, err := newdb(filepath.Join(config.DataDir, "state")) + + chainDb, err := newdb(filepath.Join(config.DataDir, "chaindata")) if err != nil { - return nil, fmt.Errorf("state db err: %v", err) + return nil, fmt.Errorf("blockchain db err: %v", err) } - if db, ok := stateDb.(*ethdb.LDBDatabase); ok { - db.Meter("eth/db/state/") + if db, ok := chainDb.(*ethdb.LDBDatabase); ok { + db.Meter("eth/db/chaindata/") } - extraDb, err := newdb(filepath.Join(config.DataDir, "extra")) + dappDb, err := newdb(filepath.Join(config.DataDir, "dapp")) if err != nil { - return nil, fmt.Errorf("extra db err: %v", err) + return nil, fmt.Errorf("dapp db err: %v", err) } - if db, ok := extraDb.(*ethdb.LDBDatabase); ok { - db.Meter("eth/db/extra/") + if db, ok := dappDb.(*ethdb.LDBDatabase); ok { + db.Meter("eth/db/dapp/") } + nodeDb := filepath.Join(config.DataDir, "nodes") glog.V(logger.Info).Infof("Protocol Versions: %v, Network Id: %v", ProtocolVersions, config.NetworkId) @@ -293,35 +296,42 @@ func New(config *Config) (*Ethereum, error) { return nil, err } - block, err := core.WriteGenesisBlock(stateDb, blockDb, fr) + block, err := core.WriteGenesisBlock(chainDb, fr) if err != nil { return nil, err } glog.V(logger.Info).Infof("Successfully wrote genesis block. New genesis hash = %x\n", block.Hash()) } + if config.Olympic { + _, err := core.WriteTestNetGenesisBlock(chainDb, 42) + if err != nil { + return nil, err + } + glog.V(logger.Error).Infoln("Starting Olympic network") + } + // This is for testing only. if config.GenesisBlock != nil { - core.WriteBlock(blockDb, config.GenesisBlock) - core.WriteHead(blockDb, config.GenesisBlock) + core.WriteBlock(chainDb, config.GenesisBlock) + core.WriteHead(chainDb, config.GenesisBlock) } if !config.SkipBcVersionCheck { - b, _ := blockDb.Get([]byte("BlockchainVersion")) + b, _ := chainDb.Get([]byte("BlockchainVersion")) bcVersion := int(common.NewValue(b).Uint()) if bcVersion != config.BlockChainVersion && bcVersion != 0 { return nil, fmt.Errorf("Blockchain DB version mismatch (%d / %d). Run geth upgradedb.\n", bcVersion, config.BlockChainVersion) } - saveBlockchainVersion(blockDb, config.BlockChainVersion) + saveBlockchainVersion(chainDb, config.BlockChainVersion) } glog.V(logger.Info).Infof("Blockchain DB Version: %d", config.BlockChainVersion) eth := &Ethereum{ shutdownChan: make(chan bool), databasesClosed: make(chan bool), - blockDb: blockDb, - stateDb: stateDb, - extraDb: extraDb, + chainDb: chainDb, + dappDb: dappDb, eventMux: &event.TypeMux{}, accountManager: config.AccountManager, DataDir: config.DataDir, @@ -351,7 +361,7 @@ func New(config *Config) (*Ethereum, error) { eth.pow = ethash.New() } //genesis := core.GenesisBlock(uint64(config.GenesisNonce), stateDb) - eth.chainManager, err = core.NewChainManager(blockDb, stateDb, extraDb, eth.pow, eth.EventMux()) + eth.chainManager, err = core.NewChainManager(chainDb, eth.pow, eth.EventMux()) if err != nil { if err == core.ErrNoGenesis { return nil, fmt.Errorf(`Genesis block not found. Please supply a genesis block with the "--genesis /path/to/file" argument`) @@ -361,12 +371,14 @@ func New(config *Config) (*Ethereum, error) { } eth.txPool = core.NewTxPool(eth.EventMux(), eth.chainManager.State, eth.chainManager.GasLimit) - eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.chainManager, eth.EventMux()) + eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockProcessor) eth.protocolManager = NewProtocolManager(config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.chainManager) eth.miner = miner.New(eth, eth.EventMux(), eth.pow) eth.miner.SetGasPrice(config.GasPrice) + eth.miner.SetExtra(config.ExtraData) + if config.Shh { eth.whisper = whisper.New() eth.shhVersionId = int(eth.whisper.Version()) @@ -480,7 +492,11 @@ func (s *Ethereum) StartMining(threads int) error { func (s *Ethereum) Etherbase() (eb common.Address, err error) { eb = s.etherbase if (eb == common.Address{}) { - err = fmt.Errorf("etherbase address must be explicitly specified") + addr, e := s.AccountManager().AddressByIndex(0) + if e != nil { + err = fmt.Errorf("etherbase address must be explicitly specified") + } + eb = common.HexToAddress(addr) } return } @@ -503,9 +519,8 @@ func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcess func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper } func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } -func (s *Ethereum) BlockDb() common.Database { return s.blockDb } -func (s *Ethereum) StateDb() common.Database { return s.stateDb } -func (s *Ethereum) ExtraDb() common.Database { return s.extraDb } +func (s *Ethereum) ChainDb() common.Database { return s.chainDb } +func (s *Ethereum) DappDb() common.Database { return s.dappDb } func (s *Ethereum) IsListening() bool { return true } // Always listening func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } @@ -552,23 +567,19 @@ done: select { case <-ticker.C: // don't change the order of database flushes - if err := s.extraDb.Flush(); err != nil { - glog.Fatalf("fatal error: flush extraDb: %v (Restart your node. We are aware of this issue)\n", err) - } - if err := s.stateDb.Flush(); err != nil { - glog.Fatalf("fatal error: flush stateDb: %v (Restart your node. We are aware of this issue)\n", err) + if err := s.dappDb.Flush(); err != nil { + glog.Fatalf("fatal error: flush dappDb: %v (Restart your node. We are aware of this issue)\n", err) } - if err := s.blockDb.Flush(); err != nil { - glog.Fatalf("fatal error: flush blockDb: %v (Restart your node. We are aware of this issue)\n", err) + if err := s.chainDb.Flush(); err != nil { + glog.Fatalf("fatal error: flush chainDb: %v (Restart your node. We are aware of this issue)\n", err) } case <-s.shutdownChan: break done } } - s.blockDb.Close() - s.stateDb.Close() - s.extraDb.Close() + s.chainDb.Close() + s.dappDb.Close() close(s.databasesClosed) } @@ -666,14 +677,6 @@ func (self *Ethereum) StartAutoDAG() { }() } -// dagFiles(epoch) returns the two alternative DAG filenames (not a path) -// 1) <revision>-<hex(seedhash[8])> 2) full-R<revision>-<hex(seedhash[8])> -func dagFiles(epoch uint64) (string, string) { - seedHash, _ := ethash.GetSeedHash(epoch * epochLength) - dag := fmt.Sprintf("full-R%d-%x", ethashRevision, seedHash[:8]) - return dag, "full-R" + dag -} - // stopAutoDAG stops automatic DAG pregeneration by quitting the loop func (self *Ethereum) StopAutoDAG() { if self.autodagquit != nil { @@ -683,20 +686,28 @@ func (self *Ethereum) StopAutoDAG() { glog.V(logger.Info).Infof("Automatic pregeneration of ethash DAG OFF (ethash dir: %s)", ethash.DefaultDir) } -/* - // The databases were previously tied to protocol versions. Currently we - // are moving away from this decision as approaching Frontier. The below - // code was left in for now but should eventually be just dropped. +func (self *Ethereum) Solc() (*compiler.Solidity, error) { + var err error + if self.solc == nil { + self.solc, err = compiler.New(self.SolcPath) + } + return self.solc, err +} - func saveProtocolVersion(db common.Database, protov int) { - d, _ := db.Get([]byte("ProtocolVersion")) - protocolVersion := common.NewValue(d).Uint() +// set in js console via admin interface or wrapper from cli flags +func (self *Ethereum) SetSolc(solcPath string) (*compiler.Solidity, error) { + self.SolcPath = solcPath + self.solc = nil + return self.Solc() +} - if protocolVersion == 0 { - db.Put([]byte("ProtocolVersion"), common.NewValue(protov).Bytes()) - } - } -*/ +// dagFiles(epoch) returns the two alternative DAG filenames (not a path) +// 1) <revision>-<hex(seedhash[8])> 2) full-R<revision>-<hex(seedhash[8])> +func dagFiles(epoch uint64) (string, string) { + seedHash, _ := ethash.GetSeedHash(epoch * epochLength) + dag := fmt.Sprintf("full-R%d-%x", ethashRevision, seedHash[:8]) + return dag, "full-R" + dag +} func saveBlockchainVersion(db common.Database, bcVersion int) { d, _ := db.Get([]byte("BlockchainVersion")) @@ -707,17 +718,69 @@ func saveBlockchainVersion(db common.Database, bcVersion int) { } } -func (self *Ethereum) Solc() (*compiler.Solidity, error) { - var err error - if self.solc == nil { - self.solc, err = compiler.New(self.SolcPath) +// mergeDatabases when required merge old database layout to one single database +func mergeDatabases(datadir string, newdb func(path string) (common.Database, error)) error { + // Check if already upgraded + data := filepath.Join(datadir, "chaindata") + if _, err := os.Stat(data); !os.IsNotExist(err) { + return nil } - return self.solc, err -} + // make sure it's not just a clean path + chainPath := filepath.Join(datadir, "blockchain") + if _, err := os.Stat(chainPath); os.IsNotExist(err) { + return nil + } + glog.Infoln("Database upgrade required. Upgrading...") -// set in js console via admin interface or wrapper from cli flags -func (self *Ethereum) SetSolc(solcPath string) (*compiler.Solidity, error) { - self.SolcPath = solcPath - self.solc = nil - return self.Solc() + database, err := newdb(data) + if err != nil { + return fmt.Errorf("creating data db err: %v", err) + } + defer database.Close() + + glog.Infoln("Merging blockchain database...") + chainDb, err := newdb(chainPath) + if err != nil { + return fmt.Errorf("state db err: %v", err) + } + defer chainDb.Close() + + if db, ok := chainDb.(*ethdb.LDBDatabase); ok { + it := db.NewIterator() + for it.Next() { + database.Put(it.Key(), it.Value()) + } + } + + glog.Infoln("Merging state database...") + state := filepath.Join(datadir, "state") + stateDb, err := newdb(state) + if err != nil { + return fmt.Errorf("state db err: %v", err) + } + defer stateDb.Close() + + if db, ok := chainDb.(*ethdb.LDBDatabase); ok { + it := db.NewIterator() + for it.Next() { + database.Put(append(trie.StatePre, it.Key()...), it.Value()) + } + } + + glog.Infoln("Merging transaction database...") + extra := filepath.Join(datadir, "extra") + extraDb, err := newdb(extra) + if err != nil { + return fmt.Errorf("state db err: %v", err) + } + defer extraDb.Close() + + if db, ok := chainDb.(*ethdb.LDBDatabase); ok { + it := db.NewIterator() + for it.Next() { + database.Put(it.Key(), it.Value()) + } + } + + return nil } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 7cf83ada3..e3e22a784 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // Package downloader contains the manual full chain synchronisation. package downloader @@ -21,6 +21,7 @@ import ( "bytes" "errors" "math" + "math/big" "math/rand" "sync" "sync/atomic" @@ -232,10 +233,10 @@ func (d *Downloader) UnregisterPeer(id string) error { // Synchronise tries to sync up our local block chain with a remote peer, both // adding various sanity checks as well as wrapping it with various log entries. -func (d *Downloader) Synchronise(id string, head common.Hash) { - glog.V(logger.Detail).Infof("Attempting synchronisation: %v, 0x%x", id, head) +func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int) { + glog.V(logger.Detail).Infof("Attempting synchronisation: %v, head 0x%x, TD %v", id, head[:4], td) - switch err := d.synchronise(id, head); err { + switch err := d.synchronise(id, head, td); err { case nil: glog.V(logger.Detail).Infof("Synchronisation completed") @@ -257,7 +258,7 @@ func (d *Downloader) Synchronise(id string, head common.Hash) { // synchronise will select the peer and use it for synchronising. If an empty string is given // it will use the best peer possible and synchronize if it's TD is higher than our own. If any of the // checks fail an error will be returned. This method is synchronous -func (d *Downloader) synchronise(id string, hash common.Hash) error { +func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int) error { // Mock out the synchonisation if testing if d.synchroniseMock != nil { return d.synchroniseMock(id, hash) @@ -295,7 +296,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash) error { if p == nil { return errUnknownPeer } - return d.syncWithPeer(p, hash) + return d.syncWithPeer(p, hash, td) } // Has checks if the downloader knows about a particular hash, meaning that its @@ -306,7 +307,7 @@ func (d *Downloader) Has(hash common.Hash) bool { // syncWithPeer starts a block synchronization based on the hash chain from the // specified peer and head hash. -func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) { +func (d *Downloader) syncWithPeer(p *peer, hash common.Hash, td *big.Int) (err error) { d.mux.Post(StartEvent{}) defer func() { // reset on error @@ -335,7 +336,7 @@ func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) { return err } errc := make(chan error, 2) - go func() { errc <- d.fetchHashes(p, number+1) }() + go func() { errc <- d.fetchHashes(p, td, number+1) }() go func() { errc <- d.fetchBlocks(number + 1) }() // If any fetcher fails, cancel the other @@ -788,7 +789,7 @@ func (d *Downloader) findAncestor(p *peer) (uint64, error) { // fetchHashes keeps retrieving hashes from the requested number, until no more // are returned, potentially throttling on the way. -func (d *Downloader) fetchHashes(p *peer, from uint64) error { +func (d *Downloader) fetchHashes(p *peer, td *big.Int, from uint64) error { glog.V(logger.Debug).Infof("%v: downloading hashes from #%d", p, from) // Create a timeout timer, and the associated hash fetcher @@ -827,8 +828,19 @@ func (d *Downloader) fetchHashes(p *peer, from uint64) error { case d.processCh <- false: case <-d.cancelCh: } - // Error out if no hashes were retrieved at all - if !gotHashes { + // If no hashes were retrieved at all, the peer violated it's TD promise that it had a + // better chain compared to ours. The only exception is if it's promised blocks were + // already imported by other means (e.g. fecher): + // + // R <remote peer>, L <local node>: Both at block 10 + // R: Mine block 11, and propagate it to L + // L: Queue block 11 for import + // L: Notice that R's head and TD increased compared to ours, start sync + // L: Import of block 11 finishes + // L: Sync begins, and finds common ancestor at 11 + // L: Request new hashes up from 11 (R's TD was higher, it must have something) + // R: Nothing to give + if !gotHashes && td.Cmp(d.headBlock().Td) > 0 { return errStallingPeer } return nil diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index cf1d0c2fb..61fc7827b 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package downloader @@ -97,8 +97,18 @@ func newTester() *downloadTester { } // sync starts synchronizing with a remote peer, blocking until it completes. -func (dl *downloadTester) sync(id string) error { - err := dl.downloader.synchronise(id, dl.peerHashes[id][0]) +func (dl *downloadTester) sync(id string, td *big.Int) error { + hash := dl.peerHashes[id][0] + + // If no particular TD was requested, load from the peer's blockchain + if td == nil { + td = big.NewInt(1) + if block, ok := dl.peerBlocks[id][hash]; ok { + td = block.Td + } + } + err := dl.downloader.synchronise(id, hash, td) + for { // If the queue is empty and processing stopped, break hashes, blocks := dl.downloader.queue.Size() @@ -261,7 +271,7 @@ func TestSynchronisation60(t *testing.T) { tester.newPeer("peer", eth60, hashes, blocks) // Synchronise with the peer and make sure all blocks were retrieved - if err := tester.sync("peer"); err != nil { + if err := tester.sync("peer", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != targetBlocks+1 { @@ -281,7 +291,7 @@ func TestCanonicalSynchronisation61(t *testing.T) { tester.newPeer("peer", eth61, hashes, blocks) // Synchronise with the peer and make sure all blocks were retrieved - if err := tester.sync("peer"); err != nil { + if err := tester.sync("peer", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != targetBlocks+1 { @@ -312,7 +322,7 @@ func testThrottling(t *testing.T, protocol int) { // Start a synchronisation concurrently errc := make(chan error) go func() { - errc <- tester.sync("peer") + errc <- tester.sync("peer", nil) }() // Iteratively take some blocks, always checking the retrieval count for len(tester.ownBlocks) < targetBlocks+1 { @@ -361,14 +371,14 @@ func TestForkedSynchronisation61(t *testing.T) { tester.newPeer("fork B", eth61, hashesB, blocksB) // Synchronise with the peer and make sure all blocks were retrieved - if err := tester.sync("fork A"); err != nil { + if err := tester.sync("fork A", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != common+fork+1 { t.Fatalf("synchronised block mismatch: have %v, want %v", imported, common+fork+1) } // Synchronise with the second peer and make sure that fork is pulled too - if err := tester.sync("fork B"); err != nil { + if err := tester.sync("fork B", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != common+2*fork+1 { @@ -411,7 +421,7 @@ func testCancel(t *testing.T, protocol int) { t.Errorf("block or hash count mismatch: %d hashes, %d blocks, want 0", hashCount, blockCount) } // Synchronise with the peer, but cancel afterwards - if err := tester.sync("peer"); err != nil { + if err := tester.sync("peer", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } tester.downloader.cancel() @@ -438,14 +448,14 @@ func testMultiSynchronisation(t *testing.T, protocol int) { } // Synchronise with the middle peer and make sure half of the blocks were retrieved id := fmt.Sprintf("peer #%d", targetPeers/2) - if err := tester.sync(id); err != nil { + if err := tester.sync(id, nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != len(tester.peerHashes[id]) { t.Fatalf("synchronised block mismatch: have %v, want %v", imported, len(tester.peerHashes[id])) } // Synchronise with the best peer and make sure everything is retrieved - if err := tester.sync("peer #0"); err != nil { + if err := tester.sync("peer #0", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != targetBlocks+1 { @@ -469,7 +479,7 @@ func TestSlowSynchronisation60(t *testing.T) { // Try to sync with the peers (pull hashes from fast) start := time.Now() - if err := tester.sync("fast"); err != nil { + if err := tester.sync("fast", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if imported := len(tester.ownBlocks); imported != targetBlocks+1 { @@ -497,14 +507,14 @@ func TestNonExistingParentAttack60(t *testing.T) { tester.newPeer("attack", eth60, hashes, blocks) // Try and sync with the malicious node and check that it fails - if err := tester.sync("attack"); err == nil { + if err := tester.sync("attack", nil); err == nil { t.Fatalf("block synchronization succeeded") } if tester.hasBlock(hashes[0]) { t.Fatalf("tester accepted unknown-parent block: %v", blocks[hashes[0]]) } // Try to synchronize with the valid chain and make sure it succeeds - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } if !tester.hasBlock(tester.peerHashes["valid"][0]) { @@ -525,7 +535,7 @@ func TestRepeatingHashAttack60(t *testing.T) { // TODO: Is this thing valid?? // Try and sync with the malicious node errc := make(chan error) go func() { - errc <- tester.sync("attack") + errc <- tester.sync("attack", nil) }() // Make sure that syncing returns and does so with a failure select { @@ -537,7 +547,7 @@ func TestRepeatingHashAttack60(t *testing.T) { // TODO: Is this thing valid?? } } // Ensure that a valid chain can still pass sync - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -555,11 +565,11 @@ func TestNonExistingBlockAttack60(t *testing.T) { tester.newPeer("attack", eth60, hashes, blocks) // Try and sync with the malicious node and check that it fails - if err := tester.sync("attack"); err != errPeersUnavailable { + if err := tester.sync("attack", nil); err != errPeersUnavailable { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errPeersUnavailable) } // Ensure that a valid chain can still pass sync - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -583,11 +593,11 @@ func TestInvalidHashOrderAttack60(t *testing.T) { tester.newPeer("attack", eth60, hashes, blocks) // Try and sync with the malicious node and check that it fails - if err := tester.sync("attack"); err != errInvalidChain { + if err := tester.sync("attack", nil); err != errInvalidChain { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errInvalidChain) } // Ensure that a valid chain can still pass sync - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -611,11 +621,11 @@ func TestMadeupHashChainAttack60(t *testing.T) { tester.newPeer("attack", eth60, randomHashes, nil) // Try and sync with the malicious node and check that it fails - if err := tester.sync("attack"); err != errCrossCheckFailed { + if err := tester.sync("attack", nil); err != errCrossCheckFailed { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errCrossCheckFailed) } // Ensure that a valid chain can still pass sync - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -636,7 +646,7 @@ func TestMadeupHashChainDrippingAttack60(t *testing.T) { // Try and sync with the attacker, one hash at a time tester.maxHashFetch = 1 tester.newPeer("attack", eth60, randomHashes, nil) - if err := tester.sync("attack"); err != errStallingPeer { + if err := tester.sync("attack", nil); err != errStallingPeer { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errStallingPeer) } } @@ -659,7 +669,7 @@ func TestMadeupBlockChainAttack60(t *testing.T) { // Try and sync with the malicious node and check that it fails tester := newTester() tester.newPeer("attack", eth60, gapped, blocks) - if err := tester.sync("attack"); err != errCrossCheckFailed { + if err := tester.sync("attack", nil); err != errCrossCheckFailed { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errCrossCheckFailed) } // Ensure that a valid chain can still pass sync @@ -667,7 +677,7 @@ func TestMadeupBlockChainAttack60(t *testing.T) { crossCheckCycle = defaultCrossCheckCycle tester.newPeer("valid", eth60, hashes, blocks) - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -690,7 +700,7 @@ func TestBannedChainStarvationAttack60(t *testing.T) { // the head of the invalid chain is blocked too. for banned := tester.downloader.banned.Size(); ; { // Try to sync with the attacker, check hash chain failure - if err := tester.sync("attack"); err != errInvalidChain { + if err := tester.sync("attack", nil); err != errInvalidChain { if tester.downloader.banned.Has(forkHashes[0]) && err == errBannedHead { break } @@ -711,7 +721,7 @@ func TestBannedChainStarvationAttack60(t *testing.T) { t.Fatalf("banned attacker registered: %v", peer) } // Ensure that a valid chain can still pass sync - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -743,7 +753,7 @@ func TestBannedChainMemoryExhaustionAttack60(t *testing.T) { // the head of the invalid chain is blocked too. for { // Try to sync with the attacker, check hash chain failure - if err := tester.sync("attack"); err != errInvalidChain { + if err := tester.sync("attack", nil); err != errInvalidChain { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errInvalidChain) } // Short circuit if the entire chain was banned. @@ -754,7 +764,7 @@ func TestBannedChainMemoryExhaustionAttack60(t *testing.T) { if bans := tester.downloader.banned.Size(); bans > maxBannedHashes { t.Fatalf("ban cap exceeded: have %v, want max %v", bans, maxBannedHashes) } - for hash, _ := range core.BadHashes { + for hash := range core.BadHashes { if !tester.downloader.banned.Has(hash) { t.Fatalf("hard coded ban evacuated: %x", hash) } @@ -764,7 +774,7 @@ func TestBannedChainMemoryExhaustionAttack60(t *testing.T) { MaxBlockFetch = defaultMaxBlockFetch maxBannedHashes = defaultMaxBannedHashes - if err := tester.sync("valid"); err != nil { + if err := tester.sync("valid", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } } @@ -790,7 +800,7 @@ func TestOverlappingDeliveryAttack60(t *testing.T) { return rawGetBlocks(append(request, hashes[0])) } // Test that synchronisation can complete, check for import success - if err := tester.sync("attack"); err != nil { + if err := tester.sync("attack", nil); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } start := time.Now() @@ -807,7 +817,7 @@ func TestOverlappingDeliveryAttack60(t *testing.T) { func TestHighTDStarvationAttack61(t *testing.T) { tester := newTester() tester.newPeer("attack", eth61, []common.Hash{genesis.Hash()}, nil) - if err := tester.sync("attack"); err != errStallingPeer { + if err := tester.sync("attack", big.NewInt(1000000)); err != errStallingPeer { t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errStallingPeer) } } @@ -849,7 +859,7 @@ func TestHashAttackerDropping(t *testing.T) { // Simulate a synchronisation and check the required result tester.downloader.synchroniseMock = func(string, common.Hash) error { return tt.result } - tester.downloader.Synchronise(id, genesis.Hash()) + tester.downloader.Synchronise(id, genesis.Hash(), big.NewInt(1000)) if _, ok := tester.peerHashes[id]; !ok != tt.drop { t.Errorf("test %d: peer drop mismatch for %v: have %v, want %v", i, tt.result, !ok, tt.drop) } diff --git a/eth/downloader/events.go b/eth/downloader/events.go index e5c62e121..64905b8f2 100644 --- a/eth/downloader/events.go +++ b/eth/downloader/events.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package downloader diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go index 89b40d1ac..4273b9168 100644 --- a/eth/downloader/peer.go +++ b/eth/downloader/peer.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // Contains the active peer-set of the downloader, maintaining both failures // as well as reputation metrics to prioritize the block retrievals. diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index a758410a5..96e08e144 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // Contains the block download scheduler to collect download tasks and schedule // them in an ordered, and throttled way. diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go index 376cf6f6f..55b6c5c1c 100644 --- a/eth/fetcher/fetcher.go +++ b/eth/fetcher/fetcher.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // Package fetcher contains the block announcement based synchonisation. package fetcher diff --git a/eth/fetcher/fetcher_test.go b/eth/fetcher/fetcher_test.go index 5050cb742..ecbb3f868 100644 --- a/eth/fetcher/fetcher_test.go +++ b/eth/fetcher/fetcher_test.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package fetcher @@ -28,12 +28,13 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/params" ) var ( testdb, _ = ethdb.NewMemDatabase() genesis = core.GenesisBlockForTesting(testdb, common.Address{}, big.NewInt(0)) - unknownBlock = types.NewBlock(&types.Header{}, nil, nil, nil) + unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit}, nil, nil, nil) ) // makeChain creates a chain of n blocks starting at and including parent. diff --git a/eth/fetcher/metrics.go b/eth/fetcher/metrics.go index 93f328bc9..76cc49226 100644 --- a/eth/fetcher/metrics.go +++ b/eth/fetcher/metrics.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // Contains the metrics collected by the fetcher. diff --git a/eth/gasprice.go b/eth/gasprice.go index fbb7fec3f..031098e9a 100644 --- a/eth/gasprice.go +++ b/eth/gasprice.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth diff --git a/eth/handler.go b/eth/handler.go index 50e2ac99b..2bd369901 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth @@ -95,6 +95,7 @@ func NewProtocolManager(networkId int, mux *event.TypeMux, txpool txPool, pow po newPeerCh: make(chan *peer, 1), txsyncCh: make(chan *txsync), quitSync: make(chan struct{}), + netId: networkId, } // Initiate a sub-protocol for every implemented version we can handle manager.SubProtocols = make([]p2p.Protocol, len(ProtocolVersions)) diff --git a/eth/metrics.go b/eth/metrics.go index 132172cb5..625b90b67 100644 --- a/eth/metrics.go +++ b/eth/metrics.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth diff --git a/eth/peer.go b/eth/peer.go index d70ad4c94..ade1f37ea 100644 --- a/eth/peer.go +++ b/eth/peer.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth diff --git a/eth/protocol.go b/eth/protocol.go index 704a637e2..b8c9b50d0 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -1,18 +1,18 @@ // Copyright 2014 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth @@ -30,7 +30,7 @@ var ProtocolVersions = []uint{61, 60} var ProtocolLengths = []uint64{9, 8} const ( - NetworkId = 0 + NetworkId = 1 ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message ) diff --git a/eth/protocol_test.go b/eth/protocol_test.go index 77941852f..08c9b6a06 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -1,18 +1,18 @@ // Copyright 2014 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth @@ -60,7 +60,7 @@ func TestStatusMsgErrors(t *testing.T) { }, { code: StatusMsg, data: statusData{uint32(ProtocolVersions[0]), 999, td, currentBlock, genesis}, - wantError: errResp(ErrNetworkIdMismatch, "999 (!= 0)"), + wantError: errResp(ErrNetworkIdMismatch, "999 (!= 1)"), }, { code: StatusMsg, data: statusData{uint32(ProtocolVersions[0]), NetworkId, td, currentBlock, common.Hash{3}}, @@ -179,12 +179,12 @@ type testPeer struct { func newProtocolManagerForTesting(txAdded chan<- []*types.Transaction) *ProtocolManager { db, _ := ethdb.NewMemDatabase() - core.WriteTestNetGenesisBlock(db, db, 0) + core.WriteTestNetGenesisBlock(db, 0) var ( em = new(event.TypeMux) - chain, _ = core.NewChainManager(db, db, db, core.FakePow{}, em) + chain, _ = core.NewChainManager(db, core.FakePow{}, em) txpool = &fakeTxPool{added: txAdded} - pm = NewProtocolManager(0, em, txpool, core.FakePow{}, chain) + pm = NewProtocolManager(NetworkId, em, txpool, core.FakePow{}, chain) ) pm.Start() return pm diff --git a/eth/sync.go b/eth/sync.go index 11e229af6..b4dea4b0f 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -1,18 +1,18 @@ // Copyright 2015 The go-ethereum Authors -// This file is part of go-ethereum. +// This file is part of the go-ethereum library. // -// go-ethereum is free software: you can redistribute it and/or modify +// The go-ethereum library is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// go-ethereum is distributed in the hope that it will be useful, +// The go-ethereum library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License -// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. package eth @@ -164,5 +164,5 @@ func (pm *ProtocolManager) synchronise(peer *peer) { return } // Otherwise try to sync with the downloader - pm.downloader.Synchronise(peer.id, peer.Head()) + pm.downloader.Synchronise(peer.id, peer.Head(), peer.Td()) } |