Skip to content

Commit

Permalink
Merge pull request #2060 from OffchainLabs/allow-empty-forwarder
Browse files Browse the repository at this point in the history
Allow the TxForwarder to be empty
  • Loading branch information
PlasmaPower authored Dec 27, 2023
2 parents 2f9c34d + 02bfe08 commit 8f33fea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 12 additions & 4 deletions execution/gethexec/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (f *TxForwarder) PublishTransaction(inctx context.Context, tx *types.Transa
if err == nil || !f.tryNewForwarderErrors.MatchString(err.Error()) {
return err
}
log.Info("error forwarding transaction to a backup target", "target", f.targets[pos], "err", err)
log.Warn("error forwarding transaction to a backup target", "target", f.targets[pos], "err", err)
}
return errors.New("failed to publish transaction to any of the forwarding targets")
}
Expand All @@ -161,7 +161,9 @@ const maxHealthTimeout = 10 * time.Second

// CheckHealth returns health of the highest priority forwarding target
func (f *TxForwarder) CheckHealth(inctx context.Context) error {
if !f.enabled.Load() {
// If f.enabled is true, len(f.rpcClients) should always be greater than zero,
// but better safe than sorry.
if !f.enabled.Load() || len(f.rpcClients) == 0 {
return ErrNoSequencer
}
f.healthMutex.Lock()
Expand Down Expand Up @@ -205,8 +207,6 @@ func (f *TxForwarder) Initialize(inctx context.Context) error {
f.targets = targets
if len(f.rpcClients) > 0 {
f.enabled.Store(true)
} else if lastError == nil {
return errors.New("no non-empty forwarding targets specified")
} else {
return lastError
}
Expand All @@ -232,6 +232,14 @@ func (f *TxForwarder) Started() bool {
return true
}

// Returns the URL of the first forwarding target, or an empty string if none are set.
func (f *TxForwarder) PrimaryTarget() string {
if len(f.targets) == 0 {
return ""
}
return f.targets[0]
}

type TxDropper struct{}

func NewTxDropper() *TxDropper {
Expand Down
6 changes: 3 additions & 3 deletions execution/gethexec/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,17 @@ func (s *Sequencer) CheckHealth(ctx context.Context) error {
func (s *Sequencer) ForwardTarget() string {
s.activeMutex.Lock()
defer s.activeMutex.Unlock()
if s.forwarder == nil || len(s.forwarder.targets) == 0 {
if s.forwarder == nil {
return ""
}
return s.forwarder.targets[0]
return s.forwarder.PrimaryTarget()
}

func (s *Sequencer) ForwardTo(url string) error {
s.activeMutex.Lock()
defer s.activeMutex.Unlock()
if s.forwarder != nil {
if len(s.forwarder.targets) > 0 && s.forwarder.targets[0] == url {
if s.forwarder.PrimaryTarget() == url {
log.Warn("attempted to update sequencer forward target with existing target", "url", url)
return nil
}
Expand Down

0 comments on commit 8f33fea

Please sign in to comment.