@@ -19,21 +19,26 @@ package types
19
19
import (
20
20
"crypto/sha256"
21
21
"fmt"
22
+ "math"
22
23
"os"
24
+ "slices"
23
25
"sort"
24
26
"strconv"
25
27
"strings"
26
28
27
29
"github.com/ethereum/go-ethereum/beacon/merkle"
28
30
"github.com/ethereum/go-ethereum/common"
29
31
"github.com/ethereum/go-ethereum/common/hexutil"
32
+ "github.com/ethereum/go-ethereum/log"
30
33
"gopkg.in/yaml.v3"
31
34
)
32
35
33
36
// syncCommitteeDomain specifies the signatures specific use to avoid clashes
34
37
// across signing different data structures.
35
38
const syncCommitteeDomain = 7
36
39
40
+ var knownForks = []string {"GENESIS" , "ALTAIR" , "BELLATRIX" , "CAPELLA" , "DENEB" }
41
+
37
42
// Fork describes a single beacon chain fork and also stores the calculated
38
43
// signature domain used after this fork.
39
44
type Fork struct {
@@ -46,6 +51,9 @@ type Fork struct {
46
51
// Fork version, see https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#custom-types
47
52
Version []byte
48
53
54
+ // index in list of known forks or MaxInt if unknown
55
+ knownIndex int
56
+
49
57
// calculated by computeDomain, based on fork version and genesis validators root
50
58
domain merkle.Value
51
59
}
@@ -99,9 +107,14 @@ func (f Forks) SigningRoot(header Header) (common.Hash, error) {
99
107
return signingRoot , nil
100
108
}
101
109
102
- func (f Forks ) Len () int { return len (f ) }
103
- func (f Forks ) Swap (i , j int ) { f [i ], f [j ] = f [j ], f [i ] }
104
- func (f Forks ) Less (i , j int ) bool { return f [i ].Epoch < f [j ].Epoch }
110
+ func (f Forks ) Len () int { return len (f ) }
111
+ func (f Forks ) Swap (i , j int ) { f [i ], f [j ] = f [j ], f [i ] }
112
+ func (f Forks ) Less (i , j int ) bool {
113
+ if f [i ].Epoch != f [j ].Epoch {
114
+ return f [i ].Epoch < f [j ].Epoch
115
+ }
116
+ return f [i ].knownIndex < f [j ].knownIndex
117
+ }
105
118
106
119
// ChainConfig contains the beacon chain configuration.
107
120
type ChainConfig struct {
@@ -122,16 +135,22 @@ func (c *ChainConfig) ForkAtEpoch(epoch uint64) Fork {
122
135
123
136
// AddFork adds a new item to the list of forks.
124
137
func (c * ChainConfig ) AddFork (name string , epoch uint64 , version []byte ) * ChainConfig {
138
+ knownIndex := slices .Index (knownForks , name )
139
+ if knownIndex == - 1 {
140
+ knownIndex = math .MaxInt // assume that the unknown fork happens after the known ones
141
+ if epoch != math .MaxUint64 {
142
+ log .Warn ("Unknown fork in config.yaml" , "fork name" , name , "known forks" , knownForks )
143
+ }
144
+ }
125
145
fork := & Fork {
126
- Name : name ,
127
- Epoch : epoch ,
128
- Version : version ,
146
+ Name : name ,
147
+ Epoch : epoch ,
148
+ Version : version ,
149
+ knownIndex : knownIndex ,
129
150
}
130
151
fork .computeDomain (c .GenesisValidatorsRoot )
131
-
132
152
c .Forks = append (c .Forks , fork )
133
153
sort .Sort (c .Forks )
134
-
135
154
return c
136
155
}
137
156
@@ -181,6 +200,5 @@ func (c *ChainConfig) LoadForks(path string) error {
181
200
for name := range versions {
182
201
return fmt .Errorf ("epoch number missing for fork %q in beacon chain config file" , name )
183
202
}
184
- sort .Sort (c .Forks )
185
203
return nil
186
204
}
0 commit comments