Skip to content

Commit

Permalink
Merge branch 'master' into gligneul/stylus-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul committed Aug 9, 2024
2 parents 50b2fb4 + 7e7b45f commit d3273f8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ FROM wasm-base AS wasm-libs-builder
# clang / lld used by soft-float wasm
RUN apt-get update && \
apt-get install -y clang=1:14.0-55.7~deb12u1 lld=1:14.0-55.7~deb12u1 wabt
# pinned rust 1.80.0
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.80.0 --target x86_64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasi
# pinned rust 1.80.1
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.80.1 --target x86_64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasi
COPY ./Makefile ./
COPY arbitrator/Cargo.* arbitrator/
COPY arbitrator/arbutil arbitrator/arbutil
Expand Down Expand Up @@ -94,7 +94,7 @@ COPY --from=contracts-builder workspace/contracts/node_modules/@offchainlabs/upg
COPY --from=contracts-builder workspace/.make/ .make/
RUN PATH="$PATH:/usr/local/go/bin" NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-wasm-bin

FROM rust:1.80-slim-bookworm AS prover-header-builder
FROM rust:1.80.1-slim-bookworm AS prover-header-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand All @@ -120,7 +120,7 @@ RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-prover-header
FROM scratch AS prover-header-export
COPY --from=prover-header-builder /workspace/target/ /

FROM rust:1.80-slim-bookworm AS prover-builder
FROM rust:1.80.1-slim-bookworm AS prover-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand Down
92 changes: 92 additions & 0 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package arbnode
import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -105,6 +106,7 @@ type BatchPoster struct {
gasRefunderAddr common.Address
building *buildingBatch
dapWriter daprovider.Writer
dapReaders []daprovider.Reader
dataPoster *dataposter.DataPoster
redisLock *redislock.Simple
messagesPerBatch *arbmath.MovingAverage[uint64]
Expand Down Expand Up @@ -169,6 +171,7 @@ type BatchPosterConfig struct {
GasEstimateBaseFeeMultipleBips arbmath.Bips `koanf:"gas-estimate-base-fee-multiple-bips"`
Dangerous BatchPosterDangerousConfig `koanf:"dangerous"`
ReorgResistanceMargin time.Duration `koanf:"reorg-resistance-margin" reload:"hot"`
CheckBatchCorrectness bool `koanf:"check-batch-correctness"`

gasRefunder common.Address
l1BlockBound l1BlockBound
Expand Down Expand Up @@ -221,6 +224,7 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".use-access-lists", DefaultBatchPosterConfig.UseAccessLists, "post batches with access lists to reduce gas usage (disabled for L3s)")
f.Uint64(prefix+".gas-estimate-base-fee-multiple-bips", uint64(DefaultBatchPosterConfig.GasEstimateBaseFeeMultipleBips), "for gas estimation, use this multiple of the basefee (measured in basis points) as the max fee per gas")
f.Duration(prefix+".reorg-resistance-margin", DefaultBatchPosterConfig.ReorgResistanceMargin, "do not post batch if its within this duration from layer 1 minimum bounds. Requires l1-block-bound option not be set to \"ignore\"")
f.Bool(prefix+".check-batch-correctness", DefaultBatchPosterConfig.CheckBatchCorrectness, "setting this to true will run the batch against an inbox multiplexer and verifies that it produces the correct set of messages")
redislock.AddConfigOptions(prefix+".redis-lock", f)
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfig)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname)
Expand Down Expand Up @@ -251,6 +255,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
RedisLock: redislock.DefaultCfg,
GasEstimateBaseFeeMultipleBips: arbmath.OneInBips * 3 / 2,
ReorgResistanceMargin: 10 * time.Minute,
CheckBatchCorrectness: true,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Expand Down Expand Up @@ -281,6 +286,7 @@ var TestBatchPosterConfig = BatchPosterConfig{
L1BlockBoundBypass: time.Hour,
UseAccessLists: true,
GasEstimateBaseFeeMultipleBips: arbmath.OneInBips * 3 / 2,
CheckBatchCorrectness: true,
}

type BatchPosterOpts struct {
Expand All @@ -295,6 +301,7 @@ type BatchPosterOpts struct {
TransactOpts *bind.TransactOpts
DAPWriter daprovider.Writer
ParentChainID *big.Int
DAPReaders []daprovider.Reader
}

func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, error) {
Expand Down Expand Up @@ -341,6 +348,7 @@ func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, e
bridgeAddr: opts.DeployInfo.Bridge,
dapWriter: opts.DAPWriter,
redisLock: redisLock,
dapReaders: opts.DAPReaders,
}
b.messagesPerBatch, err = arbmath.NewMovingAverage[uint64](20)
if err != nil {
Expand Down Expand Up @@ -384,6 +392,42 @@ func NewBatchPoster(ctx context.Context, opts *BatchPosterOpts) (*BatchPoster, e
return b, nil
}

type simulatedBlobReader struct {
blobs []kzg4844.Blob
}

func (b *simulatedBlobReader) GetBlobs(ctx context.Context, batchBlockHash common.Hash, versionedHashes []common.Hash) ([]kzg4844.Blob, error) {
return b.blobs, nil
}

func (b *simulatedBlobReader) Initialize(ctx context.Context) error { return nil }

type simulatedMuxBackend struct {
batchSeqNum uint64
positionWithinMessage uint64
seqMsg []byte
allMsgs map[arbutil.MessageIndex]*arbostypes.MessageWithMetadata
delayedInboxStart uint64
delayedInbox []*arbostypes.MessageWithMetadata
}

func (b *simulatedMuxBackend) PeekSequencerInbox() ([]byte, common.Hash, error) {
return b.seqMsg, common.Hash{}, nil
}

func (b *simulatedMuxBackend) GetSequencerInboxPosition() uint64 { return b.batchSeqNum }
func (b *simulatedMuxBackend) AdvanceSequencerInbox() {}
func (b *simulatedMuxBackend) GetPositionWithinMessage() uint64 { return b.positionWithinMessage }
func (b *simulatedMuxBackend) SetPositionWithinMessage(pos uint64) { b.positionWithinMessage = pos }

func (b *simulatedMuxBackend) ReadDelayedInbox(seqNum uint64) (*arbostypes.L1IncomingMessage, error) {
pos := arbmath.SaturatingUSub(seqNum, b.delayedInboxStart)
if pos < uint64(len(b.delayedInbox)) {
return b.delayedInbox[pos].Message, nil
}
return nil, fmt.Errorf("error serving ReadDelayedInbox, all delayed messages were read. Requested delayed message position:%d, Total delayed messages: %d", pos, len(b.delayedInbox))
}

type AccessListOpts struct {
SequencerInboxAddr common.Address
BridgeAddr common.Address
Expand Down Expand Up @@ -673,6 +717,7 @@ type buildingBatch struct {
msgCount arbutil.MessageIndex
haveUsefulMessage bool
use4844 bool
muxBackend *simulatedMuxBackend
}

func newBatchSegments(firstDelayed uint64, config *BatchPosterConfig, backlog uint64, use4844 bool) *batchSegments {
Expand Down Expand Up @@ -1112,6 +1157,12 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
startMsgCount: batchPosition.MessageCount,
use4844: use4844,
}
if b.config().CheckBatchCorrectness {
b.building.muxBackend = &simulatedMuxBackend{
batchSeqNum: batchPosition.NextSeqNum,
allMsgs: make(map[arbutil.MessageIndex]*arbostypes.MessageWithMetadata),
}
}
}
msgCount, err := b.streamer.GetMessageCount()
if err != nil {
Expand Down Expand Up @@ -1230,6 +1281,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
)
break
}
isDelayed := msg.DelayedMessagesRead > b.building.segments.delayedMsg
success, err := b.building.segments.AddMessage(msg)
if err != nil {
// Clear our cache
Expand All @@ -1244,6 +1296,12 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
b.building.haveUsefulMessage = true
break
}
if config.CheckBatchCorrectness {
b.building.muxBackend.allMsgs[b.building.msgCount] = msg
if isDelayed {
b.building.muxBackend.delayedInbox = append(b.building.muxBackend.delayedInbox, msg)
}
}
if msg.Message.Header.Kind != arbostypes.L1MessageType_BatchPostingReport {
b.building.haveUsefulMessage = true
}
Expand Down Expand Up @@ -1365,6 +1423,40 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
if err != nil {
return false, err
}

if config.CheckBatchCorrectness {
dapReaders := b.dapReaders
if b.building.use4844 {
dapReaders = append(dapReaders, daprovider.NewReaderForBlobReader(&simulatedBlobReader{kzgBlobs}))
}
seqMsg := binary.BigEndian.AppendUint64([]byte{}, l1BoundMinTimestamp)
seqMsg = binary.BigEndian.AppendUint64(seqMsg, l1BoundMaxTimestamp)
seqMsg = binary.BigEndian.AppendUint64(seqMsg, l1BoundMinBlockNumber)
seqMsg = binary.BigEndian.AppendUint64(seqMsg, l1BoundMaxBlockNumber)
seqMsg = binary.BigEndian.AppendUint64(seqMsg, b.building.segments.delayedMsg)
seqMsg = append(seqMsg, sequencerMsg...)
b.building.muxBackend.seqMsg = seqMsg
b.building.muxBackend.delayedInboxStart = batchPosition.DelayedMessageCount
b.building.muxBackend.SetPositionWithinMessage(0)
simMux := arbstate.NewInboxMultiplexer(b.building.muxBackend, batchPosition.DelayedMessageCount, dapReaders, daprovider.KeysetValidate)
log.Info("Begin checking the correctness of batch against inbox multiplexer", "startMsgSeqNum", batchPosition.MessageCount, "endMsgSeqNum", b.building.msgCount-1)
for i := batchPosition.MessageCount; i < b.building.msgCount; i++ {
msg, err := simMux.Pop(ctx)
if err != nil {
return false, fmt.Errorf("error getting message from simulated inbox multiplexer (Pop) when testing correctness of batch: %w", err)
}
if msg.DelayedMessagesRead != b.building.muxBackend.allMsgs[i].DelayedMessagesRead {
b.building = nil
return false, fmt.Errorf("simulated inbox multiplexer failed to produce correct delayedMessagesRead field for msg with seqNum: %d. Got: %d, Want: %d", i, msg.DelayedMessagesRead, b.building.muxBackend.allMsgs[i].DelayedMessagesRead)
}
if !msg.Message.Equals(b.building.muxBackend.allMsgs[i].Message) {
b.building = nil
return false, fmt.Errorf("simulated inbox multiplexer failed to produce correct message field for msg with seqNum: %d", i)
}
}
log.Debug("Successfully checked that the batch produces correct messages when ran through inbox multiplexer", "sequenceNumber", batchPosition.NextSeqNum)
}

tx, err := b.dataPoster.PostTransaction(ctx,
firstMsgTime,
nonce,
Expand Down
1 change: 1 addition & 0 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ func createNodeImpl(
TransactOpts: txOptsBatchPoster,
DAPWriter: dapWriter,
ParentChainID: parentChainID,
DAPReaders: dapReaders,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit d3273f8

Please sign in to comment.