Skip to content

Commit

Permalink
Merge "[FAB-9544] added notification about chaincode upgrade"
Browse files Browse the repository at this point in the history
  • Loading branch information
yacovm authored and Gerrit Code Review committed Apr 25, 2018
2 parents 0cac65b + f26382a commit 01afac3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 44 deletions.
6 changes: 5 additions & 1 deletion core/chaincode/shim/mockstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type MockStub struct {
ChannelID string

PvtState map[string]map[string][]byte

// channel to store ChaincodeEvents
ChaincodeEventsChannel chan *pb.ChaincodeEvent
}

func (stub *MockStub) GetTxID() string {
Expand Down Expand Up @@ -362,8 +365,8 @@ func (stub *MockStub) GetTxTimestamp() (*timestamp.Timestamp, error) {
return stub.TxTimestamp, nil
}

// Not implemented
func (stub *MockStub) SetEvent(name string, payload []byte) error {
stub.ChaincodeEventsChannel <- &pb.ChaincodeEvent{EventName: name, Payload: payload}
return nil
}

Expand All @@ -377,6 +380,7 @@ func NewMockStub(name string, cc Chaincode) *MockStub {
s.PvtState = make(map[string]map[string][]byte)
s.Invokables = make(map[string]*MockStub)
s.Keys = list.New()
s.ChaincodeEventsChannel = make(chan *pb.ChaincodeEvent, 100) //define large capacity for non-blocking setEvent calls.

return s
}
Expand Down
5 changes: 4 additions & 1 deletion core/scc/lscc/lscc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
var logger = flogging.MustGetLogger("lscc")

const (

//chaincode lifecycle commands

//INSTALL install command
Expand Down Expand Up @@ -592,7 +593,9 @@ func (lscc *lifeCycleSysCC) executeUpgrade(stub shim.ChaincodeStubInterface, cha
if err != nil {
return nil, err
}

lifecycleEvent := &pb.LifecycleEvent{ChaincodeName: chaincodeName}
lifecycleEventBytes := utils.MarshalOrPanic(lifecycleEvent)
stub.SetEvent(UPGRADE, lifecycleEventBytes)
return cdfs, nil
}

Expand Down
7 changes: 7 additions & 0 deletions core/scc/lscc/lscc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ func testUpgrade(t *testing.T, ccname string, version string, newccname string,

expectVer := "1"
assert.Equal(t, newVer, expectVer, fmt.Sprintf("Upgrade chaincode version error, expected %s, got %s", expectVer, newVer))

chaincodeEvent := <-stub.ChaincodeEventsChannel
assert.Equal(t, UPGRADE, chaincodeEvent.EventName)
lifecycleEvent := &pb.LifecycleEvent{}
err = proto.Unmarshal(chaincodeEvent.Payload, lifecycleEvent)
assert.NoError(t, err)
assert.Equal(t, newccname, lifecycleEvent.ChaincodeName)
} else {
assert.Equal(t, expectedErrorMsg, string(res.Message))
}
Expand Down
1 change: 1 addition & 0 deletions protos/peer/admin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 62 additions & 42 deletions protos/peer/chaincode.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions protos/peer/chaincode.proto
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ message ChaincodeInvocationSpec {
// Currently, SHA256 with BASE64 is supported (e.g. idGenerationAlg='sha256base64')
string id_generation_alg = 2;
}

// LifecycleEvent is used as the payload of the chaincode event emitted by LSCC
message LifecycleEvent {
string chaincode_name = 1;
}

0 comments on commit 01afac3

Please sign in to comment.