Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: avoid killing entire rly process #1396

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions relayer/processor/event_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package processor

import (
"context"

"golang.org/x/sync/errgroup"
"sync"
)

// EventProcessorBuilder is a configuration type with .With functions used for building an EventProcessor.
Expand Down Expand Up @@ -91,25 +90,37 @@ func (ep EventProcessorBuilder) Build() EventProcessor {
// It will return once all PathProcessors and ChainProcessors have stopped running due to context cancellation,
// or if a critical error has occurred within one of the ChainProcessors.
func (ep EventProcessor) Run(ctx context.Context) error {
var eg errgroup.Group
var wg sync.WaitGroup

runCtx, runCtxCancel := context.WithCancel(ctx)
for _, pathProcessor := range ep.pathProcessors {
pathProcessor := pathProcessor
eg.Go(func() error {

wg.Add(1)
go func() {
pathProcessor.Run(runCtx, runCtxCancel)
return nil
})
wg.Done()
}()
}

for _, chainProcessor := range ep.chainProcessors {
chainProcessor := chainProcessor
eg.Go(func() error {
err := chainProcessor.Run(runCtx, ep.initialBlockHistory, ep.stuckPacket)
// Signal the other chain processors to exit.
runCtxCancel()
return err
})

wg.Add(1)
go func() {
err := func() error {
err := chainProcessor.Run(runCtx, ep.initialBlockHistory, ep.stuckPacket)
return err
}()
if err != nil {
// TODO: do we need to log errors here or have they already been logged by ChainProcessor?
}
wg.Done()
}()
}
err := eg.Wait()

wg.Wait()
runCtxCancel()
return err

return nil
}
6 changes: 5 additions & 1 deletion relayer/processor/path_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,11 @@ func (pp *PathProcessor) Run(ctx context.Context, cancel func()) {
return
}

for len(pp.pathEnd1.incomingCacheData) > 0 || len(pp.pathEnd2.incomingCacheData) > 0 || len(pp.retryProcess) > 0 || len(pp.pathEnd1.finishedProcessing) > 0 || len(pp.pathEnd2.finishedProcessing) > 0 {
for len(pp.pathEnd1.incomingCacheData) > 0 ||
len(pp.pathEnd2.incomingCacheData) > 0 ||
len(pp.retryProcess) > 0 ||
len(pp.pathEnd1.finishedProcessing) > 0 ||
len(pp.pathEnd2.finishedProcessing) > 0 {
// signals are available, so this will not need to block.
if pp.processAvailableSignals(ctx, cancel) {
return
Expand Down
Loading