Skip to content

Commit

Permalink
Merge branch 'master' into Consolidate_arbos_constants
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi committed Dec 23, 2024
2 parents a09823c + d74229c commit 68a48f6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 11 deletions.
10 changes: 6 additions & 4 deletions arbos/l1pricing/l1pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"math/big"
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -520,10 +519,13 @@ func (ps *L1PricingState) GetPosterInfo(tx *types.Transaction, poster common.Add
if poster != BatchPosterAddress {
return common.Big0, 0
}
units := atomic.LoadUint64(&tx.CalldataUnits)
if units == 0 {
var units uint64
if cachedUnits := tx.GetCachedCalldataUnits(brotliCompressionLevel); cachedUnits != nil {
units = *cachedUnits
} else {
// The cache is empty or invalid, so we need to compute the calldata units
units = ps.getPosterUnitsWithoutCache(tx, poster, brotliCompressionLevel)
atomic.StoreUint64(&tx.CalldataUnits, units)
tx.SetCachedCalldataUnits(brotliCompressionLevel, units)
}

// Approximate the l1 fee charged for posting this tx's calldata
Expand Down
6 changes: 5 additions & 1 deletion cmd/conf/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ func (c *PersistentConfig) Validate() error {
}

type PebbleConfig struct {
SyncMode bool `koanf:"sync-mode"`
MaxConcurrentCompactions int `koanf:"max-concurrent-compactions"`
Experimental PebbleExperimentalConfig `koanf:"experimental"`
}

var PebbleConfigDefault = PebbleConfig{
SyncMode: false, // use NO-SYNC mode, see: https://github.com/ethereum/go-ethereum/issues/29819
MaxConcurrentCompactions: runtime.NumCPU(),
Experimental: PebbleExperimentalConfigDefault,
}

func PebbleConfigAddOptions(prefix string, f *flag.FlagSet, defaultConfig *PebbleConfig) {
f.Bool(prefix+".sync-mode", defaultConfig.SyncMode, "if true sync mode is used (data needs to be written to WAL before the write is marked as completed)")
f.Int(prefix+".max-concurrent-compactions", defaultConfig.MaxConcurrentCompactions, "maximum number of concurrent compactions")
PebbleExperimentalConfigAddOptions(prefix+".experimental", f, &defaultConfig.Experimental)
}
Expand Down Expand Up @@ -180,7 +183,7 @@ var PebbleExperimentalConfigDefault = PebbleExperimentalConfig{
BlockSize: 4 << 10, // 4 KB
IndexBlockSize: 4 << 10, // 4 KB
TargetFileSize: 2 << 20, // 2 MB
TargetFileSizeEqualLevels: true,
TargetFileSizeEqualLevels: false,

L0CompactionConcurrency: 10,
CompactionDebtConcurrency: 1 << 30, // 1GB
Expand Down Expand Up @@ -251,6 +254,7 @@ func (c *PebbleConfig) ExtraOptions(namespace string) *pebble.ExtraOptions {
walDir = path.Join(walDir, namespace)
}
return &pebble.ExtraOptions{
SyncMode: c.SyncMode,
BytesPerSync: c.Experimental.BytesPerSync,
L0CompactionFileThreshold: c.Experimental.L0CompactionFileThreshold,
L0CompactionThreshold: c.Experimental.L0CompactionThreshold,
Expand Down
3 changes: 2 additions & 1 deletion execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ func (s *ExecutionEngine) cacheL1PriceDataOfMsg(seqNum arbutil.MessageIndex, rec
gasUsedForL1 += receipts[i].GasUsedForL1
}
for _, tx := range block.Transactions() {
callDataUnits += tx.CalldataUnits
_, cachedUnits := tx.GetRawCachedCalldataUnits()
callDataUnits += cachedUnits
}
}
l1GasCharged := gasUsedForL1 * block.BaseFee().Uint64()
Expand Down
3 changes: 0 additions & 3 deletions staker/legacy/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,6 @@ func NewStaker(
return nil, err
}
stakerLastSuccessfulActionGauge.Update(time.Now().Unix())
if config().StartValidationFromStaked && blockValidator != nil {
stakedNotifiers = append(stakedNotifiers, blockValidator)
}
inactiveValidatedNodes := btree.NewG(2, func(a, b validatedNode) bool {
return a.number < b.number || (a.number == b.number && a.hash.Cmp(b.hash) < 0)
})
Expand Down
87 changes: 86 additions & 1 deletion system_tests/arbos_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/offchainlabs/nitro/arbnode"
"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/solgen/go/mocksgen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
)
Expand Down Expand Up @@ -81,7 +82,7 @@ func checkArbOSVersion(t *testing.T, testClient *TestClient, expectedVersion uin

}

func TestArbos11To32Upgrade(t *testing.T) {
func TestArbos11To32UpgradeWithMcopy(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -184,3 +185,87 @@ func TestArbos11To32Upgrade(t *testing.T) {
t.Errorf("expected sequencer and replica to have same block hash, got %v and %v", blockSeq.Hash(), blockReplica.Hash())
}
}

func TestArbos11To32UpgradeWithCalldata(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

initialVersion := uint64(11)
finalVersion := uint64(32)

builder := NewNodeBuilder(ctx).
DefaultConfig(t, true).
WithArbOSVersion(initialVersion)
builder.execConfig.TxPreChecker.Strictness = gethexec.TxPreCheckerStrictnessLikelyCompatible
cleanup := builder.Build(t)
defer cleanup()
seqTestClient := builder.L2

auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)
auth.GasLimit = 32000000

// makes Owner a chain owner
arbDebug, err := precompilesgen.NewArbDebug(types.ArbDebugAddress, seqTestClient.Client)
Require(t, err)
tx, err := arbDebug.BecomeChainOwner(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, seqTestClient.Client, tx)
Require(t, err)

// build replica node
replicaConfig := arbnode.ConfigDefaultL1Test()
replicaConfig.BatchPoster.Enable = false
replicaTestClient, replicaCleanup := builder.Build2ndNode(t, &SecondNodeParams{nodeConfig: replicaConfig})
defer replicaCleanup()

checkArbOSVersion(t, seqTestClient, initialVersion, "initial sequencer")
checkArbOSVersion(t, replicaTestClient, initialVersion, "initial replica")

// upgrade arbos to final version
arbOwner, err := precompilesgen.NewArbOwner(types.ArbOwnerAddress, seqTestClient.Client)
Require(t, err)
tx, err = arbOwner.ScheduleArbOSUpgrade(&auth, finalVersion, 0)
Require(t, err)
_, err = seqTestClient.EnsureTxSucceeded(tx)
Require(t, err)
_, err = WaitForTx(ctx, replicaTestClient.Client, tx.Hash(), time.Second*15)
Require(t, err)

// checks upgrade worked
var data []byte
for i := range 10 {
for range 100 {
data = append(data, byte(i))
}
}
tx = builder.L2Info.PrepareTx("Owner", "Owner", builder.L2Info.TransferGas, big.NewInt(1e12), data)
err = seqTestClient.Client.SendTransaction(ctx, tx)
Require(t, err)
_, err = seqTestClient.EnsureTxSucceeded(tx)
Require(t, err)
_, err = WaitForTx(ctx, replicaTestClient.Client, tx.Hash(), time.Second*15)
Require(t, err)

checkArbOSVersion(t, seqTestClient, finalVersion, "final sequencer")
checkArbOSVersion(t, replicaTestClient, finalVersion, "final replica")

blockNumberSeq, err := seqTestClient.Client.BlockNumber(ctx)
Require(t, err)
blockNumberReplica, err := replicaTestClient.Client.BlockNumber(ctx)
Require(t, err)
if blockNumberSeq != blockNumberReplica {
t.Errorf("expected sequencer and replica to have same block number, got %v and %v", blockNumberSeq, blockNumberReplica)
}
// #nosec G115
blockNumber := big.NewInt(int64(blockNumberSeq))

blockSeq, err := seqTestClient.Client.BlockByNumber(ctx, blockNumber)
Require(t, err)
blockReplica, err := replicaTestClient.Client.BlockByNumber(ctx, blockNumber)
Require(t, err)
if blockSeq.Hash() != blockReplica.Hash() {
t.Errorf("expected sequencer and replica to have same block hash, got %v and %v", blockSeq.Hash(), blockReplica.Hash())
}
}

0 comments on commit 68a48f6

Please sign in to comment.