mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package state_native
|
|
|
|
import (
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
|
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
|
)
|
|
|
|
// CurrentEpochParticipation corresponding to participation bits on the beacon chain.
|
|
func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
|
if b.version == version.Phase0 {
|
|
return nil, errNotSupported("CurrentEpochParticipation", b.version)
|
|
}
|
|
|
|
if b.currentEpochParticipation == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.currentEpochParticipationVal(), nil
|
|
}
|
|
|
|
// PreviousEpochParticipation corresponding to participation bits on the beacon chain.
|
|
func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) {
|
|
if b.version == version.Phase0 {
|
|
return nil, errNotSupported("PreviousEpochParticipation", b.version)
|
|
}
|
|
|
|
if b.previousEpochParticipation == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.previousEpochParticipationVal(), nil
|
|
}
|
|
|
|
// UnrealizedCheckpointBalances returns the total balances: active, target attested in
|
|
// current epoch and target attested in previous epoch. This function is used to
|
|
// compute the "unrealized justification" that a synced Beacon Block will have.
|
|
func (b *BeaconState) UnrealizedCheckpointBalances() (uint64, uint64, uint64, error) {
|
|
if b.version == version.Phase0 {
|
|
return 0, 0, 0, errNotSupported("UnrealizedCheckpointBalances", b.version)
|
|
}
|
|
|
|
currentEpoch := time.CurrentEpoch(b)
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
cp := b.currentEpochParticipation
|
|
pp := b.previousEpochParticipation
|
|
if cp == nil || pp == nil {
|
|
return 0, 0, 0, ErrNilParticipation
|
|
}
|
|
|
|
return stateutil.UnrealizedCheckpointBalances(cp, pp, b.validators, currentEpoch)
|
|
|
|
}
|
|
|
|
// currentEpochParticipationVal corresponding to participation bits on the beacon chain.
|
|
// This assumes that a lock is already held on BeaconState.
|
|
func (b *BeaconState) currentEpochParticipationVal() []byte {
|
|
tmp := make([]byte, len(b.currentEpochParticipation))
|
|
copy(tmp, b.currentEpochParticipation)
|
|
return tmp
|
|
}
|
|
|
|
// previousEpochParticipationVal corresponding to participation bits on the beacon chain.
|
|
// This assumes that a lock is already held on BeaconState.
|
|
func (b *BeaconState) previousEpochParticipationVal() []byte {
|
|
tmp := make([]byte, len(b.previousEpochParticipation))
|
|
copy(tmp, b.previousEpochParticipation)
|
|
return tmp
|
|
}
|