Browse Source

Merge branch 'develop' into release/1.1.2.RELEASE

tags/1.1.2^2
zhangshuang 4 years ago
parent
commit
b35a8b1997
6 changed files with 43 additions and 10 deletions
  1. +15
    -10
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java
  2. +7
    -0
      source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/service/MessageHandle.java
  3. +2
    -0
      source/deployment/deployment-gateway/src/main/resources/assembly.xml
  4. +2
    -0
      source/deployment/deployment-peer/src/main/resources/assembly.xml
  5. +4
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java
  6. +13
    -0
      source/peer/src/main/java/com/jd/blockchain/peer/consensus/ConsensusMessageDispatcher.java

+ 15
- 10
source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java View File

@@ -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<byte[]> 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<byte[]> updateAppResponses(List<byte[]> asyncResponseLinkedList) {
public List<byte[]> updateAppResponses(List<byte[]> asyncResponseLinkedList, byte[] commonHash, boolean isConsistent) {
List<byte[]> 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


+ 7
- 0
source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/service/MessageHandle.java View File

@@ -67,4 +67,11 @@ public interface MessageHandle {
*/
StateSnapshot getStateSnapshot(String realmName);

/**
* 获得创世区块的状态快照
* @param realmName
* @return 创世区块的状态快照
*/
StateSnapshot getGenisStateSnapshot(String realmName);

}

+ 2
- 0
source/deployment/deployment-gateway/src/main/resources/assembly.xml View File

@@ -17,10 +17,12 @@
<fileSet>
<directory>src/main/resources/config</directory>
<outputDirectory>config</outputDirectory>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/resources/docs</directory>
<outputDirectory>docs</outputDirectory>
<lineEnding>unix</lineEnding>
</fileSet>
</fileSets>
<dependencySets>


+ 2
- 0
source/deployment/deployment-peer/src/main/resources/assembly.xml View File

@@ -17,10 +17,12 @@
<fileSet>
<directory>src/main/resources/config</directory>
<outputDirectory>config</outputDirectory>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>src/main/resources/docs</directory>
<outputDirectory>docs</outputDirectory>
<lineEnding>unix</lineEnding>
</fileSet>
</fileSets>
<dependencySets>


+ 4
- 0
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java View File

@@ -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();
}


+ 13
- 0
source/peer/src/main/java/com/jd/blockchain/peer/consensus/ConsensusMessageDispatcher.java View File

@@ -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<byte[]> 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<byte[]> schedule(TransactionRequest txRequest) {
CompletableAsyncFuture<byte[]> asyncTxResult = new CompletableAsyncFuture<>();
TransactionResponse resp = getTxBatchProcess().schedule(txRequest);


Loading…
Cancel
Save