Skip to content

feat(cross-chain-oracle): Enable GovernorHub to change child messenger on child network#3688

Merged
chrismaree merged 18 commits intomasterfrom
npai/set-child-messenger
Dec 15, 2021
Merged

feat(cross-chain-oracle): Enable GovernorHub to change child messenger on child network#3688
chrismaree merged 18 commits intomasterfrom
npai/set-child-messenger

Conversation

@nicholaspai
Copy link
Copy Markdown
Member

Motivation

This PR enables the owner of GovernorHub to call relayGovernance with a new child messenger address, which will change the messenger address stored in the GovernorSpoke and OracleSpoke on the child chain. This allows the ChildMessenger to be upgraded without having to update the spoke contracts.

Testing

Check a box to describe how you tested these changes and list the steps for reviewers to test.

  • Ran end-to-end test, running the code as in production
  • New unit tests created
  • Existing tests adequate, no new tests required
  • All existing tests pass
  • Untested

@nicholaspai nicholaspai added cross-chain-oracle Contracts enabling cross-chain price resolution and governance audit-fix-phase6 Fixes for Phase 6 (Cross-chain oracle, optimistic rewarder, decentralized proposer) labels Dec 11, 2021
emit ExecutedGovernanceTransaction(to, inputData);
// There is a special case if `to` is this contract. If this contract is the target, then we assume that the
// cross-chain caller is attempting to change the child messenger.
if (to == address(this)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hhmm. ideally, we'd like a separate method that does this messenger upgrade. problem is though that our inbound calls from L2->L1 always go via the processMessagerFromParent call.

I don't think we want to overload this function like this. in my mind this is a bit of a code smell. it might be better to add a function on this contract called setChildMessenger, like you did on the OracleSpoke. Then, set the access control on that function to be called only by this contract. We'd then craft a normal Governance tx, sent over the bridge like any other one and it calls back into the GovernorSpoke by setting the to to be the address of this contract. Setting the messenger would be done by calling the OracleSpoke's SetMessengerSpoke via a normal governance call (using the function you added already).

what this means is we don't overload the function like this, the GovernorSpoke does not need to have an extra event, extra branching logic or need to store the Finder. We do need to send two governance transactions at once (one for each contract's spoke setting) but I think that's fine as it makes this part of the implementation was easier.

wdyt?

Copy link
Copy Markdown
Member

@chrismaree chrismaree Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this PR to use this implementation. now, we have one entry point setChildMessenger that sets the messengers in both contexts, which is intended to be called from the processMessageFromParent function.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree marked this pull request as ready for review December 14, 2021 14:59
Copy link
Copy Markdown
Member Author

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great left some nits


require(_executeCall(to, inputData), "execute call failed");
emit ExecutedGovernanceTransaction(to, inputData);
emit ExecutedGovernanceTransaction(to, data);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since "to" is a part of "data" I think you should either emit "to" and "inputData" (the data you call "to" with) or just data. I prefer leaving this the way it is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed! reverted

* to the processMessageFromParent function which intern calls back into this contract.
* @param newChildMessenger Address of the child messenger contract to set for this contract and OracleSpoke.
*/
function setChildMessenger(address newChildMessenger) public onlyThisContract {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should this be reentrant guarded?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method reverts if this has a reentrant guard on it :)

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
let owner;
let messenger;

let governor;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit to make tests easier to read.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +40 to +44
modifier onlyGovernorSpoke() {
require(
msg.sender == finder.getImplementationAddress(OracleInterfaces.GovernorSpoke),
"Caller must be governor spoke"
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be totally missing something, but where is this used?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not! good catch. removed.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree merged commit 7af4247 into master Dec 15, 2021
@chrismaree chrismaree deleted the npai/set-child-messenger branch December 15, 2021 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit-fix-phase6 Fixes for Phase 6 (Cross-chain oracle, optimistic rewarder, decentralized proposer) cross-chain-oracle Contracts enabling cross-chain price resolution and governance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants