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
b6d1fcac
Unverified
Commit
b6d1fcac
authored
Oct 06, 2021
by
Maurelian
Committed by
Kelvin Fichter
Nov 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(contracts): Combine two functions into one as setGasParams()
parent
53e4cae8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
77 deletions
+21
-77
CanonicalTransactionChain.sol
...ntracts/contracts/L1/rollup/CanonicalTransactionChain.sol
+5
-23
ICanonicalTransactionChain.sol
...tracts/contracts/L1/rollup/ICanonicalTransactionChain.sol
+2
-10
deposit.gas.spec.ts
...contracts/test/contracts/L1/messaging/deposit.gas.spec.ts
+2
-2
CanonicalTransactionChain.gas.spec.ts
...contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts
+2
-2
CanonicalTransactionChain.spec.ts
...est/contracts/L1/rollup/CanonicalTransactionChain.spec.ts
+10
-40
No files found.
packages/contracts/contracts/L1/rollup/CanonicalTransactionChain.sol
View file @
b6d1fcac
...
...
@@ -87,7 +87,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
**********************/
/**
* Modifier to enforce that, if configured, only the
OVM_Sequencer contract
may
* Modifier to enforce that, if configured, only the
Burn Admin
may
* successfully call a method.
*/
modifier onlyBurnAdmin() {
...
...
@@ -103,36 +103,17 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
*******************************/
/**
* Allows the
Sequencer to update the gas amount which is 'prepaid' during enqueue
.
* Allows the
Burn Admin to update the parameters which determine the amount of gas to burn
.
* The value of enqueueL2GasPrepaid is immediately updated as well.
*/
function set
EnqueueGasCost(
uint256 _enqueueGasCost)
function set
GasParams(uint256 _l2GasDiscountDivisor,
uint256 _enqueueGasCost)
external
onlyBurnAdmin
{
enqueueGasCost = _enqueueGasCost;
// See the comment in enqueue() for the rationale behind this formula.
enqueueL2GasPrepaid = l2GasDiscountDivisor * _enqueueGasCost;
emit L2GasParamsUpdated(
l2GasDiscountDivisor,
enqueueGasCost,
enqueueL2GasPrepaid
);
}
/**
* Allows the Sequencer to update the L2 Gas Discount Divisor, which is defined as the ratio
* of the cost of gas on L1 to L2.
* The value of enqueueL2GasPrepaid is immediately updated as well.
*/
function setGasDivisor(uint256 _l2GasDiscountDivisor)
external
onlyBurnAdmin
{
l2GasDiscountDivisor = _l2GasDiscountDivisor;
// See the comment in enqueue() for the rationale behind this formula.
enqueueL2GasPrepaid = _l2GasDiscountDivisor * enqueueGasCost;
enqueueL2GasPrepaid = _l2GasDiscountDivisor *
_
enqueueGasCost;
emit L2GasParamsUpdated(
l2GasDiscountDivisor,
...
...
@@ -141,6 +122,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
);
}
/********************
* Public Functions *
********************/
...
...
packages/contracts/contracts/L1/rollup/ICanonicalTransactionChain.sol
View file @
b6d1fcac
...
...
@@ -68,18 +68,10 @@ interface ICanonicalTransactionChain {
*******************************/
/**
* Allows the
Sequencer to update the gas amount which is 'prepaid' during enqueue
.
* Allows the
Burn Admin to update the parameters which determine the amount of gas to burn
.
* The value of enqueueL2GasPrepaid is immediately updated as well.
*/
function setEnqueueGasCost(uint256 _enqueueGasCost)
external;
/**
* Allows the Sequencer to update the L2 Gas Discount Divisor, which is defined as the ratio
* of the cost of gas on L1 to L2.
* The value of enqueueL2GasPrepaid is immediately updated as well.
*/
function setGasDivisor(uint256 _l2GasDiscountDivisor)
function setGasParams(uint256 _l2GasDiscountDivisor, uint256 _enqueueGasCost)
external;
/********************
...
...
packages/contracts/test/contracts/L1/messaging/deposit.gas.spec.ts
View file @
b6d1fcac
...
...
@@ -146,7 +146,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
const
receipt
=
await
res
.
wait
()
const
gasUsed
=
receipt
.
gasUsed
.
toNumber
()
console
.
log
(
'
- Gas used:
'
,
gasUsed
)
expectApprox
(
gasUsed
,
1
55
_089
,
{
expectApprox
(
gasUsed
,
1
16
_781
,
{
absoluteUpperDeviation
:
500
,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value!
...
...
@@ -173,7 +173,7 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
const
receipt
=
await
res
.
wait
()
const
gasUsed
=
receipt
.
gasUsed
.
toNumber
()
console
.
log
(
'
- Gas used:
'
,
gasUsed
)
expectApprox
(
gasUsed
,
202
_930
,
{
expectApprox
(
gasUsed
,
164
_622
,
{
absoluteUpperDeviation
:
500
,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value!
...
...
packages/contracts/test/contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts
View file @
b6d1fcac
...
...
@@ -293,7 +293,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
console
.
log
(
'
Benchmark complete.
'
)
expectApprox
(
gasUsed
,
220
_67
7
,
{
expectApprox
(
gasUsed
,
189
_48
7
,
{
absoluteUpperDeviation
:
500
,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value!
...
...
@@ -314,7 +314,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
console
.
log
(
'
Benchmark complete.
'
)
expectApprox
(
gasUsed
,
1
58
_69
0
,
{
expectApprox
(
gasUsed
,
1
27
_50
0
,
{
absoluteUpperDeviation
:
500
,
// Assert a lower bound of 1% reduction on gas cost. If your tests are breaking because your
// contracts are too efficient, consider updating the target value!
...
...
packages/contracts/test/contracts/L1/rollup/CanonicalTransactionChain.spec.ts
View file @
b6d1fcac
...
...
@@ -137,63 +137,33 @@ describe('CanonicalTransactionChain', () => {
})
describe
(
'
Gas param setters
'
,
()
=>
{
describe
(
'
setGas
Divisor
'
,
async
()
=>
{
it
(
'
should revert when not called by the
sequencer
'
,
async
()
=>
{
describe
(
'
setGas
Params
'
,
async
()
=>
{
it
(
'
should revert when not called by the
Burn Admin
'
,
async
()
=>
{
await
expect
(
CanonicalTransactionChain
.
connect
(
otherSigner
).
setGasDivisor
(
32
)
).
to
.
be
.
revertedWith
(
'
Only callable by the Burn Admin.
'
)
})
it
(
'
should update the l2GasDiscountDivisor and enqueueL2GasPrepaid correctly
'
,
async
()
=>
{
const
newGasDivisor
=
19
await
CanonicalTransactionChain
.
connect
(
addressManagerOwner
).
setGasDivisor
(
newGasDivisor
)
const
enqueueGasCost
=
await
CanonicalTransactionChain
.
enqueueGasCost
()
const
enqueueL2GasPrepaid
=
await
CanonicalTransactionChain
.
enqueueL2GasPrepaid
()
expect
(
enqueueL2GasPrepaid
).
to
.
equal
(
newGasDivisor
*
enqueueGasCost
)
})
it
(
'
should emit an L2GasParamsUpdated event
'
,
async
()
=>
{
await
expect
(
CanonicalTransactionChain
.
connect
(
addressManagerOwner
).
setGasDivisor
(
88
)
).
to
.
emit
(
CanonicalTransactionChain
,
'
L2GasParamsUpdated
'
)
})
})
describe
(
'
setEnqueueGasCost
'
,
async
()
=>
{
it
(
'
should revert when not called by the sequencer
'
,
async
()
=>
{
await
expect
(
CanonicalTransactionChain
.
connect
(
otherSigner
).
setEnqueueGasCost
(
60000
)
CanonicalTransactionChain
.
connect
(
otherSigner
).
setGasParams
(
60000
,
32
)
).
to
.
be
.
revertedWith
(
'
Only callable by the Burn Admin.
'
)
})
it
(
'
should update the enqueueGasCost and enqueueL2GasPrepaid correctly
'
,
async
()
=>
{
const
newEnqueueGasCost
=
31113
const
newGasDivisor
=
19
await
CanonicalTransactionChain
.
connect
(
addressManagerOwner
).
set
EnqueueGasCost
(
newEnqueueGasCost
)
).
set
GasParams
(
newGasDivisor
,
newEnqueueGasCost
)
const
l2GasDiscountDivisor
=
await
CanonicalTransactionChain
.
l2GasDiscountDivisor
()
const
enqueueL2GasPrepaid
=
await
CanonicalTransactionChain
.
enqueueL2GasPrepaid
()
expect
(
enqueueL2GasPrepaid
).
to
.
equal
(
l2GasDiscountDivisor
*
newEnqueueGasCost
)
expect
(
enqueueL2GasPrepaid
).
to
.
equal
(
newGasDivisor
*
newEnqueueGasCost
)
})
it
(
'
should emit an L2GasParamsUpdated event
'
,
async
()
=>
{
await
expect
(
CanonicalTransactionChain
.
connect
(
addressManagerOwner
).
setEnqueueGasCost
(
31514
)
CanonicalTransactionChain
.
connect
(
addressManagerOwner
).
setGasParams
(
88
,
31514
)
).
to
.
emit
(
CanonicalTransactionChain
,
'
L2GasParamsUpdated
'
)
})
})
...
...
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