Skip to content

Commit

Permalink
Merge branch 'rollup-contracts-port-tests' into rollup-contracts-port…
Browse files Browse the repository at this point in the history
…-tests-cont
  • Loading branch information
yahgwai committed Feb 23, 2022
2 parents 7f58c03 + 1c1cb95 commit d1c0d63
Show file tree
Hide file tree
Showing 152 changed files with 7,977 additions and 4,340 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/replay
/cmd/replay/replay
/*.bin
/*.test
.idea
.vscode
cmd/node/data
Expand All @@ -19,3 +20,4 @@ solgen/test/prover/proofs/*.json
/cmd/statetransfer/statetransfer
/reproducible-wasm/*.wasm
target/
yarn-error.log
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ $(output_root)/lib/host_io.wasm: arbitrator/wasm-libraries/host-io/src/**
arbitrator/prover/test-cases/%.wasm: arbitrator/prover/test-cases/%.wat
wat2wasm $< -o $@

solgen/test/prover/proofs/%.json: arbitrator/prover/test-cases/%.wasm $(arbitrator_prover_bin)
$(arbitrator_prover_bin) $< -o $@ --allow-hostapi --always-merkleize

solgen/test/prover/proofs/float%.json: arbitrator/prover/test-cases/float%.wasm $(arbitrator_prover_bin) $(output_root)/lib/soft-float.wasm
$(arbitrator_prover_bin) $< -l $(output_root)/lib/soft-float.wasm -o $@ -b --allow-hostapi --require-success --always-merkleize

Expand All @@ -247,15 +244,20 @@ solgen/test/prover/proofs/rust-%.json: arbitrator/prover/test-cases/rust/target/
solgen/test/prover/proofs/go.json: arbitrator/prover/test-cases/go/main $(arbitrator_prover_bin) $(arbitrator_wasm_libs)
$(arbitrator_prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -i 5000000

solgen/test/prover/proofs/%.json: arbitrator/prover/test-cases/%.wasm $(arbitrator_prover_bin)
$(arbitrator_prover_bin) $< -o $@ --allow-hostapi --always-merkleize

# strategic rules to minimize dependency building

.make/lint: build-node-deps | .make
golangci-lint run --fix
yarn --cwd solgen solhint
@touch $@

.make/fmt: build-node-deps | .make
.make/fmt: build-node-deps .make/yarndeps | .make
golangci-lint run --disable-all -E gofmt --fix
cargo fmt --all --manifest-path arbitrator/Cargo.toml -- --check
yarn --cwd solgen prettier:solidity
@touch $@

.make/test-go: $(go_source) build-node-deps test-go-deps | .make
Expand Down
30 changes: 19 additions & 11 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/offchainlabs/arbstate/arbstate"
"github.com/offchainlabs/arbstate/arbutil"
"github.com/offchainlabs/arbstate/solgen/go/bridgegen"
)

type BatchPoster struct {
client L1Interface
client arbutil.L1Interface
inbox *InboxTracker
streamer *TransactionStreamer
config *BatchPosterConfig
Expand Down Expand Up @@ -50,7 +52,7 @@ var TestBatchPosterConfig = BatchPosterConfig{
CompressionLevel: 2,
}

func NewBatchPoster(client L1Interface, inbox *InboxTracker, streamer *TransactionStreamer, config *BatchPosterConfig, contractAddress common.Address, refunder common.Address, transactOpts *bind.TransactOpts) (*BatchPoster, error) {
func NewBatchPoster(client arbutil.L1Interface, inbox *InboxTracker, streamer *TransactionStreamer, config *BatchPosterConfig, contractAddress common.Address, refunder common.Address, transactOpts *bind.TransactOpts) (*BatchPoster, error) {
inboxContract, err := bridgegen.NewSequencerInbox(contractAddress, client)
if err != nil {
return nil, err
Expand Down Expand Up @@ -286,7 +288,7 @@ func (b *BatchPoster) lastSubmissionIsSynced() bool {
}

// TODO make sure we detect end of block!
func (b *BatchPoster) postSequencerBatch() error {
func (b *BatchPoster) postSequencerBatch() (*types.Transaction, error) {
for !b.lastSubmissionIsSynced() {
log.Warn("BatchPoster: not in sync", "sequencedPosted", b.sequencesPosted)
<-time.After(b.config.SubmissionSyncDelay)
Expand All @@ -296,14 +298,14 @@ func (b *BatchPoster) postSequencerBatch() error {
var err error
prevBatchMeta, err = b.inbox.GetBatchMetadata(b.sequencesPosted - 1)
if err != nil {
return err
return nil, err
}
}
segments := newBatchSegments(prevBatchMeta.DelayedMessageCount, b.config)
msgToPost := prevBatchMeta.MessageCount
msgCount, err := b.streamer.GetMessageCount()
if err != nil {
return err
return nil, err
}
for msgToPost < msgCount {
msg, err := b.streamer.GetMessage(msgToPost)
Expand All @@ -323,26 +325,32 @@ func (b *BatchPoster) postSequencerBatch() error {
}
sequencerMsg, err := segments.CloseAndGetBytes()
if err != nil {
return err
return nil, err
}
if sequencerMsg == nil {
log.Debug("BatchPoster: batch nil", "sequence nr.", b.sequencesPosted, "from", prevBatchMeta.MessageCount, "prev delayed", prevBatchMeta.DelayedMessageCount)
return nil
return nil, nil
}
_, err = b.inboxContract.AddSequencerL2BatchFromOrigin(b.transactOpts, new(big.Int).SetUint64(b.sequencesPosted), sequencerMsg, new(big.Int).SetUint64(segments.delayedMsg), b.gasRefunder)
tx, err := b.inboxContract.AddSequencerL2BatchFromOrigin(b.transactOpts, new(big.Int).SetUint64(b.sequencesPosted), sequencerMsg, new(big.Int).SetUint64(segments.delayedMsg), b.gasRefunder)
if err == nil {
b.sequencesPosted++
log.Info("BatchPoster: batch sent", "sequence nr.", b.sequencesPosted, "from", prevBatchMeta.MessageCount, "to", msgToPost, "prev delayed", prevBatchMeta.DelayedMessageCount, "current delayed", segments.delayedMsg, "total segments", len(segments.rawSegments))
}
return err
return tx, err
}

func (b *BatchPoster) Start(ctx context.Context) {
go (func() {
for {
err := b.postSequencerBatch()
tx, err := b.postSequencerBatch()
if err != nil {
log.Error("error posting batch", "err", err.Error())
log.Error("error posting batch", "err", err)
}
if tx != nil {
_, err = arbutil.EnsureTxSucceededWithTimeout(ctx, b.client, tx, time.Minute)
if err != nil {
log.Error("failed ensuring batch tx succeeded", "err", err)
}
}
select {
case <-ctx.Done():
Expand Down
5 changes: 3 additions & 2 deletions arbnode/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"

"github.com/offchainlabs/arbstate/arbos"
"github.com/offchainlabs/arbstate/arbutil"
"github.com/offchainlabs/arbstate/solgen/go/bridgegen"
)

Expand Down Expand Up @@ -54,11 +55,11 @@ type DelayedBridge struct {
con *bridgegen.IBridge
address common.Address
fromBlock uint64
client L1Interface
client arbutil.L1Interface
messageProviders map[common.Address]*bridgegen.IMessageProvider
}

func NewDelayedBridge(client L1Interface, addr common.Address, fromBlock uint64) (*DelayedBridge, error) {
func NewDelayedBridge(client arbutil.L1Interface, addr common.Address, fromBlock uint64) (*DelayedBridge, error) {
con, err := bridgegen.NewIBridge(addr, client)
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions arbnode/delayed_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"github.com/ethereum/go-ethereum/log"

"github.com/offchainlabs/arbstate/arbos"
"github.com/offchainlabs/arbstate/arbutil"
)

type DelayedSequencer struct {
client L1Interface
client arbutil.L1Interface
bridge *DelayedBridge
inbox *InboxTracker
txStreamer *TransactionStreamer
Expand All @@ -39,7 +40,7 @@ var TestDelayedSequencerConfig = DelayedSequencerConfig{
TimeAggregate: time.Second,
}

func NewDelayedSequencer(client L1Interface, reader *InboxReader, txStreamer *TransactionStreamer, config *DelayedSequencerConfig) (*DelayedSequencer, error) {
func NewDelayedSequencer(client arbutil.L1Interface, reader *InboxReader, txStreamer *TransactionStreamer, config *DelayedSequencerConfig) (*DelayedSequencer, error) {
return &DelayedSequencer{
client: client,
bridge: reader.DelayedBridge(),
Expand Down Expand Up @@ -125,7 +126,7 @@ func (d *DelayedSequencer) update(ctx context.Context) error {
return errors.New("inbox reader db accumulator doesn't match delayed bridge")
}

err = d.txStreamer.SequenceDelayedMessages(messages, startPos)
err = d.txStreamer.SequenceDelayedMessages(ctx, messages, startPos)
if err != nil {
return err
}
Expand All @@ -136,7 +137,7 @@ func (d *DelayedSequencer) update(ctx context.Context) error {
}

func (d *DelayedSequencer) run(ctx context.Context) error {
headerChan, cancel := HeaderSubscribeWithRetry(ctx, d.client)
headerChan, cancel := arbutil.HeaderSubscribeWithRetry(ctx, d.client)
defer cancel()

for {
Expand Down
5 changes: 3 additions & 2 deletions arbnode/inbox_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/offchainlabs/arbstate/arbutil"
)

type InboxReaderConfig struct {
Expand Down Expand Up @@ -42,10 +43,10 @@ type InboxReader struct {
delayedBridge *DelayedBridge
sequencerInbox *SequencerInbox
caughtUpChan chan bool
client L1Interface
client arbutil.L1Interface
}

func NewInboxReader(tracker *InboxTracker, client L1Interface, firstMessageBlock *big.Int, delayedBridge *DelayedBridge, sequencerInbox *SequencerInbox, config *InboxReaderConfig) (*InboxReader, error) {
func NewInboxReader(tracker *InboxTracker, client arbutil.L1Interface, firstMessageBlock *big.Int, delayedBridge *DelayedBridge, sequencerInbox *SequencerInbox, config *InboxReaderConfig) (*InboxReader, error) {
return &InboxReader{
tracker: tracker,
delayedBridge: delayedBridge,
Expand Down
21 changes: 18 additions & 3 deletions arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/offchainlabs/arbstate/arbos/l2pricing"
"github.com/offchainlabs/arbstate/arbutil"
"github.com/offchainlabs/arbstate/statetransfer"

"github.com/offchainlabs/arbstate/arbos/util"
Expand Down Expand Up @@ -55,13 +56,27 @@ func NewTransactionStreamerForTest(t *testing.T, ownerAddress common.Address) (*
Fail(t, err)
}

// Add the init message
err = inbox.AddMessages(0, false, []arbstate.MessageWithMetadata{{
Message: &arbos.L1IncomingMessage{
Header: &arbos.L1IncomingMessageHeader{
Kind: arbos.L1MessageType_SetChainParams,
},
L2msg: []byte{},
},
DelayedMessagesRead: 0,
}})
if err != nil {
Fail(t, err)
}

return inbox, bc
}

type blockTestState struct {
balances map[common.Address]*big.Int
accounts []common.Address
numMessages uint64
numMessages arbutil.MessageIndex
blockNumber uint64
}

Expand All @@ -86,7 +101,7 @@ func TestTransactionStreamer(t *testing.T) {
rewrittenOwnerAddress: new(big.Int).Mul(maxExpectedGasCost, big.NewInt(1_000_000)),
},
accounts: []common.Address{rewrittenOwnerAddress},
numMessages: 0,
numMessages: 1,
blockNumber: 0,
})
for i := 1; i < 100; i++ {
Expand Down Expand Up @@ -147,7 +162,7 @@ func TestTransactionStreamer(t *testing.T) {

Require(t, inbox.AddMessages(state.numMessages, false, messages))

state.numMessages += uint64(len(messages))
state.numMessages += arbutil.MessageIndex(len(messages))
state.blockNumber += uint64(len(messages))
for i := 0; ; i++ {
blockNumber := bc.CurrentHeader().Number.Uint64()
Expand Down
13 changes: 7 additions & 6 deletions arbnode/inbox_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/offchainlabs/arbstate/arbos"
"github.com/offchainlabs/arbstate/arbstate"
"github.com/offchainlabs/arbstate/arbutil"
"github.com/offchainlabs/arbstate/validator"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -114,7 +115,7 @@ func (t *InboxTracker) GetDelayedCount() (uint64, error) {

type BatchMetadata struct {
Accumulator common.Hash
MessageCount uint64
MessageCount arbutil.MessageIndex
DelayedMessageCount uint64
L1Block uint64
}
Expand All @@ -137,7 +138,7 @@ func (t *InboxTracker) GetBatchMetadata(seqNum uint64) (BatchMetadata, error) {
return metadata, err
}

func (t *InboxTracker) GetBatchMessageCount(seqNum uint64) (uint64, error) {
func (t *InboxTracker) GetBatchMessageCount(seqNum uint64) (arbutil.MessageIndex, error) {
metadata, err := t.GetBatchMetadata(seqNum)
return metadata.MessageCount, err
}
Expand Down Expand Up @@ -314,7 +315,7 @@ func (t *InboxTracker) setDelayedCountReorgAndWriteBatch(batch ethdb.Batch, newD
if err != nil {
return err
}
var prevMesssageCount uint64
var prevMesssageCount arbutil.MessageIndex
if count > 0 {
prevMesssageCount, err = t.GetBatchMessageCount(count - 1)
if err != nil {
Expand All @@ -334,7 +335,7 @@ type multiplexerBackend struct {
positionWithinMessage uint64

ctx context.Context
client L1Interface
client arbutil.L1Interface
inbox *InboxTracker
}

Expand Down Expand Up @@ -374,7 +375,7 @@ func (b *multiplexerBackend) ReadDelayedInbox(seqNum uint64) ([]byte, error) {

var delayedMessagesMismatch = errors.New("sequencer batch delayed messages missing or different")

func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client L1Interface, batches []*SequencerInboxBatch) error {
func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client arbutil.L1Interface, batches []*SequencerInboxBatch) error {
if len(batches) == 0 {
return nil
}
Expand Down Expand Up @@ -436,7 +437,7 @@ func (t *InboxTracker) AddSequencerBatches(ctx context.Context, client L1Interfa
client: client,
}
multiplexer := arbstate.NewInboxMultiplexer(backend, prevbatchmeta.DelayedMessageCount)
batchMessageCounts := make(map[uint64]uint64)
batchMessageCounts := make(map[uint64]arbutil.MessageIndex)
currentpos := prevbatchmeta.MessageCount + 1
for {
if len(backend.batches) == 0 {
Expand Down
Loading

0 comments on commit d1c0d63

Please sign in to comment.