-
Notifications
You must be signed in to change notification settings - Fork 84
/
stateDb.go
47 lines (36 loc) · 1.23 KB
/
stateDb.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
package slotleader
import (
"errors"
"github.com/wanchain/go-wanchain/pos/posconfig"
"github.com/wanchain/go-wanchain/core/state"
)
var (
errNoStateDbInstance = errors.New("Do not have stateDb instance now")
)
// GetCurrentStateDb use to get stateDB instance of current state.
func (s *SLS) GetCurrentStateDb() (stateDb *state.StateDB, err error) {
return s.getCurrentStateDb()
}
func (s *SLS) getCurrentStateDb() (stateDb *state.StateDB, err error) {
if posconfig.SelfTestMode {
return s.stateDbTest, nil
}
return s.blockChain.StateAt(s.blockChain.CurrentBlock().Root())
}
func (s *SLS) getLastEpochIDFromChain() uint64 {
lastEpochID := uint64((s.blockChain.CurrentBlock().Difficulty().Int64() >> 32))
return lastEpochID
}
func (s *SLS) getLastSlotIDFromChain() uint64 {
curSlotID := uint64((s.blockChain.CurrentBlock().Difficulty().Int64() >> 8) & 0x00ffffff)
return curSlotID
}
func (s *SLS) getBlockChainHeight() uint64 {
return s.blockChain.CurrentBlock().NumberU64()
}
func (s *SLS) getBlockTime(number uint64) uint64 {
return s.blockChain.GetBlockByNumber(number).Time().Uint64()
}
func (s *SLS) getEpochIDFromBlockNumber(number uint64) uint64 {
return uint64(s.blockChain.GetBlockByNumber(number).Difficulty().Int64() >> 32)
}