Skip to content

Commit

Permalink
sync transactions on every block rather than on every state update
Browse files Browse the repository at this point in the history
  • Loading branch information
torztomasz committed Jun 29, 2023
1 parent c973e19 commit cac0a17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
19 changes: 6 additions & 13 deletions packages/backend/src/core/PerpetualValidiumSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ export class PerpetualValidiumSyncService implements IDataSyncService {
})

await this.processStateTransitions(stateTransitions)
await this.feederGatewayCollector?.collect()
}

async processStateTransitions(stateTransitions: ValidiumStateTransition[]) {
let lastStateUpdateId: number | undefined

for (const stateTransition of stateTransitions) {
const [perpetualCairoOutput, batch] = await Promise.all([
this.perpetualCairoOutputCollector.collect(
Expand All @@ -66,17 +65,11 @@ export class PerpetualValidiumSyncService implements IDataSyncService {
if (!batch) {
throw new Error(`Unable to download batch ${stateTransition.batchId}`)
}
const stateUpdate =
await this.perpetualValidiumUpdater.processValidiumStateTransition(
stateTransition,
perpetualCairoOutput,
batch
)
lastStateUpdateId = stateUpdate.id
}

if (lastStateUpdateId) {
await this.feederGatewayCollector?.collect(lastStateUpdateId)
await this.perpetualValidiumUpdater.processValidiumStateTransition(
stateTransition,
perpetualCairoOutput,
batch
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ export class FeederGatewayCollector {
private readonly logger: Logger
) {}

async collect(syncToStateUpdateId: number) {
async collect() {
const latestStateUpdate = await this.stateUpdateRepository.findLast()
if (!latestStateUpdate) return

const latestSyncedTransactionStateUpdateId =
await this.l2TransactionRepository.findLatestStateUpdateId()

for (
let stateUpdateId = latestSyncedTransactionStateUpdateId
? latestSyncedTransactionStateUpdateId + 1
: 1;
stateUpdateId <= syncToStateUpdateId;
stateUpdateId <= latestStateUpdate.id;
stateUpdateId++
) {
const stateUpdate = await this.stateUpdateRepository.findById(
Expand Down

0 comments on commit cac0a17

Please sign in to comment.