From 16f8a35e76801868fc18cd6b7bd5c947a5fb0ae4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 24 Aug 2021 11:05:05 -0700 Subject: [PATCH 1/2] fix: idiomatic go 1. No need to slice a slice. 2. Idiomatic filter (https://github.com/golang/go/wiki/SliceTricks). --- markets/storageadapter/dealpublisher.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/markets/storageadapter/dealpublisher.go b/markets/storageadapter/dealpublisher.go index 7b1ca179366..99f5980ee2b 100644 --- a/markets/storageadapter/dealpublisher.go +++ b/markets/storageadapter/dealpublisher.go @@ -257,7 +257,7 @@ func (p *DealPublisher) publishAllDeals() { // Filter out any deals that have been cancelled p.filterCancelledDeals() - deals := p.pending[:] + deals := p.pending p.pending = nil // Send the publish message @@ -384,12 +384,12 @@ func pieceCids(deals []market2.ClientDealProposal) string { // filter out deals that have been cancelled func (p *DealPublisher) filterCancelledDeals() { - i := 0 + filtered := p.pending[:0] for _, pd := range p.pending { - if pd.ctx.Err() == nil { - p.pending[i] = pd - i++ + if pd.ctx.Err() != nil { + continue } + filtered = append(filtered, pd) } - p.pending = p.pending[:i] + p.pending = filtered } From add699d2386714c85073d5cb1d7d82eaa5a4847c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 24 Aug 2021 11:05:51 -0700 Subject: [PATCH 2/2] fix: make sure we start the publish timer before recording the time Otherwise, our nice and deterministic test may keep repeatedly setting the time to _right_ before the timer fires. --- markets/storageadapter/dealpublisher.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/markets/storageadapter/dealpublisher.go b/markets/storageadapter/dealpublisher.go index 99f5980ee2b..f458e7a4f5d 100644 --- a/markets/storageadapter/dealpublisher.go +++ b/markets/storageadapter/dealpublisher.go @@ -228,11 +228,15 @@ func (p *DealPublisher) waitForMoreDeals() { // Set a timeout to wait for more deals to arrive log.Infof("waiting publish deals queue period of %s before publishing", p.publishPeriod) ctx, cancel := context.WithCancel(p.ctx) + + // Create the timer _before_ taking the current time so publishPeriod+timeout is always >= + // the actual timer timeout. + timer := build.Clock.Timer(p.publishPeriod) + p.publishPeriodStart = build.Clock.Now() p.cancelWaitForMoreDeals = cancel go func() { - timer := build.Clock.Timer(p.publishPeriod) select { case <-ctx.Done(): timer.Stop()