From 365b2d0baf244bc7780f0da1c55792b73f9d5124 Mon Sep 17 00:00:00 2001 From: gator-boi Date: Sun, 25 Feb 2024 13:29:58 -0600 Subject: [PATCH] evm: remove internal admin functions --- .../WormholeTransceiverState.sol | 79 ++++++++----------- evm/src/interfaces/IWormholeTransceiver.sol | 1 - 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol b/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol index 0317c8705..32907798a 100644 --- a/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol +++ b/evm/src/Transceiver/WormholeTransceiver/WormholeTransceiverState.sol @@ -177,76 +177,50 @@ abstract contract WormholeTransceiverState is IWormholeTransceiverState, Transce /// @inheritdoc IWormholeTransceiverState function setWormholePeer(uint16 peerChainId, bytes32 peerContract) external onlyOwner { - _setWormholePeer(peerChainId, peerContract); - } - - /// @inheritdoc IWormholeTransceiverState - function setIsWormholeEvmChain(uint16 chainId) external onlyOwner { - _setIsWormholeEvmChain(chainId); - } - - /// @inheritdoc IWormholeTransceiverState - function setIsWormholeRelayingEnabled(uint16 chainId, bool isEnabled) external onlyOwner { - _setIsWormholeRelayingEnabled(chainId, isEnabled); - } - - // ============= Internal =============================================================== - - function _setIsWormholeEvmChain(uint16 chainId) internal { - if (chainId == 0) { - revert InvalidWormholeChainIdZero(); - } - _getWormholeEvmChainIdsStorage()[chainId] = TRUE; - - emit SetIsWormholeEvmChain(chainId); - } - - function _checkInvalidRelayingConfig(uint16 chainId) internal view returns (bool) { - return isWormholeRelayingEnabled(chainId) && !isWormholeEvmChain(chainId); - } - - function _shouldRelayViaStandardRelaying(uint16 chainId) internal view returns (bool) { - return isWormholeRelayingEnabled(chainId) && isWormholeEvmChain(chainId); - } - - function _setVAAConsumed(bytes32 hash) internal { - _getWormholeConsumedVAAsStorage()[hash] = true; - } - - function _setWormholePeer(uint16 chainId, bytes32 peerContract) internal { - if (chainId == 0) { + if (peerChainId == 0) { revert InvalidWormholeChainIdZero(); } if (peerContract == bytes32(0)) { revert InvalidWormholePeerZeroAddress(); } - bytes32 oldPeerContract = _getWormholePeersStorage()[chainId]; + bytes32 oldPeerContract = _getWormholePeersStorage()[peerChainId]; // We don't want to allow updating a peer since this adds complexity in the accountant // If the owner makes a mistake with peer registration they should deploy a new Wormhole // transceiver and register this new transceiver with the NttManager if (oldPeerContract != bytes32(0)) { - revert PeerAlreadySet(chainId, oldPeerContract); + revert PeerAlreadySet(peerChainId, oldPeerContract); } - _getWormholePeersStorage()[chainId] = peerContract; + _getWormholePeersStorage()[peerChainId] = peerContract; // Publish a message for this transceiver registration TransceiverStructs.TransceiverRegistration memory registration = TransceiverStructs .TransceiverRegistration({ transceiverIdentifier: WH_PEER_REGISTRATION_PREFIX, - transceiverChainId: chainId, + transceiverChainId: peerChainId, transceiverAddress: peerContract }); wormhole.publishMessage( 0, TransceiverStructs.encodeTransceiverRegistration(registration), consistencyLevel ); - emit SetWormholePeer(chainId, peerContract); + emit SetWormholePeer(peerChainId, peerContract); } - function _setIsWormholeRelayingEnabled(uint16 chainId, bool isEnabled) internal { + /// @inheritdoc IWormholeTransceiverState + function setIsWormholeEvmChain(uint16 chainId) external onlyOwner { + if (chainId == 0) { + revert InvalidWormholeChainIdZero(); + } + _getWormholeEvmChainIdsStorage()[chainId] = TRUE; + + emit SetIsWormholeEvmChain(chainId); + } + + /// @inheritdoc IWormholeTransceiverState + function setIsWormholeRelayingEnabled(uint16 chainId, bool isEnabled) external onlyOwner { if (chainId == 0) { revert InvalidWormholeChainIdZero(); } @@ -255,7 +229,8 @@ abstract contract WormholeTransceiverState is IWormholeTransceiverState, Transce emit SetIsWormholeRelayingEnabled(chainId, isEnabled); } - function _setIsSpecialRelayingEnabled(uint16 chainId, bool isEnabled) internal { + /// @inheritdoc IWormholeTransceiverState + function setIsSpecialRelayingEnabled(uint16 chainId, bool isEnabled) external onlyOwner { if (chainId == 0) { revert InvalidWormholeChainIdZero(); } @@ -264,6 +239,20 @@ abstract contract WormholeTransceiverState is IWormholeTransceiverState, Transce emit SetIsSpecialRelayingEnabled(chainId, isEnabled); } + // ============= Internal =============================================================== + + function _checkInvalidRelayingConfig(uint16 chainId) internal view returns (bool) { + return isWormholeRelayingEnabled(chainId) && !isWormholeEvmChain(chainId); + } + + function _shouldRelayViaStandardRelaying(uint16 chainId) internal view returns (bool) { + return isWormholeRelayingEnabled(chainId) && isWormholeEvmChain(chainId); + } + + function _setVAAConsumed(bytes32 hash) internal { + _getWormholeConsumedVAAsStorage()[hash] = true; + } + // =============== MODIFIERS =============================================== modifier onlyRelayer() { diff --git a/evm/src/interfaces/IWormholeTransceiver.sol b/evm/src/interfaces/IWormholeTransceiver.sol index 75cd3c67c..c9f6a62b2 100644 --- a/evm/src/interfaces/IWormholeTransceiver.sol +++ b/evm/src/interfaces/IWormholeTransceiver.sol @@ -14,7 +14,6 @@ interface IWormholeTransceiver is IWormholeTransceiverState { event ReceivedMessage( bytes32 digest, uint16 emitterChainId, bytes32 emitterAddress, uint64 sequence ); - event SendTransceiverMessage( uint16 recipientChain, TransceiverStructs.TransceiverMessage message );