Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
77d0c065
Commit
77d0c065
authored
5 years ago
by
Tomasz Drwięga
Committed by
Gavin Wood
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Hard-cap the execution time of custom contract calls. (#4226)
* Reject call requests that allocate too high gas limit. * Lower to 5x
parent
a7c04a5b
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/frame/contracts/rpc/src/lib.rs
+23
-1
23 additions, 1 deletion
substrate/frame/contracts/rpc/src/lib.rs
with
23 additions
and
1 deletion
substrate/frame/contracts/rpc/src/lib.rs
+
23
−
1
View file @
77d0c065
...
...
@@ -39,7 +39,16 @@ const RUNTIME_ERROR: i64 = 1;
const
CONTRACT_DOESNT_EXIST
:
i64
=
2
;
const
CONTRACT_IS_A_TOMBSTONE
:
i64
=
3
;
// A private newtype for converting `GetStorageError` into an RPC error.
/// A rough estimate of how much gas a decent hardware consumes per second,
/// using native execution.
/// This value is used to set the upper bound for maximal contract calls to
/// prevent blocking the RPC for too long.
///
/// Based on W3F research spreadsheet:
/// https://docs.google.com/spreadsheets/d/1h0RqncdqiWI4KgxO0z9JIpZEJESXjX_ZCK6LFX6veDo/view
const
GAS_PER_SECOND
:
u64
=
1_000_000_000
;
/// A private newtype for converting `GetStorageError` into an RPC error.
struct
GetStorageError
(
runtime_api
::
GetStorageError
);
impl
From
<
GetStorageError
>
for
Error
{
fn
from
(
e
:
GetStorageError
)
->
Error
{
...
...
@@ -148,6 +157,19 @@ where
data
:
None
,
})
?
;
let
max_gas_limit
=
5
*
GAS_PER_SECOND
;
if
gas_limit
>
max_gas_limit
{
return
Err
(
Error
{
code
:
ErrorCode
::
InvalidParams
,
message
:
format!
(
"Requested gas limit is greater than maximum allowed: {} > {}"
,
gas_limit
,
max_gas_limit
),
data
:
None
,
});
}
let
exec_result
=
api
.call
(
&
at
,
origin
,
dest
,
value
,
gas_limit
,
input_data
.to_vec
())
.map_err
(|
e
|
Error
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment