Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 1 addition & 108 deletions arbnode/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/l2pricing"
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/validator"
"github.com/pkg/errors"
Expand Down Expand Up @@ -57,107 +56,6 @@ type ArbDebugAPI struct {
blockchain *core.BlockChain
}

type PricingModelHistoryPreExp struct {
First uint64 `json:"first"`
Timestamp []uint64 `json:"timestamp"`
BaseFee []*big.Int `json:"baseFee"`
RateEstimate []uint64 `json:"rateEstimate"`
GasPool []int64 `json:"gasPool"`
GasUsed []uint64 `json:"gasUsed"`
L1BaseFeeEstimate []*big.Int `json:"l1BaseFeeEstimate"`
L1BaseFeeUpdateTime []uint64 `json:"l1BaseFeeUpdateTime"`
GasPoolMax int64 `json:"gasPoolMax"`
GasPoolTarget uint64 `json:"gasPoolTarget"`
GasPoolWeight uint64 `json:"gasPoolWeight"`
SpeedLimit uint64 `json:"speedLimit"`
MaxPerBlockGasLimit uint64 `json:"maxPerBlockGasLimit"`
L1BaseFeeEstimateInertia uint64 `json:"l1BaseFeeEstimateInertia"`
}

func (api *ArbDebugAPI) PricingModelPreExp(ctx context.Context, start, end rpc.BlockNumber) (PricingModelHistoryPreExp, error) {
start, _ = api.blockchain.ClipToPostNitroGenesis(start)
end, _ = api.blockchain.ClipToPostNitroGenesis(end)

blocks := end.Int64() - start.Int64()
if blocks <= 0 {
return PricingModelHistoryPreExp{}, fmt.Errorf("invalid block range: %v to %v", start.Int64(), end.Int64())
}

history := PricingModelHistoryPreExp{
First: uint64(start),
Timestamp: make([]uint64, blocks),
BaseFee: make([]*big.Int, blocks),
RateEstimate: make([]uint64, blocks),
GasPool: make([]int64, blocks),
GasUsed: make([]uint64, blocks),
L1BaseFeeEstimate: make([]*big.Int, blocks),
L1BaseFeeUpdateTime: make([]uint64, blocks+1),
}

genesisBlock := api.blockchain.Config().ArbitrumChainParams.GenesisBlockNum
if start > rpc.BlockNumber(genesisBlock) {
state, _, err := stateAndHeader(api.blockchain, uint64(start)-1)
if err != nil {
return history, err
}
l1BaseFeeUpdateTime, err := state.L1PricingState().LastL1BaseFeeUpdateTime()
if err != nil {
return history, err
}
history.L1BaseFeeUpdateTime[0] = l1BaseFeeUpdateTime
}

for i := uint64(0); i < uint64(blocks); i++ {
state, header, err := stateAndHeader(api.blockchain, i+uint64(start))
if err != nil {
return history, err
}
l1Pricing := state.L1PricingState()
l2Pricing := state.L2PricingState()

if state.FormatVersion() >= l2pricing.FirstExponentialPricingVersion {
// blocks from here on use the new model so we'll zero-fill the remaining values
break
}

rateEstimate, _ := l2Pricing.RateEstimate()
gasPool, _ := l2Pricing.GasPool_preExp()
l1BaseFeeEstimate, _ := l1Pricing.L1BaseFeeEstimateWei()
l1BaseFeeUpdateTime, err := l1Pricing.LastL1BaseFeeUpdateTime()
if err != nil {
return history, err
}

history.Timestamp[i] = header.Time
history.BaseFee[i] = header.BaseFee
history.RateEstimate[i] = rateEstimate
history.GasPool[i] = gasPool
history.GasUsed[i] = header.GasUsed
history.L1BaseFeeEstimate[i] = l1BaseFeeEstimate
history.L1BaseFeeUpdateTime[i+1] = l1BaseFeeUpdateTime

if i == uint64(blocks)-1 {
speedLimit, _ := l2Pricing.SpeedLimitPerSecond()
gasPoolMax, _ := l2Pricing.GasPoolMax()
gasPoolTarget, _ := l2Pricing.GasPoolTarget()
gasPoolWeight, _ := l2Pricing.GasPoolWeight()
maxPerBlockGasLimit, _ := l2Pricing.MaxPerBlockGasLimit()
l1BaseFeeEstimateInertia, err := l1Pricing.L1BaseFeeEstimateInertia()
if err != nil {
return history, err
}
history.SpeedLimit = speedLimit
history.GasPoolMax = gasPoolMax
history.GasPoolTarget = uint64(gasPoolTarget)
history.GasPoolWeight = uint64(gasPoolWeight)
history.MaxPerBlockGasLimit = maxPerBlockGasLimit
history.L1BaseFeeEstimateInertia = l1BaseFeeEstimateInertia
}
}

return history, nil
}

type PricingModelHistory struct {
First uint64 `json:"first"`
Timestamp []uint64 `json:"timestamp"`
Expand Down Expand Up @@ -217,11 +115,6 @@ func (api *ArbDebugAPI) PricingModel(ctx context.Context, start, end rpc.BlockNu
history.Timestamp[i] = header.Time
history.BaseFee[i] = header.BaseFee

if state.FormatVersion() < l2pricing.FirstExponentialPricingVersion {
// this block doesn't use the exponential pricing model, so we'll zero-fill it
continue
}

gasBacklog, _ := l2Pricing.GasBacklog()
l1BaseFeeEstimate, _ := l1Pricing.L1BaseFeeEstimateWei()
l1BaseFeeUpdateTime, err := l1Pricing.LastL1BaseFeeUpdateTime()
Expand All @@ -236,7 +129,7 @@ func (api *ArbDebugAPI) PricingModel(ctx context.Context, start, end rpc.BlockNu

if i == uint64(blocks)-1 {
speedLimit, _ := l2Pricing.SpeedLimitPerSecond()
maxPerBlockGasLimit, _ := l2Pricing.MaxPerBlockGasLimit()
maxPerBlockGasLimit, _ := l2Pricing.PerBlockGasLimit()
l1BaseFeeEstimateInertia, err := l1Pricing.L1BaseFeeEstimateInertia()
minBaseFee, _ := l2Pricing.MinBaseFeeWei()
pricingInertia, _ := l2Pricing.PricingInertia()
Expand Down
27 changes: 5 additions & 22 deletions arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/offchainlabs/nitro/arbos/blockhash"
"github.com/offchainlabs/nitro/arbos/l2pricing"
"github.com/offchainlabs/nitro/util/arbmath"

"github.com/offchainlabs/nitro/arbos/addressSet"
"github.com/offchainlabs/nitro/arbos/burn"
Expand Down Expand Up @@ -184,7 +183,7 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p
}

arbosVersion = chainConfig.ArbitrumChainParams.InitialArbOSVersion
if arbosVersion < 1 || arbosVersion > 4 {
if arbosVersion != 1 {
return nil, fmt.Errorf("cannot initialize to unsupported ArbOS version %v", arbosVersion)
}

Expand All @@ -201,7 +200,7 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p
_ = sto.SetByUint64(uint64(chainIdOffset), common.BigToHash(chainConfig.ChainID))
_ = sto.SetUint64ByUint64(uint64(genesisBlockNumOffset), chainConfig.ArbitrumChainParams.GenesisBlockNum)
_ = l1pricing.InitializeL1PricingState(sto.OpenSubStorage(l1PricingSubspace))
_ = l2pricing.InitializeL2PricingState(sto.OpenSubStorage(l2PricingSubspace), arbosVersion)
_ = l2pricing.InitializeL2PricingState(sto.OpenSubStorage(l2PricingSubspace))
_ = retryables.InitializeRetryableState(sto.OpenSubStorage(retryablesSubspace))
addressTable.Initialize(sto.OpenSubStorage(addressTableSubspace))
merkleAccumulator.InitializeMerkleAccumulator(sto.OpenSubStorage(sendMerkleSubspace))
Expand All @@ -219,31 +218,15 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p
return OpenArbosState(stateDB, burner)
}

var TestnetUpgrade2Owner = common.HexToAddress("0x40Fd01b32e97803f12693517776826a71e2B8D5f")

func (state *ArbosState) UpgradeArbosVersionIfNecessary(currentTimestamp uint64, chainConfig *params.ChainConfig) {
upgradeTo, err := state.upgradeVersion.Get()
state.Restrict(err)
flagday, _ := state.upgradeTimestamp.Get()
if upgradeTo > state.arbosVersion && currentTimestamp >= flagday {
for upgradeTo > state.arbosVersion && currentTimestamp >= flagday {
if state.arbosVersion == 1 {
// Upgrade version 1->2 adds a chain owner for the testnet
if arbmath.BigEquals(chainConfig.ChainID, params.ArbitrumTestnetChainConfig().ChainID) {
state.Restrict(state.chainOwners.Add(TestnetUpgrade2Owner))
}
} else if state.arbosVersion == 2 {
// Upgrade version 2->3 has no state changes
} else if state.arbosVersion == 3 {
// Upgrade version 3->4 adds two fields to the L2 pricing model
// (We don't bother to remove no-longer-used fields, for safety
// and because they'll be removed when we telescope versions for re-launch.)
state.Restrict(state.l2PricingState.UpgradeToVersion4())
} else {
// code to upgrade to future versions will be put here
panic("Unable to perform requested ArbOS upgrade")
}
state.arbosVersion++
// code to upgrade to future versions will be put here
panic("Unable to perform requested ArbOS upgrade")
// state.arbosVersion++
}
state.Restrict(state.backingStorage.SetUint64ByUint64(uint64(versionOffset), state.arbosVersion))
}
Expand Down
2 changes: 1 addition & 1 deletion arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func ProduceBlockAdvanced(

header := createNewHeader(lastBlockHeader, l1Info, state, chainConfig)
signer := types.MakeSigner(chainConfig, header.Number)
gasLeft, _ := state.L2PricingState().PerBlockGasLimit(state.FormatVersion())
gasLeft, _ := state.L2PricingState().PerBlockGasLimit()
l1BlockNum := l1Info.l1BlockNumber

// Prepend a tx before all others to touch up the state (update the L1 block num, pricing pools, etc)
Expand Down
20 changes: 6 additions & 14 deletions arbos/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func InternalTxStartBlock(
if l1BaseFee == nil {
l1BaseFee = big.NewInt(0)
}
data, err := util.PackInternalTxDataStartBlock(l1BaseFee, lastHeader.BaseFee, l1BlockNum, timePassed)
data, err := util.PackInternalTxDataStartBlock(l1BaseFee, l1BlockNum, timePassed)
if err != nil {
panic(fmt.Sprintf("Failed to pack internal tx %v", err))
}
Expand All @@ -52,22 +52,14 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos
panic(err)
}
l1BaseFee, _ := inputs[0].(*big.Int) // current block's
l2BaseFee, _ := inputs[1].(*big.Int) // the last L2 block's base fee (which is the result of the calculation 2 blocks ago)
l1BlockNumber, _ := inputs[2].(uint64) // current block's
timePassed, _ := inputs[3].(uint64) // since last block
l1BlockNumber, _ := inputs[1].(uint64) // current block's
timePassed, _ := inputs[2].(uint64) // since last block

nextL1BlockNumber, err := state.Blockhashes().NextBlockNumber()
state.Restrict(err)

if state.FormatVersion() >= 3 {
// The `l2BaseFee` in the tx data is indeed the last block's base fee,
// however, for the purposes of this function, we need the previous computed base fee.
// Since the computed base fee takes one block to apply, the last block's base fee
// is actually two calculations ago. Instead, as of ArbOS format version 3,
// we use the current state's base fee, which is the result of the last calculation.
l2BaseFee, err = state.L2PricingState().BaseFeeWei()
state.Restrict(err)
}
l2BaseFee, err := state.L2PricingState().BaseFeeWei()
state.Restrict(err)

if l1BlockNumber >= nextL1BlockNumber {
var prevHash common.Hash
Expand All @@ -83,7 +75,7 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos
_ = state.RetryableState().TryToReapOneRetryable(currentTime, evm, util.TracingDuringEVM)
_ = state.RetryableState().TryToReapOneRetryable(currentTime, evm, util.TracingDuringEVM)

state.L2PricingState().UpdatePricingModel(l2BaseFee, timePassed, state.FormatVersion(), false)
state.L2PricingState().UpdatePricingModel(l2BaseFee, timePassed, false)
state.L1PricingState().UpdatePricingModel(l1BaseFee, currentTime)

state.UpgradeArbosVersionIfNecessary(currentTime, evm.ChainConfig())
Expand Down
Loading