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

fix(cli): throw warning for duplicate systems #2325

Merged
merged 4 commits into from
Feb 27, 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
6 changes: 6 additions & 0 deletions .changeset/calm-drinks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/cli": patch
"@latticexyz/world": patch
---

Attempting to deploy multiple systems where there are overlapping system IDs now throws an error.
16 changes: 16 additions & 0 deletions packages/cli/src/deploy/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getExistingContracts } from "../utils/getExistingContracts";
import { defaultModuleContracts } from "../utils/modules/constants";
import { getContractData } from "../utils/utils/getContractData";
import { configToTables } from "./configToTables";
import { groupBy } from "@latticexyz/common/utils";

// TODO: this should be replaced by https://github.com/latticexyz/mud/issues/1668

Expand Down Expand Up @@ -70,6 +71,21 @@ export function resolveConfig<config extends ConfigInput>({
};
});

// Check for overlapping system IDs (since names get truncated when turning into IDs)
// TODO: move this into the world config resolve step once it resolves system IDs
const systemsById = groupBy(systems, (system) => system.systemId);
const overlappingSystems = Array.from(systemsById.values())
.filter((matches) => matches.length > 1)
.flat();
if (overlappingSystems.length) {
const names = overlappingSystems.map((system) => system.name);
throw new Error(
`Found systems with overlapping system ID: ${names.join(
", "
)}.\n\nSystem IDs are generated from the first 16 bytes of the name, so you may need to rename them to avoid the overlap.`
);
}

// ugh (https://github.com/latticexyz/mud/issues/1668)
const resolveContext = {
tableIds: Object.fromEntries(
Expand Down
4 changes: 2 additions & 2 deletions packages/world/ts/config/resolveWorldConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STORE_NAME_MAX_LENGTH, UnrecognizedSystemErrorFactory } from "@latticexyz/config";
import { UnrecognizedSystemErrorFactory } from "@latticexyz/config";
import { StoreConfig } from "@latticexyz/store";
import { SystemConfig, WorldConfig } from "./types";

Expand Down Expand Up @@ -55,7 +55,7 @@ export function resolveWorldConfig(config: StoreConfig & WorldConfig, existingCo
* Default value for accessListSystems is []
*/
export function resolveSystemConfig(systemName: string, config?: SystemConfig, existingContracts?: string[]) {
const name = (config?.name ?? systemName).slice(0, STORE_NAME_MAX_LENGTH);
const name = config?.name ?? systemName;
const registerFunctionSelectors = config?.registerFunctionSelectors ?? true;
const openAccess = config?.openAccess ?? true;
const accessListAddresses: string[] = [];
Expand Down
Loading