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

client list-asks --by-ping #5060

Merged
merged 1 commit into from
Nov 30, 2020
Merged
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
51 changes: 40 additions & 11 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,19 @@ uiLoop:
state = "find"
}
case "find":
asks, err := getAsks(ctx, api)
asks, err := GetAsks(ctx, api)
if err != nil {
return err
}

for _, ask := range asks {
if ask.MinPieceSize > ds.PieceSize {
if ask.Ask.MinPieceSize > ds.PieceSize {
continue
}
if ask.MaxPieceSize < ds.PieceSize {
if ask.Ask.MaxPieceSize < ds.PieceSize {
continue
}
candidateAsks = append(candidateAsks, ask)
candidateAsks = append(candidateAsks, ask.Ask)
}

afmt.Printf("Found %d candidate asks\n", len(candidateAsks))
Expand Down Expand Up @@ -1191,6 +1191,11 @@ var clientDealStatsCmd = &cli.Command{
var clientListAsksCmd = &cli.Command{
Name: "list-asks",
Usage: "List asks for top miners",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "by-ping",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
Expand All @@ -1199,25 +1204,39 @@ var clientListAsksCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)

asks, err := getAsks(ctx, api)
asks, err := GetAsks(ctx, api)
if err != nil {
return err
}

for _, ask := range asks {
fmt.Printf("%s: min:%s max:%s price:%s/GiB/Epoch verifiedPrice:%s/GiB/Epoch\n", ask.Miner,
if cctx.Bool("by-ping") {
sort.Slice(asks, func(i, j int) bool {
return asks[i].Ping < asks[j].Ping
})
}

for _, a := range asks {
ask := a.Ask

fmt.Printf("%s: min:%s max:%s price:%s/GiB/Epoch verifiedPrice:%s/GiB/Epoch ping:%s\n", ask.Miner,
types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))),
types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))),
types.FIL(ask.Price),
types.FIL(ask.VerifiedPrice),
a.Ping,
)
}

return nil
},
}

func getAsks(ctx context.Context, api lapi.FullNode) ([]*storagemarket.StorageAsk, error) {
type QueriedAsk struct {
Ask *storagemarket.StorageAsk
Ping time.Duration
}

func GetAsks(ctx context.Context, api lapi.FullNode) ([]QueriedAsk, error) {
color.Blue(".. getting miner list")
miners, err := api.StateListMiners(ctx, types.EmptyTSK)
if err != nil {
Expand Down Expand Up @@ -1272,7 +1291,7 @@ loop:

color.Blue(".. querying asks")

var asks []*storagemarket.StorageAsk
var asks []QueriedAsk
var queried, got int64

done = make(chan struct{})
Expand Down Expand Up @@ -1308,9 +1327,19 @@ loop:
return
}

rt := time.Now()

_, err = api.ClientQueryAsk(ctx, *mi.PeerId, miner)
if err != nil {
return
}
Comment on lines +1332 to +1335
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could implement this using libp2p ping, but that requires exposing it on the API..

With this I'm getting 20-30ms pings to peers in the EU, so I'd say it's good enough for now


atomic.AddInt64(&got, 1)
lk.Lock()
asks = append(asks, ask)
asks = append(asks, QueriedAsk{
Ask: ask,
Ping: time.Now().Sub(rt),
})
lk.Unlock()
}(miner)
}
Expand All @@ -1328,7 +1357,7 @@ loop2:
fmt.Printf("\r* Queried %d asks, got %d responses\n", atomic.LoadInt64(&queried), atomic.LoadInt64(&got))

sort.Slice(asks, func(i, j int) bool {
return asks[i].Price.LessThan(asks[j].Price)
return asks[i].Ask.Price.LessThan(asks[j].Ask.Price)
})

return asks, nil
Expand Down