Skip to content

Commit

Permalink
node-sdk Implement new cc install / deploy
Browse files Browse the repository at this point in the history
Need to implement new remote install and deploy
replacing the prior sendDeploymentProposal with
sendInstallProposal and sendDeploymentProposal.

Protos also needed to be updated to sync up with
latest changes in fabric.

Change-Id: I69ac98a39292eb20c71cfa2bab74e558522f84b4
Signed-off-by: cdaughtr <cdaughtr@us.ibm.com>
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
cdaughtr authored and harrisob committed Feb 17, 2017
1 parent 59a96ce commit a4641aa
Show file tree
Hide file tree
Showing 20 changed files with 687 additions and 235 deletions.
295 changes: 235 additions & 60 deletions fabric-client/lib/Chain.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions fabric-client/lib/EventHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,23 @@ var EventHub = class {
eh.blockRegistrants.forEach(function(cb) {
cb(event.block);
});
event.block.Data.Data.forEach(function(transaction) {
event.block.data.data.forEach(function(transaction) {
try {
var env = _common.Envelope.decode(transaction);
var payload = _common.Payload.decode(env.payload);
if (payload.header.chainHeader.type == _common.HeaderType.ENDORSER_TRANSACTION) {
if (payload.header.channel_header.type == _common.HeaderType.ENDORSER_TRANSACTION) {
var tx = _transProto.Transaction.decode(payload.data);
var chaincodeActionPayload = _ccTransProto.ChaincodeActionPayload.decode(tx.actions[0].payload);
var propRespPayload = _responseProto.ProposalResponsePayload
.decode(chaincodeActionPayload.action.proposalResponsePayload);
.decode(chaincodeActionPayload.action.proposal_response_payload);
var caPayload = _ccProposalProto.ChaincodeAction.decode(propRespPayload.extension);
var ccEvent = _ccEventProto.ChaincodeEvent.decode(caPayload.events);
var cbtable = eh.chaincodeRegistrants.get(ccEvent.chaincodeID);
var cbtable = eh.chaincodeRegistrants.get(ccEvent.chaincode_id);
if (!cbtable) {
return;
}
cbtable.forEach(function(cbe) {
if (cbe.eventNameFilter.test(ccEvent.eventName)) {
if (cbe.eventNameFilter.test(ccEvent.event_name)) {
cbe.cb(ccEvent);
}
});
Expand Down Expand Up @@ -287,17 +287,17 @@ var EventHub = class {
txCallback(block) {
logger.debug('txCallback block=%j', block);
var eh = this;
block.Data.Data.forEach(function(transaction) {
block.data.data.forEach(function(transaction) {
try {
var env = _common.Envelope.decode(transaction);
var payload = _common.Payload.decode(env.payload);
} catch (err) {
logger.error('Error unmarshalling transaction from block=', err);
}
logger.debug('txid=' + payload.header.chainHeader.txID);
var cb = eh.txRegistrants.get(payload.header.chainHeader.txID);
logger.debug('txid=' + payload.header.channel_header.tx_id);
var cb = eh.txRegistrants.get(payload.header.channel_header.tx_id);
if (cb)
cb(transaction.txid);
cb(payload.header.channel_header.tx_id);
});
};
};
Expand Down
40 changes: 20 additions & 20 deletions fabric-client/lib/protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ enum Status {

enum HeaderType {
MESSAGE = 0; // Used for messages which are signed but opaque
CONFIGURATION_TRANSACTION = 1; // Used for messages which reconfigure the chain
CONFIGURATION_ITEM = 2; // Used inside of the the reconfiguration message for signing over ConfigurationItems
CONFIG = 1; // Used for messages which express the channel config
CONFIG_UPDATE = 2; // Used for transactions which update the channel config
ENDORSER_TRANSACTION = 3; // Used by the SDK to submit endorser based transactions
ORDERER_TRANSACTION = 4; // Used internally by the orderer for management
DELIVER_SEEK_INFO = 5; // Used as the type for Envelope messages submitted to instruct the Deliver API to seek
Expand All @@ -46,14 +46,14 @@ enum HeaderType {
// 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
LAST_CONFIG = 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
message LastConfiguration {
// LastConfig is the encoded value for the Metadata message which is encoded in the LAST_CONFIGURATION block metadata index
message LastConfig {
uint64 index = 1;
}

Expand All @@ -64,17 +64,17 @@ message Metadata {
}

message MetadataSignature {
bytes signatureHeader = 1; // An encoded SignatureHeader
bytes signature_header = 1; // An encoded SignatureHeader
bytes signature = 2; // The signature over the concatenation of the Metadata value bytes, signatureHeader, and block header
}

message Header {
ChainHeader chainHeader = 1;
SignatureHeader signatureHeader = 2;
ChannelHeader channel_header = 1;
SignatureHeader signature_header = 2;
}

// Header is a generic replay prevention and identity message to include in a signed payload
message ChainHeader {
message ChannelHeader {
int32 type = 1; // Header types 0-10000 are reserved and defined by HeaderType

// Version indicates message protocol version
Expand All @@ -84,16 +84,16 @@ message ChainHeader {
// by the sender
google.protobuf.Timestamp timestamp = 3;

// Identifier of the chain this message is bound for
string chainID = 4;
// Identifier of the channel this message is bound for
string channel_id = 4;

// An unique identifier that is used end-to-end.
// - set by higher layers such as end user or SDK
// - passed to the endorser (which will check for uniqueness)
// - as the header is passed along unchanged, it will be
// be retrieved by the committer (uniqueness check here as well)
// - to be stored in the ledger
string txID = 5;
string tx_id = 5;

// 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
Expand Down Expand Up @@ -140,24 +140,24 @@ message Envelope {
// in the BlockHeader. This makes it natural and obvious that the Data is included in the hash, but
// the Metadata is not.
message Block {
BlockHeader Header = 1;
BlockData Data = 2;
BlockMetadata Metadata = 3;
BlockHeader header = 1;
BlockData data = 2;
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
bytes DataHash = 3; // The hash of the BlockData, by MerkleTree
uint64 number = 1; // The position in the blockchain
bytes previous_hash = 2; // The hash of the previous block header
bytes data_hash = 3; // The hash of the BlockData, by MerkleTree
}

message BlockData {
repeated bytes Data = 1;
repeated bytes data = 1;
}

message BlockMetadata {
repeated bytes Metadata = 1;
repeated bytes metadata = 1;
}
119 changes: 74 additions & 45 deletions fabric-client/lib/protos/common/configtx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,68 +20,97 @@ limitations under the License.
syntax = "proto3";

import "common.proto";
import "policies.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
// ConfigEnvelope 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
// 2. Note the config properties (ConfigValue, ConfigPolicy, ConfigGroup) to be modified
// 3. Add any intermediate ConfigGroups to the ConfigUpdate.read_set (sparsely)
// 4. Add any additional desired dependencies to ConfigUpdate.read_set (sparsely)
// 5. Modify the config properties, incrementing each version by 1, set them in the ConfigUpdate.write_set
// Note: any element not modified but specified should already be in the read_set, so may be specified sparsely
// 6. Create ConfigUpdate message and marshal it into ConfigUpdateEnvelope.update and encode the required signatures
// a) Each signature is of type ConfigSignature
// b) The ConfigSignature signature is over the concatenation of signature_header and the ConfigUpdate bytes (which includes a ChainHeader)
// 5. Submit new Config for ordering in Envelope signed by submitter
// a) The Envelope Payload has data set to the marshaled ConfigEnvelope
// b) The Envelope Payload has a header of type Header.Type.CONFIG_UPDATE
//
// 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;
// 1. All items in the read_set exist at the read versions
// 2. All items in the write_set at a different version than, or not in, the read_set have been appropriately signed according to their mod_policy
// 3. The new configuration satisfies the ConfigSchema
message ConfigEnvelope {
Config config = 1; // A marshaled Config structure
ConfigUpdateEnvelope last_update = 2; // The most recent ConfigUpdateEnvelope whose diff generated the current config
}

// 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;
message ConfigGroupSchema {
map<string, ConfigGroupSchema> groups = 1;
map<string, ConfigValueSchema> values = 2;
map<string, ConfigPolicySchema> policies = 3;
}

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

message ConfigPolicySchema {}

// Config represents the config for a particular channel
message Config {
ChannelHeader header = 1;
ConfigGroup channel = 2;
}

message ConfigUpdateEnvelope {
bytes config_update = 1; // A marshaled ConfigUpdate structure
repeated ConfigSignature signatures = 2; // Signatures over the config_update
}

// ConfigUpdate is used to submit a subset of config and to have the orderer apply to Config
// it is always submitted inside a ConfigUpdateEnvelope which allows the addition of signatures
// resulting in a new total configuration. The update is applied as follows:
// 1. The versions from all of the elements in the read_set is verified against the versions in the existing config.
// If there is a mismatch in the read versions, then the config update fails and is rejected.
// 2. Any elements in the write_set with the same version as the read_set are ignored.
// 3. The corresponding mod_policy for every remaining element in the write_set is collected.
// 4. Each policy is checked against the signatures from the ConfigUpdateEnvelope, any failing to verify are rejected
// 5. The write_set is applied to the Config and the ConfigGroupSchema verifies that the updates were legal
message ConfigUpdate {
ChannelHeader header = 1; // Header scopes the update to a particular Channel
ConfigGroup read_set = 2; // ReadSet explicitly lists the portion of the config which was read, this should be sparse with only Version set
ConfigGroup write_set = 3; // WriteSet lists the portion of the config which was written, this should included updated Versions
}

// ConfigGroup is the hierarchical data structure for holding config
message ConfigGroup {
uint64 version = 1;
map<string,ConfigGroup> groups = 2;
map<string,ConfigValue> values = 3;
map<string,ConfigPolicy> policies = 4;
string mod_policy = 5;
}

// ConfigValue represents an individual piece of config data
message ConfigValue {
uint64 version = 1;
bytes value = 2;
string mod_policy = 3;
}

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 ConfigPolicy {
uint64 version = 1;
Policy policy = 2;
string mod_policy = 3;
}

message ConfigurationSignature {
bytes signatureHeader = 1; // A marshaled SignatureHeader
bytes signature = 2; // Signature over the concatenation of configurationItem bytes and signatureHeader bytes
message ConfigSignature {
bytes signature_header = 1; // A marshaled SignatureHeader
bytes signature = 2; // Signature over the concatenation signatureHeader bytes and config bytes
}
20 changes: 10 additions & 10 deletions fabric-client/lib/protos/common/msp_principal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ package common;
message MSPPrincipal {

enum Classification {
ByMSPRole = 0; // Represents the one of the dedicated MSP roles, the
ROLE = 0; // Represents the one of the dedicated MSP roles, the
// one of a member of MSP network, and the one of an
// administrator of an MSP network
ByOrganizationUnit = 1; // Denotes a finer grained (affiliation-based)
ORGANIZATION_UNIT = 1; // Denotes a finer grained (affiliation-based)
// groupping of entities, per MSP affiliation
// E.g., this can well be represented by an MSP's
// Organization unit
ByIdentity = 2; // Denotes a principal that consists of a single
IDENTITY = 2; // Denotes a principal that consists of a single
// identity
}

Expand All @@ -67,14 +67,14 @@ message MSPPrincipal {
// "Principal" contains a specific identity. Default value
// denotes that Principal contains one of the groups by
// default supported by all MSPs ("admin" or "member").
Classification PrincipalClassification = 1;
Classification principal_classification = 1;

// Principal completes the policy principal definition. For the default
// principal types, Principal can be either "Admin" or "Member".
// For the ByOrganizationUnit/ByIdentity values of Classification,
// PolicyPrincipal acquires its value from an organization unit or
// identity, respectively.
bytes Principal = 2;
bytes principal = 2;
}


Expand All @@ -85,11 +85,11 @@ message OrganizationUnit {

// MSPIdentifier represents the identifier of the MSP this organization unit
// refers to
string MSPIdentifier = 1;
string msp_identifier = 1;

// OrganizationUnitIdentifier defines the organization unit under the
// MSP identified with MSPIdentifier
string OrganizationUnitIdentifier = 2;
string organizational_unit_identifier = 2;

}

Expand All @@ -100,11 +100,11 @@ message MSPRole {

// MSPIdentifier represents the identifier of the MSP this principal
// refers to
string MSPIdentifier = 1;
string msp_identifier = 1;

enum MSPRoleType {
Member = 0; // Represents an MSP Member
Admin = 1; // Represents an MSP Admin
MEMBER = 0; // Represents an MSP Member
ADMIN = 1; // Represents an MSP Admin
}

// MSPRoleType defines which of the available, pre-defined MSP-roles
Expand Down
13 changes: 7 additions & 6 deletions fabric-client/lib/protos/common/policies.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

syntax = "proto3";

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

option go_package = "github.com/hyperledger/fabric/protos/common";
Expand All @@ -36,9 +37,9 @@ message Policy {

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

// SignaturePolicy is a recursive message structure which defines a featherweight DSL for describing
Expand All @@ -50,10 +51,10 @@ message SignaturePolicyEnvelope {
message SignaturePolicy {
message NOutOf {
int32 N = 1;
repeated SignaturePolicy Policies = 2;
repeated SignaturePolicy policies = 2;
}
oneof Type {
int32 SignedBy = 1;
NOutOf From = 2;
int32 signed_by = 1;
NOutOf from = 2;
}
}
Loading

0 comments on commit a4641aa

Please sign in to comment.