Skip to content

Commit

Permalink
feat(freezeV2): Add bandwidth cost for delegating validation
Browse files Browse the repository at this point in the history
  • Loading branch information
chaozhu committed Nov 18, 2022
1 parent 4afd4c5 commit 62e9c1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.Transaction.Result.code;
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;
import org.tron.core.utils.TransactionUtil;

@Slf4j(topic = "actuator")
public class DelegateResourceActuator extends AbstractActuator {
Expand Down Expand Up @@ -143,7 +144,12 @@ public boolean validate() throws ContractValidateException {
BandwidthProcessor processor = new BandwidthProcessor(chainBaseManager);
processor.updateUsage(ownerCapsule);

long netUsage = (long) (ownerCapsule.getNetUsage() * TRX_PRECISION * ((double)
long accountNetUsage = ownerCapsule.getNetUsage();
if (null != this.getTx() && this.getTx().isTransactionCreate()) {
accountNetUsage += TransactionUtil.estimateConsumeBandWidthSize(ownerCapsule,
chainBaseManager);
}
long netUsage = (long) (accountNetUsage * TRX_PRECISION * ((double)
(dynamicStore.getTotalNetWeight()) / dynamicStore.getTotalNetLimit()));

long ownerNetUsage = (long) (netUsage * ((double)(ownerCapsule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
private long order;
private byte[] ownerAddress;

@Getter
@Setter
private boolean isTransactionCreate = false;

public byte[] getOwnerAddress() {
if (this.ownerAddress == null) {
this.ownerAddress = getOwner(this.transaction.getRawData().getContract(0));
Expand Down
3 changes: 2 additions & 1 deletion framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,15 @@ public TransactionCapsule createTransactionCapsuleWithoutValidate(
public TransactionCapsule createTransactionCapsule(com.google.protobuf.Message message,
ContractType contractType) throws ContractValidateException {
TransactionCapsule trx = new TransactionCapsule(message, contractType);
trx.setTransactionCreate(true);
if (contractType != ContractType.CreateSmartContract
&& contractType != ContractType.TriggerSmartContract) {
List<Actuator> actList = ActuatorFactory.createActuator(trx, chainBaseManager);
for (Actuator act : actList) {
act.validate();
}
}

trx.setTransactionCreate(false);
if (contractType == ContractType.CreateSmartContract) {

CreateSmartContract contract = ContractCapsule
Expand Down

0 comments on commit 62e9c1a

Please sign in to comment.