Fabric Gateway

Fabric gateway is a bridge between client application and fabric network. Gateway simplify the interaction between client application and network.

Fabric Gateway is a service, very first introduced in Hyperledger Fabric version 2.4, which provides a simplified and minimized  API (Application Program Interface) to submit transactions over a Fabric network.

The Gateway SDK(Software Development Kit) combines the Endorse, Submit, and Commit Status actions into a single  “Submit Transaction” function to support transaction submission in a single line of code.

Gateway bypasses traditional architectural flow of hyperledger fabric.

Software Development Kits

The Gateway and its SDKs are designed to allow us as a client application developer, to concentrate on the business logic of your application without having to concern with the infrastructure logic associated with a Fabric network.

In simple words fabric gateway allow to developer to concentrate more on  blockchain based application rather than its infrastructure.

The APIs provides,

 logical abstractions like organization and contract 

rather than operational abstractions such as peer and chaincode.

Hyperledger Fabric currently supports client application development in three languages:

  • Go.
  • Node (Typescript/Javascript).
  • Java.

Different types of endorsement policies

  1. Chaincode endorsement policies.
  • The policies agreed by channel members when they approve a chaincode definition for their organization.
  • If the chaincode function calls a function in another chaincode, then both policies will need to be satisfied.
  1. Private data collection endorsement policies.
  • If the chaincode function writes to a state in a private data collection, then the endorsement policy for that collection will override the chaincode policy for that state.
  • If the chaincode function reads from a private data collection, then it will be restricted to organizations that are members of that collection.
  1. State-based endorsement (SBE) policies.
  • Also known as key-level signature policies
  • these can be applied to individual states and will override the above both policies states.
  • The endorsement posaaalicies themselves are stored in the ledger and can be updated by new transactions.

The combination of endorsement policies are applied to the transaction proposal is determined at chaincode runtime.

How the gateway endorses transaction

  • To satisfy endorsement policy a sufficient number of endorsements are required.
  • Getting endorsement from any organization means
  1. Connect to its peer.
  2. Execute proposal against copy of ledger.
  3. Execution happens by calling chaincode as required in proposal.
  4. Builds R/W SET(read write)
  • R/W set contains two things
  1. Current state of ledger
  2. Changed state after proposal execution

Fabric gateway handle complexity on behalf of client

  • Fabric gateway selects endorsing peer from organization’s peer having highest ledger block height.
  • Transaction proposal executed by keeping info about
  1. Accessed state
  2. Endorsement policies to be applied
  • This captured policies are passed to discovery service through protobuf structure to derive endorsement plan for proposed transaction

  • To satisfy all endorsement policies fabric gateway apply endorsement plan by requesting endorsement from the peer in organization with highest block height.
  • Discovery service must always enabled on peers where gateway service enabled because discovery service gives
  1. connection details of the available peers and ordering service nodes
  2. calculation of combination of peers that are required to endorsement

The gateway endorsement process for private data 

  • The process is more restrictive for private data as transient data.
  • Because data might be sensitive and cannot be shared with all peers of organization.
  • In this case only restricted set of private data collection peers can access the data by satisfying endorsement policies otherwise gateway will return error to client without forwarding private data.
  • Then client application need to clearly define which organization can endorse the transaction.
  • This is like limiting pool of endorsement entity.

Now What if client specified set of organization does not satisfies an endorsement policy?

 Transaction endorsement happens => Transaction submitted to ordering node =>But Transaction get invalid in validation and commit phase =>Invalid transaction recorded on ledger but not updated on any state database of peer.

Fabric Gateway handles

  1. Node connectivity retry attempts
  2. Errors
  3. Timeouts

Retry Attempts

     The gateway uses discovery service information to retry any transaction which fails due to an unavailability of peer or ordering node.

Retry attempts tries every possible node of organization. If all peer of one organization fails then it select another organization.

This will continue until all possible combinations of endorsing peers have been tried once.

Error Handling

Gateway manages gRPC connection to n/w peer and ordering node.

If error originated from peer or ordering node its detail like Error, endpoint and organization information all comes in field “detail”.

This detail is provided by gateway to client application. If detail field is empty then error is generated at gateway peer.

Timeout

In the gateway section of peer i.e core.yaml config. File, the value of

{peer.gateway.enndorsementTimeout} is overridden to limit time that client need to wait for collective response of evaluate and endorsement.

Leave a Reply

Your email address will not be published. Required fields are marked *