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,29 @@ 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+ #[ must_use]
45+ fn clamp ( & self , other : & Self ) -> Self ;
46+ }
47+
48+ impl LimitExtension for ( ) {
49+ fn clamp ( & self , ( ) : & Self ) -> Self { }
3350}
3451
3552/// Types implementing this trait are responsible for calculating top-level
@@ -39,16 +56,17 @@ pub struct Limits {
3956/// Implementations of this type are always called exactly once at the beginning
4057/// of a new payload job.
4158pub trait PlatformLimits < P : Platform > : Default + Send + Sync + ' static {
42- fn create ( & self , block : & BlockContext < P > ) -> Limits ;
59+ fn create ( & self , block : & BlockContext < P > ) -> Limits < P > ;
4360}
4461
45- impl Limits {
62+ impl < P : Platform > Limits < P > {
4663 pub fn gas_limit ( gas_limit : u64 ) -> Self {
4764 Self {
4865 gas_limit,
4966 blob_params : None ,
5067 deadline : None ,
5168 max_transactions : None ,
69+ ext : P :: ExtraLimits :: default ( ) ,
5270 }
5371 }
5472
@@ -109,6 +127,7 @@ impl Limits {
109127 } ,
110128 max_transactions : self . max_transactions . min ( other. max_transactions ) ,
111129 deadline : self . deadline . min ( other. deadline ) ,
130+ ext : self . ext . clamp ( & other. ext ) ,
112131 }
113132 }
114133}
0 commit comments