Skip to content

Commit

Permalink
evm: remove internal admin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gator-boi committed Feb 25, 2024
1 parent 37ddaeb commit 365b2d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion evm/src/interfaces/IWormholeTransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down

0 comments on commit 365b2d0

Please sign in to comment.