Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove synchronizer dependency from eth tx manager to confirm monitored tx #3658

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -457,25 +456,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
Loading