Skip to content

Commit e1754ed

Browse files
committed
Straighten out bridged skill trees so they match
1 parent 5aed2f0 commit e1754ed

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

contracts/colonyNetwork/ColonyNetwork.sol

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ contract ColonyNetwork is BasicMetaTransaction, ColonyNetworkStorage, Multicall
156156

157157
bridgeSkillIfNotMiningChain(skillCount);
158158

159-
emit SkillAdded(skillCount, _parentSkillId);
160159
return skillCount;
161160
}
162161

@@ -175,11 +174,17 @@ contract ColonyNetwork is BasicMetaTransaction, ColonyNetworkStorage, Multicall
175174
bridgeData[miningBridgeAddress].skillCreationAfter
176175
);
177176

177+
// This succeeds if not set, but we don't want to block e.g. domain creation if that's the situation we're in,
178+
// and we can re-call this function to bridge later if necessary.
178179
(bool success, bytes memory returnData) = miningBridgeAddress.call(payload);
179180
require(success, "colony-network-unable-to-bridge-skill-creation");
180181
}
181182

182183
function addSkillToChainTree(uint256 _parentSkillId, uint256 _skillId) private {
184+
// This indicates a new root local skill bridged from another chain. We don't do anything to the tree
185+
// in this scenario, other than incrementing
186+
// (this mirrors the behaviour of not calling addSkill() in initialiseRootLocalSkill)
187+
if (_parentSkillId != 0 && _parentSkillId << 128 == 0) { return; }
183188

184189
Skill storage parentSkill = skills[_parentSkillId];
185190
// Global and local skill trees are kept separate
@@ -222,11 +227,13 @@ contract ColonyNetwork is BasicMetaTransaction, ColonyNetworkStorage, Multicall
222227
treeWalkingCounter += 1;
223228
}
224229
} else {
225-
// Add a global skill
230+
// Add a global skill. Should not be possible on a non-mining chain
226231
require(isMiningChain(), "colony-network-not-mining-chain");
227232
s.globalSkill = true;
228233
skills[_skillId] = s;
229234
}
235+
236+
emit SkillAdded(_skillId, _parentSkillId);
230237
}
231238

232239
function addSkillFromBridge(uint256 _parentSkillId, uint256 _skillId) public always onlyMiningChain() {
@@ -238,7 +245,6 @@ contract ColonyNetwork is BasicMetaTransaction, ColonyNetworkStorage, Multicall
238245
if (networkSkillCounts[bridge.chainId] + 1 == _skillId){
239246
addSkillToChainTree(_parentSkillId, _skillId);
240247
networkSkillCounts[bridge.chainId] += 1;
241-
emit SkillAdded(_skillId, _parentSkillId);
242248
} else if (networkSkillCounts[bridge.chainId] < _skillId){
243249
pendingSkillAdditions[bridge.chainId][_skillId] = _parentSkillId;
244250
// TODO: Event?
@@ -263,14 +269,11 @@ contract ColonyNetwork is BasicMetaTransaction, ColonyNetworkStorage, Multicall
263269

264270
uint256 parentSkillId = pendingSkillAdditions[bridge.chainId][_skillId];
265271
require(parentSkillId != 0, "colony-network-no-such-bridged-skill");
266-
if (parentSkillId > bridge.chainId << 128){
267-
addSkillToChainTree(parentSkillId, _skillId);
268-
}
272+
addSkillToChainTree(parentSkillId, _skillId);
269273
networkSkillCounts[bridge.chainId] += 1;
270274

271275
// Delete the pending addition
272276
delete pendingSkillAdditions[bridge.chainId][_skillId];
273-
emit SkillAdded(_skillId, parentSkillId);
274277
}
275278

276279
function getParentSkillId(uint _skillId, uint _parentSkillIndex) public view returns (uint256) {

test/cross-chain/cross-chain.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,39 @@ contract("Cross-chain", (accounts) => {
541541
tx = await foreignColonyNetwork.bridgeSkillIfNotMiningChain(skillCount, { gasLimit: 1000000 });
542542
await checkErrorRevertEthers(tx.wait(), "colony-network-unable-to-bridge-skill-creation");
543543
});
544+
545+
it("colony root local skill structures end up the same on both chains", async () => {
546+
const homeColonyRootLocalSkillId = await homeColony.getRootLocalSkill();
547+
let homeColonyRootLocalSkill = await homeColonyNetwork.getSkill(homeColonyRootLocalSkillId);
548+
549+
const foreignColonyRootLocalSkillId = await foreignColony.getRootLocalSkill();
550+
let foreignColonyRootLocalSkill = await foreignColonyNetwork.getSkill(foreignColonyRootLocalSkillId);
551+
552+
expect(homeColonyRootLocalSkill.nParents.toString()).to.equal(foreignColonyRootLocalSkill.nParents.toString());
553+
expect(homeColonyRootLocalSkill.nChildren.toString()).to.equal(foreignColonyRootLocalSkill.nChildren.toString());
554+
555+
let tx = await homeColony.addLocalSkill();
556+
await tx.wait();
557+
558+
const p = getPromiseForNextBridgedTransaction();
559+
tx = await foreignColony.addLocalSkill();
560+
await tx.wait();
561+
await p;
562+
homeColonyRootLocalSkill = await homeColonyNetwork.getSkill(homeColonyRootLocalSkillId);
563+
foreignColonyRootLocalSkill = await foreignColonyNetwork.getSkill(foreignColonyRootLocalSkillId);
564+
565+
expect(homeColonyRootLocalSkill.nParents.toString()).to.equal(foreignColonyRootLocalSkill.nParents.toString());
566+
expect(homeColonyRootLocalSkill.nChildren.toString()).to.equal(foreignColonyRootLocalSkill.nChildren.toString());
567+
568+
let zeroSkill = await foreignColonyNetwork.getSkill(ethers.BigNumber.from(foreignChainId).mul(ethers.BigNumber.from(2).pow(128)));
569+
expect(zeroSkill.nChildren.toNumber()).to.equal(0);
570+
571+
zeroSkill = await homeColonyNetwork.getSkill(ethers.BigNumber.from(foreignChainId).mul(ethers.BigNumber.from(2).pow(128)));
572+
expect(zeroSkill.nChildren.toNumber()).to.equal(0);
573+
574+
zeroSkill = await homeColonyNetwork.getSkill(0);
575+
expect(zeroSkill.nChildren.toNumber()).to.equal(0);
576+
});
544577
});
545578

546579
describe("while earning reputation on another chain", async () => {
@@ -566,14 +599,12 @@ contract("Cross-chain", (accounts) => {
566599
// console.log(txDataToBeSentToAMB);
567600

568601
// process.exit(1)
569-
console.log("****asdf");
570602
let p = getPromiseForNextBridgedTransaction();
571603
// Emit reputation
572604
await foreignColony.emitDomainReputationReward(1, accounts[0], "0x1337");
573605
// See that it's bridged to the inactive log
574-
console.log("asdf");
575606
await p;
576-
console.log("asdf");
607+
577608
const logAddress = await homeColonyNetwork.getReputationMiningCycle(false);
578609
const reputationMiningCycleInactive = await new ethers.Contract(logAddress, IReputationMiningCycle.abi, ethersHomeSigner);
579610

0 commit comments

Comments
 (0)