您好,登錄后才能下訂單哦!
今天小編給大家分享一下java開源區(qū)塊鏈jdchain怎么部署的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
jdchain是京東數(shù)科開源的區(qū)塊鏈平臺(tái),目標(biāo)是實(shí)現(xiàn)一個(gè)面向企業(yè)應(yīng)用場(chǎng)景的通用區(qū)塊鏈框架系統(tǒng),能夠作為企業(yè)級(jí)基礎(chǔ)設(shè)施,為業(yè)務(wù)創(chuàng)新提供高效、靈活和安全的解決方案。
之所以選擇jdchain研究是因?yàn)閖dchain是為數(shù)不多的底層也是采用java實(shí)現(xiàn)的一個(gè)區(qū)塊鏈平臺(tái)
peer:區(qū)塊鏈主節(jié)點(diǎn),參與共識(shí)、賬本操作等
gateway:與Peer節(jié)點(diǎn)通信,負(fù)責(zé)區(qū)塊鏈瀏覽器及消息傳遞
客戶端:采用SDK和網(wǎng)關(guān)鏈接,通過網(wǎng)關(guān)發(fā)起交易
有兩種途徑可以拿到部署包,一、直接從官網(wǎng)下載.二、從github上拉源碼,然后自己構(gòu)建,在deployment目錄下會(huì)生成部署包,自己構(gòu)建的需要注意,如果是在Windows系統(tǒng)上構(gòu)建的包,包里的啟動(dòng)腳本在linux系統(tǒng)下運(yùn)行會(huì)有轉(zhuǎn)義字符的問題,需要在assembly.xml里設(shè)置lineEnding為unix
區(qū)塊鏈部署工具
區(qū)塊鏈瀏覽器
官方文檔算比較詳細(xì),但是很多細(xì)節(jié)沒有寫明,一般體驗(yàn)和開發(fā)時(shí)部署的環(huán)境比較簡(jiǎn)單,可能在一個(gè)主機(jī)上部署4個(gè)節(jié)點(diǎn)的peer。這個(gè)時(shí)候端口的編排要非常注意,因?yàn)閖dchain目前的共識(shí)算法采用的開源的bftsmart實(shí)現(xiàn),共識(shí)端口在同一臺(tái)主機(jī)上不能連續(xù),不然就會(huì)端口沖突。博主就遇到了這個(gè)問題,下面是詳細(xì)排錯(cuò)過程:采用SDK創(chuàng)建用戶時(shí)拋如下異常,網(wǎng)關(guān)可以正常連接,秘鑰認(rèn)證沒有問題:
Caused by: java.lang.IndexOutOfBoundsException: The accessing index is out of BytesSlice's bounds! at com.jd.blockchain.utils.io.BytesSlice.checkBoundary(BytesSlice.java:174) at com.jd.blockchain.utils.io.BytesSlice.getInt(BytesSlice.java:97) at com.jd.blockchain.utils.io.BytesSlice.getInt(BytesSlice.java:86) at com.jd.blockchain.binaryproto.impl.HeaderEncoder.resolveCode(HeaderEncoder.java:71) at com.jd.blockchain.binaryproto.BinaryProtocol.decode(BinaryProtocol.java:41) at com.jd.blockchain.sdk.converters.BinarySerializeResponseConverter.getResponse(BinarySerializeResponseConverter.java:33) at com.jd.blockchain.utils.http.agent.HttpServiceAgent.invoke(HttpServiceAgent.java:587) ... 7 more
11:57:05.537 ERROR com.jd.blockchain.gateway.web.GatewayGlobalExceptionHandler 34 json - Unexpected exception occurred! --[RequestURL=[POST] http://192.168.1.190:8081/rpc/tx][class java.lang.IllegalStateException]Returned object not currently part of this pool java.lang.IllegalStateException: Returned object not currently part of this pool at org.apache.commons.pool2.impl.GenericObjectPool.returnObject(GenericObjectPool.java:530) ~[commons-pool2-2.5.0.jar!/:2.5.0] at com.jd.blockchain.consensus.bftsmart.client.BftsmartMessageService.sendOrderedMessage(BftsmartMessageService.java:46) ~[consensus-bftsmart-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] at com.jd.blockchain.consensus.bftsmart.client.BftsmartMessageService.sendOrdered(BftsmartMessageService.java:22) ~[consensus-bftsmart-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] at com.jd.blockchain.sdk.service.NodeSigningAppender.process(NodeSigningAppender.java:84) ~[sdk-base-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] at com.jd.blockchain.sdk.service.PeerServiceProxy.process(PeerServiceProxy.java:89) ~[sdk-base-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] at com.jd.blockchain.gateway.web.TxProcessingController.process(TxProcessingController.java:70) ~[gateway-1.1.1.RELEASE.jar!/:1.1.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_231] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_231] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_231]
最終查明異常是由于網(wǎng)關(guān)里創(chuàng)建AsynchServiceProxy失敗導(dǎo)致的,這部分實(shí)現(xiàn)采用了Apache-commons-pool2。實(shí)現(xiàn)如下:
public class BftsmartPeerProxyFactory extends BasePooledObjectFactory{ private BftsmartClientSettings bftsmartClientSettings; private int gatewayId; private AtomicInteger index = new AtomicInteger(1); public BftsmartPeerProxyFactory(BftsmartClientSettings bftsmartClientSettings, int gatewayId) { this.bftsmartClientSettings = bftsmartClientSettings; this.gatewayId = gatewayId; } @Override public AsynchServiceProxy create() throws Exception { BftsmartTopology topology = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology()); MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(topology.getView()); TOMConfiguration tomConfiguration = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTomConfig()); //every proxy client has unique id; tomConfiguration.setProcessId(gatewayId + index.getAndIncrement()); AsynchServiceProxy peerProxy = new AsynchServiceProxy(tomConfiguration, viewStorage); return peerProxy; } @Override public PooledObjectwrap(AsynchServiceProxy asynchServiceProxy) { return new DefaultPooledObject<>(asynchServiceProxy); } }
這個(gè)代碼BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology())返回的是null,沒有正確拿到Bftsmart的網(wǎng)絡(luò)拓?fù)洹_M(jìn)而查看peer節(jié)點(diǎn),發(fā)現(xiàn)只有節(jié)點(diǎn)0成功了,其他都拋如下異常,初步判斷bftsmart的副本服務(wù)因?yàn)槎丝谡加脝?dòng)失敗了:
11:36:48.479 ERROR bftsmart.tom.ServiceReplica 247 init - null java.net.BindException: 地址已在使用 at sun.nio.ch.Net.bind0(Native Method) ~[?:1.8.0_231] at sun.nio.ch.Net.bind(Net.java:433) ~[?:1.8.0_231] at sun.nio.ch.Net.bind(Net.java:425) ~[?:1.8.0_231] at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:1.8.0_231] at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:130) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1358) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1019) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:446) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-all-4.1.29.Final.jar:4.1.29.Final] at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_231]
從bftsmart官方文檔得知,如果在同一個(gè)主機(jī)運(yùn)行,不能使用順序的端口號(hào),即一開始編排的peer的共識(shí)端口,6000、6001、6002、6003是不行的,原因如下:如果在同一臺(tái)計(jì)算機(jī)(127.0.0.1)中部署/執(zhí)行了某些(或全部)副本,config/hosts.config則不能具有順序的端口號(hào)(例如10000、10001、10002、10003)。這是因?yàn)槊總€(gè)副本都綁定了兩個(gè)端口:一個(gè)用于接收來自客戶端的消息,另一個(gè)用于接收來自其他副本的消息(通過獲取下一個(gè)端口號(hào)選擇) 。更一般而言,如果為副本R分配了端口號(hào)P,它將嘗試將端口P(綁定到接收到的客戶端請(qǐng)求)和端口P + 1(綁定到其他副本)進(jìn)行綁定。如果不執(zhí)行此準(zhǔn)則,則副本可能無法綁定所有需要的端口。
以上就是“java開源區(qū)塊鏈jdchain怎么部署”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。