Skip to content

Commit

Permalink
remove synchronizer dependency from eth tx manager to confirm monitor…
Browse files Browse the repository at this point in the history
…ed tx (#3658) (#3679)
  • Loading branch information
tclemos authored Jun 5, 2024
1 parent bc064aa commit e6864e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 67 deletions.
23 changes: 3 additions & 20 deletions ethtxmanager/ethtxmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -486,25 +485,9 @@ func (c *Client) monitorTx(ctx context.Context, mTx monitoredTx, logger *log.Log

// if mined, check receipt and mark as Failed or Confirmed
if lastReceiptChecked.Status == types.ReceiptStatusSuccessful {
receiptBlockNum := lastReceiptChecked.BlockNumber.Uint64()

// check if state is already synchronized until the block
// where the tx was mined
block, err := c.state.GetLastBlock(ctx, nil)
if errors.Is(err, state.ErrStateNotSynchronized) {
logger.Debugf("state not synchronized yet, waiting for L1 block %v to be synced", receiptBlockNum)
return
} else if err != nil {
logger.Errorf("failed to check if L1 block %v is already synced: %v", receiptBlockNum, err)
return
} else if block.BlockNumber < receiptBlockNum {
logger.Debugf("L1 block %v not synchronized yet, waiting for L1 block to be synced in order to confirm monitored tx", receiptBlockNum)
return
} else {
mTx.status = MonitoredTxStatusConfirmed
mTx.blockNumber = lastReceiptChecked.BlockNumber
logger.Info("confirmed")
}
mTx.status = MonitoredTxStatusConfirmed
mTx.blockNumber = lastReceiptChecked.BlockNumber
logger.Info("confirmed")
} else {
// if we should continue to monitor, we move to the next one and this will
// be reviewed in the next monitoring cycle
Expand Down
49 changes: 2 additions & 47 deletions ethtxmanager/ethtxmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/test/dbutils"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -118,14 +117,6 @@ func TestTxGetMined(t *testing.T) {
Return("", nil).
Once()

block := &state.Block{
BlockNumber: blockNumber.Uint64(),
}
st.
On("GetLastBlock", ctx, nil).
Return(block, nil).
Once()

err = ethTxManagerClient.Add(ctx, owner, id, from, to, value, data, gasOffset, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -263,14 +254,6 @@ func TestTxGetMinedAfterReviewed(t *testing.T) {
Return(receipt, nil).
Once()

block := &state.Block{
BlockNumber: blockNumber.Uint64(),
}
st.
On("GetLastBlock", ctx, nil).
Return(block, nil).
Once()

// Build result
etherman.
On("GetTx", ctx, firstSignedTx.Hash()).
Expand Down Expand Up @@ -383,16 +366,8 @@ func TestTxGetMinedAfterConfirmedAndReorged(t *testing.T) {
}
etherman.
On("GetTxReceipt", ctx, signedTx.Hash()).
Return(receipt, nil).
Once()

block := &state.Block{
BlockNumber: blockNumber.Uint64(),
}
st.
On("GetLastBlock", ctx, nil).
Run(func(args mock.Arguments) { ethTxManagerClient.Stop() }). // stops the management cycle to avoid problems with mocks
Return(block, nil).
Return(receipt, nil).
Once()

// Build Result 1
Expand Down Expand Up @@ -433,12 +408,8 @@ func TestTxGetMinedAfterConfirmedAndReorged(t *testing.T) {
// Monitoring Cycle 3
etherman.
On("CheckTxWasMined", ctx, signedTx.Hash()).
Return(true, receipt, nil).
Once()
st.
On("GetLastBlock", ctx, nil).
Run(func(args mock.Arguments) { ethTxManagerClient.Stop() }). // stops the management cycle to avoid problems with mocks
Return(block, nil).
Return(true, receipt, nil).
Once()

// Build Result 3
Expand Down Expand Up @@ -643,14 +614,6 @@ func TestExecutionReverted(t *testing.T) {
Return(receipt, nil).
Once()

block := &state.Block{
BlockNumber: blockNumber.Uint64(),
}
st.
On("GetLastBlock", ctx, nil).
Return(block, nil).
Once()

// Build result
etherman.
On("GetTx", ctx, firstSignedTx.Hash()).
Expand Down Expand Up @@ -959,14 +922,6 @@ func TestFailedToEstimateTxWithForcedGasGetMined(t *testing.T) {
Return("", nil).
Once()

block := &state.Block{
BlockNumber: blockNumber.Uint64(),
}
st.
On("GetLastBlock", ctx, nil).
Return(block, nil).
Once()

err = ethTxManagerClient.Add(ctx, owner, id, from, to, value, data, gasOffset, nil)
require.NoError(t, err)

Expand Down

0 comments on commit e6864e5

Please sign in to comment.