From d0abeb71f80a9f6cb9c9b91b5c404d05bd135a5e Mon Sep 17 00:00:00 2001 From: Zergity Date: Fri, 27 Sep 2019 16:02:07 +0700 Subject: [PATCH] consensus/dccs: don't init the price engine when price.url not configured --- consensus/dccs/2_dccs.go | 2 +- consensus/dccs/2_price.go | 8 ++++++++ eth/config.go | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/consensus/dccs/2_dccs.go b/consensus/dccs/2_dccs.go index 5ad5a3a078cc..d18741d1c700 100644 --- a/consensus/dccs/2_dccs.go +++ b/consensus/dccs/2_dccs.go @@ -511,7 +511,7 @@ func (c *Context) prepare2(header *types.Header) error { header.Difficulty = new(big.Int).SetUint64(difficulty) var price *Price - if c.engine.config.IsPriceBlock(number) { + if c.engine.config.IsPriceBlock(number) && len(c.engine.priceURL) > 0 { price = c.engine.PriceEngine().CurrentPrice() if price == nil { log.Warn("No price to record in block", "number", number) diff --git a/consensus/dccs/2_price.go b/consensus/dccs/2_price.go index 17591fded8c5..f5b02258498f 100644 --- a/consensus/dccs/2_price.go +++ b/consensus/dccs/2_price.go @@ -105,6 +105,10 @@ func (a ByPrice) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // CalcMedianPrice calculates the median price of a price block and cache it. // TODO: optimize rolling median calculation func (c *Context) CalcMedianPrice(number uint64) (*Price, error) { + if len(c.engine.priceURL) == 0 { + // price server URL not provided + return nil, nil + } if !c.engine.config.IsPriceBlock(number) { // not a price block return nil, nil @@ -156,6 +160,10 @@ func medianPrice(prices []*Price, minValues int) (*Price, error) { // GetBlockPrice returns the price encoded in a block header extra data func (c *Context) GetBlockPrice(number uint64) *Price { + if len(c.engine.priceURL) == 0 { + // price server URL not provided + return nil + } if !c.engine.config.IsPriceBlock(number) { // not a price block return nil diff --git a/eth/config.go b/eth/config.go index ee08f7c365ee..312be45e01e8 100644 --- a/eth/config.go +++ b/eth/config.go @@ -61,7 +61,6 @@ var DefaultConfig = Config{ Blocks: 20, Percentile: 60, }, - PriceServiceURL: "http://localhost:3000/price/NUSD_USD", } func init() {