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

Waiting for receipt in simulation tests. #1571

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
24 changes: 24 additions & 0 deletions integration/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"time"

"github.com/obscuronet/go-obscuro/go/common/retry"
"github.com/obscuronet/go-obscuro/go/ethadapter"

"github.com/obscuronet/go-obscuro/go/obsclient"

"github.com/obscuronet/go-obscuro/go/wallet"

"github.com/ethereum/go-ethereum"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/obscuronet/go-obscuro/go/rpc"
Expand All @@ -36,6 +38,28 @@ func RndBtwTime(min time.Duration, max time.Duration) time.Duration {
return time.Duration(RndBtw(uint64(min.Nanoseconds()), uint64(max.Nanoseconds()))) * time.Nanosecond
}

func AwaitReceiptEth(client ethadapter.EthClient, txHash gethcommon.Hash, timeout time.Duration) error {
Copy link
Contributor

@otherview otherview Nov 2, 2023

Choose a reason for hiding this comment

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

There's an existingAwaitReceiptEth method that we can potentially use instead.

var receipt *types.Receipt
var err error
err = retry.Do(func() error {
receipt, err = client.TransactionReceipt(txHash)
if err != nil && !errors.Is(err, rpc.ErrNilResponse) && !errors.Is(err, ethereum.NotFound) {
// we only retry for a nil "not found" response. This is a different error, so we bail out of the retry loop
return retry.FailFast(err)
}
return err
}, retry.NewTimeoutStrategy(timeout, _awaitReceiptPollingInterval))
if err != nil {
return fmt.Errorf("could not retrieve receipt for transaction %s - %w", txHash.Hex(), err)
}

if receipt.Status == types.ReceiptStatusFailed {
return fmt.Errorf("receipt had status failed for transaction %s", txHash.Hex())
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this an error?

}

return nil
}

// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
Copy link

Choose a reason for hiding this comment

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

The AwaitReceiptEth function prints to the console with fmt.Println. This is not a standard approach for logging in production code and could be replaced with a structured logging framework that allows for log levels and better control over log output.

- fmt.Println("Fetching receipt for tx: ", txHash.Hex())
- fmt.Println("No tx receipt after: ", time.Since(startTime))
+ // Use structured logging instead
+ log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
+ log.Info("No tx receipt after", "duration", time.Since(startTime))

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// Use structured logging instead
log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
log.Info("No tx receipt after", "duration", time.Since(startTime))

The AwaitReceiptEth function's use of fmt.Println for logging is not ideal. Consider using a structured logging approach for better log management and consistency across the codebase.

- fmt.Println("Fetching receipt for tx: ", txHash.Hex())
- fmt.Println("No tx receipt after: ", time.Since(startTime))
+ // Replace with structured logging
+ log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
+ log.Info("No tx receipt after", "duration", time.Since(startTime))

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// Replace with structured logging
log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
log.Info("No tx receipt after", "duration", time.Since(startTime))

The AwaitReceiptEth function prints to the console with fmt.Println. This is not a standard approach for logging in production code and could be replaced with a structured logging framework that allows for log levels and better control over log output.

- fmt.Println("Fetching receipt for tx: ", txHash.Hex())
- fmt.Println("No tx receipt after: ", time.Since(startTime))
+ // Use structured logging instead
+ log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
+ log.Info("No tx receipt after", "duration", time.Since(startTime))

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// Use structured logging instead
log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
log.Info("No tx receipt after", "duration", time.Since(startTime))

The AwaitReceiptEth function's use of fmt.Println for logging is not ideal. Consider using a structured logging approach for better log management and consistency across the codebase.

- fmt.Println("Fetching receipt for tx: ", txHash.Hex())
- fmt.Println("No tx receipt after: ", time.Since(startTime))
+ // Replace with structured logging
+ log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
+ log.Info("No tx receipt after", "duration", time.Since(startTime))

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the
// Replace with structured logging
log.Info("Fetching receipt for tx", "txHash", txHash.Hex())
log.Info("No tx receipt after", "duration", time.Since(startTime))

// transaction is unsuccessful or times out.
func AwaitReceipt(ctx context.Context, client *obsclient.AuthObsClient, txHash gethcommon.Hash, timeout time.Duration) error {
Expand Down
12 changes: 7 additions & 5 deletions integration/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,34 +146,36 @@ func (s *Simulation) bridgeFundingToObscuro() {
panic(err)
}

transactions := make(types.Transactions, 0)
for idx, wallet := range wallets {
opts, err := bind.NewKeyedTransactorWithChainID(wallet.PrivateKey(), wallet.ChainID())
if err != nil {
panic(err)
}
opts.Value = value

_, err = busCtr.SendValueToL2(opts, receivers[idx], value)
tx, err := busCtr.SendValueToL2(opts, receivers[idx], value)
if err != nil {
panic(err)
}
transactions = append(transactions, tx)
}

time.Sleep(3 * time.Second)
// time.Sleep(3 * time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove comment

// todo - fix the wait group, for whatever reason it does not find a receipt...
/*wg := sync.WaitGroup{}
wg := sync.WaitGroup{}
for _, tx := range transactions {
wg.Add(1)
transaction := tx
go func() {
defer wg.Done()
err := testcommon.AwaitReceiptEth(s.ctx, s.RPCHandles.RndEthClient(), transaction.Hash(), 20*time.Second)
err := testcommon.AwaitReceiptEth(s.RPCHandles.RndEthClient(), transaction.Hash(), 2*time.Minute)
if err != nil {
panic(err)
}
}()
}
wg.Wait()*/
wg.Wait()
}

// We subscribe to logs on every client for every wallet.
Expand Down