-
Notifications
You must be signed in to change notification settings - Fork 107
/
client.go
155 lines (143 loc) · 5.37 KB
/
client.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package beacon
import (
"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/go-bitfield"
"github.com/rocket-pool/rocketpool-go/types"
)
// API request options
type ValidatorStatusOptions struct {
Epoch *uint64
Slot *uint64
}
// API response types
type SyncStatus struct {
Syncing bool
Progress float64
}
type Eth2Config struct {
GenesisForkVersion []byte
GenesisValidatorsRoot []byte
GenesisEpoch uint64
GenesisTime uint64
SecondsPerSlot uint64
SlotsPerEpoch uint64
SecondsPerEpoch uint64
EpochsPerSyncCommitteePeriod uint64
}
type Eth2DepositContract struct {
ChainID uint64
Address common.Address
}
type BeaconHead struct {
Epoch uint64
FinalizedEpoch uint64
JustifiedEpoch uint64
PreviousJustifiedEpoch uint64
}
type ValidatorStatus struct {
Pubkey types.ValidatorPubkey
Index string
WithdrawalCredentials common.Hash
Balance uint64
Status ValidatorState
EffectiveBalance uint64
Slashed bool
ActivationEligibilityEpoch uint64
ActivationEpoch uint64
ExitEpoch uint64
WithdrawableEpoch uint64
Exists bool
}
type Eth1Data struct {
DepositRoot common.Hash
DepositCount uint64
BlockHash common.Hash
}
type BeaconBlock struct {
Slot uint64
ProposerIndex string
HasExecutionPayload bool
Attestations []AttestationInfo
FeeRecipient common.Address
ExecutionBlockNumber uint64
}
type BeaconBlockHeader struct {
Slot uint64
ProposerIndex string
}
// Committees is an interface as an optimization- since committees responses
// are quite large, there's a decent cpu/memory improvement to removing the
// translation to an intermediate storage class.
//
// Instead, the interface provides the access pattern that smartnode (or more
// specifically, tree-gen) wants, and the underlying format is just the format
// of the Beacon Node response.
type Committees interface {
// Index returns the index of the committee at the provided offset
Index(int) uint64
// Slot returns the slot of the committee at the provided offset
Slot(int) uint64
// Validators returns the list of validators of the committee at
// the provided offset
Validators(int) []string
// Count returns the number of committees in the response
Count() int
// Release returns the reused validators slice buffer to the pool for
// further reuse, and must be called when the user is done with this
// committees instance
Release()
}
type AttestationInfo struct {
AggregationBits bitfield.Bitlist
SlotIndex uint64
CommitteeIndex uint64
}
// Beacon client type
type BeaconClientType int
const (
// This client is a traditional "split process" design, where the beacon
// client and validator process are separate and run in different
// containers
SplitProcess BeaconClientType = iota
// This client is a "single process" where the beacon client and
// validator run in the same process (or run as separate processes
// within the same docker container)
SingleProcess
// Unknown / missing client type
Unknown
)
type ValidatorState string
const (
ValidatorState_PendingInitialized ValidatorState = "pending_initialized"
ValidatorState_PendingQueued ValidatorState = "pending_queued"
ValidatorState_ActiveOngoing ValidatorState = "active_ongoing"
ValidatorState_ActiveExiting ValidatorState = "active_exiting"
ValidatorState_ActiveSlashed ValidatorState = "active_slashed"
ValidatorState_ExitedUnslashed ValidatorState = "exited_unslashed"
ValidatorState_ExitedSlashed ValidatorState = "exited_slashed"
ValidatorState_WithdrawalPossible ValidatorState = "withdrawal_possible"
ValidatorState_WithdrawalDone ValidatorState = "withdrawal_done"
)
// Beacon client interface
type Client interface {
GetClientType() (BeaconClientType, error)
GetSyncStatus() (SyncStatus, error)
GetEth2Config() (Eth2Config, error)
GetEth2DepositContract() (Eth2DepositContract, error)
GetAttestations(blockId string) ([]AttestationInfo, bool, error)
GetBeaconBlock(blockId string) (BeaconBlock, bool, error)
GetBeaconBlockHeader(blockId string) (BeaconBlockHeader, bool, error)
GetBeaconHead() (BeaconHead, error)
GetValidatorStatusByIndex(index string, opts *ValidatorStatusOptions) (ValidatorStatus, error)
GetValidatorStatus(pubkey types.ValidatorPubkey, opts *ValidatorStatusOptions) (ValidatorStatus, error)
GetValidatorStatuses(pubkeys []types.ValidatorPubkey, opts *ValidatorStatusOptions) (map[types.ValidatorPubkey]ValidatorStatus, error)
GetValidatorIndex(pubkey types.ValidatorPubkey) (string, error)
GetValidatorSyncDuties(indices []string, epoch uint64) (map[string]bool, error)
GetValidatorProposerDuties(indices []string, epoch uint64) (map[string]uint64, error)
GetDomainData(domainType []byte, epoch uint64, useGenesisFork bool) ([]byte, error)
ExitValidator(validatorIndex string, epoch uint64, signature types.ValidatorSignature) error
Close() error
GetEth1DataForEth2Block(blockId string) (Eth1Data, bool, error)
GetCommitteesForEpoch(epoch *uint64) (Committees, error)
ChangeWithdrawalCredentials(validatorIndex string, fromBlsPubkey types.ValidatorPubkey, toExecutionAddress common.Address, signature types.ValidatorSignature) error
}