Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(branch): master merge into develop #5153

Merged
merged 13 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions actuator/src/main/java/org/tron/core/utils/TransactionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract;
import org.tron.protos.Protocol.Transaction.Result.contractResult;
import org.tron.protos.Protocol.TransactionSign;
import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
Expand Down Expand Up @@ -184,21 +183,6 @@ public static String makeUpperCamelMethod(String originName) {
.replace("_", "");
}

public static TransactionCapsule getTransactionSign(TransactionSign transactionSign) {
byte[] privateKey = transactionSign.getPrivateKey().toByteArray();
TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction());
trx.sign(privateKey);
return trx;
}

public TransactionCapsule addSign(TransactionSign transactionSign)
throws PermissionException, SignatureException, SignatureFormatException {
byte[] privateKey = transactionSign.getPrivateKey().toByteArray();
TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction());
trx.addSign(privateKey, chainBaseManager.getAccountStore());
return trx;
}

public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
TransactionSignWeight.Builder tswBuilder = TransactionSignWeight.newBuilder();
TransactionExtention.Builder trxExBuilder = TransactionExtention.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public void payEnergyBill(DynamicPropertiesStore dynamicPropertiesStore,
AccountCapsule caller,
long percent, long originEnergyLimit, EnergyProcessor energyProcessor, long now)
throws BalanceInsufficientException {

// Reset origin energy usage here! Because after stake 2.0, this field are reused for
// recording pre-merge frozen energy for origin account. If total energy usage is zero, this
// field will be a dirty record.
this.setOriginEnergyUsage(0);

if (receipt.getEnergyUsageTotal() <= 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void pay() throws BalanceInsufficientException {
AccountCapsule origin = accountStore.get(originAccount);
AccountCapsule caller = accountStore.get(callerAccount);
if (dynamicPropertiesStore.supportUnfreezeDelay()
&& receipt.getReceipt().getResult().equals(contractResult.SUCCESS)) {
&& getRuntimeResult().getException() == null && !getRuntimeResult().isRevert()) {

// just fo caller is not origin, we set the related field for origin account
if (origin != null && !caller.getAddress().equals(origin.getAddress())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.tron.core.db.TransactionStore;
import org.tron.core.db.TronStoreWithRevoking;
import org.tron.core.exception.BadItemException;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.TransactionInfo;

@Slf4j(topic = "DB")
Expand Down Expand Up @@ -54,6 +55,17 @@ public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemExcep
ByteString id = ByteString.copyFrom(key);
for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) {
if (transactionResultInfo.getId().equals(id)) {
Protocol.ResourceReceipt receipt = transactionResultInfo.getReceipt();
// If query a result with dirty origin usage in receipt, we just reset it.
if (receipt.getEnergyUsageTotal() == 0 && receipt.getOriginEnergyUsage() > 0) {
transactionResultInfo =
transactionResultInfo.toBuilder()
.setReceipt(
receipt.toBuilder()
.clearOriginEnergyUsage()
.build())
.build();
}
return new TransactionInfoCapsule(transactionResultInfo);
}
}
Expand Down
23 changes: 9 additions & 14 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -648,18 +648,6 @@ public TransactionApprovedList getTransactionApprovedList(Transaction trx) {
return tswBuilder.build();
}

public byte[] pass2Key(byte[] passPhrase) {
return Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), passPhrase);
}

public byte[] createAddress(byte[] passPhrase) {
byte[] privateKey = pass2Key(passPhrase);
SignInterface ecKey = SignUtils.fromPrivate(privateKey,
Args.getInstance().isECKeyCryptoEngine());
return ecKey.getAddress();
}

public Block getNowBlock() {
List<BlockCapsule> blockList = chainBaseManager.getBlockStore().getBlockByLatestNum(1);
if (CollectionUtils.isEmpty(blockList)) {
Expand Down Expand Up @@ -765,19 +753,26 @@ public DelegatedResourceList getDelegatedResourceV2(
.createDbKeyV2(fromAddress.toByteArray(), toAddress.toByteArray(), false);
DelegatedResourceCapsule unlockResource = chainBaseManager.getDelegatedResourceStore()
.get(dbKey);
if (unlockResource != null) {
if (nonEmptyResource(unlockResource)) {
builder.addDelegatedResource(unlockResource.getInstance());
}
dbKey = DelegatedResourceCapsule
.createDbKeyV2(fromAddress.toByteArray(), toAddress.toByteArray(), true);
DelegatedResourceCapsule lockResource = chainBaseManager.getDelegatedResourceStore()
.get(dbKey);
if (lockResource != null) {
if (nonEmptyResource(lockResource)) {
builder.addDelegatedResource(lockResource.getInstance());
}
return builder.build();
}

private boolean nonEmptyResource(DelegatedResourceCapsule resource) {
return Objects.nonNull(resource) && !(resource.getExpireTimeForBandwidth() == 0
&& resource.getExpireTimeForEnergy() == 0
&& resource.getFrozenBalanceForBandwidth() == 0
&& resource.getFrozenBalanceForEnergy() == 0);
}

public GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage getCanWithdrawUnfreezeAmount(
ByteString ownerAddress, long timestamp) {
GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage.Builder builder =
Expand Down
Loading