@@ -20,8 +20,8 @@ use clarity::vm::analysis::CheckErrors;
20
20
use clarity:: vm:: ast:: parser:: v1:: CLARITY_NAME_REGEX ;
21
21
use clarity:: vm:: clarity:: ClarityConnection ;
22
22
use clarity:: vm:: costs:: { CostErrors , ExecutionCost , LimitedCostTracker } ;
23
- use clarity:: vm:: errors:: Error as ClarityRuntimeError ;
24
23
use clarity:: vm:: errors:: Error :: Unchecked ;
24
+ use clarity:: vm:: errors:: { Error as ClarityRuntimeError , InterpreterError } ;
25
25
use clarity:: vm:: representations:: { CONTRACT_NAME_REGEX_STRING , STANDARD_PRINCIPAL_REGEX_STRING } ;
26
26
use clarity:: vm:: types:: { PrincipalData , QualifiedContractIdentifier } ;
27
27
use clarity:: vm:: { ClarityName , ContractName , SymbolicExpression , Value } ;
@@ -61,7 +61,7 @@ pub struct CallReadOnlyResponse {
61
61
62
62
#[ derive( Clone ) ]
63
63
pub struct RPCCallReadOnlyRequestHandler {
64
- maximum_call_argument_size : u32 ,
64
+ pub maximum_call_argument_size : u32 ,
65
65
read_only_call_limit : ExecutionCost ,
66
66
67
67
/// Runtime fields
@@ -70,16 +70,10 @@ pub struct RPCCallReadOnlyRequestHandler {
70
70
pub sender : Option < PrincipalData > ,
71
71
pub sponsor : Option < PrincipalData > ,
72
72
pub arguments : Option < Vec < Value > > ,
73
-
74
- read_only_max_execution_time : Duration ,
75
73
}
76
74
77
75
impl RPCCallReadOnlyRequestHandler {
78
- pub fn new (
79
- maximum_call_argument_size : u32 ,
80
- read_only_call_limit : ExecutionCost ,
81
- read_only_max_execution_time : Duration ,
82
- ) -> Self {
76
+ pub fn new ( maximum_call_argument_size : u32 , read_only_call_limit : ExecutionCost ) -> Self {
83
77
Self {
84
78
maximum_call_argument_size,
85
79
read_only_call_limit,
@@ -88,7 +82,6 @@ impl RPCCallReadOnlyRequestHandler {
88
82
sender : None ,
89
83
sponsor : None ,
90
84
arguments : None ,
91
- read_only_max_execution_time,
92
85
}
93
86
}
94
87
}
@@ -193,12 +186,6 @@ impl RPCRequestHandler for RPCCallReadOnlyRequestHandler {
193
186
}
194
187
} ;
195
188
196
- let cost_tracker = contents
197
- . get_query_args ( )
198
- . get ( "cost_tracker" )
199
- . map ( |cost_tracker| cost_tracker. as_str ( ) . into ( ) )
200
- . unwrap_or ( CostTrackerRequest :: Limited ) ;
201
-
202
189
let contract_identifier = self
203
190
. contract_identifier
204
191
. take ( )
@@ -239,19 +226,14 @@ impl RPCRequestHandler for RPCCallReadOnlyRequestHandler {
239
226
|clarity_tx| {
240
227
let epoch = clarity_tx. get_epoch ( ) ;
241
228
let cost_track = clarity_tx
242
- . with_clarity_db_readonly ( |clarity_db| match cost_tracker {
243
- CostTrackerRequest :: Limited => LimitedCostTracker :: new_mid_block (
229
+ . with_clarity_db_readonly ( |clarity_db| {
230
+ LimitedCostTracker :: new_mid_block (
244
231
mainnet, chain_id, cost_limit, clarity_db, epoch,
245
- ) ,
246
- CostTrackerRequest :: Free => {
247
- enforce_max_execution_time = true ;
248
- Ok ( LimitedCostTracker :: new_free ( ) )
249
- }
250
- CostTrackerRequest :: Invalid => {
251
- Err ( CostErrors :: Expect ( "Invalid cost tracker" . into ( ) ) )
252
- }
232
+ )
253
233
} )
254
- . map_err ( |e| ClarityRuntimeError :: from ( e) ) ?;
234
+ . map_err ( |_| {
235
+ ClarityRuntimeError :: from ( InterpreterError :: CostContractLoadFailure )
236
+ } ) ?;
255
237
256
238
let clarity_version = clarity_tx
257
239
. with_analysis_db_readonly ( |analysis_db| {
@@ -272,13 +254,6 @@ impl RPCRequestHandler for RPCCallReadOnlyRequestHandler {
272
254
sponsor,
273
255
cost_track,
274
256
|env| {
275
- // cost tracking in read only calls is meamingful mainly from a security point of view
276
- // for this reason we enforce max_execution_time when cost tracking is disabled/free
277
- if enforce_max_execution_time {
278
- env. global_context
279
- . set_max_execution_time ( self . read_only_max_execution_time ) ;
280
- }
281
-
282
257
// we want to execute any function as long as no actual writes are made as
283
258
// opposed to be limited to purely calling `define-read-only` functions,
284
259
// so use `read_only = false`. This broadens the number of functions that
@@ -355,38 +330,6 @@ impl HttpResponse for RPCCallReadOnlyRequestHandler {
355
330
}
356
331
}
357
332
358
- /// All representations of the `cost_tracker=` query parameter value
359
- #[ derive( Debug , Clone , PartialEq ) ]
360
- pub enum CostTrackerRequest {
361
- Limited ,
362
- Free ,
363
- Invalid ,
364
- }
365
-
366
- impl CostTrackerRequest { }
367
-
368
- impl std:: fmt:: Display for CostTrackerRequest {
369
- fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
370
- match self {
371
- Self :: Limited => write ! ( f, "limited" ) ,
372
- Self :: Free => write ! ( f, "free" ) ,
373
- Self :: Invalid => write ! ( f, "invalid" ) ,
374
- }
375
- }
376
- }
377
-
378
- impl From < & str > for CostTrackerRequest {
379
- fn from ( s : & str ) -> CostTrackerRequest {
380
- if s == "limited" || s == "" {
381
- CostTrackerRequest :: Limited
382
- } else if s == "free" {
383
- CostTrackerRequest :: Free
384
- } else {
385
- CostTrackerRequest :: Invalid
386
- }
387
- }
388
- }
389
-
390
333
impl StacksHttpRequest {
391
334
/// Make a new request to run a read-only function
392
335
pub fn new_callreadonlyfunction (
@@ -398,7 +341,6 @@ impl StacksHttpRequest {
398
341
function_name : ClarityName ,
399
342
function_args : Vec < Value > ,
400
343
tip_req : TipRequest ,
401
- cost_tracker : CostTrackerRequest ,
402
344
) -> StacksHttpRequest {
403
345
StacksHttpRequest :: new_for_peer (
404
346
host,
@@ -407,17 +349,14 @@ impl StacksHttpRequest {
407
349
"/v2/contracts/call-read/{}/{}/{}" ,
408
350
& contract_addr, & contract_name, & function_name
409
351
) ,
410
- HttpRequestContents :: new ( )
411
- . for_tip ( tip_req)
412
- . query_arg ( "cost_tracker" . to_string ( ) , cost_tracker. to_string ( ) )
413
- . payload_json (
414
- serde_json:: to_value ( CallReadOnlyRequestBody {
415
- sender : sender. to_string ( ) ,
416
- sponsor : sponsor. map ( |s| s. to_string ( ) ) ,
417
- arguments : function_args. into_iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ,
418
- } )
419
- . expect ( "FATAL: failed to encode infallible data" ) ,
420
- ) ,
352
+ HttpRequestContents :: new ( ) . for_tip ( tip_req) . payload_json (
353
+ serde_json:: to_value ( CallReadOnlyRequestBody {
354
+ sender : sender. to_string ( ) ,
355
+ sponsor : sponsor. map ( |s| s. to_string ( ) ) ,
356
+ arguments : function_args. into_iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ,
357
+ } )
358
+ . expect ( "FATAL: failed to encode infallible data" ) ,
359
+ ) ,
421
360
)
422
361
. expect ( "FATAL: failed to construct request from infallible data" )
423
362
}
0 commit comments