Skip to content

Commit

Permalink
feat: clean deprecated code more
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinlink committed Aug 27, 2024
1 parent 34a4be6 commit 73ca43d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 90 deletions.
6 changes: 2 additions & 4 deletions contracts/BSCValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
}

function handleAckPackage(uint8 channelId, bytes calldata msgBytes) external override onlyCrossChainContract {
// should not happen
emit unexpectedPackage(channelId, msgBytes);
revert("deprecated");
}

function handleFailAckPackage(uint8 channelId, bytes calldata msgBytes) external override onlyCrossChainContract {
// should not happen
emit unexpectedPackage(channelId, msgBytes);
revert("deprecated");
}

/*----------------- External Functions -----------------*/
Expand Down
91 changes: 5 additions & 86 deletions contracts/deprecated/RelayerHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,109 +73,28 @@ contract RelayerHub is IRelayerHub, System, IParamSubscriber {
}

function whitelistInit() external {
require(!whitelistInitDone, "the whitelists already updated");
addInitRelayer(WHITELIST_1);
addInitRelayer(WHITELIST_2);
whitelistInitDone = true;
}

function addInitRelayer(address addr) internal {
relayManagersExistMap[addr] = true;
managerToRelayer[addr] = addr; // for the current whitelisted relayers we are keeping manager and relayer address the same
currentRelayers[addr] = true;
emit managerAdded(addr);
emit relayerUpdated(address(0), addr);
revert("deprecated");
}

/*----------------- Param update -----------------*/
function updateParam(string calldata key, bytes calldata value) external override onlyInit onlyGov {
if (Memory.compareStrings(key, "addManager")) {
require(value.length == 20, "length of manager address mismatch");
address newManager = BytesToTypes.bytesToAddress(20, value);
addManagerByGov(newManager);
} else if (Memory.compareStrings(key, "removeManager")) {
require(value.length == 20, "length of manager address mismatch");
address managerAddress = BytesToTypes.bytesToAddress(20, value);
removeManager(managerAddress);
} else {
require(false, "unknown param");
}
emit paramChange(key, value);
revert("deprecated");
}

function removeManagerByHimself() external {
// here the manager removes himself
removeManager(msg.sender);
}

function removeManager(address managerAddress) internal {
// check if the manager address already exists
require(relayManagersExistMap[managerAddress], "manager doesn't exist");

address relayerAddress = managerToRelayer[managerAddress];

delete (relayManagersExistMap[managerAddress]);
delete (managerToRelayer[managerAddress]);

delete (provisionalRelayers[managerToProvisionalRelayer[managerAddress]]);
delete (managerToProvisionalRelayer[managerAddress]);

// emit success event
emit managerRemoved(managerAddress);
if (relayerAddress != address(0)) {
delete (currentRelayers[relayerAddress]);
emit relayerUpdated(relayerAddress, address(0));
}
}

function addManagerByGov(address managerToBeAdded) internal {
require(!relayManagersExistMap[managerToBeAdded], "manager already exists");

relayManagersExistMap[managerToBeAdded] = true;

emit managerAdded(managerToBeAdded);
revert("deprecated");
}

// updateRelayer() can be used to add relayer for the first time, update it in future and remove it
// in case of removal, we set relayerToBeAdded to be address(0)
function updateRelayer(address relayerToBeAdded) external onlyManager {
require(!isContract(relayerToBeAdded), "contract is not allowed to be a relayer");

if (relayerToBeAdded != address(0)) {
require(!currentRelayers[relayerToBeAdded], "relayer already exists");
provisionalRelayers[relayerToBeAdded] = true;
managerToProvisionalRelayer[msg.sender] = relayerToBeAdded;
} else {
address oldRelayer = managerToRelayer[msg.sender];
address oldProvisionalRelayer = managerToProvisionalRelayer[msg.sender];
delete managerToRelayer[msg.sender];
delete currentRelayers[oldRelayer];
delete provisionalRelayers[oldProvisionalRelayer];
delete managerToProvisionalRelayer[msg.sender];
emit relayerUpdated(oldRelayer, relayerToBeAdded);
return;
}

emit relayerAddedProvisionally(relayerToBeAdded);
revert("deprecated");
}

// acceptBeingRelayer needs to be called by the relayer after being added provisionally.
// This 2 step process of relayer updating is required to avoid having a contract as a relayer.
function acceptBeingRelayer(address manager) external onlyProvisionalRelayer {
// ensure msg.sender is not contract and it is not a proxy
require(!isContract(msg.sender), "provisional relayer is a contract");
require(tx.origin == msg.sender, "provisional relayer is a proxy");
require(managerToProvisionalRelayer[manager] == msg.sender, "provisional is not set for this manager");

address oldRelayer = managerToRelayer[manager];

currentRelayers[msg.sender] = true;
managerToRelayer[manager] = msg.sender;

delete provisionalRelayers[msg.sender];
delete managerToProvisionalRelayer[manager];
delete currentRelayers[oldRelayer];
emit relayerUpdated(oldRelayer, msg.sender);
revert("deprecated");
}

function isRelayer(address relayerAddress) external view override returns (bool) {
Expand Down

0 comments on commit 73ca43d

Please sign in to comment.