Skip to content

Commit

Permalink
consensus/dccs: don't init the price engine when price.url not config…
Browse files Browse the repository at this point in the history
…ured
  • Loading branch information
Zergity committed Oct 1, 2019
1 parent a194f95 commit d0abeb7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion consensus/dccs/2_dccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions consensus/dccs/2_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var DefaultConfig = Config{
Blocks: 20,
Percentile: 60,
},
PriceServiceURL: "http://localhost:3000/price/NUSD_USD",
}

func init() {
Expand Down

0 comments on commit d0abeb7

Please sign in to comment.