Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Closed
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
9 changes: 4 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,11 @@ func createSequenceSender(cfg config.Config, pool *pool.Pool, etmStorage *ethtxm
log.Fatal(err)
}

for _, privateKey := range cfg.SequenceSender.PrivateKeys {
_, err := etherman.LoadAuthFromKeyStore(privateKey.Path, privateKey.Password)
if err != nil {
log.Fatal(err)
}
auth, err := etherman.LoadAuthFromKeyStore(cfg.SequenceSender.PrivateKey.Path, cfg.SequenceSender.PrivateKey.Password)
if err != nil {
log.Fatal(err)
}
cfg.SequenceSender.SenderAddress = auth.From

ethTxManager := ethtxmanager.New(cfg.EthTxManager, etherman, etmStorage, st)

Expand Down
4 changes: 2 additions & 2 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ MaxTxLifetime = "3h"
WaitPeriodSendSequence = "5s"
LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
MaxTxSizeForL1 = 131072
SenderAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKeys = [{Path = "/pk/sequencer.keystore", Password = "testonly"}]
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKey = {Path = "/pk/sequencer.keystore", Password = "testonly"}

[PriceGetter]
Type = "default"
Expand Down
4 changes: 2 additions & 2 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ MaxTxLifetime = "3h"
WaitPeriodSendSequence = "5s"
LastBatchVirtualizationTimeMaxWaitPeriod = "5s"
MaxTxSizeForL1 = 131072
SenderAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKeys = [{Path = "/pk/sequencer.keystore", Password = "testonly"}]
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKey = {Path = "/pk/sequencer.keystore", Password = "testonly"}

[Aggregator]
Host = "0.0.0.0"
Expand Down
12 changes: 6 additions & 6 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,14 @@ func (etherMan *Client) WaitTxToBeMined(ctx context.Context, tx *types.Transacti
}

// EstimateGasSequenceBatches estimates gas for sending batches
func (etherMan *Client) EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence) (*types.Transaction, error) {
func (etherMan *Client) EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (*types.Transaction, error) {
opts, err := etherMan.getAuthByAddress(sender)
if err == ErrNotFound {
return nil, ErrPrivateKeyNotFound
}
opts.NoSend = true

tx, err := etherMan.sequenceBatches(opts, sequences)
tx, err := etherMan.sequenceBatches(opts, sequences, l2Coinbase)
if err != nil {
return nil, err
}
Expand All @@ -485,7 +485,7 @@ func (etherMan *Client) EstimateGasSequenceBatches(sender common.Address, sequen
}

// BuildSequenceBatchesTxData builds a []bytes to be sent to the PoE SC method SequenceBatches.
func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence) (to *common.Address, data []byte, err error) {
func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (to *common.Address, data []byte, err error) {
opts, err := etherMan.getAuthByAddress(sender)
if err == ErrNotFound {
return nil, nil, fmt.Errorf("failed to build sequence batches, err: %w", ErrPrivateKeyNotFound)
Expand All @@ -496,15 +496,15 @@ func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequen
opts.GasLimit = uint64(1)
opts.GasPrice = big.NewInt(1)

tx, err := etherMan.sequenceBatches(opts, sequences)
tx, err := etherMan.sequenceBatches(opts, sequences, l2Coinbase)
if err != nil {
return nil, nil, err
}

return tx.To(), tx.Data(), nil
}

func (etherMan *Client) sequenceBatches(opts bind.TransactOpts, sequences []ethmanTypes.Sequence) (*types.Transaction, error) {
func (etherMan *Client) sequenceBatches(opts bind.TransactOpts, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (*types.Transaction, error) {
var batches []polygonzkevm.PolygonZkEVMBatchData
for _, seq := range sequences {
batch := polygonzkevm.PolygonZkEVMBatchData{
Expand All @@ -517,7 +517,7 @@ func (etherMan *Client) sequenceBatches(opts bind.TransactOpts, sequences []ethm
batches = append(batches, batch)
}

tx, err := etherMan.ZkEVM.SequenceBatches(&opts, batches, opts.From)
tx, err := etherMan.ZkEVM.SequenceBatches(&opts, batches, l2Coinbase)
if err != nil {
if parsedErr, ok := tryParseError(err); ok {
err = parsedErr
Expand Down
2 changes: 1 addition & 1 deletion etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func TestSendSequences(t *testing.T) {
Timestamp: int64(currentBlock.Time() - 1),
BatchL2Data: batchL2Data,
}
tx, err := etherman.sequenceBatches(*auth, []ethmanTypes.Sequence{sequence})
tx, err := etherman.sequenceBatches(*auth, []ethmanTypes.Sequence{sequence}, auth.From)
require.NoError(t, err)
log.Debug("TX: ", tx.Hash())
ethBackend.Commit()
Expand Down
4 changes: 2 additions & 2 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type txPool interface {

// etherman contains the methods required to interact with ethereum.
type etherman interface {
EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence) (*types.Transaction, error)
EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (*types.Transaction, error)
GetSendSequenceFee(numBatches uint64) (*big.Int, error)
TrustedSequencer() (common.Address, error)
GetLatestBatchNumber() (uint64, error)
GetLastBatchTimestamp() (uint64, error)
GetLatestBlockTimestamp(ctx context.Context) (uint64, error)
BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence) (to *common.Address, data []byte, err error)
BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (to *common.Address, data []byte, err error)
GetLatestBlockNumber(ctx context.Context) (uint64, error)
}

Expand Down
4 changes: 2 additions & 2 deletions sequencer/mock_etherman.go

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

9 changes: 6 additions & 3 deletions sequencesender/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sequencesender

import (
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/ethereum/go-ethereum/common"
)

// Config represents the configuration of a sequence sender
Expand All @@ -18,8 +19,10 @@ type Config struct {
MaxTxSizeForL1 uint64 `mapstructure:"MaxTxSizeForL1"`
// SenderAddress defines which private key the eth tx manager needs to use
// to sign the L1 txs
SenderAddress string `mapstructure:"SenderAddress"`
// PrivateKeys defines all the key store files that are going
SenderAddress common.Address
// L2Coinbase defines which addess is going to receive the fees
L2Coinbase common.Address `mapstructure:"L2Coinbase"`
// PrivateKey defines all the key store files that are going
// to be read in order to provide the private keys to sign the L1 txs
PrivateKeys []types.KeystoreFileConfig `mapstructure:"PrivateKeys"`
PrivateKey types.KeystoreFileConfig `mapstructure:"PrivateKey"`
}
4 changes: 2 additions & 2 deletions sequencesender/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

// etherman contains the methods required to interact with ethereum.
type etherman interface {
BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence) (to *common.Address, data []byte, err error)
EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence) (*types.Transaction, error)
BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (to *common.Address, data []byte, err error)
EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence, l2Coinbase common.Address) (*types.Transaction, error)
GetLastBatchTimestamp() (uint64, error)
GetLatestBlockTimestamp(ctx context.Context) (uint64, error)
GetLatestBatchNumber() (uint64, error)
Expand Down
11 changes: 4 additions & 7 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/sequencer/metrics"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/jackc/pgx/v4"
)
Expand Down Expand Up @@ -108,16 +107,15 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context, ticker *time.Tic
metrics.SequencesSentToL1(float64(sequenceCount))

// add sequence to be monitored
sender := common.HexToAddress(s.cfg.SenderAddress)
to, data, err := s.etherman.BuildSequenceBatchesTxData(sender, sequences)
to, data, err := s.etherman.BuildSequenceBatchesTxData(s.cfg.SenderAddress, sequences, s.cfg.L2Coinbase)
if err != nil {
log.Error("error estimating new sequenceBatches to add to eth tx manager: ", err)
return
}
firstSequence := sequences[0]
lastSequence := sequences[len(sequences)-1]
monitoredTxID := fmt.Sprintf(monitoredIDFormat, firstSequence.BatchNumber, lastSequence.BatchNumber)
err = s.ethTxManager.Add(ctx, ethTxManagerOwner, monitoredTxID, sender, to, nil, data, nil)
err = s.ethTxManager.Add(ctx, ethTxManagerOwner, monitoredTxID, s.cfg.SenderAddress, to, nil, data, nil)
if err != nil {
log.Error("error to add sequences tx to eth tx manager: ", err)
return
Expand Down Expand Up @@ -173,8 +171,7 @@ func (s *SequenceSender) getSequencesToSend(ctx context.Context) ([]types.Sequen

sequences = append(sequences, seq)
// Check if can be send
sender := common.HexToAddress(s.cfg.SenderAddress)
tx, err = s.etherman.EstimateGasSequenceBatches(sender, sequences)
tx, err = s.etherman.EstimateGasSequenceBatches(s.cfg.SenderAddress, sequences, s.cfg.L2Coinbase)
if err == nil && tx.Size() > s.cfg.MaxTxSizeForL1 {
metrics.SequencesOvesizedDataError()
log.Infof("oversized Data on TX oldHash %s (txSize %d > 128KB)", tx.Hash(), tx.Size())
Expand All @@ -185,7 +182,7 @@ func (s *SequenceSender) getSequencesToSend(ctx context.Context) ([]types.Sequen
sequences, err = s.handleEstimateGasSendSequenceErr(ctx, sequences, currentBatchNumToSequence, err)
if sequences != nil {
// Handling the error gracefully, re-processing the sequence as a sanity check
_, err = s.etherman.EstimateGasSequenceBatches(sender, sequences)
_, err = s.etherman.EstimateGasSequenceBatches(s.cfg.SenderAddress, sequences, s.cfg.L2Coinbase)
return sequences, err
}
return sequences, err
Expand Down
4 changes: 2 additions & 2 deletions test/config/debug.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ MaxTxLifetime = "3h"
WaitPeriodSendSequence = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "10s"
MaxTxSizeForL1 = 131072
SenderAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKeys = [{Path = "./test/sequencer.keystore", Password = "testonly"}]
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKey = {Path = "./test/sequencer.keystore", Password = "testonly"}

[Aggregator]
Host = "0.0.0.0"
Expand Down
4 changes: 2 additions & 2 deletions test/config/test.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ MaxTxLifetime = "3h"
WaitPeriodSendSequence = "15s"
LastBatchVirtualizationTimeMaxWaitPeriod = "10s"
MaxTxSizeForL1 = 131072
SenderAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKeys = [{Path = "/pk/sequencer.keystore", Password = "testonly"}]
L2Coinbase = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
PrivateKey = {Path = "/pk/sequencer.keystore", Password = "testonly"}

[Aggregator]
Host = "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/batchsender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func sendBatches(cliCtx *cli.Context) error {
}

// send to L1
to, data, err := ethMan.BuildSequenceBatchesTxData(auth.From, seqs)
to, data, err := ethMan.BuildSequenceBatchesTxData(auth.From, seqs, auth.From)
if err != nil {
return err
}
Expand Down