diff --git a/.changeset/calm-drinks-dance.md b/.changeset/calm-drinks-dance.md new file mode 100644 index 0000000000..0a893bb917 --- /dev/null +++ b/.changeset/calm-drinks-dance.md @@ -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. diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index 0b8ea9f260..bc56ad8dc2 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -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 @@ -70,6 +71,21 @@ export function resolveConfig({ }; }); + // 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( diff --git a/packages/world/ts/config/resolveWorldConfig.ts b/packages/world/ts/config/resolveWorldConfig.ts index 656cc8fd5e..d2b3830d19 100644 --- a/packages/world/ts/config/resolveWorldConfig.ts +++ b/packages/world/ts/config/resolveWorldConfig.ts @@ -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"; @@ -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[] = [];