aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2019-08-15 01:09:01 -0400
committerDeterminant <ted.sybil@gmail.com>2019-08-15 01:09:01 -0400
commit0cfa95ffa018041e53b056365a66fee32235779f (patch)
treeb512d51597c0a54f511ffd007d365ca1ec713978
parentd271cc649e34963507411d4915512353ae1780e4 (diff)
apply the stupid gofmt
-rw-r--r--coreth.go105
-rw-r--r--eth/backend.go12
-rw-r--r--miner/miner.go58
-rw-r--r--miner/worker.go55
-rw-r--r--node/node.go2
5 files changed, 113 insertions, 119 deletions
diff --git a/coreth.go b/coreth.go
index 06471a9..49864c7 100644
--- a/coreth.go
+++ b/coreth.go
@@ -1,19 +1,19 @@
package coreth
import (
- "io"
- "os"
- "crypto/ecdsa"
-
- "github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/event"
- "github.com/Determinant/coreth/eth"
- "github.com/Determinant/coreth/node"
- "github.com/Determinant/coreth/consensus/dummy"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
- "github.com/mattn/go-isatty"
+ "crypto/ecdsa"
+ "io"
+ "os"
+
+ "github.com/Determinant/coreth/consensus/dummy"
+ "github.com/Determinant/coreth/eth"
+ "github.com/Determinant/coreth/node"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/crypto"
+ "github.com/ethereum/go-ethereum/event"
+ "github.com/ethereum/go-ethereum/log"
+ "github.com/mattn/go-isatty"
)
type Tx = types.Transaction
@@ -21,81 +21,80 @@ type Block = types.Block
type Hash = common.Hash
type ETHChain struct {
- backend *eth.Ethereum
- cb *dummy.ConsensusCallbacks
+ backend *eth.Ethereum
+ cb *dummy.ConsensusCallbacks
}
-
func isLocalBlock(block *types.Block) bool {
- return false
+ return false
}
func NewETHChain(config *eth.Config, etherBase *common.Address) *ETHChain {
- if config == nil {
- config = &eth.DefaultConfig
- }
- mux := new(event.TypeMux)
- ctx := node.NewServiceContext(mux)
- cb := new(dummy.ConsensusCallbacks)
- backend, _ := eth.New(&ctx, config, cb)
- chain := &ETHChain { backend: backend, cb: cb }
- if etherBase == nil {
- etherBase = &common.Address{
- 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- }
- }
- backend.SetEtherbase(*etherBase)
- return chain
+ if config == nil {
+ config = &eth.DefaultConfig
+ }
+ mux := new(event.TypeMux)
+ ctx := node.NewServiceContext(mux)
+ cb := new(dummy.ConsensusCallbacks)
+ backend, _ := eth.New(&ctx, config, cb)
+ chain := &ETHChain{backend: backend, cb: cb}
+ if etherBase == nil {
+ etherBase = &common.Address{
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ }
+ }
+ backend.SetEtherbase(*etherBase)
+ return chain
}
func (self *ETHChain) Start() {
- self.backend.StartMining(0)
+ self.backend.StartMining(0)
}
func (self *ETHChain) Stop() {
- self.backend.StopPart()
+ self.backend.StopPart()
}
func (self *ETHChain) GenBlock() {
- self.backend.Miner().GenBlock()
+ self.backend.Miner().GenBlock()
}
func (self *ETHChain) AddRemoteTxs(txs []*types.Transaction) []error {
- return self.backend.TxPool().AddRemotes(txs)
+ return self.backend.TxPool().AddRemotes(txs)
}
func (self *ETHChain) AddLocalTxs(txs []*types.Transaction) []error {
- return self.backend.TxPool().AddLocals(txs)
+ return self.backend.TxPool().AddLocals(txs)
}
func (self *ETHChain) SetOnSeal(cb func(*types.Block)) {
- self.cb.OnSeal = cb
+ self.cb.OnSeal = cb
}
type Key struct {
- Address common.Address
+ Address common.Address
PrivateKey *ecdsa.PrivateKey
}
func NewKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key {
- key := &Key{
- Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey),
- PrivateKey: privateKeyECDSA,
- }
- return key
+ key := &Key{
+ Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey),
+ PrivateKey: privateKeyECDSA,
+ }
+ return key
}
func NewKey(rand io.Reader) (*Key, error) {
- privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand)
- if err != nil {
- return nil, err
- }
- return NewKeyFromECDSA(privateKeyECDSA), nil
+ privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand)
+ if err != nil {
+ return nil, err
+ }
+ return NewKeyFromECDSA(privateKeyECDSA), nil
}
func init() {
- usecolor := (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb"
- glogger := log.StreamHandler(io.Writer(os.Stderr), log.TerminalFormat(usecolor))
- log.Root().SetHandler(glogger)
+ usecolor := (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb"
+ glogger := log.StreamHandler(io.Writer(os.Stderr), log.TerminalFormat(usecolor))
+ log.Root().SetHandler(glogger)
}
diff --git a/eth/backend.go b/eth/backend.go
index a2cda02..5f2aa75 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -25,6 +25,11 @@ import (
"sync"
"sync/atomic"
+ "github.com/Determinant/coreth/consensus/dummy"
+ mycore "github.com/Determinant/coreth/core"
+ "github.com/Determinant/coreth/internal/ethapi"
+ "github.com/Determinant/coreth/miner"
+ "github.com/Determinant/coreth/node"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
@@ -33,8 +38,6 @@ import (
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
- mycore "github.com/Determinant/coreth/core"
- "github.com/Determinant/coreth/consensus/dummy"
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
@@ -44,10 +47,7 @@ import (
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
- "github.com/Determinant/coreth/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
- "github.com/Determinant/coreth/miner"
- "github.com/Determinant/coreth/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/params"
@@ -246,7 +246,7 @@ func makeExtraData(extra []byte) []byte {
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database, cb *dummy.ConsensusCallbacks) consensus.Engine {
- return dummy.NewDummyEngine(cb)
+ return dummy.NewDummyEngine(cb)
}
// APIs return the collection of RPC services the ethereum package offers.
diff --git a/miner/miner.go b/miner/miner.go
index 53a37b0..e4ff64c 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -18,18 +18,18 @@
package miner
import (
- "fmt"
- "time"
- "math/big"
+ "fmt"
+ "math/big"
+ "time"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/hexutil"
+ "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
+ "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
- "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/params"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/core/state"
)
// Backend wraps all methods required for mining.
@@ -40,43 +40,42 @@ type Backend interface {
// Config is the configuration parameters of mining.
type Config struct {
- Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account)
- Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
- ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
- GasFloor uint64 // Target gas floor for mined blocks.
- GasCeil uint64 // Target gas ceiling for mined blocks.
- GasPrice *big.Int // Minimum gas price for mining a transaction
- Recommit time.Duration // The time interval for miner to re-create mining work.
- Noverify bool // Disable remote mining solution verification(only useful in ethash).
- ManualMining bool
- ManualUncle bool
+ Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account)
+ Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
+ ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
+ GasFloor uint64 // Target gas floor for mined blocks.
+ GasCeil uint64 // Target gas ceiling for mined blocks.
+ GasPrice *big.Int // Minimum gas price for mining a transaction
+ Recommit time.Duration // The time interval for miner to re-create mining work.
+ Noverify bool // Disable remote mining solution verification(only useful in ethash).
+ ManualMining bool
+ ManualUncle bool
}
type Miner struct {
- w *worker
+ w *worker
}
func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, isLocalBlock func(block *types.Block) bool) *Miner {
- return &Miner {
- w: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock),
- }
+ return &Miner{
+ w: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock),
+ }
}
-
func (self *Miner) Start(coinbase common.Address) {
- self.w.start()
+ self.w.start()
}
func (self *Miner) Stop() {
- self.w.stop()
+ self.w.stop()
}
-func (self *Miner) Mining() bool {
- return false
+func (self *Miner) Mining() bool {
+ return false
}
func (self *Miner) HashRate() uint64 {
- return 0
+ return 0
}
func (self *Miner) SetExtra(extra []byte) error {
@@ -95,15 +94,14 @@ func (self *Miner) Pending() (*types.Block, *state.StateDB) {
return self.w.pending()
}
-
func (self *Miner) PendingBlock() *types.Block {
return self.w.pendingBlock()
}
func (self *Miner) SetEtherbase(addr common.Address) {
- self.w.setEtherbase(addr)
+ self.w.setEtherbase(addr)
}
func (self *Miner) GenBlock() {
- self.w.genBlock()
+ self.w.genBlock()
}
diff --git a/miner/worker.go b/miner/worker.go
index 304c014..80fef3a 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -14,9 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//
-// NOTE: this piece of code is adopted from
-// github.com/ethereum/go-ethereum/miner/worker.go,
-// modified by Ted Yin.
+// NOTE: this piece of code is modified by Ted Yin.
// The modification is also licensed under the same LGPL.
package miner
@@ -28,7 +26,7 @@ import (
"sync"
"sync/atomic"
"time"
- //"fmt"
+ //"fmt"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/common"
@@ -180,8 +178,8 @@ type worker struct {
skipSealHook func(*task) bool // Method to decide whether skipping the sealing.
fullTaskHook func() // Method to call before pushing the full sealing task.
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
- manualMining bool
- manualUncle bool
+ manualMining bool
+ manualUncle bool
}
func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool) *worker {
@@ -207,8 +205,8 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
startCh: make(chan struct{}, 1),
resubmitIntervalCh: make(chan time.Duration),
resubmitAdjustCh: make(chan *intervalAdjust, resubmitAdjustChanSize),
- manualMining: config.ManualMining,
- manualUncle: config.ManualUncle,
+ manualMining: config.ManualMining,
+ manualUncle: config.ManualUncle,
}
// Subscribe NewTxsEvent for tx pool
worker.txsSub = eth.TxPool().SubscribeNewTxsEvent(worker.txsCh)
@@ -295,13 +293,13 @@ func (w *worker) close() {
}
func (w *worker) genBlock() {
- interrupt := new(int32)
- *interrupt = commitInterruptNone
- w.newWorkCh <- &newWorkReq{
- interrupt: interrupt,
- noempty: false,
- timestamp: time.Now().Unix(),
- }
+ interrupt := new(int32)
+ *interrupt = commitInterruptNone
+ w.newWorkCh <- &newWorkReq{
+ interrupt: interrupt,
+ noempty: false,
+ timestamp: time.Now().Unix(),
+ }
}
// newWorkLoop is a standalone goroutine to submit new mining work upon received events.
@@ -362,18 +360,18 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
case <-w.startCh:
clearPending(w.chain.CurrentBlock().NumberU64())
timestamp = time.Now().Unix()
- if !w.manualMining {
- log.Trace("commit ch")
- commit(false, commitInterruptNewHead)
- }
+ if !w.manualMining {
+ log.Trace("commit ch")
+ commit(false, commitInterruptNewHead)
+ }
case head := <-w.chainHeadCh:
clearPending(head.Block.NumberU64())
timestamp = time.Now().Unix()
- if !w.manualMining {
- log.Trace("commit update")
- commit(false, commitInterruptNewHead)
- }
+ if !w.manualMining {
+ log.Trace("commit update")
+ commit(false, commitInterruptNewHead)
+ }
case <-timer.C:
// If mining is running resubmit a new work cycle periodically to pull in
@@ -384,7 +382,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
timer.Reset(recommit)
continue
}
- log.Trace("commit resubmit")
+ log.Trace("commit resubmit")
commit(true, commitInterruptResubmit)
}
@@ -616,9 +614,9 @@ func (w *worker) resultLoop() {
logs = append(logs, receipt.Logs...)
}
// Commit block and state to database.
- //fmt.Printf("parent1: %s\n", w.chain.CurrentBlock().Hash().String())
+ //fmt.Printf("parent1: %s\n", w.chain.CurrentBlock().Hash().String())
stat, err := w.chain.WriteBlockWithState(block, receipts, task.state)
- //fmt.Printf("parent2: %s\n", w.chain.CurrentBlock().Hash().String())
+ //fmt.Printf("parent2: %s\n", w.chain.CurrentBlock().Hash().String())
if err != nil {
log.Error("Failed writing block to chain", "err", err)
continue
@@ -628,7 +626,6 @@ func (w *worker) resultLoop() {
// Broadcast the block and announce chain insertion event
w.mux.Post(core.NewMinedBlockEvent{Block: block})
- //w.chain.FastSyncCommitHead(block.Hash())
var events []interface{}
switch stat {
@@ -948,7 +945,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
if !noempty && !w.manualUncle {
// Create an empty block based on temporary copied state for sealing in advance without waiting block
// execution finished.
- log.Trace("commit n1")
+ log.Trace("commit n1")
w.commit(uncles, nil, false, tstart)
}
@@ -983,7 +980,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
return
}
}
- log.Trace("commit n2")
+ log.Trace("commit n2")
w.commit(uncles, w.fullTaskHook, true, tstart)
}
diff --git a/node/node.go b/node/node.go
index bf496a4..5422e2c 100644
--- a/node/node.go
+++ b/node/node.go
@@ -26,11 +26,11 @@ import (
"strings"
"sync"
+ "github.com/Determinant/coreth/internal/debug"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
- "github.com/Determinant/coreth/internal/debug"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"