-
Notifications
You must be signed in to change notification settings - Fork 105
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
Allow the agent and channel to not exist at first #978
Allow the agent and channel to not exist at first #978
Conversation
Hey Clara. Not sure if I fully understand the context. Maybe miss something important you and team discussed? I would assume the agent/channel of bridgeHub is an built-in config when deploy the contracts. For other sibling chains they need to customize the runtime to allow sending xcm to create agent/channel through the channel of bridgeHub(as we do for the template chain). After that they send other messages through their own channels. So there is no problem but correct me if I'm wrong. |
Hey @yrong! If you run |
Just tested seems
Yes, it's as expected and the log will be fine after we create agent/channel for template parachain. |
Let me retest. 😄 |
// The agent will not exist at first and needs to be created. | ||
if (ch.agent == address(0)) { | ||
return (0, 0); | ||
} |
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.
With solidity, null values are implicitly converted to zero values, so can drop the null check
// The agent will not exist at first and needs to be created. | |
if (ch.agent == address(0)) { | |
return (0, 0); | |
} |
@@ -220,8 +224,8 @@ contract Gateway is IGateway, IInitializable { | |||
} | |||
|
|||
function agentOf(bytes32 agentID) external view returns (address) { | |||
address agentAddress = _ensureAgent(agentID); | |||
return agentAddress; | |||
// No error checking here, because the agent will not exist at first and needs to be created. |
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 would rather document the behavior in a more generic manner in a doc comment above the function. For example:
A zero address is returned if no matching agent contract is found
This will also help to convey to auditors that this an explicit design choice on our part.
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 am not sure if we need to make this change in agentOf
to stop the relayers from restarting. We should only need this for channelNoncesOf
. Another thing we could do is not change the contracts at all and change the relayers to ignore the specific error, log it out and return default (0, 0)
for nonces. The reason for this is that I think these calls returning errors has better UX for people calling them from Etherscan UI or Tenderly.
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.
Agree. I would assume the restarting behavior as expected and not worthwhile to change contract just for that.
Another option is to revamp the e2e script a bit to first create agent/channel before starting the template relayer. To not block the e2e setup too long we can move these to a seperate script. But anyway, it's just a nice to have
improvement and not essential.
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.
Another thing we could do is not change the contracts at all and change the relayers to ignore the specific error, log it out and return default (0, 0) for nonces
Yes, I like this idea. It means we can leave the contracts alone. 👍
Otherwise we'd have to update all four getters in this file to stop using _ensure*
.
I have confirmed the create agent and create channel tests pass, thanks! I think it might have been related to some of the changes I have in-flight on #972. |
Checking if the agent and channel exists creates a chicken/egg condition where the agent and channel creation cannot be relayed for the first time.