Skip to content

Commit

Permalink
Merge branch 'koanf-cont-cont' into enable-custom-linter-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
anodar authored Sep 15, 2023
2 parents 0e29494 + 70b883a commit e8c44f6
Show file tree
Hide file tree
Showing 27 changed files with 570 additions and 103 deletions.
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
5 changes: 4 additions & 1 deletion 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
69 changes: 39 additions & 30 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"math"
"math/big"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -75,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 @@ -167,19 +169,20 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
var DefaultBatchPosterConfig = BatchPosterConfig{
Enable: false,
DisableDasFallbackStoreDataOnChain: false,
MaxSize: 100000,
PollInterval: time.Second * 10,
ErrorDelay: time.Second * 10,
MaxDelay: time.Hour,
WaitForMaxDelay: false,
CompressionLevel: brotli.BestCompression,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 50_000,
DataPoster: dataposter.DefaultDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
// This default is overridden for L3 chains in applyChainParameters in cmd/nitro/nitro.go
MaxSize: 100000,
PollInterval: time.Second * 10,
ErrorDelay: time.Second * 10,
MaxDelay: time.Hour,
WaitForMaxDelay: false,
CompressionLevel: brotli.BestCompression,
DASRetentionPeriod: time.Hour * 24 * 15,
GasRefunderAddress: "",
ExtraBatchGas: 50_000,
DataPoster: dataposter.DefaultDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
L1BlockBound: "",
L1BlockBoundBypass: time.Hour,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Expand Down Expand Up @@ -261,12 +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.
func (b *BatchPoster) checkReverts(ctx context.Context, from, to int64) (bool, error) {
if from > to {
return false, fmt.Errorf("wrong range, from: %d is more 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 idx := from; idx <= to; idx++ {
number := big.NewInt(idx)
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 All @@ -276,7 +279,7 @@ func (b *BatchPoster) checkReverts(ctx context.Context, from, to int64) (bool, e
if err != nil {
return false, fmt.Errorf("getting sender of transaction tx: %v, %w", tx.Hash(), err)
}
if bytes.Equal(from.Bytes(), b.dataPoster.Sender().Bytes()) {
if from == b.dataPoster.Sender() {
r, err := b.l1Reader.Client().TransactionReceipt(ctx, tx.Hash())
if err != nil {
return false, fmt.Errorf("getting a receipt for transaction: %v, %w", tx.Hash(), err)
Expand All @@ -302,7 +305,6 @@ func (b *BatchPoster) pollForReverts(ctx context.Context) {
headerCh, unsubscribe := b.l1Reader.Subscribe(false)
defer unsubscribe()

last := int64(0) // number of last seen block
for {
// Poll until:
// - L1 headers reader channel is closed, or
Expand All @@ -311,31 +313,38 @@ func (b *BatchPoster) pollForReverts(ctx context.Context) {
select {
case h, ok := <-headerCh:
if !ok {
log.Info("L1 headers channel has been closed")
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 last == 0 || last == h.Number.Int64() {
last = h.Number.Int64() - 1
if b.nextRevertCheckBlock == 0 || b.nextRevertCheckBlock > blockNum {
b.nextRevertCheckBlock = blockNum
}
if h.Number.Int64()-last > 100 {
log.Warn("Large gap between last seen and current block number, skipping check for reverts", "last", last, "current", h.Number)
last = 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, last+1, h.Number.Int64())
reverted, err := b.checkReverts(ctx, blockNum)
if err != nil {
log.Error("Checking batch reverts", "error", err)
logLevel := log.Error
if strings.Contains(err.Error(), "not found") {
// Just parent chain node inconsistency
// One node sent us a block, but another didn't have it
// We'll try to check this block again next loop
logLevel = log.Debug
}
logLevel("Error checking batch reverts", "err", err)
continue
}
if reverted {
b.batchReverted.Store(true)
return
}
last = h.Number.Int64()
case <-ctx.Done():
return
}
Expand Down
12 changes: 6 additions & 6 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ func NewDataPoster(db ethdb.Database, headerReader *headerreader.HeaderReader, a
switch {
case initConfig.UseNoOpStorage:
queue = &noop.Storage{}
case initConfig.UseLevelDB:
queue = leveldb.New(db, func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} })
case redisClient == nil:
queue = slice.NewStorage(func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} })
default:
case redisClient != nil:
var err error
queue, err = redisstorage.NewStorage(redisClient, "data-poster.queue", &initConfig.RedisSigner, encF)
if err != nil {
return nil, err
}
case initConfig.UseLevelDB:
queue = leveldb.New(db, func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} })
default:
queue = slice.NewStorage(func() storage.EncoderDecoderInterface { return &storage.EncoderDecoder{} })
}
return &DataPoster{
headerReader: headerReader,
Expand Down Expand Up @@ -665,7 +665,7 @@ var DefaultDataPosterConfig = DataPosterConfig{
MaxTipCapGwei: 5,
NonceRbfSoftConfs: 1,
AllocateMempoolBalance: true,
UseLevelDB: false,
UseLevelDB: true,
UseNoOpStorage: false,
LegacyStorageEncoding: true,
}
Expand Down
1 change: 1 addition & 0 deletions arbnode/dataposter/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
ErrStorageRace = errors.New("storage race error")

BlockValidatorPrefix string = "v" // the prefix for all block validator keys
StakerPrefix string = "S" // the prefix for all staker keys
BatchPosterPrefix string = "b" // the prefix for all batch poster keys
// TODO(anodar): move everything else from schema.go file to here once
// execution split is complete.
Expand Down
4 changes: 2 additions & 2 deletions arbnode/delayed_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func DelayedSequencerConfigAddOptions(prefix string, f *flag.FlagSet) {
var DefaultDelayedSequencerConfig = DelayedSequencerConfig{
Enable: false,
FinalizeDistance: 20,
RequireFullFinality: true,
RequireFullFinality: false,
UseMergeFinality: true,
}

var TestDelayedSequencerConfig = DelayedSequencerConfig{
Enable: true,
FinalizeDistance: 20,
RequireFullFinality: true,
RequireFullFinality: false,
UseMergeFinality: true,
}

Expand Down
1 change: 1 addition & 0 deletions arbnode/execution/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ var DefaultSequencerConfig = SequencerConfig{
NonceCacheSize: 1024,
Dangerous: DefaultDangerousSequencerConfig,
// 95% of the default batch poster limit, leaving 5KB for headers and such
// This default is overridden for L3 chains in applyChainParameters in cmd/nitro/nitro.go
MaxTxDataSize: 95000,
NonceFailureCacheSize: 1024,
NonceFailureCacheExpiry: time.Second,
Expand Down
10 changes: 5 additions & 5 deletions arbnode/execution/tx_pre_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ func PreCheckTx(bc *core.BlockChain, chainConfig *params.ChainConfig, header *ty
if config.Strictness < TxPreCheckerStrictnessLikelyCompatible {
return nil
}
balance := statedb.GetBalance(sender)
cost := tx.Cost()
if arbmath.BigLessThan(balance, cost) {
return fmt.Errorf("%w: address %v have %v want %v", core.ErrInsufficientFunds, sender, balance, cost)
}
if options != nil {
if err := options.Check(extraInfo.L1BlockNumber, header.Time, statedb); err != nil {
conditionalTxRejectedByTxPreCheckerCurrentStateCounter.Inc(1)
Expand Down Expand Up @@ -185,6 +180,11 @@ func PreCheckTx(bc *core.BlockChain, chainConfig *params.ChainConfig, header *ty
conditionalTxAcceptedByTxPreCheckerOldStateCounter.Inc(1)
}
}
balance := statedb.GetBalance(sender)
cost := tx.Cost()
if arbmath.BigLessThan(balance, cost) {
return fmt.Errorf("%w: address %v have %v want %v", core.ErrInsufficientFunds, sender, balance, cost)
}
if config.Strictness >= TxPreCheckerStrictnessFullValidation && tx.Nonce() > stateNonce {
return MakeNonceError(sender, tx.Nonce(), stateNonce)
}
Expand Down
23 changes: 9 additions & 14 deletions 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 @@ -234,19 +235,12 @@ func GenerateRollupConfig(prod bool, wasmModuleRoot common.Hash, rollupOwner com
}
}

func DeployOnL1(ctx context.Context, l1client arbutil.L1Interface, deployAuth *bind.TransactOpts, batchPoster common.Address, authorizeValidators uint64, readerConfig headerreader.ConfigFetcher, config rollupgen.Config) (*chaininfo.RollupAddresses, error) {
l1Reader, err := headerreader.New(ctx, l1client, readerConfig)
if err != nil {
return nil, err
}
l1Reader.Start(ctx)
defer l1Reader.StopAndWait()

func DeployOnL1(ctx context.Context, parentChainReader *headerreader.HeaderReader, deployAuth *bind.TransactOpts, batchPoster common.Address, authorizeValidators uint64, config rollupgen.Config) (*chaininfo.RollupAddresses, error) {
if config.WasmModuleRoot == (common.Hash{}) {
return nil, errors.New("no machine specified")
}

rollupCreator, _, validatorUtils, validatorWalletCreator, err := deployRollupCreator(ctx, l1Reader, deployAuth)
rollupCreator, _, validatorUtils, validatorWalletCreator, err := deployRollupCreator(ctx, parentChainReader, deployAuth)
if err != nil {
return nil, fmt.Errorf("error deploying rollup creator: %w", err)
}
Expand All @@ -265,7 +259,7 @@ func DeployOnL1(ctx context.Context, l1client arbutil.L1Interface, deployAuth *b
if err != nil {
return nil, fmt.Errorf("error submitting create rollup tx: %w", err)
}
receipt, err := l1Reader.WaitForTxApproval(ctx, tx)
receipt, err := parentChainReader.WaitForTxApproval(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error executing create rollup tx: %w", err)
}
Expand Down Expand Up @@ -545,7 +539,7 @@ func checkArbDbSchemaVersion(arbDb ethdb.Database) error {
return nil
}

func ValidatorDataposter(
func StakerDataposter(
db ethdb.Database, l1Reader *headerreader.HeaderReader,
transactOpts *bind.TransactOpts, cfgFetcher ConfigFetcher, syncMonitor *SyncMonitor,
) (*dataposter.DataPoster, error) {
Expand Down Expand Up @@ -611,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 Expand Up @@ -809,8 +804,8 @@ func createNodeImpl(
var messagePruner *MessagePruner

if config.Staker.Enable {
dp, err := ValidatorDataposter(
rawdb.NewTable(arbDb, storage.BlockValidatorPrefix),
dp, err := StakerDataposter(
rawdb.NewTable(arbDb, storage.StakerPrefix),
l1Reader,
txOptsValidator,
configFetcher,
Expand Down
6 changes: 5 additions & 1 deletion cmd/chaininfo/arbitrum_chain_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"chain-name": "arb1",
"parent-chain-id": 1,
"parent-chain-is-arbitrum": false,
"sequencer-url": "https://arb1-sequencer.arbitrum.io/rpc",
"feed-url": "wss://arb1.arbitrum.io/feed",
"has-genesis-state": true,
Expand Down Expand Up @@ -51,6 +52,7 @@
{
"chain-name": "nova",
"parent-chain-id": 1,
"parent-chain-is-arbitrum": false,
"sequencer-url": "https://nova.arbitrum.io/rpc",
"feed-url": "wss://nova.arbitrum.io/feed",
"das-index-url": "https://nova.arbitrum.io/das-servers",
Expand Down Expand Up @@ -100,6 +102,7 @@
{
"chain-name": "goerli-rollup",
"parent-chain-id": 5,
"parent-chain-is-arbitrum": false,
"sequencer-url": "https://goerli-rollup.arbitrum.io/rpc",
"feed-url": "wss://goerli-rollup.arbitrum.io/feed",
"chain-config":
Expand Down Expand Up @@ -215,9 +218,10 @@
}
}
},
{
{
"chain-id": 421614,
"parent-chain-id": 11155111,
"parent-chain-is-arbitrum": false,
"chain-name": "sepolia-rollup",
"sequencer-url": "https://sepolia-rollup-sequencer.arbitrum.io/rpc",
"feed-url": "wss://sepolia-rollup.arbitrum.io/feed",
Expand Down
5 changes: 3 additions & 2 deletions cmd/chaininfo/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
var DefaultChainInfo []byte

type ChainInfo struct {
ChainName string `json:"chain-name"`
ParentChainId uint64 `json:"parent-chain-id"`
ChainName string `json:"chain-name"`
ParentChainId uint64 `json:"parent-chain-id"`
ParentChainIsArbitrum *bool `json:"parent-chain-is-arbitrum"`
// This is the forwarding target to submit transactions to, called the sequencer URL for clarity
SequencerUrl string `json:"sequencer-url"`
FeedUrl string `json:"feed-url"`
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
Loading

0 comments on commit e8c44f6

Please sign in to comment.