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

Fix anvil behavior in CI #1955

Open
dwasse opened this issue Feb 1, 2024 · 1 comment
Open

Fix anvil behavior in CI #1955

dwasse opened this issue Feb 1, 2024 · 1 comment

Comments

@dwasse
Copy link
Collaborator

dwasse commented Feb 1, 2024

Currently the RFQ TestIntegrationSuite tests work locally, but do not work in CI. After inspecting the runtime with upterm it seems that anvil hangs on the base implementation for WaitForConfirmation- need to figure out why this is.

Copy link

greptile-apps bot commented Jun 24, 2024

To fix the anvil behavior in CI, modify the WaitForConfirmation method in ethergo/backends/base/base.go to include additional logging and error handling to diagnose the issue. Specifically, add logging to track the state of the transaction and the responses from the client. Here's a possible implementation:

func WaitForConfirmation(ctx context.Context, client ConfirmationClient, transaction *types.Transaction, timeout time.Duration) {
	// if tx is nil , we should panic here so we can see the call context
	_ = transaction.Hash()

	const debugTimeout = time.Second * 5

	start := time.Now()
	logIfShould := func(locker *sync.Once, template string, args ...interface{}) {
		if time.Since(start) > debugTimeout {
			locker.Do(func() {
				logger.Debugf(template, args...)
			})
		}
	}

	txConfirmedCtx, cancel := context.WithCancel(ctx)
	var logWaitOnce, logFetchErrOnce, logErrOnce sync.Once
	wait.UntilWithContext(txConfirmedCtx, func(ctx context.Context) {
		tx, isPending, err := client.TransactionByHash(txConfirmedCtx, transaction.Hash())
		logIfShould(&logWaitOnce, "waiting for tx %s", transaction.Hash())

		// Log the state of the transaction
		logger.Infof("Transaction state: isPending=%v, err=%v", isPending, err)

		if err != nil && !errors.Is(err, ethereum.NotFound) {
			receipt, receiptErr := client.TransactionReceipt(ctx, transaction.Hash())
			if err != nil {
				err = multierror.Append(err, receiptErr)
			}

			if receipt != nil {
				if receipt.Status == types.ReceiptStatusFailed {
					rawJSON, _ := transaction.MarshalJSON()
					logger.Errorf("transaction %s with body %s reverted", transaction, string(rawJSON))
				}
				cancel()
				return
			}
		}

		if err != nil {
			logIfShould(&logFetchErrOnce, "could not fetch transaction: %v", err)
		}

		if !isPending && tx != nil {
			receipt, err := client.TransactionReceipt(ctx, tx.Hash())
			if err != nil {
				if receipt.Status == types.ReceiptStatusFailed {
					rawJSON, _ := transaction.MarshalJSON()
					logger.Errorf("transaction %s with body %s reverted", transaction, string(rawJSON))
				}
			}

			cancel()
		} else if !isPending || time.Since(start) > debugTimeout {
			err := client.SendTransaction(ctx, transaction)
			if err != nil {
				ogErr := err
				call, err := util.TxToCall(transaction)
				if err != nil {
					logger.Errorf("could not convert tx to call: %v", err)
					return
				}

			realNonce, err := client.NonceAt(ctx, call.From, nil)
				if err != nil {
					logger.Errorf("could not get nonce: %v", err)
					return
				}

				logIfShould(&logErrOnce, "could not send transaction (from %s, account nonce %d, tx nonce: %d, tx hash: %s): %v", call.From, realNonce, transaction.Nonce(), transaction.Hash(), ogErr)
			}
		}
	}, timeout)
}

This will help identify where the process is hanging by providing more detailed logs. Additionally, ensure that the CI environment has the necessary resources and configurations to run the tests reliably.

References

/ethergo/backends/anvil/anvil.go
/ethergo/backends/base/base.go
/ethergo/backends/base/base_test.go
/services/rfq/e2e/rfq_test.go

Ask Greptile

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

No branches or pull requests

2 participants