Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider transaction dropped for some time #11

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions internal/eth/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)

const (
// notDroppedUntil is how long to wait for a transaction
// before considering it dropped.
notDroppedUntil = time.Second * 30
)

type WaitProgress interface {
Start(hash common.Hash)
Canceled()
Expand Down Expand Up @@ -64,13 +70,16 @@ func (w progressWaiter) Wait(ctx context.Context, hash common.Hash) (uint64, err
}

func WaitForTransaction(ctx context.Context, backend WaitBackend, hash common.Hash, progress WaitProgress) (uint64, error) {
startTime := time.Now()

if ctx == nil {
ctx = context.Background()
}
if progress == nil {
progress = NoProgress{}
}
progress.Start(hash)

for {
select {
case <-time.After(time.Millisecond * 100):
Expand Down Expand Up @@ -98,8 +107,13 @@ func WaitForTransaction(ctx context.Context, backend WaitBackend, hash common.Ha
switch {
case err == nil:
case err == ethereum.NotFound:
progress.Dropped()
return 0, errors.New("transaction dropped")
// Wait up to notDroppedUntil time before considering the
// transaction dropped. This avoids false positives when using
// networks like Infura, whose nodes are eventually consistent.
if time.Since(startTime) >= notDroppedUntil {
progress.Dropped()
return 0, errors.New("transaction dropped")
}
default:
progress.TempError(fmt.Errorf("failed to query for transaction by hash: %+v", err))
}
Expand Down
Loading