@@ -21,7 +21,7 @@ const (
2121 targetOffset uint64 = iota
2222 adjustmentWindowOffset
2323 backlogOffset
24- sumWeightsOffset
24+ maxWeightOffset
2525 weightedResourcesBaseOffset
2626)
2727
@@ -31,7 +31,7 @@ type MultiGasConstraint struct {
3131 target storage.StorageBackedUint64
3232 adjustmentWindow storage.StorageBackedUint32
3333 backlog storage.StorageBackedUint64
34- sumWeights storage.StorageBackedUint64
34+ maxWeight storage.StorageBackedUint64
3535 weightedResources [multigas .NumResourceKind ]storage.StorageBackedUint64
3636}
3737
@@ -41,7 +41,7 @@ func OpenMultiGasConstraint(sto *storage.Storage) *MultiGasConstraint {
4141 target : sto .OpenStorageBackedUint64 (targetOffset ),
4242 adjustmentWindow : sto .OpenStorageBackedUint32 (adjustmentWindowOffset ),
4343 backlog : sto .OpenStorageBackedUint64 (backlogOffset ),
44- sumWeights : sto .OpenStorageBackedUint64 (sumWeightsOffset ),
44+ maxWeight : sto .OpenStorageBackedUint64 (maxWeightOffset ),
4545 }
4646 for i := range int (multigas .NumResourceKind ) {
4747 // #nosec G115 safe: NumResourceKind < 2^32
@@ -62,7 +62,7 @@ func (c *MultiGasConstraint) Clear() error {
6262 if err := c .backlog .Clear (); err != nil {
6363 return err
6464 }
65- if err := c .sumWeights .Clear (); err != nil {
65+ if err := c .maxWeight .Clear (); err != nil {
6666 return err
6767 }
6868 for i := range int (multigas .NumResourceKind ) {
@@ -75,12 +75,14 @@ func (c *MultiGasConstraint) Clear() error {
7575
7676// SetResourceWeights assigns per-resource weight multipliers for this constraint.
7777func (c * MultiGasConstraint ) SetResourceWeights (weights map [uint8 ]uint64 ) error {
78- var total uint64
78+ var maxWeight uint64
7979 for kind , weight := range weights {
8080 if _ , err := multigas .CheckResourceKind (kind ); err != nil {
8181 return err
8282 }
83- total = arbmath .SaturatingUAdd (total , weight )
83+ if weight > maxWeight {
84+ maxWeight = weight
85+ }
8486 }
8587 for i := range int (multigas .NumResourceKind ) {
8688 // #nosec G115 safe: NumResourceKind < 2^32
@@ -89,7 +91,7 @@ func (c *MultiGasConstraint) SetResourceWeights(weights map[uint8]uint64) error
8991 return err
9092 }
9193 }
92- return c .sumWeights .Set (total )
94+ return c .maxWeight .Set (maxWeight )
9395}
9496
9597// GrowBacklog adds the resource usage in multiGas to this constraint's backlog.
@@ -156,8 +158,8 @@ func (c *MultiGasConstraint) ResourceWeight(kind uint8) (uint64, error) {
156158 return c .weightedResources [kind ].Get ()
157159}
158160
159- func (c * MultiGasConstraint ) SumWeights () (uint64 , error ) {
160- return c .sumWeights .Get ()
161+ func (c * MultiGasConstraint ) MaxWeight () (uint64 , error ) {
162+ return c .maxWeight .Get ()
161163}
162164
163165func (c * MultiGasConstraint ) ResourcesWithWeights () (map [multigas.ResourceKind ]uint64 , error ) {
0 commit comments