Skip to content

Commit

Permalink
Make skill reputation scaling calculation more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Jun 20, 2023
1 parent be83bc8 commit bbaaddb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
11 changes: 6 additions & 5 deletions contracts/colony/ColonyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,14 @@ contract ColonyStorage is ColonyDataTypes, ColonyNetworkDataTypes, DSMath, Commo
}

function getSkillReputationScaling(uint256 _skillId) public view returns (uint256) {
Skill memory skill = IColonyNetwork(colonyNetworkAddress).getSkill(_skillId);
uint256 factor = WAD - skillReputationRateComplements[_skillId];

while (skill.nParents > 0 && factor > 0) {
uint256 skillId = skill.parents[0];
skill = IColonyNetwork(colonyNetworkAddress).getSkill(skillId);
factor = wmul(factor, WAD - skillReputationRateComplements[skillId]);
uint256[] memory allParents = IColonyNetwork(colonyNetworkAddress).getAllSkillParents(_skillId);
uint256 count;

while (count < allParents.length && factor > 0) {
factor = wmul(factor, WAD - skillReputationRateComplements[allParents[count]]);
count +=1;
}

return factor;
Expand Down
12 changes: 12 additions & 0 deletions contracts/colonyNetwork/ColonyNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ contract ColonyNetwork is ColonyDataTypes, BasicMetaTransaction, ColonyNetworkSt
skill = skills[_skillId];
}

function getAllSkillParents(uint256 _skillId) public view returns (uint256[] memory){
Skill storage skill = skills[_skillId];
uint[] memory allParents = new uint256[](skill.nParents);
uint256 count;
for (uint256 count = 0; count < allParents.length; count += 1) {
allParents[count] = skill.parents[0];
skill = skills[skill.parents[0]];
}

return allParents;
}

function getReputationRootHash() public view returns (bytes32) {
return reputationRootHash;
}
Expand Down
6 changes: 6 additions & 0 deletions contracts/colonyNetwork/IColonyNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,10 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery, IBasicMetaTransac
/// @return numerator The numerator of the fraction reputation does down by every reputation cycle
/// @return denominator The denominator of the fraction reputation does down by every reputation cycle
function getColonyReputationDecayRate(address _colony) external view returns (uint256 numerator, uint256 denominator);

/// @notice Called to get an array containing all parent skill ids of a skill
/// @param _skillId The skill id being queried
/// @return parents An array containing the ids of all parent skills
function getAllSkillParents(uint256 _skillId) external view returns (uint256[] memory parents);

}
17 changes: 17 additions & 0 deletions docs/interfaces/icolonynetwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,23 @@ Set deprecation status for a skill
|---|---|---|
|_changed|bool|Whether the deprecated state was changed

### `getAllSkillParents(uint256 _skillId):uint256[] parents`

Called to get an array containing all parent skill ids of a skill


**Parameters**

|Name|Type|Description|
|---|---|---|
|_skillId|uint256|The skill id being queried

**Return Parameters**

|Name|Type|Description|
|---|---|---|
|parents|uint256[]|An array containing the ids of all parent skills

### `getChildSkillId(uint256 _skillId, uint256 _childSkillIndex):uint256 _childSkillId`

Get the id of the child skill at index `_childSkillIndex` for skill with Id `_skillId`.
Expand Down
4 changes: 2 additions & 2 deletions test/contracts-network/colony-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,15 @@ contract("ColonyPermissions", (accounts) => {
});

it("should be able to apply reputation earned scaling to 150 layers of domains", async () => {
const N_LAYERS = 50;
const N_LAYERS = 150;
await removeSubdomainLimit(colonyNetwork);
await colony.addDomain(1, UINT256_MAX, 1);
let domainCount = await colony.getDomainCount();
domainCount = domainCount.toNumber();

const limit = domainCount + N_LAYERS;

// Limit currently appears to be ???
// Limit currently appears to be about 160
for (let i = domainCount - 2; i < limit - 2; i += 1) {
await colony.addDomain(1, i, i + 2);
}
Expand Down

0 comments on commit bbaaddb

Please sign in to comment.