latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
738 stars 187 forks source link

deployer should reuse deterministic world or change salt #3227

Open holic opened 1 month ago

holic commented 1 month ago

If I deploy a world with mud dev-contracts to a long-running anvil instance, then restart and deploy again, it'll reuse the salt and thus get the same world address. However, the second world deploy will fail.

It should either detect this and pick a new salt or reuse the already-deployed world.

We should also see if we can improve the error message from these instances, because it's really unclear

Error while attempting deploy 

ContractFunctionExecutionError: The contract function "deployWorld" reverted.

Contract Call:
  address:   0x573802f86c51B61d7Cf620952217eC6Ce0537d2E
  function:  deployWorld(bytes salt)
  args:                 (0x)
  sender:    0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Docs: https://viem.sh/docs/contract/writeContract
Version: 2.21.6
holic commented 1 month ago

We could potentially add this to the factory, like

address expectedWorldAddress = Create2.computeAddress(...);
if (expectedWorldAddress.code.length > 0) {
  revert WorldExists(expectedWorldAddress);
}

but could do something similar in the deployer just before deploying to avoid modifying audited code