Browse Source

1)0.0.0.0; 2)gateway's pool; 3)bftsmart's optimization;

tags/1.1.3
zhaoguangwei 5 years ago
parent
commit
1b8923f851
8 changed files with 92 additions and 24 deletions
  1. +3
    -1
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartMessageService.java
  2. +9
    -9
      source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java
  3. +7
    -0
      source/gateway/src/main/java/com/jd/blockchain/gateway/web/TxProcessingController.java
  4. +4
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java
  5. +8
    -4
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java
  6. +3
    -1
      source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java
  7. +57
    -6
      source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java
  8. +1
    -1
      source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java

+ 3
- 1
source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/client/BftsmartMessageService.java View File

@@ -43,7 +43,9 @@ public class BftsmartMessageService implements MessageService {
throw new RuntimeException(e);

} finally {
asyncPeerProxyPool.returnObject(asynchServiceProxy);
if (asynchServiceProxy != null) {
asyncPeerProxyPool.returnObject(asynchServiceProxy);
}
}

return asyncFuture;


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

@@ -33,7 +33,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer

private static Logger LOGGER = LoggerFactory.getLogger(BftsmartNodeServer.class);

private static final String DEFAULT_BINDING_HOST = "0.0.0.0";
// private static final String DEFAULT_BINDING_HOST = "0.0.0.0";

private List<StateHandle> stateHandles = new CopyOnWriteArrayList<>();

@@ -59,7 +59,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer

private TOMConfiguration tomConfig;

private TOMConfiguration outerTomConfig;
// private TOMConfiguration outerTomConfig;

private HostsConfig hostsConfig;
private Properties systemConfig;
@@ -129,12 +129,12 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer
}

protected void initConfig(int id, Properties systemsConfig, HostsConfig hostConfig) {
byte[] serialHostConf = BinarySerializeUtils.serialize(hostConfig);
Properties sysConfClone = (Properties)systemsConfig.clone();
int port = hostConfig.getPort(id);
hostConfig.add(id, DEFAULT_BINDING_HOST, port);
// byte[] serialHostConf = BinarySerializeUtils.serialize(hostConfig);
// Properties sysConfClone = (Properties)systemsConfig.clone();
// int port = hostConfig.getPort(id);
// hostConfig.add(id, DEFAULT_BINDING_HOST, port);
this.tomConfig = new TOMConfiguration(id, systemsConfig, hostConfig);
this.outerTomConfig = new TOMConfiguration(id, sysConfClone, BinarySerializeUtils.deserialize(serialHostConf));
// this.outerTomConfig = new TOMConfiguration(id, systemsConfig, hostConfig);
}

@Override
@@ -153,7 +153,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer
}

public TOMConfiguration getTomConfig() {
return outerTomConfig;
return tomConfig;
}

public int getId() {
@@ -165,7 +165,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer
throw new IllegalArgumentException("ReplicaID is negative!");
}
this.tomConfig.setProcessId(id);
this.outerTomConfig.setProcessId(id);
// this.outerTomConfig.setProcessId(id);
}

public BftsmartConsensusSettings getConsensusSetting() {


+ 7
- 0
source/gateway/src/main/java/com/jd/blockchain/gateway/web/TxProcessingController.java View File

@@ -3,6 +3,8 @@ package com.jd.blockchain.gateway.web;
import com.jd.blockchain.crypto.*;
import com.jd.blockchain.gateway.service.GatewayInterceptService;
import com.jd.blockchain.transaction.SignatureUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -27,6 +29,8 @@ import com.jd.blockchain.web.converters.BinaryMessageConverter;
@RestController
public class TxProcessingController implements TransactionService {

private static Logger LOGGER = LoggerFactory.getLogger(TxProcessingController.class);

@Autowired
private PeerService peerService;

@@ -59,11 +63,14 @@ public class TxProcessingController implements TransactionService {
throw new IllegalStateException("Not implemented!");
} else {
// 验证签名;
StringBuilder signer = new StringBuilder(txRequest.getHash().toString()).append("->");
for (DigitalSignature sign : partiSigns) {
signer.append(AddressEncoding.generateAddress(sign.getPubKey()).toBase58()).append(",");
if (!SignatureUtils.verifySignature(txRequest.getTransactionContent(), sign.getDigest(), sign.getPubKey())) {
throw new BusinessException("The validation of participant signatures fail!");
}
}
LOGGER.debug(signer.toString());
}

// 注:转发前自动附加网关的签名并转发请求至共识节点;异步的处理方式


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

@@ -370,9 +370,11 @@ public class LedgerQueryService implements BlockchainQueryService {
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));

// int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
// return dataAccount.getDataset().getDataEntry(key, version).getDataEntries(pages[0], pages[1]);
fromIndex = pages[0];
count = pages[1];

DataIterator<String, TypedValue> iterator = dataAccount.getDataset().iterator();
iterator.skip(fromIndex);
DataEntry<String, TypedValue>[] dataEntries = iterator.next(count);


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

@@ -1,11 +1,9 @@
package com.jd.blockchain.ledger.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.*;

import com.jd.blockchain.ledger.*;
import com.jd.blockchain.utils.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -117,6 +115,12 @@ public class TransactionBatchProcessor implements TransactionBatchProcess {
TransactionRequestExtension reqExt = new TransactionRequestExtensionImpl(request);

// 初始化交易的用户安全策略;
// Set<Bytes> endPointAddresses = reqExt.getEndpointAddresses();
// int index = 0;
// for (Bytes address : endPointAddresses) {
// System.out.printf("EndPoint Sign Address %s[%s] -> %s \r\n", request.getHash(), index++, address.toBase58());
//// LOGGER.debug("EndPoint Sign Address {}[{}] -> {}", request.getHash(), index++, address.toBase58());
// }
SecurityPolicy securityPolicy = securityManager.createSecurityPolicy(reqExt.getEndpointAddresses(),
reqExt.getNodeAddresses());
SecurityContext.setContextUsersPolicy(securityPolicy);


+ 3
- 1
source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java View File

@@ -449,8 +449,10 @@ public class LedgerQueryController implements BlockchainQueryService {
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));

// int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount());
// return dataAccount.getDataEntries(pages[0], pages[1]);
fromIndex = pages[0];
count = pages[1];

DataIterator<String, TypedValue> iterator = dataAccount.getDataset().iterator();
iterator.skip(fromIndex);


+ 57
- 6
source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/service/NodeSigningAppender.java View File

@@ -8,14 +8,13 @@ import com.jd.blockchain.crypto.AsymmetricKeypair;
import com.jd.blockchain.crypto.Crypto;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.HashFunction;
import com.jd.blockchain.ledger.DigitalSignature;
import com.jd.blockchain.ledger.NodeRequest;
import com.jd.blockchain.ledger.TransactionRequest;
import com.jd.blockchain.ledger.TransactionResponse;
import com.jd.blockchain.ledger.*;
import com.jd.blockchain.transaction.SignatureUtils;
import com.jd.blockchain.transaction.TransactionService;
import com.jd.blockchain.transaction.TxRequestMessage;
import com.jd.blockchain.utils.concurrent.AsyncFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* {@link NodeSigningAppender} 以装饰者模式实现,为交易请求附加上节点签名;
@@ -25,6 +24,8 @@ import com.jd.blockchain.utils.concurrent.AsyncFuture;
*/
public class NodeSigningAppender implements TransactionService {

private static Logger LOGGER = LoggerFactory.getLogger(NodeSigningAppender.class);

static {
DataContractRegistry.register(NodeRequest.class);
}
@@ -78,8 +79,58 @@ public class NodeSigningAppender implements TransactionService {
HashDigest txHash = hashFunc.hash(nodeRequestBytes);
txMessage.setHash(txHash);

AsyncFuture<byte[]> result = messageService.sendOrdered(BinaryProtocol.encode(txMessage, TransactionRequest.class));
try {
AsyncFuture<byte[]> asyncFuture = messageService.sendOrdered(BinaryProtocol.encode(txMessage, TransactionRequest.class));
byte[] result = asyncFuture.get();
if (result == null) {
LOGGER.error("Gateway receive [{}]'s result is null!", txRequest.getHash());
return new ErrorTransactionResponse(txRequest.getTransactionContent().getHash());
}
return BinaryProtocol.decode(result);
} catch (IllegalStateException e) {
e.printStackTrace();
LOGGER.error("Gateway send tx [{}] error {} !", txRequest.getHash(), e);
return new ErrorTransactionResponse(txRequest.getTransactionContent().getHash());
}
}


private static class ErrorTransactionResponse implements TransactionResponse {

HashDigest contentHash;

public ErrorTransactionResponse(HashDigest contentHash) {
this.contentHash = contentHash;
}

@Override
public HashDigest getContentHash() {
return contentHash;
}

@Override
public TransactionState getExecutionState() {
return TransactionState.TIMEOUT;
}

@Override
public HashDigest getBlockHash() {
return null;
}

@Override
public long getBlockHeight() {
return -1L;
}

@Override
public boolean isSuccess() {
return false;
}

return BinaryProtocol.decode(result.get());
@Override
public OperationResult[] getOperationResults() {
return null;
}
}
}

+ 1
- 1
source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java View File

@@ -82,7 +82,7 @@ public class SDK_GateWay_User_Test_ {

CLIENT_CERT = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey0, SDK_GateWay_KeyPair_Para.privkey0);
GATEWAY_IPADDR = "127.0.0.1";
GATEWAY_PORT = 8081;
GATEWAY_PORT = 10300;
SECURE = false;
GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
CLIENT_CERT);


Loading…
Cancel
Save