Skip to content

Commit bbaaddb

Browse files
committed
Make skill reputation scaling calculation more efficient
1 parent be83bc8 commit bbaaddb

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

contracts/colony/ColonyStorage.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,14 @@ contract ColonyStorage is ColonyDataTypes, ColonyNetworkDataTypes, DSMath, Commo
366366
}
367367

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

372-
while (skill.nParents > 0 && factor > 0) {
373-
uint256 skillId = skill.parents[0];
374-
skill = IColonyNetwork(colonyNetworkAddress).getSkill(skillId);
375-
factor = wmul(factor, WAD - skillReputationRateComplements[skillId]);
371+
uint256[] memory allParents = IColonyNetwork(colonyNetworkAddress).getAllSkillParents(_skillId);
372+
uint256 count;
373+
374+
while (count < allParents.length && factor > 0) {
375+
factor = wmul(factor, WAD - skillReputationRateComplements[allParents[count]]);
376+
count +=1;
376377
}
377378

378379
return factor;

contracts/colonyNetwork/ColonyNetwork.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ contract ColonyNetwork is ColonyDataTypes, BasicMetaTransaction, ColonyNetworkSt
6060
skill = skills[_skillId];
6161
}
6262

63+
function getAllSkillParents(uint256 _skillId) public view returns (uint256[] memory){
64+
Skill storage skill = skills[_skillId];
65+
uint[] memory allParents = new uint256[](skill.nParents);
66+
uint256 count;
67+
for (uint256 count = 0; count < allParents.length; count += 1) {
68+
allParents[count] = skill.parents[0];
69+
skill = skills[skill.parents[0]];
70+
}
71+
72+
return allParents;
73+
}
74+
6375
function getReputationRootHash() public view returns (bytes32) {
6476
return reputationRootHash;
6577
}

contracts/colonyNetwork/IColonyNetwork.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,10 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery, IBasicMetaTransac
473473
/// @return numerator The numerator of the fraction reputation does down by every reputation cycle
474474
/// @return denominator The denominator of the fraction reputation does down by every reputation cycle
475475
function getColonyReputationDecayRate(address _colony) external view returns (uint256 numerator, uint256 denominator);
476+
477+
/// @notice Called to get an array containing all parent skill ids of a skill
478+
/// @param _skillId The skill id being queried
479+
/// @return parents An array containing the ids of all parent skills
480+
function getAllSkillParents(uint256 _skillId) external view returns (uint256[] memory parents);
481+
476482
}

docs/interfaces/icolonynetwork.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,23 @@ Set deprecation status for a skill
332332
|---|---|---|
333333
|_changed|bool|Whether the deprecated state was changed
334334

335+
### `getAllSkillParents(uint256 _skillId):uint256[] parents`
336+
337+
Called to get an array containing all parent skill ids of a skill
338+
339+
340+
**Parameters**
341+
342+
|Name|Type|Description|
343+
|---|---|---|
344+
|_skillId|uint256|The skill id being queried
345+
346+
**Return Parameters**
347+
348+
|Name|Type|Description|
349+
|---|---|---|
350+
|parents|uint256[]|An array containing the ids of all parent skills
351+
335352
### `getChildSkillId(uint256 _skillId, uint256 _childSkillIndex):uint256 _childSkillId`
336353

337354
Get the id of the child skill at index `_childSkillIndex` for skill with Id `_skillId`.

test/contracts-network/colony-permissions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,15 @@ contract("ColonyPermissions", (accounts) => {
409409
});
410410

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

418418
const limit = domainCount + N_LAYERS;
419419

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

0 commit comments

Comments
 (0)