Skip to content

Commit 7c9edb4

Browse files
committed
solve concurrency problem
1 parent 7e3a25d commit 7c9edb4

File tree

1 file changed

+13
-6
lines changed
  • pkg/coordinator/tasks/tx_pool_latency_analysis

1 file changed

+13
-6
lines changed

pkg/coordinator/tasks/tx_pool_latency_analysis/task.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func (t *Task) Execute(ctx context.Context) error {
126126
var totNumberOfTxes int = t.config.QPS * t.config.Duration_s
127127
var txs []*ethtypes.Transaction = make([]*ethtypes.Transaction, totNumberOfTxes)
128128
var txStartTime []time.Time = make([]time.Time, totNumberOfTxes)
129-
var hashToIndex map[string]int = make(map[string]int)
130129
var testDeadline time.Time = time.Now().Add(time.Duration(t.config.Duration_s+60) * time.Second)
131130
var latenciesMus = make([]int64, totNumberOfTxes)
132131

@@ -153,7 +152,7 @@ func (t *Task) Execute(ctx context.Context) error {
153152
return
154153
}
155154

156-
tx, err := t.generateTransaction(ctx)
155+
tx, err := t.generateTransaction(ctx, i)
157156
if err != nil {
158157
t.logger.Errorf("Failed to create transaction: %v", err)
159158
t.ctx.SetResult(types.TaskResultFailure)
@@ -171,7 +170,7 @@ func (t *Task) Execute(ctx context.Context) error {
171170
}
172171

173172
txs[i] = tx
174-
hashToIndex[tx.Hash().String()] = i
173+
//hashToIndex[tx.Hash().String()] = i
175174
sentTxCount++
176175

177176
// log transaction sending
@@ -220,7 +219,15 @@ func (t *Task) Execute(ctx context.Context) error {
220219
}
221220

222221
for _, tx := range *txes {
223-
tx_index := hashToIndex[tx.Hash().String()]
222+
tx_data := tx.Data()
223+
// read tx_data that is in the format "tx_index:<index>"
224+
var tx_index int
225+
_, err := fmt.Sscanf(string(tx_data), "tx_index:%d", &tx_index)
226+
if err != nil {
227+
t.logger.Errorf("Failed to parse transaction data: %v", err)
228+
t.ctx.SetResult(types.TaskResultFailure)
229+
return
230+
}
224231
latenciesMus[tx_index] = time.Now().Sub(txStartTime[tx_index]).Microseconds()
225232
receivedEvents++
226233

@@ -357,7 +364,7 @@ func (t *Task) getTcpConn(ctx context.Context, client *execution.Client) (*sentr
357364
return conn, nil
358365
}
359366

360-
func (t *Task) generateTransaction(ctx context.Context) (*ethtypes.Transaction, error) {
367+
func (t *Task) generateTransaction(ctx context.Context, i int) (*ethtypes.Transaction, error) {
361368
tx, err := t.wallet.BuildTransaction(ctx, func(_ context.Context, nonce uint64, _ bind.SignerFn) (*ethtypes.Transaction, error) {
362369
addr := t.wallet.GetAddress()
363370
toAddr := &addr
@@ -377,7 +384,7 @@ func (t *Task) generateTransaction(ctx context.Context) (*ethtypes.Transaction,
377384
Gas: 50000,
378385
To: toAddr,
379386
Value: txAmount,
380-
Data: []byte{},
387+
Data: []byte(fmt.Sprintf("tx_index:%d", i)),
381388
}
382389

383390
return ethtypes.NewTx(txObj), nil

0 commit comments

Comments
 (0)