Transaction Flow In Hyperledger Fabric v2.5

Pavan Adhav
Coinmonks
Published in
4 min readDec 13, 2023

--

Use Case:

Consider a scenario involving a contract agreement where three organizations are participants in a network. These organizations engage in agreement operations such as creating, updating, and renewing contracts. To facilitate these operations, they have established a Hyperledger Fabric network, with a channel serving as the communication medium. The organizations deploy business logic, represented by chain code or smart contracts, to execute these agreement operations. The established chaincode policy mandates that all organizations must endorse transactions.

It is assumed that the user has already registered and enrolled with the organization’s Certificate Authority (CA) and possesses the necessary private key, public key, and certificate. This article delineates the transaction flow during asset operations, with the asset in focus being an agreement. Sample agreement data is provided below.

{
"_id": "45511ecd-0446-4e1d-8dd4-4c1713bb41e0",
"_rev": "2-3f2b33e1f083d874c6faef7f2bb6c1c1",
"approvals": [
{
"action": "test",
"agreementId": "45511ecd-0446-4e1d-8dd4-4c1713bb41e0",
"comment": "test",
"createAt": "2023-12-07T06:00:27.069Z",
"createBy": "admin102@gmail.com",
"department": "legal",
"description": "test",
"docType": "approval",
"id": "a518bf54-41e0-4741-9119-a2dc486cf471",
"orgId": 1,
"status": "approved",
"updatedAt": "2023-12-07T06:00:27.069Z",
"updatedBy": "admin102@gmail.com"
}
],
"comments": [
"test"
],
"contract": "test",
"createAt": "2023-12-07T03:11:35.090Z",
"createBy": "admin102@gmail.com",
"department": "legal",
"docType": "agreement",
"document": {
"contentHash": "ff44e9c20a77d9195c71a868b705d7f059e91a8e",
"createAt": "2023-12-07T03:11:35.090Z",
"createBy": "admin102@gmail.com",
"id": "ff44e9c20a77d9195c71a868b705d7f059e91a8e-test pdf file.pdf",
"name": "test pdf file",
"orgName": "org1",
"updatedAt": "2023-12-07T03:11:35.090Z",
"updatedBy": "admin102@gmail.com",
"url": "https://e-agreements.s3.us-west-2.amazonaws.com/org1/ff44e9c20a77d9195c71a868b705d7f059e91a8e-test%20pdf%20file.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWKYUXK2DAENBPDCM%2F20231207%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20231207T060031Z&X-Amz-Expires=3600&X-Amz-Signature=aaa082f2fabeb0c7035b6323462cb30e237d74805c5b4fa0b36f55158d682c1e&X-Amz-SignedHeaders=host"
},
"endDate": 1703269800000,
"firstParty": "Org1",
"id": "45511ecd-0446-4e1d-8dd4-4c1713bb41e0",
"orgId": 1,
"owner": "org1",
"secondParty": "Org2",
"startDate": 1701369000000,
"status": "active",
"title": "test",
"typeOfContract": "test",
"updatedAt": "2023-12-07T03:11:35.090Z",
"updatedBy": "admin102@gmail.com",
"~version": "CgMBGAA="
}

When a user from organization 1 initiates a transaction, a signed proposal is generated at the API. This proposal includes both a signature and proposal byte. The signature is formed by utilizing a private key on a hash of the proposal data, as illustrated in the diagram below.

The signed proposal is transmitted to the designated peer within the same organization, for instance, peer0 in org1. Subsequently, the target peer forwards this transaction to other endorsing peers from different organizations. Before doing so, the target peer first verifies the number of endorsements needed for this transaction and ensures the operational status of the participating peers.

Endorsing Phase

When an endorsing peer receives a transaction proposal, it undergoes the following validations:

  1. Confirm that the transaction proposal is well-formed.
  2. Ensure that the proposal has not been previously submitted (providing protection against replay attacks).
  3. Validate the signature associated with the proposal.
  4. Verify that the submitter is duly authorized to execute the proposed operation on the specified channel.”
Signature validation

Endorsing peers utilize the transaction proposal inputs as parameters for the invoked chaincode function. Subsequently, the chaincode is executed against the current state database to generate transaction results, including a response value, read set, and write set. It is important to note that ledger updates do not occur at this stage. The combination of these values, accompanied by the endorsing peer’s signature, is transmitted as a ‘proposal response’ back to the target peer.

The target peer performs verification to ensure consistency among the proposal responses before advancing to the transaction submission phase. Subsequently, the target peer ‘broadcasts’ both the transaction proposal and response encapsulated within a ‘transaction message’ to the ordering service. This transaction message comprises the Channel ID, read/write sets, and a signature from each endorsing peer.

Ordering Phase

The ordering service does not necessitate a comprehensive examination of the entire transaction content to execute its function. Its role involves receiving transactions, arranging them in order, and forming blocks of transactions specific to each channel. Subsequently, the orderer transmits the block to the leader peer of the respective

Committing Phase

The transactions contained within the block undergo validation to verify compliance with the endorsement policy and to confirm that there have been no alterations to the ledger state for the variables in the read set since the transaction execution generated it. Each transaction within the block is labeled as either valid or invalid. Subsequently, each peer adds the block to the chain of the respective channel, and for every valid transaction, the write sets are committed to the current state database, whether it be CouchDB or LevelDB

I have just released a course on Full-stack development course with Hyperledger Fabric v2.5— Agreement Management. I have covered all core concepts, API, UI, and explorer integration with best practices. If you want to learn, enroll now: https://pavantechacademy.graphy.com/courses/Agreement-Management-using-Hyperledger-Fabric-v25Full-Stack-Application-657577ade4b063cb4155c7ac-657577ade4b063cb4155c7ac

Find the proposal flow below

If you have any doubts or issues, please contact me on Instagram or email

insta: Instagram: https://www.instagram.com/pavanadhavofficial/

email: adhavpavan@gmail.com

--

--