-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
105 lines (93 loc) · 3.01 KB
/
config.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
package beacon
import (
"context"
"fmt"
"reflect"
"strconv"
"strings"
"github.com/theQRL/go-zond/common/hexutil"
"github.com/theQRL/qrysm/v4/config/params"
"github.com/theQRL/qrysm/v4/network/forks"
zondpb "github.com/theQRL/qrysm/v4/proto/zond/v1"
"go.opencensus.io/trace"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
)
// GetForkSchedule retrieve all scheduled upcoming forks this node is aware of.
func (_ *Server) GetForkSchedule(ctx context.Context, _ *emptypb.Empty) (*zondpb.ForkScheduleResponse, error) {
ctx, span := trace.StartSpan(ctx, "beacon.GetForkSchedule")
defer span.End()
schedule := params.BeaconConfig().ForkVersionSchedule
if len(schedule) == 0 {
return &zondpb.ForkScheduleResponse{
Data: make([]*zondpb.Fork, 0),
}, nil
}
versions := forks.SortedForkVersions(schedule)
chainForks := make([]*zondpb.Fork, len(schedule))
var previous, current []byte
for i, v := range versions {
if i == 0 {
previous = params.BeaconConfig().GenesisForkVersion
} else {
previous = current
}
copyV := v
current = copyV[:]
chainForks[i] = &zondpb.Fork{
PreviousVersion: previous,
CurrentVersion: current,
Epoch: schedule[v],
}
}
return &zondpb.ForkScheduleResponse{
Data: chainForks,
}, nil
}
// GetSpec retrieves specification configuration (without Phase 1 params) used on this node. Specification params list
// Values are returned with following format:
// - any value starting with 0x in the spec is returned as a hex string.
// - all other values are returned as number.
func (_ *Server) GetSpec(ctx context.Context, _ *emptypb.Empty) (*zondpb.SpecResponse, error) {
ctx, span := trace.StartSpan(ctx, "beacon.GetSpec")
defer span.End()
data, err := prepareConfigSpec()
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to prepare spec data: %v", err)
}
return &zondpb.SpecResponse{Data: data}, nil
}
func prepareConfigSpec() (map[string]string, error) {
data := make(map[string]string)
config := *params.BeaconConfig()
t := reflect.TypeOf(config)
v := reflect.ValueOf(config)
for i := 0; i < t.NumField(); i++ {
tField := t.Field(i)
_, isSpecField := tField.Tag.Lookup("spec")
if !isSpecField {
// Field should not be returned from API.
continue
}
tagValue := strings.ToUpper(tField.Tag.Get("yaml"))
vField := v.Field(i)
switch vField.Kind() {
case reflect.Int:
data[tagValue] = strconv.FormatInt(vField.Int(), 10)
case reflect.Uint64:
data[tagValue] = strconv.FormatUint(vField.Uint(), 10)
case reflect.Slice:
data[tagValue] = hexutil.Encode(vField.Bytes())
case reflect.Array:
data[tagValue] = hexutil.Encode(reflect.ValueOf(&config).Elem().Field(i).Slice(0, vField.Len()).Bytes())
case reflect.String:
data[tagValue] = vField.String()
case reflect.Uint8:
data[tagValue] = hexutil.Encode([]byte{uint8(vField.Uint())})
default:
return nil, fmt.Errorf("unsupported config field type: %s", vField.Kind().String())
}
}
return data, nil
}