Skip to content

Commit 3b6c70d

Browse files
author
Srinivasan Muralidharan
committed
FAB-1128 further cleanup of protos
https://jira.hyperledger.org/browse/FAB-1128 Further cleanup . replace Header in peer with Header from common . remove epoch from ProposalResponse epoch in header. Not needed in payload . move epoch from SignatureHeader to ChainHeader epoch . add extension field to ChainHeader We need ChaincodeHeaderExtension to be added if type is ENDORSER_TRANSACTION. Change-Id: If5c77e588ea090d83f7e6d6167f563f6758a0b07 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent 82e72f4 commit 3b6c70d

18 files changed

+174
-351
lines changed

core/chaincode/exectransaction_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/hyperledger/fabric/core/ledger/kvledger"
3636
"github.com/hyperledger/fabric/core/peer"
3737
"github.com/hyperledger/fabric/core/util"
38+
"github.com/hyperledger/fabric/protos/common"
3839
pb "github.com/hyperledger/fabric/protos/peer"
3940
putils "github.com/hyperledger/fabric/protos/utils"
4041

@@ -138,7 +139,7 @@ func endTxSimulation(txsim ledger.TxSimulator, payload []byte, commit bool) erro
138139
if txSimulationResults, err = txsim.GetTxSimulationResults(); err != nil {
139140
return err
140141
}
141-
tx, err := putils.CreateTx(pb.Header_CHAINCODE, util.ComputeCryptoHash([]byte("dummyProposal")), []byte("dummyCCEvents"), txSimulationResults, []*pb.Endorsement{&pb.Endorsement{}})
142+
tx, err := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, util.ComputeCryptoHash([]byte("dummyProposal")), []byte("dummyCCEvents"), txSimulationResults, []*pb.Endorsement{&pb.Endorsement{}})
142143
if err != nil {
143144
return err
144145
}

core/endorser/endorser.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/hyperledger/fabric/core/ledger"
2828
"github.com/hyperledger/fabric/core/ledger/kvledger"
2929
"github.com/hyperledger/fabric/core/peer"
30+
"github.com/hyperledger/fabric/protos/common"
3031
pb "github.com/hyperledger/fabric/protos/peer"
3132
putils "github.com/hyperledger/fabric/protos/utils"
3233
)
@@ -237,7 +238,7 @@ func (e *Endorser) endorseProposal(ctx context.Context, proposal *pb.Proposal, s
237238

238239
// FIXME: this method might be of general interest, should we package it somewhere else?
239240
// validateChaincodeProposalMessage checks the validity of a CHAINCODE Proposal message
240-
func (e *Endorser) validateChaincodeProposalMessage(prop *pb.Proposal, hdr *pb.Header) (*pb.ChaincodeHeaderExtension, error) {
241+
func (e *Endorser) validateChaincodeProposalMessage(prop *pb.Proposal, hdr *common.Header) (*pb.ChaincodeHeaderExtension, error) {
241242
devopsLogger.Infof("validateChaincodeProposalMessage starts for proposal %p, header %p", prop, hdr)
242243

243244
// 4) based on the header type (assuming it's CHAINCODE), look at the extensions
@@ -263,7 +264,7 @@ func (e *Endorser) validateChaincodeProposalMessage(prop *pb.Proposal, hdr *pb.H
263264
// validateProposalMessage checks the validity of a generic Proposal message
264265
// this function returns Header and ChaincodeHeaderExtension messages since they
265266
// have been unmarshalled and validated
266-
func (e *Endorser) validateProposalMessage(prop *pb.Proposal) (*pb.Header, *pb.ChaincodeHeaderExtension, error) {
267+
func (e *Endorser) validateProposalMessage(prop *pb.Proposal) (*common.Header, *pb.ChaincodeHeaderExtension, error) {
267268
devopsLogger.Infof("validateProposalMessage starts for proposal %p", prop)
268269

269270
// 1) look at the ProposalHeader
@@ -273,17 +274,17 @@ func (e *Endorser) validateProposalMessage(prop *pb.Proposal) (*pb.Header, *pb.C
273274
}
274275

275276
// - validate the type
276-
if hdr.Type != pb.Header_CHAINCODE {
277-
return nil, nil, fmt.Errorf("Invalid proposal type %d", hdr.Type)
277+
if hdr.ChainHeader.Type != int32(common.HeaderType_ENDORSER_TRANSACTION) {
278+
return nil, nil, fmt.Errorf("Invalid proposal type %d", hdr.ChainHeader.Type)
278279
}
279280

280-
devopsLogger.Infof("validateProposalMessage info: proposal type %d", hdr.Type)
281+
devopsLogger.Infof("validateProposalMessage info: proposal type %d", hdr.ChainHeader.Type)
281282

282283
// - ensure that there is a nonce and a creator
283-
if hdr.Nonce == nil || len(hdr.Nonce) == 0 {
284+
if hdr.SignatureHeader.Nonce == nil || len(hdr.SignatureHeader.Nonce) == 0 {
284285
return nil, nil, fmt.Errorf("Invalid nonce specified in the header")
285286
}
286-
if hdr.Creator == nil || len(hdr.Creator) == 0 {
287+
if hdr.SignatureHeader.Creator == nil || len(hdr.SignatureHeader.Creator) == 0 {
287288
return nil, nil, fmt.Errorf("Invalid creator specified in the header")
288289
}
289290

core/ledger/kvledger/example/app.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/golang/protobuf/proto"
2323
"github.com/hyperledger/fabric/core/ledger"
2424

25+
"github.com/hyperledger/fabric/protos/common"
2526
pb "github.com/hyperledger/fabric/protos/peer"
2627
putils "github.com/hyperledger/fabric/protos/utils"
2728
)
@@ -113,7 +114,7 @@ func (app *App) QueryBalances(accounts []string) ([]int, error) {
113114
}
114115

115116
func constructTransaction(simulationResults []byte) *pb.Transaction2 {
116-
tx, _ := putils.CreateTx(pb.Header_CHAINCODE, nil, nil, simulationResults, []*pb.Endorsement{})
117+
tx, _ := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, nil, nil, simulationResults, []*pb.Endorsement{})
117118
return tx
118119
}
119120

core/ledger/testutil/test_helper.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/golang/protobuf/proto"
2323

24+
"github.com/hyperledger/fabric/protos/common"
2425
pb "github.com/hyperledger/fabric/protos/peer"
2526
putils "github.com/hyperledger/fabric/protos/utils"
2627
)
@@ -48,15 +49,15 @@ func ConstructTestBlocks(t *testing.T, numBlocks int) []*pb.Block2 {
4849
func ConstructTestBlock(t *testing.T, numTx int, txSize int, startingTxID int) *pb.Block2 {
4950
txs := []*pb.Transaction2{}
5051
for i := startingTxID; i < numTx+startingTxID; i++ {
51-
tx, _ := putils.CreateTx(pb.Header_CHAINCODE, []byte{}, []byte{}, ConstructRandomBytes(t, txSize), []*pb.Endorsement{})
52+
tx, _ := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, []byte{}, []byte{}, ConstructRandomBytes(t, txSize), []*pb.Endorsement{})
5253
txs = append(txs, tx)
5354
}
5455
return newBlock(txs)
5556
}
5657

5758
// ConstructTestTransaction constructs a transaction for testing
5859
func ConstructTestTransaction(t *testing.T, simulationResults []byte) *pb.Transaction2 {
59-
tx, _ := putils.CreateTx(pb.Header_CHAINCODE, []byte{}, []byte{}, simulationResults, []*pb.Endorsement{})
60+
tx, _ := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, []byte{}, []byte{}, simulationResults, []*pb.Endorsement{})
6061
return tx
6162
}
6263

core/system_chaincode/escc/endorser_onevalidsignature.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,26 @@ func (e *EndorserOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) ([]
7474
var hdr []byte
7575
if args[1] == nil {
7676
return nil, errors.New("serialized Header object is null")
77-
} else {
78-
hdr = args[1]
7977
}
8078

79+
hdr = args[1]
80+
8181
// handle the proposal payload
8282
var payl []byte
8383
if args[2] == nil {
8484
return nil, errors.New("serialized ChaincodeProposalPayload object is null")
85-
} else {
86-
payl = args[2]
8785
}
8886

87+
payl = args[2]
88+
8989
// handle simulation results
9090
var results []byte
9191
if args[3] == nil {
9292
return nil, errors.New("simulation results are null")
93-
} else {
94-
results = args[3]
9593
}
9694

95+
results = args[3]
96+
9797
// Handle serialized events if they have been provided
9898
// they might be nil in case there's no events but there
9999
// is a visibility field specified as the next arg
@@ -107,9 +107,8 @@ func (e *EndorserOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) ([]
107107
if len(args) > 5 {
108108
if args[5] == nil {
109109
return nil, errors.New("serialized events are null")
110-
} else {
111-
visibility = args[5]
112110
}
111+
visibility = args[5]
113112
}
114113

115114
// obtain the proposal hash given proposal header, payload and the requested visibility
@@ -118,12 +117,12 @@ func (e *EndorserOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) ([]
118117
return nil, fmt.Errorf("Could not compute proposal hash: err %s", err)
119118
}
120119

121-
// TODO: obtain current epoch
120+
// TODO: obtain current epoch and set it on header
122121
epoch := []byte("current_epoch")
123122
logger.Infof("using epoch %s", string(epoch))
124123

125124
// get the bytes of the proposal response payload - we need to sign them
126-
prpBytes, err := utils.GetBytesProposalResponsePayload(pHashBytes, epoch, results, events)
125+
prpBytes, err := utils.GetBytesProposalResponsePayload(pHashBytes, results, events)
127126
if err != nil {
128127
return nil, errors.New("Failure while unmarshalling the ProposalResponsePayload")
129128
}

orderer/common/bootstrap/static/static.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ func makeChainHeader(headerType cb.HeaderType, version int32, chainID []byte) *c
6565
}
6666
}
6767

68-
func makeSignatureHeader(serializedCreatorCertChain []byte, nonce []byte, epoch uint64) *cb.SignatureHeader {
68+
func makeSignatureHeader(serializedCreatorCertChain []byte, nonce []byte) *cb.SignatureHeader {
6969
return &cb.SignatureHeader{
7070
Creator: serializedCreatorCertChain,
7171
Nonce: nonce,
72-
Epoch: epoch,
7372
}
7473
}
7574

@@ -103,7 +102,7 @@ func (b *bootstrapper) makeEnvelope(configurationEnvelope *cb.ConfigurationEnvel
103102
marshaledPayload := errorlessMarshal(&cb.Payload{
104103
Header: &cb.Header{
105104
ChainHeader: makeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, 1, b.chainID),
106-
SignatureHeader: makeSignatureHeader(nil, nonce, 0),
105+
SignatureHeader: makeSignatureHeader(nil, nonce),
107106
},
108107
Data: errorlessMarshal(configurationEnvelope),
109108
})

protos/common/common.pb.go

+54-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/common/common.proto

+12-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ message ChainHeader {
5858

5959
// Identifier of the chain this message is bound for
6060
bytes chainID = 4;
61+
62+
// The epoch in which this header was generated, where epoch is defined based on block height
63+
// Epoch in which the response has been generated. This field identifies a
64+
// logical window of time. A proposal response is accepted by a peer only if
65+
// two conditions hold:
66+
// 1. the epoch specified in the message is the current epoch
67+
// 2. this message has been only seen once during this epoch (i.e. it hasn't
68+
// been replayed)
69+
uint64 epoch = 5;
70+
71+
// Extension that may be attached based on the header type
72+
bytes extension = 6;
6173
}
6274

6375
message SignatureHeader {
@@ -66,9 +78,6 @@ message SignatureHeader {
6678

6779
// Arbitrary number that may only be used once. Can be used to detect replay attacks.
6880
bytes nonce = 2;
69-
70-
// The epoch in which this header was generated, where epoch is defined based on block height
71-
uint64 epoch = 3;
7281
}
7382

7483
// Payload is the message contents (and header to allow for signing)

protos/peer/api.pb.go

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)