Skip to content

Commit

Permalink
miner blockchain interface
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Sep 30, 2023
1 parent 89db795 commit 564e2be
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
16 changes: 15 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -39,10 +40,23 @@ import (
// Backend wraps all methods required for mining. Only full node is capable
// to offer all the functions here.
type Backend interface {
BlockChain() *core.BlockChain
BlockChain() BlockChain
TxPool() *txpool.TxPool
}

type BlockChain interface {
GetVMConfig() *vm.Config
Engine() consensus.Engine
CurrentBlock() *types.Header
StateAt(common.Hash) (state.StateDBI, error)
StateAtBlockNumber(uint64) (state.StateDBI, error)
GetBlockByHash(common.Hash) *types.Block
consensus.ChainHeaderReader
HasBlock(common.Hash, uint64) bool
SubscribeChainHeadEvent(chan<- core.ChainHeadEvent) event.Subscription
WriteBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state state.StateDBI, emitHeadEvent bool) (status core.WriteStatus, err error)
}

// Config is the configuration parameters of mining.
type Config struct {
Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards
Expand Down
4 changes: 2 additions & 2 deletions miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
)

type mockBackend struct {
bc *core.BlockChain
bc BlockChain
txPool *txpool.TxPool
}

Expand All @@ -51,7 +51,7 @@ func NewMockBackend(bc *core.BlockChain, txPool *txpool.TxPool) *mockBackend {
}
}

func (m *mockBackend) BlockChain() *core.BlockChain {
func (m *mockBackend) BlockChain() BlockChain {
return m.bc
}

Expand Down
7 changes: 5 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type worker struct {
chainConfig *params.ChainConfig
engine consensus.Engine
eth Backend
chain *core.BlockChain
chain BlockChain

// Feeds
pendingLogsFeed event.Feed
Expand Down Expand Up @@ -706,7 +706,10 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co
// the miner to speed block sealing up a bit.
state, err := w.chain.StateAt(parent.Root)
if err != nil {
return nil, err
state, err = w.chain.StateAtBlockNumber(parent.Number.Uint64())
if err != nil {
return nil, err
}
}
state.StartPrefetcher("miner")

Expand Down
4 changes: 2 additions & 2 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
}
}

func (b *testWorkerBackend) BlockChain() *core.BlockChain { return b.chain }
func (b *testWorkerBackend) TxPool() *txpool.TxPool { return b.txPool }
func (b *testWorkerBackend) BlockChain() BlockChain { return b.chain }
func (b *testWorkerBackend) TxPool() *txpool.TxPool { return b.txPool }

func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
var tx *types.Transaction
Expand Down

0 comments on commit 564e2be

Please sign in to comment.