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

Allow ignition modules as a dependency for futures #828

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 45 additions & 14 deletions packages/core/src/ignition-module-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contractName: future.contractName,
constructorArgs: future.constructorArgs.map((arg) =>
Expand All @@ -161,7 +163,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contractName: future.contractName,
artifact: future.artifact,
Expand All @@ -187,7 +191,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contractName: future.contractName,
from: isRuntimeValue(future.from)
Expand All @@ -204,7 +210,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contractName: future.contractName,
artifact: future.artifact,
Expand All @@ -222,7 +230,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contract: this._convertFutureToFutureToken(future.contract),
functionName: future.functionName,
Expand All @@ -245,7 +255,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contract: this._convertFutureToFutureToken(future.contract),
functionName: future.functionName,
Expand All @@ -264,7 +276,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contract: this._convertFutureToFutureToken(future.contract),
functionName: future.functionName,
Expand All @@ -279,7 +293,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contractName: future.contractName,
address: isFuture(future.address)
Expand All @@ -298,7 +314,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
contractName: future.contractName,
artifact: future.artifact,
Expand All @@ -318,7 +336,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
futureToReadFrom: this._convertFutureToFutureToken(
future.futureToReadFrom
Expand All @@ -336,7 +356,9 @@ export class IgnitionModuleSerializer {
moduleId: future.module.id,
type: future.type,
dependencies: Array.from(future.dependencies).map((d) =>
this._convertFutureToFutureToken(d)
isFuture(d)
? this._convertFutureToFutureToken(d)
: this._convertModuleToModuleToken(d)
),
to: isFuture(future.to)
? this._convertFutureToFutureToken(future.to)
Expand Down Expand Up @@ -475,7 +497,14 @@ export class IgnitionModuleDeserializer {
);

for (const dependencyId of serializedFuture.dependencies) {
const dependency = this._lookup(futuresLookup, dependencyId.futureId);
let dependency: Future | IgnitionModule;

if (dependencyId._kind === "FutureToken") {
dependency = this._lookup(futuresLookup, dependencyId.futureId);
} else {
dependency = this._lookup(modulesLookup, dependencyId.moduleId);
}

future.dependencies.add(dependency);
}

Expand Down Expand Up @@ -548,8 +577,10 @@ export class IgnitionModuleDeserializer {

for (const serializedFuture of serializedFutures) {
for (const dependencyToken of serializedFuture.dependencies) {
const dependency = serializedFuturesMap[dependencyToken.futureId];
graph.get(dependency)!.add(serializedFuture);
if (dependencyToken._kind === "FutureToken") {
const dependency = serializedFuturesMap[dependencyToken.futureId];
graph.get(dependency)!.add(serializedFuture);
}
}
}

Expand Down
24 changes: 23 additions & 1 deletion packages/core/src/internal/batcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,29 @@ export class Batcher {
): boolean {
const dependencies = batchState.adjacencyList.getDependenciesFor(futureId);

return [...dependencies].every(
return [...dependencies].every((depId) => {
// We distinguish between module and future ids here, as the future's always have `#` and the modules don't.
if (/#/.test(depId)) {
zoeyTM marked this conversation as resolved.
Show resolved Hide resolved
return batchState.visitState[depId] === VisitStatus.VISITED;
}

return this._checkModuleDependencyIsComplete(depId, batchState);
});
}

/**
* This is needed because moduleIds are not present in the visit state
* causing an infinite loop when checking whether a depenedency is visited if that dependency is a module.
*/
private static _checkModuleDependencyIsComplete(
moduleId: string,
batchState: BatchState
) {
const dependencies = Object.keys(batchState.visitState).filter((futureId) =>
futureId.startsWith(moduleId)
);

return dependencies.every(
(depId) => batchState.visitState[depId] === VisitStatus.VISITED
);
}
Expand Down
40 changes: 40 additions & 0 deletions packages/core/src/internal/module-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

for (const libraryFuture of Object.values(options.libraries)) {
Expand Down Expand Up @@ -356,6 +360,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

for (const libraryFuture of Object.values(options.libraries)) {
Expand Down Expand Up @@ -426,6 +434,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

for (const libraryFuture of Object.values(options.libraries)) {
Expand Down Expand Up @@ -470,6 +482,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

for (const libraryFuture of Object.values(options.libraries)) {
Expand Down Expand Up @@ -543,6 +559,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

this._module.futures.add(future);
Expand Down Expand Up @@ -607,6 +627,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

this._module.futures.add(future);
Expand Down Expand Up @@ -669,6 +693,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

this._module.futures.add(future);
Expand Down Expand Up @@ -774,6 +802,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

if (isFuture(address)) {
Expand Down Expand Up @@ -819,6 +851,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

if (isFuture(address)) {
Expand Down Expand Up @@ -953,6 +989,10 @@ class IgnitionModuleBuilderImplementation<

for (const afterFuture of options.after ?? []) {
future.dependencies.add(afterFuture);

if (!isFuture(afterFuture)) {
this._module.submodules.add(afterFuture);
}
}

this._module.futures.add(future);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/internal/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
const customInspectSymbol = Symbol.for("util.inspect.custom");

abstract class BaseFutureImplementation<FutureTypeT extends FutureType> {
public readonly dependencies: Set<Future> = new Set();
public readonly dependencies: Set<Future | IgnitionModule> = new Set();

constructor(
public readonly id: string,
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/internal/utils/adjacency-list-converter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isFuture } from "../../type-guards";
import { Future } from "../../types/module";

import { AdjacencyList } from "./adjacency-list";
Expand All @@ -12,11 +13,13 @@ export class AdjacencyListConverter {
for (const dependency of future.dependencies) {
dependencyGraph.addDependency({ from: future.id, to: dependency.id });

this._optionallyAddDependenciesSubmoduleSiblings(
dependencyGraph,
future,
dependency
);
if (isFuture(dependency)) {
this._optionallyAddDependenciesSubmoduleSiblings(
dependencyGraph,
future,
dependency
);
}
}
}

Expand Down
Loading
Loading