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

elderberry seq-sender #3312

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func TestForcedBatchEvent(t *testing.T) {
assert.Equal(t, auth.From, blocks[0].ForcedBatches[0].Sequencer)
}

// TODO: Review tests with Joan

/*
func TestSequencedBatchesEvent(t *testing.T) {
// Set up testing environment
etherman, ethBackend, auth, _, br := newTestingEnv()
Expand Down Expand Up @@ -162,6 +165,7 @@ func TestSequencedBatchesEvent(t *testing.T) {
}, polygonzkevm.PolygonRollupBaseEtrogBatchData{
Transactions: common.Hex2Bytes(rawTxs),
})

_, err = etherman.ZkEVM.SequenceBatches(auth, sequences, auth.From)
require.NoError(t, err)

Expand Down Expand Up @@ -228,6 +232,7 @@ func TestVerifyBatchEvent(t *testing.T) {
assert.Equal(t, 0, order[blocks[1].BlockHash][0].Pos)
assert.Equal(t, 0, order[blocks[1].BlockHash][1].Pos)
}
*/

func TestSequenceForceBatchesEvent(t *testing.T) {
// Set up testing environment
Expand Down Expand Up @@ -310,9 +315,12 @@ func TestSendSequences(t *testing.T) {
batchL2Data, err := state.EncodeTransactions([]types.Transaction{*tx1}, constants.EffectivePercentage, forkID6)
require.NoError(t, err)
sequence := ethmanTypes.Sequence{
BatchNumber: 0,
BatchL2Data: batchL2Data,
Timestamp: time.Now().Unix(),
}
tx, err := etherman.sequenceBatches(*auth, []ethmanTypes.Sequence{sequence}, auth.From)

tx, err := etherman.sequenceBatches(*auth, []ethmanTypes.Sequence{sequence}, uint64(sequence.Timestamp), sequence.BatchNumber, auth.From)
require.NoError(t, err)
log.Debug("TX: ", tx.Hash())
ethBackend.Commit()
Expand Down
1 change: 1 addition & 0 deletions etherman/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type GlobalExitRoot struct {
PreviousBlockHash common.Hash
}

// SequencedBatchElderberryData represents an Elderberry sequenced batch data
type SequencedBatchElderberryData struct {
MaxSequenceTimestamp uint64
InitSequencedBatchNumber uint64
Expand Down
40 changes: 20 additions & 20 deletions sequencesender/mock_etherman.go

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

29 changes: 24 additions & 5 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) {
}

// add sequence to be monitored
to, data, err := s.etherman.BuildSequenceBatchesTxData(s.cfg.SenderAddress, sequences, s.cfg.L2Coinbase)
firstSequence := sequences[0]
lastSequence := sequences[len(sequences)-1]

to, data, err := s.etherman.BuildSequenceBatchesTxData(s.cfg.SenderAddress, sequences, uint64(lastSequence.Timestamp), firstSequence.BatchNumber, 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, s.cfg.SenderAddress, to, nil, data, s.cfg.GasOffset, nil)
if err != nil {
Expand Down Expand Up @@ -286,11 +288,28 @@ func (s *SequenceSender) getSequencesToSend(ctx context.Context) ([]types.Sequen
seq.GlobalExitRoot = forcedBatch.GlobalExitRoot
seq.ForcedBatchTimestamp = forcedBatch.ForcedAt.Unix()
seq.PrevBlockHash = fbL1Block.ParentHash
// Set sequence timestamps as the forced batch timestamp
seq.Timestamp = seq.ForcedBatchTimestamp
} else {
// Set sequence timestamps as the latest l2 block timestamp
l2Blocks, err := s.state.GetL2BlocksByBatchNumber(ctx, currentBatchNumToSequence, nil)
if err != nil {
return nil, err
}
if len(l2Blocks) == 0 {
return nil, fmt.Errorf("no L2 blocks returned from the state for batch %d", currentBatchNumToSequence)
}

// Get timestamp of the last L2 block in the sequence
lastL2Block := l2Blocks[len(l2Blocks)-1]
seq.Timestamp = lastL2Block.ReceivedAt.Unix()
}

sequences = append(sequences, seq)
// Check if can be send
tx, err = s.etherman.EstimateGasSequenceBatches(s.cfg.SenderAddress, sequences, s.cfg.L2Coinbase)
firstSequence := sequences[0]
lastSequence := sequences[len(sequences)-1]
tx, err = s.etherman.EstimateGasSequenceBatches(s.cfg.SenderAddress, sequences, uint64(lastSequence.Timestamp), firstSequence.BatchNumber, s.cfg.L2Coinbase)
if err == nil && tx.Size() > s.cfg.MaxTxSizeForL1 {
metrics.SequencesOvesizedDataError()
log.Infof("oversized Data on TX oldHash %s (txSize %d > %d)", tx.Hash(), tx.Size(), s.cfg.MaxTxSizeForL1)
Expand All @@ -301,7 +320,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(s.cfg.SenderAddress, sequences, s.cfg.L2Coinbase)
_, err = s.etherman.EstimateGasSequenceBatches(s.cfg.SenderAddress, sequences, uint64(lastSequence.Timestamp), firstSequence.BatchNumber, s.cfg.L2Coinbase)
return sequences, err
}
return sequences, err
Expand Down
2 changes: 1 addition & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ services:

zkevm-mock-l1-network:
container_name: zkevm-mock-l1-network
image: hermeznetwork/geth-zkevm-contracts:v2.1.1-fork.7-geth1.12.0
image: hermeznetwork/geth-zkevm-contracts:v2.1.2-fork.8-geth1.12.0
ports:
- 8545:8545
- 8546:8546
Expand Down
5 changes: 4 additions & 1 deletion test/scripts/batchsender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ func sendBatches(cliCtx *cli.Context) error {
for i := 0; i < nb; i++ {
// empty rollup
seqs = append(seqs, ethmanTypes.Sequence{
BatchNumber: uint64(i),
GlobalExitRoot: common.HexToHash("0x"),
BatchL2Data: []byte{},
Timestamp: int64(currentBlock.Time() - 1), // fit in latest-sequence < > current-block rage
})
}

// send to L1
to, data, err := ethMan.BuildSequenceBatchesTxData(auth.From, seqs, auth.From)
firstSequence := seqs[0]
lastSequence := seqs[len(seqs)-1]
to, data, err := ethMan.BuildSequenceBatchesTxData(auth.From, seqs, uint64(lastSequence.Timestamp), firstSequence.BatchNumber, auth.From)
if err != nil {
return err
}
Expand Down
Loading