Skip to content

Commit

Permalink
Merge branch 'master' into pebble-support
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz authored Sep 19, 2023
2 parents 042edea + 8b7db54 commit cfb72dc
Show file tree
Hide file tree
Showing 25 changed files with 1,088 additions and 221 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ jobs:
version: latest
skip-go-installation: true
skip-pkg-cache: true
- name: Custom Lint
run: |
go run ./linter/koanf ./...
go run ./linter/pointercheck ./...
- name: Set environment variables
run: |
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ WORKDIR /home/user
COPY --from=node-builder /workspace/target/bin/nitro /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/relay /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/nitro-val /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/seq-coordinator-manager /usr/local/bin/
COPY --from=machine-versions /workspace/machines /home/user/target/machines
USER root
RUN export DEBIAN_FRONTEND=noninteractive && \
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ push: lint test-go .make/fmt
all: build build-replay-env test-gen-proofs
@touch .make/all

build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool seq-coordinator-invalidate nitro-val)
build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool seq-coordinator-invalidate nitro-val seq-coordinator-manager)
@printf $(done)

build-node-deps: $(go_source) build-prover-header build-prover-lib build-jit .make/solgen .make/cbrotli-lib
Expand Down Expand Up @@ -185,6 +185,9 @@ $(output_root)/bin/seq-coordinator-invalidate: $(DEP_PREDICATE) build-node-deps
$(output_root)/bin/nitro-val: $(DEP_PREDICATE) build-node-deps
go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/nitro-val"

$(output_root)/bin/seq-coordinator-manager: $(DEP_PREDICATE) build-node-deps
go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/seq-coordinator-manager"

# recompile wasm, but don't change timestamp unless files differ
$(replay_wasm): $(DEP_PREDICATE) $(go_source) .make/solgen
mkdir -p `dirname $(replay_wasm)`
Expand Down Expand Up @@ -304,8 +307,8 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(arbitrator_pro
# strategic rules to minimize dependency building

.make/lint: $(DEP_PREDICATE) build-node-deps $(ORDER_ONLY_PREDICATE) .make
go run linter/koanf/koanf.go ./...
go run linter/pointercheck/pointer.go ./...
go run ./linter/koanf ./...
go run ./linter/pointercheck ./...
golangci-lint run --fix
yarn --cwd contracts solhint
@touch $@
Expand Down
28 changes: 14 additions & 14 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ type BatchPoster struct {
backlog uint64
lastHitL1Bounds time.Time // The last time we wanted to post a message but hit the L1 bounds

batchReverted atomic.Bool // indicates whether data poster batch was reverted
batchReverted atomic.Bool // indicates whether data poster batch was reverted
nextRevertCheckBlock int64 // the last parent block scanned for reverting batches
}

type l1BlockBound int
Expand Down Expand Up @@ -263,13 +264,12 @@ func NewBatchPoster(dataPosterDB ethdb.Database, l1Reader *headerreader.HeaderRe
// contain reverted batch_poster transaction.
// It returns true if it finds batch posting needs to halt, which is true if a batch reverts
// unless the data poster is configured with noop storage which can tolerate reverts.
// From must be a pointer to the starting block, which is updated after each block is checked for reverts
func (b *BatchPoster) checkReverts(ctx context.Context, from *int64, to int64) (bool, error) {
if *from > to {
return false, fmt.Errorf("wrong range, from: %d > to: %d", from, to)
func (b *BatchPoster) checkReverts(ctx context.Context, to int64) (bool, error) {
if b.nextRevertCheckBlock > to {
return false, fmt.Errorf("wrong range, from: %d > to: %d", b.nextRevertCheckBlock, to)
}
for ; *from <= to; *from++ {
number := big.NewInt(*from)
for ; b.nextRevertCheckBlock <= to; b.nextRevertCheckBlock++ {
number := big.NewInt(b.nextRevertCheckBlock)
block, err := b.l1Reader.Client().BlockByNumber(ctx, number)
if err != nil {
return false, fmt.Errorf("getting block: %v by number: %w", number, err)
Expand Down Expand Up @@ -305,7 +305,6 @@ func (b *BatchPoster) pollForReverts(ctx context.Context) {
headerCh, unsubscribe := b.l1Reader.Subscribe(false)
defer unsubscribe()

nextToCheck := int64(0) // the first unchecked block
for {
// Poll until:
// - L1 headers reader channel is closed, or
Expand All @@ -317,19 +316,20 @@ func (b *BatchPoster) pollForReverts(ctx context.Context) {
log.Info("L1 headers channel checking for batch poster reverts has been closed")
return
}
blockNum := h.Number.Int64()
// If this is the first block header, set last seen as number-1.
// We may see same block number again if there is L1 reorg, in that
// case we check the block again.
if nextToCheck == 0 || nextToCheck == h.Number.Int64() {
nextToCheck = h.Number.Int64()
if b.nextRevertCheckBlock == 0 || b.nextRevertCheckBlock > blockNum {
b.nextRevertCheckBlock = blockNum
}
if h.Number.Int64()-nextToCheck > 100 {
log.Warn("Large gap between last seen and current block number, skipping check for reverts", "last", nextToCheck, "current", h.Number)
nextToCheck = h.Number.Int64()
if blockNum-b.nextRevertCheckBlock > 100 {
log.Warn("Large gap between last seen and current block number, skipping check for reverts", "last", b.nextRevertCheckBlock, "current", blockNum)
b.nextRevertCheckBlock = blockNum
continue
}

reverted, err := b.checkReverts(ctx, &nextToCheck, h.Number.Int64())
reverted, err := b.checkReverts(ctx, blockNum)
if err != nil {
logLevel := log.Error
if strings.Contains(err.Error(), "not found") {
Expand Down
4 changes: 3 additions & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
"github.com/offchainlabs/nitro/solgen/go/challengegen"
"github.com/offchainlabs/nitro/solgen/go/ospgen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/contracts"
Expand Down Expand Up @@ -604,7 +605,8 @@ func createNodeImpl(

var l1Reader *headerreader.HeaderReader
if config.ParentChainReader.Enable {
l1Reader, err = headerreader.New(ctx, l1client, func() *headerreader.Config { return &configFetcher.Get().ParentChainReader })
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1client)
l1Reader, err = headerreader.New(ctx, l1client, func() *headerreader.Config { return &configFetcher.Get().ParentChainReader }, arbSys)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/daserver/daserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import (
flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/exp"

"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
"github.com/offchainlabs/nitro/das"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/headerreader"
)

Expand Down Expand Up @@ -196,7 +198,8 @@ func startup() error {
if err != nil {
return err
}
l1Reader, err = headerreader.New(ctx, l1Client, func() *headerreader.Config { return &headerreader.DefaultConfig }) // TODO: config
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1Client)
l1Reader, err = headerreader.New(ctx, l1Client, func() *headerreader.Config { return &headerreader.DefaultConfig }, arbSys) // TODO: config
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (

"github.com/offchainlabs/nitro/cmd/chaininfo"
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/validator/server_common"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -127,7 +129,8 @@ func main() {
panic(fmt.Errorf("failed to deserialize chain config: %w", err))
}

l1Reader, err := headerreader.New(ctx, l1client, func() *headerreader.Config { return &headerReaderConfig })
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1client)
l1Reader, err := headerreader.New(ctx, l1client, func() *headerreader.Config { return &headerReaderConfig }, arbSys)
if err != nil {
panic(fmt.Errorf("failed to create header reader: %w", err))
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/arbitrum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
Expand All @@ -49,6 +50,7 @@ import (
"github.com/offchainlabs/nitro/cmd/util"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
_ "github.com/offchainlabs/nitro/nodeInterface"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/colors"
"github.com/offchainlabs/nitro/util/headerreader"
Expand Down Expand Up @@ -355,7 +357,8 @@ func mainImpl() int {
flag.Usage()
log.Crit("--node.validator.only-create-wallet-contract requires --node.validator.use-smart-contract-wallet")
}
l1Reader, err := headerreader.New(ctx, l1Client, func() *headerreader.Config { return &liveNodeConfig.Get().Node.ParentChainReader })
arbSys, _ := precompilesgen.NewArbSys(types.ArbSysAddress, l1Client)
l1Reader, err := headerreader.New(ctx, l1Client, func() *headerreader.Config { return &liveNodeConfig.Get().Node.ParentChainReader }, arbSys)
if err != nil {
log.Crit("failed to get L1 headerreader", "error", err)
}
Expand Down
28 changes: 28 additions & 0 deletions cmd/seq-coordinator-manager/rediscoordinator/redis_coordinator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rediscoordinator

import (
"context"
"errors"
"strings"

"github.com/go-redis/redis/v8"
"github.com/offchainlabs/nitro/util/redisutil"
)

// RedisCoordinator builds upon RedisCoordinator of redisutil with additional functionality
type RedisCoordinator struct {
*redisutil.RedisCoordinator
}

// UpdatePriorities updates the priority list of sequencers
func (rc *RedisCoordinator) UpdatePriorities(ctx context.Context, priorities []string) error {
prioritiesString := strings.Join(priorities, ",")
err := rc.Client.Set(ctx, redisutil.PRIORITIES_KEY, prioritiesString, 0).Err()
if err != nil {
if errors.Is(err, redis.Nil) {
err = errors.New("sequencer priorities unset")
}
return err
}
return nil
}
Loading

0 comments on commit cfb72dc

Please sign in to comment.