Skip to content
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
3 changes: 1 addition & 2 deletions src/main/java/org/tron/core/db/BandwidthProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ public void consumeBandwidth(TransactionCapsule trx)

private boolean consumeFee(AccountCapsule accountCapsule, long fee) {
try {
dbManager.adjustBalance(accountCapsule.getAddress().toByteArray(), -fee);
long latestOperationTime = dbManager.getHeadBlockTimeStamp();
accountCapsule.setLatestOperationTime(latestOperationTime);
dbManager.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
dbManager.adjustBalance(accountCapsule.createDbKey(), -fee);
return true;
} catch (BalanceInsufficientException e) {
return false;
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,31 @@ public AccountStore getAccountStore() {
return this.accountStore;
}

public void adjustBalance(byte[] accountAddress, long amount)
throws BalanceInsufficientException {
AccountCapsule account = getAccountStore().get(accountAddress);
adjustBalance(account, amount);
}

/**
* judge balance.
*/
public void adjustBalance(byte[] accountAddress, long amount)
public void adjustBalance(AccountCapsule account, long amount)
throws BalanceInsufficientException {
AccountCapsule account = getAccountStore().get(accountAddress);

long balance = account.getBalance();
if (amount == 0) {
return;
}

if (amount < 0 && balance < -amount) {
throw new BalanceInsufficientException(accountAddress + " Insufficient");
throw new BalanceInsufficientException(account.createDbKey() + " Insufficient");
}
account.setBalance(Math.addExact(balance, amount));
this.getAccountStore().put(account.getAddress().toByteArray(), account);
}


public void adjustAllowance(byte[] accountAddress, long amount)
throws BalanceInsufficientException {
AccountCapsule account = getAccountStore().get(accountAddress);
Expand Down