Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to exclude l2 transaction types #433

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2c7143d
implement clock
torztomasz Jul 13, 2023
3266bba
implement L2TransactionDownloader
torztomasz Jul 13, 2023
73afa8d
run adding l2 transaction in transaction with locked table
torztomasz Jul 13, 2023
3510802
add tests
torztomasz Jul 13, 2023
0e16506
Merge remote-tracking branch 'origin/master' into implement-l2-transa…
torztomasz Jul 17, 2023
3c0b66b
improve LiveL2TransactionDownloader
torztomasz Jul 17, 2023
6b9903f
improve live l2 transaction log
torztomasz Jul 17, 2023
593ea6b
add live l2 transaction downloader tests
torztomasz Jul 18, 2023
d95e2e9
replace count with find for adding transactions
torztomasz Jul 18, 2023
256d89c
remove .only
torztomasz Jul 18, 2023
6fbfd21
fix linter errors
torztomasz Jul 18, 2023
915e223
remove randomness from tests
torztomasz Jul 20, 2023
2655d8b
rename L2TransactionDownloader to LiveL2TransactionDownloader
torztomasz Jul 20, 2023
0927847
Merge remote-tracking branch 'origin/master' into implement-l2-transa…
torztomasz Jul 20, 2023
60f9680
add tests
torztomasz Jul 20, 2023
94b5e76
fix build issues
torztomasz Jul 20, 2023
492b885
fix after merge bug
torztomasz Jul 20, 2023
ab3155e
Merge remote-tracking branch 'origin/master' into implement-l2-transa…
torztomasz Jul 20, 2023
38d7dcf
add live txs count
torztomasz Jul 20, 2023
ef76a6f
Merge branch 'master' into implement-l2-transactions-downloader
torztomasz Jul 21, 2023
03bf0af
fix linter issues
torztomasz Jul 21, 2023
9ae4198
add l2TransactionsEnabled flag to config (#432)
torztomasz Jul 21, 2023
7620ae0
add possibility to exclude l2 transaction types in config
torztomasz Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 49 additions & 19 deletions packages/backend/src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ import { SpotValidiumSyncService } from './core/SpotValidiumSyncService'
import { SpotValidiumUpdater } from './core/SpotValidiumUpdater'
import { StatusService } from './core/StatusService'
import { BlockDownloader } from './core/sync/BlockDownloader'
import { Clock } from './core/sync/Clock'
import { LiveL2TransactionDownloader } from './core/sync/LiveL2TransactionDownloader'
import { SyncScheduler } from './core/sync/SyncScheduler'
import { TransactionStatusService } from './core/TransactionStatusService'
import { UserService } from './core/UserService'
Expand Down Expand Up @@ -88,6 +90,7 @@ import { TokenInspector } from './peripherals/ethereum/TokenInspector'
import { AvailabilityGatewayClient } from './peripherals/starkware/AvailabilityGatewayClient'
import { FeederGatewayClient } from './peripherals/starkware/FeederGatewayClient'
import { FetchClient } from './peripherals/starkware/FetchClient'
import { LiveL2TransactionClient } from './peripherals/starkware/LiveL2TransactionClient'
import { handleServerError, reportError } from './tools/ErrorReporter'

export class Application {
Expand All @@ -101,6 +104,8 @@ export class Application {
reportError,
})

const clock = new Clock()

// #endregion tools
// #region peripherals

Expand Down Expand Up @@ -219,7 +224,43 @@ export class Application {
| PerpetualRollupUpdater
let stateTransitionCollector: IStateTransitionCollector

let feederGatewayCollector: FeederGatewayCollector | undefined
const feederGatewayClient = config.starkex.l2Transactions.enabled
? new FeederGatewayClient(
config.starkex.l2Transactions.feederGateway,
fetchClient,
logger
)
: undefined

const feederGatewayCollector = feederGatewayClient
? new FeederGatewayCollector(
feederGatewayClient,
l2TransactionRepository,
stateUpdateRepository,
logger,
config.starkex.l2Transactions.enabled
)
: undefined

const liveL2TransactionClient =
config.starkex.l2Transactions.enabled &&
config.starkex.l2Transactions.liveApi
? new LiveL2TransactionClient(
config.starkex.l2Transactions.liveApi,
fetchClient
)
: undefined

const liveL2TransactionDownloader = liveL2TransactionClient
? new LiveL2TransactionDownloader(
liveL2TransactionClient,
l2TransactionRepository,
stateUpdateRepository,
kvStore,
clock,
logger
)
: undefined

if (config.starkex.dataAvailabilityMode === 'validium') {
const availabilityGatewayClient = new AvailabilityGatewayClient(
Expand All @@ -236,22 +277,6 @@ export class Application {
)
stateTransitionCollector = perpetualValidiumStateTransitionCollector

const feederGatewayClient = config.starkex.feederGateway
? new FeederGatewayClient(
config.starkex.feederGateway,
fetchClient,
logger
)
: undefined
feederGatewayCollector = feederGatewayClient
? new FeederGatewayCollector(
feederGatewayClient,
l2TransactionRepository,
stateUpdateRepository,
logger
)
: undefined

const perpetualCairoOutputCollector = new PerpetualCairoOutputCollector(
ethereumClient,
config.starkex
Expand Down Expand Up @@ -279,6 +304,7 @@ export class Application {
perpetualValidiumUpdater,
withdrawalAllowedCollector,
feederGatewayCollector,
liveL2TransactionDownloader,
logger
)
} else {
Expand Down Expand Up @@ -539,7 +565,8 @@ export class Application {
userTransactionRepository,
forcedTradeOfferRepository,
l2TransactionRepository,
preprocessedStateDetailsRepository
preprocessedStateDetailsRepository,
config.starkex.l2Transactions.excludeTypes
)

const userController = new UserController(
Expand All @@ -555,6 +582,7 @@ export class Application {
withdrawableAssetRepository,
preprocessedUserStatisticsRepository,
preprocessedUserL2TransactionsStatisticsRepository,
config.starkex.l2Transactions.excludeTypes,
config.starkex.contracts.perpetual
)
const stateUpdateController = new StateUpdateController(
Expand All @@ -564,7 +592,8 @@ export class Application {
userTransactionRepository,
l2TransactionRepository,
preprocessedAssetHistoryRepository,
preprocessedStateDetailsRepository
preprocessedStateDetailsRepository,
config.starkex.l2Transactions.excludeTypes
)
const transactionController = new TransactionController(
pageContextService,
Expand Down Expand Up @@ -657,6 +686,7 @@ export class Application {
if (config.enableSync) {
transactionStatusService.start()
await syncScheduler.start()
await liveL2TransactionDownloader?.start()
await blockDownloader.start()
}

Expand Down
58 changes: 45 additions & 13 deletions packages/backend/src/api/controllers/HomeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@explorer/frontend'
import { UserDetails } from '@explorer/shared'

import { L2TransactionTypesToExclude } from '../../config/starkex/StarkexConfig'
import { AssetDetailsService } from '../../core/AssetDetailsService'
import { ForcedTradeOfferViewService } from '../../core/ForcedTradeOfferViewService'
import { PageContextService } from '../../core/PageContextService'
Expand Down Expand Up @@ -34,7 +35,10 @@ export class HomeController {
private readonly userTransactionRepository: UserTransactionRepository,
private readonly forcedTradeOfferRepository: ForcedTradeOfferRepository,
private readonly l2TransactionRepository: L2TransactionRepository,
private readonly preprocessedStateDetailsRepository: PreprocessedStateDetailsRepository
private readonly preprocessedStateDetailsRepository: PreprocessedStateDetailsRepository,
private readonly excludeL2TransactionTypes:
| L2TransactionTypesToExclude
| undefined
) {}

async getHomePage(
Expand All @@ -45,15 +49,20 @@ export class HomeController {
const [
l2Transactions,
lastStateDetailsWithL2TransactionsStatistics,
liveL2TransactionsStatistics,
stateUpdates,
stateUpdatesCount,
forcedUserTransactions,
forcedUserTransactionsCount,
availableOffers,
availableOffersCount,
] = await Promise.all([
this.l2TransactionRepository.getPaginatedWithoutMulti(paginationOpts),
this.l2TransactionRepository.getPaginatedWithoutMulti(
paginationOpts,
this.excludeL2TransactionTypes
),
this.preprocessedStateDetailsRepository.findLastWithL2TransactionsStatistics(),
this.l2TransactionRepository.getLiveStatistics(),
this.preprocessedStateDetailsRepository.getPaginated(paginationOpts),
this.preprocessedStateDetailsRepository.countAll(),
this.userTransactionRepository.getPaginated({
Expand Down Expand Up @@ -82,13 +91,21 @@ export class HomeController {
forcedTransactionCount: update.forcedTransactionCount,
}))

const totalL2Transactions =
sumUpTransactionCount(
lastStateDetailsWithL2TransactionsStatistics?.cumulativeL2TransactionsStatistics,
this.excludeL2TransactionTypes
) +
sumUpTransactionCount(
liveL2TransactionsStatistics,
this.excludeL2TransactionTypes
)

const content = renderHomePage({
context,
tutorials: [], // explicitly no tutorials
l2Transactions: l2Transactions.map(l2TransactionToEntry),
totalL2Transactions: sumUpTransactionCount(
lastStateDetailsWithL2TransactionsStatistics?.cumulativeL2TransactionsStatistics
),
totalL2Transactions,
stateUpdates: stateUpdateEntries,
totalStateUpdates: stateUpdatesCount,
forcedTransactions: forcedTransactionEntries,
Expand All @@ -109,18 +126,33 @@ export class HomeController {
): Promise<ControllerResult> {
const context = await this.pageContextService.getPageContext(givenUser)

const [l2Transactions, lastStateDetailsWithL2TransactionsStatistics] =
await Promise.all([
this.l2TransactionRepository.getPaginatedWithoutMulti(pagination),
this.preprocessedStateDetailsRepository.findLastWithL2TransactionsStatistics(),
])
const [
l2Transactions,
lastStateDetailsWithL2TransactionsStatistics,
liveL2TransactionsStatistics,
] = await Promise.all([
this.l2TransactionRepository.getPaginatedWithoutMulti(
pagination,
this.excludeL2TransactionTypes
),
this.preprocessedStateDetailsRepository.findLastWithL2TransactionsStatistics(),
this.l2TransactionRepository.getLiveStatistics(),
])

const totalL2Transactions =
sumUpTransactionCount(
lastStateDetailsWithL2TransactionsStatistics?.cumulativeL2TransactionsStatistics,
this.excludeL2TransactionTypes
) +
sumUpTransactionCount(
liveL2TransactionsStatistics,
this.excludeL2TransactionTypes
)

const content = renderHomeL2TransactionsPage({
context,
l2Transactions: l2Transactions.map(l2TransactionToEntry),
total: sumUpTransactionCount(
lastStateDetailsWithL2TransactionsStatistics?.cumulativeL2TransactionsStatistics
),
total: totalL2Transactions,
...pagination,
})
return { type: 'success', content }
Expand Down
18 changes: 13 additions & 5 deletions packages/backend/src/api/controllers/StateUpdateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { UserDetails } from '@explorer/shared'
import { AssetHash } from '@explorer/types'

import { L2TransactionTypesToExclude } from '../../config/starkex/StarkexConfig'
import { AssetDetailsMap } from '../../core/AssetDetailsMap'
import { AssetDetailsService } from '../../core/AssetDetailsService'
import { PageContextService } from '../../core/PageContextService'
Expand Down Expand Up @@ -40,7 +41,10 @@ export class StateUpdateController {
private readonly userTransactionRepository: UserTransactionRepository,
private readonly l2TransactionRepository: L2TransactionRepository,
private readonly preprocessedAssetHistoryRepository: PreprocessedAssetHistoryRepository,
private readonly preprocessedStateDetailsRepository: PreprocessedStateDetailsRepository
private readonly preprocessedStateDetailsRepository: PreprocessedStateDetailsRepository,
private readonly excludeL2TransactionTypes:
| L2TransactionTypesToExclude
| undefined
) {}

async getStateUpdatePage(
Expand Down Expand Up @@ -82,7 +86,8 @@ export class StateUpdateController {
{
offset: 0,
limit: 6,
}
},
this.excludeL2TransactionTypes
),
this.preprocessedStateDetailsRepository.findByStateUpdateId(
stateUpdateId
Expand Down Expand Up @@ -132,7 +137,8 @@ export class StateUpdateController {
l2Transactions: l2Transactions.map(l2TransactionToEntry),
totalL2Transactions: preprocessedStateDetails?.l2TransactionsStatistics
? sumUpTransactionCount(
preprocessedStateDetails.l2TransactionsStatistics
preprocessedStateDetails.l2TransactionsStatistics,
this.excludeL2TransactionTypes
)
: 'processing',
transactions,
Expand All @@ -152,7 +158,8 @@ export class StateUpdateController {
const [l2Transactions, preprocessedStateDetails] = await Promise.all([
this.l2TransactionRepository.getPaginatedWithoutMultiByStateUpdateId(
stateUpdateId,
pagination
pagination,
this.excludeL2TransactionTypes
),
this.preprocessedStateDetailsRepository.findByStateUpdateId(
stateUpdateId
Expand All @@ -166,7 +173,8 @@ export class StateUpdateController {
...pagination,
total: preprocessedStateDetails?.l2TransactionsStatistics
? sumUpTransactionCount(
preprocessedStateDetails.l2TransactionsStatistics
preprocessedStateDetails.l2TransactionsStatistics,
this.excludeL2TransactionTypes
)
: 'processing',
})
Expand Down
Loading
Loading