22 crate :: { alloy:: eips:: eip7840:: BlobParams , prelude:: * } ,
33 core:: time:: Duration ,
44 serde:: { Deserialize , Serialize } ,
5- std:: time:: Instant ,
5+ std:: { fmt :: Debug , time:: Instant } ,
66} ;
77
88/// This type specifies the limits that payloads should stay within.
1212/// - Limits are specified on a pipeline scope level. If a pipeline scope
1313/// doesn't explicitly specify its limits it will inherit its enclosing scope
1414/// limits.
15- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize ) ]
16- pub struct Limits {
15+ #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
16+ pub struct Limits < P : Platform > {
1717 /// The maximum cumulative gas that can be used in the block.
1818 /// This includes all transactions, epilogues, prologues, and other
1919 /// gas-consuming operations.
@@ -24,12 +24,30 @@ pub struct Limits {
2424
2525 /// The maximum number of transactions that can be included in the block.
2626 ///
27- /// This is not a standard known ethereum limit, however it can be imposed by
28- /// custom limits factories.
27+ /// This is not a standard known ethereum limit; however, it can be imposed
28+ /// by custom limits factories.
2929 pub max_transactions : Option < usize > ,
3030
3131 /// The time a pipeline is allowed to spend on execution.
3232 pub deadline : Option < Duration > ,
33+
34+ /// Per platform extension.
35+ pub ext : P :: ExtraLimits ,
36+ }
37+
38+ impl < P : Platform > Copy for Limits < P > { }
39+
40+ /// This trait must be implemented by extension limits
41+ pub trait LimitExtension :
42+ Copy + Debug + Default + Send + Sync + ' static
43+ {
44+ fn clamp ( & self , other : & Self ) -> Self ;
45+ }
46+
47+ impl LimitExtension for ( ) {
48+ fn clamp ( & self , _: & Self ) -> Self {
49+ ( )
50+ }
3351}
3452
3553/// Types implementing this trait are responsible for calculating top-level
@@ -39,16 +57,17 @@ pub struct Limits {
3957/// Implementations of this type are always called exactly once at the beginning
4058/// of a new payload job.
4159pub trait PlatformLimits < P : Platform > : Default + Send + Sync + ' static {
42- fn create ( & self , block : & BlockContext < P > ) -> Limits ;
60+ fn create ( & self , block : & BlockContext < P > ) -> Limits < P > ;
4361}
4462
45- impl Limits {
63+ impl < P : Platform > Limits < P > {
4664 pub fn gas_limit ( gas_limit : u64 ) -> Self {
4765 Self {
4866 gas_limit,
4967 blob_params : None ,
5068 deadline : None ,
5169 max_transactions : None ,
70+ ext : P :: ExtraLimits :: default ( ) ,
5271 }
5372 }
5473
@@ -109,6 +128,7 @@ impl Limits {
109128 } ,
110129 max_transactions : self . max_transactions . min ( other. max_transactions ) ,
111130 deadline : self . deadline . min ( other. deadline ) ,
131+ ext : self . ext . clamp ( & other. ext ) ,
112132 }
113133 }
114134}
0 commit comments