diff --git a/eth/filters/api.go b/eth/filters/api.go index b9783031fb..311cd146e5 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -138,6 +138,7 @@ done: // NewBlockFilter create a new filter that returns blocks that are included into the canonical chain. func (s *PublicFilterAPI) NewBlockFilter() (string, error) { +fmt.Println("NewBlockFilter") externalId, err := newFilterId() if err != nil { return "", err @@ -155,8 +156,10 @@ func (s *PublicFilterAPI) NewBlockFilter() (string, error) { filter.BlockCallback = func(block *types.Block, logs vm.Logs) { s.blockMu.Lock() defer s.blockMu.Unlock() +fmt.Println("callback") if queue := s.blockQueue[id]; queue != nil { +fmt.Println(" add") queue.add(block.Hash()) } } @@ -498,8 +501,11 @@ func (s *PublicFilterAPI) blockFilterChanged(id int) []common.Hash { s.blockMu.Lock() defer s.blockMu.Unlock() +fmt.Println("blockFilterChanged") if s.blockQueue[id] != nil { - return s.blockQueue[id].get() + res := s.blockQueue[id].get() +fmt.Println(" len = ", len(res)) + return res } return nil } diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 4343dfa21c..104f6e55ae 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -134,9 +134,12 @@ func (fs *FilterSystem) filterLoop() { for event := range fs.sub.Chan() { switch ev := event.Data.(type) { case core.ChainEvent: +fmt.Println("ChainEvent") fs.filterMu.RLock() for _, filter := range fs.chainFilters { +fmt.Println("1") if filter.BlockCallback != nil && !filter.created.After(event.Time) { +fmt.Println("2") filter.BlockCallback(ev.Block, ev.Logs) } } diff --git a/light/events.go b/light/events.go deleted file mode 100644 index 28d91e31d4..0000000000 --- a/light/events.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// 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. -// -// 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 -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package light - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" -) - -type LightChainSplitEvent struct{ Header *types.Header } - -type LightChainEvent struct { - Header *types.Header - Hash common.Hash -} - -type LightChainSideEvent struct{ Header *types.Header } - -type LightChainHeadEvent struct{ Header *types.Header } diff --git a/light/lightchain.go b/light/lightchain.go index a70cb4493a..f6a1202807 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -338,9 +338,9 @@ func (self *LightChain) Rollback(chain []common.Hash) { // posts them into the event mux. func (self *LightChain) postChainEvents(events []interface{}) { for _, event := range events { - if event, ok := event.(LightChainEvent); ok { + if event, ok := event.(core.ChainEvent); ok { if self.LastBlockHash() == event.Hash { - self.eventMux.Post(LightChainHeadEvent{event.Header}) + self.eventMux.Post(core.ChainHeadEvent{Block: event.Block}) } } // Fire the insertion events individually too @@ -379,16 +379,16 @@ func (self *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) if glog.V(logger.Debug) { glog.Infof("[%v] inserted header #%d (%x...).\n", time.Now().UnixNano(), header.Number, header.Hash().Bytes()[0:4]) } - events = append(events, LightChainEvent{header, header.Hash()}) + events = append(events, core.ChainEvent{Block: types.NewBlockWithHeader(header), Hash: header.Hash()}) case core.SideStatTy: if glog.V(logger.Detail) { glog.Infof("inserted forked header #%d (TD=%v) (%x...).\n", header.Number, header.Difficulty, header.Hash().Bytes()[0:4]) } - events = append(events, LightChainSideEvent{header}) + events = append(events, core.ChainSideEvent{Block: types.NewBlockWithHeader(header)}) case core.SplitStatTy: - events = append(events, LightChainSplitEvent{header}) + events = append(events, core.ChainSplitEvent{Block: types.NewBlockWithHeader(header)}) } return err diff --git a/light/txpool.go b/light/txpool.go index b1e3f92e6a..15a2c540b4 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -84,7 +84,7 @@ func NewTxPool(config *core.ChainConfig, eventMux *event.TypeMux, chain *LightCh mined: make(map[common.Hash][]*types.Transaction), quit: make(chan bool), eventMux: eventMux, - events: eventMux.Subscribe(LightChainHeadEvent{}), + events: eventMux.Subscribe(core.ChainHeadEvent{}), chain: chain, relay: relay, odr: chain.Odr(), @@ -274,7 +274,7 @@ const blockCheckTimeout = time.Second * 3 func (pool *TxPool) eventLoop() { for ev := range pool.events.Chan() { switch ev.Data.(type) { - case LightChainHeadEvent: + case core.ChainHeadEvent: pool.mu.Lock() ctx, _ := context.WithTimeout(context.Background(), blockCheckTimeout) head := pool.chain.CurrentHeader()