Skip to content

Commit

Permalink
Consolidate ArbOS version constants into a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi committed Dec 20, 2024
1 parent 3b646ad commit d540d2a
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 92 deletions.
2 changes: 1 addition & 1 deletion arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
if err != nil {
return false, err
}
if arbOSVersion >= 20 {
if arbOSVersion >= params.ArbosVersion_20 {
if config.IgnoreBlobPrice {
use4844 = true
} else {
Expand Down
3 changes: 2 additions & 1 deletion arbos/addressSet/addressSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/storage"
"github.com/offchainlabs/nitro/arbos/util"
Expand Down Expand Up @@ -185,7 +186,7 @@ func (as *AddressSet) Remove(addr common.Address, arbosVersion uint64) error {
if err != nil {
return err
}
if arbosVersion >= 11 {
if arbosVersion >= params.ArbosVersion_11 {
err = as.byAddress.Set(atSize, util.UintToHash(slot))
if err != nil {
return err
Expand Down
39 changes: 18 additions & 21 deletions arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type ArbosState struct {
Burner burn.Burner
}

const MaxArbosVersionSupported uint64 = params.ArbosVersion_StylusChargingFixes
const MaxDebugArbosVersionSupported uint64 = params.ArbosVersion_StylusChargingFixes

var ErrUninitializedArbOS = errors.New("ArbOS uninitialized")
var ErrAlreadyInitialized = errors.New("ArbOS is already initialized")

Expand Down Expand Up @@ -205,7 +202,7 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p
_ = sto.SetUint64ByUint64(uint64(versionOffset), 1) // initialize to version 1; upgrade at end of this func if needed
_ = sto.SetUint64ByUint64(uint64(upgradeVersionOffset), 0)
_ = sto.SetUint64ByUint64(uint64(upgradeTimestampOffset), 0)
if desiredArbosVersion >= 2 {
if desiredArbosVersion >= params.ArbosVersion_2 {
_ = sto.SetByUint64(uint64(networkFeeAccountOffset), util.AddressToHash(initialChainOwner))
} else {
_ = sto.SetByUint64(uint64(networkFeeAccountOffset), common.Hash{}) // the 0 address until an owner sets it
Expand All @@ -217,7 +214,7 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p
_ = sto.SetUint64ByUint64(uint64(brotliCompressionLevelOffset), 0) // default brotliCompressionLevel for fast compression is 0

initialRewardsRecipient := l1pricing.BatchPosterAddress
if desiredArbosVersion >= 2 {
if desiredArbosVersion >= params.ArbosVersion_2 {
initialRewardsRecipient = initialChainOwner
}
_ = l1pricing.InitializeL1PricingState(sto.OpenCachedSubStorage(l1PricingSubspace), initialRewardsRecipient, initMessage.InitialL1BaseFee)
Expand Down Expand Up @@ -274,29 +271,29 @@ func (state *ArbosState) UpgradeArbosVersion(

nextArbosVersion := state.arbosVersion + 1
switch nextArbosVersion {
case 2:
case params.ArbosVersion_2:
ensure(state.l1PricingState.SetLastSurplus(common.Big0, 1))
case 3:
case params.ArbosVersion_3:
ensure(state.l1PricingState.SetPerBatchGasCost(0))
ensure(state.l1PricingState.SetAmortizedCostCapBips(math.MaxUint64))
case 4:
case params.ArbosVersion_4:
// no state changes needed
case 5:
case params.ArbosVersion_5:
// no state changes needed
case 6:
case params.ArbosVersion_6:
// no state changes needed
case 7:
case params.ArbosVersion_7:
// no state changes needed
case 8:
case params.ArbosVersion_8:
// no state changes needed
case 9:
case params.ArbosVersion_9:
// no state changes needed
case 10:
case params.ArbosVersion_10:
ensure(state.l1PricingState.SetL1FeesAvailable(stateDB.GetBalance(
l1pricing.L1PricerFundsPoolAddress,
).ToBig()))

case 11:
case params.ArbosVersion_11:
// Update the PerBatchGasCost to a more accurate value compared to the old v6 default.
ensure(state.l1PricingState.SetPerBatchGasCost(l1pricing.InitialPerBatchGasCostV12))

Expand All @@ -316,23 +313,23 @@ func (state *ArbosState) UpgradeArbosVersion(
case 12, 13, 14, 15, 16, 17, 18, 19:
// these versions are left to Orbit chains for custom upgrades.

case 20:
case params.ArbosVersion_20:
// Update Brotli compression level for fast compression from 0 to 1
ensure(state.SetBrotliCompressionLevel(1))

case 21, 22, 23, 24, 25, 26, 27, 28, 29:
// these versions are left to Orbit chains for custom upgrades.

case 30:
case params.ArbosVersion_30:
programs.Initialize(state.backingStorage.OpenSubStorage(programsSubspace))

case 31:
case params.ArbosVersion_31:
params, err := state.Programs().Params()
ensure(err)
ensure(params.UpgradeToVersion(2))
ensure(params.Save())

case 32:
case params.ArbosVersion_32:
// no change state needed

default:
Expand All @@ -353,8 +350,8 @@ func (state *ArbosState) UpgradeArbosVersion(
state.arbosVersion = nextArbosVersion
}

if firstTime && upgradeTo >= 6 {
if upgradeTo < 11 {
if firstTime && upgradeTo >= params.ArbosVersion_6 {
if upgradeTo < params.ArbosVersion_11 {
state.Restrict(state.l1PricingState.SetPerBatchGasCost(l1pricing.InitialPerBatchGasCostV6))
}
state.Restrict(state.l1PricingState.SetEquilibrationUnits(l1pricing.InitialEquilibrationUnitsV6))
Expand Down
3 changes: 2 additions & 1 deletion arbos/blockhash/blockhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/storage"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ func (bh *Blockhashes) RecordNewL1Block(number uint64, blockHash common.Hash, ar
// fill in hashes for any "skipped over" blocks
nextNumber++
var nextNumBuf [8]byte
if arbosVersion >= 8 {
if arbosVersion >= params.ArbosVersion_8 {
binary.LittleEndian.PutUint64(nextNumBuf[:], nextNumber)
}

Expand Down
3 changes: 2 additions & 1 deletion arbos/blockhash/blockhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/arbos/storage"
"github.com/offchainlabs/nitro/util/testhelpers"
)

func TestBlockhash(t *testing.T) {
arbosVersion := uint64(8)
arbosVersion := params.ArbosVersion_8

sto := storage.NewMemoryBacked(burn.NewSystemBurner(nil, false))
InitializeBlockhashes(sto)
Expand Down
5 changes: 3 additions & 2 deletions arbos/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/util"
Expand Down Expand Up @@ -56,11 +57,11 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos

l1BlockNumber := util.SafeMapGet[uint64](inputs, "l1BlockNumber")
timePassed := util.SafeMapGet[uint64](inputs, "timePassed")
if state.ArbOSVersion() < 3 {
if state.ArbOSVersion() < params.ArbosVersion_3 {
// (incorrectly) use the L2 block number instead
timePassed = util.SafeMapGet[uint64](inputs, "l2BlockNumber")
}
if state.ArbOSVersion() < 8 {
if state.ArbOSVersion() < params.ArbosVersion_8 {
// in old versions we incorrectly used an L1 block number one too high
l1BlockNumber++
}
Expand Down
5 changes: 3 additions & 2 deletions arbos/l1pricing/l1PricingOldVersions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/util"
am "github.com/offchainlabs/nitro/util/arbmath"
Expand All @@ -24,7 +25,7 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
l1Basefee *big.Int,
scenario util.TracingScenario,
) error {
if arbosVersion < 2 {
if arbosVersion < params.ArbosVersion_2 {
return ps._preVersion2_UpdateForBatchPosterSpending(statedb, evm, updateTime, currentTime, batchPoster, weiSpent, scenario)
}

Expand Down Expand Up @@ -69,7 +70,7 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
}

// impose cap on amortized cost, if there is one
if arbosVersion >= 3 {
if arbosVersion >= params.ArbosVersion_3 {
amortizedCostCapBips, err := ps.AmortizedCostCapBips()
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions arbos/l1pricing/l1pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (ps *L1PricingState) LastSurplus() (*big.Int, error) {
}

func (ps *L1PricingState) SetLastSurplus(val *big.Int, arbosVersion uint64) error {
if arbosVersion < 7 {
if arbosVersion < params.ArbosVersion_7 {
return ps.lastSurplus.Set_preVersion7(val)
}
return ps.lastSurplus.SetSaturatingWithWarning(val, "L1 pricer last surplus")
Expand Down Expand Up @@ -309,7 +309,7 @@ func (ps *L1PricingState) UpdateForBatchPosterSpending(
l1Basefee *big.Int,
scenario util.TracingScenario,
) error {
if arbosVersion < 10 {
if arbosVersion < params.ArbosVersion_10 {
return ps._preversion10_UpdateForBatchPosterSpending(statedb, evm, arbosVersion, updateTime, currentTime, batchPoster, weiSpent, l1Basefee, scenario)
}

Expand Down Expand Up @@ -359,7 +359,7 @@ func (ps *L1PricingState) UpdateForBatchPosterSpending(
}

// impose cap on amortized cost, if there is one
if arbosVersion >= 3 {
if arbosVersion >= params.ArbosVersion_3 {
amortizedCostCapBips, err := ps.AmortizedCostCapBips()
if err != nil {
return err
Expand Down
16 changes: 8 additions & 8 deletions arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (p *TxProcessor) StartTxHook() (endTxNow bool, gasUsed uint64, err error, r
// pay for the retryable's gas and update the pools
gascost := arbmath.BigMulByUint(effectiveBaseFee, usergas)
networkCost := gascost
if p.state.ArbOSVersion() >= 11 {
if p.state.ArbOSVersion() >= params.ArbosVersion_11 {
infraFeeAccount, err := p.state.InfraFeeAccount()
p.state.Restrict(err)
if infraFeeAccount != (common.Address{}) {
Expand Down Expand Up @@ -576,7 +576,7 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, success bool) {
takeFunds(maxRefund, arbmath.BigMulByUint(effectiveBaseFee, gasUsed))
// Refund any unused gas, without overdrafting the L1 deposit.
networkRefund := gasRefund
if p.state.ArbOSVersion() >= 11 {
if p.state.ArbOSVersion() >= params.ArbosVersion_11 {
infraFeeAccount, err := p.state.InfraFeeAccount()
p.state.Restrict(err)
if infraFeeAccount != (common.Address{}) {
Expand Down Expand Up @@ -629,7 +629,7 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, success bool) {
}

purpose := "feeCollection"
if p.state.ArbOSVersion() > 4 {
if p.state.ArbOSVersion() > params.ArbosVersion_4 {
infraFeeAccount, err := p.state.InfraFeeAccount()
p.state.Restrict(err)
if infraFeeAccount != (common.Address{}) {
Expand All @@ -646,11 +646,11 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, success bool) {
util.MintBalance(&networkFeeAccount, computeCost, p.evm, scenario, purpose)
}
posterFeeDestination := l1pricing.L1PricerFundsPoolAddress
if p.state.ArbOSVersion() < 2 {
if p.state.ArbOSVersion() < params.ArbosVersion_2 {
posterFeeDestination = p.evm.Context.Coinbase
}
util.MintBalance(&posterFeeDestination, p.PosterFee, p.evm, scenario, purpose)
if p.state.ArbOSVersion() >= 10 {
if p.state.ArbOSVersion() >= params.ArbosVersion_10 {
if _, err := p.state.L1PricingState().AddToL1FeesAvailable(p.PosterFee); err != nil {
log.Error("failed to update L1FeesAvailable: ", "err", err)
}
Expand Down Expand Up @@ -748,21 +748,21 @@ func (p *TxProcessor) L1BlockHash(blockCtx vm.BlockContext, l1BlockNumber uint64

func (p *TxProcessor) DropTip() bool {
version := p.state.ArbOSVersion()
return version != 9 || p.delayedInbox
return version != params.ArbosVersion_9 || p.delayedInbox
}

func (p *TxProcessor) GetPaidGasPrice() *big.Int {
gasPrice := p.evm.GasPrice
version := p.state.ArbOSVersion()
if version != 9 {
if version != params.ArbosVersion_9 {
// p.evm.Context.BaseFee is already lowered to 0 when vm runs with NoBaseFee flag and 0 gas price
gasPrice = p.evm.Context.BaseFee
}
return gasPrice
}

func (p *TxProcessor) GasPriceOp(evm *vm.EVM) *big.Int {
if p.state.ArbOSVersion() >= 3 {
if p.state.ArbOSVersion() >= params.ArbosVersion_3 {
return p.GetPaidGasPrice()
}
return evm.GasPrice
Expand Down
3 changes: 2 additions & 1 deletion arbos/util/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/util/arbmath"
)
Expand Down Expand Up @@ -66,7 +67,7 @@ func TransferBalance(
if arbmath.BigLessThan(balance.ToBig(), amount) {
return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount)
}
if evm.Context.ArbOSVersion < 30 && amount.Sign() == 0 {
if evm.Context.ArbOSVersion < params.ArbosVersion_30 && amount.Sign() == 0 {
evm.StateDB.CreateZombieIfDeleted(*from)
}
evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount), tracing.BalanceChangeTransfer)
Expand Down
8 changes: 4 additions & 4 deletions cmd/nitro/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ func validateBlockChain(blockChain *core.BlockChain, chainConfig *params.ChainCo
}
// Make sure we don't allow accidentally downgrading ArbOS
if chainConfig.DebugMode() {
if currentArbosState.ArbOSVersion() > arbosState.MaxDebugArbosVersionSupported {
return fmt.Errorf("attempted to launch node in debug mode with ArbOS version %v on ArbOS state with version %v", arbosState.MaxDebugArbosVersionSupported, currentArbosState.ArbOSVersion())
if currentArbosState.ArbOSVersion() > params.MaxDebugArbosVersionSupported {
return fmt.Errorf("attempted to launch node in debug mode with ArbOS version %v on ArbOS state with version %v", params.MaxDebugArbosVersionSupported, currentArbosState.ArbOSVersion())
}
} else {
if currentArbosState.ArbOSVersion() > arbosState.MaxArbosVersionSupported {
return fmt.Errorf("attempted to launch node with ArbOS version %v on ArbOS state with version %v", arbosState.MaxArbosVersionSupported, currentArbosState.ArbOSVersion())
if currentArbosState.ArbOSVersion() > params.MaxArbosVersionSupported {
return fmt.Errorf("attempted to launch node with ArbOS version %v on ArbOS state with version %v", params.MaxArbosVersionSupported, currentArbosState.ArbOSVersion())
}

}
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
6 changes: 3 additions & 3 deletions precompiles/ArbGasInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (con ArbGasInfo) GetPricesInWeiWithAggregator(
evm mech,
aggregator addr,
) (huge, huge, huge, huge, huge, huge, error) {
if c.State.ArbOSVersion() < 4 {
if c.State.ArbOSVersion() < params.ArbosVersion_4 {
return con._preVersion4_GetPricesInWeiWithAggregator(c, evm, aggregator)
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (con ArbGasInfo) GetPricesInWei(c ctx, evm mech) (huge, huge, huge, huge, h

// GetPricesInArbGasWithAggregator gets prices in ArbGas when using the provided aggregator
func (con ArbGasInfo) GetPricesInArbGasWithAggregator(c ctx, evm mech, aggregator addr) (huge, huge, huge, error) {
if c.State.ArbOSVersion() < 4 {
if c.State.ArbOSVersion() < params.ArbosVersion_4 {
return con._preVersion4_GetPricesInArbGasWithAggregator(c, evm, aggregator)
}
l1GasPrice, err := c.State.L1PricingState().PricePerUnit()
Expand Down Expand Up @@ -220,7 +220,7 @@ func (con ArbGasInfo) GetGasBacklogTolerance(c ctx, evm mech) (uint64, error) {

// GetL1PricingSurplus gets the surplus of funds for L1 batch posting payments (may be negative)
func (con ArbGasInfo) GetL1PricingSurplus(c ctx, evm mech) (*big.Int, error) {
if c.State.ArbOSVersion() < 10 {
if c.State.ArbOSVersion() < params.ArbosVersion_10 {
return con._preversion10_GetL1PricingSurplus(c, evm)
}
ps := c.State.L1PricingState()
Expand Down
3 changes: 2 additions & 1 deletion precompiles/ArbOwnerPublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package precompiles

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
)

// ArbOwnerPublic precompile provides non-owners with info about the current chain owners.
Expand Down Expand Up @@ -42,7 +43,7 @@ func (con ArbOwnerPublic) GetNetworkFeeAccount(c ctx, evm mech) (addr, error) {

// GetInfraFeeAccount gets the infrastructure fee collector
func (con ArbOwnerPublic) GetInfraFeeAccount(c ctx, evm mech) (addr, error) {
if c.State.ArbOSVersion() < 6 {
if c.State.ArbOSVersion() < params.ArbosVersion_6 {
return c.State.NetworkFeeAccount()
}
return c.State.InfraFeeAccount()
Expand Down
Loading

0 comments on commit d540d2a

Please sign in to comment.