From e6604b489f5b64801f8bf3f1699340ebd2d6de98 Mon Sep 17 00:00:00 2001 From: zhaoguangwei Date: Wed, 11 Dec 2019 10:54:59 +0800 Subject: [PATCH 1/5] add lineEnding:unix --- .../deployment-gateway/src/main/resources/assembly.xml | 3 +++ .../deployment/deployment-peer/src/main/resources/assembly.xml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/source/deployment/deployment-gateway/src/main/resources/assembly.xml b/source/deployment/deployment-gateway/src/main/resources/assembly.xml index 39811c14..861990d0 100644 --- a/source/deployment/deployment-gateway/src/main/resources/assembly.xml +++ b/source/deployment/deployment-gateway/src/main/resources/assembly.xml @@ -12,14 +12,17 @@ src/main/resources/scripts bin + unix src/main/resources/config config + unix src/main/resources/docs docs + unix diff --git a/source/deployment/deployment-peer/src/main/resources/assembly.xml b/source/deployment/deployment-peer/src/main/resources/assembly.xml index 881c0aef..37aa494c 100644 --- a/source/deployment/deployment-peer/src/main/resources/assembly.xml +++ b/source/deployment/deployment-peer/src/main/resources/assembly.xml @@ -12,14 +12,17 @@ src/main/resources/scripts bin + unix src/main/resources/config config + unix src/main/resources/docs docs + unix From 46c63a021fd867a4d349680e18e4b57e000eabe0 Mon Sep 17 00:00:00 2001 From: zhaoguangwei Date: Thu, 12 Dec 2019 10:58:33 +0800 Subject: [PATCH 2/5] not use the oss-parent node in the central library publishing. fill some info related in the proifle and distributionManagement node; --- source/pom.xml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/source/pom.xml b/source/pom.xml index 5b9d0c10..259eb4dc 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -515,7 +515,63 @@ -Xdoclint:none + + + + sonatype-oss-release + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.7 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.1 + + + sign-artifacts + verify + + sign + + + + + + + + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + From 00a02efc95c8c67e7c11264f5eb2d0f28159c39c Mon Sep 17 00:00:00 2001 From: zhaoguangwei Date: Thu, 12 Dec 2019 18:36:08 +0800 Subject: [PATCH 3/5] add the param: jdchain.log --- .../blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java | 1 + 1 file changed, 1 insertion(+) diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java index ec77fbee..1ccf994c 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java @@ -53,6 +53,7 @@ public class LedgerInitializeWeb4Nodes { System.setProperty("peer.log", path); System.setProperty("init.log", path); System.setProperty("gateway.log", path); + System.setProperty("jdchain.log", path); } catch (Exception e) { e.printStackTrace(); } From 2d16188e443eb27549e2657c293228f2ffb55bcd Mon Sep 17 00:00:00 2001 From: zhaoguangwei Date: Thu, 12 Dec 2019 19:17:09 +0800 Subject: [PATCH 4/5] add the interface: 6.9 /ledgers/{ledger}/accounts/address/{address}/keys/count/search?keyword={keyword} 6.10 /ledgers/{ledger}/accounts/address/{address}/keys/search?keyword={keyword}&fromIndex={start_index}&count={count} --- .../src/main/resources/docs/api_doc_cn_1.4.MD | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD b/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD index 7ff79c96..3a02ce4c 100644 --- a/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD +++ b/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD @@ -1808,6 +1808,57 @@ http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/ |type|value类型| |value|值| +### 6.9 查询某数据账户键数量 +``` +GET /ledgers/{ledger}/accounts/address/{address}/keys/count/search?keyword={keyword} +``` +#### 参数 +请求类型 | 名称 | 是否必需 | 说明 | 数据类型 +--- | --- | --- | --- | --- +path | ledger | 是 | 所要搜索的账本,需要完整的账本哈希 | string +path | address | 是 | 所要搜索的数据账户地址,需要完整的数据账户地址 | string +query | keyword | 否 | 键的部分字符,空表示全部 | string + +#### 请求实例 +``` +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/address/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa/keys/count/search?keyword=j +``` +#### 返回实例 +``` +{ "data": 66, "success": true } +``` +说明 + +名称 | 说明 +--- | --- +data | 条件查询键总数 + +### 6.10 查询某数据账户键 +``` +GET /ledgers/{ledger}/accounts/address/{address}/keys/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` +#### 参数 +请求类型 | 名称 | 是否必需 | 说明 | 数据类型 +--- | --- | --- | --- | --- +path | ledger | 是 | 所要搜索的账本,需要完整的账本哈希 | string +path | address | 是 | 所要搜索的数据账户地址,需要完整的数据账户地址 | string +query | keyword | 否 | 键的部分字符,空表示全部 | string +query | start_index | 否 | 查询数据账户对应Key的起始序号,默认为0 | 数字 +query | count | 否 | 查询返回数据账户对应Key的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集 | 数字 + +#### 请求实例 +``` +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/address/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa/keys/search?keyword=j&fromIndex=0&count=-1 +``` +#### 返回实例 +``` +{ "data": [ { "key": "jd" }, { "key": "jdchain" }], "success": true } +``` +说明 + +名称 | 说明 +--- | --- +key | 键 ## 7 搜索 From e622a7b24748398798aef0813e75d793004b3adb Mon Sep 17 00:00:00 2001 From: zhangshuang Date: Sat, 14 Dec 2019 21:27:40 +0800 Subject: [PATCH 5/5] when most of block hash is inconsistent, less than Quorum consistent responses, will return null response --- .../bftsmart/service/BftsmartNodeServer.java | 25 +++++++++++-------- .../consensus/service/MessageHandle.java | 7 ++++++ .../core/TransactionBatchProcessor.java | 4 +++ .../consensus/ConsensusMessageDispatcher.java | 13 ++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java index aa62da01..61a6a619 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java @@ -10,6 +10,7 @@ import bftsmart.consensus.app.BatchAppResultImpl; import bftsmart.tom.*; import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.consensus.service.*; +import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.*; import com.jd.blockchain.transaction.TxResponseMessage; import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils; @@ -363,6 +364,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer List responseLinkedList = new ArrayList<>(); StateSnapshot newStateSnapshot = null; StateSnapshot preStateSnapshot = null; + StateSnapshot genisStateSnapshot = null; BatchAppResultImpl result = null; String batchId = null; int msgId = 0; @@ -370,7 +372,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer try { batchId = messageHandle.beginBatch(realmName); - + genisStateSnapshot = messageHandle.getGenisStateSnapshot(realmName); preStateSnapshot = messageHandle.getStateSnapshot(realmName); if (preStateSnapshot == null) { @@ -388,7 +390,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer responseLinkedList.add(asyncFutureLinkedList.get(i).get()); } - result = new BatchAppResultImpl(responseLinkedList, newStateSnapshot.getSnapshot(), batchId); + result = new BatchAppResultImpl(responseLinkedList, newStateSnapshot.getSnapshot(), batchId, genisStateSnapshot.getSnapshot()); result.setErrorCode((byte) 0); } catch (Exception e) { @@ -397,7 +399,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer responseLinkedList.add(createAppResponse(commands[i],TransactionState.IGNORED_BY_BLOCK_FULL_ROLLBACK)); } - result = new BatchAppResultImpl(responseLinkedList,preStateSnapshot.getSnapshot(), batchId); + result = new BatchAppResultImpl(responseLinkedList,preStateSnapshot.getSnapshot(), batchId, genisStateSnapshot.getSnapshot()); result.setErrorCode((byte) 1); } @@ -415,20 +417,23 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer return BinaryProtocol.encode(resp, TransactionResponse.class); } - //update batch messages to block full rollback state - public List updateAppResponses(List asyncResponseLinkedList) { + public List updateAppResponses(List asyncResponseLinkedList, byte[] commonHash, boolean isConsistent) { List updatedResponses = new ArrayList<>(); + TxResponseMessage resp = null; for(int i = 0; i < asyncResponseLinkedList.size(); i++) { TransactionResponse txResponse = BinaryProtocol.decode(asyncResponseLinkedList.get(i)); - TxResponseMessage resp = new TxResponseMessage(txResponse.getContentHash()); + if (isConsistent) { + resp = new TxResponseMessage(txResponse.getContentHash()); + } + else { + resp = new TxResponseMessage(new HashDigest(commonHash)); + } resp.setExecutionState(TransactionState.IGNORED_BY_BLOCK_FULL_ROLLBACK); updatedResponses.add(BinaryProtocol.encode(resp, TransactionResponse.class)); - } - - return updatedResponses; } - + return updatedResponses; +} /** * * Decision has been made at the consensus stage, commit block diff --git a/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/service/MessageHandle.java b/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/service/MessageHandle.java index 1acb44c4..e864d2d0 100644 --- a/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/service/MessageHandle.java +++ b/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/service/MessageHandle.java @@ -67,4 +67,11 @@ public interface MessageHandle { */ StateSnapshot getStateSnapshot(String realmName); + /** + * 获得创世区块的状态快照 + * @param realmName + * @return 创世区块的状态快照 + */ + StateSnapshot getGenisStateSnapshot(String realmName); + } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java index be733dbf..e2f42050 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java @@ -43,6 +43,10 @@ public class TransactionBatchProcessor implements TransactionBatchProcess { return ledger.getLatestBlockHash().toBytes(); } + public byte[] getGenisBlockHash() { + return ledger.getBlockHash(0).toBytes(); + } + public long getPreLatestBlockHeight() { return ledger.getLatestBlockHeight(); } diff --git a/source/peer/src/main/java/com/jd/blockchain/peer/consensus/ConsensusMessageDispatcher.java b/source/peer/src/main/java/com/jd/blockchain/peer/consensus/ConsensusMessageDispatcher.java index fb123b99..6b8967f6 100644 --- a/source/peer/src/main/java/com/jd/blockchain/peer/consensus/ConsensusMessageDispatcher.java +++ b/source/peer/src/main/java/com/jd/blockchain/peer/consensus/ConsensusMessageDispatcher.java @@ -75,6 +75,15 @@ public class ConsensusMessageDispatcher implements MessageHandle { } + @Override + public StateSnapshot getGenisStateSnapshot(String realmName) { + RealmProcessor realmProcessor = realmProcessorMap.get(realmName); + if (realmProcessor == null) { + throw new IllegalArgumentException("RealmName is not init!"); + } + return realmProcessor.getGenisStateSnapshot(); + } + @Override public AsyncFuture processOrdered(int messageId, byte[] message, String realmName, String batchId) { // TODO 要求messageId在同一个批次不重复,但目前暂不验证 @@ -209,6 +218,10 @@ public class ConsensusMessageDispatcher implements MessageHandle { return new BlockStateSnapshot(((TransactionBatchProcessor)getTxBatchProcess()).getPreLatestBlockHeight(), ((TransactionBatchProcessor)getTxBatchProcess()).getPrevLatestBlockHash()); } + public StateSnapshot getGenisStateSnapshot() { + return new BlockStateSnapshot(0, ((TransactionBatchProcessor)getTxBatchProcess()).getGenisBlockHash()); + } + public AsyncFuture schedule(TransactionRequest txRequest) { CompletableAsyncFuture asyncTxResult = new CompletableAsyncFuture<>(); TransactionResponse resp = getTxBatchProcess().schedule(txRequest);