Skip to content

Commit 989ddc5

Browse files
fix(tx_pool_throughput_analysis): enhance transaction handling by re-sending missing transactions on timeout and improving failure state management
1 parent 8f84332 commit 989ddc5

File tree

1 file changed

+25
-7
lines changed
  • pkg/coordinator/tasks/tx_pool_throughput_analysis

1 file changed

+25
-7
lines changed

pkg/coordinator/tasks/tx_pool_throughput_analysis/task.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func (t *Task) Execute(ctx context.Context) error {
129129

130130
// generate and sign tx
131131
go func() {
132-
if ctx.Err() != nil {
133-
return;
132+
if ctx.Err() != nil && !isFailed {
133+
return
134134
}
135135

136136
tx, err := t.generateTransaction(ctx)
@@ -152,14 +152,15 @@ func (t *Task) Execute(ctx context.Context) error {
152152
if err != nil {
153153
t.logger.WithField("client", client.GetName()).Errorf("Failed to send transaction: %v", err)
154154
t.ctx.SetResult(types.TaskResultFailure)
155+
isFailed = true
155156
return
156157
}
157158

158159
txs = append(txs, tx)
159160
}()
160161

161162
if isFailed {
162-
return;
163+
return
163164
}
164165

165166
time.Sleep(sleepTime)
@@ -173,7 +174,7 @@ func (t *Task) Execute(ctx context.Context) error {
173174
gotTx := 0
174175

175176
if isFailed {
176-
return nil;
177+
return nil
177178
}
178179

179180
for gotTx < t.config.QPS {
@@ -204,9 +205,26 @@ func (t *Task) Execute(ctx context.Context) error {
204205
}
205206
gotTx += len(*result.txs)
206207
case <-time.After(180 * time.Second):
207-
t.logger.Errorf("Timeout after 180 seconds while reading transaction messages")
208-
t.ctx.SetResult(types.TaskResultFailure)
209-
return nil
208+
t.logger.Warnf("Timeout after 180 seconds while reading transaction messages. Re-sending transactions...")
209+
210+
// Calculate how many transactions we're still missing
211+
missingTxCount := t.config.QPS - gotTx
212+
if missingTxCount <= 0 {
213+
break
214+
}
215+
216+
// Re-send transactions to the original client
217+
for i := 0; i < missingTxCount && i < len(txs); i++ {
218+
err = client.GetRPCClient().SendTransaction(ctx, txs[i])
219+
if err != nil {
220+
t.logger.WithError(err).Errorf("Failed to re-send transaction message, error: %v", err)
221+
t.ctx.SetResult(types.TaskResultFailure)
222+
return nil
223+
}
224+
}
225+
226+
t.logger.Infof("Re-sent %d transactions", missingTxCount)
227+
continue
210228
}
211229

212230
if gotTx%t.config.MeasureInterval != 0 {

0 commit comments

Comments
 (0)