Skip to content

Commit

Permalink
Fix for nonces.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed May 15, 2024
1 parent 61cd4ad commit 9d9401c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,14 @@ func (p *Publisher) PublishCrossChainBundle(bundle *common.ExtCrossChainBundle)
return
}

nonce, err := p.ethClient.EthClient().PendingNonceAt(context.Background(), p.hostWallet.Address())
if err != nil {
p.logger.Error("Unable to get nonce for management contract", log.ErrKey, err)
return
}

// transactor.GasLimit = 200_000
transactor.Nonce = big.NewInt(0).SetUint64(p.hostWallet.GetNonceAndIncrement())
transactor.Nonce = big.NewInt(0).SetUint64(nonce)

tx, err := managementCtr.AddCrossChainMessagesRoot(transactor, [32]byte(bundle.StateRootHash.Bytes()), bundle.L1BlockHash, bundle.L1BlockNum, bundle.CrossChainHashes, bundle.Signature)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions integration/simulation/transaction_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ func (ti *TransactionInjector) awaitAndFinalizeWithdrawal(tx *types.Transaction,
}

time.Sleep(20 * time.Second)

oldBalance, err := ti.rpcHandles.RndEthClient().BalanceAt(vTransfers[0].Receiver, nil)
if err != nil {
ti.logger.Error("Failed to retrieve balance of receiver", log.ErrKey, err)
return
}

withdrawalTx, err := mCtr.ExtractNativeValue(opts, ManagementContract.StructsValueTransferMessage(vTransfers[0]), proof32, header.TransfersTree)
if err != nil {
ti.logger.Error("Failed to extract value transfer from L2", log.ErrKey, err)
Expand All @@ -419,6 +426,17 @@ func (ti *TransactionInjector) awaitAndFinalizeWithdrawal(tx *types.Transaction,
return
}

newBalance, err := ti.rpcHandles.RndEthClient().BalanceAt(vTransfers[0].Receiver, nil)
if err != nil {
ti.logger.Error("Failed to retrieve balance of receiver", log.ErrKey, err)
return
}

if newBalance.Sub(newBalance, oldBalance).Cmp(vTransfers[0].Amount) != 0 {
ti.logger.Error("Balance of receiver did not increase by the expected amount", "expected", vTransfers[0].Amount, "actual", newBalance.Sub(newBalance, oldBalance))
return
}

ti.logger.Info("Successful bridge withdrawal", log.TxKey, withdrawalTx.Hash())
}

Expand Down

0 comments on commit 9d9401c

Please sign in to comment.