Skip to content

Commit

Permalink
fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
lyh169 committed Oct 11, 2023
1 parent c35836c commit 9b98216
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
7 changes: 5 additions & 2 deletions gasprice/fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
)

const (
OKBWei = 1e18
// OKBWei OKB wei
OKBWei = 1e18
minOKBWei = 1e-18
)

// FixedGasPrice struct
type FixedGasPrice struct {
cfg Config
pool poolInterface
Expand Down Expand Up @@ -45,7 +48,7 @@ func (f *FixedGasPrice) UpdateGasPriceAvg() {
}

l2CoinPrice := f.ratePrc.GetL2CoinPrice()
if l2CoinPrice < 1e-18 {
if l2CoinPrice < minOKBWei {
log.Warn("the L2 native coin price too small...")
return
}
Expand Down
21 changes: 0 additions & 21 deletions gasprice/fixed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,3 @@ func TestUpdateGasPriceAvgCases(t *testing.T) {
f.UpdateGasPriceAvg()
}
}

func TestLimitMasGasPriceFixed(t *testing.T) {
ctx := context.Background()
var d time.Duration = 1000000000

cfg := Config{
Type: FollowerType,
DefaultGasPriceWei: 100000000,
MaxGasPriceWei: 50000000,
UpdatePeriod: types.NewDuration(d),
Factor: 0.5,
}
l1GasPrice := big.NewInt(1000000000)
poolM := new(poolMock)
ethM := new(ethermanMock)
ethM.On("GetL1GasPrice", ctx).Return(l1GasPrice)
// Ensure SetGasPrices is called with the MaxGasPriceWei
poolM.On("SetGasPrices", ctx, cfg.MaxGasPriceWei, l1GasPrice.Uint64()).Return(nil)
f := newFollowerGasPriceSuggester(ctx, cfg, poolM, ethM)
f.UpdateGasPriceAvg()
}
14 changes: 10 additions & 4 deletions gasprice/kafka_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
)

const (
okbcoinId = 7184
okbcoinId = 7184
defaultTime = 10
)

// aliyun root ca
Expand Down Expand Up @@ -50,16 +51,19 @@ e4seRTTZgyXU+5dgFIXqagub2A79tRtPAr+4Xi84jzY84ceUwqX2fxRwkfaUUJb8
Hh2q+P+VJeK50B83DZ4ui+WNJbAaAbcLMsn/idX3
-----END CERTIFICATE-----`

// MsgInfo msg info
type MsgInfo struct {
Topic string `json:"topic"`
Data *Body `json:"data"`
}

// Body msg body
type Body struct {
Id string `json:"id"`
PriceList []*Price `json:"priceList"`
}

// Price coin price
type Price struct {
CoinId int `json:"coinId"`
Symbol string `json:"symbol"`
Expand Down Expand Up @@ -89,6 +93,7 @@ type Price struct {
Id string `json:"id"`
}

// KafkaProcessor kafka processor
type KafkaProcessor struct {
kreader *kafka.Reader
L2Price float64
Expand Down Expand Up @@ -122,10 +127,10 @@ func getKafkaReader(cfg Config) *kafka.Reader {
panic("caCertPool.AppendCertsFromPEM")
}
dialer = &kafka.Dialer{
Timeout: 10 * time.Second,
Timeout: defaultTime * time.Second,
DualStack: true,
SASLMechanism: plain.Mechanism{Username: cfg.Username, Password: cfg.Password},
TLS: &tls.Config{RootCAs: caCertPool, InsecureSkipVerify: true},
TLS: &tls.Config{RootCAs: caCertPool, InsecureSkipVerify: true}, // #nosec G402

Check failure on line 133 in gasprice/kafka_proc.go

View workflow job for this annotation

GitHub Actions / lint

G402: TLS InsecureSkipVerify set true. (gosec)
}
}

Expand All @@ -151,14 +156,15 @@ func (rp *KafkaProcessor) processor() {
value, err := rp.ReadAndCalc(rp.ctx)
if err != nil {
log.Warn("get the destion data fail ", err)
time.Sleep(time.Second * 10)
time.Sleep(time.Second * defaultTime)
continue
}
rp.updateL2CoinPrice(value)
}
}
}

// ReadAndCalc read and calc
func (rp *KafkaProcessor) ReadAndCalc(ctx context.Context) (float64, error) {
m, err := rp.kreader.ReadMessage(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion gasprice/kafka_proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestCalculateRate(t *testing.T) {
{
// error
l2CoinId: okbcoinId,
msg: fmt.Sprintf("{\"topic\":\"middle_coinPrice_push\"}"),
msg: "{\"topic\":\"middle_coinPrice_push\"}",
check: func(rate float64, err error) {
require.Error(t, err)
},
Expand Down

0 comments on commit 9b98216

Please sign in to comment.