Skip to content

Commit

Permalink
NodeSDK chain create submit to orderer FAB-1531
Browse files Browse the repository at this point in the history
Updates to Chain to implement the first part of the
chain create, submitting the configuration info to
the orderer. Other changes are for proto changes in
fabric.

Change-Id: I6445a36685c1e8cc57183bb7cbe3fb8238a5a412
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Jan 11, 2017
1 parent a4dd2b6 commit 2f3d29e
Show file tree
Hide file tree
Showing 11 changed files with 828 additions and 84 deletions.
404 changes: 394 additions & 10 deletions hfc/lib/Chain.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions hfc/lib/Orderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ var Orderer = class extends Remote {
clearTimeout(broadcast_timeout);
all_done = true;

if(response.Status) {
if (response.Status === 'SUCCESS') {
logger.debug('Orderer.sendBroadcast - resolve with %s', response.Status);
if(response.status) {
if (response.status === 'SUCCESS') {
logger.debug('Orderer.sendBroadcast - resolve with %s', response.status);
return resolve(response);
} else {
logger.error('Orderer.sendBroadcast - reject with %s', response.Status);
return reject(new Error(response.Status));
logger.error('Orderer.sendBroadcast - reject with %s', response.status);
return reject(response);
}
}
else {
Expand Down
16 changes: 12 additions & 4 deletions hfc/lib/protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ 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
ENDORSER_TRANSACTION = 3; // Used by the SDK to submit endorser based transactions
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
ENDORSER_TRANSACTION = 3; // Used by the SDK to submit endorser based transactions
ORDERER_TRANSACTION = 4; // Used internally by the orderer for management
}

// This enum enlist 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
}

message Header {
Expand Down
10 changes: 8 additions & 2 deletions hfc/lib/protos/common/configuration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ message ConfigurationSignature {
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 {
oneof Type {
SignaturePolicyEnvelope SignaturePolicy = 1;
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
Expand Down
59 changes: 32 additions & 27 deletions hfc/lib/protos/orderer/ab.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,48 @@ option go_package = "github.com/hyperledger/fabric/protos/orderer";
package orderer;

message BroadcastResponse {
common.Status Status = 1;
common.Status status = 1;
}

message SeekInfo {
// Start may be specified to a specific block number, or may be request from the newest or oldest available
// The start location is always inclusive, so the first reply from NEWEST will contain the newest block at the time
// of reception, it will must not wait until a new block is created. Similarly, when SPECIFIED, and SpecifiedNumber = 10
// The first block received must be block 10, not block 11
enum StartType {
NEWEST = 0;
OLDEST = 1;
SPECIFIED = 2;
}
StartType Start = 1;
uint64 SpecifiedNumber = 2; // Only used when start = SPECIFIED
uint64 WindowSize = 3; // The window size is the maximum number of blocks that will be sent without Acknowledgement, the base of the window moves to the most recently received acknowledgment
string ChainID = 4; // The chain to seek within
}
message SeekNewest { }

message SeekOldest { }

message Acknowledgement {
uint64 Number = 1;
message SeekSpecified {
uint64 number = 1;
}

// The update message either causes a seek to a new stream start with a new window, or acknowledges a received block and advances the base of the window
message DeliverUpdate {
message SeekPosition {
oneof Type {
Acknowledgement Acknowledgement = 1; // Acknowledgement should be sent monotonically and only for a block which has been received, Acknowledgements received non-monotonically has undefined behavior
SeekInfo Seek = 2; // When set, SeekInfo causes a seek and potential reconfiguration of the window size
SeekNewest newest = 1;
SeekOldest oldest = 2;
SeekSpecified specified = 3;
}
}

// SeekInfo specifies the range of requested blocks to return
// If the start position is not found, an error is immediately returned
// Otherwise, blocks are returned until a missing block is encountered, then behavior is dictated
// by the SeekBehavior specified. If BLOCK_UNTIL_READY is specified, the reply will block until
// the requested blocks are available, if FAIL_IF_NOT_READY is specified, the reply will return an
// error indicating that the block is not found. To request that all blocks be returned indefinitely
// as they are created, behavior should be set to BLOCK_UNTIL_READY and the stop should be set to
// specified with a number of MAX_UINT64
message SeekInfo {
enum SeekBehavior {
BLOCK_UNTIL_READY = 0;
FAIL_IF_NOT_READY = 1;
}
string chainID = 1; // The chain to seek within
SeekPosition start = 2; // The position to start the deliver from
SeekPosition stop = 3; // The position to stop the deliver
SeekBehavior behavior = 4; // The behavior when a missing block is encountered
}

message DeliverResponse {
oneof Type {
common.Status Error = 1;
common.Block Block = 2;
common.Status status = 1;
common.Block block = 2;
}
}

Expand All @@ -66,7 +73,5 @@ service AtomicBroadcast {
rpc Broadcast(stream common.Envelope) returns (stream BroadcastResponse) {}

// deliver first requires an update containing a seek message, then a stream of block replies is received.
// The receiver may choose to send an Acknowledgement for any block number it receives, however Acknowledgements must never be more than WindowSize apart
// To avoid latency, clients will likely acknowledge before the WindowSize has been exhausted, preventing the server from stopping and waiting for an Acknowledgement
rpc Deliver(stream DeliverUpdate) returns (stream DeliverResponse) {}
rpc Deliver(stream SeekInfo) returns (stream DeliverResponse) {}
}
76 changes: 76 additions & 0 deletions hfc/lib/protos/orderer/configuration.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright IBM Corp. 2016 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.
*/

syntax = "proto3";

import "../common/common.proto";

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

package orderer;


// The orderer config is specified by the following convention:
// For a configuration item with key "Key"
// the encoded value is a a proto message of type "Key"
// For example, for the configuration item of name "ConsensusType"
// the encoded value is the proto message "ConsensusType"

message ConsensusType {
string type = 1;
}

message BatchSize {
// Simply specified as number of messages for now, in the future
// we may want to allow this to be specified by size in bytes
uint32 maxMessageCount = 1;
}

message BatchTimeout {
// Any duration string parseable by ParseDuration():
// https://golang.org/pkg/time/#ParseDuration
string timeout = 1;
}

// When submitting a new chain configuration transaction to create a new chain,
// the first configuration item must be of type Orderer with Key CreationPolicy
// and contents of a Marshaled CreationPolicy. The policy should be set to the
// policy which was supplied by the ordering service for the client's chain
// creation. The digest should be the hash of the concatenation of the remaining
// ConfigurationItem bytes. The signatures of the configuration item should
// satisfy the policy for chain creation.
message CreationPolicy {
// The name of the policy which should be used to validate the creation of
// this chain
string policy = 1;

// The hash of the concatenation of remaining configuration item bytes
bytes digest = 2;
}

message ChainCreators {
// A list of policies, any of which may be specified as the chain creation
// policy in a chain creation request
repeated string policies = 1;
}

// Carries a list of bootstrap brokers, i.e. this is not the exclusive set of
// brokers an ordering service
message KafkaBrokers {
// Each broker here should be identified using the (IP|host):port notation,
// e.g. 127.0.0.1:7050, or localhost:7050 are valid entries
repeated string brokers = 1;
}
2 changes: 1 addition & 1 deletion hfc/lib/protos/peer/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

syntax = "proto3";

import "../common/common.proto";
import "chaincodeevent.proto";
import "fabric_transaction.proto";
import "fabric_block.proto";

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

Expand Down
28 changes: 0 additions & 28 deletions hfc/lib/protos/peer/fabric_block.proto

This file was deleted.

8 changes: 4 additions & 4 deletions test/unit/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ test('End-to-end flow of chaincode deploy, transaction invocation, and query', f
// in sequence, will need to sleep for 30sec here
promise = promise.then(
function(response) {
if (response.Status === 'SUCCESS') {
if (response.status === 'SUCCESS') {
t.pass('Successfully ordered deployment endorsement.');
console.log(' need to wait now for the committer to catch up after the deployment');
console.log(' ** need to wait now for the committer to catch up after the deployment');
return sleep(30000);
} else {
t.fail('Failed to order the deployment endorsement. Error code: ' + response.status);
Expand Down Expand Up @@ -238,13 +238,13 @@ test('End-to-end flow of chaincode deploy, transaction invocation, and query', f
// in sequence, will need to sleep for 30sec here
promise = promise.then(
function(response) {
if (response.Status === 'SUCCESS') {
if (response.status === 'SUCCESS') {
t.pass('Successfully ordered endorsement transaction.');
} else {
t.fail('Failed to order the endorsement of the transaction. Error code: ' + response.status);
}
// always sleep and check with query
console.log(' need to wait now for the committer to catch up after the **** MOVE ****');
console.log(' ** need to wait now for the committer to catch up after the **** MOVE ****');
t.end();
return sleep(30000);
},
Expand Down
Loading

0 comments on commit 2f3d29e

Please sign in to comment.