Skip to content

Commit

Permalink
fixed Global-02, DPX-15, DPX-14
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed May 8, 2024
1 parent 4107caa commit 3b72cf9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/contracts/src/DaofinPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -564,28 +564,33 @@ contract DaofinPlugin is BaseDaofinPlugin {
// register if it is a candidate
if (!getGlobalSettings().xdcValidator.isCandidate(masterNode)) revert IsNotCandidate();

// delegatee must not be a jury or house member
// Delegatee/Master Node must not be a jury
if (isJudiciaryMember(delegatee_)) revert InValidAddress();
if (isJudiciaryMember(masterNode)) revert InValidAddress();

// Delegatee/Master Node must not be a house member
if (isPeopleHouse(delegatee_)) revert InValidAddress();
if (isPeopleHouse(masterNode)) revert InValidAddress();

// Store in mapping and reverse mappings
_updateMasterNodeDelegatee(masterNode, delegatee_);
_createOrUpdateMasterNodeDelegatee(masterNode, delegatee_);

emit MasterNodeDelegateeUpdated(masterNode, delegatee_);
}

function _updateMasterNodeDelegatee(address masterNode_, address delegatee_) private {
address _delegatee = _masterNodeDelegatee.masterNodeToDelegatee[masterNode_];
address _masterNode = _masterNodeDelegatee.delegateeToMasterNode[delegatee_];
function _createOrUpdateMasterNodeDelegatee(address masterNode_, address delegatee_) private {
address _cachedMasterNode = _masterNodeDelegatee.delegateeToMasterNode[delegatee_];
address _cachedDelegatee = _masterNodeDelegatee.masterNodeToDelegatee[masterNode_];

if (_cachedDelegatee == delegatee_ && _cachedMasterNode == masterNode_)
revert InValidAddress();

// Duplicate record
if (_delegatee == delegatee_ && _masterNode == masterNode_) revert InValidAddress();
if (_cachedMasterNode != address(0) && _cachedDelegatee == address(0))
revert InValidAddress();

// Master Node registers at the first time
if (_delegatee == address(0) && _masterNode == address(0)) {
if (_cachedDelegatee == address(0) && _cachedMasterNode == address(0)) {
_masterNodeDelegatee.numberOfJointMasterNodes++;
} else {
// Master Node wants to change its delegatee
if (isWithinElectionPeriod()) revert InValidTime();
}

Expand Down

0 comments on commit 3b72cf9

Please sign in to comment.