-
Notifications
You must be signed in to change notification settings - Fork 40
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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" | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -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 { | ||||||||||||||||||||||||||||||||||||||||||
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()) | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - 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
Suggested change
The - 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
Suggested change
The - 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
Suggested change
The - 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
// transaction is unsuccessful or times out. | ||||||||||||||||||||||||||||||||||||||||||
func AwaitReceipt(ctx context.Context, client *obsclient.AuthObsClient, txHash gethcommon.Hash, timeout time.Duration) error { | ||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an existing
AwaitReceiptEth
method that we can potentially use instead.