mirror of
https://github.com/status-im/op-geth.git
synced 2025-02-09 05:16:37 +00:00
core, miner: move Backend to miner
This ensures that package core doesn't depend on package accounts and resolves an age-old TODO.
This commit is contained in:
parent
1a9e66915b
commit
3c09c5f12d
@ -19,12 +19,9 @@ package core
|
|||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validator is an interface which defines the standard for block validation.
|
// Validator is an interface which defines the standard for block validation.
|
||||||
@ -63,15 +60,3 @@ type HeaderValidator interface {
|
|||||||
type Processor interface {
|
type Processor interface {
|
||||||
Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error)
|
Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backend is an interface defining the basic functionality for an operable node
|
|
||||||
// with all the functionality to be a functional, valid Ethereum operator.
|
|
||||||
//
|
|
||||||
// TODO Remove this
|
|
||||||
type Backend interface {
|
|
||||||
AccountManager() *accounts.Manager
|
|
||||||
BlockChain() *BlockChain
|
|
||||||
TxPool() *TxPool
|
|
||||||
ChainDb() ethdb.Database
|
|
||||||
EventMux() *event.TypeMux
|
|
||||||
}
|
|
||||||
|
@ -22,11 +22,13 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
@ -34,6 +36,15 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Backend wraps all methods required for mining.
|
||||||
|
type Backend interface {
|
||||||
|
AccountManager() *accounts.Manager
|
||||||
|
BlockChain() *core.BlockChain
|
||||||
|
TxPool() *core.TxPool
|
||||||
|
ChainDb() ethdb.Database
|
||||||
|
}
|
||||||
|
|
||||||
|
// Miner creates blocks and searches for proof-of-work values.
|
||||||
type Miner struct {
|
type Miner struct {
|
||||||
mux *event.TypeMux
|
mux *event.TypeMux
|
||||||
|
|
||||||
@ -44,15 +55,21 @@ type Miner struct {
|
|||||||
threads int
|
threads int
|
||||||
coinbase common.Address
|
coinbase common.Address
|
||||||
mining int32
|
mining int32
|
||||||
eth core.Backend
|
eth Backend
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
|
|
||||||
canStart int32 // can start indicates whether we can start the mining operation
|
canStart int32 // can start indicates whether we can start the mining operation
|
||||||
shouldStart int32 // should start indicates whether we should start after sync
|
shouldStart int32 // should start indicates whether we should start after sync
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(eth core.Backend, config *core.ChainConfig, mux *event.TypeMux, pow pow.PoW) *Miner {
|
func New(eth Backend, config *core.ChainConfig, mux *event.TypeMux, pow pow.PoW) *Miner {
|
||||||
miner := &Miner{eth: eth, mux: mux, pow: pow, worker: newWorker(config, common.Address{}, eth), canStart: 1}
|
miner := &Miner{
|
||||||
|
eth: eth,
|
||||||
|
mux: mux,
|
||||||
|
pow: pow,
|
||||||
|
worker: newWorker(config, common.Address{}, eth, mux),
|
||||||
|
canStart: 1,
|
||||||
|
}
|
||||||
go miner.update()
|
go miner.update()
|
||||||
|
|
||||||
return miner
|
return miner
|
||||||
|
@ -60,7 +60,7 @@ type uint64RingBuffer struct {
|
|||||||
next int //where is the next insertion? assert 0 <= next < len(ints)
|
next int //where is the next insertion? assert 0 <= next < len(ints)
|
||||||
}
|
}
|
||||||
|
|
||||||
// environment is the workers current environment and holds
|
// Work is the workers current environment and holds
|
||||||
// all of the current state information
|
// all of the current state information
|
||||||
type Work struct {
|
type Work struct {
|
||||||
config *core.ChainConfig
|
config *core.ChainConfig
|
||||||
@ -105,7 +105,7 @@ type worker struct {
|
|||||||
recv chan *Result
|
recv chan *Result
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
|
|
||||||
eth core.Backend
|
eth Backend
|
||||||
chain *core.BlockChain
|
chain *core.BlockChain
|
||||||
proc core.Validator
|
proc core.Validator
|
||||||
chainDb ethdb.Database
|
chainDb ethdb.Database
|
||||||
@ -130,11 +130,11 @@ type worker struct {
|
|||||||
fullValidation bool
|
fullValidation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(config *core.ChainConfig, coinbase common.Address, eth core.Backend) *worker {
|
func newWorker(config *core.ChainConfig, coinbase common.Address, eth Backend, mux *event.TypeMux) *worker {
|
||||||
worker := &worker{
|
worker := &worker{
|
||||||
config: config,
|
config: config,
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: eth.EventMux(),
|
mux: mux,
|
||||||
chainDb: eth.ChainDb(),
|
chainDb: eth.ChainDb(),
|
||||||
recv: make(chan *Result, resultQueueSize),
|
recv: make(chan *Result, resultQueueSize),
|
||||||
gasPrice: new(big.Int),
|
gasPrice: new(big.Int),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user