mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
Introducing a blockchain interface instead of passing the implementation directly to the protocol manager. Allows for better mocking and improves reusability of ProtocolManager..
This commit is contained in:
parent
b3b110bc95
commit
dc98fecbec
2 changed files with 26 additions and 2 deletions
|
|
@ -60,7 +60,7 @@ type ProtocolManager struct {
|
||||||
|
|
||||||
fastSync bool
|
fastSync bool
|
||||||
txpool txPool
|
txpool txPool
|
||||||
blockchain *core.BlockChain
|
blockchain blockChain
|
||||||
chaindb ethdb.Database
|
chaindb ethdb.Database
|
||||||
|
|
||||||
downloader *downloader.Downloader
|
downloader *downloader.Downloader
|
||||||
|
|
@ -86,7 +86,7 @@ type ProtocolManager struct {
|
||||||
|
|
||||||
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
|
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
|
||||||
// with the ethereum network.
|
// with the ethereum network.
|
||||||
func NewProtocolManager(fastSync bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
|
func NewProtocolManager(fastSync bool, networkId int, mux *event.TypeMux, txpool txPool, pow pow.PoW, blockchain blockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
|
||||||
// Figure out whether to allow fast sync or not
|
// Figure out whether to allow fast sync or not
|
||||||
if fastSync && blockchain.CurrentBlock().NumberU64() > 0 {
|
if fastSync && blockchain.CurrentBlock().NumberU64() > 0 {
|
||||||
glog.V(logger.Info).Infof("blockchain not empty, fast sync disabled")
|
glog.V(logger.Info).Infof("blockchain not empty, fast sync disabled")
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,30 @@ type chainManager interface {
|
||||||
Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash)
|
Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// proxy interface to core.BlockChain
|
||||||
|
type blockChain interface {
|
||||||
|
Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash)
|
||||||
|
Genesis() *types.Block
|
||||||
|
CurrentHeader() *types.Header
|
||||||
|
CurrentBlock() *types.Block
|
||||||
|
CurrentFastBlock() *types.Block
|
||||||
|
HasHeader(hash common.Hash) bool
|
||||||
|
HasBlock(hash common.Hash) bool
|
||||||
|
HasBlockAndState(hash common.Hash) bool
|
||||||
|
GetHeader(hash common.Hash) *types.Header
|
||||||
|
GetHeaderByNumber(number uint64) *types.Header
|
||||||
|
GetBlock(hash common.Hash) *types.Block
|
||||||
|
GetBlockByNumber(number uint64) *types.Block
|
||||||
|
GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
|
||||||
|
GetBodyRLP(hash common.Hash) rlp.RawValue
|
||||||
|
FastSyncCommitHead(hash common.Hash) error
|
||||||
|
GetTd(hash common.Hash) *big.Int
|
||||||
|
InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error)
|
||||||
|
InsertChain(chain types.Blocks) (int, error)
|
||||||
|
InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts) (int, error)
|
||||||
|
Rollback(chain []common.Hash)
|
||||||
|
}
|
||||||
|
|
||||||
// statusData is the network packet for the status message.
|
// statusData is the network packet for the status message.
|
||||||
type statusData struct {
|
type statusData struct {
|
||||||
ProtocolVersion uint32
|
ProtocolVersion uint32
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue