Skip to content

Commit

Permalink
fix(cli): throw error when deploying overlapping systems (#2325)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
vmaark and holic committed Feb 27, 2024
1 parent 7c23dd7 commit 8f49c27
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .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.
16 changes: 16 additions & 0 deletions packages/cli/src/deploy/resolveConfig.ts
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
@@ -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

0 comments on commit 8f49c27

Please sign in to comment.