Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Aug 6, 2024
2 parents 4360752 + 48f438d commit a5a02c8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions services/rfq/relayer/inventory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ func NewInventoryManager(ctx context.Context, clientFetcher submitter.ClientFetc

//nolint:gocognit,cyclop
func (i *inventoryManagerImpl) Start(ctx context.Context) error {
g, _ := errgroup.WithContext(ctx)
g, gctx := errgroup.WithContext(ctx)
for _, rebalanceManager := range i.rebalanceManagers {
rebalanceManager := rebalanceManager
g.Go(func() error {
err := rebalanceManager.Start(ctx)
err := rebalanceManager.Start(gctx)
if err != nil {
return fmt.Errorf("could not start rebalance manager: %w", err)
}
Expand All @@ -245,12 +245,12 @@ func (i *inventoryManagerImpl) Start(ctx context.Context) error {
g.Go(func() error {
for {
select {
case <-ctx.Done():
return fmt.Errorf("context canceled: %w", ctx.Err())
case <-gctx.Done():
return fmt.Errorf("context canceled: %w", gctx.Err())
case <-time.After(250 * time.Millisecond):
// this returning an error isn't really possible unless a config error happens
// TODO: need better error handling.
err := i.refreshBalances(ctx)
err := i.refreshBalances(gctx)
if err != nil {
logger.Errorf("could not refresh balances")
//nolint:nilerr
Expand All @@ -266,16 +266,16 @@ func (i *inventoryManagerImpl) Start(ctx context.Context) error {
g.Go(func() error {
for {
select {
case <-ctx.Done():
return fmt.Errorf("context canceled: %w", ctx.Err())
case <-gctx.Done():
return fmt.Errorf("context canceled: %w", gctx.Err())
case <-time.After(rebalanceInterval):
err := i.refreshBalances(ctx)
err := i.refreshBalances(gctx)
if err != nil {
return fmt.Errorf("could not refresh balances: %w", err)
}
for chainID, chainConfig := range i.cfg.Chains {
for tokenName, tokenConfig := range chainConfig.Tokens {
err = i.Rebalance(ctx, chainID, common.HexToAddress(tokenConfig.Address))
err = i.Rebalance(gctx, chainID, common.HexToAddress(tokenConfig.Address))
if err != nil {
logger.Errorf("could not rebalance %s on chain %d: %v", tokenName, chainID, err)
}
Expand Down

0 comments on commit a5a02c8

Please sign in to comment.