Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove in-mem blacklist for dodo #291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
}
7 changes: 0 additions & 7 deletions pkg/source/dodo/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,3 @@ var v1PoolData []byte

//go:embed abi/DodoV2Pool.json
var v2PoolData []byte

//go:embed blacklist/bsc.txt
var bscBlacklistFilePath []byte

var bytesByPath = map[string][]byte{
"blacklist/bsc.txt": bscBlacklistFilePath,
}
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