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

Commit a4a6020

Browse files
Return only new ID to Key (#102)
* Return only new ID to Key * Rename after review
1 parent 7ea953a commit a4a6020

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

EXAMPLES.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,6 @@ peer chaincode invoke -n mycc -c '{"Args":["updateComputePlan","{\"computePlanID
14991499
```json
15001500
{
15011501
"IDToKey": {
1502-
"firstTraintupleID": "432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
1503-
"secondTraintupleID": "d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299",
15041502
"thirdTraintupleID": "c163663889566a4c51fad3765107774891f8ed456dcc859a9a1a7fcd17b11386"
15051503
},
15061504
"aggregatetupleKeys": null,
@@ -1598,11 +1596,7 @@ peer chaincode invoke -n mycc -c '{"Args":["queryComputePlan","{\"key\":\"7dd808
15981596
##### Command output:
15991597
```json
16001598
{
1601-
"IDToKey": {
1602-
"firstTraintupleID": "432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
1603-
"secondTraintupleID": "d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299",
1604-
"thirdTraintupleID": "c163663889566a4c51fad3765107774891f8ed456dcc859a9a1a7fcd17b11386"
1605-
},
1599+
"IDToKey": {},
16061600
"aggregatetupleKeys": null,
16071601
"compositeTraintupleKeys": null,
16081602
"computePlanID": "7dd808239c1e062399449bd11b634d9bd1fd0a2b795ad345b62f95b4933bfa17",
@@ -1629,11 +1623,7 @@ peer chaincode invoke -n mycc -c '{"Args":["queryComputePlans"]}' -C myc
16291623
```json
16301624
[
16311625
{
1632-
"IDToKey": {
1633-
"firstTraintupleID": "432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
1634-
"secondTraintupleID": "d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299",
1635-
"thirdTraintupleID": "c163663889566a4c51fad3765107774891f8ed456dcc859a9a1a7fcd17b11386"
1636-
},
1626+
"IDToKey": {},
16371627
"aggregatetupleKeys": null,
16381628
"compositeTraintupleKeys": null,
16391629
"computePlanID": "7dd808239c1e062399449bd11b634d9bd1fd0a2b795ad345b62f95b4933bfa17",
@@ -1669,11 +1659,7 @@ peer chaincode invoke -n mycc -c '{"Args":["cancelComputePlan","{\"key\":\"7dd80
16691659
##### Command output:
16701660
```json
16711661
{
1672-
"IDToKey": {
1673-
"firstTraintupleID": "432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
1674-
"secondTraintupleID": "d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299",
1675-
"thirdTraintupleID": "c163663889566a4c51fad3765107774891f8ed456dcc859a9a1a7fcd17b11386"
1676-
},
1662+
"IDToKey": {},
16771663
"aggregatetupleKeys": null,
16781664
"compositeTraintupleKeys": null,
16791665
"computePlanID": "7dd808239c1e062399449bd11b634d9bd1fd0a2b795ad345b62f95b4933bfa17",

chaincode/compute_plan.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func createComputePlanInternal(db *LedgerDB, inp inputComputePlan, tag string) (
138138
len(inp.CompositeTraintuples) +
139139
len(inp.Testtuples)
140140
if count == 0 {
141-
resp.Fill(ID, computePlan)
141+
resp.Fill(ID, computePlan, []string{})
142142
return resp, nil
143143
}
144144
return updateComputePlanInternal(db, ID, inp)
@@ -154,6 +154,7 @@ func updateComputePlanInternal(db *LedgerDB, computePlanID string, inp inputComp
154154
for ID, trainTask := range computePlan.IDToTrainTask {
155155
IDToTrainTask[ID] = trainTask
156156
}
157+
NewIDs := []string{}
157158
DAG, err := createComputeDAG(inp, computePlan.IDToTrainTask)
158159
if err != nil {
159160
return resp, errors.BadRequest(err)
@@ -211,6 +212,7 @@ func updateComputePlanInternal(db *LedgerDB, computePlanID string, inp inputComp
211212
}
212213
}
213214
IDToTrainTask[task.ID] = TrainTask{Depth: task.Depth, Key: tupleKey}
215+
NewIDs = append(NewIDs, task.ID)
214216
}
215217

216218
for index, computeTesttuple := range inp.Testtuples {
@@ -236,7 +238,7 @@ func updateComputePlanInternal(db *LedgerDB, computePlanID string, inp inputComp
236238
if err != nil {
237239
return resp, err
238240
}
239-
resp.Fill(computePlanID, computePlan)
241+
resp.Fill(computePlanID, computePlan, NewIDs)
240242
return resp, err
241243
}
242244

@@ -275,7 +277,7 @@ func getOutComputePlan(db *LedgerDB, key string) (resp outputComputePlan, err er
275277
return resp, err
276278
}
277279

278-
resp.Fill(key, computePlan)
280+
resp.Fill(key, computePlan, []string{})
279281
return resp, err
280282
}
281283

@@ -297,7 +299,7 @@ func cancelComputePlan(db *LedgerDB, args []string) (resp outputComputePlan, err
297299
}
298300

299301
db.AddComputePlanEvent(inp.Key, computeplan.State.Status)
300-
resp.Fill(inp.Key, computeplan)
302+
resp.Fill(inp.Key, computeplan, []string{})
301303
return resp, nil
302304
}
303305

chaincode/compute_plan_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func TestUpdateComputePlan(t *testing.T) {
681681
assert.Len(
682682
t,
683683
out.IDToKey,
684-
3,
685-
"IDToKey should match the 3 train like tuples keys to their respective ID")
684+
1,
685+
"IDToKey should match the newly created tuple keys to its ID")
686686
assert.Equal(t, 4, out.TupleCount)
687687
}

chaincode/output.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ type outputComputePlan struct {
311311
IDToKey map[string]string `json:"IDToKey"`
312312
}
313313

314-
func (out *outputComputePlan) Fill(key string, in ComputePlan) {
314+
func (out *outputComputePlan) Fill(key string, in ComputePlan, newIDs []string) {
315315
out.ComputePlanID = key
316316
nb := getLimitedNbSliceElements(in.TraintupleKeys)
317317
out.TraintupleKeys = in.TraintupleKeys[:nb]
@@ -325,8 +325,8 @@ func (out *outputComputePlan) Fill(key string, in ComputePlan) {
325325
out.TupleCount = in.State.TupleCount
326326
out.DoneCount = in.State.DoneCount
327327
IDToKey := map[string]string{}
328-
for ID, trainTask := range in.IDToTrainTask {
329-
IDToKey[ID] = trainTask.Key
328+
for _, ID := range newIDs {
329+
IDToKey[ID] = in.IDToTrainTask[ID].Key
330330
}
331331
out.IDToKey = IDToKey
332332
}

0 commit comments

Comments
 (0)