fabric chaincode 同一channel 與不同channel 間相互調用區別

新項目中需要進行chaincode開發工作。並且可能需要chaincode 間互相調用的操作。這裏記錄一下我的調研過程。

首先問題

1:chaincode 間是否可以互相調用,是從fabric 哪個版本開始支持,最新版是否支持?

2:chaincode 間互相調用的邊界?如,是否支持不同channel 間的chaincode調用?還是隻支持同一channel 裏的chaincode 調用?

3:chaincode 間的調用是否支持寫操作?

 

基於以上三個問題,開始探索之路。

首先利用百度,檢索chaincode 間調用的博客。發現還是有很多的文章,這裏放一些我看的文章地址:

https://blog.csdn.net/xiaohuanglv/article/details/89033472

通過上面一個文章我們可以發現幾乎已經回答了我們所有的問題。1:chaincode 間可以相互調用,筆者當前使用的是fabric1.4 TLS(版本),支持chaincode 間相互調用。2:chaincode 支持不同channel 間與同一channel 間的相互調用。3:不同chaincode 間的相互調用不能執行寫操作。同一chaincode 間的調用支持寫操作。(也就是會修改最終的狀態數據庫,我還是喜歡叫世界狀態)

接着我們需要查看fabric 官方文章的介紹。

官方文章筆者沒有找到,對invokechaincode 的內容介紹。暫不說明

最後就是我們實際操作,以及源碼研究了。

先簡單曝一下InvokeChaincode 接口的介紹,接口文件在fabric/core/chaincode/shim/interface.go

    // InvokeChaincode locally calls the specified chaincode `Invoke` using the
	// same transaction context; that is, chaincode calling chaincode doesn't
	// create a new transaction message.
	// If the called chaincode is on the same channel, it simply adds the called
	// chaincode read set and write set to the calling transaction.
	// If the called chaincode is on a different channel,
	// only the Response is returned to the calling chaincode; any PutState calls
	// from the called chaincode will not have any effect on the ledger; that is,
	// the called chaincode on a different channel will not have its read set
	// and write set applied to the transaction. Only the calling chaincode's
	// read set and write set will be applied to the transaction. Effectively
	// the called chaincode on a different channel is a `Query`, which does not
	// participate in state validation checks in subsequent commit phase.
	// If `channel` is empty, the caller's channel is assumed.

/*
我是翻譯:
InvokeChaincode使用相同的事務上下文在本地調用指定的chaincode“Invoke”;也就是說,
調用chaincode不會創建新的事務消息。如果調用的chaincode在相同的通道上,它只需將調用的chaincode讀集和寫集添加到調用事務中。
如果被調用的鏈碼位於不同的通道上,則只向調用的鏈碼返回響應;任何來自被調用鏈碼的PutState調用都不會對分類帳產生任何影響;也就是說,
在不同的通道上調用的chaincode不會將其讀集和寫集應用於事務。只有調用鏈碼的讀集和寫集將應用於事務。實際上,
不同通道上被調用的chaincode是一個“查詢”,它不參與後續提交階段的狀態驗證檢查。如果“channel”爲空,則假定調用方的channel爲空。
*/
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章