Skip to content

Commit

Permalink
Add initial adapters and quorum to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominator008 committed Oct 6, 2023
1 parent 6b25342 commit c4973e8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
27 changes: 19 additions & 8 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,20 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
////////////////////////////////////////////////////////////////*/

/// @notice sets the initial parameters
constructor(uint256 _srcChainId, address _gac) {
constructor(uint256 _srcChainId, address _gac, address[] memory _receiverAdapters, uint64 _quorum) {
srcChainId = _srcChainId;
gac = IGAC(_gac);

uint256 numAdapters = _receiverAdapters.length;
bool[] memory operations = new bool[](numAdapters);
for (uint256 i; i < numAdapters;) {
operations[i] = true;
unchecked {
++i;
}
}
_updateReceiverAdapters(_receiverAdapters, operations);
_validateAndUpdateQuorum(_quorum);
}

/*/////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -177,12 +188,12 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
_validateQuorum(quorum);
}

/// @notice Update bridge receiver adapters after quorum update
/// @dev called by admin to update receiver bridge adapters on all other chains
function updateQuorumAndReceiverAdapter(
uint64 _newQuorum,
/// @notice Update bridge receiver adapters and quorum
/// @dev called by admin to update receiver bridge adapters on all other chains along with quorum
function updateReceiverAdaptersAndQuorum(
address[] calldata _receiverAdapters,
bool[] calldata _operations
bool[] calldata _operations,
uint64 _newQuorum
) external override onlyGlobalOwner {
_updateReceiverAdapters(_receiverAdapters, _operations);
_validateAndUpdateQuorum(_newQuorum);
Expand Down Expand Up @@ -224,7 +235,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
PRIVATE/INTERNAL FUNCTIONS
////////////////////////////////////////////////////////////////*/

function _validateAndUpdateQuorum(uint64 _quorum) internal {
function _validateAndUpdateQuorum(uint64 _quorum) private {
_validateQuorum(_quorum);

uint64 oldValue = quorum;
Expand All @@ -233,7 +244,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
emit QuorumUpdated(oldValue, _quorum);
}

function _updateReceiverAdapters(address[] memory _receiverAdapters, bool[] memory _operations) internal {
function _updateReceiverAdapters(address[] memory _receiverAdapters, bool[] memory _operations) private {
uint256 len = _receiverAdapters.length;

if (len == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/IMultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ interface IMultiBridgeMessageReceiver {
function updateQuorum(uint64 _quorum) external;

/// @notice updates the the list of receiver adapters and the quorum for message validity.
/// @param _newQuorum is the new quorum value
/// @param _receiverAdapters the list of receiver adapters to add or remove
/// @param _operations the list of operations to perform for corresponding receiver adapters, true for add, false for remove
function updateQuorumAndReceiverAdapter(
uint64 _newQuorum,
/// @param _newQuorum is the new quorum value
function updateReceiverAdaptersAndQuorum(
address[] calldata _receiverAdapters,
bool[] calldata _operations
bool[] calldata _operations,
uint64 _newQuorum
) external;
}
16 changes: 6 additions & 10 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,13 @@ abstract contract Setup is Test {
uint256 chainId = DST_CHAINS[i];

vm.selectFork(fork[chainId]);

address[] memory _receiverAdapters = new address[](2);
_receiverAdapters[0] = contractAddress[chainId][bytes("WORMHOLE_RECEIVER_ADAPTER")];
_receiverAdapters[1] = contractAddress[chainId][bytes("AXELAR_RECEIVER_ADAPTER")];

address mmaReceiver = address(
new MultiBridgeMessageReceiver{salt: _salt}(SRC_CHAIN_ID, contractAddress[chainId][bytes("GAC")])
new MultiBridgeMessageReceiver{salt: _salt}(SRC_CHAIN_ID, contractAddress[chainId][bytes("GAC")], _receiverAdapters, 2)
);
contractAddress[chainId][bytes("MMA_RECEIVER")] = mmaReceiver;
contractAddress[chainId][bytes("TIMELOCK")] =
Expand Down Expand Up @@ -304,19 +309,10 @@ abstract contract Setup is Test {
for (uint256 i; i < DST_CHAINS.length;) {
uint256 chainId = DST_CHAINS[i];

address[] memory _receiverAdapters = new address[](2);
_receiverAdapters[0] = contractAddress[chainId][bytes("WORMHOLE_RECEIVER_ADAPTER")];
_receiverAdapters[1] = contractAddress[chainId][bytes("AXELAR_RECEIVER_ADAPTER")];

bool[] memory _operations = new bool[](2);
_operations[0] = true;
_operations[1] = true;

vm.selectFork(fork[chainId]);

MultiBridgeMessageReceiver dstMMReceiver =
MultiBridgeMessageReceiver(contractAddress[chainId][bytes("MMA_RECEIVER")]);
dstMMReceiver.updateQuorumAndReceiverAdapter(2, _receiverAdapters, _operations);
dstMMReceiver.updateGovernanceTimelock(contractAddress[chainId]["TIMELOCK"]);

MessageReceiverGAC receiverGAC = MessageReceiverGAC(contractAddress[chainId][bytes("GAC")]);
Expand Down
6 changes: 3 additions & 3 deletions test/integration-tests/RemoteAdapterRemove.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ contract RemoteAdapterRemove is Setup {
DST_CHAIN_ID,
address(contractAddress[DST_CHAIN_ID][bytes("MMA_RECEIVER")]),
abi.encodeWithSelector(
MultiBridgeMessageReceiver.updateQuorumAndReceiverAdapter.selector,
newQuorum,
MultiBridgeMessageReceiver.updateReceiverAdaptersAndQuorum.selector,
adaptersToRemove,
operation
operation,
newQuorum
),
0,
EXPIRATION_CONSTANT,
Expand Down
8 changes: 4 additions & 4 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ contract MultiBridgeMessageReceiverTest is Setup {
uint64 newQuorum = 1;

/// @dev removes the newly updated adapter by reducing quorum by one
receiver.updateQuorumAndReceiverAdapter(newQuorum, adapters, new bool[](1));
receiver.updateReceiverAdaptersAndQuorum(adapters, new bool[](1), newQuorum);

/// @dev asserts the quorum and adapter lengths
assertEq(receiver.quorum(), newQuorum);
Expand Down Expand Up @@ -478,7 +478,7 @@ contract MultiBridgeMessageReceiverTest is Setup {

uint64 newQuorum = 4;

receiver.updateQuorumAndReceiverAdapter(newQuorum, addTwoAdapters, addTwoOps);
receiver.updateReceiverAdaptersAndQuorum(addTwoAdapters, addTwoOps, newQuorum);

/// @dev asserts the quorum and adapter lengths
assertEq(receiver.quorum(), newQuorum);
Expand All @@ -496,7 +496,7 @@ contract MultiBridgeMessageReceiverTest is Setup {

uint64 newQuorum = 1;

receiver.updateQuorumAndReceiverAdapter(newQuorum, removeOneAdapter, new bool[](1));
receiver.updateReceiverAdaptersAndQuorum(removeOneAdapter, new bool[](1), newQuorum);

/// @dev asserts the quorum and adapter lengths
assertEq(receiver.quorum(), newQuorum);
Expand All @@ -520,7 +520,7 @@ contract MultiBridgeMessageReceiverTest is Setup {

uint64 newQuorum = 3;

receiver.updateQuorumAndReceiverAdapter(newQuorum, removeAddAdapters, removeAddOps);
receiver.updateReceiverAdaptersAndQuorum(removeAddAdapters, removeAddOps, newQuorum);

/// @dev asserts the quorum and adapter lengths
assertEq(receiver.quorum(), newQuorum);
Expand Down

0 comments on commit c4973e8

Please sign in to comment.