-
Notifications
You must be signed in to change notification settings - Fork 969
/
getters_misc.go
107 lines (85 loc) · 2.47 KB
/
getters_misc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package state_native
import (
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
)
// Id is the identifier of the beacon state.
func (b *BeaconState) Id() uint64 {
return b.id
}
// GenesisTime of the beacon state as a uint64.
func (b *BeaconState) GenesisTime() uint64 {
b.lock.RLock()
defer b.lock.RUnlock()
return b.genesisTime
}
// GenesisValidatorsRoot of the beacon state.
func (b *BeaconState) GenesisValidatorsRoot() []byte {
b.lock.RLock()
defer b.lock.RUnlock()
return b.genesisValidatorsRoot[:]
}
// Version of the beacon state. This method
// is strictly meant to be used without a lock
// internally.
func (b *BeaconState) Version() int {
return b.version
}
// Slot of the current beacon chain state.
func (b *BeaconState) Slot() primitives.Slot {
b.lock.RLock()
defer b.lock.RUnlock()
return b.slot
}
// Fork version of the beacon chain.
func (b *BeaconState) Fork() *ethpb.Fork {
if b.fork == nil {
return nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.forkVal()
}
// forkVal version of the beacon chain.
// This assumes that a lock is already held on BeaconState.
func (b *BeaconState) forkVal() *ethpb.Fork {
if b.fork == nil {
return nil
}
prevVersion := make([]byte, len(b.fork.PreviousVersion))
copy(prevVersion, b.fork.PreviousVersion)
currVersion := make([]byte, len(b.fork.CurrentVersion))
copy(currVersion, b.fork.CurrentVersion)
return ðpb.Fork{
PreviousVersion: prevVersion,
CurrentVersion: currVersion,
Epoch: b.fork.Epoch,
}
}
// HistoricalRoots based on epochs stored in the beacon state.
func (b *BeaconState) HistoricalRoots() ([][]byte, error) {
if b.historicalRoots == nil {
return nil, nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.historicalRoots.Slice(), nil
}
// HistoricalSummaries of the beacon state.
func (b *BeaconState) HistoricalSummaries() ([]*ethpb.HistoricalSummary, error) {
if b.version < version.Capella {
return nil, errNotSupported("HistoricalSummaries", b.version)
}
if b.historicalSummaries == nil {
return nil, nil
}
b.lock.RLock()
defer b.lock.RUnlock()
return b.historicalSummariesVal(), nil
}
// historicalSummariesVal of the beacon state.
// This assumes that a lock is already held on BeaconState.
func (b *BeaconState) historicalSummariesVal() []*ethpb.HistoricalSummary {
return ethpb.CopyHistoricalSummaries(b.historicalSummaries)
}