Skip to content

Commit

Permalink
Wait for mirror transaction to be mined
Browse files Browse the repository at this point in the history
  • Loading branch information
mboben committed Oct 17, 2023
1 parent a1a23b5 commit 462c183
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions indexer/cronjob/mirror_stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion indexer/cronjob/voting_stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions utils/chain/tx_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 462c183

Please sign in to comment.