区块链技术问询:所有Peer节点是否均执行Chaincode?
Great question — this is a super common point of confusion, especially when working with frameworks like Hyperledger Fabric where endorsement nodes play a key role. Let’s break it down step by step:
1. 交易提案阶段:仅背书节点执行Chaincode
When a client wants to initiate a transaction (like a transfer or data update), it sends a transaction proposal only to the endorsement nodes defined in the channel’s endorsement policy. These are the only peers that will execute the Chaincode at this stage.
What happens here:
- The endorsement nodes run the Chaincode logic against their local copy of the ledger state.
- They generate a read-write set (the data that would be changed if the transaction is approved) and sign this result as an endorsement.
- The signed response is sent back to the client, who then collects enough valid endorsements (as per the policy) before submitting the transaction for ordering.
2. 交易验证与提交阶段:所有Peer验证,但不执行Chaincode逻辑
Once the client submits the endorsed transaction to the ordering service, the service sorts transactions into blocks and distributes them to all Peer nodes in the channel.
Here’s what non-endorsement peers do:
- They don’t re-run the Chaincode to generate new read-write sets. Instead, they validate the transaction:
- Check that the number and identities of endorsements match the channel’s policy.
- Verify that the read-write set doesn’t conflict with the current local ledger state (to prevent double-spending or stale data issues).
- If validation passes, the peer applies the read-write set to its local ledger state and appends the block to its copy of the blockchain.
例外情况:Peer节点同步账本
If a new peer joins the network later, it will sync the full ledger from existing peers. This process also doesn’t involve executing Chaincode — it just copies blocks and applies the pre-computed state updates from those blocks.
总结
To put it simply:
- Only endorsement nodes execute Chaincode (during the transaction proposal phase, to generate valid endorsements and read-write sets).
- All other peers only validate the transaction’s legitimacy and apply the pre-approved state changes — they don’t run the Chaincode’s business logic.
内容的提问来源于stack exchange,提问作者T_murder

