From e33fd4c73651e03cfc607ff7754631b28b7513ea Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 3 Oct 2023 12:01:08 +0300 Subject: [PATCH 1/4] Waiting for receipt instead of random wait. --- integration/common/utils.go | 24 ++++++++++++++++++++++++ integration/simulation/simulation.go | 12 +++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/integration/common/utils.go b/integration/common/utils.go index 24df954384..4d5ca021af 100644 --- a/integration/common/utils.go +++ b/integration/common/utils.go @@ -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(ctx context.Context, 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()) + } + + return nil +} + // AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the // transaction is unsuccessful or times out. func AwaitReceipt(ctx context.Context, client *obsclient.AuthObsClient, txHash gethcommon.Hash, timeout time.Duration) error { diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index 376d20c0ea..04ece6fc6c 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -146,6 +146,7 @@ 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 { @@ -153,27 +154,28 @@ func (s *Simulation) bridgeFundingToObscuro() { } 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) // 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.ctx, 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. From 2fb3765b8960ac7f4aac5f74cea8962938c39668 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 3 Oct 2023 14:55:40 +0300 Subject: [PATCH 2/4] Linter fixes. --- integration/common/utils.go | 2 +- integration/simulation/simulation.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/common/utils.go b/integration/common/utils.go index 4d5ca021af..9b2a5d9ba3 100644 --- a/integration/common/utils.go +++ b/integration/common/utils.go @@ -38,7 +38,7 @@ func RndBtwTime(min time.Duration, max time.Duration) time.Duration { return time.Duration(RndBtw(uint64(min.Nanoseconds()), uint64(max.Nanoseconds()))) * time.Nanosecond } -func AwaitReceiptEth(ctx context.Context, client ethadapter.EthClient, txHash gethcommon.Hash, timeout time.Duration) error { +func AwaitReceiptEth(client ethadapter.EthClient, txHash gethcommon.Hash, timeout time.Duration) error { var receipt *types.Receipt var err error err = retry.Do(func() error { diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index 04ece6fc6c..545739ca94 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -161,7 +161,7 @@ func (s *Simulation) bridgeFundingToObscuro() { transactions = append(transactions, tx) } - //time.Sleep(3 * time.Second) + // time.Sleep(3 * time.Second) // todo - fix the wait group, for whatever reason it does not find a receipt... wg := sync.WaitGroup{} for _, tx := range transactions { @@ -169,7 +169,7 @@ func (s *Simulation) bridgeFundingToObscuro() { transaction := tx go func() { defer wg.Done() - err := testcommon.AwaitReceiptEth(s.ctx, s.RPCHandles.RndEthClient(), transaction.Hash(), 2*time.Minute) + err := testcommon.AwaitReceiptEth(s.RPCHandles.RndEthClient(), transaction.Hash(), 2*time.Minute) if err != nil { panic(err) } From d801f04199b1fa7d77beb382ad4a7d415db9ca21 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 19 Dec 2023 15:53:35 +0200 Subject: [PATCH 3/4] Removed comment. --- integration/simulation/simulation.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index 545739ca94..aa732cbb85 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -161,8 +161,6 @@ func (s *Simulation) bridgeFundingToObscuro() { transactions = append(transactions, tx) } - // time.Sleep(3 * time.Second) - // todo - fix the wait group, for whatever reason it does not find a receipt... wg := sync.WaitGroup{} for _, tx := range transactions { wg.Add(1) From 3673e66539558def6d8f2975527c71f30301395e Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Tue, 19 Dec 2023 16:14:51 +0200 Subject: [PATCH 4/4] Removed commented out function. --- integration/common/utils.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/integration/common/utils.go b/integration/common/utils.go index b44735f22b..676e6db689 100644 --- a/integration/common/utils.go +++ b/integration/common/utils.go @@ -39,29 +39,6 @@ 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()) - } - - return nil -}*/ - // AwaitReceipt blocks until the receipt for the transaction with the given hash has been received. Errors if the // transaction is unsuccessful or times out. func AwaitReceipt(ctx context.Context, client *obsclient.AuthObsClient, txHash gethcommon.Hash, timeout time.Duration) error {