-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_epoch_state.go
49 lines (41 loc) · 1.05 KB
/
store_epoch_state.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
package abft
import (
"github.com/Deepchain-foundation/lachesis-base/inter/idx"
"github.com/Deepchain-foundation/lachesis-base/inter/pos"
)
const esKey = "e"
// SetEpochState stores epoch.
func (s *Store) SetEpochState(e *EpochState) {
s.cache.EpochState = e
s.setEpochState([]byte(esKey), e)
}
// GetEpochState returns stored epoch.
func (s *Store) GetEpochState() *EpochState {
if s.cache.EpochState != nil {
return s.cache.EpochState
}
e := s.getEpochState([]byte(esKey))
if e == nil {
s.crit(ErrNoGenesis)
}
s.cache.EpochState = e
return e
}
func (s *Store) setEpochState(key []byte, e *EpochState) {
s.set(s.table.EpochState, key, e)
}
func (s *Store) getEpochState(key []byte) *EpochState {
w, exists := s.get(s.table.EpochState, key, &EpochState{}).(*EpochState)
if !exists {
return nil
}
return w
}
// GetEpoch returns current epoch
func (s *Store) GetEpoch() idx.Epoch {
return s.GetEpochState().Epoch
}
// GetValidators returns current validators
func (s *Store) GetValidators() *pos.Validators {
return s.GetEpochState().Validators
}