Skip to content

Commit

Permalink
fix(bundles): fix range start block and bundle id when assigning even…
Browse files Browse the repository at this point in the history
…ts (#69)
  • Loading branch information
melisaguevara authored Oct 16, 2024
1 parent 106430c commit 38f81a2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
12 changes: 9 additions & 3 deletions packages/indexer-database/src/entities/Bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export class Bundle {
@Column()
slowRelayRoot: string;

@OneToOne(() => ProposedRootBundle, { nullable: false })
@OneToOne(() => ProposedRootBundle, (proposal) => proposal.bundle, {
nullable: false,
})
@JoinColumn({
foreignKeyConstraintName: "FK_bundle_rootBundleProposeId",
})
Expand All @@ -44,7 +46,9 @@ export class Bundle {
@Column({ nullable: false })
proposalId: number;

@OneToOne(() => RootBundleCanceled, { nullable: true })
@OneToOne(() => RootBundleCanceled, (cancelation) => cancelation.bundle, {
nullable: true,
})
@JoinColumn({
foreignKeyConstraintName: "FK_bundle_rootBundleCanceledId",
})
Expand All @@ -53,7 +57,9 @@ export class Bundle {
@Column({ nullable: true })
cancelationId: number;

@OneToOne(() => RootBundleDisputed, { nullable: true })
@OneToOne(() => RootBundleDisputed, (dispute) => dispute.bundle, {
nullable: true,
})
@JoinColumn({
foreignKeyConstraintName: "FK_bundle_rootBundleDisputedId",
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
Column,
CreateDateColumn,
Entity,
OneToOne,
PrimaryGeneratedColumn,
Unique,
} from "typeorm";
import { Bundle } from "../Bundle";

@Entity({ schema: "evm" })
@Unique("UK_proposedRootBundle_txHash", ["transactionHash"])
Expand Down Expand Up @@ -36,6 +38,9 @@ export class ProposedRootBundle {
@Column()
proposer: string;

@OneToOne(() => Bundle, (bundle) => bundle.proposal)
bundle: Bundle;

@Column()
transactionHash: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
Column,
CreateDateColumn,
Entity,
OneToOne,
PrimaryGeneratedColumn,
Unique,
} from "typeorm";
import { Bundle } from "../Bundle";

@Entity({ schema: "evm" })
@Unique("UK_rootBundleCanceled_txHash", ["transactionHash"])
Expand All @@ -18,6 +20,9 @@ export class RootBundleCanceled {
@Column()
requestTime: Date;

@OneToOne(() => Bundle, (bundle) => bundle.cancelation)
bundle: Bundle;

@Column()
transactionHash: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
Column,
CreateDateColumn,
Entity,
OneToOne,
PrimaryGeneratedColumn,
Unique,
} from "typeorm";
import { Bundle } from "../Bundle";

@Entity({ schema: "evm" })
@Unique("UK_rootBundleDisputed_txHash", ["transactionHash"])
Expand All @@ -18,6 +20,9 @@ export class RootBundleDisputed {
@Column()
requestTime: Date;

@OneToOne(() => Bundle, (bundle) => bundle.dispute)
bundle: Bundle;

@Column()
transactionHash: string;

Expand Down
18 changes: 9 additions & 9 deletions packages/indexer/src/database/BundleRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class BundleRepository extends utils.BaseRepository {
);
// Find all canceled events that haven't been associated with a bundle.
return canceledRootBundleRepository
.createQueryBuilder("drb")
.createQueryBuilder("crb")
.select([
"drb.id",
"drb.blockNumber",
"drb.logIndex",
"drb.transactionIndex",
"crb.id",
"crb.blockNumber",
"crb.logIndex",
"crb.transactionIndex",
])
.leftJoin("bundle", "b", "b.cancelationId = drb.id")
.leftJoin("crb.bundle", "b")
.where("b.cancelationId IS NULL")
.getMany();
}
Expand All @@ -80,7 +80,7 @@ export class BundleRepository extends utils.BaseRepository {
"drb.logIndex",
"drb.transactionIndex",
])
.leftJoin("bundle", "b", "b.disputeId = drb.id")
.leftJoin("drb.bundle", "b")
.where("b.disputeId IS NULL")
.getMany();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export class BundleRepository extends utils.BaseRepository {
"prb.relayerRefundRoot",
"prb.slowRelayRoot",
])
.leftJoin("bundle", "b", "b.proposalId = prb.id")
.leftJoin("prb.bundle", "b")
.where("b.proposalId IS NULL")
.getMany();
}
Expand Down Expand Up @@ -177,7 +177,7 @@ export class BundleRepository extends utils.BaseRepository {
return this.postgres
.getRepository(entities.ProposedRootBundle)
.createQueryBuilder("prb")
.leftJoin(entities.Bundle, "b", "b.proposalId = prb.id")
.leftJoinAndSelect("prb.bundle", "b")
.where(
// Proposal is in the past
"(prb.blockNumber < :blockNumber OR " +
Expand Down
19 changes: 13 additions & 6 deletions packages/indexer/src/services/bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function assignDisputeEventToBundle(
return undefined;
}
return {
bundleId: proposedBundle.id,
bundleId: proposedBundle.bundle.id,
eventId: id,
};
},
Expand Down Expand Up @@ -156,7 +156,7 @@ async function assignCanceledEventToBundle(
return undefined;
}
return {
bundleId: proposedBundle.id,
bundleId: proposedBundle.bundle.id,
eventId: id,
};
},
Expand Down Expand Up @@ -201,7 +201,7 @@ async function assignExecutionsToBundle(
);
}
return {
bundleId: proposedBundle.id,
bundleId: proposedBundle.bundle.id,
executionId: id,
};
},
Expand Down Expand Up @@ -268,14 +268,17 @@ async function assignBundleRangesToProposal(
// matches the previous. For the case that the current bundle adds a new chain
// to the proposal, the corresponding previous event index should resolve undefined
// and therefore the start block should be 0.
const startBlock =
const previousEndBlock =
previousEvent.bundleEvaluationBlockNumbers[idx] ?? 0;
return [
...acc,
{
bundleId: bundle.id,
chainId,
startBlock,
startBlock:
previousEndBlock !== endBlock
? previousEndBlock + 1
: previousEndBlock, // Bundle range doesn't change for disabled chains
endBlock,
},
];
Expand All @@ -285,7 +288,11 @@ async function assignBundleRangesToProposal(
}),
);
const insertResults = await dbRepository.associateBlockRangeWithBundle(
rangeSegments.filter((segment) => segment !== undefined).flat(),
rangeSegments
.filter(
(segment): segment is BlockRangeInsertType[] => segment !== undefined,
)
.flat(),
);
logResultOfAssignment(
logger,
Expand Down

0 comments on commit 38f81a2

Please sign in to comment.