diff options
author | bas-vk <bas-vk@users.noreply.github.com> | 2016-11-28 21:59:06 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-11-28 21:59:06 +0800 |
commit | b5be6b72cb06ded22075a41db6abc670d33c5ea7 (patch) | |
tree | 288845ba8db1db4d1e0d01ed612240c6229d8a9e /miner/worker.go | |
parent | 318ad3c1e424912ff69c9febc4e08a0137f8803f (diff) | |
download | go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.tar go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.tar.gz go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.tar.bz2 go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.tar.lz go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.tar.xz go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.tar.zst go-tangerine-b5be6b72cb06ded22075a41db6abc670d33c5ea7.zip |
eth/filter: add support for pending logs (#3219)
Diffstat (limited to 'miner/worker.go')
-rw-r--r-- | miner/worker.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/miner/worker.go b/miner/worker.go index 2933b6bd3..ca00c7229 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -262,6 +262,7 @@ func newLocalMinedBlock(blockNumber uint64, prevMinedBlocks *uint64RingBuffer) ( func (self *worker) wait() { for { + mustCommitNewWork := true for result := range self.recv { atomic.AddInt32(&self.atWork, -1) @@ -315,6 +316,8 @@ func (self *worker) wait() { core.WriteReceipts(self.chainDb, work.receipts) // Write map map bloom filters core.WriteMipmapBloom(self.chainDb, block.NumberU64(), work.receipts) + // implicit by posting ChainHeadEvent + mustCommitNewWork = false } // broadcast before waiting for validation @@ -343,7 +346,9 @@ func (self *worker) wait() { } glog.V(logger.Info).Infof("🔨 Mined %sblock (#%v / %x). %s", stale, block.Number(), block.Hash().Bytes()[:4], confirm) - self.commitNewWork() + if mustCommitNewWork { + self.commitNewWork() + } } } } @@ -451,6 +456,7 @@ func (self *worker) commitNewWork() { tstart := time.Now() parent := self.chain.CurrentBlock() + tstamp := tstart.Unix() if parent.Time().Cmp(new(big.Int).SetInt64(tstamp)) >= 0 { tstamp = parent.Time().Int64() + 1 @@ -618,7 +624,16 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB txs.Shift() } } + if len(coalescedLogs) > 0 || env.tcount > 0 { + // make a copy, the state caches the logs and these logs get "upgraded" from pending to mined + // logs by filling in the block hash when the block was mined by the local miner. This can + // cause a race condition if a log was "upgraded" before the PendingLogsEvent is processed. + cpy := make(vm.Logs, len(coalescedLogs)) + for i, l := range coalescedLogs { + cpy[i] = new(vm.Log) + *cpy[i] = *l + } go func(logs vm.Logs, tcount int) { if len(logs) > 0 { mux.Post(core.PendingLogsEvent{Logs: logs}) @@ -626,7 +641,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB if tcount > 0 { mux.Post(core.PendingStateEvent{}) } - }(coalescedLogs, env.tcount) + }(cpy, env.tcount) } } |