Skip to content

Commit

Permalink
Merge pull request #2646 from OffchainLabs/batch-poster-first-msg-sel…
Browse files Browse the repository at this point in the history
…ection

Be more precise when selecting firstMsg in the batch poster
  • Loading branch information
PlasmaPower authored Oct 15, 2024
2 parents 65d7401 + 31dc016 commit 5d74164
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,14 @@ type batchSegments struct {
}

type buildingBatch struct {
segments *batchSegments
startMsgCount arbutil.MessageIndex
msgCount arbutil.MessageIndex
haveUsefulMessage bool
use4844 bool
muxBackend *simulatedMuxBackend
segments *batchSegments
startMsgCount arbutil.MessageIndex
msgCount arbutil.MessageIndex
haveUsefulMessage bool
use4844 bool
muxBackend *simulatedMuxBackend
firstNonDelayedMsg *arbostypes.MessageWithMetadata
firstUsefulMsg *arbostypes.MessageWithMetadata
}

func newBatchSegments(firstDelayed uint64, config *BatchPosterConfig, backlog uint64, use4844 bool) *batchSegments {
Expand Down Expand Up @@ -1171,20 +1173,14 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
// There's nothing after the newest batch, therefore batch posting was not required
return false, nil
}
firstMsg, err := b.streamer.GetMessage(batchPosition.MessageCount)
if err != nil {
return false, err
}
// #nosec G115
firstMsgTime := time.Unix(int64(firstMsg.Message.Header.Timestamp), 0)

lastPotentialMsg, err := b.streamer.GetMessage(msgCount - 1)
if err != nil {
return false, err
}

config := b.config()
forcePostBatch := config.MaxDelay <= 0 || time.Since(firstMsgTime) >= config.MaxDelay
forcePostBatch := config.MaxDelay <= 0

var l1BoundMaxBlockNumber uint64 = math.MaxUint64
var l1BoundMaxTimestamp uint64 = math.MaxUint64
Expand Down Expand Up @@ -1296,6 +1292,9 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
forcePostBatch = true
}
b.building.haveUsefulMessage = true
if b.building.firstUsefulMsg == nil {
b.building.firstUsefulMsg = msg
}
break
}
if config.CheckBatchCorrectness {
Expand All @@ -1306,13 +1305,28 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}
if msg.Message.Header.Kind != arbostypes.L1MessageType_BatchPostingReport {
b.building.haveUsefulMessage = true
if b.building.firstUsefulMsg == nil {
b.building.firstUsefulMsg = msg
}
}
if !isDelayed && b.building.firstNonDelayedMsg == nil {
b.building.firstNonDelayedMsg = msg
}
b.building.msgCount++
}

if hasL1Bound && config.ReorgResistanceMargin > 0 {
firstMsgBlockNumber := firstMsg.Message.Header.BlockNumber
firstMsgTimeStamp := firstMsg.Message.Header.Timestamp
firstUsefulMsgTime := time.Now()
if b.building.firstUsefulMsg != nil {
// #nosec G115
firstUsefulMsgTime = time.Unix(int64(b.building.firstUsefulMsg.Message.Header.Timestamp), 0)
if time.Since(firstUsefulMsgTime) >= config.MaxDelay {
forcePostBatch = true
}
}

if b.building.firstNonDelayedMsg != nil && hasL1Bound && config.ReorgResistanceMargin > 0 {
firstMsgBlockNumber := b.building.firstNonDelayedMsg.Message.Header.BlockNumber
firstMsgTimeStamp := b.building.firstNonDelayedMsg.Message.Header.Timestamp
// #nosec G115
batchNearL1BoundMinBlockNumber := firstMsgBlockNumber <= arbmath.SaturatingUAdd(l1BoundMinBlockNumber, uint64(config.ReorgResistanceMargin/ethPosBlockTime))
// #nosec G115
Expand Down Expand Up @@ -1463,7 +1477,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
}

tx, err := b.dataPoster.PostTransaction(ctx,
firstMsgTime,
firstUsefulMsgTime,
nonce,
newMeta,
b.seqInboxAddr,
Expand Down

0 comments on commit 5d74164

Please sign in to comment.