链码是否仅需安装在背书节点?非背书节点账本更新逻辑疑问
Understanding Hyperledger Fabric: Non-Endorsing Nodes & Ledger Updates
Great question—this is a super common point of confusion when getting to grips with Fabric's node roles! Let's break down exactly how non-endorsing nodes handle ledger updates without running chaincode.
First: Who Generates the Read-Write Set?
Short answer: Only endorsing nodes generate read-write sets—non-endorsing nodes never need to do this. Here's the full flow:
- A client submits a transaction proposal to the required endorsing nodes (defined by the channel's endorsement policy).
- Each endorsing node runs the chaincode locally, executes the business logic, and generates a read-write set (this includes which keys were read, their current versions, and which keys will be written with new values).
- Endorsing nodes sign the read-write set and send it back to the client.
- The client collects enough valid endorsements, then packages the read-write set + signatures into a complete transaction and sends it to the ordering service.
How Do Non-Endorsing Nodes Update the Ledger?
Non-endorsing nodes don't need to understand chaincode logic—their job is to validate transactions and apply pre-generated read-write sets to their local ledger. Here's what happens:
- The ordering service sorts transactions into blocks and distributes them to all nodes in the channel (including non-endorsing ones).
- For each transaction in the block, the non-endorsing node performs two key checks:
- Endorsement validation: Does the transaction have enough valid signatures from endorsing nodes that meet the channel's policy?
- MVCC (Multi-Version Concurrency Control) check: Do the read versions in the read-write set match the current versions of those keys in the node's local ledger? This ensures no conflicting transactions were committed since the proposal was endorsed.
- If both checks pass, the node applies the read-write set directly to its ledger: it writes the new values for the specified keys, and updates the version numbers. It doesn't need to run any chaincode—it just executes the "write" instructions from the pre-validated read-write set.
Example to Make It Concrete
Let's say you have a chaincode that handles asset transfers:
- A client sends a proposal to transfer 100 tokens from User A to User B.
- Endorsing nodes run the chaincode, verify User A has enough tokens, and generate a read-write set:
- Read: User A's balance (version 2, value 500)
- Write: User A's balance (version 3, value 400); User B's balance (version 1, value 100)
- The client collects endorsements, sends the transaction to ordering, which distributes it to all nodes.
- A non-endorsing node checks that the endorsements are valid, confirms User A's balance is still at version 2 locally, then applies the write operations to update both users' balances. It never runs the chaincode—it just trusts that the endorsing nodes already validated the business logic, and only checks for consistency and proper authorization.
内容的提问来源于stack exchange,提问作者user9040429
相关产品推荐
相关产品推荐

