Commit cc11fcbe authored by Jason Yellick's avatar Jason Yellick
Browse files

[FAB-2033] Proto switch ChainHeader->ChannelHeader

https://jira.hyperledger.org/browse/FAB-2033



The user facing documentation refers to channels, but the vast majority
of the fabric code refers to chains.  This CR switches the protos to
refer to channels as they are generally the interface between the user
and fabric code.

Change-Id: I869e6d68c1228e638a99e2460274889f18f2543d
Signed-off-by: default avatarJason Yellick <jyellick@us.ibm.com>
parent 0045a79d
......@@ -77,7 +77,7 @@ func makeConfigItem(id, modificationPolicy string, lastModified uint64, data []b
func makeMarshaledConfig(chainID string, configItems ...*cb.ConfigItem) []byte {
config := &cb.Config{
Header: &cb.ChainHeader{ChannelId: chainID},
Header: &cb.ChannelHeader{ChannelId: chainID},
Items: configItems,
}
return utils.MarshalOrPanic(config)
......
......@@ -97,7 +97,7 @@ func (st *simpleTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error) {
}
marshaledConfig, err := proto.Marshal(&cb.ConfigNext{
Header: &cb.ChainHeader{
Header: &cb.ChannelHeader{
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
},
......@@ -172,7 +172,7 @@ func (ct *compositeTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error
}
marshaledConfig, err := proto.Marshal(&cb.ConfigNext{
Header: &cb.ChainHeader{
Header: &cb.ChannelHeader{
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
},
......@@ -239,9 +239,9 @@ func MakeChainCreationTransaction(creationPolicy string, chainID string, signer
return nil, err
}
payloadChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, msgVersion, chainID, epoch)
payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, msgVersion, chainID, epoch)
payloadSignatureHeader := utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())
payloadHeader := utils.MakePayloadHeader(payloadChainHeader, payloadSignatureHeader)
payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader)
payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(newConfigEnv)}
paylBytes := utils.MarshalOrPanic(payload)
......
......@@ -48,9 +48,9 @@ func (f *factory) Block(chainID string) (*cb.Block, error) {
return nil, err
}
payloadChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, msgVersion, chainID, epoch)
payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, msgVersion, chainID, epoch)
payloadSignatureHeader := utils.MakeSignatureHeader(nil, utils.CreateNonceOrPanic())
payloadHeader := utils.MakePayloadHeader(payloadChainHeader, payloadSignatureHeader)
payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader)
payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(configEnv)}
envelope := &cb.Envelope{Payload: utils.MarshalOrPanic(payload), Signature: nil}
......
......@@ -207,5 +207,5 @@ func extractTxID(txEnvelopBytes []byte) (string, error) {
if err != nil {
return "", nil
}
return txPayload.Header.ChainHeader.TxId, nil
return txPayload.Header.ChannelHeader.TxId, nil
}
......@@ -75,7 +75,7 @@ func TestNewTxValidator_DuplicateTransactions(t *testing.T) {
// Create simeple endorsement transaction
payload := &common.Payload{
Header: &common.Header{
ChainHeader: &common.ChainHeader{
ChannelHeader: &common.ChannelHeader{
TxId: "simple_txID", // Fake txID
Type: int32(common.HeaderType_ENDORSER_TRANSACTION),
ChannelId: util2.GetTestChainID(),
......
......@@ -118,7 +118,7 @@ func (v *txValidator) Validate(block *common.Block) error {
continue
}
chain := payload.Header.ChainHeader.ChannelId
chain := payload.Header.ChannelHeader.ChannelId
logger.Debug("Transaction is for chain %s", chain)
if !v.chainExists(chain) {
......@@ -126,9 +126,9 @@ func (v *txValidator) Validate(block *common.Block) error {
continue
}
if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
// Check duplicate transactions
txID := payload.Header.ChainHeader.TxId
txID := payload.Header.ChannelHeader.TxId
if _, err := v.support.Ledger().GetTransactionByID(txID); err == nil {
logger.Warning("Duplicate transaction found, ", txID, ", skipping")
continue
......@@ -141,7 +141,7 @@ func (v *txValidator) Validate(block *common.Block) error {
logger.Errorf("VSCCValidateTx for transaction txId = %s returned error %s", txID, err)
continue
}
} else if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_CONFIGURATION_TRANSACTION {
} else if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_CONFIGURATION_TRANSACTION {
configEnvelope, err := configtx.UnmarshalConfigEnvelope(payload.Data)
if err != nil {
err := fmt.Errorf("Error unmarshaling config which passed initial validity checks: %s", err)
......@@ -179,7 +179,7 @@ func (v *txValidator) Validate(block *common.Block) error {
func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []byte) error {
// Chain ID
chainID := payload.Header.ChainHeader.ChannelId
chainID := payload.Header.ChannelHeader.ChannelId
if chainID == "" {
err := fmt.Errorf("transaction header does not contain an chain ID")
logger.Errorf("%s", err)
......@@ -187,8 +187,8 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
}
// Get transaction id
txid := payload.Header.ChainHeader.TxId
logger.Info("[XXX remove me XXX] Transaction type,", common.HeaderType(payload.Header.ChainHeader.Type))
txid := payload.Header.ChannelHeader.TxId
logger.Info("[XXX remove me XXX] Transaction type,", common.HeaderType(payload.Header.ChannelHeader.Type))
if txid == "" {
err := fmt.Errorf("transaction header does not contain transaction ID")
logger.Errorf("%s", err)
......
......@@ -78,7 +78,7 @@ func ValidateProposalMessage(signedProp *pb.SignedProposal) (*pb.Proposal, *comm
}
// validate the signature
err = checkSignatureFromCreator(hdr.SignatureHeader.Creator, signedProp.Signature, signedProp.ProposalBytes, hdr.ChainHeader.ChannelId)
err = checkSignatureFromCreator(hdr.SignatureHeader.Creator, signedProp.Signature, signedProp.ProposalBytes, hdr.ChannelHeader.ChannelId)
if err != nil {
return nil, nil, nil, err
}
......@@ -88,7 +88,7 @@ func ValidateProposalMessage(signedProp *pb.SignedProposal) (*pb.Proposal, *comm
// TODO: perform a check against replay attacks
// continue the validation in a way that depends on the type specified in the header
switch common.HeaderType(hdr.ChainHeader.Type) {
switch common.HeaderType(hdr.ChannelHeader.Type) {
case common.HeaderType_CONFIGURATION_TRANSACTION:
//which the types are different the validation is the same
//viz, validate a proposal to a chaincode. If we need other
......@@ -105,7 +105,7 @@ func ValidateProposalMessage(signedProp *pb.SignedProposal) (*pb.Proposal, *comm
return prop, hdr, chaincodeHdrExt, err
default:
//NOTE : we proably need a case
return nil, nil, nil, fmt.Errorf("Unsupported proposal type %d", common.HeaderType(hdr.ChainHeader.Type))
return nil, nil, nil, fmt.Errorf("Unsupported proposal type %d", common.HeaderType(hdr.ChannelHeader.Type))
}
}
......@@ -172,11 +172,11 @@ func validateSignatureHeader(sHdr *common.SignatureHeader) error {
return nil
}
// checks for a valid ChainHeader
func validateChainHeader(cHdr *common.ChainHeader) error {
// checks for a valid ChannelHeader
func validateChannelHeader(cHdr *common.ChannelHeader) error {
// check for nil argument
if cHdr == nil {
return fmt.Errorf("Nil ChainHeader provided")
return fmt.Errorf("Nil ChannelHeader provided")
}
// validate the header type
......@@ -186,7 +186,7 @@ func validateChainHeader(cHdr *common.ChainHeader) error {
return fmt.Errorf("invalid header type %s", common.HeaderType(cHdr.Type))
}
putilsLogger.Infof("validateChainHeader info: header type %d", common.HeaderType(cHdr.Type))
putilsLogger.Infof("validateChannelHeader info: header type %d", common.HeaderType(cHdr.Type))
// TODO: validate chainID in cHdr.ChainID
......@@ -203,7 +203,7 @@ func validateCommonHeader(hdr *common.Header) error {
return fmt.Errorf("Nil header")
}
err := validateChainHeader(hdr.ChainHeader)
err := validateChannelHeader(hdr.ChannelHeader)
if err != nil {
return err
}
......@@ -296,8 +296,8 @@ func validateEndorserTransaction(data []byte, hdr *common.Header) error {
}
// build the original header by stitching together
// the common ChainHeader and the per-action SignatureHeader
hdrOrig := &common.Header{ChainHeader: hdr.ChainHeader, SignatureHeader: sHdr}
// the common ChannelHeader and the per-action SignatureHeader
hdrOrig := &common.Header{ChannelHeader: hdr.ChannelHeader, SignatureHeader: sHdr}
hdrBytes, err := utils.GetBytesHeader(hdrOrig) // FIXME: here we hope that hdrBytes will be the same one that the endorser had
if err != nil {
return err
......@@ -342,7 +342,7 @@ func ValidateTransaction(e *common.Envelope) (*common.Payload, error) {
}
// validate the signature in the envelope
err = checkSignatureFromCreator(payload.Header.SignatureHeader.Creator, e.Signature, e.Payload, payload.Header.ChainHeader.ChannelId)
err = checkSignatureFromCreator(payload.Header.SignatureHeader.Creator, e.Signature, e.Payload, payload.Header.ChannelHeader.ChannelId)
if err != nil {
return nil, err
}
......@@ -352,7 +352,7 @@ func ValidateTransaction(e *common.Envelope) (*common.Payload, error) {
// TODO: perform a check against replay attacks
// continue the validation in a way that depends on the type specified in the header
switch common.HeaderType(payload.Header.ChainHeader.Type) {
switch common.HeaderType(payload.Header.ChannelHeader.Type) {
case common.HeaderType_ENDORSER_TRANSACTION:
err = validateEndorserTransaction(payload.Data, payload.Header)
putilsLogger.Infof("ValidateTransactionEnvelope returns err %s", err)
......@@ -362,6 +362,6 @@ func ValidateTransaction(e *common.Envelope) (*common.Payload, error) {
putilsLogger.Infof("ValidateTransactionEnvelope returns err %s", err)
return payload, err
default:
return nil, fmt.Errorf("Unsupported transaction payload type %d", common.HeaderType(payload.Header.ChainHeader.Type))
return nil, fmt.Errorf("Unsupported transaction payload type %d", common.HeaderType(payload.Header.ChannelHeader.Type))
}
}
......@@ -178,7 +178,7 @@ func (b *blocksProviderImpl) seekOldest() error {
return b.client.Send(&common.Envelope{
Payload: utils.MarshalOrPanic(&common.Payload{
Header: &common.Header{
ChainHeader: &common.ChainHeader{
ChannelHeader: &common.ChannelHeader{
ChannelId: b.chainID,
},
SignatureHeader: &common.SignatureHeader{},
......@@ -196,7 +196,7 @@ func (b *blocksProviderImpl) seekLatestFromCommitter(height uint64) error {
return b.client.Send(&common.Envelope{
Payload: utils.MarshalOrPanic(&common.Payload{
Header: &common.Header{
ChainHeader: &common.ChainHeader{
ChannelHeader: &common.ChannelHeader{
ChannelId: b.chainID,
},
SignatureHeader: &common.SignatureHeader{},
......
......@@ -273,7 +273,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
}
chainID := hdr.ChainHeader.ChannelId
chainID := hdr.ChannelHeader.ChannelId
//chainless MSPs have "" chain name
ischainless := syscc.IsChainlessSysCC(hdrExt.ChaincodeId.Name)
......@@ -290,7 +290,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
//TODO check for uniqueness of prop.TxID with ledger
txid := hdr.ChainHeader.TxId
txid := hdr.ChannelHeader.TxId
if txid == "" {
err = fmt.Errorf("Invalid txID")
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
......
......@@ -106,7 +106,7 @@ func (historyDB *historyDB) Commit(block *common.Block) error {
return err
}
if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
// extract actions from the envelope message
respPayload, err := putils.GetActionFromEnvelope(envBytes)
......
......@@ -122,7 +122,7 @@ func getTxIDandKeyWriteValueFromTran(
return "", nil, err
}
txID := payload.Header.ChainHeader.TxId
txID := payload.Header.ChannelHeader.TxId
txRWSet := &rwset.TxReadWriteSet{}
......
......@@ -107,7 +107,7 @@ func (v *Validator) ValidateAndPrepareBatch(block *common.Block, doMVCCValidatio
}
valid := false
if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
txRWSet, err := v.validateEndorserTX(envBytes, doMVCCValidation, updates)
if err != nil {
return nil, err
......@@ -118,13 +118,13 @@ func (v *Validator) ValidateAndPrepareBatch(block *common.Block, doMVCCValidatio
addWriteSetToBatch(txRWSet, committingTxHeight, updates)
valid = true
}
} else if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_CONFIGURATION_TRANSACTION {
} else if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_CONFIGURATION_TRANSACTION {
valid, err = v.validateConfigTX(env)
if err != nil {
return nil, err
}
} else {
logger.Errorf("Skipping transaction %d that's not an endorsement or configuration %d", txIndex, payload.Header.ChainHeader.Type)
logger.Errorf("Skipping transaction %d that's not an endorsement or configuration %d", txIndex, payload.Header.ChannelHeader.Type)
valid = false
}
......
......@@ -143,7 +143,7 @@ func getCurrConfigBlockFromLedger(ledger ledger.PeerLedger) (*common.Block, erro
currBlockNumber = block.Header.Number - 1
continue
}
if tx.Header.ChainHeader.Type == int32(common.HeaderType_CONFIGURATION_TRANSACTION) {
if tx.Header.ChannelHeader.Type == int32(common.HeaderType_CONFIGURATION_TRANSACTION) {
return block, nil
}
}
......
......@@ -234,6 +234,6 @@ func getChainID(blockBytes []byte) (string, error) {
if err := proto.Unmarshal(envelope.Payload, payload); err != nil {
return "", err
}
fmt.Printf("chain id: %v\n", payload.Header.ChainHeader.ChannelId)
return payload.Header.ChainHeader.ChannelId, nil
fmt.Printf("Channel id: %v\n", payload.Header.ChannelHeader.ChannelId)
return payload.Header.ChannelHeader.ChannelId, nil
}
......@@ -86,7 +86,7 @@ func (vscc *ValidatorOneValidSignature) Invoke(stub shim.ChaincodeStubInterface)
}
// get the policy
mgr := mspmgmt.GetManagerForChain(payl.Header.ChainHeader.ChannelId)
mgr := mspmgmt.GetManagerForChain(payl.Header.ChannelHeader.ChannelId)
pProvider := cauthdsl.NewPolicyProvider(mgr)
policy, err := pProvider.NewPolicy(args[2])
if err != nil {
......@@ -95,9 +95,9 @@ func (vscc *ValidatorOneValidSignature) Invoke(stub shim.ChaincodeStubInterface)
}
// validate the payload type
if common.HeaderType(payl.Header.ChainHeader.Type) != common.HeaderType_ENDORSER_TRANSACTION {
logger.Errorf("Only Endorser Transactions are supported, provided type %d", payl.Header.ChainHeader.Type)
return shim.Error(fmt.Sprintf("Only Endorser Transactions are supported, provided type %d", payl.Header.ChainHeader.Type))
if common.HeaderType(payl.Header.ChannelHeader.Type) != common.HeaderType_ENDORSER_TRANSACTION {
logger.Errorf("Only Endorser Transactions are supported, provided type %d", payl.Header.ChannelHeader.Type)
return shim.Error(fmt.Sprintf("Only Endorser Transactions are supported, provided type %d", payl.Header.ChannelHeader.Type))
}
// ...and the transaction...
......
......@@ -84,7 +84,7 @@ func (a *Adapter) Disconnected(err error) {
}
func createTestBlock(t *testing.T) *common.Block {
chdr := &common.ChainHeader{
chdr := &common.ChannelHeader{
Type: int32(common.HeaderType_ENDORSER_TRANSACTION),
Version: 1,
Timestamp: &timestamp.Timestamp{
......@@ -92,7 +92,7 @@ func createTestBlock(t *testing.T) *common.Block {
Nanos: 0,
},
ChannelId: "test"}
hdr := &common.Header{ChainHeader: chdr}
hdr := &common.Header{ChannelHeader: chdr}
payload := &common.Payload{Header: hdr}
cea := &ehpb.ChaincodeEndorsedAction{}
ccaPayload := &ehpb.ChaincodeActionPayload{Action: cea}
......
......@@ -49,7 +49,7 @@ func SendProducerBlockEvent(block *common.Block) error {
return fmt.Errorf("Could not extract payload from envelope, err %s", err)
}
if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
tx, err := utils.GetTransaction(payload.Data)
if err != nil {
return fmt.Errorf("Error unmarshalling transaction payload for block event: %s", err)
......
......@@ -99,7 +99,7 @@ func getChainCodeEvents(tdata []byte) (*pb.ChaincodeEvent, error) {
return nil, fmt.Errorf("Could not extract payload from envelope, err %s", err)
}
if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
if common.HeaderType(payload.Header.ChannelHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
tx, err := utils.GetTransaction(payload.Data)
if err != nil {
return nil, fmt.Errorf("Error unmarshalling transaction payload for block event: %s", err)
......@@ -158,7 +158,7 @@ func main() {
fmt.Printf("\n")
fmt.Printf("Received invalid transaction\n")
fmt.Printf("--------------\n")
fmt.Printf("Transaction invalid: TxID: %s\n", tx.Header.ChainHeader.TxId)
fmt.Printf("Transaction invalid: TxID: %s\n", tx.Header.ChannelHeader.TxId)
}
} else {
fmt.Printf("Transaction:\n\t[%v]\n", r)
......
......@@ -79,15 +79,15 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
payload := &cb.Payload{}
err = proto.Unmarshal(msg.Payload, payload)
if payload.Header == nil || payload.Header.ChainHeader == nil || payload.Header.ChainHeader.ChannelId == "" {
if payload.Header == nil || payload.Header.ChannelHeader == nil || payload.Header.ChannelHeader.ChannelId == "" {
logger.Debugf("Received malformed message, dropping connection")
return srv.Send(&ab.BroadcastResponse{Status: cb.Status_BAD_REQUEST})
}
support, ok := bh.sm.GetChain(payload.Header.ChainHeader.ChannelId)
support, ok := bh.sm.GetChain(payload.Header.ChannelHeader.ChannelId)
if !ok {
// Chain not found, maybe create one?
if payload.Header.ChainHeader.Type != int32(cb.HeaderType_CONFIGURATION_TRANSACTION) {
if payload.Header.ChannelHeader.Type != int32(cb.HeaderType_CONFIGURATION_TRANSACTION) {
return srv.Send(&ab.BroadcastResponse{Status: cb.Status_NOT_FOUND})
}
......@@ -100,7 +100,7 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
}
if logger.IsEnabledFor(logging.DEBUG) {
logger.Debugf("Broadcast is filtering message for chain %s", payload.Header.ChainHeader.ChannelId)
logger.Debugf("Broadcast is filtering message for chain %s", payload.Header.ChannelHeader.ChannelId)
}
// Normal transaction for existing chain
......@@ -117,7 +117,7 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
}
if logger.IsEnabledFor(logging.DEBUG) {
logger.Debugf("Broadcast is successfully enqueued message for chain %s", payload.Header.ChainHeader.ChannelId)
logger.Debugf("Broadcast is successfully enqueued message for chain %s", payload.Header.ChannelHeader.ChannelId)
}
err = srv.Send(&ab.BroadcastResponse{Status: cb.Status_SUCCESS})
......
......@@ -74,7 +74,7 @@ func (mm *mockSupportManager) GetChain(chainID string) (Support, bool) {
func (mm *mockSupportManager) ProposeChain(configTx *cb.Envelope) cb.Status {
payload := utils.ExtractPayloadOrPanic(configTx)
mm.chains[string(payload.Header.ChainHeader.ChannelId)] = &mockSupport{
mm.chains[string(payload.Header.ChannelHeader.ChannelId)] = &mockSupport{
filters: filter.NewRuleSet([]filter.Rule{
filter.EmptyRejectRule,
filter.AcceptRule,
......@@ -101,7 +101,7 @@ func makeConfigMessage(chainID string) *cb.Envelope {
payload := &cb.Payload{
Data: utils.MarshalOrPanic(&cb.ConfigEnvelope{}),
Header: &cb.Header{
ChainHeader: &cb.ChainHeader{
ChannelHeader: &cb.ChannelHeader{
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_TRANSACTION),
},
......@@ -116,7 +116,7 @@ func makeMessage(chainID string, data []byte) *cb.Envelope {
payload := &cb.Payload{
Data: data,
Header: &cb.Header{
ChainHeader: &cb.ChainHeader{
ChannelHeader: &cb.ChannelHeader{
ChannelId: chainID,
},
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment