diff --git a/cmd/run.go b/cmd/run.go index 15d24c29..33a40a9b 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -163,15 +163,15 @@ func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuild switch contracts.VersionType(cfg.Common.ContractVersions) { case contracts.VersionBanana: if cfg.Common.IsValidiumMode { - txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1) + txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, cfg.SequenceSender.MaxBatchesForL1) } else { - txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1) + txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, cfg.SequenceSender.MaxTxSizeForL1) } case contracts.VersionElderberry: if cfg.Common.IsValidiumMode { - txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1) + txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, cfg.SequenceSender.MaxBatchesForL1) } else { - txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1) + txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, cfg.SequenceSender.MaxTxSizeForL1) } default: err = fmt.Errorf("unknown contract version: %s", cfg.Common.ContractVersions) diff --git a/sequencesender/sequencesender.go b/sequencesender/sequencesender.go index 961b6f75..941e6db6 100644 --- a/sequencesender/sequencesender.go +++ b/sequencesender/sequencesender.go @@ -520,7 +520,7 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) { log.Infof("[SeqSender] sending sequences to L1. From batch %d to batch %d", firstSequence.BatchNumber(), lastSequence.BatchNumber()) log.Infof(sequence.String()) - tx, err := s.TxBuilder.BuildSequenceBatchesTx(ctx, s.cfg.SenderAddress, sequence) + tx, err := s.TxBuilder.BuildSequenceBatchesTx(ctx, sequence) if err != nil { log.Errorf("[SeqSender] error building sequenceBatches tx: %v", err) return diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 60c6c4a7..6d36e33b 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -17,19 +17,16 @@ type TxBuilderBananaBase struct { rollupContract contracts.RollupBananaType globalExitRootContract contracts.GlobalExitRootBananaType - opts bind.TransactOpts - SenderAddress common.Address + opts bind.TransactOpts } func NewTxBuilderBananaBase(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, - opts bind.TransactOpts, - sender common.Address) *TxBuilderBananaBase { + opts bind.TransactOpts) *TxBuilderBananaBase { return &TxBuilderBananaBase{ rollupContract: rollupContract, globalExitRootContract: gerContract, opts: opts, - SenderAddress: sender, } } diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index e518d107..7abaae17 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -24,21 +24,19 @@ type TxBuilderBananaValidium struct { func NewTxBuilderBananaValidium(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, - da dataavailability.SequenceSender, opts bind.TransactOpts, sender common.Address, maxBatchesForL1 uint64) *TxBuilderBananaValidium { + da dataavailability.SequenceSender, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { return &TxBuilderBananaValidium{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), da: da, - condNewSeq: &ConditionalNewSequenceNumBatches{ - maxBatchesForL1: maxBatchesForL1, - }, + condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), } } func (t *TxBuilderBananaValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { // TODO: param sender // Post sequences to DA backend var dataAvailabilityMessage []byte @@ -56,7 +54,7 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se } // Build sequence data - tx, err := t.internalBuildSequenceBatchesTx(t.SenderAddress, ethseq, dataAvailabilityMessage) + tx, err := t.internalBuildSequenceBatchesTx(ethseq, dataAvailabilityMessage) if err != nil { log.Errorf("[SeqSender] error estimating new sequenceBatches to add to ethtxmanager: ", err) return nil, err @@ -65,7 +63,7 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se } // BuildSequenceBatchesTx builds a tx to be sent to the PoE SC method SequenceBatches. -func (t *TxBuilderBananaValidium) internalBuildSequenceBatchesTx(sender common.Address, sequence etherman.SequenceBanana, +func (t *TxBuilderBananaValidium) internalBuildSequenceBatchesTx(sequence etherman.SequenceBanana, dataAvailabilityMessage []byte) (*ethtypes.Transaction, error) { newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/banana_zkevm.go b/sequencesender/txbuilder/banana_zkevm.go index e2a2e1aa..28cdcdd2 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -19,20 +19,18 @@ type TxBuilderBananaZKEVM struct { condNewSeq CondNewSequence } -func NewTxBuilderBananaZKEVM(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, opts bind.TransactOpts, sender common.Address, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { +func NewTxBuilderBananaZKEVM(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { return &TxBuilderBananaZKEVM{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), - condNewSeq: &ConditionalNewSequenceMaxSize{ - maxTxSizeForL1: maxTxSizeForL1, - }, + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), + condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), } } func (t *TxBuilderBananaZKEVM) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { var err error ethseq, err := convertToSequenceBanana(sequences) if err != nil { diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index 2a223878..d6dde1d5 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -27,7 +27,7 @@ type TxBuilderElderberryValidium struct { func NewTxBuilderElderberryValidium(zkevm contracts.RollupElderberryType, da dataavailability.SequenceSenderElderberry, - opts bind.TransactOpts, sender common.Address, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { + opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { return &TxBuilderElderberryValidium{ da: da, TxBuilderElderberryBase: *NewTxBuilderElderberryBase( @@ -37,10 +37,10 @@ func NewTxBuilderElderberryValidium(zkevm contracts.RollupElderberryType, } } func (t *TxBuilderElderberryValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { if sequences == nil || sequences.Len() == 0 { return nil, fmt.Errorf("can't sequence an empty sequence") } diff --git a/sequencesender/txbuilder/elderberry_validium_test.go b/sequencesender/txbuilder/elderberry_validium_test.go index 68f5e303..a5bfb818 100644 --- a/sequencesender/txbuilder/elderberry_validium_test.go +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -30,12 +30,12 @@ func TestElderberryValidiumName(t *testing.T) { func TestElderberryValidiumBuildSequenceBatchesTxEmtpySequence(t *testing.T) { testData := newElderberryValidiumSUT(t) ctx := context.TODO() - _, err := testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, nil) + _, err := testData.sut.BuildSequenceBatchesTx(ctx, nil) require.Error(t, err) seq, err := testData.sut.NewSequence(nil, common.Address{}) require.NoError(t, err) - _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) } @@ -56,10 +56,10 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing seq, err := testData.sut.NewSequence(batches, common.Address{}) require.NoError(t, err) testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, nil) - _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err, "data availability message is nil") testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, fmt.Errorf("test error")) - _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err, "error posting sequences to the data availability protocol: test error") } @@ -80,7 +80,7 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { seq, err := testData.sut.NewSequence(batches, common.Address{}) require.NoError(t, err) testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return([]byte{1}, nil) - tx, err := testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + tx, err := testData.sut.BuildSequenceBatchesTx(ctx, seq) require.NoError(t, err) require.NotNil(t, tx) } @@ -97,10 +97,10 @@ func newElderberryValidiumSUT(t *testing.T) *testDataElderberryValidium { require.NoError(t, err) opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) require.NoError(t, err) - sender := common.Address{} + da := mocks_da.NewSequenceSenderElderberry(t) - sut := txbuilder.NewTxBuilderElderberryValidium(*zkevmContract, da, *opts, sender, uint64(100)) + sut := txbuilder.NewTxBuilderElderberryValidium(*zkevmContract, da, *opts, uint64(100)) require.NotNil(t, sut) return &testDataElderberryValidium{ mockDA: da, diff --git a/sequencesender/txbuilder/elderberry_zkevm.go b/sequencesender/txbuilder/elderberry_zkevm.go index 46df1f57..0db8b6e3 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -21,7 +21,7 @@ type TxBuilderElderberryZKEVM struct { condNewSeq CondNewSequence } -func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind.TransactOpts, sender common.Address, maxTxSizeForL1 uint64) *TxBuilderElderberryZKEVM { +func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderElderberryZKEVM { return &TxBuilderElderberryZKEVM{ TxBuilderElderberryBase: *NewTxBuilderElderberryBase( zkevm, opts, @@ -31,7 +31,7 @@ func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind } func (t *TxBuilderElderberryZKEVM) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } // SetCondNewSeq allow to override the default conditional for new sequence @@ -39,7 +39,7 @@ func (t *TxBuilderElderberryZKEVM) SetCondNewSeq(cond CondNewSequence) { t.condNewSeq = cond } -func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/elderberry_zkevm_test.go b/sequencesender/txbuilder/elderberry_zkevm_test.go index 6ae3b6eb..1819bbe2 100644 --- a/sequencesender/txbuilder/elderberry_zkevm_test.go +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -22,8 +22,7 @@ import ( func TestElderberryZkevmName(t *testing.T) { zkevmContract := contracts.RollupElderberryType{} opts := bind.TransactOpts{} - sender := common.Address{} - sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, sender, 100) + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, 100) require.NotNil(t, sut) require.True(t, strings.Contains(sut.String(), "Elderberry")) require.True(t, strings.Contains(sut.String(), "ZKEVM")) @@ -32,8 +31,7 @@ func TestElderberryZkevmName(t *testing.T) { func TestElderberryZkevmNewSequence(t *testing.T) { zkevmContract := contracts.RollupElderberryType{} opts := bind.TransactOpts{} - sender := common.Address{} - sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, sender, 100) + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, 100) require.NotNil(t, sut) seq, err := sut.NewSequence(nil, common.Address{}) require.NoError(t, err) @@ -43,12 +41,12 @@ func TestElderberryZkevmNewSequence(t *testing.T) { func TestElderberryZkevmBuildSequenceBatchesTxEmtpySequence(t *testing.T) { sut := newElderberryZkevmSUT(t) ctx := context.TODO() - _, err := sut.BuildSequenceBatchesTx(ctx, common.Address{}, nil) + _, err := sut.BuildSequenceBatchesTx(ctx, nil) require.Error(t, err) seq, err := sut.NewSequence(nil, common.Address{}) require.NoError(t, err) - _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) } @@ -68,7 +66,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1Batch(t *testing.T) { } seq, err := sut.NewSequence(batches, common.Address{}) require.NoError(t, err) - _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.NoError(t, err) } @@ -90,7 +88,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1BatchError(t *testing.T) } seq, err := sut.NewSequence(batches, common.Address{}) require.NoError(t, err) - _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) } @@ -99,7 +97,7 @@ func TestElderberryZkevmNewSequenceIfWorthToSend(t *testing.T) { mockCond := mocks_txbuilder.NewCondNewSequence(t) sut.SetCondNewSeq(mockCond) // Returns that is not work to be send - mockCond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) + mockCond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) seq, err := sut.NewSequenceIfWorthToSend(context.TODO(), nil, common.Address{}, 0) require.NoError(t, err) require.Nil(t, seq) @@ -112,8 +110,7 @@ func newElderberryZkevmSUT(t *testing.T) *txbuilder.TxBuilderElderberryZKEVM { require.NoError(t, err) opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) require.NoError(t, err) - sender := common.Address{} - sut := txbuilder.NewTxBuilderElderberryZKEVM(*zkevmContract, *opts, sender, 100) + sut := txbuilder.NewTxBuilderElderberryZKEVM(*zkevmContract, *opts, 100) require.NotNil(t, sut) return sut } diff --git a/sequencesender/txbuilder/interface.go b/sequencesender/txbuilder/interface.go index ea6e8770..ddcd5105 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -10,7 +10,7 @@ import ( ) type TxBuilder interface { - BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) + BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch @@ -19,5 +19,5 @@ type TxBuilder interface { type CondNewSequence interface { //NewSequenceIfWorthToSend Return nil, nil if the sequence is not worth sending - NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) + NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) } diff --git a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go index 2600af02..ae818ce9 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go +++ b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go @@ -27,9 +27,9 @@ func (_m *CondNewSequence) EXPECT() *CondNewSequence_Expecter { return &CondNewSequence_Expecter{mock: &_m.Mock} } -// NewSequenceIfWorthToSend provides a mock function with given fields: ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase -func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress common.Address, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { - ret := _m.Called(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) +// NewSequenceIfWorthToSend provides a mock function with given fields: ctx, txBuilder, sequenceBatches, l2Coinbase +func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { + ret := _m.Called(ctx, txBuilder, sequenceBatches, l2Coinbase) if len(ret) == 0 { panic("no return value specified for NewSequenceIfWorthToSend") @@ -37,19 +37,19 @@ func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuild var r0 seqsendertypes.Sequence var r1 error - if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) (seqsendertypes.Sequence, error)); ok { - return rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)); ok { + return rf(ctx, txBuilder, sequenceBatches, l2Coinbase) } - if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) seqsendertypes.Sequence); ok { - r0 = rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) seqsendertypes.Sequence); ok { + r0 = rf(ctx, txBuilder, sequenceBatches, l2Coinbase) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(seqsendertypes.Sequence) } } - if rf, ok := ret.Get(1).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) error); ok { - r1 = rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + if rf, ok := ret.Get(1).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) error); ok { + r1 = rf(ctx, txBuilder, sequenceBatches, l2Coinbase) } else { r1 = ret.Error(1) } @@ -66,15 +66,14 @@ type CondNewSequence_NewSequenceIfWorthToSend_Call struct { // - ctx context.Context // - txBuilder txbuilder.TxBuilder // - sequenceBatches []seqsendertypes.Batch -// - senderAddress common.Address // - l2Coinbase common.Address -func (_e *CondNewSequence_Expecter) NewSequenceIfWorthToSend(ctx interface{}, txBuilder interface{}, sequenceBatches interface{}, senderAddress interface{}, l2Coinbase interface{}) *CondNewSequence_NewSequenceIfWorthToSend_Call { - return &CondNewSequence_NewSequenceIfWorthToSend_Call{Call: _e.mock.On("NewSequenceIfWorthToSend", ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase)} +func (_e *CondNewSequence_Expecter) NewSequenceIfWorthToSend(ctx interface{}, txBuilder interface{}, sequenceBatches interface{}, l2Coinbase interface{}) *CondNewSequence_NewSequenceIfWorthToSend_Call { + return &CondNewSequence_NewSequenceIfWorthToSend_Call{Call: _e.mock.On("NewSequenceIfWorthToSend", ctx, txBuilder, sequenceBatches, l2Coinbase)} } -func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Run(run func(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress common.Address, l2Coinbase common.Address)) *CondNewSequence_NewSequenceIfWorthToSend_Call { +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Run(run func(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address)) *CondNewSequence_NewSequenceIfWorthToSend_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(txbuilder.TxBuilder), args[2].([]seqsendertypes.Batch), args[3].(common.Address), args[4].(common.Address)) + run(args[0].(context.Context), args[1].(txbuilder.TxBuilder), args[2].([]seqsendertypes.Batch), args[3].(common.Address)) }) return _c } @@ -84,7 +83,7 @@ func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Return(_a0 seqsendertyp return _c } -func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) (seqsendertypes.Sequence, error)) *CondNewSequence_NewSequenceIfWorthToSend_Call { +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)) *CondNewSequence_NewSequenceIfWorthToSend_Call { _c.Call.Return(run) return _c } diff --git a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go index e9aa9127..4b713efa 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go +++ b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go @@ -29,9 +29,9 @@ func (_m *TxBuilder) EXPECT() *TxBuilder_Expecter { return &TxBuilder_Expecter{mock: &_m.Mock} } -// BuildSequenceBatchesTx provides a mock function with given fields: ctx, sender, sequences -func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*types.Transaction, error) { - ret := _m.Called(ctx, sender, sequences) +// BuildSequenceBatchesTx provides a mock function with given fields: ctx, sequences +func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*types.Transaction, error) { + ret := _m.Called(ctx, sequences) if len(ret) == 0 { panic("no return value specified for BuildSequenceBatchesTx") @@ -39,19 +39,19 @@ func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sender common.A var r0 *types.Transaction var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Address, seqsendertypes.Sequence) (*types.Transaction, error)); ok { - return rf(ctx, sender, sequences) + if rf, ok := ret.Get(0).(func(context.Context, seqsendertypes.Sequence) (*types.Transaction, error)); ok { + return rf(ctx, sequences) } - if rf, ok := ret.Get(0).(func(context.Context, common.Address, seqsendertypes.Sequence) *types.Transaction); ok { - r0 = rf(ctx, sender, sequences) + if rf, ok := ret.Get(0).(func(context.Context, seqsendertypes.Sequence) *types.Transaction); ok { + r0 = rf(ctx, sequences) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*types.Transaction) } } - if rf, ok := ret.Get(1).(func(context.Context, common.Address, seqsendertypes.Sequence) error); ok { - r1 = rf(ctx, sender, sequences) + if rf, ok := ret.Get(1).(func(context.Context, seqsendertypes.Sequence) error); ok { + r1 = rf(ctx, sequences) } else { r1 = ret.Error(1) } @@ -66,15 +66,14 @@ type TxBuilder_BuildSequenceBatchesTx_Call struct { // BuildSequenceBatchesTx is a helper method to define mock.On call // - ctx context.Context -// - sender common.Address // - sequences seqsendertypes.Sequence -func (_e *TxBuilder_Expecter) BuildSequenceBatchesTx(ctx interface{}, sender interface{}, sequences interface{}) *TxBuilder_BuildSequenceBatchesTx_Call { - return &TxBuilder_BuildSequenceBatchesTx_Call{Call: _e.mock.On("BuildSequenceBatchesTx", ctx, sender, sequences)} +func (_e *TxBuilder_Expecter) BuildSequenceBatchesTx(ctx interface{}, sequences interface{}) *TxBuilder_BuildSequenceBatchesTx_Call { + return &TxBuilder_BuildSequenceBatchesTx_Call{Call: _e.mock.On("BuildSequenceBatchesTx", ctx, sequences)} } -func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Run(run func(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence)) *TxBuilder_BuildSequenceBatchesTx_Call { +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Run(run func(ctx context.Context, sequences seqsendertypes.Sequence)) *TxBuilder_BuildSequenceBatchesTx_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.Address), args[2].(seqsendertypes.Sequence)) + run(args[0].(context.Context), args[1].(seqsendertypes.Sequence)) }) return _c } @@ -84,7 +83,7 @@ func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Return(_a0 *types.Transaction, return _c } -func (_c *TxBuilder_BuildSequenceBatchesTx_Call) RunAndReturn(run func(context.Context, common.Address, seqsendertypes.Sequence) (*types.Transaction, error)) *TxBuilder_BuildSequenceBatchesTx_Call { +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) RunAndReturn(run func(context.Context, seqsendertypes.Sequence) (*types.Transaction, error)) *TxBuilder_BuildSequenceBatchesTx_Call { _c.Call.Return(run) return _c } diff --git a/sequencesender/txbuilder/validium_cond_num_batches.go b/sequencesender/txbuilder/validium_cond_num_batches.go index 66c7c905..1b85582b 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -18,7 +18,7 @@ func NewConditionalNewSequenceNumBatches(maxBatchesForL1 uint64) *ConditionalNew } } -func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { +func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { if c.maxBatchesForL1 > 0 && len(sequenceBatches) >= int(c.maxBatchesForL1) { log.Infof( "[SeqSender] sequence should be sent to L1, because MaxBatchesForL1 (%d) has been reached", diff --git a/sequencesender/txbuilder/validium_cond_num_batches_test.go b/sequencesender/txbuilder/validium_cond_num_batches_test.go index 5375b4fd..c449f161 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches_test.go +++ b/sequencesender/txbuilder/validium_cond_num_batches_test.go @@ -15,7 +15,7 @@ func TestConditionalNumBatchesDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) sut := txbuilder.NewConditionalNewSequenceNumBatches(0) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -26,7 +26,7 @@ func TestConditionalNumBatchesDontFulfillCondition(t *testing.T) { sut := txbuilder.NewConditionalNewSequenceNumBatches(2) var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -39,7 +39,7 @@ func TestConditionalNumBatchesFulfillCondition(t *testing.T) { sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) mockTxBuilder.EXPECT().NewSequence(mock.Anything, mock.Anything).Return(nil, nil) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } diff --git a/sequencesender/txbuilder/zkevm_cond_max_size.go b/sequencesender/txbuilder/zkevm_cond_max_size.go index 5280b71f..805014fe 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size.go @@ -26,7 +26,7 @@ func NewConditionalNewSequenceMaxSize(maxTxSizeForL1 uint64) *ConditionalNewSequ } } -func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { +func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { if c.maxTxSizeForL1 == 0 { log.Debug("maxTxSizeForL1 is 0, so is disabled") return nil, nil @@ -42,7 +42,7 @@ func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Con } // Check if can be sent - tx, err := txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) + tx, err := txBuilder.BuildSequenceBatchesTx(ctx, sequence) if tx == nil && err == nil { err = fmt.Errorf("error txBuilder.BuildSequenceBatchesTx, returns tx=nil and err==nil, is not expected") log.Errorf(err.Error()) @@ -64,7 +64,7 @@ func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Con return nil, err } - txReduced, err := txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) + txReduced, err := txBuilder.BuildSequenceBatchesTx(ctx, sequence) log.Debugf("After reducing batches: (txSize %d -> %d)", tx.Size(), txReduced.Size()) if err == nil && txReduced != nil && txReduced.Size() > c.maxTxSizeForL1 { log.Warnf("After reducing batches: (txSize %d -> %d) is still too big > %d", tx.Size(), txReduced.Size(), c.maxTxSizeForL1) diff --git a/sequencesender/txbuilder/zkevm_cond_max_size_test.go b/sequencesender/txbuilder/zkevm_cond_max_size_test.go index 0f87e78c..a65cdc44 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size_test.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size_test.go @@ -18,7 +18,7 @@ func TestConditionalMaxSizeDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) sut := txbuilder.NewConditionalNewSequenceMaxSize(0) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -29,7 +29,7 @@ func TestConditionalMaxSizeTxBuilderNewSequenceReturnsNil(t *testing.T) { var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(nil, nil) - _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.Error(t, err) } @@ -40,8 +40,8 @@ func TestConditionalMaxSizeTxBuilderBuildSequenceBatchesTxReturnsNil(t *testing. sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) seq := &txbuilder.ElderberrySequence{} mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) - _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything).Return(nil, nil) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.Error(t, err) } @@ -54,9 +54,9 @@ func TestConditionalMaxSizeTxBuilderDontFulFill(t *testing.T) { mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) inner := ðtypes.LegacyTx{} tx := ethtypes.NewTx(inner) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything, mock.Anything).Return(tx, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything).Return(tx, nil) - res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, res) @@ -74,13 +74,13 @@ func TestConditionalMaxSizeTxBuilderFulFill(t *testing.T) { Data: []byte{0x01, 0x02, 0x03, 0x04}, } tx := ethtypes.NewTx(inner) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, mock.Anything, newSeq).Return(tx, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, newSeq).Return(tx, nil) // The size of result Tx is 14 that is > 10, so it reduce 1 batch newSeqReduced := newTestSeq(2, 100, l2coinbase) mockTxBuilder.EXPECT().NewSequence(newSeqReduced.Batches(), l2coinbase).Return(newSeqReduced, nil) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, mock.Anything, newSeqReduced).Return(tx, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, newSeqReduced).Return(tx, nil) - res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), common.Address{}, l2coinbase) + res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), l2coinbase) require.NoError(t, err) require.NotNil(t, res)