Consistify location of user ENS registry address setting #6005
Conversation
Hm, this seems to be failing CI for a reason I don't understand. Will have to take a look. |
packages/deployer/index.js
Outdated
options.ens.registryAddress = | ||
this.networks[this.network].registryAddress ?? | ||
this.networks[this.network].registry?.address ?? | ||
options.ens.registryAddress ?? | ||
options.ens.registry?.address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mentioned, this is not ideal. I think it would be better to have Config resolver fn ensRegistryAddress(networkName)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A config resolver function? What does that mean? (Just to be clear what I was talking about above having just a getter that returns the current registry address, it wouldn't take any arguments.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah shoot, CURRENT! I forgot it gets set, and the getter won't need a network name.
I think we should do It's a bit tricky though... I think the right place for this ENS config is per-network (i.e., |
These are interesting thoughts on where the user settings in the config should live, but this doesn't answer the question of how to name the getter so as to avoid a naming conflict! |
After consideration and discussion, let's just make whatever getter that doesn't conflict with user settings. Maybe |
OK, I've updated this to use a config getter, even though it's ugly. I also did some manual testing of the Really this is still not the cleanest even with the factoring, because I'm still just plugging the getter in to the particular places early on, converting it to a value, rather than letting config pass through and usign the getter as late as possible. But whatever -- that can be a thing for the future, likely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @haltman-at, though I have a few comments. I think the new settings behavior should be documented on the website, and, imho, linked to by the new exception error the code can produce.
//if this throws, then there's no network config, whatever | ||
} | ||
//NOTE: in what follows I'm not just using || or ?? because I want | ||
//null to be respected but undefined not to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the resolution order be called out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the particular order is important as long as network-specific is placed above generic. You shouldn't be setting the same thing twice anyway, so to my mind there's no need to guarantee an order between them; if you set both and get an unpredictable result, that's your own problem for setting the same thing twice.
(To be clear I consider network specific and generic settings to be different -- that's not setting the same thing twice, and there guaranteeing the order matters.)
Changed my mind because of untested complexity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be some unit tests to guard ens precedence resolution.
networkConfig?.registry?.address, | ||
networkConfig?.registryAddress, | ||
configObject.ens?.registry?.address, | ||
configObject.ens?.registryAddress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This precedence resolution locks the API behavior and should be guarded by unit tests to maintain behavior to prevent introducing a subtle bug in future maintenances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, as long as specific is before generic, I don't think there's a problem (see comments earlier). In any case I did add a test that tests the specific-before-generic behavior; I don't see a need to add a test for the remainder of the order and lock it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, though It would be helpful to inform the user they're in undefined territory if they set both network specific and generic ens settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, hm, yeah, we could throw an error in that case! I guess I'll go do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I reworked the logic here to throw an error in that case. I did use copy/paste but I think it's fine, it's all right next to each other and it's just two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks, @haltman-at
PR description
This PR addresses #5997. I'm not entirely happy with this one, but, well, I figured I ought to put it up as it is and we can iron out the problems in review.
Basically, I altered both Truffle Contract and Truffle Deployer to check 4 places for the ens registry address:
config.network_config.registryAddress
config.network_config.registry.address
config.ens.registryAddress
config.ens.registry.address
Note that specific network configs are checked before the overall ENS config, so that a specific network config can override the overall ENS config.
Now I say I altered Truffle Contract, but actually I didn't -- the easiest place to make these changes was actually the provisioner, rather than Contract itself. Not sure if that's appropriate, but I didn't want to deal with the complication of doing it a different way.
I say I'm not entirely happy with this one, and there are two reasons for that:
??
, if you setconfig.ens.registryAddress
, it's not possible to, say, set an explicitnull
in a network config to say that you shouldn't use the global registry for that specific network. I can imagine people might want this indeployer
. So likely onlyundefined
should defer to the next one, rather thannull
.config
like we have for various other properties of the config; it could be calledconfig.ensRegistryAddress
or something (config.networkRegistryAddress
? IDK). The naming's a little ugly, but it seems probably better than the alternative?Anyway, let me know what you think and what changes should be made to this.
Testing instructions
I added tests to
deployer
to test the code changes there. I didn't really directly test theprovisioner
changes, hm, maybe I should go back and do that... (adding tests there seemed pretty messy)