Skip to content

Commit

Permalink
NodeSDK - update to latest protos
Browse files Browse the repository at this point in the history
Pull in all latest fabric proto files.
Update new chain flow with new structure.

Change-Id: Ie9042e2019ee096f0530dcc3caa4071d656e7204
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Feb 8, 2017
1 parent 5e43972 commit 59e88c6
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 148 deletions.
36 changes: 14 additions & 22 deletions fabric-client/lib/Chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ var _proposalProto = grpc.load(__dirname + '/protos/peer/proposal.proto').protos
var _responseProto = grpc.load(__dirname + '/protos/peer/proposal_response.proto').protos;
var _mspPrProto = grpc.load(__dirname + '/protos/common/msp_principal.proto').common;
var _commonProto = grpc.load(__dirname + '/protos/common/common.proto').common;
var _configurationProto = grpc.load(__dirname + '/protos/common/configuration.proto').common;
var _configtxProto = grpc.load(__dirname + '/protos/common/configtx.proto').common;
var _policiesProto = grpc.load(__dirname + '/protos/common/policies.proto').common;
var _ledgerProto = grpc.load(__dirname + '/protos/common/ledger.proto').common;
var _ordererConfigurationProto = grpc.load(__dirname + '/protos/orderer/configuration.proto').orderer;
var _abProto = grpc.load(__dirname + '/protos/orderer/ab.proto').orderer;
var _mspConfigProto = grpc.load(__dirname + '/protos/msp/mspconfig.proto').msp;
Expand Down Expand Up @@ -457,9 +459,9 @@ var Chain = class {
);

var orderer_type =
_configurationProto.ConfigurationItem.ConfigurationType.Orderer;
_configtxProto.ConfigurationItem.ConfigurationType.Orderer;
var policy_type =
_configurationProto.ConfigurationItem.ConfigurationType.Policy;
_configtxProto.ConfigurationItem.ConfigurationType.Policy;
var last_modified = '0';
var mod_policy = 'DefaultModificationPolicy';

Expand All @@ -469,7 +471,6 @@ var Chain = class {
var consensusType = new _ordererConfigurationProto.ConsensusType();
consensusType.setType(self.getConsensusType());
var consensusTypeItem = buildSignedConfigurationItem(
configItemChainHeader,
orderer_type,
last_modified,
mod_policy,
Expand All @@ -483,7 +484,6 @@ var Chain = class {
batchSize.setAbsoluteMaxBytes(self.getInitialAbsoluteMaxBytes());
batchSize.setPreferredMaxBytes(self.getInitialPreferredMaxBytes());
var batchSizeItem = buildSignedConfigurationItem(
configItemChainHeader,
orderer_type,
last_modified,
mod_policy,
Expand All @@ -498,7 +498,6 @@ var Chain = class {
// var chainCreators = new _ordererConfigurationProto.ChainCreators();
// chainCreators.setPolicies([chainCreatorPolicyName]);
// var chainCreatorsItem = buildSignedConfigurationItem(
// configItemChainHeader,
// orderer_type,
// last_modified,
// mod_policy,
Expand All @@ -510,7 +509,6 @@ var Chain = class {
var ingressPolicy = new _ordererConfigurationProto.IngressPolicyNames();
ingressPolicy.setNames([chainCreatorPolicyName]);
var ingressPolicyItem = buildSignedConfigurationItem(
configItemChainHeader,
orderer_type,
last_modified,
mod_policy,
Expand All @@ -522,7 +520,6 @@ var Chain = class {
var egressPolicy = new _ordererConfigurationProto.EgressPolicyNames();
egressPolicy.setNames([chainCreatorPolicyName]);
var egressPolicyItem = buildSignedConfigurationItem(
configItemChainHeader,
orderer_type,
last_modified,
mod_policy,
Expand All @@ -534,7 +531,6 @@ var Chain = class {
var acceptAllPolicy = buildAcceptAllPolicy();
logger.debug('accept policy::'+JSON.stringify(acceptAllPolicy));
var acceptAllPolicyItem = buildSignedConfigurationItem(
configItemChainHeader,
policy_type,
last_modified,
mod_policy,
Expand All @@ -548,7 +544,6 @@ var Chain = class {
var rejectAllPolicy = buildRejectAllPolicy();
logger.debug('reject policy::'+JSON.stringify(rejectAllPolicy));
var defaultModificationPolicyItem = buildSignedConfigurationItem(
configItemChainHeader,
policy_type,
last_modified,
mod_policy,
Expand Down Expand Up @@ -576,7 +571,6 @@ var Chain = class {
mspconf.setType(0);

var mspConfigItem = buildSignedConfigurationItem(
configItemChainHeader,
orderer_type,
last_modified,
mod_policy,
Expand All @@ -601,7 +595,6 @@ var Chain = class {
creationPolicy.setDigest(Buffer.from(creation_items_hash, 'hex'));
//creationPolicy.setDigest(creation_items_hash);
var createPolicyItem = buildSignedConfigurationItem(
configItemChainHeader,
orderer_type,
last_modified,
mod_policy,
Expand All @@ -612,7 +605,7 @@ var Chain = class {
logger.debug('initializeChain - all items built');

//bundle all the items
var configurationEnvelope = new _configurationProto.ConfigurationEnvelope();
var configurationEnvelope = new _configtxProto.ConfigurationEnvelope();
configurationEnvelope.setItems([
createPolicyItem,
consensusTypeItem,
Expand All @@ -624,6 +617,7 @@ var Chain = class {
defaultModificationPolicyItem,
mspConfigItem
]);
configurationEnvelope.setHeader(configItemChainHeader);

// build a chain header for later to be
// used in the atomic broadcast
Expand Down Expand Up @@ -1427,22 +1421,20 @@ function buildHeader(creator, chainHeader, nonce) {

//utility method to build a signed configuration item
function buildSignedConfigurationItem(
chain_header,
type,
last_modified,
mod_policy,
key,
value,
signatures) {
var configurationItem = new _configurationProto.ConfigurationItem();
configurationItem.setHeader(chain_header); // ChainHeader
var configurationItem = new _configtxProto.ConfigurationItem();
configurationItem.setType(type); // ConfigurationType
configurationItem.setLastModified(last_modified); // uint64
configurationItem.setModificationPolicy(mod_policy); // ModificationPolicy
configurationItem.setKey(key); // string
configurationItem.setValue(value); // bytes

var signedConfigurationItem = new _configurationProto.SignedConfigurationItem();
var signedConfigurationItem = new _configtxProto.SignedConfigurationItem();
signedConfigurationItem.setConfigurationItem(configurationItem.toBuffer());
if(signatures) {
signedConfigurationItem.setSignatures(signatures);
Expand All @@ -1464,21 +1456,21 @@ function buildRejectAllPolicy() {
//utility method to build a policy with a signature policy envelope
function buildPolicyEnvelope(nOf) {
logger.debug('buildPolicyEnvelope - building policy with nOf::'+nOf);
var nOutOf = new _configurationProto.SignaturePolicy.NOutOf();
var nOutOf = new _policiesProto.SignaturePolicy.NOutOf();
nOutOf.setN(nOf);
nOutOf.setPolicies([]);
var signaturePolicy = new _configurationProto.SignaturePolicy();
var signaturePolicy = new _policiesProto.SignaturePolicy();
signaturePolicy.setFrom(nOutOf);
var signaturePolicyEnvelope = new _configurationProto.SignaturePolicyEnvelope();
var signaturePolicyEnvelope = new _policiesProto.SignaturePolicyEnvelope();
signaturePolicyEnvelope.setVersion(0);
signaturePolicyEnvelope.setPolicy(signaturePolicy);
// var identity = new _mspPrProto.MSPPrincipal();
// identity.setPrincipalClassification(_mspPrProto.MSPPrincipal.Classification.ByIdentity);
// identity.setPrincipal(Buffer.from('Admin'));
signaturePolicyEnvelope.setIdentities([]);

var policy = new _configurationProto.Policy();
policy.setType(_configurationProto.Policy.PolicyType.SIGNATURE);
var policy = new _policiesProto.Policy();
policy.setType(_policiesProto.Policy.PolicyType.SIGNATURE);
policy.setPolicy(signaturePolicyEnvelope.toBuffer());
return policy;
};
Expand Down
7 changes: 6 additions & 1 deletion fabric-client/lib/protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ enum HeaderType {
DELIVER_SEEK_INFO = 5; // Used as the type for Envelope messages submitted to instruct the Deliver API to seek
}

// This enum enlist indexes of the block metadata array
// This enum enlists indexes of the block metadata array
enum BlockMetadataIndex {
SIGNATURES = 0; // Block metadata array position for block signatures
LAST_CONFIGURATION = 1; // Block metadata array poistion to store last configuration block sequence number
TRANSACTIONS_FILTER = 2; // Block metadata array poistion to store serialized bit array filter of invalid transactions
ORDERER = 3; // Block metadata array position to store operational metadata for orderers
// e.g. For Kafka, this is where we store the last offset written to the local ledger.
}

// LastConfiguration is the encoded value for the Metadata message which is encoded in the LAST_CONFIGURATION block metadata index
Expand Down Expand Up @@ -143,6 +145,9 @@ message Block {
BlockMetadata Metadata = 3;
}

// BlockHeader is the element of the block which forms the block chain
// The block header is hashed using the configured chain hashing algorithm
// over the ASN.1 encoding of the BlockHeader
message BlockHeader {
uint64 Number = 1; // The position in the blockchain
bytes PreviousHash = 2; // The hash of the previous block header
Expand Down
87 changes: 87 additions & 0 deletions fabric-client/lib/protos/common/configtx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright IBM Corp. 2017 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// XXX This is the older mechanism for specifying channel configuration
// it is intended to be removed once there is no more dependency on it.

syntax = "proto3";

import "common.proto";

option go_package = "github.com/hyperledger/fabric/protos/common";

package common;

// ConfigurationEnvelope is designed to contain _all_ configuration for a chain with no dependency
// on previous configuration transactions.
//
// It is generated with the following scheme:
// 1. Retrieve the existing configuration
// 2. Note the highest configuration sequence number, store it and increment it by one
// 3. Modify desired ConfigurationItems, setting each LastModified to the stored and incremented sequence number
// a) Note that the ConfigurationItem has a ChainHeader header attached to it, who's type is set to CONFIGURATION_ITEM
// 4. Update SignedConfigurationItem with appropriate signatures over the modified ConfigurationItem
// a) Each signature is of type ConfigurationSignature
// b) The ConfigurationSignature signature is over the concatenation of signatureHeader and the ConfigurationItem bytes (which includes a ChainHeader)
// 5. Submit new Configuration for ordering in Envelope signed by submitter
// a) The Envelope Payload has data set to the marshaled ConfigurationEnvelope
// b) The Envelope Payload has a header of type Header.Type.CONFIGURATION_TRANSACTION
//
// The configuration manager will verify:
// 1. All configuration items and the envelope refer to the correct chain
// 2. Some configuration item has been added or modified
// 3. No existing configuration item has been ommitted
// 4. All configuration changes have a LastModification of one more than the last configuration's highest LastModification number
// 5. All configuration changes satisfy the corresponding modification policy
message ConfigurationEnvelope {
repeated SignedConfigurationItem Items = 1;

// XXX This needs to be signed over, purely temporary pending completion of https://jira.hyperledger.org/browse/FAB-1880
ChainHeader header = 2;
}

// ConfigurationTemplate is used as a serialization format to share configuration templates
// The orderer supplies a configuration template to the user to use when constructing a new
// chain creation transaction, so this is used to facilitate that.
message ConfigurationTemplate {
repeated ConfigurationItem Items = 1;
}

// This message may change slightly depending on the finalization of signature schemes for transactions
message SignedConfigurationItem {
bytes ConfigurationItem = 1;
repeated ConfigurationSignature Signatures = 2;
}

message ConfigurationItem {
enum ConfigurationType {
Policy = 0; // Implies that the Value is a marshaled Policy message, and may be referred to by Key as a ModificationPolicy
Chain = 1; // Marshaled format for this type is yet to be determined
Orderer = 2; // Marshaled format for this type is yet to be determined
Peer = 3; // Marshaled format for this type is yet to be determined
MSP = 4; // Marshaled MSPConfig proto
}
ConfigurationType Type = 1; // The type of configuration this is.
uint64 LastModified = 2; // The Sequence number in the ConfigurationEnvelope this item was last modified
string ModificationPolicy = 3; // What policy to check before allowing modification
string Key = 4; // A unique ID, unique scoped by Type, to reference the value by
bytes Value = 5; // The byte representation of this configuration, usually a marshaled message
}

message ConfigurationSignature {
bytes signatureHeader = 1; // A marshaled SignatureHeader
bytes signature = 2; // Signature over the concatenation of configurationItem bytes and signatureHeader bytes
}
99 changes: 0 additions & 99 deletions fabric-client/lib/protos/common/configuration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,109 +16,10 @@ limitations under the License.

syntax = "proto3";

import "common.proto";
import "msp_principal.proto";

option go_package = "github.com/hyperledger/fabric/protos/common";

package common;

// ConfigurationEnvelope is designed to contain _all_ configuration for a chain with no dependency
// on previous configuration transactions.
//
// It is generated with the following scheme:
// 1. Retrieve the existing configuration
// 2. Note the highest configuration sequence number, store it and increment it by one
// 3. Modify desired ConfigurationItems, setting each LastModified to the stored and incremented sequence number
// a) Note that the ConfigurationItem has a ChainHeader header attached to it, who's type is set to CONFIGURATION_ITEM
// 4. Update SignedConfigurationItem with appropriate signatures over the modified ConfigurationItem
// a) Each signature is of type ConfigurationSignature
// b) The ConfigurationSignature signature is over the concatenation of signatureHeader and the ConfigurationItem bytes (which includes a ChainHeader)
// 5. Submit new Configuration for ordering in Envelope signed by submitter
// a) The Envelope Payload has data set to the marshaled ConfigurationEnvelope
// b) The Envelope Payload has a header of type Header.Type.CONFIGURATION_TRANSACTION
//
// The configuration manager will verify:
// 1. All configuration items and the envelope refer to the correct chain
// 2. Some configuration item has been added or modified
// 3. No existing configuration item has been ommitted
// 4. All configuration changes have a LastModification of one more than the last configuration's highest LastModification number
// 5. All configuration changes satisfy the corresponding modification policy
message ConfigurationEnvelope {
repeated SignedConfigurationItem Items = 1;
}

// ConfigurationTemplate is used as a serialization format to share configuration templates
// The orderer supplies a configuration template to the user to use when constructing a new
// chain creation transaction, so this is used to facilitate that.
message ConfigurationTemplate {
repeated ConfigurationItem Items = 1;
}

// This message may change slightly depending on the finalization of signature schemes for transactions
message SignedConfigurationItem {
bytes ConfigurationItem = 1;
repeated ConfigurationSignature Signatures = 2;
}

message ConfigurationItem {
enum ConfigurationType {
Policy = 0; // Implies that the Value is a marshaled Policy message, and may be referred to by Key as a ModificationPolicy
Chain = 1; // Marshaled format for this type is yet to be determined
Orderer = 2; // Marshaled format for this type is yet to be determined
Peer = 3; // Marshaled format for this type is yet to be determined
MSP = 4; // Marshaled MSPConfig proto
}
ChainHeader Header = 1; // The header which ties this configuration to a particular chain
ConfigurationType Type = 2; // The type of configuration this is.
uint64 LastModified = 3; // The Sequence number in the ConfigurationEnvelope this item was last modified
string ModificationPolicy = 4; // What policy to check before allowing modification
string Key = 5; // A unique ID, unique scoped by Type, to reference the value by
bytes Value = 6; // The byte representation of this configuration, usually a marshaled message
}

message ConfigurationSignature {
bytes signatureHeader = 1; // A marshaled SignatureHeader
bytes signature = 2; // Signature over the concatenation of configurationItem bytes and signatureHeader bytes
}

// Policy expresses a policy which the orderer can evaluate, because there has been some desire expressed to support
// multiple policy engines, this is typed as a oneof for now
message Policy {
enum PolicyType {
UNKNOWN = 0; // Reserved to check for proper initialization
SIGNATURE = 1;
MSP = 2;
}
int32 type = 1; // For outside implementors, consider the first 1000 types reserved, otherwise one of PolicyType
bytes policy = 2;
}

// SignaturePolicyEnvelope wraps a SignaturePolicy and includes a version for future enhancements
message SignaturePolicyEnvelope {
int32 Version = 1;
SignaturePolicy Policy = 2;
repeated MSPPrincipal Identities = 3;
}

// SignaturePolicy is a recursive message structure which defines a featherweight DSL for describing
// policies which are more complicated than 'exactly this signature'. The NOutOf operator is sufficent
// to express AND as well as OR, as well as of course N out of the following M policies
// SignedBy implies that the signature is from a valid certificate which is signed by the trusted
// authority specified in the bytes. This will be the certificate itself for a self-signed certificate
// and will be the CA for more traditional certificates
message SignaturePolicy {
message NOutOf {
int32 N = 1;
repeated SignaturePolicy Policies = 2;
}
oneof Type {
int32 SignedBy = 1;
NOutOf From = 2;
}
}


// HashingAlgorithm is encoded into the configuration transaction as a configuration item of type Chain
// with a Key of "HashingAlgorithm" and a Value of HashingAlgorithm as marshaled protobuf bytes
message HashingAlgorithm {
Expand Down
Loading

0 comments on commit 59e88c6

Please sign in to comment.