Skip to content

Commit

Permalink
Merge pull request tronprotocol#3082 from tronprotocol/pbft-3.8-dev
Browse files Browse the repository at this point in the history
Pbft 3.8 dev
  • Loading branch information
lvs007 authored Apr 13, 2020
2 parents 1f060f8 + 90955ad commit 2400131
Show file tree
Hide file tree
Showing 149 changed files with 6,070 additions and 779 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.tron.core.store.DynamicPropertiesStore;
import org.tron.core.store.NullifierStore;
import org.tron.core.store.ZKProofStore;
import org.tron.core.utils.TransactionUtil;
import org.tron.protos.Protocol.AccountType;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.Transaction.Result.code;
Expand Down Expand Up @@ -74,7 +75,7 @@ public boolean execute(Object result)
try {
if (shieldedTransferContract.getTransparentFromAddress().toByteArray().length > 0) {
executeTransparentFrom(shieldedTransferContract.getTransparentFromAddress().toByteArray(),
shieldedTransferContract.getFromAmount(), ret,fee);
shieldedTransferContract.getFromAmount(), ret, fee);
}
Commons.adjustAssetBalanceV2(accountStore.getBlackhole().createDbKey(),
CommonParameter.getInstance().getZenTokenId(), fee,
Expand All @@ -87,11 +88,11 @@ public boolean execute(Object result)
}

executeShielded(shieldedTransferContract.getSpendDescriptionList(),
shieldedTransferContract.getReceiveDescriptionList(), ret,fee);
shieldedTransferContract.getReceiveDescriptionList(), ret, fee);

if (shieldedTransferContract.getTransparentToAddress().toByteArray().length > 0) {
executeTransparentTo(shieldedTransferContract.getTransparentToAddress().toByteArray(),
shieldedTransferContract.getToAmount(), ret,fee);
shieldedTransferContract.getToAmount(), ret, fee);
}

//adjust and verify total shielded pool value
Expand Down Expand Up @@ -155,7 +156,7 @@ private void executeTransparentTo(byte[] toAddress, long amount, TransactionResu

//record shielded transaction data.
private void executeShielded(List<SpendDescription> spends, List<ReceiveDescription> receives,
TransactionResultCapsule ret,long fee)
TransactionResultCapsule ret, long fee)
throws ContractExeException {

NullifierStore nullifierStore = chainBaseManager.getNullifierStore();
Expand Down Expand Up @@ -225,7 +226,7 @@ public boolean validate() throws ContractValidateException {
//transparent verification
checkSender(shieldedTransferContract);
checkReceiver(shieldedTransferContract);
validateTransparent(shieldedTransferContract,fee);
validateTransparent(shieldedTransferContract, fee);

List<SpendDescription> spendDescriptions = shieldedTransferContract.getSpendDescriptionList();
// check duplicate sapling nullifiers
Expand Down Expand Up @@ -263,7 +264,7 @@ public boolean validate() throws ContractValidateException {

//check spendProofs receiveProofs and Binding sign hash
try {
checkProof(spendDescriptions, receiveDescriptions,fee);
checkProof(spendDescriptions, receiveDescriptions, fee);
} catch (ZkProofValidateException e) {
if (e.isFirstValidated()) {
recordProof(tx.getTransactionId(), false);
Expand All @@ -275,7 +276,7 @@ public boolean validate() throws ContractValidateException {
}

private void checkProof(List<SpendDescription> spendDescriptions,
List<ReceiveDescription> receiveDescriptions,long fee) throws ZkProofValidateException {
List<ReceiveDescription> receiveDescriptions, long fee) throws ZkProofValidateException {
DynamicPropertiesStore dynamicStore = chainBaseManager.getDynamicPropertiesStore();
ZKProofStore proofStore = chainBaseManager.getProofStore();
if (proofStore.has(tx.getTransactionId().getBytes())) {
Expand All @@ -286,7 +287,6 @@ private void checkProof(List<SpendDescription> spendDescriptions,
}
}


byte[] signHash = getShieldTransactionHashIgnoreTypeException(tx.getInstance());

if (CollectionUtils.isNotEmpty(spendDescriptions)
Expand Down
14 changes: 13 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore, Fork
}
break;
}
case ALLOW_PBFT: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_3_8)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_PBFT]");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_PBFT] is only allowed to be 1");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -346,7 +357,8 @@ public enum ProposalType { // current value, value range
ALLOW_TVM_SOLIDITY_059(32), // 1, {0, 1}
ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33), // 10, [1, 1000]
// SHIELDED_TRANSACTION_CREATE_ACCOUNT_FEE(34), // 1 TRX, [0, 10000] TRX
FORBID_TRANSFER_TO_CONTRACT(35); // 1, {0, 1}
FORBID_TRANSFER_TO_CONTRACT(35), // 1, {0, 1}
ALLOW_PBFT(40);// 1,40

private long code;

Expand Down
Empty file.
11 changes: 11 additions & 0 deletions chainbase/src/main/java/org/tron/common/utils/LocalWitnesses.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.tron.common.crypto.ECKey;
import org.tron.common.crypto.SignInterface;
import org.tron.common.crypto.SignUtils;
import org.tron.core.config.Parameter.ChainConstant;
Expand Down Expand Up @@ -106,4 +107,14 @@ public String getPrivateKey() {
return privateKeys.get(0);
}

public byte[] getPublicKey() {
if (CollectionUtils.isEmpty(privateKeys)) {
logger.warn("privateKey is null");
return null;
}
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
final ECKey ecKey = ECKey.fromPrivate(privateKey);
return ecKey.getAddress();
}

}
12 changes: 12 additions & 0 deletions chainbase/src/main/java/org/tron/core/ChainBaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.tron.core.db.BlockIndexStore;
import org.tron.core.db.BlockStore;
import org.tron.core.db.CommonStore;
import org.tron.core.db.CommonDataBase;
import org.tron.core.db.DelegationService;
import org.tron.core.db.KhaosDatabase;
import org.tron.core.db.RecentBlockStore;
Expand All @@ -27,6 +28,7 @@
import org.tron.core.exception.BadItemException;
import org.tron.core.exception.HeaderNotFound;
import org.tron.core.exception.ItemNotFoundException;
import org.tron.core.db.PbftSignDataStore;
import org.tron.core.store.AccountIdIndexStore;
import org.tron.core.store.AccountIndexStore;
import org.tron.core.store.AccountStore;
Expand Down Expand Up @@ -161,6 +163,14 @@ public class ChainBaseManager {
@Setter
private BlockCapsule genesisBlock;

@Autowired
@Getter
private CommonDataBase commonDataBase;

@Autowired
@Getter
private PbftSignDataStore pbftSignDataStore;

public void closeOneStore(ITronChainBase database) {
logger.info("******** begin to close " + database.getName() + " ********");
try {
Expand Down Expand Up @@ -200,6 +210,8 @@ public void closeAllStore() {
closeOneStore(delegationStore);
closeOneStore(proofStore);
closeOneStore(commonStore);
closeOneStore(commonDataBase);
closeOneStore(pbftSignDataStore);
}

// for test only
Expand Down
Loading

0 comments on commit 2400131

Please sign in to comment.