forked from cerc-io/plugeth
"centralised" mining to backend. Closes #323
This commit is contained in:
parent
164de5e22b
commit
8135752a32
@ -43,7 +43,7 @@ type AppContainer interface {
|
|||||||
|
|
||||||
type ExtApplication struct {
|
type ExtApplication struct {
|
||||||
*xeth.XEth
|
*xeth.XEth
|
||||||
eth core.EthManager
|
eth core.Backend
|
||||||
|
|
||||||
events event.Subscription
|
events event.Subscription
|
||||||
watcherQuitChan chan bool
|
watcherQuitChan chan bool
|
||||||
|
@ -41,7 +41,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
|
||||||
"github.com/ethereum/go-ethereum/ui/qt/qwhisper"
|
"github.com/ethereum/go-ethereum/ui/qt/qwhisper"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
@ -81,8 +80,6 @@ type Gui struct {
|
|||||||
config *ethutil.ConfigManager
|
config *ethutil.ConfigManager
|
||||||
|
|
||||||
plugins map[string]plugin
|
plugins map[string]plugin
|
||||||
|
|
||||||
miner *miner.Miner
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GUI, but doesn't start it
|
// Create GUI, but doesn't start it
|
||||||
@ -454,7 +451,7 @@ func (gui *Gui) update() {
|
|||||||
case <-generalUpdateTicker.C:
|
case <-generalUpdateTicker.C:
|
||||||
statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number().String()
|
statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number().String()
|
||||||
lastBlockLabel.Set("text", statusText)
|
lastBlockLabel.Set("text", statusText)
|
||||||
miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.miner.HashRate(), 10)+"/Khash")
|
miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.Miner().HashRate(), 10)+"/Khash")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
blockLength := gui.eth.BlockPool().BlocksProcessed
|
blockLength := gui.eth.BlockPool().BlocksProcessed
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/event/filter"
|
"github.com/ethereum/go-ethereum/event/filter"
|
||||||
"github.com/ethereum/go-ethereum/javascript"
|
"github.com/ethereum/go-ethereum/javascript"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
)
|
)
|
||||||
@ -56,13 +55,10 @@ type UiLib struct {
|
|||||||
|
|
||||||
filterCallbacks map[int][]int
|
filterCallbacks map[int][]int
|
||||||
filterManager *filter.FilterManager
|
filterManager *filter.FilterManager
|
||||||
|
|
||||||
miner *miner.Miner
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
|
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
|
||||||
lib := &UiLib{XEth: xeth.New(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
|
lib := &UiLib{XEth: xeth.New(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
|
||||||
lib.miner = miner.New(eth.KeyManager().Address(), eth)
|
|
||||||
lib.filterManager = filter.NewFilterManager(eth.EventMux())
|
lib.filterManager = filter.NewFilterManager(eth.EventMux())
|
||||||
go lib.filterManager.Start()
|
go lib.filterManager.Start()
|
||||||
|
|
||||||
@ -221,20 +217,20 @@ func (self *UiLib) RemoveLocalTransaction(id int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) SetGasPrice(price string) {
|
func (self *UiLib) SetGasPrice(price string) {
|
||||||
self.miner.MinAcceptedGasPrice = ethutil.Big(price)
|
self.Miner().MinAcceptedGasPrice = ethutil.Big(price)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) SetExtra(extra string) {
|
func (self *UiLib) SetExtra(extra string) {
|
||||||
self.miner.Extra = extra
|
self.Miner().Extra = extra
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) ToggleMining() bool {
|
func (self *UiLib) ToggleMining() bool {
|
||||||
if !self.miner.Mining() {
|
if !self.Miner().Mining() {
|
||||||
self.miner.Start()
|
self.Miner().Start()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
self.miner.Stop()
|
self.Miner().Stop()
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ type FilterOptions struct {
|
|||||||
|
|
||||||
// Filtering interface
|
// Filtering interface
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
eth EthManager
|
eth Backend
|
||||||
earliest int64
|
earliest int64
|
||||||
latest int64
|
latest int64
|
||||||
skip int
|
skip int
|
||||||
@ -40,7 +40,7 @@ type Filter struct {
|
|||||||
|
|
||||||
// Create a new filter which uses a bloom filter on blocks to figure out whether a particular block
|
// Create a new filter which uses a bloom filter on blocks to figure out whether a particular block
|
||||||
// is interesting or not.
|
// is interesting or not.
|
||||||
func NewFilter(eth EthManager) *Filter {
|
func NewFilter(eth Backend) *Filter {
|
||||||
return &Filter{eth: eth}
|
return &Filter{eth: eth}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,11 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EthManager interface {
|
type Backend interface {
|
||||||
BlockProcessor() *BlockProcessor
|
BlockProcessor() *BlockProcessor
|
||||||
ChainManager() *ChainManager
|
ChainManager() *ChainManager
|
||||||
TxPool() *TxPool
|
TxPool() *TxPool
|
||||||
PeerCount() int
|
PeerCount() int
|
||||||
IsMining() bool
|
|
||||||
IsListening() bool
|
IsListening() bool
|
||||||
Peers() []*p2p.Peer
|
Peers() []*p2p.Peer
|
||||||
KeyManager() *crypto.KeyManager
|
KeyManager() *crypto.KeyManager
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||||
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
@ -95,6 +96,7 @@ type Ethereum struct {
|
|||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
txSub event.Subscription
|
txSub event.Subscription
|
||||||
blockSub event.Subscription
|
blockSub event.Subscription
|
||||||
|
miner *miner.Miner
|
||||||
|
|
||||||
RpcServer rpc.RpcServer
|
RpcServer rpc.RpcServer
|
||||||
WsServer rpc.RpcServer
|
WsServer rpc.RpcServer
|
||||||
@ -151,6 +153,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
|
eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
|
||||||
eth.chainManager.SetProcessor(eth.blockProcessor)
|
eth.chainManager.SetProcessor(eth.blockProcessor)
|
||||||
eth.whisper = whisper.New()
|
eth.whisper = whisper.New()
|
||||||
|
eth.miner = miner.New(keyManager.Address(), eth)
|
||||||
|
|
||||||
hasBlock := eth.chainManager.HasBlock
|
hasBlock := eth.chainManager.HasBlock
|
||||||
insertChain := eth.chainManager.InsertChain
|
insertChain := eth.chainManager.InsertChain
|
||||||
@ -181,69 +184,22 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
return eth, nil
|
return eth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ethereum) KeyManager() *crypto.KeyManager {
|
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
|
||||||
return s.keyManager
|
func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger }
|
||||||
}
|
func (s *Ethereum) Name() string { return s.net.Name }
|
||||||
|
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
||||||
func (s *Ethereum) Logger() ethlogger.LogSystem {
|
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
||||||
return s.logger
|
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
|
||||||
}
|
func (s *Ethereum) BlockPool() *BlockPool { return s.blockPool }
|
||||||
|
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
|
||||||
func (s *Ethereum) Name() string {
|
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
|
||||||
return s.net.Name
|
func (s *Ethereum) Db() ethutil.Database { return s.db }
|
||||||
}
|
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
||||||
|
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
||||||
func (s *Ethereum) ChainManager() *core.ChainManager {
|
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
||||||
return s.chainManager
|
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
|
||||||
}
|
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
|
||||||
|
func (s *Ethereum) Coinbase() []byte { return nil } // TODO
|
||||||
func (s *Ethereum) BlockProcessor() *core.BlockProcessor {
|
|
||||||
return s.blockProcessor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) TxPool() *core.TxPool {
|
|
||||||
return s.txPool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) BlockPool() *BlockPool {
|
|
||||||
return s.blockPool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) Whisper() *whisper.Whisper {
|
|
||||||
return s.whisper
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) EventMux() *event.TypeMux {
|
|
||||||
return s.eventMux
|
|
||||||
}
|
|
||||||
func (self *Ethereum) Db() ethutil.Database {
|
|
||||||
return self.db
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) IsMining() bool {
|
|
||||||
return s.Mining
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) IsListening() bool {
|
|
||||||
// XXX TODO
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) PeerCount() int {
|
|
||||||
return s.net.PeerCount()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) Peers() []*p2p.Peer {
|
|
||||||
return s.net.Peers()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) MaxPeers() int {
|
|
||||||
return s.net.MaxPeers
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) Coinbase() []byte {
|
|
||||||
return nil // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the ethereum
|
// Start the ethereum
|
||||||
func (s *Ethereum) Start() error {
|
func (s *Ethereum) Start() error {
|
||||||
|
@ -3,7 +3,7 @@ package miner
|
|||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/pow/ezp"
|
"github.com/ethereum/go-ethereum/pow/ezp"
|
||||||
)
|
)
|
||||||
@ -16,13 +16,13 @@ type Miner struct {
|
|||||||
MinAcceptedGasPrice *big.Int
|
MinAcceptedGasPrice *big.Int
|
||||||
Extra string
|
Extra string
|
||||||
|
|
||||||
coinbase []byte
|
Coinbase []byte
|
||||||
mining bool
|
mining bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(coinbase []byte, eth *eth.Ethereum) *Miner {
|
func New(coinbase []byte, eth core.Backend) *Miner {
|
||||||
miner := &Miner{
|
miner := &Miner{
|
||||||
coinbase: coinbase,
|
Coinbase: coinbase,
|
||||||
worker: newWorker(coinbase, eth),
|
worker: newWorker(coinbase, eth),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
@ -25,7 +24,7 @@ type environment struct {
|
|||||||
uncles *set.Set
|
uncles *set.Set
|
||||||
}
|
}
|
||||||
|
|
||||||
func env(block *types.Block, eth *eth.Ethereum) *environment {
|
func env(block *types.Block, eth core.Backend) *environment {
|
||||||
state := state.New(block.Root(), eth.Db())
|
state := state.New(block.Root(), eth.Db())
|
||||||
env := &environment{
|
env := &environment{
|
||||||
totalUsedGas: new(big.Int),
|
totalUsedGas: new(big.Int),
|
||||||
@ -63,7 +62,7 @@ type worker struct {
|
|||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
|
|
||||||
eth *eth.Ethereum
|
eth core.Backend
|
||||||
chain *core.ChainManager
|
chain *core.ChainManager
|
||||||
proc *core.BlockProcessor
|
proc *core.BlockProcessor
|
||||||
coinbase []byte
|
coinbase []byte
|
||||||
@ -73,7 +72,7 @@ type worker struct {
|
|||||||
mining bool
|
mining bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(coinbase []byte, eth *eth.Ethereum) *worker {
|
func newWorker(coinbase []byte, eth core.Backend) *worker {
|
||||||
return &worker{
|
return &worker{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: eth.EventMux(),
|
mux: eth.EventMux(),
|
||||||
|
@ -15,7 +15,7 @@ func fromHex(s string) []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter {
|
func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter {
|
||||||
filter := core.NewFilter(eth)
|
filter := core.NewFilter(eth)
|
||||||
|
|
||||||
if object["earliest"] != nil {
|
if object["earliest"] != nil {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter {
|
func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter {
|
||||||
filter := ui.NewFilterFromMap(object, eth)
|
filter := ui.NewFilterFromMap(object, eth)
|
||||||
|
|
||||||
if object["topics"] != nil {
|
if object["topics"] != nil {
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"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/miner"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/whisper"
|
"github.com/ethereum/go-ethereum/whisper"
|
||||||
@ -27,13 +28,13 @@ type Backend interface {
|
|||||||
ChainManager() *core.ChainManager
|
ChainManager() *core.ChainManager
|
||||||
TxPool() *core.TxPool
|
TxPool() *core.TxPool
|
||||||
PeerCount() int
|
PeerCount() int
|
||||||
IsMining() bool
|
|
||||||
IsListening() bool
|
IsListening() bool
|
||||||
Peers() []*p2p.Peer
|
Peers() []*p2p.Peer
|
||||||
KeyManager() *crypto.KeyManager
|
KeyManager() *crypto.KeyManager
|
||||||
Db() ethutil.Database
|
Db() ethutil.Database
|
||||||
EventMux() *event.TypeMux
|
EventMux() *event.TypeMux
|
||||||
Whisper() *whisper.Whisper
|
Whisper() *whisper.Whisper
|
||||||
|
Miner() *miner.Miner
|
||||||
}
|
}
|
||||||
|
|
||||||
type XEth struct {
|
type XEth struct {
|
||||||
@ -42,6 +43,7 @@ type XEth struct {
|
|||||||
chainManager *core.ChainManager
|
chainManager *core.ChainManager
|
||||||
state *State
|
state *State
|
||||||
whisper *Whisper
|
whisper *Whisper
|
||||||
|
miner *miner.Miner
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(eth Backend) *XEth {
|
func New(eth Backend) *XEth {
|
||||||
@ -50,6 +52,7 @@ func New(eth Backend) *XEth {
|
|||||||
blockProcessor: eth.BlockProcessor(),
|
blockProcessor: eth.BlockProcessor(),
|
||||||
chainManager: eth.ChainManager(),
|
chainManager: eth.ChainManager(),
|
||||||
whisper: NewWhisper(eth.Whisper()),
|
whisper: NewWhisper(eth.Whisper()),
|
||||||
|
miner: eth.Miner(),
|
||||||
}
|
}
|
||||||
xeth.state = NewState(xeth)
|
xeth.state = NewState(xeth)
|
||||||
|
|
||||||
@ -59,6 +62,7 @@ func New(eth Backend) *XEth {
|
|||||||
func (self *XEth) Backend() Backend { return self.eth }
|
func (self *XEth) Backend() Backend { return self.eth }
|
||||||
func (self *XEth) State() *State { return self.state }
|
func (self *XEth) State() *State { return self.state }
|
||||||
func (self *XEth) Whisper() *Whisper { return self.whisper }
|
func (self *XEth) Whisper() *Whisper { return self.whisper }
|
||||||
|
func (self *XEth) Miner() *miner.Miner { return self.miner }
|
||||||
|
|
||||||
func (self *XEth) BlockByHash(strHash string) *Block {
|
func (self *XEth) BlockByHash(strHash string) *Block {
|
||||||
hash := fromHex(strHash)
|
hash := fromHex(strHash)
|
||||||
@ -96,7 +100,7 @@ func (self *XEth) PeerCount() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) IsMining() bool {
|
func (self *XEth) IsMining() bool {
|
||||||
return self.eth.IsMining()
|
return self.miner.Mining()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) IsListening() bool {
|
func (self *XEth) IsListening() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user