Skip to content

Commit

Permalink
Introduce protocol_version field for TP registration
Browse files Browse the repository at this point in the history
1. MAX_SDK_PROTOCOL_VERSION is the maximum version that the
validator can support. The SDK shall consider registration
attempt unsuccessful if validator cannot support a feature.
2. A protocol_version field is sent in TpRegisterRequest message.
This is acknowledged back with a echoed protocol_version if
validator can handle the request successfully. Otherwise
registration attempt would be rejected.

Signed-off-by: S m, Aruna <[email protected]>
  • Loading branch information
arsulegai committed May 10, 2019
1 parent 2eed8b4 commit 5c27af8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
15 changes: 13 additions & 2 deletions protos/processor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import "transaction.proto";


// The registration request from the transaction processor to the
// validator/executor
// validator/executor.
//
// The protocol_version field is used to check if the validator supports
// requested features by a transaction processor.
message TpRegisterRequest {

// A settled upon name for the capabilities of the transaction processor.
// For example: intkey, xo
string family = 1;
Expand All @@ -42,6 +44,11 @@ message TpRegisterRequest {
// The maximum number of transactions that this transaction processor can
// handle at once.
uint32 max_occupancy = 5;

// Validator can make use of this field to check if the requested features
// are supported. Registration requests can be either accepted or rejected
// based on this field.
uint32 protocol_version = 6;
}

// A response sent from the validator to the transaction processor
Expand All @@ -54,6 +61,10 @@ message TpRegisterResponse {
}

Status status = 1;

// Respond back with protocol_version, the value that can be used by SDK to
// know if validator supports expected feature.
uint32 protocol_version = 2;
}

// The unregistration request from the transaction processor to the
Expand Down
44 changes: 36 additions & 8 deletions validator/sawtooth_validator/execution/processor_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
LOGGER = logging.getLogger(__name__)

DEFAULT_MAX_OCCUPANCY = 10
# This is the version used by the SDK to match if the validator supports
# features it requested during registration. It should only be incremented
# when there are changes in TpRegisterRequest.
# Remember to sync this information in SDK if changed here.
MAX_SDK_PROTOCOL_VERSION = 1


class ProcessorRegisterHandler(Handler):
Expand All @@ -44,14 +49,25 @@ def handle(self, connection_id, message_content):
else:
max_occupancy = request.max_occupancy

LOGGER.info(
'registered transaction processor: connection_id=%s, family=%s, '
'version=%s, namespaces=%s, max_occupancy=%s',
connection_id,
request.family,
request.version,
list(request.namespaces),
max_occupancy)

# Reject the request if requested version cannot be handled,
# validator does backward compatible support.
if request.protocol_version > MAX_SDK_PROTOCOL_VERSION:
ack = processor_pb2.TpRegisterResponse()
ack.status = ack.ERROR
# Send protocol_version of validator, so that the SDK can cross
# verify if it can get all services requested for.
ack.protocol_version = request.protocol_version
LOGGER.error(
'Validator version %s does not support the features requested'
' by the %s version of transaction processor',
str(MAX_SDK_PROTOCOL_VERSION),
str(request.protocol_version))

return HandlerResult(
status=HandlerStatus.RETURN,
message_out=ack,
message_type=validator_pb2.Message.TP_REGISTER_RESPONSE)

processor_type = processor_manager.ProcessorType(
request.family,
Expand All @@ -66,6 +82,18 @@ def handle(self, connection_id, message_content):

ack = processor_pb2.TpRegisterResponse()
ack.status = ack.OK
# Echo back the requested protocol_version, so that the SDK can
# cross verify that it can get all services requested
ack.protocol_version = request.protocol_version

LOGGER.info(
'registered transaction processor: connection_id=%s, family=%s, '
'version=%s, namespaces=%s, max_occupancy=%s',
connection_id,
request.family,
request.version,
list(request.namespaces),
max_occupancy)

return HandlerResult(
status=HandlerStatus.RETURN,
Expand Down

0 comments on commit 5c27af8

Please sign in to comment.