github.com/MetalBlockchain/subnet-evm@v0.4.9/miner/miner.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. 2 // 3 // This file is a derived work, based on the go-ethereum library whose original 4 // notices appear below. 5 // 6 // It is distributed under a license compatible with the licensing terms of the 7 // original code from which it is derived. 8 // 9 // Much love to the original authors for their work. 10 // ********** 11 // Copyright 2014 The go-ethereum Authors 12 // This file is part of the go-ethereum library. 13 // 14 // The go-ethereum library is free software: you can redistribute it and/or modify 15 // it under the terms of the GNU Lesser General Public License as published by 16 // the Free Software Foundation, either version 3 of the License, or 17 // (at your option) any later version. 18 // 19 // The go-ethereum library is distributed in the hope that it will be useful, 20 // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 // GNU Lesser General Public License for more details. 23 // 24 // You should have received a copy of the GNU Lesser General Public License 25 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 26 27 // Package miner implements Ethereum block creation and mining. 28 package miner 29 30 import ( 31 "github.com/MetalBlockchain/metalgo/utils/timer/mockable" 32 "github.com/MetalBlockchain/subnet-evm/consensus" 33 "github.com/MetalBlockchain/subnet-evm/core" 34 "github.com/MetalBlockchain/subnet-evm/core/types" 35 "github.com/MetalBlockchain/subnet-evm/params" 36 "github.com/ethereum/go-ethereum/common" 37 "github.com/ethereum/go-ethereum/event" 38 ) 39 40 // Backend wraps all methods required for mining. 41 type Backend interface { 42 BlockChain() *core.BlockChain 43 TxPool() *core.TxPool 44 } 45 46 // Config is the configuration parameters of mining. 47 type Config struct { 48 Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account) 49 } 50 51 type Miner struct { 52 worker *worker 53 } 54 55 func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, clock *mockable.Clock) *Miner { 56 return &Miner{ 57 worker: newWorker(config, chainConfig, engine, eth, mux, clock), 58 } 59 } 60 61 func (miner *Miner) SetEtherbase(addr common.Address) { 62 miner.worker.setEtherbase(addr) 63 } 64 65 func (miner *Miner) GenerateBlock() (*types.Block, error) { 66 return miner.worker.commitNewWork() 67 } 68 69 // SubscribePendingLogs starts delivering logs from pending transactions 70 // to the given channel. 71 func (miner *Miner) SubscribePendingLogs(ch chan<- []*types.Log) event.Subscription { 72 return miner.worker.pendingLogsFeed.Subscribe(ch) 73 }