@@ -16,6 +16,7 @@ use conf::{
16
16
} ;
17
17
use dusk_consensus:: config:: MAX_BLOCK_SIZE ;
18
18
use dusk_consensus:: errors:: BlobError ;
19
+ use dusk_core:: TxPreconditionError ;
19
20
use node_data:: events:: { Event , TransactionEvent } ;
20
21
use node_data:: get_current_timestamp;
21
22
use node_data:: ledger:: { Header , SpendingId , Transaction } ;
@@ -89,6 +90,26 @@ impl From<BlobError> for TxAcceptanceError {
89
90
}
90
91
}
91
92
93
+ impl From < TxPreconditionError > for TxAcceptanceError {
94
+ fn from ( err : TxPreconditionError ) -> Self {
95
+ match err {
96
+ TxPreconditionError :: BlobLowLimit ( min) => {
97
+ TxAcceptanceError :: GasLimitTooLow ( min)
98
+ }
99
+ TxPreconditionError :: DeployLowLimit ( min) => {
100
+ TxAcceptanceError :: GasLimitTooLow ( min)
101
+ }
102
+ TxPreconditionError :: DeployLowPrice ( min) => {
103
+ TxAcceptanceError :: GasPriceTooLow ( min)
104
+ }
105
+ TxPreconditionError :: BlobEmpty => TxAcceptanceError :: BlobEmpty ,
106
+ TxPreconditionError :: BlobTooMany ( n) => {
107
+ TxAcceptanceError :: BlobTooMany ( n)
108
+ }
109
+ }
110
+ }
111
+ }
112
+
92
113
pub struct MempoolSrv {
93
114
inbound : AsyncQueue < Message > ,
94
115
conf : Params ,
@@ -258,27 +279,43 @@ impl MempoolSrv {
258
279
return Err ( TxAcceptanceError :: GasPriceTooLow ( 1 ) ) ;
259
280
}
260
281
261
- if tx . inner . deploy ( ) . is_some ( ) {
262
- // TODO: Remove this duplicated code in favor of vm::deploy_check
282
+ {
283
+ // Mimic the VM's additional checks for transactions
263
284
let vm = vm. read ( ) . await ;
264
- let min_deployment_gas_price = vm. min_deployment_gas_price ( ) ;
265
- if tx. gas_price ( ) < min_deployment_gas_price {
266
- return Err ( TxAcceptanceError :: GasPriceTooLow (
285
+
286
+ // Check deployment tx
287
+ if tx. inner . deploy ( ) . is_some ( ) {
288
+ let min_deployment_gas_price = vm. min_deployment_gas_price ( ) ;
289
+ let gas_per_deploy_byte = vm. gas_per_deploy_byte ( ) ;
290
+ let min_deploy_points = vm. min_deploy_points ( ) ;
291
+ tx. inner . deploy_check (
292
+ gas_per_deploy_byte,
267
293
min_deployment_gas_price,
268
- ) ) ;
294
+ min_deploy_points,
295
+ ) ?;
269
296
}
270
297
271
- let gas_per_deploy_byte = vm. gas_per_deploy_byte ( ) ;
272
- let deploy_charge = tx
273
- . inner
274
- . deploy_charge ( gas_per_deploy_byte, vm. min_deploy_points ( ) ) ;
275
- if tx. inner . gas_limit ( ) < deploy_charge {
276
- return Err ( TxAcceptanceError :: GasLimitTooLow ( deploy_charge) ) ;
298
+ // Check blob tx
299
+ if tx. inner . blob ( ) . is_some ( ) {
300
+ db. read ( )
301
+ . await
302
+ . view ( |db| {
303
+ db. block_label_by_height ( vm. blob_activation_height ( ) )
304
+ } )
305
+ . map_err ( |e| {
306
+ anyhow ! ( "Cannot get blob activation height: {e}" )
307
+ } ) ?
308
+ . ok_or ( anyhow ! (
309
+ "Blobs acceptance will start at block height: {}" ,
310
+ vm. blob_activation_height( )
311
+ ) ) ?;
312
+
313
+ let gas_per_blob = vm. gas_per_blob ( ) ;
314
+ tx. inner . blob_check ( gas_per_blob) ?;
315
+ dusk_consensus:: validate_blob_sidecars ( tx) ?;
277
316
}
278
- } else if tx. inner . blob ( ) . is_some ( ) {
279
- dusk_consensus:: validate_blobs ( tx) ?;
280
- } else {
281
- let vm = vm. read ( ) . await ;
317
+
318
+ // Check global minimum gas limit
282
319
let min_gas_limit = vm. min_gas_limit ( ) ;
283
320
if tx. inner . gas_limit ( ) < min_gas_limit {
284
321
return Err ( TxAcceptanceError :: GasLimitTooLow ( min_gas_limit) ) ;
0 commit comments