Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
5edc0cfc
Commit
5edc0cfc
authored
May 09, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `message-utils` to mimic `MigrateWithdrawalGasLimit`
parent
1aed44ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
4 deletions
+28
-4
message-utils.ts
packages/sdk/src/utils/message-utils.ts
+28
-4
No files found.
packages/sdk/src/utils/message-utils.ts
View file @
5edc0cfc
...
...
@@ -5,6 +5,15 @@ import { LowLevelMessage } from '../interfaces'
const
{
hexDataLength
}
=
utils
// Constants used by `CrossDomainMessenger.baseGas`
const
RELAY_CONSTANT_OVERHEAD
=
200
_000
const
RELAY_PER_BYTE_DATA_COST
=
16
const
MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR
=
64
const
MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR
=
63
const
RELAY_CALL_OVERHEAD
=
40
_000
const
RELAY_RESERVED_GAS
=
40
_000
const
RELAY_GAS_CHECK_BUFFER
=
5
_000
/**
* Utility for hashing a LowLevelMessage object.
*
...
...
@@ -46,11 +55,26 @@ export const migratedWithdrawalGasLimit = (
chainID
:
number
):
BigNumber
=>
{
// Compute the gas limit and cap at 25 million
const
dataCost
=
BigNumber
.
from
(
hexDataLength
(
data
)).
mul
(
16
)
let
overhead
=
200
_000
if
(
chainID
!==
420
)
{
overhead
=
1
_000_000
const
dataCost
=
BigNumber
.
from
(
hexDataLength
(
data
)).
mul
(
RELAY_PER_BYTE_DATA_COST
)
let
overhead
:
number
if
(
chainID
===
420
)
{
overhead
=
200
_000
}
else
{
// Constant overhead
overhead
=
RELAY_CONSTANT_OVERHEAD
+
// Dynamic overhead (EIP-150)
(
MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR
*
1
_000_000
)
/
MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR
+
// Gas reserved for the worst-case cost of 3/5 of the `CALL` opcode's dynamic gas
// factors. (Conservative)
RELAY_CALL_OVERHEAD
+
// Relay reserved gas (to ensure execution of `relayMessage` completes after the
// subcontext finishes executing) (Conservative)
RELAY_RESERVED_GAS
+
// Gas reserved for the execution between the `hasMinGas` check and the `CALL`
// opcode. (Conservative)
RELAY_GAS_CHECK_BUFFER
}
let
minGasLimit
=
dataCost
.
add
(
overhead
)
if
(
minGasLimit
.
gt
(
25
_000_000
))
{
minGasLimit
=
BigNumber
.
from
(
25
_000_000
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment