From 715430eab3d61d61de012eae2a8ac14f04e7ac09 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 12 Jan 2024 10:52:56 +0100 Subject: [PATCH] made `generate_eoa_transactions` task more resilent against RPC errors --- .../tasks/generate_eoa_transactions/task.go | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/pkg/coordinator/tasks/generate_eoa_transactions/task.go b/pkg/coordinator/tasks/generate_eoa_transactions/task.go index 0ac34ed..23c2d9f 100644 --- a/pkg/coordinator/tasks/generate_eoa_transactions/task.go +++ b/pkg/coordinator/tasks/generate_eoa_transactions/task.go @@ -160,14 +160,6 @@ func (t *Task) Execute(ctx context.Context) error { totalCount := 0 for { - if pendingChan != nil { - select { - case <-ctx.Done(): - return nil - case pendingChan <- true: - } - } - txIndex := t.txIndex t.txIndex++ @@ -185,6 +177,14 @@ func (t *Task) Execute(ctx context.Context) error { if err != nil { t.logger.Errorf("error generating transaction: %v", err.Error()) } else { + if pendingChan != nil { + select { + case <-ctx.Done(): + return nil + case pendingChan <- true: + } + } + perBlockCount++ totalCount++ } @@ -317,13 +317,21 @@ func (t *Task) generateTransaction(ctx context.Context, transactionIdx uint64, c } } - client := clients[transactionIdx%uint64(len(clients))] + err = nil + + for i := 0; i < len(clients); i++ { + client := clients[(transactionIdx+uint64(i))%uint64(len(clients))] + + t.logger.WithFields(logrus.Fields{ + "client": client.GetName(), + }).Infof("sending tx %v: %v", transactionIdx, tx.Hash().Hex()) - t.logger.WithFields(logrus.Fields{ - "client": client.GetName(), - }).Infof("sending tx %v: %v", transactionIdx, tx.Hash().Hex()) + err = client.GetRPCClient().SendTransaction(ctx, tx) + if err == nil { + break + } + } - err = client.GetRPCClient().SendTransaction(ctx, tx) if err != nil { return err }