Skip to content

Conversation

@hieudinhngoc-ncc
Copy link
Collaborator

No description provided.

if err != nil {
// If transaction failed due to context cancellation, do not count it as failed
if contains(err.Error(), "context canceled") || lt.ctx.Err() == context.Canceled {
atomic.AddInt64(&lt.totalTxsSent, -1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

đoạn này có nên check totalTxsent <0 trước khi giảm không ô nhỉ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Đoạn này tôi nghĩ là không cần check, vì là trước khi gọi vào hàm sendTransaction() ta đã tăng totalTxsSent lên trước đó rồi => nên không cần thiết phải check totalTxsSent < 0

Comment on lines +675 to +683
if !lt.incrementAndCheckLimit() {
return
}

lt.wg.Add(1)
go func() {
defer lt.wg.Done()
lt.sendTransaction(sender, receiver, nonce, txErr)
}()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theo như tôi hiểu thì đoạn này đang tăng tx trước khi send , oke cái này để confirm thôi nếu đúng thì....vấn đề thực sự trong hàm send này ô ạ, có vẻ như nếu send lỗi hay như nào đó ( return sớm ) mà không có logic rollback lại cái total tx vừa tăng lên . Nếu đúng là như vậy thì tôi nghĩ trong này nên có một hàm helper kiểu rollbackcounttx để ở bất cứ nơi nào return sớm trong hàm sendTx này!

Copy link
Collaborator Author

@hieudinhngoc-ncc hieudinhngoc-ncc Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cũng đúng, với code hiện tại hàm sendTransaction() đang có 1 logic lắng nghe sự kiện nếu context bị hủy ngang khi đang xử lý tạo transaction mà chưa gọi đến hàm AddTx() => thì sẽ không có logic để rollback lại totalTxsSent
image

Hướng giải quyết:

  • Hiện tại trong hàm sendTransaction() chỉ có logic nói ở trên là không cập nhật gì về số lượng transaction => còn các logic khác đều đã có logic để xử lý số lượng transaction để đảm bảo totalTxsSent = totalTxsSuccess + totalTxsFailed trước khi return.
    => Tôi sẽ xóa logic lắng nghe sự kiện context cancel ở hàm sendTransaction() đi =>nếu đang send mà bị context cancel thì hàm AddTx() sẽ trả về false => sẽ ăn vào ngay logic rollback ở đó
  • Hình ảnh test lại với code mới (TPS: 3000, đang chạy thì ctrl + C giữa chừng (dừng đột ngột)
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeahhh

Cũng đúng, với code hiện tại hàm sendTransaction() đang có 1 logic lắng nghe sự kiện nếu context bị hủy ngang khi đang xử lý tạo transaction mà chưa gọi đến hàm AddTx() => thì sẽ không có logic để rollback lại totalTxsSent image

Hướng giải quyết:

  • Hiện tại trong hàm sendTransaction() chỉ có logic nói ở trên là không cập nhật gì về số lượng transaction => còn các logic khác đều đã có logic để xử lý số lượng transaction để đảm bảo totalTxsSent = totalTxsSuccess + totalTxsFailed trước khi return.
    => Tôi sẽ xóa logic lắng nghe sự kiện context cancel ở hàm sendTransaction() đi =>nếu đang send mà bị context cancel thì hàm AddTx() sẽ trả về false => sẽ ăn vào ngay logic rollback ở đó
  • Hình ảnh test lại với code mới (TPS: 3000, đang chạy thì ctrl + C giữa chừng (dừng đột ngột)
image

yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants