From 4c490db6afeb5a48d3e8d1d65ea8ddc9811d0a6d Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Tue, 30 Jun 2015 09:13:16 +0200 Subject: Use uint64 for block header timestamp --- miner/worker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index f06b6afa1..90914ddcb 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -368,8 +368,8 @@ func (self *worker) commitNewWork() { tstart := time.Now() parent := self.chain.CurrentBlock() tstamp := tstart.Unix() - if tstamp <= parent.Time() { - tstamp = parent.Time() + 1 + if tstamp <= int64(parent.Time()) { + tstamp = int64(parent.Time()) + 1 } // this will ensure we're not going off too far in the future if now := time.Now().Unix(); tstamp > now+4 { @@ -382,7 +382,7 @@ func (self *worker) commitNewWork() { header := &types.Header{ ParentHash: parent.Hash(), Number: num.Add(num, common.Big1), - Difficulty: core.CalcDifficulty(tstamp, parent.Time(), parent.Difficulty()), + Difficulty: core.CalcDifficulty(int64(tstamp), int64(parent.Time()), parent.Difficulty()), GasLimit: core.CalcGasLimit(parent), GasUsed: new(big.Int), Coinbase: self.coinbase, -- cgit v1.2.3 From 29e2fb38f8e80dfa077d139d8ff563169c644d74 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Fri, 3 Jul 2015 11:24:42 +0200 Subject: core, miner: miner header validation, transaction & receipt writing * Miners do now verify their own header, not their state. * Changed old putTx and putReceipts to be exported * Moved writing of transactions and receipts out of the block processer in to the chain manager. Closes #1386 * Miner post ChainHeadEvent & ChainEvent. Closes #1388 --- miner/worker.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index 90914ddcb..a23b663f9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -79,9 +79,10 @@ type worker struct { quit chan struct{} pow pow.PoW - eth core.Backend - chain *core.ChainManager - proc *core.BlockProcessor + eth core.Backend + chain *core.ChainManager + proc *core.BlockProcessor + extraDb common.Database coinbase common.Address gasPrice *big.Int @@ -105,6 +106,7 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker { worker := &worker{ eth: eth, mux: eth.EventMux(), + extraDb: eth.ExtraDb(), recv: make(chan *types.Block), gasPrice: new(big.Int), chain: eth.ChainManager(), @@ -233,11 +235,28 @@ func (self *worker) wait() { continue } - _, err := self.chain.WriteBlock(block, false) + parent := self.chain.GetBlock(block.ParentHash()) + if parent == nil { + glog.V(logger.Error).Infoln("Invalid block found during mining") + continue + } + if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent, true); err != nil { + glog.V(logger.Error).Infoln("Invalid header on mined block:", err) + continue + } + + stat, err := self.chain.WriteBlock(block, false) if err != nil { glog.V(logger.Error).Infoln("error writing block to chain", err) continue } + // check if canon block and write transactions + if stat == core.CanonStatTy { + // This puts transactions in a extra db for rpc + core.PutTransactions(self.extraDb, block, block.Transactions()) + // store the receipts + core.PutReceipts(self.extraDb, block.Hash(), self.current.receipts) + } // check staleness and display confirmation var stale, confirm string @@ -252,7 +271,13 @@ func (self *worker) wait() { glog.V(logger.Info).Infof("🔨 Mined %sblock (#%v / %x). %s", stale, block.Number(), block.Hash().Bytes()[:4], confirm) // broadcast before waiting for validation - go self.mux.Post(core.NewMinedBlockEvent{block}) + go func(block *types.Block, logs state.Logs) { + self.mux.Post(core.NewMinedBlockEvent{block}) + self.mux.Post(core.ChainEvent{block, block.Hash(), logs}) + if stat == core.CanonStatTy { + self.mux.Post(core.ChainHeadEvent{block}) + } + }(block, self.current.state.Logs()) self.commitNewWork() } -- cgit v1.2.3 From 0e33fbdcb9769245f79f76e416f74ac50f51c4ab Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Fri, 3 Jul 2015 17:21:23 +0200 Subject: miner: ignore future errors --- miner/worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index a23b663f9..1c1e8f927 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -240,7 +240,7 @@ func (self *worker) wait() { glog.V(logger.Error).Infoln("Invalid block found during mining") continue } - if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent, true); err != nil { + if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent, true); err != nil && err != core.BlockFutureErr { glog.V(logger.Error).Infoln("Invalid header on mined block:", err) continue } -- cgit v1.2.3 From 2feb23c1dacf1cc7ef664d92f28b63dd46502f21 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 4 Jul 2015 02:25:04 +0200 Subject: core, eth, miner, xeth: receipt storage fix * Added GetReceiptsFromBlock, GetReceipt, PutReceipts * Added ContractAddress to receipt. See #1042 --- miner/worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index 1c1e8f927..dd004da6e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -255,7 +255,7 @@ func (self *worker) wait() { // This puts transactions in a extra db for rpc core.PutTransactions(self.extraDb, block, block.Transactions()) // store the receipts - core.PutReceipts(self.extraDb, block.Hash(), self.current.receipts) + core.PutReceipts(self.extraDb, self.current.receipts) } // check staleness and display confirmation -- cgit v1.2.3 From ab16ce70fc68d9ab1b7d8cda57c180b4785cab6a Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Wed, 1 Jul 2015 12:07:14 +0200 Subject: core, miner, tests: renamed state methods * Update => SyncIntermediate * Added SyncObjects SyncIntermediate only updates whatever has changed, but, as a side effect, requires much more disk space. SyncObjects will only sync whatever is required for a block and will not save intermediate state to disk. As drawback this requires more time when more txs come in. --- miner/worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index dd004da6e..1615ff84b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -453,7 +453,7 @@ func (self *worker) commitNewWork() { if atomic.LoadInt32(&self.mining) == 1 { // commit state root after all state transitions. core.AccumulateRewards(self.current.state, header, uncles) - current.state.Update() + current.state.SyncObjects() self.current.state.Sync() header.Root = current.state.Root() } -- cgit v1.2.3 From bcc1660abc1c0a5ef838dea89e4f3830d84fb51c Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 4 Jul 2015 17:45:18 +0200 Subject: core, miner, tests: added test, implemented bad block reporting --- miner/worker.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index 1615ff84b..c28258799 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -298,8 +298,6 @@ func (self *worker) push() { if agent.Work() != nil { agent.Work() <- self.current.block - } else { - common.Report(fmt.Sprintf("%v %T\n", agent, agent)) } } } -- cgit v1.2.3 From e6bb9c1cadd311475f54ed60630fc20eb2f54871 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 6 Jul 2015 11:54:11 +0200 Subject: core, miner: removed vm errors from consensus err checking Removed VM errors from the consensus errors. They now used for output only. --- miner/worker.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index c28258799..840609721 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -524,18 +524,18 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP err := env.commitTransaction(tx, proc) switch { - case core.IsNonceErr(err) || core.IsInvalidTxErr(err): - env.remove.Add(tx.Hash()) - - if glog.V(logger.Detail) { - glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) - } case state.IsGasLimitErr(err): // ignore the transactor so no nonce errors will be thrown for this account // next time the worker is run, they'll be picked up again. env.ignoredTransactors.Add(from) glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4]) + case err != nil: + env.remove.Add(tx.Hash()) + + if glog.V(logger.Detail) { + glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) + } default: env.tcount++ } @@ -545,7 +545,7 @@ func (env *environment) commitTransactions(transactions types.Transactions, gasP func (env *environment) commitTransaction(tx *types.Transaction, proc *core.BlockProcessor) error { snap := env.state.Copy() receipt, _, err := proc.ApplyTransaction(env.coinbase, env.state, env.header, tx, env.header.GasUsed, true) - if err != nil && (core.IsNonceErr(err) || state.IsGasLimitErr(err) || core.IsInvalidTxErr(err)) { + if err != nil { env.state.Set(snap) return err } -- cgit v1.2.3 From 37c1a8f69de44827a60296342189b6719a49dbc3 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Tue, 7 Jul 2015 10:58:47 +0200 Subject: eth,miner,rpc: set coinbase --- miner/miner.go | 5 +++++ miner/worker.go | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'miner') diff --git a/miner/miner.go b/miner/miner.go index 7f73f3ee8..83f7c4503 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -137,3 +137,8 @@ func (self *Miner) PendingState() *state.StateDB { func (self *Miner) PendingBlock() *types.Block { return self.worker.pendingBlock() } + +func (self *Miner) SetEtherbase(addr common.Address) { + self.coinbase = addr + self.worker.setEtherbase(addr) +} diff --git a/miner/worker.go b/miner/worker.go index 840609721..7be41118c 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -124,6 +124,12 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker { return worker } +func (self *worker) setEtherbase(addr common.Address) { + self.mu.Lock() + defer self.mu.Unlock() + self.coinbase = addr +} + func (self *worker) pendingState() *state.StateDB { self.currentMu.Lock() defer self.currentMu.Unlock() -- cgit v1.2.3 From ea54283b304a1d308141d21e3ef75b7de0f4519d Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 7 Jul 2015 02:54:22 +0200 Subject: all: update license information --- miner/agent.go | 16 ++++++++++++++++ miner/miner.go | 16 ++++++++++++++++ miner/remote_agent.go | 16 ++++++++++++++++ miner/worker.go | 16 ++++++++++++++++ 4 files changed, 64 insertions(+) (limited to 'miner') diff --git a/miner/agent.go b/miner/agent.go index a7d017aa5..8455ed36e 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -1,3 +1,19 @@ +// Copyright 2015 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum 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, +// 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 go-ethereum. If not, see . + package miner import ( diff --git a/miner/miner.go b/miner/miner.go index 83f7c4503..4d44b8c74 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -1,3 +1,19 @@ +// Copyright 2014 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum 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, +// 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 go-ethereum. If not, see . + package miner import ( diff --git a/miner/remote_agent.go b/miner/remote_agent.go index 6a44782f6..b05d9c7e0 100644 --- a/miner/remote_agent.go +++ b/miner/remote_agent.go @@ -1,3 +1,19 @@ +// Copyright 2015 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum 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, +// 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 go-ethereum. If not, see . + package miner import ( diff --git a/miner/worker.go b/miner/worker.go index 7be41118c..79514b231 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1,3 +1,19 @@ +// Copyright 2015 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum 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, +// 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 go-ethereum. If not, see . + package miner import ( -- cgit v1.2.3 From bdae4fd573dbc163bab3d0e2d1a5c457892037cd Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 7 Jul 2015 05:08:16 +0200 Subject: all: add some godoc synopsis comments --- miner/miner.go | 1 + 1 file changed, 1 insertion(+) (limited to 'miner') diff --git a/miner/miner.go b/miner/miner.go index 4d44b8c74..173be1a14 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with go-ethereum. If not, see . +// Package miner implements Ethereum block creation and mining. package miner import ( -- cgit v1.2.3