Skip to content

Commit 33f7add

Browse files
authored
Merge pull request #612 from tronprotocol/feature/rm_division
remove division in calculateBandwidth()
2 parents cb68a61 + ca6ad76 commit 33f7add

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/main/java/org/tron/core/actuator/FreezeBalanceActuator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
6060

6161
private long calculateBandwidth(FreezeBalanceContract freezeBalanceContract) {
6262

63-
return freezeBalanceContract.getFrozenBalance() / 1_000_000L
63+
return freezeBalanceContract.getFrozenBalance()
6464
* freezeBalanceContract.getFrozenDuration()
6565
* dbManager.getDynamicPropertiesStore().getBandwidthPerCoinday();
6666
}

src/main/java/org/tron/core/db/DynamicPropertiesStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ private DynamicPropertiesStore(@Qualifier("properties") String dbName) {
151151
try {
152152
this.getBandwidthPerTransaction();
153153
} catch (IllegalArgumentException e) {
154-
this.saveBandwidthPerTransaction(1);
154+
this.saveBandwidthPerTransaction(100_000);
155155
}
156156

157157
try {
158158
this.getBandwidthPerCoinday();
159159
} catch (IllegalArgumentException e) {
160-
this.saveBandwidthPerCoinday(10);
160+
this.saveBandwidthPerCoinday(1);
161161
}
162162

163163
try {

src/main/java/org/tron/core/db/Manager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ public synchronized boolean pushTransactions(final TransactionCapsule trx)
424424
if (!trx.validateSignature()) {
425425
throw new ValidateSignatureException("trans sig validate failed");
426426
}
427-
consumeBandwidth(trx);
428427

429428
validateTapos(trx);
430429

@@ -435,6 +434,7 @@ public synchronized boolean pushTransactions(final TransactionCapsule trx)
435434
}
436435

437436
try (RevokingStore.Dialog tmpDialog = revokingStore.buildDialog()) {
437+
consumeBandwidth(trx);
438438
processTransaction(trx);
439439
pendingTransactions.add(trx);
440440
tmpDialog.merge();
@@ -457,7 +457,10 @@ public void consumeBandwidth(TransactionCapsule trx) throws ValidateBandwidthExc
457457
long bandwidth = accountCapsule.getBandwidth();
458458
long now = Time.getCurrentMillis();
459459
long latestOperationTime = accountCapsule.getLatestOperationTime();
460-
if (now - latestOperationTime >= 5 * 60 * 1000) {
460+
//5 * 60 * 1000
461+
if (now - latestOperationTime >= 300_000L) {
462+
accountCapsule.setLatestOperationTime(now);
463+
this.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
461464
return;
462465
}
463466
long bandwidthPerTransaction = getDynamicPropertiesStore().getBandwidthPerTransaction();

src/test/java/org/tron/core/actuator/FreezeBalanceActuatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void testFreezeBalance() {
114114
Assert.assertEquals(owner.getBalance(), initBalance - frozenBalance
115115
- ChainConstant.TRANSFER_FEE);
116116
Assert.assertEquals(owner.getFrozenBalance(), frozenBalance);
117-
Assert.assertEquals(owner.getBandwidth(), frozenBalance / 1_000_000
117+
Assert.assertEquals(owner.getBandwidth(), frozenBalance
118118
* duration
119119
* dbManager.getDynamicPropertiesStore().getBandwidthPerCoinday());
120120
} catch (ContractValidateException e) {

0 commit comments

Comments
 (0)