Skip to content

Commit

Permalink
R4R: DTL stop sync TransactionEnqueued event once DTL_SHUTOFF_BLOCK i…
Browse files Browse the repository at this point in the history
…s set (#1358)

# Goals of PR

Core changes:

- Preparing for bedrock upgrade, **DTL** stop sync **TransactionEnqueued
event** once DTL_SHUTOFF_BLOCK is set in addressManager
- Add sleep in deploy scripts to accommodate normal l1
blockchain(produce blocks periodically)
  • Loading branch information
HaoyangLiu authored Sep 14, 2023
2 parents 5894e31 + faba895 commit 6dc6b2d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
4 changes: 3 additions & 1 deletion packages/contracts/deploy/011-AddressDictator.deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'
import { hexStringEquals } from '@mantleio/core-utils'
import { hexStringEquals, sleep } from '@mantleio/core-utils'

/* Imports: Internal */
import {
Expand Down Expand Up @@ -75,6 +75,8 @@ const deployFn: DeployFunction = async (hre) => {
return !hexStringEquals(existingAddresses[name], address)
})

await sleep(10000)

await deployAndVerifyAndThen({
hre,
name: names.unmanaged.AddressDictator,
Expand Down
14 changes: 11 additions & 3 deletions packages/contracts/tasks/fraud-proof-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { task } from 'hardhat/config'
import { ethers } from 'ethers'
import { hexStringEquals } from '@mantleio/core-utils'
import {hexStringEquals, sleep} from '@mantleio/core-utils'

// @ts-ignore
import { getContractFactory } from '../src'
Expand Down Expand Up @@ -112,6 +112,7 @@ task('rollupStake')
}

await mantle.connect(deployer).transfer(stakerWallet.address, mantleAmount)
await sleep(10000)
console.log(
'balance: ',
stakerWallet.address,
Expand All @@ -122,22 +123,29 @@ task('rollupStake')
'ETH Balance:',
stakerWallet.address,
' ',
await stakerWallet.getBalance()
(await stakerWallet.getBalance()).toString()
)
await sleep(10000)
await mantle
.connect(stakerWallet)
.approve(taskArgs.rollup, ethers.utils.parseEther(taskArgs.amount))

await sleep(10000);
console.log(
'ETH Balance:',
stakerWallet.address,
' ',
await stakerWallet.getBalance()
(await stakerWallet.getBalance()).toString()
)

await sleep(10000)

console.log('stake', stakerWallet.address, operators[i])
await rollup
.connect(stakerWallet)
.stake(ethers.utils.parseEther(taskArgs.amount), operators[i])

await sleep(10000)
}
})

Expand Down
50 changes: 39 additions & 11 deletions packages/data-transport-layer/src/services/l1-ingestion/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseService, Metrics } from '@mantleio/common-ts'
import { TypedEvent } from '@mantleio/contracts/dist/types/common'
import { BaseProvider, StaticJsonRpcProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup'
import { constants } from 'ethers'
import { BigNumber, constants } from 'ethers'
import { Gauge, Counter } from 'prom-client'

/* Imports: Internal */
Expand Down Expand Up @@ -260,16 +260,44 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
targetL1Block,
})

// I prefer to do this in serial to avoid non-determinism. We could have a discussion about
// using Promise.all if necessary, but I don't see a good reason to do so unless parsing is
// really, really slow for all event types.
await this._syncEvents(
'CanonicalTransactionChain',
'TransactionEnqueued',
highestSyncedL1Block,
targetL1Block,
handleEventsTransactionEnqueued
)
// We always try loading the deposit shutoff block in every loop! Less efficient but will
// guarantee that we don't miss the shutoff block being set and that we can automatically
// recover if the shutoff block is set and then unset.
const depositShutoffBlock = BigNumber.from(
await this.state.contracts.Lib_AddressManager.getAddress(
'DTL_SHUTOFF_BLOCK'
)
).toNumber()

// If the deposit shutoff block is set, then we should stop syncing deposits at that block.
let depositTargetL1Block = targetL1Block
if (depositShutoffBlock > 0) {
this.logger.info(`Deposit shutoff active`, {
targetL1Block,
depositShutoffBlock,
})
depositTargetL1Block = Math.min(
depositTargetL1Block,
depositShutoffBlock
)
}

// We should not sync TransactionEnqueued events beyond the deposit shutoff block.
if (depositTargetL1Block >= highestSyncedL1Block) {
await this._syncEvents(
'CanonicalTransactionChain',
'TransactionEnqueued',
highestSyncedL1Block,
depositTargetL1Block,
handleEventsTransactionEnqueued
)
} else {
this.logger.info('Deposit shutoff reached', {
depositTargetL1Block,
highestSyncedL1Block,
depositShutoffBlock,
})
}

if (!this.options.eigenUpgradeEnable) {
await this._syncEvents(
Expand Down

0 comments on commit 6dc6b2d

Please sign in to comment.