This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
/
variants.go
136 lines (122 loc) 路 4.02 KB
/
variants.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package builders
import (
"fmt"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/test-vectors/schema"
)
// ProtocolVersion represents a protocol upgrade we track.
type ProtocolVersion struct {
// ID is the code name of the version. It is output as a selector
// on vectors.
ID string
// Height is the height at which the version activates. It is used to
// calculate the variant's epoch.
FirstEpoch abi.ChainEpoch
// Network is the network version. It is output on the variant's epoch.
Network network.Version
// StateTree is the state tree version.
StateTree types.StateTreeVersion
// Actors is the actors version.
Actors actors.Version
// ZeroStateTree is the constructor of the initial state tree, including
// singleton system actors.
ZeroStateTree func(*StateTracker, schema.Selector)
}
// KnownProtocolVersions enumerates the protocol versions we're capable of
// generating test vectors against.
var KnownProtocolVersions = []ProtocolVersion{
{
ID: "genesis",
FirstEpoch: 1,
StateTree: types.StateTreeVersion0,
Network: network.Version0,
Actors: actors.Version0,
ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
},
{
ID: "breeze",
FirstEpoch: build.UpgradeBreezeHeight + 1,
StateTree: types.StateTreeVersion0,
Network: network.Version1,
Actors: actors.Version0,
ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
}, {
ID: "smoke",
FirstEpoch: build.UpgradeSmokeHeight + 1,
StateTree: types.StateTreeVersion0,
Network: network.Version2,
Actors: actors.Version0,
ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
}, {
ID: "ignition",
FirstEpoch: build.UpgradeIgnitionHeight + 1,
StateTree: types.StateTreeVersion0,
Network: network.Version3,
Actors: actors.Version0,
ZeroStateTree: (*StateTracker).ActorsZeroStateV0,
}, {
ID: "actorsv2",
FirstEpoch: build.UpgradeActorsV2Height + 1,
StateTree: types.StateTreeVersion1,
Network: network.Version4,
Actors: actors.Version2,
ZeroStateTree: (*StateTracker).ActorsZeroStateV2,
},
{
ID: "tape",
FirstEpoch: build.UpgradeTapeHeight + 1,
StateTree: types.StateTreeVersion1,
Network: network.Version5,
Actors: actors.Version2,
ZeroStateTree: (*StateTracker).ActorsZeroStateV2,
},
{
ID: "liftoff",
FirstEpoch: build.UpgradeLiftoffHeight + 1,
StateTree: types.StateTreeVersion1,
Network: network.Version5,
Actors: actors.Version2,
ZeroStateTree: (*StateTracker).ActorsZeroStateV2,
},
}
// KnownProtocolVersionsFrom returns all protocol versions known starting from
// the protocol version with the supplied ID, it inclusive.
func KnownProtocolVersionsFrom(id string) []ProtocolVersion {
for i, pv := range KnownProtocolVersions {
if pv.ID == id {
return KnownProtocolVersions[i:]
}
}
panic(fmt.Sprintf("unknown protocol version: %s", id))
}
// KnownProtocolVersionsBefore returns all protocol versions known until the
// protocol version with the supplied ID, it exclusive.
func KnownProtocolVersionsBefore(id string) []ProtocolVersion {
for i, pv := range KnownProtocolVersions {
if pv.ID == id {
return KnownProtocolVersions[0:i]
}
}
panic(fmt.Sprintf("unknown protocol version: %s", id))
}
// KnownProtocolVersionsBetween returns all protocol versions known between the
// supplied range, both inclusive.
func KnownProtocolVersionsBetween(from, to string) []ProtocolVersion {
start, end := -1, -1
for i, pv := range KnownProtocolVersions {
if pv.ID == from {
start = i
}
if pv.ID == to {
end = i
}
}
if start == -1 || end == -1 {
panic(fmt.Sprintf("at least one unknown protocol version: %s, %s", from, to))
}
return KnownProtocolVersions[start : end+1]
}