diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-12-10 21:10:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-10 21:10:35 +0800 |
commit | 9fe5d200117bab0b2adbcf1d09629879366bcc54 (patch) | |
tree | 7449a43a27c17627540ffde7eb78a8a13ffbe1f7 /eth/handler.go | |
parent | dd98d1da9464c9ae6e1da69d7a41d4551f20bd8d (diff) | |
parent | 31b33349227715e8d1f8753d913892c1e35439d7 (diff) | |
download | go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.tar go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.tar.gz go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.tar.bz2 go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.tar.lz go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.tar.xz go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.tar.zst go-tangerine-9fe5d200117bab0b2adbcf1d09629879366bcc54.zip |
Merge pull request #18028 from ryanschneider/blockhash-whitelist
cmd, eth: add support for `--whitelist <blocknum>=<hash>`
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/eth/handler.go b/eth/handler.go index 741fc9d5a..b42612a56 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -88,6 +88,8 @@ type ProtocolManager struct { txsSub event.Subscription minedBlockSub *event.TypeMuxSubscription + whitelist map[uint64]common.Hash + // channels for fetcher, syncer, txsyncLoop newPeerCh chan *peer txsyncCh chan *txsync @@ -101,7 +103,7 @@ type ProtocolManager struct { // NewProtocolManager returns a new Ethereum sub protocol manager. The Ethereum sub protocol manages peers capable // with the Ethereum network. -func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, networkID uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) { +func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, networkID uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine, blockchain *core.BlockChain, chaindb ethdb.Database, whitelist map[uint64]common.Hash) (*ProtocolManager, error) { // Create the protocol manager with the base fields manager := &ProtocolManager{ networkID: networkID, @@ -110,6 +112,7 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne blockchain: blockchain, chainconfig: config, peers: newPeerSet(), + whitelist: whitelist, newPeerCh: make(chan *peer), noMorePeers: make(chan struct{}), txsyncCh: make(chan *txsync), @@ -307,7 +310,13 @@ func (pm *ProtocolManager) handle(p *peer) error { } }() } - // main loop. handle incoming messages. + // If we have any explicit whitelist block hashes, request them + for number := range pm.whitelist { + if err := p.RequestHeadersByNumber(number, 1, 0, false); err != nil { + return err + } + } + // Handle incoming messages until the connection is torn down for { if err := pm.handleMsg(p); err != nil { p.Log().Debug("Ethereum message handling failed", "err", err) @@ -466,6 +475,14 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { p.Log().Debug("Verified to be on the same side of the DAO fork") return nil } + // Otherwise if it's a whitelisted block, validate against the set + if want, ok := pm.whitelist[headers[0].Number.Uint64()]; ok { + if hash := headers[0].Hash(); want != hash { + p.Log().Info("Whitelist mismatch, dropping peer", "number", headers[0].Number.Uint64(), "hash", hash, "want", want) + return errors.New("whitelist block mismatch") + } + p.Log().Debug("Whitelist block verified", "number", headers[0].Number.Uint64(), "hash", want) + } // Irrelevant of the fork checks, send the header to the fetcher just in case headers = pm.fetcher.FilterHeaders(p.id, headers, time.Now()) } |