Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 973ea33

Browse files
Query model permissions (#79)
* Create fct queryModelPermissions * Add test * Add model to index * Add to smart contract switch * Add to README and EXAMPLES * Fix model permissions * Remove storage address from head model * Hash structure (#88) * Hash structure for head model * Improvements of the structure * Remove CompositeModelType system * Prevent from composite traintuple creation if worker not the same * Check directly the workers * Test worker conflict * Changes after reviews * Re-declare createModelIndex * Not comment * Add test on head model Co-authored-by: Kelvin <Kelvin-M@users.noreply.github.com>
1 parent 438be31 commit 973ea33

31 files changed

+337
-168
lines changed

EXAMPLES.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,28 @@ peer chaincode query -n mycc -c '{"Args":["queryModels"]}' -C myc
12311231
}
12321232
]
12331233
```
1234+
#### ------------ Query model permissions ------------
1235+
Smart contract: `queryModelPermissions`
1236+
1237+
##### JSON Inputs:
1238+
```go
1239+
{
1240+
"key": string (required,len=64,hexadecimal),
1241+
}
1242+
```
1243+
##### Command peer example:
1244+
```bash
1245+
peer chaincode query -n mycc -c '{"Args":["queryModelPermissions","{\"key\":\"eedbb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482eed\"}"]}' -C myc
1246+
```
1247+
##### Command output:
1248+
```json
1249+
{
1250+
"process": {
1251+
"authorizedIDs": [],
1252+
"public": true
1253+
}
1254+
}
1255+
```
12341256
#### ------------ Query Dataset ------------
12351257
Smart contract: `queryDataset`
12361258

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Note for internal use only: See the [technical specifications](https://github.co
3434

3535
### Implemented smart contracts
3636

37+
- `cancelComputePlan`
3738
- `createAggregatetuple`
3839
- `createCompositeTraintuple`
3940
- `createComputePlan`
@@ -69,6 +70,7 @@ Note for internal use only: See the [technical specifications](https://github.co
6970
- `queryDataset`
7071
- `queryFilter`
7172
- `queryModelDetails`
73+
- `queryModelPermissions`
7274
- `queryModels`
7375
- `queryNodes`
7476
- `queryObjective`

chaincode/algo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func registerAlgo(db *LedgerDB, args []string) (resp map[string]string, err erro
7777

7878
// queryAlgo returns an algo of the ledger given its key
7979
func queryAlgo(db *LedgerDB, args []string) (out outputAlgo, err error) {
80-
inp := inputHash{}
80+
inp := inputKey{}
8181
err = AssetFromJSON(args, &inp)
8282
if err != nil {
8383
return

chaincode/algo_aggregate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func registerAggregateAlgo(db *LedgerDB, args []string) (resp map[string]string,
7777

7878
// queryAggregateAlgo returns an algo of the ledger given its key
7979
func queryAggregateAlgo(db *LedgerDB, args []string) (out outputAggregateAlgo, err error) {
80-
inp := inputHash{}
80+
inp := inputKey{}
8181
err = AssetFromJSON(args, &inp)
8282
if err != nil {
8383
return

chaincode/algo_composite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func registerCompositeAlgo(db *LedgerDB, args []string) (resp map[string]string,
7777

7878
// queryCompositeAlgo returns an algo of the ledger given its key
7979
func queryCompositeAlgo(db *LedgerDB, args []string) (out outputCompositeAlgo, err error) {
80-
inp := inputHash{}
80+
inp := inputKey{}
8181
err = AssetFromJSON(args, &inp)
8282
if err != nil {
8383
return

chaincode/compute_plan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func createComputePlanInternal(db *LedgerDB, inp inputComputePlan) (resp outputC
227227
}
228228

229229
func queryComputePlan(db *LedgerDB, args []string) (resp outputComputePlan, err error) {
230-
inp := inputHash{}
230+
inp := inputKey{}
231231
err = AssetFromJSON(args, &inp)
232232
if err != nil {
233233
return
@@ -266,7 +266,7 @@ func getOutComputePlan(db *LedgerDB, key string) (resp outputComputePlan, err er
266266
}
267267

268268
func cancelComputePlan(db *LedgerDB, args []string) (resp outputComputePlan, err error) {
269-
inp := inputHash{}
269+
inp := inputKey{}
270270
err = AssetFromJSON(args, &inp)
271271
if err != nil {
272272
return

chaincode/compute_plan_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ func TestModelCompositionComputePlanWorkflow(t *testing.T) {
175175
validateTupleRank(t, db, 2, out.CompositeTraintupleKeys[2], CompositeTraintupleType)
176176
validateTupleRank(t, db, 2, out.CompositeTraintupleKeys[3], CompositeTraintupleType)
177177

178-
_, err = logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[0]}))
178+
_, err = logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[0]}))
179179
assert.NoError(t, err)
180-
_, err = logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[1]}))
180+
_, err = logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[1]}))
181181
assert.NoError(t, err)
182182

183183
db.tuplesEvent = &TuplesEvent{}
@@ -197,7 +197,7 @@ func TestModelCompositionComputePlanWorkflow(t *testing.T) {
197197
require.Len(t, db.tuplesEvent.Aggregatetuples, 1)
198198
assert.Equal(t, StatusTodo, db.tuplesEvent.Aggregatetuples[0].Status)
199199

200-
_, err = logStartAggregate(db, assetToArgs(inputHash{out.AggregatetupleKeys[0]}))
200+
_, err = logStartAggregate(db, assetToArgs(inputKey{out.AggregatetupleKeys[0]}))
201201
assert.NoError(t, err)
202202

203203
inpLogAgg := inputLogSuccessTrain{}
@@ -207,9 +207,9 @@ func TestModelCompositionComputePlanWorkflow(t *testing.T) {
207207
assert.NoError(t, err)
208208
assert.Equal(t, StatusDone, agg.Status)
209209

210-
_, err = logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[2]}))
210+
_, err = logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[2]}))
211211
assert.NoError(t, err)
212-
_, err = logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[3]}))
212+
_, err = logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[3]}))
213213
assert.NoError(t, err)
214214

215215
db.tuplesEvent = &TuplesEvent{}
@@ -227,7 +227,7 @@ func TestModelCompositionComputePlanWorkflow(t *testing.T) {
227227
}
228228

229229
func validateTupleRank(t *testing.T, db *LedgerDB, expectedRank int, key string, assetType AssetType) {
230-
inp := inputHash{Key: key}
230+
inp := inputKey{Key: key}
231231
rank := -42
232232
switch assetType {
233233
case CompositeTraintupleType:
@@ -302,7 +302,7 @@ func TestCreateComputePlanCompositeAggregate(t *testing.T) {
302302
require.Contains(t, outCP.AggregatetupleKeys, aggtuples[1].Key)
303303

304304
// Query the compute plan
305-
cp, err := queryComputePlan(db, assetToArgs(inputHash{Key: outCP.ComputePlanID}))
305+
cp, err := queryComputePlan(db, assetToArgs(inputKey{Key: outCP.ComputePlanID}))
306306
assert.NoError(t, err, "calling queryComputePlan should succeed")
307307
assert.NotNil(t, cp)
308308
assert.Equal(t, 2, len(cp.CompositeTraintupleKeys))
@@ -383,7 +383,7 @@ func TestQueryComputePlan(t *testing.T) {
383383
assert.NoError(t, err)
384384
assert.NotNil(t, outCP)
385385

386-
cp, err := queryComputePlan(db, assetToArgs(inputHash{Key: outCP.ComputePlanID}))
386+
cp, err := queryComputePlan(db, assetToArgs(inputKey{Key: outCP.ComputePlanID}))
387387
assert.NoError(t, err, "calling queryComputePlan should succeed")
388388
assert.NotNil(t, cp)
389389
validateDefaultComputePlan(t, cp)
@@ -452,7 +452,7 @@ func TestComputePlanEmptyTesttuples(t *testing.T) {
452452
assert.NotNil(t, outCP)
453453
assert.Len(t, outCP.TesttupleKeys, 0)
454454

455-
cp, err := queryComputePlan(db, assetToArgs(inputHash{Key: outCP.ComputePlanID}))
455+
cp, err := queryComputePlan(db, assetToArgs(inputKey{Key: outCP.ComputePlanID}))
456456
assert.NoError(t, err, "calling queryComputePlan should succeed")
457457
assert.NotNil(t, cp)
458458
assert.Len(t, outCP.TesttupleKeys, 0)
@@ -489,7 +489,7 @@ func TestCancelComputePlan(t *testing.T) {
489489
assert.NotNil(t, db.tuplesEvent)
490490
assert.Len(t, db.tuplesEvent.CompositeTraintuples, 2)
491491

492-
_, err = cancelComputePlan(db, assetToArgs(inputHash{Key: out.ComputePlanID}))
492+
_, err = cancelComputePlan(db, assetToArgs(inputKey{Key: out.ComputePlanID}))
493493
assert.NoError(t, err)
494494

495495
computePlan, err := getOutComputePlan(db, out.ComputePlanID)
@@ -529,11 +529,11 @@ func TestStartedTuplesOfCanceledComputePlan(t *testing.T) {
529529
out, err := createComputePlanInternal(db, modelCompositionComputePlan)
530530
assert.NoError(t, err)
531531

532-
logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[0]}))
533-
logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[1]}))
534-
logFailCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[1]}))
532+
logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[0]}))
533+
logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[1]}))
534+
logFailCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[1]}))
535535

536-
_, err = cancelComputePlan(db, assetToArgs(inputHash{Key: out.ComputePlanID}))
536+
_, err = cancelComputePlan(db, assetToArgs(inputKey{Key: out.ComputePlanID}))
537537
assert.NoError(t, err)
538538

539539
computePlan, err := getOutComputePlan(db, out.ComputePlanID)
@@ -561,10 +561,10 @@ func TestLogSuccessAfterCancel(t *testing.T) {
561561
out, err := createComputePlanInternal(db, modelCompositionComputePlan)
562562
assert.NoError(t, err)
563563

564-
logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[0]}))
565-
logStartCompositeTrain(db, assetToArgs(inputHash{out.CompositeTraintupleKeys[1]}))
564+
logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[0]}))
565+
logStartCompositeTrain(db, assetToArgs(inputKey{out.CompositeTraintupleKeys[1]}))
566566

567-
_, err = cancelComputePlan(db, assetToArgs(inputHash{Key: out.ComputePlanID}))
567+
_, err = cancelComputePlan(db, assetToArgs(inputKey{Key: out.ComputePlanID}))
568568
assert.NoError(t, err)
569569

570570
inp := inputLogSuccessCompositeTrain{}
@@ -617,7 +617,7 @@ func TestComputePlanMetrics(t *testing.T) {
617617
}
618618

619619
func traintupleToDone(t *testing.T, db *LedgerDB, key string) {
620-
_, err := logStartTrain(db, assetToArgs(inputHash{Key: key}))
620+
_, err := logStartTrain(db, assetToArgs(inputKey{Key: key}))
621621
assert.NoError(t, err)
622622

623623
success := inputLogSuccessTrain{}
@@ -627,7 +627,7 @@ func traintupleToDone(t *testing.T, db *LedgerDB, key string) {
627627
assert.NoError(t, err)
628628
}
629629
func testtupleToDone(t *testing.T, db *LedgerDB, key string) {
630-
_, err := logStartTest(db, assetToArgs(inputHash{Key: key}))
630+
_, err := logStartTest(db, assetToArgs(inputKey{Key: key}))
631631
assert.NoError(t, err)
632632

633633
success := inputLogSuccessTest{}

chaincode/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func updateDataManager(db *LedgerDB, args []string) (resp map[string]string, err
238238

239239
// queryDataManager returns dataManager and its key
240240
func queryDataManager(db *LedgerDB, args []string) (out outputDataManager, err error) {
241-
inp := inputHash{}
241+
inp := inputKey{}
242242
err = AssetFromJSON(args, &inp)
243243
if err != nil {
244244
return
@@ -282,7 +282,7 @@ func queryDataManagers(db *LedgerDB, args []string) ([]outputDataManager, error)
282282

283283
// queryDataset returns info about a dataManager and all related dataSample
284284
func queryDataset(db *LedgerDB, args []string) (outputDataset, error) {
285-
inp := inputHash{}
285+
inp := inputKey{}
286286
out := outputDataset{}
287287
err := AssetFromJSON(args, &inp)
288288
if err != nil {

chaincode/generate_examples_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestPipeline(t *testing.T) {
7070
dataManagerKey := res["key"]
7171

7272
fmt.Fprintln(&out, "#### ------------ Query DataManager From key ------------")
73-
callAssertAndPrint("invoke", "queryDataManager", inputHash{dataManagerKey})
73+
callAssertAndPrint("invoke", "queryDataManager", inputKey{dataManagerKey})
7474

7575
fmt.Fprintln(&out, "#### ------------ Add test DataSample ------------")
7676
inpDataSample := inputDataSample{
@@ -148,7 +148,7 @@ func TestPipeline(t *testing.T) {
148148
callAssertAndPrint("invoke", "queryFilter", filter)
149149

150150
fmt.Fprintln(&out, "#### ------------ Log Start Training ------------")
151-
callAssertAndPrint("invoke", "logStartTrain", inputHash{traintupleKey})
151+
callAssertAndPrint("invoke", "logStartTrain", inputKey{traintupleKey})
152152

153153
fmt.Fprintln(&out, "#### ------------ Log Success Training ------------")
154154
inp := inputLogSuccessTrain{}
@@ -157,7 +157,7 @@ func TestPipeline(t *testing.T) {
157157
callAssertAndPrint("invoke", "logSuccessTrain", inp)
158158

159159
fmt.Fprintln(&out, "#### ------------ Query Traintuple From key ------------")
160-
callAssertAndPrint("invoke", "queryTraintuple", inputHash{traintupleKey})
160+
callAssertAndPrint("invoke", "queryTraintuple", inputKey{traintupleKey})
161161

162162
fmt.Fprintln(&out, "#### ------------ Add Non-Certified Testtuple ------------")
163163
inpTesttuple := inputTesttuple{
@@ -204,7 +204,7 @@ func TestPipeline(t *testing.T) {
204204
callAssertAndPrint("invoke", "queryFilter", filter)
205205

206206
fmt.Fprintln(&out, "#### ------------ Log Start Testing ------------")
207-
callAssertAndPrint("invoke", "logStartTest", inputHash{testtupleKey})
207+
callAssertAndPrint("invoke", "logStartTest", inputKey{testtupleKey})
208208

209209
fmt.Fprintln(&out, "#### ------------ Log Success Testing ------------")
210210
success := inputLogSuccessTest{}
@@ -213,19 +213,22 @@ func TestPipeline(t *testing.T) {
213213
callAssertAndPrint("invoke", "logSuccessTest", success)
214214

215215
fmt.Fprintln(&out, "#### ------------ Query Testtuple from its key ------------")
216-
callAssertAndPrint("query", "queryTesttuple", inputHash{testtupleKey})
216+
callAssertAndPrint("query", "queryTesttuple", inputKey{testtupleKey})
217217

218218
fmt.Fprintln(&out, "#### ------------ Query all Testtuples ------------")
219219
callAssertAndPrint("query", "queryTesttuples", nil)
220220

221221
fmt.Fprintln(&out, "#### ------------ Query details about a model ------------")
222-
callAssertAndPrint("query", "queryModelDetails", inputHash{traintupleKey})
222+
callAssertAndPrint("query", "queryModelDetails", inputKey{traintupleKey})
223223

224224
fmt.Fprintln(&out, "#### ------------ Query all models ------------")
225225
callAssertAndPrint("query", "queryModels", nil)
226226

227+
fmt.Fprintln(&out, "#### ------------ Query model permissions ------------")
228+
callAssertAndPrint("query", "queryModelPermissions", inputKey{modelHash})
229+
227230
fmt.Fprintln(&out, "#### ------------ Query Dataset ------------")
228-
callAssertAndPrint("query", "queryDataset", inputHash{dataManagerOpenerHash})
231+
callAssertAndPrint("query", "queryDataset", inputKey{dataManagerOpenerHash})
229232

230233
fmt.Fprintln(&out, "#### ------------ Query nodes ------------")
231234
callAssertAndPrint("query", "queryNodes", nil)
@@ -245,7 +248,7 @@ func TestPipeline(t *testing.T) {
245248
callAssertAndPrint("invoke", "updateDataSample", updateData)
246249

247250
fmt.Fprintln(&out, "#### ------------ Query the new Dataset ------------")
248-
callAssertAndPrint("query", "queryDataset", inputHash{newDataManagerKey})
251+
callAssertAndPrint("query", "queryDataset", inputKey{newDataManagerKey})
249252

250253
fmt.Fprintln(&out, "#### ------------ Create a ComputePlan ------------")
251254
resp = callAssertAndPrint("invoke", "createComputePlan", defaultComputePlan)
@@ -259,10 +262,10 @@ func TestPipeline(t *testing.T) {
259262
}
260263
callAssertAndPrint("invoke", "queryObjectiveLeaderboard", inpLeaderboard)
261264

262-
callAssertAndPrint("invoke", "queryComputePlan", inputHash{outCp.ComputePlanID})
265+
callAssertAndPrint("invoke", "queryComputePlan", inputKey{outCp.ComputePlanID})
263266
callAssertAndPrint("invoke", "queryComputePlans", nil)
264267

265-
callAssertAndPrint("invoke", "cancelComputePlan", inputHash{outCp.ComputePlanID})
268+
callAssertAndPrint("invoke", "cancelComputePlan", inputKey{outCp.ComputePlanID})
266269

267270
// Use the output to check the EXAMPLES.md file and if asked update it
268271
doc := out.String()

chaincode/input.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type inputTesttuple struct {
108108
TraintupleKey string `validate:"required,len=64,hexadecimal" json:"traintupleKey"`
109109
}
110110

111-
type inputHash struct {
111+
type inputKey struct {
112112
Key string `validate:"required,len=64,hexadecimal" json:"key"`
113113
}
114114

@@ -131,6 +131,10 @@ type inputLog struct {
131131
Log string `validate:"lte=200" json:"log"`
132132
}
133133

134+
type inputHash struct {
135+
Hash string `validate:"required,len=64,hexadecimal" json:"hash"`
136+
}
137+
134138
type inputHashDress struct {
135139
Hash string `validate:"required,len=64,hexadecimal" json:"hash"`
136140
StorageAddress string `validate:"required" json:"storageAddress"`

0 commit comments

Comments
 (0)