@lodestar/beacon-node 1.39.0-dev.075956b855 → 1.39.0-dev.100ab480bb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chain/chain.d.ts +4 -7
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +1 -4
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/interface.d.ts +4 -7
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/package.json +14 -14
- package/src/chain/chain.ts +7 -6
- package/src/chain/interface.ts +4 -6
- package/lib/chain/rewards/attestationsRewards.d.ts +0 -8
- package/lib/chain/rewards/attestationsRewards.d.ts.map +0 -1
- package/lib/chain/rewards/attestationsRewards.js +0 -112
- package/lib/chain/rewards/attestationsRewards.js.map +0 -1
- package/lib/chain/rewards/blockRewards.d.ts +0 -15
- package/lib/chain/rewards/blockRewards.d.ts.map +0 -1
- package/lib/chain/rewards/blockRewards.js +0 -94
- package/lib/chain/rewards/blockRewards.js.map +0 -1
- package/lib/chain/rewards/syncCommitteeRewards.d.ts +0 -7
- package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +0 -1
- package/lib/chain/rewards/syncCommitteeRewards.js +0 -36
- package/lib/chain/rewards/syncCommitteeRewards.js.map +0 -1
- package/src/chain/rewards/attestationsRewards.ts +0 -206
- package/src/chain/rewards/blockRewards.ts +0 -153
- package/src/chain/rewards/syncCommitteeRewards.ts +0 -60
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {routes} from "@lodestar/api";
|
|
2
|
-
import {BeaconConfig} from "@lodestar/config";
|
|
3
|
-
import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
|
|
4
|
-
import {CachedBeaconStateAllForks, CachedBeaconStateAltair, Index2PubkeyCache} from "@lodestar/state-transition";
|
|
5
|
-
import {BeaconBlock, ValidatorIndex, altair} from "@lodestar/types";
|
|
6
|
-
|
|
7
|
-
export type SyncCommitteeRewards = routes.beacon.SyncCommitteeRewards;
|
|
8
|
-
type BalanceRecord = {val: number}; // Use val for convenient way to increment/decrement balance
|
|
9
|
-
|
|
10
|
-
export async function computeSyncCommitteeRewards(
|
|
11
|
-
config: BeaconConfig,
|
|
12
|
-
index2pubkey: Index2PubkeyCache,
|
|
13
|
-
block: BeaconBlock,
|
|
14
|
-
preState: CachedBeaconStateAllForks,
|
|
15
|
-
validatorIds: (ValidatorIndex | string)[] = []
|
|
16
|
-
): Promise<SyncCommitteeRewards> {
|
|
17
|
-
const fork = config.getForkName(block.slot);
|
|
18
|
-
if (fork === ForkName.phase0) {
|
|
19
|
-
throw Error("Cannot get sync rewards as phase0 block does not have sync committee");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const altairBlock = block as altair.BeaconBlock;
|
|
23
|
-
const preStateAltair = preState as CachedBeaconStateAltair;
|
|
24
|
-
|
|
25
|
-
// Bound syncCommitteeValidatorIndices in case it goes beyond SYNC_COMMITTEE_SIZE just to be safe
|
|
26
|
-
const syncCommitteeValidatorIndices = preStateAltair.epochCtx.currentSyncCommitteeIndexed.validatorIndices.slice(
|
|
27
|
-
0,
|
|
28
|
-
SYNC_COMMITTEE_SIZE
|
|
29
|
-
);
|
|
30
|
-
const {syncParticipantReward} = preStateAltair.epochCtx;
|
|
31
|
-
const {syncCommitteeBits} = altairBlock.body.syncAggregate;
|
|
32
|
-
|
|
33
|
-
// Use balance of each committee as starting point such that we cap the penalty to avoid balance dropping below 0
|
|
34
|
-
const balances: Map<ValidatorIndex, BalanceRecord> = new Map();
|
|
35
|
-
for (const i of syncCommitteeValidatorIndices) {
|
|
36
|
-
balances.set(i, {val: preStateAltair.balances.get(i)});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (const i of syncCommitteeValidatorIndices) {
|
|
40
|
-
const balanceRecord = balances.get(i) as BalanceRecord;
|
|
41
|
-
if (syncCommitteeBits.get(i)) {
|
|
42
|
-
// Positive rewards for participants
|
|
43
|
-
balanceRecord.val += syncParticipantReward;
|
|
44
|
-
} else {
|
|
45
|
-
// Negative rewards for non participants
|
|
46
|
-
balanceRecord.val = Math.max(0, balanceRecord.val - syncParticipantReward);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const rewards = Array.from(balances, ([validatorIndex, v]) => ({validatorIndex, reward: v.val}));
|
|
51
|
-
|
|
52
|
-
if (validatorIds.length) {
|
|
53
|
-
const filtersSet = new Set(validatorIds);
|
|
54
|
-
return rewards.filter(
|
|
55
|
-
(reward) => filtersSet.has(reward.validatorIndex) || filtersSet.has(index2pubkey[reward.validatorIndex].toHex())
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return rewards;
|
|
60
|
-
}
|