diff --git a/eth/backend.go b/eth/backend.go index a7de2b130e..b5318f9679 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -133,7 +133,7 @@ type FullNodeService struct { httpclient *httpclient.HTTPClient accountManager *accounts.Manager - apiBackend *EthApiBackend + ApiBackend *EthApiBackend miner *miner.Miner Mining bool @@ -251,7 +251,7 @@ func New(ctx *node.ServiceContext, config *Config) (*FullNodeService, error) { GpobaseCorrectionFactor: config.GpobaseCorrectionFactor, } gpo := gasprice.NewGasPriceOracle(eth.blockchain, chainDb, eth.eventMux, gpoParams) - eth.apiBackend = &EthApiBackend{eth, gpo} + eth.ApiBackend = &EthApiBackend{eth, gpo} return eth, nil } @@ -318,7 +318,7 @@ func CreatePoW(config *Config) (*ethash.Ethash, error) { // APIs returns the collection of RPC services the ethereum package offers. // NOTE, some of these services probably need to be moved to somewhere else. func (s *FullNodeService) APIs() []rpc.API { - return append(ethapi.GetAPIs(s.apiBackend, &s.solcPath, &s.solc), []rpc.API{ + return append(ethapi.GetAPIs(s.ApiBackend, &s.solcPath, &s.solc), []rpc.API{ { Namespace: "eth", Version: "1.0", diff --git a/eth/bind.go b/eth/bind.go index 7eb15ca1b6..040797190a 100644 --- a/eth/bind.go +++ b/eth/bind.go @@ -42,11 +42,11 @@ type ContractBackend struct { // NewContractBackend creates a new native contract backend using an existing // Etheruem object. -func NewContractBackend(eth *FullNodeService) *ContractBackend { +func NewContractBackend(apiBackend ethapi.Backend) *ContractBackend { return &ContractBackend{ - eapi: ethapi.NewPublicEthereumAPI(eth.apiBackend, nil, nil), - bcapi: ethapi.NewPublicBlockChainAPI(eth.apiBackend), - txapi: ethapi.NewPublicTransactionPoolAPI(eth.apiBackend), + eapi: ethapi.NewPublicEthereumAPI(apiBackend, nil, nil), + bcapi: ethapi.NewPublicBlockChainAPI(apiBackend), + txapi: ethapi.NewPublicTransactionPoolAPI(apiBackend), } } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 56c56bf2c1..7e5a9092c8 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1648,10 +1648,23 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error { for i, header := range rollback { hashes[i] = header.Hash() } - lastHeader, lastFastBlock, lastBlock := d.headHeader().Number, d.headFastBlock().Number(), d.headBlock().Number() + lastHeader, lastFastBlock, lastBlock := d.headHeader().Number, common.Big0, common.Big0 + if d.headFastBlock != nil { + lastFastBlock = d.headFastBlock().Number() + } + if d.headBlock != nil { + lastBlock = d.headBlock().Number() + } d.rollback(hashes) + curFastBlock, curBlock := common.Big0, common.Big0 + if d.headFastBlock != nil { + curFastBlock = d.headFastBlock().Number() + } + if d.headBlock != nil { + curBlock = d.headBlock().Number() + } glog.V(logger.Warn).Infof("Rolled back %d headers (LH: %d->%d, FB: %d->%d, LB: %d->%d)", - len(hashes), lastHeader, d.headHeader().Number, lastFastBlock, d.headFastBlock().Number(), lastBlock, d.headBlock().Number()) + len(hashes), lastHeader, d.headHeader().Number, lastFastBlock, curFastBlock, lastBlock, curBlock) // If we're already past the pivot point, this could be an attack, thread carefully if rollback[len(rollback)-1].Number.Uint64() > pivot { diff --git a/les/backend.go b/les/backend.go index dcf19b57f5..d261a92ecd 100644 --- a/les/backend.go +++ b/les/backend.go @@ -55,7 +55,7 @@ type LightNodeService struct { chainDb ethdb.Database // Block chain database dappDb ethdb.Database // Dapp database - apiBackend *LesApiBackend + ApiBackend *LesApiBackend eventMux *event.TypeMux pow *ethash.Ethash @@ -123,15 +123,15 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightNodeService, error } odr.removePeer = eth.protocolManager.removePeer - eth.apiBackend = &LesApiBackend{eth, nil} - eth.apiBackend.gpo = gasprice.NewLightPriceOracle(eth.apiBackend) + eth.ApiBackend = &LesApiBackend{eth, nil} + eth.ApiBackend.gpo = gasprice.NewLightPriceOracle(eth.ApiBackend) return eth, nil } // APIs returns the collection of RPC services the ethereum package offers. // NOTE, some of these services probably need to be moved to somewhere else. func (s *LightNodeService) APIs() []rpc.API { - return append(ethapi.GetAPIs(s.apiBackend, &s.solcPath, &s.solc), []rpc.API{ + return append(ethapi.GetAPIs(s.ApiBackend, &s.solcPath, &s.solc), []rpc.API{ { Namespace: "eth", Version: "1.0", diff --git a/release/release.go b/release/release.go index 07eb9359cf..60031938aa 100644 --- a/release/release.go +++ b/release/release.go @@ -25,6 +25,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/internal/ethapi" + "github.com/ethereum/go-ethereum/les" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/node" @@ -58,12 +60,20 @@ type ReleaseService struct { // releases and notify the user of such. func NewReleaseService(ctx *node.ServiceContext, config Config) (node.Service, error) { // Retrieve the Ethereum service dependency to access the blockchain + var apiBackend ethapi.Backend var ethereum *eth.FullNodeService - if err := ctx.Service(ðereum); err != nil { - return nil, err + if err := ctx.Service(ðereum); err == nil { + apiBackend = ethereum.ApiBackend + } else { + var ethereum *les.LightNodeService + if err := ctx.Service(ðereum); err == nil { + apiBackend = ethereum.ApiBackend + } else { + return nil, err + } } // Construct the release service - contract, err := NewReleaseOracle(config.Oracle, eth.NewContractBackend(ethereum)) + contract, err := NewReleaseOracle(config.Oracle, eth.NewContractBackend(apiBackend)) if err != nil { return nil, err }