Commit bc1758ca authored by Kelvin Fichter's avatar Kelvin Fichter

fix(sdk): remove blocktime logic

parent 5f2fae12
......@@ -43,7 +43,6 @@ export class CrossChainProvider implements ICrossChainProvider {
public l1Provider: Provider
public l2Provider: Provider
public l1ChainId: number
public l1BlockTime: number
public contracts: OEContracts
public bridges: CustomBridges
......@@ -54,7 +53,6 @@ export class CrossChainProvider implements ICrossChainProvider {
* @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.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.bridges Optional bridge address list.
*/
......@@ -62,16 +60,12 @@ export class CrossChainProvider implements ICrossChainProvider {
l1Provider: ProviderLike
l2Provider: ProviderLike
l1ChainId: NumberLike
l1BlockTime?: NumberLike
contracts?: DeepPartial<OEContractsLike>
bridges?: Partial<CustomBridgesLike>
}) {
this.l1Provider = toProvider(opts.l1Provider)
this.l2Provider = toProvider(opts.l2Provider)
this.l1ChainId = toBigNumber(opts.l1ChainId).toNumber()
this.l1BlockTime = opts.l1BlockTime
? toBigNumber(opts.l1ChainId).toNumber()
: 15
this.contracts = getAllOEContracts(this.l1ChainId, {
l1SignerOrProvider: this.l1Provider,
l2SignerOrProvider: this.l2Provider,
......@@ -366,9 +360,12 @@ export class CrossChainProvider implements ICrossChainProvider {
if (stateRoot === null) {
return MessageStatus.STATE_ROOT_NOT_PUBLISHED
} else {
const challengePeriod = await this.getChallengePeriodBlocks()
const latestBlock = await this.l1Provider.getBlockNumber()
if (stateRoot.blockNumber + challengePeriod > latestBlock) {
const challengePeriod = await this.getChallengePeriodSeconds()
const targetBlock = await this.l1Provider.getBlock(
stateRoot.blockNumber
)
const latestBlock = await this.l1Provider.getBlock('latest')
if (targetBlock.timestamp + challengePeriod > latestBlock.timestamp) {
return MessageStatus.IN_CHALLENGE_PERIOD
} else {
return MessageStatus.READY_FOR_RELAY
......@@ -504,24 +501,12 @@ export class CrossChainProvider implements ICrossChainProvider {
throw new Error('Not implemented')
}
public async estimateMessageWaitTimeBlocks(
message: MessageLike
): Promise<number> {
throw new Error('Not implemented')
}
public async getChallengePeriodSeconds(): Promise<number> {
const challengePeriod =
await this.contracts.l1.StateCommitmentChain.FRAUD_PROOF_WINDOW()
return challengePeriod.toNumber()
}
public async getChallengePeriodBlocks(): Promise<number> {
return Math.ceil(
(await this.getChallengePeriodSeconds()) / this.l1BlockTime
)
}
public async getMessageStateRoot(
message: MessageLike
): Promise<StateRoot | null> {
......
......@@ -228,17 +228,6 @@ export interface ICrossChainProvider {
*/
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.
*
......@@ -246,14 +235,6 @@ export interface ICrossChainProvider {
*/
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
* block in which the transaction was included, as published to the StateCommitmentChain. If the
......
......@@ -898,10 +898,9 @@ describe('CrossChainProvider', () => {
await submitStateRootBatchForMessage(message)
const challengePeriod = await provider.getChallengePeriodBlocks()
for (let x = 0; x < challengePeriod + 1; x++) {
await ethers.provider.send('evm_mine', [])
}
const challengePeriod = await provider.getChallengePeriodSeconds()
ethers.provider.send('evm_increaseTime', [challengePeriod + 1])
ethers.provider.send('evm_mine', [])
await l1Messenger.triggerRelayedMessageEvents([
hashCrossChainMessage(message),
......@@ -921,10 +920,9 @@ describe('CrossChainProvider', () => {
await submitStateRootBatchForMessage(message)
const challengePeriod = await provider.getChallengePeriodBlocks()
for (let x = 0; x < challengePeriod + 1; x++) {
await ethers.provider.send('evm_mine', [])
}
const challengePeriod = await provider.getChallengePeriodSeconds()
ethers.provider.send('evm_increaseTime', [challengePeriod + 1])
ethers.provider.send('evm_mine', [])
await l1Messenger.triggerFailedRelayedMessageEvents([
hashCrossChainMessage(message),
......@@ -944,10 +942,9 @@ describe('CrossChainProvider', () => {
await submitStateRootBatchForMessage(message)
const challengePeriod = await provider.getChallengePeriodBlocks()
for (let x = 0; x < challengePeriod + 1; x++) {
await ethers.provider.send('evm_mine', [])
}
const challengePeriod = await provider.getChallengePeriodSeconds()
ethers.provider.send('evm_increaseTime', [challengePeriod + 1])
ethers.provider.send('evm_mine', [])
expect(await provider.getMessageStatus(message)).to.equal(
MessageStatus.READY_FOR_RELAY
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment