Skip to content

Commit

Permalink
FAB-1128 further cleanup of protos
Browse files Browse the repository at this point in the history
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 <muralisr@us.ibm.com>
  • Loading branch information
Srinivasan Muralidharan committed Nov 15, 2016
1 parent 82e72f4 commit 3b6c70d
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 351 deletions.
3 changes: 2 additions & 1 deletion core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"

Expand Down Expand Up @@ -138,7 +139,7 @@ func endTxSimulation(txsim ledger.TxSimulator, payload []byte, commit bool) erro
if txSimulationResults, err = txsim.GetTxSimulationResults(); err != nil {
return err
}
tx, err := putils.CreateTx(pb.Header_CHAINCODE, util.ComputeCryptoHash([]byte("dummyProposal")), []byte("dummyCCEvents"), txSimulationResults, []*pb.Endorsement{&pb.Endorsement{}})
tx, err := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, util.ComputeCryptoHash([]byte("dummyProposal")), []byte("dummyCCEvents"), txSimulationResults, []*pb.Endorsement{&pb.Endorsement{}})
if err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"
)
Expand Down Expand Up @@ -237,7 +238,7 @@ func (e *Endorser) endorseProposal(ctx context.Context, proposal *pb.Proposal, s

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

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

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

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

devopsLogger.Infof("validateProposalMessage info: proposal type %d", hdr.Type)
devopsLogger.Infof("validateProposalMessage info: proposal type %d", hdr.ChainHeader.Type)

// - ensure that there is a nonce and a creator
if hdr.Nonce == nil || len(hdr.Nonce) == 0 {
if hdr.SignatureHeader.Nonce == nil || len(hdr.SignatureHeader.Nonce) == 0 {
return nil, nil, fmt.Errorf("Invalid nonce specified in the header")
}
if hdr.Creator == nil || len(hdr.Creator) == 0 {
if hdr.SignatureHeader.Creator == nil || len(hdr.SignatureHeader.Creator) == 0 {
return nil, nil, fmt.Errorf("Invalid creator specified in the header")
}

Expand Down
3 changes: 2 additions & 1 deletion core/ledger/kvledger/example/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/ledger"

"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"
)
Expand Down Expand Up @@ -113,7 +114,7 @@ func (app *App) QueryBalances(accounts []string) ([]int, error) {
}

func constructTransaction(simulationResults []byte) *pb.Transaction2 {
tx, _ := putils.CreateTx(pb.Header_CHAINCODE, nil, nil, simulationResults, []*pb.Endorsement{})
tx, _ := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, nil, nil, simulationResults, []*pb.Endorsement{})
return tx
}

Expand Down
5 changes: 3 additions & 2 deletions core/ledger/testutil/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/golang/protobuf/proto"

"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"
)
Expand Down Expand Up @@ -48,15 +49,15 @@ func ConstructTestBlocks(t *testing.T, numBlocks int) []*pb.Block2 {
func ConstructTestBlock(t *testing.T, numTx int, txSize int, startingTxID int) *pb.Block2 {
txs := []*pb.Transaction2{}
for i := startingTxID; i < numTx+startingTxID; i++ {
tx, _ := putils.CreateTx(pb.Header_CHAINCODE, []byte{}, []byte{}, ConstructRandomBytes(t, txSize), []*pb.Endorsement{})
tx, _ := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, []byte{}, []byte{}, ConstructRandomBytes(t, txSize), []*pb.Endorsement{})
txs = append(txs, tx)
}
return newBlock(txs)
}

// ConstructTestTransaction constructs a transaction for testing
func ConstructTestTransaction(t *testing.T, simulationResults []byte) *pb.Transaction2 {
tx, _ := putils.CreateTx(pb.Header_CHAINCODE, []byte{}, []byte{}, simulationResults, []*pb.Endorsement{})
tx, _ := putils.CreateTx(common.HeaderType_ENDORSER_TRANSACTION, []byte{}, []byte{}, simulationResults, []*pb.Endorsement{})
return tx
}

Expand Down
19 changes: 9 additions & 10 deletions core/system_chaincode/escc/endorser_onevalidsignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ func (e *EndorserOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) ([]
var hdr []byte
if args[1] == nil {
return nil, errors.New("serialized Header object is null")
} else {
hdr = args[1]
}

hdr = args[1]

// handle the proposal payload
var payl []byte
if args[2] == nil {
return nil, errors.New("serialized ChaincodeProposalPayload object is null")
} else {
payl = args[2]
}

payl = args[2]

// handle simulation results
var results []byte
if args[3] == nil {
return nil, errors.New("simulation results are null")
} else {
results = args[3]
}

results = args[3]

// Handle serialized events if they have been provided
// they might be nil in case there's no events but there
// is a visibility field specified as the next arg
Expand All @@ -107,9 +107,8 @@ func (e *EndorserOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) ([]
if len(args) > 5 {
if args[5] == nil {
return nil, errors.New("serialized events are null")
} else {
visibility = args[5]
}
visibility = args[5]
}

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

// TODO: obtain current epoch
// TODO: obtain current epoch and set it on header
epoch := []byte("current_epoch")
logger.Infof("using epoch %s", string(epoch))

// get the bytes of the proposal response payload - we need to sign them
prpBytes, err := utils.GetBytesProposalResponsePayload(pHashBytes, epoch, results, events)
prpBytes, err := utils.GetBytesProposalResponsePayload(pHashBytes, results, events)
if err != nil {
return nil, errors.New("Failure while unmarshalling the ProposalResponsePayload")
}
Expand Down
5 changes: 2 additions & 3 deletions orderer/common/bootstrap/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ func makeChainHeader(headerType cb.HeaderType, version int32, chainID []byte) *c
}
}

func makeSignatureHeader(serializedCreatorCertChain []byte, nonce []byte, epoch uint64) *cb.SignatureHeader {
func makeSignatureHeader(serializedCreatorCertChain []byte, nonce []byte) *cb.SignatureHeader {
return &cb.SignatureHeader{
Creator: serializedCreatorCertChain,
Nonce: nonce,
Epoch: epoch,
}
}

Expand Down Expand Up @@ -103,7 +102,7 @@ func (b *bootstrapper) makeEnvelope(configurationEnvelope *cb.ConfigurationEnvel
marshaledPayload := errorlessMarshal(&cb.Payload{
Header: &cb.Header{
ChainHeader: makeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, 1, b.chainID),
SignatureHeader: makeSignatureHeader(nil, nonce, 0),
SignatureHeader: makeSignatureHeader(nil, nonce),
},
Data: errorlessMarshal(configurationEnvelope),
})
Expand Down
99 changes: 54 additions & 45 deletions protos/common/common.pb.go

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

15 changes: 12 additions & 3 deletions protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ message ChainHeader {

// Identifier of the chain this message is bound for
bytes chainID = 4;

// The epoch in which this header was generated, where epoch is defined based on block height
// Epoch in which the response has been generated. This field identifies a
// logical window of time. A proposal response is accepted by a peer only if
// two conditions hold:
// 1. the epoch specified in the message is the current epoch
// 2. this message has been only seen once during this epoch (i.e. it hasn't
// been replayed)
uint64 epoch = 5;

// Extension that may be attached based on the header type
bytes extension = 6;
}

message SignatureHeader {
Expand All @@ -66,9 +78,6 @@ message SignatureHeader {

// Arbitrary number that may only be used once. Can be used to detect replay attacks.
bytes nonce = 2;

// The epoch in which this header was generated, where epoch is defined based on block height
uint64 epoch = 3;
}

// Payload is the message contents (and header to allow for signing)
Expand Down
2 changes: 0 additions & 2 deletions protos/peer/api.pb.go

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

Loading

0 comments on commit 3b6c70d

Please sign in to comment.