Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

fix running-bytes-limit and add test coverage #44

Merged
merged 1 commit into from
Aug 29, 2021

Conversation

merlinran
Copy link
Contributor

previously, if bidbot doesn't win an auction, the requested quota never gets cleared. this adds a way to expire the quota after a period of time, unless it's secured.

Copy link
Contributor Author

@merlinran merlinran left a comment

Choose a reason for hiding this comment

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

Okay, finally get this fix working. Overly complicated though. Simpler solutions would be much appreciated!

@@ -590,5 +590,5 @@ func parseRunningBytesLimit(s string) (limiter.Limiter, error) {
if err != nil {
return nil, err
}
return limiter.NewRunningTotalLimiter(d, nBytes), nil
return limiter.NewRunningTotalLimiter(nBytes, d), nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parameter is reordered unintentionally, but this reads better.

Request(n uint64) bool
Commit(n uint64)
Withdraw(n uint64)
Request(id string, n uint64, period time.Duration) bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the interface so we can use the auction ID as ID here. Hope the "Request + Secure" logic is not that confusing.

// if the caller commits some tokens more than once,
// this could happen. Add a guard here just to prevent
// the total from wraping around to a gigantic number.
rl.total = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the check here now we use ID to identify the entry.

}
if rl.total+n > rl.limit {
return false
}
rl.total += n
rl.requested[id] = requested{
n: n,
t: time.AfterFunc(expiration, func() { rl.Withdraw(id) }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is simple: requested tokens are withdrawn (removed from requested) if not being Secure-ed in time.

service/limiter/running_total_limiter.go Outdated Show resolved Hide resolved
@@ -331,59 +336,25 @@ func (s *Service) auctionsHandler(from core.ID, topic string, msg []byte) ([]byt
return nil, nil
}

func (s *Service) winsHandler(from core.ID, topic string, msg []byte) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

simply moved down to below filterAuction.

return fmt.Errorf("getting number of sealing sectors: %v", err)
}
if n > s.sealingSectorsLimit {
log.Errorf("fail to get number of sealing sectors, continuing: %v", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is likely to happen, see filecoin-project/lotus#7078 (comment) . Need to fix later but for now just avoid this error from preventing bidding.

DealDataDirectory: t.TempDir(),
}
_, err = service.New(config, store, lc, fc)
_, err := newService(t, func(config *service.Config) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DRY

_, err = service.New(config, store, lc, fc2)
require.Error(t, err)
}

func TestBytesLimit(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is a bit fragile consider the timing of different activities and potential conflict when committing transactions. It's surprising to see badger store hits conflict too. Anyway, seems working with the current setup.

Copy link
Member

Choose a reason for hiding this comment

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

might be worth trying a newer badger release. unless we updated since the start of bidbot, there have been a few releases for v3... latest release: https://github.com/dgraph-io/badger/releases/tag/v3.2103.1

return nil, fmt.Errorf("setting proposal cid: %v", err)
}
// ready to fetch data, so the requested quota is actually in use.
s.bytesLimiter.Secure(prop.AuctionId)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the core change - secure the quota when start downloading, and other requested quotas will eventually expire, leave room for new auctions.

previously, if bidbot doesn't win an auction, the requested quota never
gets cleared. this adds a way to expire the quota after a period of
time, unless it's secured.

Signed-off-by: Merlin Ran <merlinran@gmail.com>
Copy link
Member

@sanderpick sanderpick left a comment

Choose a reason for hiding this comment

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

Over my head as I wasn't involved in the original limiter work, but LGTM. Interesting problem!

_, err = service.New(config, store, lc, fc2)
require.Error(t, err)
}

func TestBytesLimit(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

might be worth trying a newer badger release. unless we updated since the start of bidbot, there have been a few releases for v3... latest release: https://github.com/dgraph-io/badger/releases/tag/v3.2103.1

@merlinran merlinran merged commit c400dba into main Aug 29, 2021
@merlinran merlinran deleted the merlin/bytes-limiter branch August 29, 2021 14:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants