Skip to content

Commit 0ca7128

Browse files
author
wubinTron
committed
fix bug following comment
1 parent 88e6de1 commit 0ca7128

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎chainbase/src/main/java/org/tron/core/db/DelegationService.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public void payStandbyWitness() {
6767
double eachVotePay = (double) totalPay / voteSum;
6868
long pay = (long) (getWitnesseByAddress(b).getVoteCount() * eachVotePay);
6969
logger.debug("pay {} stand reward {}", Hex.toHexString(b.toByteArray()), pay);
70+
delegationStore.addVodeReward(dynamicPropertiesStore
71+
.getCurrentCycleNumber(), b.toByteArray(), pay);
7072
payReward(b.toByteArray(), pay);
7173
}
7274
}

‎chainbase/src/main/java/org/tron/core/store/DelegationStore.java‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.tron.core.capsule.AccountCapsule;
1111
import org.tron.core.capsule.BytesCapsule;
1212
import org.tron.core.db.TronStoreWithRevoking;
13-
import java.util.Arrays;
1413

1514
@Slf4j
1615
@Component
@@ -31,7 +30,7 @@ public BytesCapsule get(byte[] key) {
3130
}
3231

3332
public void addBlockReward(long cycle, byte[] address, long value) {
34-
byte[] key = buildRewarkBlockKey(cycle, address);
33+
byte[] key = buildRewardBlockKey(cycle, address);
3534
BytesCapsule bytesCapsule = get(key);
3635

3736
if (bytesCapsule == null) {
@@ -43,7 +42,28 @@ public void addBlockReward(long cycle, byte[] address, long value) {
4342
}
4443

4544
public long getBlockReward(long cycle, byte[] address) {
46-
BytesCapsule bytesCapsule = get(buildRewarkBlockKey(cycle, address));
45+
BytesCapsule bytesCapsule = get(buildRewardBlockKey(cycle, address));
46+
if (bytesCapsule == null) {
47+
return 0L;
48+
} else {
49+
return ByteArray.toLong(bytesCapsule.getData());
50+
}
51+
}
52+
53+
public void addVodeReward(long cycle, byte[] address, long value) {
54+
byte[] key = buildRewardVoteKey(cycle, address);
55+
BytesCapsule bytesCapsule = get(key);
56+
57+
if (bytesCapsule == null) {
58+
put(key, new BytesCapsule(ByteArray.fromLong(value)));
59+
} else {
60+
put(key, new BytesCapsule(ByteArray
61+
.fromLong(ByteArray.toLong(bytesCapsule.getData()) + value)));
62+
}
63+
}
64+
65+
public long getVoteReward(long cycle, byte[] address) {
66+
BytesCapsule bytesCapsule = get(buildRewardVoteKey(cycle, address));
4767
if (bytesCapsule == null) {
4868
return 0L;
4969
} else {
@@ -161,10 +181,14 @@ private byte[] buildRewardKey(long cycle, byte[] address) {
161181
return (cycle + "-" + Hex.toHexString(address) + "-reward").getBytes();
162182
}
163183

164-
private byte[] buildRewarkBlockKey(long cycle, byte[] address) {
184+
private byte[] buildRewardBlockKey(long cycle, byte[] address) {
165185
return (cycle + "-" + Hex.toHexString(address) + "-block").getBytes();
166186
}
167187

188+
private byte[] buildRewardVoteKey(long cycle, byte[] address) {
189+
return (cycle + "-" + Hex.toHexString(address) + "-reward-vote").getBytes();
190+
}
191+
168192
private byte[] buildRemarkKey(long cycle, byte[] address) {
169193
return (cycle + "-" + Hex.toHexString(address) + "-remark").getBytes();
170194
}

‎framework/src/main/java/org/tron/core/Wallet.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,9 +2408,14 @@ public HashMap<String, Long> queryPayByCycle(byte[] address,
24082408
if (beginCycle <= endCycle) {
24092409
for (long cycle = beginCycle; cycle <= endCycle; cycle++) {
24102410
int brokerage = dbManager.getDelegationStore().getBrokerage(cycle, address);
2411-
double brokerageRate = (double) brokerage / 100;
2412-
reward += dbManager.getDelegationStore().getReward(cycle, address) / (1 - brokerageRate);
24132411
blockPayReward += dbManager.getDelegationStore().getBlockReward(cycle, address);
2412+
if (brokerage == 100) {
2413+
reward += dbManager.getDelegationStore().getBlockReward(cycle, address) + dbManager
2414+
.getDelegationStore().getVoteReward(cycle, address);
2415+
} else {
2416+
double brokerageRate = (double) brokerage / 100;
2417+
reward += dbManager.getDelegationStore().getReward(cycle, address) / (1 - brokerageRate);
2418+
}
24142419
}
24152420
}
24162421
rewardMap.put("total", reward);

0 commit comments

Comments
 (0)