Skip to content

Commit

Permalink
Merge pull request #5407 from connext/testnet-prod
Browse files Browse the repository at this point in the history
main <- testnet prod sync
  • Loading branch information
wanglonghong authored Dec 20, 2023
2 parents e2a7f5a + 5199fe4 commit 2f22c5a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/adapters/database/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ export const getCurrentProposedOptimisticRoot = async (
.selectOne(
"spoke_optimistic_roots",
{ domain, status: "Proposed" },
{ limit: 1, order: { by: "root_timestamp", direction: "DESC" } },
{ limit: 1, order: { by: "end_of_dispute", direction: "DESC" } },
)
.run(poolToUse);
return opRoot ? convertFromDbSpokeOptimisticRoot(opRoot) : undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/adapters/database/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@ describe("Database client", () => {
m.id = `${_i}`;
m.rootTimestamp = _i;
m.proposeTimestamp = _i;
m.endOfDispute = _i;
spokeOptimisticRoots.push(m);
}
await saveProposedSpokeRoots(spokeOptimisticRoots, pool);
Expand Down
6 changes: 3 additions & 3 deletions packages/adapters/subgraph/src/lib/operations/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ export const getProposedSnapshotsByDomainQuery = (
};

export const getProposedSpokeOptimisticRootsByDomainQuery = (
params: { domain: string; rootTimestamp: number; limit: number; maxBlockNumber: number }[],
params: { domain: string; proposeTimestamp: number; limit: number; maxBlockNumber: number }[],
) => {
const { config } = getContext();
let combinedQuery = "";
Expand All @@ -1148,10 +1148,10 @@ export const getProposedSpokeOptimisticRootsByDomainQuery = (
${prefix}_aggregateRootProposeds (
first: ${param.limit},
where: {
rootTimestamp_gt: ${param.rootTimestamp},
timestamp_gt: ${param.proposeTimestamp},
blockNumber_lte: ${param.maxBlockNumber}
}
orderBy: rootTimestamp,
orderBy: timestamp,
orderDirection: asc
) {
${SPOKE_OPTIMISTIC_ROOT_ENTITY}
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/subgraph/src/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ export class SubgraphReader {
* Gets proposed spoke optimistic roots
*/
public async getProposedSpokeOptimisticRootsByDomain(
params: { domain: string; rootTimestamp: number; limit: number; maxBlockNumber: number }[],
params: { domain: string; proposeTimestamp: number; limit: number; maxBlockNumber: number }[],
): Promise<SpokeOptimisticRoot[]> {
const { parser, execute } = getHelpers();
const proposedSpokeOptimisticRootsByDomainQuery = getProposedSpokeOptimisticRootsByDomainQuery(params);
Expand Down
16 changes: 8 additions & 8 deletions packages/agents/cartographer/poller/src/lib/operations/roots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,27 @@ export const updateProposedSpokeOptimisticRoot = async (maxBlockNumbers: Map<str
continue;
}

const rootTimestamp = await database.getCheckPoint("proposed_optimistic_root_" + domain);
const proposeTimestamp = await database.getCheckPoint("proposed_optimistic_root_" + domain);
const limit = 100;
logger.debug("Retrieving proposed optimistic root for spoke", requestContext, methodContext, {
domain,
rootTimestamp: rootTimestamp,
proposeTimestamp: proposeTimestamp,
limit: limit,
});

const opRoots: SpokeOptimisticRoot[] = await subgraph.getProposedSpokeOptimisticRootsByDomain([
{ domain, rootTimestamp, limit, maxBlockNumber },
{ domain, proposeTimestamp, limit, maxBlockNumber },
]);

const newRootTimestamp =
opRoots.length == 0 ? 0 : opRoots.sort((a, b) => b.rootTimestamp - a.rootTimestamp)[0].rootTimestamp;
if (rootTimestamp === 0 || newRootTimestamp > rootTimestamp) {
const newProposeTimestamp =
opRoots.length == 0 ? 0 : opRoots.sort((a, b) => b.proposeTimestamp! - a.proposeTimestamp!)[0].proposeTimestamp!;
if (proposeTimestamp === 0 || newProposeTimestamp > proposeTimestamp) {
await database.saveProposedSpokeRoots(opRoots);

await database.saveCheckPoint("proposed_optimistic_root_" + domain, newRootTimestamp);
await database.saveCheckPoint("proposed_optimistic_root_" + domain, newProposeTimestamp);
logger.debug("Saved proposed optimistic root for spoke", requestContext, methodContext, {
domain,
rootTimestamp: newRootTimestamp,
proposeTimestamp: newProposeTimestamp,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const proposeHub = async () => {
const latestSnapshotTimestamp = latestSnapshotId * config.snapshotDuration;

const timeSinceSnapshotStart = currentTimestamp - latestSnapshotTimestamp;
const waitTime = config.snapshotDuration / 3;
const waitTime = Math.floor(config.snapshotDuration / 3);
if (timeSinceSnapshotStart < waitTime) {
// Exit if earlier than 1/3 of the snapshot duration to help accommodate time boundary conditions
logger.info("Skipping ProposeHub. Wait time not completed", requestContext, methodContext, {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/mocks/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,5 +706,5 @@ export const mock = {
},
},
},
snapshotDuration: 1800,
snapshotDuration: 1,
};

0 comments on commit 2f22c5a

Please sign in to comment.