Skip to content

Commit

Permalink
Add les chain reader for istanbul (ethereum#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcewen authored and celo-ci-bot-user committed Jan 2, 2020
1 parent a90c7a4 commit 36357a9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
25 changes: 19 additions & 6 deletions les/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
istanbulBackend "github.com/ethereum/go-ethereum/consensus/istanbul/backend"
"github.com/ethereum/go-ethereum/contract_comm"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits"
Expand Down Expand Up @@ -55,12 +56,13 @@ type LightEthereum struct {
shutdownChan chan bool

// Handlers
peers *peerSet
txPool *light.TxPool
blockchain *light.LightChain
serverPool *serverPool
reqDist *requestDistributor
retriever *retrieveManager
peers *peerSet
txPool *light.TxPool
blockchain *light.LightChain
serverPool *serverPool
reqDist *requestDistributor
retriever *retrieveManager
chainreader *LightChainReader

bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer
Expand Down Expand Up @@ -169,6 +171,17 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
return nil, err
}
leth.ApiBackend = &LesApiBackend{leth}

leth.chainreader = &LightChainReader{
config: leth.chainConfig,
blockchain: leth.blockchain,
}

// If the engine is istanbul, then inject the blockchain
if istanbul, isIstanbul := leth.engine.(*istanbulBackend.Backend); isIstanbul {
istanbul.SetChain(leth.chainreader, nil)
}

return leth, nil
}

Expand Down
35 changes: 35 additions & 0 deletions les/lightchainreader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package les

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/params"
)

type LightChainReader struct {
config *params.ChainConfig
blockchain *light.LightChain
}

// Config returns the chain configuration.
func (lcr *LightChainReader) Config() *params.ChainConfig {
return lcr.config
}

func (lcr *LightChainReader) CurrentHeader() *types.Header {
return lcr.blockchain.CurrentHeader()
}
func (lcr *LightChainReader) GetHeaderByNumber(number uint64) *types.Header {
return lcr.blockchain.GetHeaderByNumber(number)
}
func (lcr *LightChainReader) GetHeaderByHash(hash common.Hash) *types.Header {
return lcr.blockchain.GetHeaderByHash(hash)
}
func (lcr *LightChainReader) GetHeader(hash common.Hash, number uint64) *types.Header {
return lcr.blockchain.GetHeader(hash, number)
}
func (lcr *LightChainReader) GetBlock(hash common.Hash, number uint64) *types.Block {
panic("GetBlock cannot be called on LightChainReader")
return nil
}

0 comments on commit 36357a9

Please sign in to comment.