Skip to content

Commit

Permalink
Remove go routines for now to simplify logic
Browse files Browse the repository at this point in the history
Signed-off-by: asoliman <[email protected]>
  • Loading branch information
asoliman92 committed Sep 4, 2024
1 parent f19b01d commit 664a798
Showing 1 changed file with 23 additions and 41 deletions.
64 changes: 23 additions & 41 deletions commit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commit
import (
"context"
"fmt"
"sync"
"time"

"github.com/smartcontractkit/libocr/commontypes"
Expand Down Expand Up @@ -197,51 +196,34 @@ func (p *Plugin) Outcome(
)
}

wg := &sync.WaitGroup{}
wg.Add(3)

var merkleOutcome merkleroot.Outcome
var tokensOutcome tokenprice.Outcome
var gasOutcome chainfee.Outcome

go func(mOut *merkleroot.Outcome) {
defer wg.Done()
outcome, err := p.merkleProcessor.Outcome(
prevOutcome.MerkleRootOutcome,
merkleroot.Query{},
merkleObservations,
)
if err != nil {
p.lggr.Errorw("failed to get merkle outcome", "err", err)
}

*mOut = outcome
}(&merkleOutcome)
merkleRootOutcome, err := p.merkleProcessor.Outcome(
prevOutcome.MerkleRootOutcome,
merkleroot.Query{},
merkleObservations,
)
if err != nil {
p.lggr.Errorw("failed to get merkle outcome", "err", err)
}

go func(tOut *tokenprice.Outcome) {
defer wg.Done()
outcome, err := p.tokenProcessor.Outcome(prevOutcome.TokenPriceOutcome, tokenprice.Query{}, tokensObservations)
if err != nil {
p.lggr.Errorw("failed to get token prices outcome", "err", err)
}
*tOut = outcome
}(&tokensOutcome)
tokenPriceOutcome, err := p.tokenProcessor.Outcome(
prevOutcome.TokenPriceOutcome,
tokenprice.Query{},
tokensObservations,
)

go func(gOut *chainfee.Outcome) {
defer wg.Done()
outcome, err := p.feeProcessor.Outcome(prevOutcome.ChainFeeOutcome, chainfee.Query{}, feeObservations)
if err != nil {
p.lggr.Errorw("failed to get gas prices outcome", "err", err)
}
*gOut = outcome
}(&gasOutcome)
if err != nil {
p.lggr.Errorw("failed to get token prices outcome", "err", err)
}

wg.Wait()
chainFeeOutcome, err := p.feeProcessor.Outcome(prevOutcome.ChainFeeOutcome, chainfee.Query{}, feeObservations)
if err != nil {
p.lggr.Errorw("failed to get gas prices outcome", "err", err)
}

return Outcome{
MerkleRootOutcome: merkleOutcome,
TokenPriceOutcome: tokensOutcome,
ChainFeeOutcome: gasOutcome,
MerkleRootOutcome: merkleRootOutcome,
TokenPriceOutcome: tokenPriceOutcome,
ChainFeeOutcome: chainFeeOutcome,
}.Encode()
}

Expand Down

0 comments on commit 664a798

Please sign in to comment.