Skip to content

Commit

Permalink
Improve chain id mapping update events
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Oct 8, 2023
1 parent 8a99e67 commit a91403d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
}
address oldGovernanceTimelock = governanceTimelock;
governanceTimelock = _governanceTimelock;
emit GovernanceTimelockUpdated(oldGovernanceTimelock, governanceTimelock);
emit GovernanceTimelockUpdated(oldGovernanceTimelock, _governanceTimelock);
}

/// @notice Update bridge receiver adapters.
Expand Down
8 changes: 5 additions & 3 deletions src/adapters/axelar/AxelarSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import "./interfaces/IAxelarGasService.sol";
import "./libraries/StringAddressConversion.sol";

contract AxelarSenderAdapter is BaseSenderAdapter {
/// @notice event emitted when chain id mapping is updated
event ChainIDMappingUpdated(uint256[] origIds, string[] axlIds);
/// @notice event emitted when a chain id mapping is updated
event ChainIDMappingUpdated(uint256 indexed origId, string oldAxlId, string newAxlId);

string public constant name = "AXELAR";

Expand Down Expand Up @@ -85,13 +85,15 @@ contract AxelarSenderAdapter is BaseSenderAdapter {
revert Error.ZERO_CHAIN_ID();
}

string memory oldAxlId = chainIdMap[_origIds[i]];
chainIdMap[_origIds[i]] = _axlIds[i];

emit ChainIDMappingUpdated(_origIds[i], oldAxlId, _axlIds[i]);

unchecked {
++i;
}
}
emit ChainIDMappingUpdated(_origIds, _axlIds);
}

/*/////////////////////////////////////////////////////////////////
Expand Down
8 changes: 5 additions & 3 deletions src/adapters/wormhole/WormholeSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import "../../libraries/Types.sol";

/// @notice sender adapter for wormhole bridge
contract WormholeSenderAdapter is BaseSenderAdapter {
/// @notice event emitted when chain id mapping is updated
event ChainIDMappingUpdated(uint256[] origIds, uint16[] whIds);
/// @notice event emitted when a chain id mapping is updated
event ChainIDMappingUpdated(uint256 indexed origId, uint16 oldWhId, uint16 newWhId);

string public constant name = "WORMHOLE";
IWormholeRelayer public immutable relayer;
Expand Down Expand Up @@ -87,12 +87,14 @@ contract WormholeSenderAdapter is BaseSenderAdapter {
revert Error.ZERO_CHAIN_ID();
}

uint16 oldWhId = chainIdMap[_origIds[i]];
chainIdMap[_origIds[i]] = _whIds[i];

emit ChainIDMappingUpdated(_origIds[i], oldWhId, _whIds[i]);

unchecked {
++i;
}
}
emit ChainIDMappingUpdated(_origIds, _whIds);
}
}
4 changes: 2 additions & 2 deletions test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract AxelarSenderAdapterTest is Setup {
event MessageDispatched(
bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data
);
event ChainIDMappingUpdated(uint256[] origIds, string[] axlIds);
event ChainIDMappingUpdated(uint256 indexed origId, string oldAxlId, string newAxlId);

address senderAddr;
AxelarSenderAdapter adapter;
Expand Down Expand Up @@ -111,7 +111,7 @@ contract AxelarSenderAdapterTest is Setup {
axlIds[0] = "42";

vm.expectEmit(true, true, true, true, address(adapter));
emit ChainIDMappingUpdated(origIds, axlIds);
emit ChainIDMappingUpdated(origIds[0], adapter.chainIdMap(DST_CHAIN_ID), axlIds[0]);

adapter.setChainIdMap(origIds, axlIds);

Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract WormholeSenderAdapterTest is Setup {
event MessageDispatched(
bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data
);
event ChainIDMappingUpdated(uint256[] origIds, uint16[] whIds);
event ChainIDMappingUpdated(uint256 indexed origId, uint16 oldWhId, uint16 newWhId);

address senderAddr;
WormholeSenderAdapter adapter;
Expand Down Expand Up @@ -108,7 +108,7 @@ contract WormholeSenderAdapterTest is Setup {
whIds[0] = 42;

vm.expectEmit(true, true, true, true, address(adapter));
emit ChainIDMappingUpdated(origIds, whIds);
emit ChainIDMappingUpdated(origIds[0], adapter.chainIdMap(DST_CHAIN_ID), whIds[0]);

adapter.setChainIdMap(origIds, whIds);

Expand Down

0 comments on commit a91403d

Please sign in to comment.