Skip to content

Commit e7ddbbe

Browse files
authored
Fix naming bug so ens names are for graph accounts. Not subgraphs (#258)
* Fix default name to be on account, not subgraph. Subgraph metadata no longer triggers version update * Fix tests for naming changes
1 parent 9ef1c13 commit e7ddbbe

File tree

2 files changed

+101
-94
lines changed

2 files changed

+101
-94
lines changed

contracts/GNS.sol

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ contract GNS is Governed, BancorFormula {
5959

6060
// -- Events --
6161

62+
/**
63+
* @dev TODO
64+
*/
65+
event SetDefaultName(
66+
address graphAccount,
67+
uint256 nameSystem, // only ENS for now
68+
bytes32 nameIdentifier,
69+
string name
70+
);
71+
72+
event SubgraphMetadataUpdated(
73+
address graphAccount,
74+
uint256 subgraphNumber,
75+
bytes32 subgraphMetadata
76+
);
77+
6278
/**
6379
* @dev Emitted when a `graph account` publishes a `subgraph` with a `version`.
6480
* Every time this event is emitted, indicates a new version has been created.
@@ -68,10 +84,7 @@ contract GNS is Governed, BancorFormula {
6884
address graphAccount,
6985
uint256 subgraphNumber,
7086
bytes32 subgraphDeploymentID,
71-
uint256 nameSystem, // only ENS for now
72-
bytes32 nameIdentifier,
73-
string name,
74-
bytes32 metadataHash
87+
bytes32 versionMetadata
7588
);
7689

7790
/**
@@ -183,90 +196,76 @@ contract GNS is Governed, BancorFormula {
183196
emit ParameterUpdated("minimumVSignalStake");
184197
}
185198

199+
function setDefaultName(
200+
address _graphAccount,
201+
uint8 _nameSystem,
202+
bytes32 _nameIdentifier,
203+
string calldata _name
204+
) external onlyGraphAccountOwner(_graphAccount) {
205+
emit SetDefaultName(_graphAccount, _nameSystem, _nameIdentifier, _name);
206+
}
207+
208+
function updateSubgraphMetadata(
209+
address _graphAccount,
210+
uint256 _subgraphNumber,
211+
bytes32 _metadataHash
212+
) public onlyGraphAccountOwner(_graphAccount) {
213+
emit SubgraphMetadataUpdated(_graphAccount, _subgraphNumber, _metadataHash);
214+
}
215+
186216
/**
187217
* @dev Allows a graph account to publish a new subgraph, which means a new subgraph number
188-
* will be used. It then will call publish version. Subsequent versions can be created
189-
* by calling publishVersion() directly.
218+
* will be used.
190219
* @param _graphAccount Account that is publishing the subgraph
191220
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
192-
* @param _nameIdentifier The value used to look up ownership in the naming system
193-
* @param _name Name of the subgraph, from any valid system
194-
* @param _metadataHash IPFS hash for the subgraph, and subgraph version metadata
221+
* @param _versionMetadata IPFS hash for the subgraph version metadata
195222
*/
196223
function publishNewSubgraph(
197224
address _graphAccount,
198225
bytes32 _subgraphDeploymentID,
199-
bytes32 _nameIdentifier,
200-
string calldata _name,
201-
bytes32 _metadataHash
226+
bytes32 _versionMetadata
202227
) external onlyGraphAccountOwner(_graphAccount) {
203228
uint256 subgraphNumber = graphAccountSubgraphNumbers[_graphAccount];
204-
publishVersion(
205-
_graphAccount,
206-
subgraphNumber,
207-
_subgraphDeploymentID,
208-
_nameIdentifier,
209-
_name,
210-
_metadataHash
211-
);
229+
publishVersion(_graphAccount, subgraphNumber, _subgraphDeploymentID, _versionMetadata);
212230
graphAccountSubgraphNumbers[_graphAccount]++;
213231
}
214232

215233
/**
216-
* @dev Allows a graph account to publish a subgraph, with a version, a name, and metadata
217-
* Graph account must own the name of the name system they are linking to the subgraph
218-
* Version is derived from the occurance of SubgraphPublish being emitted. i.e. version 0
219-
* is the first time the event is emitted for the graph account and subgraph number
220-
* combination.
234+
* @dev Allows a graph account to publish a new version of their subgraph.
235+
* Version is derived from the occurance of SubgraphPublished being emitted.
236+
* The first time SubgraphPublished is called would be Version 0
221237
* @param _graphAccount Account that is publishing the subgraph
222238
* @param _subgraphNumber Subgraph number for the account
223239
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
224-
* @param _nameIdentifier The value used to look up ownership in the naming system
225-
* @param _name Name of the subgraph, from any valid system
226-
* @param _metadataHash IPFS hash for the subgraph, and subgraph version metadata
240+
* @param _versionMetadata IPFS hash for the subgraph version metadata
227241
*/
228242
function publishNewVersion(
229243
address _graphAccount,
230244
uint256 _subgraphNumber,
231245
bytes32 _subgraphDeploymentID,
232-
bytes32 _nameIdentifier,
233-
string calldata _name,
234-
bytes32 _metadataHash
246+
bytes32 _versionMetadata
235247
) external onlyGraphAccountOwner(_graphAccount) {
236248
require(
237-
isPublished(_graphAccount, _subgraphNumber) || // Hasn't been created yet
238-
_subgraphNumber < graphAccountSubgraphNumbers[_graphAccount], // Was created, but deprecated
239-
"GNS: Cant publish a version directly for a subgraph that wasnt created yet"
240-
);
241-
242-
publishVersion(
243-
_graphAccount,
244-
_subgraphNumber,
245-
_subgraphDeploymentID,
246-
_nameIdentifier,
247-
_name,
248-
_metadataHash
249+
isPublished(_graphAccount, _subgraphNumber),
250+
"GNS: Cannot update version if not published, or has been deprecated"
249251
);
252+
publishVersion(_graphAccount, _subgraphNumber, _subgraphDeploymentID, _versionMetadata);
250253
}
251254

252255
/**
253256
* @dev Internal function used by both external publishing functions
254257
* @param _graphAccount Account that is publishing the subgraph
255258
* @param _subgraphNumber Subgraph number for the account
256259
* @param _subgraphDeploymentID Subgraph deployment ID of the version, linked to the name
257-
* @param _nameIdentifier The value used to look up ownership in the naming system
258-
* @param _name Name of the subgraph, from any valid system
259-
* @param _metadataHash IPFS hash for the subgraph, and subgraph version metadata
260+
* @param _versionMetadata IPFS hash for the subgraph version metadata
260261
*/
261262
function publishVersion(
262263
address _graphAccount,
263264
uint256 _subgraphNumber,
264265
bytes32 _subgraphDeploymentID,
265-
bytes32 _nameIdentifier,
266-
string memory _name,
267-
bytes32 _metadataHash
266+
bytes32 _versionMetadata
268267
) internal {
269-
require(_subgraphDeploymentID != 0, "GNS: Cannot set to 0 in publish");
268+
require(_subgraphDeploymentID != 0, "GNS: Cannot set deploymentID to 0 in publish");
270269

271270
// Stores a subgraph deployment ID, which indicates a version has been created
272271
subgraphs[_graphAccount][_subgraphNumber] = _subgraphDeploymentID;
@@ -275,10 +274,7 @@ contract GNS is Governed, BancorFormula {
275274
_graphAccount,
276275
_subgraphNumber,
277276
_subgraphDeploymentID,
278-
0,
279-
_nameIdentifier,
280-
_name,
281-
_metadataHash
277+
_versionMetadata
282278
);
283279
}
284280

@@ -353,6 +349,7 @@ contract GNS is Governed, BancorFormula {
353349
uint256 _subgraphNumber,
354350
bytes32 _newSubgraphDeploymentID
355351
) external onlyGraphAccountOwner(_graphAccount) {
352+
require(_newSubgraphDeploymentID != 0, "GNS: Deployment ID cannot be 0");
356353
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
357354
// Subgraph owner must first update the numbered subgraph to point to this deploymentID
358355
// Then they can direct the name curators vSignal to this new name curation curve
@@ -486,7 +483,7 @@ contract GNS is Governed, BancorFormula {
486483
bytes32 subgraphDeploymentID = subgraphs[_graphAccount][_subgraphNumber];
487484
NameCurationPool storage namePool = nameSignals[_graphAccount][_subgraphNumber];
488485
require(
489-
namePool.subgraphDeploymentID == subgraphDeploymentID,
486+
namePool.subgraphDeploymentID == subgraphDeploymentID, // TODO EDGE CASE - when both subgraph ids are 0, this will fail, leading something to be deprecated before it exists
490487
"GNS: Name owner updated version without updating name signal"
491488
);
492489
require(namePool.disabled == false, "GNS: Cannot be disabled twice");

test/gns.test.ts

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface Subgraph {
1414
subgraphDeploymentID: string
1515
name: string
1616
nameIdentifier: string
17-
metadataHash: string
17+
versionMetadata: string
18+
subgraphMetadata: string
1819
}
1920

2021
describe('GNS', () => {
@@ -40,7 +41,8 @@ describe('GNS', () => {
4041
subgraphDeploymentID: randomHexBytes(),
4142
name: name,
4243
nameIdentifier: ethers.utils.namehash(name),
43-
metadataHash: randomHexBytes(),
44+
versionMetadata: randomHexBytes(),
45+
subgraphMetadata: randomHexBytes(),
4446
}
4547
}
4648

@@ -62,20 +64,15 @@ describe('GNS', () => {
6264
.publishNewSubgraph(
6365
graphAccount,
6466
subgraphToPublish.subgraphDeploymentID,
65-
subgraphToPublish.nameIdentifier,
66-
subgraphToPublish.name,
67-
subgraphToPublish.metadataHash,
67+
subgraphToPublish.versionMetadata,
6868
)
6969
await expect(tx)
7070
.emit(gns, 'SubgraphPublished')
7171
.withArgs(
7272
subgraphToPublish.graphAccount.address,
7373
subgraphNumber0,
7474
subgraphToPublish.subgraphDeploymentID,
75-
0,
76-
subgraphToPublish.nameIdentifier,
77-
subgraphToPublish.name,
78-
subgraphToPublish.metadataHash,
75+
subgraphToPublish.versionMetadata,
7976
)
8077
return tx
8178
}
@@ -91,9 +88,7 @@ describe('GNS', () => {
9188
graphAccount,
9289
subgraphNumber0,
9390
subgraphToPublish.subgraphDeploymentID,
94-
subgraphToPublish.nameIdentifier,
95-
subgraphToPublish.name,
96-
subgraphToPublish.metadataHash,
91+
subgraphToPublish.versionMetadata,
9792
)
9893

9994
const deprecateSubgraph = async (
@@ -419,7 +414,39 @@ describe('GNS', () => {
419414
await fixture.tearDown()
420415
})
421416

422-
describe('Publishing names', function () {
417+
describe('Publishing names and versions', function () {
418+
describe('setDefaultName', function () {
419+
it('setDefaultName emits the event', async function () {
420+
const tx = gns
421+
.connect(me.signer)
422+
.setDefaultName(me.address, 0, subgraph1.nameIdentifier, subgraph1.name)
423+
await expect(tx)
424+
.emit(gns, 'SetDefaultName')
425+
.withArgs(subgraph1.graphAccount.address, 0, subgraph1.nameIdentifier, subgraph1.name)
426+
})
427+
it('setDefaultName fails if not owner', async function () {
428+
const tx = gns
429+
.connect(other.signer)
430+
.setDefaultName(me.address, 0, subgraph1.nameIdentifier, subgraph1.name)
431+
await expect(tx).revertedWith('GNS: Only graph account owner can call')
432+
})
433+
})
434+
describe('updateSubgraphMetadata', function () {
435+
it('updateSubgraphMetadata emits the event', async function () {
436+
const tx = gns
437+
.connect(me.signer)
438+
.updateSubgraphMetadata(me.address, 0, subgraph1.subgraphMetadata)
439+
await expect(tx)
440+
.emit(gns, 'SubgraphMetadataUpdated')
441+
.withArgs(subgraph1.graphAccount.address, 0, subgraph1.subgraphMetadata)
442+
})
443+
it('updateSubgraphMetadata fails if not owner', async function () {
444+
const tx = gns
445+
.connect(other.signer)
446+
.updateSubgraphMetadata(me.address, 0, subgraph1.subgraphMetadata)
447+
await expect(tx).revertedWith('GNS: Only graph account owner can call')
448+
})
449+
})
423450
describe('isPublished', function () {
424451
it('should return if the subgraph is published', async function () {
425452
expect(await gns.isPublished(subgraph1.graphAccount.address, 0)).eq(false)
@@ -455,11 +482,9 @@ describe('GNS', () => {
455482
.publishNewSubgraph(
456483
subgraph1.graphAccount.address,
457484
ethers.constants.HashZero,
458-
subgraph1.nameIdentifier,
459-
subgraph1.name,
460-
subgraph1.metadataHash,
485+
subgraph1.versionMetadata,
461486
)
462-
await expect(tx).revertedWith('GNS: Cannot set to 0 in publish')
487+
await expect(tx).revertedWith('GNS: Cannot set deploymentID to 0 in publish')
463488
})
464489
})
465490

@@ -475,18 +500,13 @@ describe('GNS', () => {
475500
subgraph1.graphAccount.address,
476501
0,
477502
subgraph1.subgraphDeploymentID,
478-
0,
479-
subgraph1.nameIdentifier,
480-
subgraph1.name,
481-
subgraph1.metadataHash,
503+
subgraph1.versionMetadata,
482504
)
483505
})
484506

485507
it('should reject publishing a version to a numbered subgraph that does not exist', async function () {
486-
const tx = publishNewVersion(me, me.address, 0)
487-
await expect(tx).revertedWith(
488-
'GNS: Cant publish a version directly for a subgraph that wasnt created yet',
489-
)
508+
const tx = publishNewVersion(me, me.address, 9999)
509+
await expect(tx).revertedWith('GNS: Cannot update version if not published')
490510
})
491511

492512
it('reject if not the owner', async function () {
@@ -507,23 +527,13 @@ describe('GNS', () => {
507527
expect(ethers.constants.HashZero).eq(deploymentID)
508528
})
509529

510-
it('should allow a deprecated subgraph to be republished', async function () {
530+
it('should prevent a deprecated subgraph from being republished', async function () {
511531
await publishNewSubgraph(me, me.address, 0)
512532
await deprecateSubgraph(me, me.address, 0)
513533
const tx = publishNewVersion(me, me.address, 0)
514-
515-
// Event being emitted indicates version has been updated
516-
await expect(tx)
517-
.emit(gns, 'SubgraphPublished')
518-
.withArgs(
519-
subgraph1.graphAccount.address,
520-
0,
521-
subgraph1.subgraphDeploymentID,
522-
0,
523-
subgraph1.nameIdentifier,
524-
subgraph1.name,
525-
subgraph1.metadataHash,
526-
)
534+
await expect(tx).revertedWith(
535+
'Cannot update version if not published, or has been deprecated',
536+
)
527537
})
528538

529539
it('reject if the subgraph does not exist', async function () {

0 commit comments

Comments
 (0)