-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixedschedule.go
62 lines (49 loc) · 1.58 KB
/
fixedschedule.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
package shardingconfig
import (
"math/big"
)
const (
// VLBPE is a Very Large Block Per Epoch
VLBPE = 1000000000000
)
type fixedSchedule struct {
instance Instance
}
// InstanceForEpoch returns the fixed sharding configuration instance regardless
// the given epoch.
func (s fixedSchedule) InstanceForEpoch(epoch *big.Int) Instance {
return s.instance
}
func (s fixedSchedule) BlocksPerEpoch() uint64 {
return VLBPE
}
func (s fixedSchedule) CalcEpochNumber(blockNum uint64) *big.Int {
return big.NewInt(int64(blockNum / s.BlocksPerEpoch()))
}
func (s fixedSchedule) IsLastBlock(blockNum uint64) bool {
blocks := s.BlocksPerEpoch()
return blockNum%blocks == blocks-1
}
func (s fixedSchedule) EpochLastBlock(epochNum uint64) uint64 {
blocks := s.BlocksPerEpoch()
return blocks*(epochNum+1) - 1
}
func (s fixedSchedule) VdfDifficulty() int {
return mainnetVdfDifficulty
}
func (s fixedSchedule) GetNetworkID() NetworkID {
return DevNet
}
// GetShardingStructure is the sharding structure for fixed schedule.
func (s fixedSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, TestNetHTTPPattern, TestNetHTTPPattern)
}
// IsSkippedEpoch returns if an epoch was skipped on shard due to staking epoch
func (s fixedSchedule) IsSkippedEpoch(shardID uint32, epoch *big.Int) bool {
return false
}
// NewFixedSchedule returns a sharding configuration schedule that uses the
// given config instance for all epochs. Useful for testing.
func NewFixedSchedule(instance Instance) Schedule {
return fixedSchedule{instance: instance}
}