Skip to content

Commit

Permalink
feat: update with PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Sep 20, 2024
1 parent 722da75 commit 84c4282
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
12 changes: 6 additions & 6 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (s *SequenceSender) purgeSequences() {

// Purge the information of batches that are already virtualized
s.mutexSequence.Lock()
defer s.mutexSequence.Unlock()
truncateUntil := 0
toPurge := make([]uint64, 0)
for i := 0; i < len(s.sequenceList); i++ {
Expand All @@ -240,7 +241,6 @@ func (s *SequenceSender) purgeSequences() {
}
s.logger.Infof("batches purged count: %d, fromBatch: %d, toBatch: %d", len(toPurge), firstPurged, lastPurged)
}
s.mutexSequence.Unlock()
}

// purgeEthTx purges transactions from memory structures
Expand All @@ -252,6 +252,7 @@ func (s *SequenceSender) purgeEthTx(ctx context.Context) {

// Purge old transactions that are finalized
s.mutexEthTx.Lock()
defer s.mutexEthTx.Unlock()
timePurge := time.Now().Add(-s.cfg.WaitPeriodPurgeTxFile.Duration)
toPurge := make([]common.Hash, 0)
for hash, data := range s.ethTransactions {
Expand Down Expand Up @@ -289,7 +290,6 @@ func (s *SequenceSender) purgeEthTx(ctx context.Context) {
}
s.logger.Infof("txs purged count: %d, fromNonce: %d, toNonce: %d", len(toPurge), firstPurged, lastPurged)
}
s.mutexEthTx.Unlock()
}

// syncEthTxResults syncs results from L1 for transactions in the memory structure
Expand Down Expand Up @@ -1168,6 +1168,7 @@ func (s *SequenceSender) addInfoSequenceBatchEnd(batch *datastream.BatchEnd) {
// addNewBatchL2Block adds a new L2 block to the work in progress batch
func (s *SequenceSender) addNewBatchL2Block(l2Block *datastream.L2Block) {
s.mutexSequence.Lock()
defer s.mutexSequence.Unlock()
s.logger.Infof(".....new L2 block, number %d (batch %d) l1infotree %d",
l2Block.Number, l2Block.BatchNumber, l2Block.L1InfotreeIndex)

Expand All @@ -1187,7 +1188,8 @@ func (s *SequenceSender) addNewBatchL2Block(l2Block *datastream.L2Block) {
if l2Block.L1InfotreeIndex != 0 {
data.batch.SetL1InfoTreeIndex(l2Block.L1InfotreeIndex)
} else {
s.logger.Warnf("L1InfotreeIndex is 0, we don't change batch L1InfotreeIndex (%d)", data.batch.L1InfoTreeIndex())
s.logger.Warnf("L2 Block L1InfotreeIndex is 0, we don't change batch L1InfotreeIndex (%d)",
data.batch.L1InfoTreeIndex())
}
// New L2 block raw
newBlockRaw := state.L2BlockRaw{}
Expand All @@ -1205,13 +1207,12 @@ func (s *SequenceSender) addNewBatchL2Block(l2Block *datastream.L2Block) {
blockRaw.DeltaTimestamp = l2Block.DeltaTimestamp
blockRaw.IndexL1InfoTree = l2Block.L1InfotreeIndex
}

s.mutexSequence.Unlock()
}

// addNewBlockTx adds a new Tx to the current L2 block
func (s *SequenceSender) addNewBlockTx(l2Tx *datastream.Transaction) {
s.mutexSequence.Lock()
defer s.mutexSequence.Unlock()
s.logger.Debugf("........new tx, length %d EGP %d SR %x..",
len(l2Tx.Encoded), l2Tx.EffectiveGasPricePercentage, l2Tx.ImStateRoot[:8],
)
Expand All @@ -1234,7 +1235,6 @@ func (s *SequenceSender) addNewBlockTx(l2Tx *datastream.Transaction) {

// Add Tx
blockRaw.Transactions = append(blockRaw.Transactions, l2TxRaw)
s.mutexSequence.Unlock()
}

// getWipL2Block returns index of the array and pointer to the current L2 block (helper func)
Expand Down
2 changes: 1 addition & 1 deletion sequencesender/txbuilder/banana_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (t *TxBuilderBananaBase) NewSequence(
}

func SequenceSanityCheck(seq *etherman.SequenceBanana) error {
maxL1InfoIndex, err := CalculateMaxL1InfoTreeIndexInsideSequence(seq)
maxL1InfoIndex, err := calculateMaxL1InfoTreeIndexInsideSequence(seq)
if err != nil {
return err
}
Expand Down
21 changes: 12 additions & 9 deletions sequencesender/txbuilder/banana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,32 @@ func (b *BananaSequence) SetLastVirtualBatchNumber(batchNumber uint64) {
b.SequenceBanana.LastVirtualBatchNumber = batchNumber
}

func CalculateMaxL1InfoTreeIndexInsideL2Data(l2data []byte) (uint32, error) {
func calculateMaxL1InfoTreeIndexInsideL2Data(l2data []byte) (uint32, error) {
batchRawV2, err := state.DecodeBatchV2(l2data)
if err != nil {
return 0, fmt.Errorf("CalculateMaxL1InfoTreeIndexInsideL2Data: error decoding batchL2Data, err:%w", err)
return 0, fmt.Errorf("calculateMaxL1InfoTreeIndexInsideL2Data: error decoding batchL2Data, err:%w", err)
}
if batchRawV2 == nil {
return 0, fmt.Errorf("CalculateMaxL1InfoTreeIndexInsideL2Data: batchRawV2 is nil")
return 0, fmt.Errorf("calculateMaxL1InfoTreeIndexInsideL2Data: batchRawV2 is nil")
}
maxIndex := uint32(0)
for i := range batchRawV2.Blocks {
if batchRawV2.Blocks[i].IndexL1InfoTree > maxIndex {
maxIndex = batchRawV2.Blocks[i].IndexL1InfoTree
for _, block := range batchRawV2.Blocks {
if block.IndexL1InfoTree > maxIndex {
maxIndex = block.IndexL1InfoTree
}
}
return maxIndex, nil
}

func CalculateMaxL1InfoTreeIndexInsideSequence(seq *etherman.SequenceBanana) (uint32, error) {
func calculateMaxL1InfoTreeIndexInsideSequence(seq *etherman.SequenceBanana) (uint32, error) {
if seq == nil {
return 0, fmt.Errorf("calculateMaxL1InfoTreeIndexInsideSequence: seq is nil")
}
maxIndex := uint32(0)
for _, batch := range seq.Batches {
index, err := CalculateMaxL1InfoTreeIndexInsideL2Data(batch.L2Data)
index, err := calculateMaxL1InfoTreeIndexInsideL2Data(batch.L2Data)
if err != nil {
return 0, fmt.Errorf("CalculateMaxL1InfoTreeIndexInsideBatches: error getting batch L1InfoTree , err:%w", err)
return 0, fmt.Errorf("calculateMaxL1InfoTreeIndexInsideBatches: error getting batch L1InfoTree , err:%w", err)
}
if index > maxIndex {
maxIndex = index
Expand Down

0 comments on commit 84c4282

Please sign in to comment.