Skip to content

Commit

Permalink
address PR comments and track last error in init
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Nov 27, 2023
1 parent a54b8c2 commit aa80bf9
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions execution/gethexec/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,30 @@ func (f *TxForwarder) Initialize(inctx context.Context) error {
if f.ctx == nil {
f.ctx = inctx
}

pos := 0
for pos < len(f.targets) {
if f.targets[pos] == "" {
f.targets = append(f.targets[:pos], f.targets[pos+1:]...)
} else {
pos += 1
}
}

ctx, cancelFunc := f.ctxWithTimeout()
defer cancelFunc()
pos = 0
for pos < len(f.targets) {
rpcClient, err := rpc.DialTransport(ctx, f.targets[pos], f.transport)
var targets []string
var lastError error
for _, target := range f.targets {
if target == "" {
continue
}
rpcClient, err := rpc.DialTransport(ctx, target, f.transport)
if err != nil {
log.Warn("error initializing a forwarding client in txForwarder", "forwarding url", f.targets[pos], "err", err)
f.targets = append(f.targets[:pos], f.targets[pos+1:]...)
log.Warn("error initializing a forwarding client in txForwarder", "forwarding url", target, "err", err)
lastError = err
continue
}
targets = append(targets, target)
ethClient := ethclient.NewClient(rpcClient)
f.rpcClients = append(f.rpcClients, rpcClient)
f.ethClients = append(f.ethClients, ethClient)
pos += 1
}
f.targets = targets
if len(f.rpcClients) > 0 {
f.enabled.Store(true)
} else {
return lastError
}
return nil
}
Expand Down

0 comments on commit aa80bf9

Please sign in to comment.