Skip to content

Commit

Permalink
removed sender from txbuilder because is already in opts (auth)
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Jul 30, 2024
1 parent 069ef90 commit 9c0aaa2
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 98 deletions.
8 changes: 4 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions sequencesender/txbuilder/banana_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

}
Expand Down
16 changes: 7 additions & 9 deletions sequencesender/txbuilder/banana_validium.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions sequencesender/txbuilder/banana_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions sequencesender/txbuilder/elderberry_validium.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
}
Expand Down
14 changes: 7 additions & 7 deletions sequencesender/txbuilder/elderberry_validium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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")
}

Expand All @@ -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)
}
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions sequencesender/txbuilder/elderberry_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,15 +31,15 @@ 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
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

Expand Down
19 changes: 8 additions & 11 deletions sequencesender/txbuilder/elderberry_zkevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions sequencesender/txbuilder/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Loading

0 comments on commit 9c0aaa2

Please sign in to comment.