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

Commit bd634f3

Browse files
Add CP ID to tuples hashes (#116)
1 parent 3e2972b commit bd634f3

File tree

8 files changed

+123
-113
lines changed

8 files changed

+123
-113
lines changed

EXAMPLES.md

Lines changed: 102 additions & 102 deletions
Large diffs are not rendered by default.

chaincode/compute_plan.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ func UpdateComputePlanState(db *LedgerDB, ComputePlanID, tupleStatus, tupleKey s
414414
return err
415415
}
416416
if statusUpdated || len(doneModels) != 0 {
417-
db.AddComputePlanEvent(ComputePlanID, cp.State.Status, doneModels)
417+
err = db.AddComputePlanEvent(ComputePlanID, cp.State.Status, doneModels)
418+
if err != nil {
419+
return err
420+
}
418421
return cp.SaveState(db)
419422
}
420423
return nil

chaincode/compute_plan_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,10 @@ func TestLogSuccessAfterCancel(t *testing.T) {
577577
computePlan, err := getOutComputePlan(db, out.ComputePlanID)
578578
assert.Equal(t, StatusCanceled, computePlan.Status)
579579

580-
tuples, err := queryCompositeTraintuples(db, []string{})
581-
assert.NoError(t, err)
582-
expected := []string{StatusDone, StatusDoing, StatusAborted, StatusAborted}
583-
for i, tuple := range tuples {
580+
expected := []string{StatusDoing, StatusDone, StatusAborted, StatusAborted}
581+
for i, tuplekey := range out.CompositeTraintupleKeys {
582+
tuple, err := queryCompositeTraintuple(db, keyToArgs(tuplekey))
583+
assert.NoError(t, err)
584584
assert.Equal(t, expected[i], tuple.Status)
585585
}
586586
}
@@ -624,6 +624,7 @@ func traintupleToDone(t *testing.T, db *LedgerDB, key string) {
624624

625625
success := inputLogSuccessTrain{}
626626
success.Key = key
627+
success.OutModel.Hash = GetRandomHash()
627628
success.fillDefaults()
628629
_, err = logSuccessTrain(db, assetToArgs(success))
629630
assert.NoError(t, err)

chaincode/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ const headModelHash = modelHash
5252
const trunkModelHash = "ccdbb7c31f62244c0f3a761cc168804227115793d01c270021fe3f7935482ecc"
5353
const trunkModelAddress = "https://substrabac/model/titi"
5454
const worker = "SampleOrg"
55-
const traintupleKey = "9da043ddc233996d2e62c196471290de4726fc59d65dbbd2b32a920326e8adf3"
56-
const compositeTraintupleKey = "57104c72d50215d8cfa288059fdf47bcc5f808f6685a5f08fa08f792cd782c68"
57-
const aggregatetupleKey = "af689258ffecdb5172b285b04475ac44941b7e6acd88a0d076059ce520cb0a95"
55+
const traintupleKey = "ebbf6cdde286539ea9cc34214dce7acb71e72799a676e4845be1b0fea155b35c"
56+
const compositeTraintupleKey = "b6f20e7ed89073d995c50d4b2bff6bb365a05b8d77f10469117d8aad81d83989"
57+
const aggregatetupleKey = "48c17bb556e1a122138d89178d81b22469a0cae260af322de9b391086ad27b2c"
5858
const tag = "a tag is simply a string"
5959

6060
func TestInit(t *testing.T) {

chaincode/testtuple.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (testtuple *Testtuple) GetKey() string {
176176
testtuple.ObjectiveKey,
177177
testtuple.Dataset.OpenerHash,
178178
testtuple.Creator,
179+
testtuple.ComputePlanID,
179180
}
180181
hashKeys = append(hashKeys, testtuple.Dataset.DataSampleKeys...)
181182
return HashForKey("testtuple", hashKeys...)

chaincode/traintuple.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ func (traintuple *Traintuple) SetFromParents(db *LedgerDB, inModels []string) er
104104

105105
// GetKey return the key of the traintuple depending on its key parameters.
106106
func (traintuple *Traintuple) GetKey() string {
107-
hashKeys := []string{traintuple.Creator, traintuple.AlgoKey, traintuple.Dataset.DataManagerKey}
107+
hashKeys := []string{
108+
traintuple.Creator,
109+
traintuple.AlgoKey,
110+
traintuple.Dataset.DataManagerKey,
111+
traintuple.ComputePlanID}
108112
hashKeys = append(hashKeys, traintuple.Dataset.DataSampleKeys...)
109113
hashKeys = append(hashKeys, traintuple.InModelKeys...)
110114
return HashForKey("traintuple", hashKeys...)

chaincode/traintuple_composite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ func (traintuple *CompositeTraintuple) GetKey() string {
150150
traintuple.AlgoKey,
151151
traintuple.Dataset.DataManagerKey,
152152
traintuple.InHeadModel,
153-
traintuple.InTrunkModel}
153+
traintuple.InTrunkModel,
154+
traintuple.ComputePlanID}
154155
hashKeys = append(hashKeys, traintuple.Dataset.DataSampleKeys...)
155156
return HashForKey("compositeTraintuple", hashKeys...)
156157
}

chaincode/tuple_aggregate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (tuple *Aggregatetuple) SetFromParents(db *LedgerDB, inModels []string) err
114114

115115
// GetKey return the key of the aggregate tuple depending on its key parameters.
116116
func (tuple *Aggregatetuple) GetKey() string {
117-
hashKeys := []string{tuple.Creator, tuple.AlgoKey}
117+
hashKeys := []string{tuple.Creator, tuple.AlgoKey, tuple.ComputePlanID}
118118
hashKeys = append(hashKeys, tuple.InModelKeys...)
119119
return HashForKey("aggregate-traintuple", hashKeys...)
120120
}

0 commit comments

Comments
 (0)