Skip to content

Commit

Permalink
feat: New zkevm-ethtx-manager version (#98)
Browse files Browse the repository at this point in the history
* fix: update zkevm-ethtx-manager version

* fix: UTs
  • Loading branch information
goran-ethernal authored Sep 30, 2024
1 parent c4c790f commit 473cc88
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 39 deletions.
3 changes: 1 addition & 2 deletions aggoracle/chaingersender/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type EthTxManager interface {
Result(ctx context.Context, id common.Hash) (ethtxmanager.MonitoredTxResult, error)
Add(ctx context.Context,
to *common.Address,
forcedNonce *uint64,
value *big.Int,
data []byte,
gasOffset uint64,
Expand Down Expand Up @@ -103,7 +102,7 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com
if err != nil {
return err
}
id, err := c.ethTxMan.Add(ctx, &c.gerAddr, nil, big.NewInt(0), data, c.gasOffset, nil)
id, err := c.ethTxMan.Add(ctx, &c.gerAddr, big.NewInt(0), data, c.gasOffset, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ func (a *Aggregator) settleDirect(
return false
}

monitoredTxID, err := a.ethTxManager.Add(ctx, to, nil, big.NewInt(0), data, a.cfg.GasOffset, nil)
monitoredTxID, err := a.ethTxManager.Add(ctx, to, big.NewInt(0), data, a.cfg.GasOffset, nil)
if err != nil {
a.logger.Errorf("Error Adding TX to ethTxManager: %v", err)
mTxLogger := ethtxmanager.CreateLogger(monitoredTxID, sender, to)
Expand Down
2 changes: 1 addition & 1 deletion bridgesync/mock_l2_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions claimsponsor/evmclaimsponsor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type EthTxManager interface {
ResultsByStatus(ctx context.Context, statuses []ethtxmanager.MonitoredTxStatus,
) ([]ethtxmanager.MonitoredTxResult, error)
Result(ctx context.Context, id common.Hash) (ethtxmanager.MonitoredTxResult, error)
Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte,
Add(ctx context.Context, to *common.Address, value *big.Int, data []byte,
gasOffset uint64, sidecar *types.BlobTxSidecar) (common.Hash, error)
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *EVMClaimSponsor) sendClaim(ctx context.Context, claim *Claim) (string,
if err != nil {
return "", err
}
id, err := c.ethTxManager.Add(ctx, &c.bridgeAddr, nil, big.NewInt(0), data, c.gasOffest, nil)
id, err := c.ethTxManager.Add(ctx, &c.bridgeAddr, big.NewInt(0), data, c.gasOffest, nil)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/0xPolygon/cdk-data-availability v0.0.9
github.com/0xPolygon/cdk-rpc v0.0.0-20240905074455-431d3c271fe8
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.6
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240716105056-c051c96d0234
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240930120324-65816dead447
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.1
github.com/ethereum/go-ethereum v1.14.8
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/0xPolygonHermez/zkevm-data-streamer v0.2.6 h1:BSO1uu6dmLQ5kKb3uyDvsUx
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.6/go.mod h1:RC6ouyNsUtJrv5aGPcM6Dm5xhXN209tRSzcsJsaOtZI=
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240716105056-c051c96d0234 h1:QElCysO7f2xaknY/RDjxcs7IVmcgORfsCX2g+YD0Ko4=
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240716105056-c051c96d0234/go.mod h1:zBZWxwOHKlw+ghd9roQLgIkDZWA7e7qO3EsfQQT/+oQ=
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240930120324-65816dead447 h1:8nZjZrHZo+P9hTkhwtQ4J6eh9v4MTMtVb9jRDra8h0s=
github.com/0xPolygonHermez/zkevm-ethtx-manager v0.1.10-0.20240930120324-65816dead447/go.mod h1:4iWpcwMOZJPapUzFB/HjTAM0X/gltHSEzQHE0lOt+eY=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.1 h1:8GbJBNsYO4zrqiBX++et8eQrJDEWEZuo3Ch3M416YnI=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.1/go.mod h1:96i+QSANfbikwlUY3U9MLNtg3656W3dWfbGqH+Od1/k=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down
9 changes: 7 additions & 2 deletions reorgdetector/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestBlockMap(t *testing.T) {
Expand Down Expand Up @@ -50,8 +51,12 @@ func TestBlockMap(t *testing.T) {
t.Parallel()

copiedBm := bm.copy()
if !reflect.DeepEqual(bm, copiedBm) {
t.Errorf("add() returned incorrect result, expected: %v, got: %v", bm, copiedBm)
for i, header := range bm.headers {
copiedHeader, exists := copiedBm.headers[i]
require.True(t, exists)
if !reflect.DeepEqual(header, copiedHeader) {
t.Errorf("copy() returned incorrect result, expected: %v, got: %v", header, copiedHeader)
}
}
})

Expand Down
19 changes: 1 addition & 18 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type SequenceSender struct {
logger *log.Logger
ethTxManager *ethtxmanager.Client
etherman *etherman.Client
currentNonce uint64
nonceMutex sync.Mutex
latestVirtualBatch uint64 // Latest virtualized batch obtained from L1
latestVirtualTime time.Time // Latest virtual batch timestamp
latestSentToL1Batch uint64 // Latest batch sent to L1
Expand Down Expand Up @@ -141,14 +139,6 @@ func (s *SequenceSender) Start(ctx context.Context) {

// Get current nonce
var err error
s.nonceMutex.Lock()
s.currentNonce, err = s.etherman.CurrentNonce(ctx, s.cfg.L2Coinbase)
if err != nil {
s.logger.Fatalf("failed to get current nonce from %v, error: %v", s.cfg.L2Coinbase, err)
} else {
s.logger.Infof("current nonce for %v is %d", s.cfg.L2Coinbase, s.currentNonce)
}
s.nonceMutex.Unlock()

// Get latest virtual state batch from L1
err = s.updateLatestVirtualBatch()
Expand Down Expand Up @@ -601,18 +591,12 @@ func (s *SequenceSender) sendTx(
) error {
// Params if new tx to send or resend a previous tx
var paramTo *common.Address
var paramNonce *uint64
var paramData []byte
var valueFromBatch uint64
var valueToBatch uint64
var valueToAddress common.Address

if !resend {
s.nonceMutex.Lock()
nonce := s.currentNonce
s.currentNonce++
s.nonceMutex.Unlock()
paramNonce = &nonce
paramTo = to
paramData = data
valueFromBatch = fromBatch
Expand All @@ -623,7 +607,6 @@ func (s *SequenceSender) sendTx(
return errors.New("resend tx with nil hash monitor id")
}
paramTo = &s.ethTransactions[*txOldHash].To
paramNonce = &s.ethTransactions[*txOldHash].Nonce
paramData = s.ethTxData[*txOldHash]
valueFromBatch = s.ethTransactions[*txOldHash].FromBatch
valueToBatch = s.ethTransactions[*txOldHash].ToBatch
Expand All @@ -633,7 +616,7 @@ func (s *SequenceSender) sendTx(
}

// Add sequence tx
txHash, err := s.ethTxManager.AddWithGas(ctx, paramTo, paramNonce, big.NewInt(0), paramData, s.cfg.GasOffset, nil, gas)
txHash, err := s.ethTxManager.AddWithGas(ctx, paramTo, big.NewInt(0), paramData, s.cfg.GasOffset, nil, gas)
if err != nil {
s.logger.Errorf("error adding sequence to ethtxmanager: %v", err)
return err
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/ethtxmanmock_e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func NewEthTxManMock(

const (
ArgToIndex = 1
ArgDataIndex = 4
ArgDataIndex = 3
ZeroValue = 0
)

ethTxMock := NewEthTxManagerMock(t)
ethTxMock.On(
"Add", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
"Add", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Run(func(args mock.Arguments) {
ctx := context.Background()
nonce, err := client.Client().PendingNonceAt(ctx, auth.From)
Expand Down
20 changes: 10 additions & 10 deletions test/helpers/mock_ethtxmanager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 473cc88

Please sign in to comment.