Skip to content

Commit

Permalink
Merge branch 'master' into secp256r1-precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Apr 29, 2024
2 parents 2139931 + 82988d5 commit 2d7b153
Show file tree
Hide file tree
Showing 50 changed files with 1,708 additions and 405 deletions.
7 changes: 3 additions & 4 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
Enable: false,
DisableDasFallbackStoreDataOnChain: false,
// This default is overridden for L3 chains in applyChainParameters in cmd/nitro/nitro.go
MaxSize: 100000,
// TODO: is 1000 bytes an appropriate margin for error vs blob space efficiency?
Max4844BatchSize: blobs.BlobEncodableData*(params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob) - 1000,
MaxSize: 100000,
Max4844BatchSize: blobs.BlobEncodableData*(params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob) - 2000,
PollInterval: time.Second * 10,
ErrorDelay: time.Second * 10,
MaxDelay: time.Hour,
Expand Down Expand Up @@ -1278,7 +1277,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
return false, err
}
if len(kzgBlobs)*params.BlobTxBlobGasPerBlob > params.MaxBlobGasPerBlock {
return false, fmt.Errorf("produced %v blobs for batch but a block can only hold %v", len(kzgBlobs), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
return false, fmt.Errorf("produced %v blobs for batch but a block can only hold %v (compressed batch was %v bytes long)", len(kzgBlobs), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob, len(sequencerMsg))
}
accessList := b.accessList(int(batchPosition.NextSeqNum), int(b.building.segments.delayedMsg))
// On restart, we may be trying to estimate gas for a batch whose successor has
Expand Down
45 changes: 42 additions & 3 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,37 @@ func (p *DataPoster) sendTx(ctx context.Context, prevTx *storage.QueuedTransacti
if err := p.saveTx(ctx, prevTx, newTx); err != nil {
return err
}

// The following check is to avoid sending transactions of a different type (eg DynamicFeeTxType vs BlobTxType)
// to the previous tx if the previous tx is not yet included in a reorg resistant block, in order to avoid issues
// where eventual consistency of parent chain mempools causes a tx with higher nonce blocking a tx of a
// different type with a lower nonce.
// If we decide not to send this tx yet, just leave it queued and with Sent set to false.
// The resending/repricing loop in DataPoster.Start will keep trying.
if !newTx.Sent && newTx.FullTx.Nonce() > 0 {
precedingTx, err := p.queue.Get(ctx, arbmath.SaturatingUSub(newTx.FullTx.Nonce(), 1))
if err != nil {
return fmt.Errorf("couldn't get preceding tx in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err)
}
if precedingTx != nil && // precedingTx == nil -> the actual preceding tx was already confirmed
(precedingTx.FullTx.Type() != newTx.FullTx.Type() || !precedingTx.Sent) {
latestBlockNumber, err := p.client.BlockNumber(ctx)
if err != nil {
return fmt.Errorf("couldn't get block number in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err)
}
prevBlockNumber := arbmath.SaturatingUSub(latestBlockNumber, 1)
reorgResistantNonce, err := p.client.NonceAt(ctx, p.Sender(), new(big.Int).SetUint64(prevBlockNumber))
if err != nil {
return fmt.Errorf("couldn't determine reorg resistant nonce in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err)
}

if precedingTx.FullTx.Nonce() > reorgResistantNonce {
log.Info("DataPoster is avoiding creating a mempool nonce gap (the tx remains queued and will be retried)", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent)
return nil
}
}
}

if err := p.client.SendTransaction(ctx, newTx.FullTx); err != nil {
if !rpcclient.IsAlreadyKnownError(err) && !strings.Contains(err.Error(), "nonce too low") {
log.Warn("DataPoster failed to send transaction", "err", err, "nonce", newTx.FullTx.Nonce(), "feeCap", newTx.FullTx.GasFeeCap(), "tipCap", newTx.FullTx.GasTipCap(), "blobFeeCap", newTx.FullTx.BlobGasFeeCap(), "gas", newTx.FullTx.Gas())
Expand Down Expand Up @@ -1072,19 +1103,21 @@ func (p *DataPoster) Start(ctxIn context.Context) {
latestNonce = latestQueued.FullTx.Nonce()
}
for _, tx := range queueContents {
replacing := false
previouslyUnsent := !tx.Sent
sendAttempted := false
if now.After(tx.NextReplacement) {
replacing = true
nonceBacklog := arbmath.SaturatingUSub(latestNonce, tx.FullTx.Nonce())
weightBacklog := arbmath.SaturatingUSub(latestCumulativeWeight, tx.CumulativeWeight())
err := p.replaceTx(ctx, tx, arbmath.MaxInt(nonceBacklog, weightBacklog))
sendAttempted = true
p.maybeLogError(err, tx, "failed to replace-by-fee transaction")
}
if nextCheck.After(tx.NextReplacement) {
nextCheck = tx.NextReplacement
}
if !replacing && !tx.Sent {
if !sendAttempted && previouslyUnsent {
err := p.sendTx(ctx, tx, tx)
sendAttempted = true
p.maybeLogError(err, tx, "failed to re-send transaction")
if err != nil {
nextSend := time.Now().Add(time.Minute)
Expand All @@ -1093,6 +1126,12 @@ func (p *DataPoster) Start(ctxIn context.Context) {
}
}
}
if previouslyUnsent && sendAttempted {
// Don't try to send more than 1 unsent transaction, to play nicely with parent chain mempools.
// Transactions will be unsent if there was some error when originally sending them,
// or if transaction type changes and the prior tx is not yet reorg resistant.
break
}
}
wait := time.Until(nextCheck)
if wait < minWait {
Expand Down
2 changes: 1 addition & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func createNodeImpl(
txStreamer.SetInboxReaders(inboxReader, delayedBridge)

var statelessBlockValidator *staker.StatelessBlockValidator
if config.BlockValidator.ValidationServerConfigs[0].URL != "" {
if config.BlockValidator.RedisValidationClientConfig.Enabled() || config.BlockValidator.ValidationServerConfigs[0].URL != "" {
statelessBlockValidator, err = staker.NewStatelessBlockValidator(
inboxReader,
inboxTracker,
Expand Down
48 changes: 30 additions & 18 deletions arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,26 @@ import (
// persisted beyond the end of the test.)

type ArbosState struct {
arbosVersion uint64 // version of the ArbOS storage format and semantics
upgradeVersion storage.StorageBackedUint64 // version we're planning to upgrade to, or 0 if not planning to upgrade
upgradeTimestamp storage.StorageBackedUint64 // when to do the planned upgrade
networkFeeAccount storage.StorageBackedAddress
l1PricingState *l1pricing.L1PricingState
l2PricingState *l2pricing.L2PricingState
retryableState *retryables.RetryableState
addressTable *addressTable.AddressTable
chainOwners *addressSet.AddressSet
sendMerkle *merkleAccumulator.MerkleAccumulator
blockhashes *blockhash.Blockhashes
chainId storage.StorageBackedBigInt
chainConfig storage.StorageBackedBytes
genesisBlockNum storage.StorageBackedUint64
infraFeeAccount storage.StorageBackedAddress
brotliCompressionLevel storage.StorageBackedUint64 // brotli compression level used for pricing
backingStorage *storage.Storage
Burner burn.Burner
arbosVersion uint64 // version of the ArbOS storage format and semantics
maxArbosVersionSupported uint64 // maximum ArbOS version supported by this code
maxDebugArbosVersionSupported uint64 // maximum ArbOS version supported by this code in debug mode
upgradeVersion storage.StorageBackedUint64 // version we're planning to upgrade to, or 0 if not planning to upgrade
upgradeTimestamp storage.StorageBackedUint64 // when to do the planned upgrade
networkFeeAccount storage.StorageBackedAddress
l1PricingState *l1pricing.L1PricingState
l2PricingState *l2pricing.L2PricingState
retryableState *retryables.RetryableState
addressTable *addressTable.AddressTable
chainOwners *addressSet.AddressSet
sendMerkle *merkleAccumulator.MerkleAccumulator
blockhashes *blockhash.Blockhashes
chainId storage.StorageBackedBigInt
chainConfig storage.StorageBackedBytes
genesisBlockNum storage.StorageBackedUint64
infraFeeAccount storage.StorageBackedAddress
brotliCompressionLevel storage.StorageBackedUint64 // brotli compression level used for pricing
backingStorage *storage.Storage
Burner burn.Burner
}

var ErrUninitializedArbOS = errors.New("ArbOS uninitialized")
Expand All @@ -70,6 +72,8 @@ func OpenArbosState(stateDB vm.StateDB, burner burn.Burner) (*ArbosState, error)
}
return &ArbosState{
arbosVersion,
20,
20,
backingStorage.OpenStorageBackedUint64(uint64(upgradeVersionOffset)),
backingStorage.OpenStorageBackedUint64(uint64(upgradeTimestampOffset)),
backingStorage.OpenStorageBackedAddress(uint64(networkFeeAccountOffset)),
Expand Down Expand Up @@ -400,6 +404,14 @@ func (state *ArbosState) RetryableState() *retryables.RetryableState {
return state.retryableState
}

func (state *ArbosState) MaxArbosVersionSupported() uint64 {
return state.maxArbosVersionSupported
}

func (state *ArbosState) MaxDebugArbosVersionSupported() uint64 {
return state.maxDebugArbosVersionSupported
}

func (state *ArbosState) L1PricingState() *l1pricing.L1PricingState {
return state.l1PricingState
}
Expand Down
13 changes: 8 additions & 5 deletions cmd/daserver/daserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"golang.org/x/exp/slog"

koanfjson "github.com/knadh/koanf/parsers/json"
flag "github.com/spf13/pflag"

Expand Down Expand Up @@ -182,14 +185,14 @@ func startup() error {
confighelpers.PrintErrorAndExit(errors.New("please specify at least one of --enable-rest or --enable-rpc"), printSampleUsage)
}

logFormat, err := genericconf.ParseLogType(serverConfig.LogType)
handler, err := genericconf.HandlerFromLogType(serverConfig.LogType, io.Writer(os.Stderr))
if err != nil {
flag.Usage()
panic(fmt.Sprintf("Error parsing log type: %v", err))
return fmt.Errorf("error parsing log type when creating handler: %w", err)
}
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, logFormat))
glogger.Verbosity(log.Lvl(serverConfig.LogLevel))
log.Root().SetHandler(glogger)
glogger := log.NewGlogHandler(handler)
glogger.Verbosity(slog.Level(serverConfig.LogLevel))
log.SetDefault(log.NewLogger(glogger))

if err := startMetrics(serverConfig); err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"math/big"
"os"
"strings"
Expand All @@ -30,9 +31,10 @@ import (
)

func main() {
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false)))
glogger := log.NewGlogHandler(
log.NewTerminalHandler(io.Writer(os.Stderr), false))
glogger.Verbosity(log.LvlDebug)
log.Root().SetHandler(glogger)
log.SetDefault(log.NewLogger(glogger))
log.Info("deploying rollup")

ctx := context.Background()
Expand Down
8 changes: 5 additions & 3 deletions cmd/genericconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package genericconf

import (
"errors"
"io"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
flag "github.com/spf13/pflag"
"golang.org/x/exp/slog"
)

type ConfConfig struct {
Expand Down Expand Up @@ -63,11 +65,11 @@ var DefaultS3Config = S3Config{
SecretKey: "",
}

func ParseLogType(logType string) (log.Format, error) {
func HandlerFromLogType(logType string, output io.Writer) (slog.Handler, error) {
if logType == "plaintext" {
return log.TerminalFormat(false), nil
return log.NewTerminalHandler(output, false), nil
} else if logType == "json" {
return log.JSONFormat(), nil
return log.JSONHandler(output), nil
}
return nil, errors.New("invalid log type")
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/genericconf/filehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ func testFileHandler(t *testing.T, testCompressed bool) {
config.MaxSize = 1
config.Compress = testCompressed
config.File = testFile
fileHandler := globalFileHandlerFactory.newHandler(log.JSONFormat(), &config, testFile)
defer func() { testhelpers.RequireImpl(t, globalFileHandlerFactory.close()) }()
log.Root().SetHandler(fileHandler)
handler, err := HandlerFromLogType("json", globalFileLoggerFactory.newFileWriter(&config, testFile))
defer func() { testhelpers.RequireImpl(t, globalFileLoggerFactory.close()) }()
testhelpers.RequireImpl(t, err)
log.SetDefault(log.NewLogger(handler))
expected := []string{"dead", "beef", "ate", "bad", "beef"}
for _, e := range expected {
log.Warn(e)
Expand Down
Loading

0 comments on commit 2d7b153

Please sign in to comment.