Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
* master:
  fixed bugs of missing the main method of peer booter;
  made the crypto-providers of ledger configurable;
  extracted the  default state const of participant;
  refactored DataAccountKVSetOperationBuilder;
  fixed bugs of event account and test case of MerkleHashTrie ;
  fix negative additional count
  fix null value in algorithms
  • Loading branch information
huanghaiquan committed Apr 7, 2021
2 parents 7471511 + a7b8238 commit 98388a3
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ public long getAdditionalTransactionCount(@PathVariable(name = "ledgerHash") Has
if (blockHeight == GENESIS_BLOCK_HEIGHT) {
return currentBlockTxCount;
}
if(currentBlockTxCount == 0) {
return 0;
}
long lastBlockHeight = blockHeight - 1;
long lastBlockTxCount = peerService.getQueryService(ledgerHash).getTransactionCount(ledgerHash,
lastBlockHeight);
Expand All @@ -556,6 +559,9 @@ public long getAdditionalTransactionCount(@PathVariable(name = "ledgerHash") Has
if (currentBlock.getHeight() == GENESIS_BLOCK_HEIGHT) {
return currentBlockTxCount;
}
if(currentBlockTxCount == 0) {
return 0;
}
HashDigest previousHash = currentBlock.getPreviousHash();
long lastBlockTxCount = peerService.getQueryService(ledgerHash).getTransactionCount(ledgerHash, previousHash);
// 当前区块交易数减上个区块交易数
Expand All @@ -572,6 +578,9 @@ public long getAdditionalTransactionCount(@PathVariable(name = "ledgerHash") Has
if (maxBlockHeight == GENESIS_BLOCK_HEIGHT) { // 只有一个创世区块
return totalCount;
}
if(totalCount == 0) {
return 0;
}
long lastTotalCount = peerService.getQueryService(ledgerHash).getTransactionCount(ledgerHash,
maxBlockHeight - 1);
return totalCount - lastTotalCount;
Expand All @@ -586,6 +595,9 @@ public long getAdditionalDataAccountCount(@PathVariable(name = "ledgerHash") Has
if (blockHeight == GENESIS_BLOCK_HEIGHT) {
return currentDaCount;
}
if(currentDaCount == 0) {
return 0;
}
long lastBlockHeight = blockHeight - 1;
long lastDaCount = peerService.getQueryService(ledgerHash).getDataAccountCount(ledgerHash, lastBlockHeight);
return currentDaCount - lastDaCount;
Expand All @@ -601,6 +613,9 @@ public long getAdditionalDataAccountCount(@PathVariable(name = "ledgerHash") Has
if (currentBlock.getHeight() == GENESIS_BLOCK_HEIGHT) {
return currentBlockDaCount;
}
if(currentBlockDaCount == 0) {
return 0;
}
HashDigest previousHash = currentBlock.getPreviousHash();
long lastBlockDaCount = peerService.getQueryService(ledgerHash).getDataAccountCount(ledgerHash, previousHash);
// 当前区块数据账户数量减上个区块数据账户数量
Expand All @@ -617,6 +632,9 @@ public long getAdditionalDataAccountCount(@PathVariable(name = "ledgerHash") Has
if (maxBlockHeight == GENESIS_BLOCK_HEIGHT) { // 只有一个创世区块
return totalCount;
}
if(totalCount == 0) {
return 0;
}
long lastTotalCount = peerService.getQueryService(ledgerHash).getDataAccountCount(ledgerHash,
maxBlockHeight - 1);
return totalCount - lastTotalCount;
Expand All @@ -631,6 +649,9 @@ public long getAdditionalUserCount(@PathVariable(name = "ledgerHash") HashDigest
if (blockHeight == GENESIS_BLOCK_HEIGHT) {
return currentUserCount;
}
if(currentUserCount == 0) {
return 0;
}
long lastBlockHeight = blockHeight - 1;
long lastUserCount = peerService.getQueryService(ledgerHash).getUserCount(ledgerHash, lastBlockHeight);
return currentUserCount - lastUserCount;
Expand All @@ -646,6 +667,9 @@ public long getAdditionalUserCount(@PathVariable(name = "ledgerHash") HashDigest
if (currentBlock.getHeight() == GENESIS_BLOCK_HEIGHT) {
return currentBlockUserCount;
}
if(currentBlockUserCount == 0) {
return 0;
}
HashDigest previousHash = currentBlock.getPreviousHash();
long lastBlockUserCount = peerService.getQueryService(ledgerHash).getUserCount(ledgerHash, previousHash);
// 当前区块用户数量减上个区块用户数量
Expand All @@ -662,6 +686,9 @@ public long getAdditionalUserCount(@PathVariable(name = "ledgerHash") HashDigest
if (maxBlockHeight == GENESIS_BLOCK_HEIGHT) { // 只有一个创世区块
return totalCount;
}
if(totalCount == 0) {
return 0;
}
long lastTotalCount = peerService.getQueryService(ledgerHash).getUserCount(ledgerHash, maxBlockHeight - 1);
return totalCount - lastTotalCount;
}
Expand All @@ -675,6 +702,9 @@ public long getAdditionalContractCount(@PathVariable(name = "ledgerHash") HashDi
if (blockHeight == GENESIS_BLOCK_HEIGHT) {
return currentContractCount;
}
if(currentContractCount == 0) {
return 0;
}
long lastBlockHeight = blockHeight - 1;
long lastContractCount = peerService.getQueryService(ledgerHash).getContractCount(ledgerHash, lastBlockHeight);
return currentContractCount - lastContractCount;
Expand All @@ -691,6 +721,9 @@ public long getAdditionalContractCount(@PathVariable(name = "ledgerHash") HashDi
if (currentBlock.getHeight() == GENESIS_BLOCK_HEIGHT) {
return currentBlockContractCount;
}
if(currentBlockContractCount == 0) {
return 0;
}
HashDigest previousHash = currentBlock.getPreviousHash();
long lastBlockContractCount = peerService.getQueryService(ledgerHash).getContractCount(ledgerHash,
previousHash);
Expand All @@ -708,6 +741,9 @@ public long getAdditionalContractCount(@PathVariable(name = "ledgerHash") HashDi
if (maxBlockHeight == GENESIS_BLOCK_HEIGHT) { // 只有一个创世区块
return totalCount;
}
if(totalCount == 0) {
return 0;
}
long lastTotalCount = peerService.getQueryService(ledgerHash).getContractCount(ledgerHash, maxBlockHeight - 1);
return totalCount - lastTotalCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public EventPublishingAccount getAccount(Bytes address) {

@Override
public EventPublishingAccount getAccount(Bytes address, long version) {
CompositeAccount account = accountSet.getAccount(address);
CompositeAccount account = accountSet.getAccount(address, version);
if (null == account) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ public DataAccountKVSetOperationExecBuilder(Bytes accountAddress) {
public DataAccountKVSetOperation getOperation() {
return op;
}

@Override
public DataAccountKVSetOperationBuilder set(String key, BytesValue value, long expVersion) {
this.op = new SingleKVSetOpTemplate(key, value, expVersion);
handle(op);
return this;
}

@Override
public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void doProcess(ParticipantRegisterOperation op, LedgerTransactionConte

ParticipantNode participantNode = new PartNode((int) (adminAccountDataSet.getParticipantCount()),
participantRegOp.getParticipantName(), participantRegOp.getParticipantID().getPubKey(),
ParticipantNodeState.READY);
ParticipantRegisterOperation.DEFAULT_STATE);

// add new participant
adminAccountDataSet.addParticipant(participantNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void copyCryptoProviders(CryptoProvider[] cps) {
}
CryptoAlgorithmInfo[] cryptoAlgorithmInfos = new CryptoAlgorithmInfo[cpAlgorithms.length];
for (int j = 0; j < cpAlgorithms.length; j++) {
cryptoAlgorithmInfos[i] = new CryptoAlgorithmInfo(cpAlgorithms[i]);
cryptoAlgorithmInfos[j] = new CryptoAlgorithmInfo(cpAlgorithms[j]);
}
CryptoProviderInfo cryptoProviderInfo = new CryptoProviderInfo(cp.getName(), cryptoAlgorithmInfos);
supportedProviders[i] = cryptoProviderInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.jd.binaryproto.BinaryProtocol;
import com.jd.binaryproto.DataContractEncoder;
import com.jd.binaryproto.DataContractRegistry;
import com.jd.binaryproto.DataSpecification;
import com.jd.binaryproto.impl.DataContractContext;
import com.jd.blockchain.consts.DataCodes;
Expand Down Expand Up @@ -199,7 +200,7 @@ private void testMerkleDataSerialize(MerkleTrieData data) {

assertEquals(expectedSize, dataBytes.length);

DataContractEncoder dataContractEncoder = DataContractContext.resolve(MerkleTrieData.class);
DataContractEncoder dataContractEncoder = DataContractRegistry.register(MerkleTrieData.class);
DataSpecification dataSpec = dataContractEncoder.getSpecification();
assertEquals(4, dataSpec.getFields().size());
assertEquals(5, dataSpec.getSlices().size());
Expand Down
34 changes: 21 additions & 13 deletions peer/src/main/java/com/jd/blockchain/peer/PeerServerBooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,17 @@ public class PeerServerBooter {
registerDataContracts();
}


/**
* 主入口方法,由启动脚本进行调用;
*
* @param args
*/
public static void main(String[] args) {
PeerServerBooter peerServerBooter = new PeerServerBooter();
peerServerBooter.handle(args);
}

public void handle(String[] args){
public void handle(String[] args) {
LedgerBindingConfig ledgerBindingConfig = null;
ArgumentSet arguments = ArgumentSet.resolve(args,
ArgumentSet.setting().prefix(LEDGERBIND_ARG, HOST_ARG, PORT_ARG).option(DEBUG_OPT));
Expand Down Expand Up @@ -181,8 +189,9 @@ public void handle(String[] args){

debug = arguments.hasOption(DEBUG_OPT);
PeerServerBooter booter = new PeerServerBooter(ledgerBindingConfig, host, port);
if(log.isDebugEnabled()){
log.debug("PeerServerBooter's urls="+ Arrays.toString(((URLClassLoader) booter.getClass().getClassLoader()).getURLs()));
if (log.isDebugEnabled()) {
log.debug("PeerServerBooter's urls="
+ Arrays.toString(((URLClassLoader) booter.getClass().getClassLoader()).getURLs()));
}
booter.start();
} catch (Exception e) {
Expand All @@ -199,10 +208,11 @@ public void handle(String[] args){
private Object[] externalBeans;
private volatile ConfigurableApplicationContext appContext;

public PeerServerBooter(){}
public PeerServerBooter() {
}

public PeerServerBooter(LedgerBindingConfig ledgerBindingConfig, String hostAddress, int port,
Object... externalBeans) {
Object... externalBeans) {
this.ledgerBindingConfig = ledgerBindingConfig;
this.hostAddress = hostAddress;
this.port = port;
Expand Down Expand Up @@ -234,12 +244,9 @@ public void closeServer() {
/**
* 启动服务;
*
* @param ledgerBindingConfig
* 账本绑定配置;
* @param hostAddress
* 服务地址;如果为空,则采用默认配置;
* @param port
* 端口地址;如果小于等于 0 ,则采用默认配置;
* @param ledgerBindingConfig 账本绑定配置;
* @param hostAddress 服务地址;如果为空,则采用默认配置;
* @param port 端口地址;如果小于等于 0 ,则采用默认配置;
* @return
*/
private static ConfigurableApplicationContext startServer(LedgerBindingConfig ledgerBindingConfig,
Expand Down Expand Up @@ -278,7 +285,8 @@ private static ConfigurableApplicationContext startServer(LedgerBindingConfig le
// 配置文件为空,则说明目前没有账本,不需要配置账本相关信息
if (ledgerBindingConfig != null) {
// 建立共识网络;
Map<String, LedgerBindingConfigAware> bindingConfigAwares = ctx.getBeansOfType(LedgerBindingConfigAware.class);
Map<String, LedgerBindingConfigAware> bindingConfigAwares = ctx
.getBeansOfType(LedgerBindingConfigAware.class);
for (LedgerBindingConfigAware aware : bindingConfigAwares.values()) {
aware.setConfig(ledgerBindingConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

public class LedgerInitConfiguration {

private static final String[] SUPPORTED_PROVIDERS = { ClassicCryptoService.class.getName(),
SMCryptoService.class.getName() };
// private static final String[] supportedProviders = { ClassicCryptoService.class.getName(),
// SMCryptoService.class.getName() };

private static final String DEFAULT_HASH_ALGORITHM = "SHA256";

Expand Down Expand Up @@ -132,11 +132,7 @@ private static ConsensusConfig createConsensusConfig(LedgerInitProperties initPr
}

private static CryptoConfig createCryptoConfig(CryptoProperties cryptoProperties) {
// 总是包含默认的提供者;
Set<String> cryptoProviderNames = new LinkedHashSet<String>();
for (String providerName : SUPPORTED_PROVIDERS) {
cryptoProviderNames.add(providerName);
}
if (cryptoProperties.getProviders() != null) {
for (String providerName : cryptoProperties.getProviders()) {
cryptoProviderNames.add(providerName);
Expand Down

0 comments on commit 98388a3

Please sign in to comment.