Skip to content

Commit

Permalink
remove in-mem blacklist for dodo
Browse files Browse the repository at this point in the history
  • Loading branch information
it4rb committed Jan 8, 2024
1 parent ba439fe commit bd2464c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 52 deletions.
1 change: 0 additions & 1 deletion pkg/source/dodo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ type Config struct {
SubgraphAPI string `json:"subgraphAPI"`
NewPoolLimit int `json:"newPoolLimit"`
DodoV1SellHelper string `json:"dodoV1SellHelper"`
BlacklistFilePath string `json:"blacklistFilePath"`
}
61 changes: 10 additions & 51 deletions pkg/source/dodo/pool_tracker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dodo

import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
Expand All @@ -12,7 +10,6 @@ import (
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/logger"
"github.com/ethereum/go-ethereum/common"
cmap "github.com/orcaman/concurrent-map"

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
Expand All @@ -21,22 +18,15 @@ import (
type PoolTracker struct {
config *Config
ethrpcClient *ethrpc.Client
blackList cmap.ConcurrentMap
}

func NewPoolTracker(
cfg *Config,
ethrpcClient *ethrpc.Client,
) (*PoolTracker, error) {
blackList, err := initBlackList(cfg.BlacklistFilePath)
if err != nil {
return nil, err
}

return &PoolTracker{
config: cfg,
ethrpcClient: ethrpcClient,
blackList: blackList,
}, nil
}

Expand Down Expand Up @@ -177,15 +167,6 @@ func (d *PoolTracker) getNewPoolStateDodoV1(ctx context.Context, p entity.Pool)
func (d *PoolTracker) getNewPoolStateDodoV2(ctx context.Context, p entity.Pool) (entity.Pool, error) {
logger.Infof("[Dodo] Start getting new state of dodoV2 pool: %v", p.Address)

_, ok := d.blackList.Get(p.Address)
if ok {
logger.WithFields(logger.Fields{
"poolAddress": p.Address,
}).Error(ErrPoolAddressBanned.Error())

return entity.Pool{}, ErrPoolAddressBanned
}

var (
state PoolState
feeRate FeeRate
Expand Down Expand Up @@ -225,15 +206,21 @@ func (d *PoolTracker) getNewPoolStateDodoV2(ctx context.Context, p entity.Pool)
Params: []interface{}{common.HexToAddress(p.Address)},
}, []interface{}{&feeRate})
if _, err := calls.Call(); err != nil {
// retry 1 time before adding to blacklist
// retry 1 time
if _, errRetry := calls.Call(); errRetry != nil {
logger.WithFields(logger.Fields{
"poolAddress": p.Address,
"error": errRetry,
}).Errorf("[DodoV2] failed to call getUserFeeRate, add pool address to blacklist")
d.blackList.Set(p.Address, true)
}).Errorf("[DodoV2] failed to call getUserFeeRate, clear pool data")

// clear pool data instead of adding to blacklist
p.Extra = ""
p.Reserves = entity.PoolReserves{zeroString, zeroString}
p.Timestamp = time.Now().Unix()

return entity.Pool{}, err
logger.Infof("[Dodo] Finish clearing state of dodoV2 pool: %v", p.Address)

return p, nil
}
}

Expand Down Expand Up @@ -292,34 +279,6 @@ func (d *PoolTracker) getNewPoolStateDodoV2(ctx context.Context, p entity.Pool)
return p, nil
}

func initBlackList(blackListPath string) (cmap.ConcurrentMap, error) {
blackListMap := cmap.New()

if blackListPath == "" {
return blackListMap, nil
}

byteData, ok := bytesByPath[blackListPath]
if !ok {
logger.WithFields(logger.Fields{
"blacklistFilePath": blackListPath,
}).Error(ErrInitializeBlacklistFailed.Error())

return blackListMap, ErrInitializeBlacklistFailed
}

file := bytes.NewReader(byteData)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
poolAddress := scanner.Text()
if poolAddress != "" {
blackListMap.Set(poolAddress, true)
}
}

return blackListMap, nil
}

func bigToFloat64(b *big.Float) float64 {
f, _ := b.Float64()

Expand Down

0 comments on commit bd2464c

Please sign in to comment.