mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12: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>
125 lines
3.5 KiB
Go
125 lines
3.5 KiB
Go
package state_native
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
// JustificationBits marking which epochs have been justified in the beacon chain.
|
|
func (b *BeaconState) JustificationBits() bitfield.Bitvector4 {
|
|
if b.justificationBits == nil {
|
|
return nil
|
|
}
|
|
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.justificationBitsVal()
|
|
}
|
|
|
|
// justificationBitsVal marking which epochs have been justified in the beacon chain.
|
|
// This assumes that a lock is already held on BeaconState.
|
|
func (b *BeaconState) justificationBitsVal() bitfield.Bitvector4 {
|
|
if b.justificationBits == nil {
|
|
return nil
|
|
}
|
|
|
|
res := make([]byte, len(b.justificationBits.Bytes()))
|
|
copy(res, b.justificationBits.Bytes())
|
|
return res
|
|
}
|
|
|
|
// PreviousJustifiedCheckpoint denoting an epoch and block root.
|
|
func (b *BeaconState) PreviousJustifiedCheckpoint() *ethpb.Checkpoint {
|
|
if b.previousJustifiedCheckpoint == nil {
|
|
return nil
|
|
}
|
|
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.previousJustifiedCheckpointVal()
|
|
}
|
|
|
|
// previousJustifiedCheckpointVal denoting an epoch and block root.
|
|
// This assumes that a lock is already held on BeaconState.
|
|
func (b *BeaconState) previousJustifiedCheckpointVal() *ethpb.Checkpoint {
|
|
return ethpb.CopyCheckpoint(b.previousJustifiedCheckpoint)
|
|
}
|
|
|
|
// CurrentJustifiedCheckpoint denoting an epoch and block root.
|
|
func (b *BeaconState) CurrentJustifiedCheckpoint() *ethpb.Checkpoint {
|
|
if b.currentJustifiedCheckpoint == nil {
|
|
return nil
|
|
}
|
|
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.currentJustifiedCheckpointVal()
|
|
}
|
|
|
|
// currentJustifiedCheckpointVal denoting an epoch and block root.
|
|
// This assumes that a lock is already held on BeaconState.
|
|
func (b *BeaconState) currentJustifiedCheckpointVal() *ethpb.Checkpoint {
|
|
return ethpb.CopyCheckpoint(b.currentJustifiedCheckpoint)
|
|
}
|
|
|
|
// MatchCurrentJustifiedCheckpoint returns true if input justified checkpoint matches
|
|
// the current justified checkpoint in state.
|
|
func (b *BeaconState) MatchCurrentJustifiedCheckpoint(c *ethpb.Checkpoint) bool {
|
|
if b.currentJustifiedCheckpoint == nil {
|
|
return false
|
|
}
|
|
|
|
if c.Epoch != b.currentJustifiedCheckpoint.Epoch {
|
|
return false
|
|
}
|
|
return bytes.Equal(c.Root, b.currentJustifiedCheckpoint.Root)
|
|
}
|
|
|
|
// MatchPreviousJustifiedCheckpoint returns true if the input justified checkpoint matches
|
|
// the previous justified checkpoint in state.
|
|
func (b *BeaconState) MatchPreviousJustifiedCheckpoint(c *ethpb.Checkpoint) bool {
|
|
if b.previousJustifiedCheckpoint == nil {
|
|
return false
|
|
}
|
|
|
|
if c.Epoch != b.previousJustifiedCheckpoint.Epoch {
|
|
return false
|
|
}
|
|
return bytes.Equal(c.Root, b.previousJustifiedCheckpoint.Root)
|
|
}
|
|
|
|
// FinalizedCheckpoint denoting an epoch and block root.
|
|
func (b *BeaconState) FinalizedCheckpoint() *ethpb.Checkpoint {
|
|
if b.finalizedCheckpoint == nil {
|
|
return nil
|
|
}
|
|
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.finalizedCheckpointVal()
|
|
}
|
|
|
|
// finalizedCheckpointVal denoting an epoch and block root.
|
|
// This assumes that a lock is already held on BeaconState.
|
|
func (b *BeaconState) finalizedCheckpointVal() *ethpb.Checkpoint {
|
|
return ethpb.CopyCheckpoint(b.finalizedCheckpoint)
|
|
}
|
|
|
|
// FinalizedCheckpointEpoch returns the epoch value of the finalized checkpoint.
|
|
func (b *BeaconState) FinalizedCheckpointEpoch() types.Epoch {
|
|
if b.finalizedCheckpoint == nil {
|
|
return 0
|
|
}
|
|
b.lock.RLock()
|
|
defer b.lock.RUnlock()
|
|
|
|
return b.finalizedCheckpoint.Epoch
|
|
}
|