Skip to content
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

Closed

Conversation

claravanstaden
Copy link
Contributor

@claravanstaden claravanstaden commented Oct 25, 2023

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.

@claravanstaden claravanstaden marked this pull request as ready for review October 25, 2023 11:59
@yrong
Copy link
Contributor

yrong commented Oct 25, 2023

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.

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.

@claravanstaden
Copy link
Contributor Author

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.

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 start-services.sh, you'll see that the template parachain execution and parachain relayer keeps restarting. If you run the create agent test, you'll see the create agent message is sent to the outbound queue but it doesn't get relayed. So perhaps this is another bug - the bridge hub relayer isn't picking up the message as it should.

@yrong
Copy link
Contributor

yrong commented Oct 26, 2023

you'll see the create agent message is sent to the outbound queue but it doesn't get relayed.

Just tested seems create_agent and create_channel work as expected.

cargo test --test create_agent
...
Event found at ethereum block 278
test create_agent ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 87.78s
...

cargo test --test create_channel
...
test create_channel ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 126.06s

you'll see that the template parachain execution and parachain relayer keeps restarting.

Yes, it's as expected and the log will be fine after we create agent/channel for template parachain.

@claravanstaden
Copy link
Contributor Author

Let me retest. 😄

Comment on lines +214 to +217
// The agent will not exist at first and needs to be created.
if (ch.agent == address(0)) {
return (0, 0);
}
Copy link
Collaborator

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

Suggested change
// 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.
Copy link
Collaborator

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.

Copy link
Contributor

@alistair-singh alistair-singh Oct 26, 2023

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.

Copy link
Contributor

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.

Copy link
Collaborator

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*.

@claravanstaden
Copy link
Contributor Author

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.

@claravanstaden claravanstaden deleted the clara/agent-and-channel-will-not-exist-at-first branch October 30, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants