Skip to content

Commit 9c873e7

Browse files
authored
Merge pull request #899 from tronprotocol/feature/fix_transaction_fee
fix transaction fee bug
2 parents 4d45605 + 2dccfed commit 9c873e7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ public void consumeBandwidth(TransactionCapsule trx)
124124

125125
private boolean consumeFee(AccountCapsule accountCapsule, long fee) {
126126
try {
127-
dbManager.adjustBalance(accountCapsule.getAddress().toByteArray(), -fee);
128127
long latestOperationTime = dbManager.getHeadBlockTimeStamp();
129128
accountCapsule.setLatestOperationTime(latestOperationTime);
130-
dbManager.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
129+
dbManager.adjustBalance(accountCapsule.createDbKey(), -fee);
131130
return true;
132131
} catch (BalanceInsufficientException e) {
133132
return false;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,31 @@ public AccountStore getAccountStore() {
380380
return this.accountStore;
381381
}
382382

383+
public void adjustBalance(byte[] accountAddress, long amount)
384+
throws BalanceInsufficientException {
385+
AccountCapsule account = getAccountStore().get(accountAddress);
386+
adjustBalance(account, amount);
387+
}
388+
383389
/**
384390
* judge balance.
385391
*/
386-
public void adjustBalance(byte[] accountAddress, long amount)
392+
public void adjustBalance(AccountCapsule account, long amount)
387393
throws BalanceInsufficientException {
388-
AccountCapsule account = getAccountStore().get(accountAddress);
394+
389395
long balance = account.getBalance();
390396
if (amount == 0) {
391397
return;
392398
}
393399

394400
if (amount < 0 && balance < -amount) {
395-
throw new BalanceInsufficientException(accountAddress + " Insufficient");
401+
throw new BalanceInsufficientException(account.createDbKey() + " Insufficient");
396402
}
397403
account.setBalance(Math.addExact(balance, amount));
398404
this.getAccountStore().put(account.getAddress().toByteArray(), account);
399405
}
400406

407+
401408
public void adjustAllowance(byte[] accountAddress, long amount)
402409
throws BalanceInsufficientException {
403410
AccountCapsule account = getAccountStore().get(accountAddress);

0 commit comments

Comments
 (0)