99
1010 "github.com/ethereum/go-ethereum/params"
1111
12+ "github.com/offchainlabs/nitro/arbos/storage"
1213 "github.com/offchainlabs/nitro/util/arbmath"
1314)
1415
@@ -24,8 +25,8 @@ const InitialPricingInertia = 102
2425const InitialBacklogTolerance = 10
2526const InitialPerTxGasLimitV50 uint64 = 32 * 1000000
2627
27- func (ps * L2PricingState ) ShouldUseMultiConstraints ( arbosVersion uint64 ) (bool , error ) {
28- if arbosVersion >= ArbosMultiConstraintsVersion {
28+ func (ps * L2PricingState ) ShouldUseGasConstraints ( ) (bool , error ) {
29+ if ps . ArbosVersion >= ArbosMultiConstraintsVersion {
2930 constraintsLength , err := ps .ConstraintsLength ()
3031 if err != nil {
3132 return false , err
@@ -35,8 +36,8 @@ func (ps *L2PricingState) ShouldUseMultiConstraints(arbosVersion uint64) (bool,
3536 return false , nil
3637}
3738
38- func (ps * L2PricingState ) AddToGasPool (gas int64 , arbosVersion uint64 ) error {
39- shouldUseMultiConstraints , err := ps .ShouldUseMultiConstraints ( arbosVersion )
39+ func (ps * L2PricingState ) AddToGasPool (gas int64 ) error {
40+ shouldUseMultiConstraints , err := ps .ShouldUseGasConstraints ( )
4041 if err != nil {
4142 return err
4243 }
@@ -74,10 +75,32 @@ func (ps *L2PricingState) addToGasPoolMultiConstraints(gas int64) error {
7475 return nil
7576}
7677
78+ func (ps * L2PricingState ) GasPoolUpdateCost () uint64 {
79+ result := storage .StorageReadCost + storage .StorageWriteCost
80+
81+ // Multi-Constraint pricer requires an extra storage read, since ArbOS must load the constraints from state.
82+ // This overhead applies even when no constraints are configured.
83+ if ps .ArbosVersion >= params .ArbosVersion_50 {
84+ result += storage .StorageReadCost // read length for "souldUseGasConstraints"
85+ }
86+
87+ if ps .ArbosVersion >= params .ArbosVersion_MultiConstraintFix {
88+ // addToGasPoolWithGasConstraints costs (ArbOS 51 and later)
89+ constraintsLength , _ := ps .constraints .Length ()
90+ if constraintsLength > 0 {
91+ result += storage .StorageReadCost // read length to traverse
92+ // updating (read+write) all constraints, first one was already accounted for
93+ result += uint64 (constraintsLength - 1 ) * (storage .StorageReadCost + storage .StorageWriteCost )
94+ }
95+ }
96+
97+ return result
98+ }
99+
77100// UpdatePricingModel updates the pricing model with info from the last block
78- func (ps * L2PricingState ) UpdatePricingModel (timePassed uint64 , arbosVersion uint64 ) {
79- shouldUseMultiConstraints , _ := ps .ShouldUseMultiConstraints ( arbosVersion )
80- if shouldUseMultiConstraints {
101+ func (ps * L2PricingState ) UpdatePricingModel (timePassed uint64 ) {
102+ shouldUseGasConstraints , _ := ps .ShouldUseGasConstraints ( )
103+ if shouldUseGasConstraints {
81104 ps .updatePricingModelMultiConstraints (timePassed )
82105 } else {
83106 ps .updatePricingModelLegacy (timePassed )
0 commit comments