Skip to content

Commit

Permalink
adding wait groups for reward server claims
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Mar 24, 2024
1 parent 804fc2f commit b5c5023
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions protocol/rpcprovider/rewardserver/reward_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ func (rws *RewardServer) sendRewardsClaim(ctx context.Context, epoch uint64) err
},
}

paymentWaitGroup := sync.WaitGroup{}
paymentWaitGroup.Add(newRewardsLength + failedRewardsLength)

// add expected pay and ask for rewards
for _, paymentConfig := range paymentConfiguration {
for _, rewardsToClaim := range paymentConfig.relaySessionChunks {
Expand All @@ -277,6 +280,7 @@ func (rws *RewardServer) sendRewardsClaim(ctx context.Context, epoch uint64) err
continue
}
go func(rewards []*pairingtypes.RelaySession, payment *PaymentConfiguration) { // send rewards asynchronously
defer paymentWaitGroup.Done()
specs := map[string]struct{}{}
if payment.shouldAddExpectedPayment {
for _, relay := range rewards {
Expand Down Expand Up @@ -319,6 +323,8 @@ func (rws *RewardServer) sendRewardsClaim(ctx context.Context, epoch uint64) err
}(rewardsToClaim, paymentConfig)
}
}
utils.LavaFormatDebug("Waiting for all Payment groups to finish", utils.LogAttr("wait_group_size", newRewardsLength+failedRewardsLength))
paymentWaitGroup.Wait()
return nil
}

Expand Down

0 comments on commit b5c5023

Please sign in to comment.