Skip to content

Commit beb6b44

Browse files
author
LazyLuis
committed
optimized log level
1 parent 2ed946e commit beb6b44

File tree

6 files changed

+15
-55
lines changed

6 files changed

+15
-55
lines changed

x/oracle/abci/extension.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewPriceOracleVoteExtHandler(logger log.Logger, valStore baseapp.ValidatorS
4545
}
4646

4747
return PriceOracleVoteExtHandler{
48-
logger: logger,
48+
logger: logger.With("module", types.ModuleName),
4949
currentBlock: 0,
5050
valStore: valStore,
5151
Keeper: oracleKeeper,
@@ -94,7 +94,6 @@ func (h *PriceOracleVoteExtHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteE
9494
}
9595

9696
validator := hex.EncodeToString(req.ValidatorAddress)
97-
h.logger.Info("VerifyVoteExtensionHandler", "height", req.Height, "validator", validator)
9897
var voteExt types.OracleVoteExtension
9998
err := voteExt.Unmarshal(req.VoteExtension)
10099
if err != nil {
@@ -105,16 +104,7 @@ func (h *PriceOracleVoteExtHandler) VerifyVoteExtensionHandler() sdk.VerifyVoteE
105104
return nil, fmt.Errorf("vote extension height does not match request height; expected: %d, got: %d", req.Height, voteExt.Height)
106105
}
107106

108-
// if len(voteExt.Prices) > 0 {
109-
// // check if a fack price is existing.
110-
// if _, ok := voteExt.Prices[types.NULL_SYMBOL]; !ok {
111-
// return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
112-
// }
113-
// }
114-
115-
// if voteExt.HasError {
116-
// return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
117-
// }
107+
h.logger.Debug("verify", "height", req.Height, "validator", validator, "prices", voteExt.Prices, "blocks", voteExt.Blocks)
118108

119109
for _, blk := range voteExt.Blocks {
120110
if err = blk.Validate(); err != nil {
@@ -222,7 +212,7 @@ func (h *PriceOracleVoteExtHandler) getAllVolumeWeightedPrices() map[string]stri
222212
}
223213
}
224214

225-
h.logger.Info("AvgPrice", "prices", avgPrices)
215+
h.logger.Debug("avg exchange prices", "prices", avgPrices)
226216

227217
textPrices := make(map[string]string)
228218
for symbol, price := range avgPrices {
@@ -321,7 +311,7 @@ func (h *PriceOracleVoteExtHandler) PreBlocker(ctx sdk.Context, req *abci.Reques
321311
return nil, err
322312
}
323313

324-
h.logger.Warn("Oracle Final States", "price", prices)
314+
h.logger.Info("Oracle Final States", "price", prices, "headers", headers)
325315

326316
return res, nil
327317
}
@@ -345,7 +335,7 @@ func (h *PriceOracleVoteExtHandler) extractPricesAndBlockHeaders(_ sdk.Context,
345335
return nil, nil, err
346336
}
347337

348-
h.logger.Warn("extension", "validator", hex.EncodeToString(v.Validator.Address), "extension", voteExt)
338+
h.logger.Debug("received", "validator", hex.EncodeToString(v.Validator.Address), "extension", voteExt)
349339

350340
totalStake += v.Validator.Power
351341

@@ -390,10 +380,11 @@ func (h *PriceOracleVoteExtHandler) extractPricesAndBlockHeaders(_ sdk.Context,
390380
}
391381

392382
// finalize average by dividing by total stake, i.e. total weights
383+
finalPrices := make(map[string]math.LegacyDec, len(types.PRICE_CACHE))
393384
for base, price := range stakeWeightedPrices {
394385
if price.GT(math.LegacyZeroDec()) {
395386
if vp, ok := stakeWeightedVotingPower[base]; ok && vp.RoundInt64()*3 > totalStake*2 {
396-
stakeWeightedPrices[base] = price.Quo(vp)
387+
finalPrices[base] = price.Quo(vp)
397388
}
398389
} else {
399390
h.logger.Error("Got invalid price.", "symbal", base, "price", price)
@@ -407,7 +398,7 @@ func (h *PriceOracleVoteExtHandler) extractPricesAndBlockHeaders(_ sdk.Context,
407398
break
408399
}
409400
}
410-
return stakeWeightedPrices, headers, nil
401+
return finalPrices, headers, nil
411402
}
412403

413404
func voteExtensionEnabled(ctx sdk.Context, height int64) bool {

x/oracle/module/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Start(svrCtx *server.Context, clientCtx client.Context, ctx context.Context
2020

2121
if types.StartProviders {
2222

23-
svrCtx.Logger.Info("price service", "module", "oracle", "msg", "Start Oracle Price Subscriber")
23+
svrCtx.Logger.With("module", types.ModuleName).Info("price service", "module", "oracle", "msg", "Start Oracle Price Subscriber")
2424

2525
go binance.Subscribe(svrCtx, ctx)
2626
go okex.Subscribe(svrCtx, ctx)
@@ -33,7 +33,7 @@ func Start(svrCtx *server.Context, clientCtx client.Context, ctx context.Context
3333
// g.Go(func() error { return bybit.Subscribe(svrCtx, ctx) })
3434
// g.Go(func() error { return bitget.Subscribe(svrCtx, ctx) })
3535
} else {
36-
svrCtx.Logger.Warn("Price service is disabled. It is required if your node is a validator. ")
36+
svrCtx.Logger.With("module", types.ModuleName).Warn("Price service is disabled. It is required if your node is a validator. ")
3737
}
3838

3939
return nil

x/oracle/providers/binance/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
SymbolMap = map[string]string{
3131
"BTCUSDT": types.BTCUSD,
3232
}
33-
URL = "wss://stream.binance.com:443/stream?streams=btcusdt@miniTicker/atomusdt@miniTicker"
33+
URL = "wss://stream.binance.com:443/stream?streams=btcusdt@miniTicker/ethbtc@miniTicker"
3434
SubscribeMsg = ""
3535
)
3636

x/oracle/providers/bybit/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var (
1818
"op": "subscribe",
1919
"args": [
2020
"tickers.BTCUSDT",
21-
"tickers.ATOMUSDT"
21+
"tickers.ETHBTC"
2222
]
2323
}`
2424
SymbolMap = map[string]string{

x/oracle/types/cache.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,6 @@ func CachePrice(exchange string, price Price) {
2626
v[exchange] = price
2727
PRICE_CACHE[price.Symbol] = v
2828
}
29-
30-
// a null price is used to identify whether price provider is working
31-
nullPrice := nullPrice(price.Time)
32-
if v, ok := PRICE_CACHE[nullPrice.Symbol]; ok {
33-
v[exchange] = nullPrice
34-
PRICE_CACHE[nullPrice.Symbol] = v
35-
} else {
36-
v = make(map[string]Price)
37-
v[exchange] = nullPrice
38-
PRICE_CACHE[nullPrice.Symbol] = v
39-
}
40-
}
41-
42-
func nullPrice(pTime int64) Price {
43-
return Price{
44-
Symbol: NULL_SYMBOL,
45-
Price: "0",
46-
Time: pTime,
47-
}
4829
}
4930

5031
func GetPrices(lastBlockTime int64) map[string][]math.LegacyDec {
@@ -65,15 +46,3 @@ func GetPrices(lastBlockTime int64) map[string][]math.LegacyDec {
6546
}
6647
return symbolPrices
6748
}
68-
69-
// func setMapValue(target map[string][]Price, ex string, p Price) {
70-
// if list, ok := target[ex]; ok {
71-
// if len(list) > 100 {
72-
// list = list[100:]
73-
// }
74-
// list = append(list, p)
75-
// target[ex] = list
76-
// } else {
77-
// target[ex] = []Price{p}
78-
// }
79-
// }

x/oracle/types/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func Subscribe(provider string, svrCtx *server.Context, ctx context.Context, url
3434
if c, _, err = websocket.DefaultDialer.Dial(url, nil); err == nil {
3535
reconnect = false
3636
sendMessage(c, msg)
37-
svrCtx.Logger.Info("connected price provider", "url", url)
37+
svrCtx.Logger.With("module", ModuleName).Info("connected price provider", "url", url)
3838
break
3939
} else {
40-
svrCtx.Logger.Error("re-connecting...", "error", err, "provider", provider)
40+
svrCtx.Logger.With("module", ModuleName).Error("re-connecting...", "error", err, "provider", provider)
4141
}
4242
}
4343
}
@@ -48,7 +48,7 @@ func Subscribe(provider string, svrCtx *server.Context, ctx context.Context, url
4848
CachePrice(provider, p)
4949
}
5050
} else {
51-
svrCtx.Logger.Error("provider disconnected", "error", err, "provider", provider)
51+
svrCtx.Logger.With("module", ModuleName).Error("provider disconnected", "error", err, "provider", provider)
5252
c.Close()
5353
reconnect = true
5454
}

0 commit comments

Comments
 (0)