From 462c18359e19f53727f37fdea614dd230d674fe5 Mon Sep 17 00:00:00 2001 From: Marko Boben Date: Tue, 17 Oct 2023 11:28:52 +0200 Subject: [PATCH] Wait for mirror transaction to be mined --- indexer/cronjob/mirror_stubs.go | 14 +++++++++++--- indexer/cronjob/voting_stubs.go | 2 +- utils/chain/tx_utils.go | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/indexer/cronjob/mirror_stubs.go b/indexer/cronjob/mirror_stubs.go index 3aa4edd..2fa56e6 100644 --- a/indexer/cronjob/mirror_stubs.go +++ b/indexer/cronjob/mirror_stubs.go @@ -139,8 +139,16 @@ func (m mirrorContractsCChain) MirrorStake( stakeData *mirroring.IPChainStakeMirrorVerifierPChainStake, merkleProof [][32]byte, ) error { - _, err := m.mirroring.MirrorStake(m.txOpts, *stakeData, merkleProof) - return err + tx, err := m.mirroring.MirrorStake(m.txOpts, *stakeData, merkleProof) + if err != nil { + return err + } + err = m.txVerifier.WaitUntilMined(m.txOpts.From, tx, chain.DefaultTxTimeout) + if err != nil { + return err + } + logger.Debug("Mined mirror tx %s", tx.Hash().Hex()) + return nil } func (m mirrorContractsCChain) IsAddressRegistered(address string) (bool, error) { @@ -164,7 +172,7 @@ func (m mirrorContractsCChain) RegisterPublicKey(publicKey crypto.PublicKey) err if err != nil { return err } - err = m.txVerifier.WaitUntilMined(m.txOpts.From, tx, 60*time.Second) + err = m.txVerifier.WaitUntilMined(m.txOpts.From, tx, chain.DefaultTxTimeout) if err != nil { return err } diff --git a/indexer/cronjob/voting_stubs.go b/indexer/cronjob/voting_stubs.go index 19858d8..b2131cc 100644 --- a/indexer/cronjob/voting_stubs.go +++ b/indexer/cronjob/voting_stubs.go @@ -81,7 +81,7 @@ func (c *votingContractCChain) SubmitVote(epoch *big.Int, merkleRoot [32]byte) e if err != nil { return err } - err = c.txVerifier.WaitUntilMined(c.callOpts.From, tx, 60*time.Second) + err = c.txVerifier.WaitUntilMined(c.callOpts.From, tx, chain.DefaultTxTimeout) if err != nil { if strings.Contains(err.Error(), "epoch already finalized") { logger.Info("Epoch %s already finalized", epoch.String()) diff --git a/utils/chain/tx_utils.go b/utils/chain/tx_utils.go index c8e3fb1..759e6bb 100644 --- a/utils/chain/tx_utils.go +++ b/utils/chain/tx_utils.go @@ -15,6 +15,11 @@ import ( "github.com/pkg/errors" ) +const ( + // default timeout for waiting for a tx to be mined. + DefaultTxTimeout = 60 * time.Second +) + type TxVerifier struct { eth *ethclient.Client }