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
bc1758ca
Unverified
Commit
bc1758ca
authored
Jan 25, 2022
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(sdk): remove blocktime logic
parent
5f2fae12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
52 deletions
+15
-52
cross-chain-provider.ts
packages/sdk/src/cross-chain-provider.ts
+6
-21
cross-chain-provider.ts
packages/sdk/src/interfaces/cross-chain-provider.ts
+0
-19
cross-chain-provider.spec.ts
packages/sdk/test/cross-chain-provider.spec.ts
+9
-12
No files found.
packages/sdk/src/cross-chain-provider.ts
View file @
bc1758ca
...
@@ -43,7 +43,6 @@ export class CrossChainProvider implements ICrossChainProvider {
...
@@ -43,7 +43,6 @@ export class CrossChainProvider implements ICrossChainProvider {
public
l1Provider
:
Provider
public
l1Provider
:
Provider
public
l2Provider
:
Provider
public
l2Provider
:
Provider
public
l1ChainId
:
number
public
l1ChainId
:
number
public
l1BlockTime
:
number
public
contracts
:
OEContracts
public
contracts
:
OEContracts
public
bridges
:
CustomBridges
public
bridges
:
CustomBridges
...
@@ -54,7 +53,6 @@ export class CrossChainProvider implements ICrossChainProvider {
...
@@ -54,7 +53,6 @@ export class CrossChainProvider implements ICrossChainProvider {
* @param opts.l1Provider Provider for the L1 chain, or a JSON-RPC url.
* @param opts.l1Provider Provider for the L1 chain, or a JSON-RPC url.
* @param opts.l2Provider Provider for the L2 chain, or a JSON-RPC url.
* @param opts.l2Provider Provider for the L2 chain, or a JSON-RPC url.
* @param opts.l1ChainId Chain ID for the L1 chain.
* @param opts.l1ChainId Chain ID for the L1 chain.
* @param opts.l1BlockTime Optional L1 block time in seconds. Defaults to 15 seconds.
* @param opts.contracts Optional contract address overrides.
* @param opts.contracts Optional contract address overrides.
* @param opts.bridges Optional bridge address list.
* @param opts.bridges Optional bridge address list.
*/
*/
...
@@ -62,16 +60,12 @@ export class CrossChainProvider implements ICrossChainProvider {
...
@@ -62,16 +60,12 @@ export class CrossChainProvider implements ICrossChainProvider {
l1Provider
:
ProviderLike
l1Provider
:
ProviderLike
l2Provider
:
ProviderLike
l2Provider
:
ProviderLike
l1ChainId
:
NumberLike
l1ChainId
:
NumberLike
l1BlockTime
?:
NumberLike
contracts
?:
DeepPartial
<
OEContractsLike
>
contracts
?:
DeepPartial
<
OEContractsLike
>
bridges
?:
Partial
<
CustomBridgesLike
>
bridges
?:
Partial
<
CustomBridgesLike
>
})
{
})
{
this
.
l1Provider
=
toProvider
(
opts
.
l1Provider
)
this
.
l1Provider
=
toProvider
(
opts
.
l1Provider
)
this
.
l2Provider
=
toProvider
(
opts
.
l2Provider
)
this
.
l2Provider
=
toProvider
(
opts
.
l2Provider
)
this
.
l1ChainId
=
toBigNumber
(
opts
.
l1ChainId
).
toNumber
()
this
.
l1ChainId
=
toBigNumber
(
opts
.
l1ChainId
).
toNumber
()
this
.
l1BlockTime
=
opts
.
l1BlockTime
?
toBigNumber
(
opts
.
l1ChainId
).
toNumber
()
:
15
this
.
contracts
=
getAllOEContracts
(
this
.
l1ChainId
,
{
this
.
contracts
=
getAllOEContracts
(
this
.
l1ChainId
,
{
l1SignerOrProvider
:
this
.
l1Provider
,
l1SignerOrProvider
:
this
.
l1Provider
,
l2SignerOrProvider
:
this
.
l2Provider
,
l2SignerOrProvider
:
this
.
l2Provider
,
...
@@ -366,9 +360,12 @@ export class CrossChainProvider implements ICrossChainProvider {
...
@@ -366,9 +360,12 @@ export class CrossChainProvider implements ICrossChainProvider {
if
(
stateRoot
===
null
)
{
if
(
stateRoot
===
null
)
{
return
MessageStatus
.
STATE_ROOT_NOT_PUBLISHED
return
MessageStatus
.
STATE_ROOT_NOT_PUBLISHED
}
else
{
}
else
{
const
challengePeriod
=
await
this
.
getChallengePeriodBlocks
()
const
challengePeriod
=
await
this
.
getChallengePeriodSeconds
()
const
latestBlock
=
await
this
.
l1Provider
.
getBlockNumber
()
const
targetBlock
=
await
this
.
l1Provider
.
getBlock
(
if
(
stateRoot
.
blockNumber
+
challengePeriod
>
latestBlock
)
{
stateRoot
.
blockNumber
)
const
latestBlock
=
await
this
.
l1Provider
.
getBlock
(
'
latest
'
)
if
(
targetBlock
.
timestamp
+
challengePeriod
>
latestBlock
.
timestamp
)
{
return
MessageStatus
.
IN_CHALLENGE_PERIOD
return
MessageStatus
.
IN_CHALLENGE_PERIOD
}
else
{
}
else
{
return
MessageStatus
.
READY_FOR_RELAY
return
MessageStatus
.
READY_FOR_RELAY
...
@@ -504,24 +501,12 @@ export class CrossChainProvider implements ICrossChainProvider {
...
@@ -504,24 +501,12 @@ export class CrossChainProvider implements ICrossChainProvider {
throw
new
Error
(
'
Not implemented
'
)
throw
new
Error
(
'
Not implemented
'
)
}
}
public
async
estimateMessageWaitTimeBlocks
(
message
:
MessageLike
):
Promise
<
number
>
{
throw
new
Error
(
'
Not implemented
'
)
}
public
async
getChallengePeriodSeconds
():
Promise
<
number
>
{
public
async
getChallengePeriodSeconds
():
Promise
<
number
>
{
const
challengePeriod
=
const
challengePeriod
=
await
this
.
contracts
.
l1
.
StateCommitmentChain
.
FRAUD_PROOF_WINDOW
()
await
this
.
contracts
.
l1
.
StateCommitmentChain
.
FRAUD_PROOF_WINDOW
()
return
challengePeriod
.
toNumber
()
return
challengePeriod
.
toNumber
()
}
}
public
async
getChallengePeriodBlocks
():
Promise
<
number
>
{
return
Math
.
ceil
(
(
await
this
.
getChallengePeriodSeconds
())
/
this
.
l1BlockTime
)
}
public
async
getMessageStateRoot
(
public
async
getMessageStateRoot
(
message
:
MessageLike
message
:
MessageLike
):
Promise
<
StateRoot
|
null
>
{
):
Promise
<
StateRoot
|
null
>
{
...
...
packages/sdk/src/interfaces/cross-chain-provider.ts
View file @
bc1758ca
...
@@ -228,17 +228,6 @@ export interface ICrossChainProvider {
...
@@ -228,17 +228,6 @@ export interface ICrossChainProvider {
*/
*/
estimateMessageWaitTimeSeconds
(
message
:
MessageLike
):
Promise
<
number
>
estimateMessageWaitTimeSeconds
(
message
:
MessageLike
):
Promise
<
number
>
/**
* Returns the estimated amount of time before the message can be executed (in L1 blocks).
* When this is a message being sent to L1, this will return the estimated time until the message
* will complete its challenge period. When this is a message being sent to L2, this will return
* the estimated amount of time until the message will be picked up and executed on L2.
*
* @param message Message to estimate the time remaining for.
* @returns Estimated amount of time remaining (in blocks) before the message can be executed.
*/
estimateMessageWaitTimeBlocks
(
message
:
MessageLike
):
Promise
<
number
>
/**
/**
* Queries the current challenge period in seconds from the StateCommitmentChain.
* Queries the current challenge period in seconds from the StateCommitmentChain.
*
*
...
@@ -246,14 +235,6 @@ export interface ICrossChainProvider {
...
@@ -246,14 +235,6 @@ export interface ICrossChainProvider {
*/
*/
getChallengePeriodSeconds
():
Promise
<
number
>
getChallengePeriodSeconds
():
Promise
<
number
>
/**
* Queries the current challenge period in blocks from the StateCommitmentChain. Estimation is
* based on the challenge period in seconds divided by the L1 block time.
*
* @returns Current challenge period in blocks.
*/
getChallengePeriodBlocks
():
Promise
<
number
>
/**
/**
* Returns the state root that corresponds to a given message. This is the state root for the
* Returns the state root that corresponds to a given message. This is the state root for the
* block in which the transaction was included, as published to the StateCommitmentChain. If the
* block in which the transaction was included, as published to the StateCommitmentChain. If the
...
...
packages/sdk/test/cross-chain-provider.spec.ts
View file @
bc1758ca
...
@@ -898,10 +898,9 @@ describe('CrossChainProvider', () => {
...
@@ -898,10 +898,9 @@ describe('CrossChainProvider', () => {
await
submitStateRootBatchForMessage
(
message
)
await
submitStateRootBatchForMessage
(
message
)
const
challengePeriod
=
await
provider
.
getChallengePeriodBlocks
()
const
challengePeriod
=
await
provider
.
getChallengePeriodSeconds
()
for
(
let
x
=
0
;
x
<
challengePeriod
+
1
;
x
++
)
{
ethers
.
provider
.
send
(
'
evm_increaseTime
'
,
[
challengePeriod
+
1
])
await
ethers
.
provider
.
send
(
'
evm_mine
'
,
[])
ethers
.
provider
.
send
(
'
evm_mine
'
,
[])
}
await
l1Messenger
.
triggerRelayedMessageEvents
([
await
l1Messenger
.
triggerRelayedMessageEvents
([
hashCrossChainMessage
(
message
),
hashCrossChainMessage
(
message
),
...
@@ -921,10 +920,9 @@ describe('CrossChainProvider', () => {
...
@@ -921,10 +920,9 @@ describe('CrossChainProvider', () => {
await
submitStateRootBatchForMessage
(
message
)
await
submitStateRootBatchForMessage
(
message
)
const
challengePeriod
=
await
provider
.
getChallengePeriodBlocks
()
const
challengePeriod
=
await
provider
.
getChallengePeriodSeconds
()
for
(
let
x
=
0
;
x
<
challengePeriod
+
1
;
x
++
)
{
ethers
.
provider
.
send
(
'
evm_increaseTime
'
,
[
challengePeriod
+
1
])
await
ethers
.
provider
.
send
(
'
evm_mine
'
,
[])
ethers
.
provider
.
send
(
'
evm_mine
'
,
[])
}
await
l1Messenger
.
triggerFailedRelayedMessageEvents
([
await
l1Messenger
.
triggerFailedRelayedMessageEvents
([
hashCrossChainMessage
(
message
),
hashCrossChainMessage
(
message
),
...
@@ -944,10 +942,9 @@ describe('CrossChainProvider', () => {
...
@@ -944,10 +942,9 @@ describe('CrossChainProvider', () => {
await
submitStateRootBatchForMessage
(
message
)
await
submitStateRootBatchForMessage
(
message
)
const
challengePeriod
=
await
provider
.
getChallengePeriodBlocks
()
const
challengePeriod
=
await
provider
.
getChallengePeriodSeconds
()
for
(
let
x
=
0
;
x
<
challengePeriod
+
1
;
x
++
)
{
ethers
.
provider
.
send
(
'
evm_increaseTime
'
,
[
challengePeriod
+
1
])
await
ethers
.
provider
.
send
(
'
evm_mine
'
,
[])
ethers
.
provider
.
send
(
'
evm_mine
'
,
[])
}
expect
(
await
provider
.
getMessageStatus
(
message
)).
to
.
equal
(
expect
(
await
provider
.
getMessageStatus
(
message
)).
to
.
equal
(
MessageStatus
.
READY_FOR_RELAY
MessageStatus
.
READY_FOR_RELAY
...
...
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