-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keymanager APIs - get,post,delete graffiti #13474
Changes from 14 commits
02d99b2
b3f2d52
6954e6c
a619275
3a67b18
c4a68de
9d09686
6163564
8fa12b4
33fbd8f
4fb7c0a
30204c1
2ba1d90
357ecb2
77c2329
4a82c2d
ab1ec5d
aa34ba5
a58f927
5f28c9c
feb1a98
f01b04c
558fbee
ba26d89
2df8437
0ef666f
b83a12b
e9d26e3
e9af279
ec61a61
41e6cfb
cafc2bc
0a76ad9
74e2a01
499b2bd
352cf4c
0472a99
8fe24d6
021ccdb
6a47352
94eb5d7
0ff6520
8cff0ac
2e51b34
2d50abf
98b3712
9ad18fa
44b37db
ca16050
d5e1f6d
0aaeea0
3341883
46ec87c
c03f501
ebb136c
01278b1
752af27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"sync" | ||
"time" | ||
|
||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" | ||
validatorserviceconfig "github.com/prysmaticlabs/prysm/v4/config/validator/service" | ||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" | ||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" | ||
|
@@ -90,6 +91,7 @@ func (_ *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerC | |
type Validator struct { | ||
Km keymanager.IKeymanager | ||
proposerSettings *validatorserviceconfig.ProposerSettings | ||
Graffiti string | ||
} | ||
|
||
func (_ *Validator) LogSyncCommitteeMessagesSubmitted() {} | ||
|
@@ -213,6 +215,26 @@ func (m *Validator) SetProposerSettings(_ context.Context, settings *validatorse | |
return nil | ||
} | ||
|
||
// GetGraffiti for mocking | ||
func (m *Validator) GetGraffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte) ([]byte, error) { | ||
if m.Graffiti == "" { | ||
return nil, errors.New("graffiti is missing ") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would not having a graffiti produce an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was just for the mock, but i'll think of a better way to represent |
||
return []byte(m.Graffiti), nil | ||
} | ||
|
||
// SetGraffiti for mocking | ||
func (m *Validator) SetGraffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte, graffiti []byte) error { | ||
m.Graffiti = string(graffiti) | ||
return nil | ||
} | ||
|
||
// DeleteGraffiti for mocking | ||
func (m *Validator) DeleteGraffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte) error { | ||
m.Graffiti = "" | ||
return nil | ||
} | ||
|
||
func (_ *Validator) StartEventStream(_ context.Context) error { | ||
panic("implement me") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,14 @@ import ( | |
"fmt" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/golang/protobuf/ptypes/timestamp" | ||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/v4/async" | ||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/signing" | ||
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" | ||
"github.com/prysmaticlabs/prysm/v4/config/params" | ||
validatorserviceconfig "github.com/prysmaticlabs/prysm/v4/config/validator/service" | ||
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks" | ||
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" | ||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" | ||
|
@@ -64,7 +66,7 @@ func (v *validator) ProposeBlock(ctx context.Context, slot primitives.Slot, pubK | |
return | ||
} | ||
|
||
g, err := v.getGraffiti(ctx, pubKey) | ||
g, err := v.GetGraffiti(ctx, pubKey) | ||
if err != nil { | ||
// Graffiti is not a critical enough to fail block production and cause | ||
// validator to miss block reward. When failed, validator should continue | ||
|
@@ -382,9 +384,24 @@ func signVoluntaryExit( | |
return sig.Marshal(), nil | ||
} | ||
|
||
// Gets the graffiti from cli or file for the validator public key. | ||
func (v *validator) getGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) ([]byte, error) { | ||
// When specified, default graffiti from the command line takes the first priority. | ||
// GetGraffiti Gets the graffiti from cli or file for the validator public key. | ||
james-prysm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (v *validator) GetGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) ([]byte, error) { | ||
// Check proposer settings first | ||
if v.proposerSettings != nil { | ||
if v.proposerSettings.ProposeConfig != nil { | ||
option, ok := v.proposerSettings.ProposeConfig[pubKey] | ||
if ok && option.Graffiti != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why checking if |
||
return []byte(option.Graffiti), nil | ||
} | ||
} | ||
if v.proposerSettings.DefaultConfig != nil { | ||
if v.proposerSettings.DefaultConfig.Graffiti != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here, even if I agree it has less sense... |
||
return []byte(v.proposerSettings.DefaultConfig.Graffiti), nil | ||
} | ||
} | ||
} | ||
|
||
// When specified, default graffiti from the command line takes the second priority. | ||
james-prysm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(v.graffiti) != 0 { | ||
return bytesutil.PadTo(v.graffiti, 32), nil | ||
} | ||
|
@@ -393,7 +410,7 @@ func (v *validator) getGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubk | |
return nil, errors.New("graffitiStruct can't be nil") | ||
} | ||
|
||
// When specified, individual validator specified graffiti takes the second priority. | ||
// When specified, individual validator specified graffiti takes the third priority. | ||
nalepae marked this conversation as resolved.
Show resolved
Hide resolved
|
||
idx, err := v.validatorClient.ValidatorIndex(ctx, ðpb.ValidatorIndexRequest{PublicKey: pubKey[:]}) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -403,7 +420,7 @@ func (v *validator) getGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubk | |
return bytesutil.PadTo([]byte(g), 32), nil | ||
} | ||
|
||
// When specified, a graffiti from the ordered list in the file take third priority. | ||
// When specified, a graffiti from the ordered list in the file take fourth priority. | ||
if v.graffitiOrderedIndex < uint64(len(v.graffitiStruct.Ordered)) { | ||
graffiti := v.graffitiStruct.Ordered[v.graffitiOrderedIndex] | ||
v.graffitiOrderedIndex = v.graffitiOrderedIndex + 1 | ||
|
@@ -414,7 +431,7 @@ func (v *validator) getGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubk | |
return bytesutil.PadTo([]byte(graffiti), 32), nil | ||
} | ||
|
||
// When specified, a graffiti from the random list in the file take fourth priority. | ||
// When specified, a graffiti from the random list in the file take Fifth priority. | ||
if len(v.graffitiStruct.Random) != 0 { | ||
r := rand.NewGenerator() | ||
r.Seed(time.Now().Unix()) | ||
|
@@ -429,3 +446,34 @@ func (v *validator) getGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubk | |
|
||
return []byte{}, nil | ||
} | ||
|
||
func (v *validator) SetGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, graffiti []byte) error { | ||
if v.proposerSettings != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually handle error conditions first. I would rewrite the code as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops yeah i should do it this way |
||
ps := v.proposerSettings.Clone() | ||
if ps.ProposeConfig != nil { | ||
var option *validatorserviceconfig.ProposerOption | ||
option, ok := ps.ProposeConfig[pubKey] | ||
if ok && option != nil { | ||
option.Graffiti = string(graffiti) | ||
return v.SetProposerSettings(ctx, ps) // save the proposer settings | ||
} | ||
return fmt.Errorf("attempted to set graffiti but proposer settings are missing for pubkey:%s", hexutil.Encode(pubKey[:])) | ||
} | ||
} | ||
return errors.New("attempted to set graffiti without proposer settings, graffiti will default to flag options") | ||
} | ||
|
||
func (v *validator) DeleteGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) error { | ||
if v.proposerSettings != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
ps := v.proposerSettings.Clone() | ||
if ps.ProposeConfig != nil { | ||
option, ok := ps.ProposeConfig[pubKey] | ||
if ok && option != nil { | ||
option.Graffiti = "" | ||
return v.SetProposerSettings(ctx, ps) // save the proposer settings | ||
} | ||
return fmt.Errorf("graffiti not found in proposer settings for pubkey:%s", hexutil.Encode(pubKey[:])) | ||
} | ||
} | ||
return errors.New("attempted to delete graffiti without proposer settings, graffiti will default to flag options") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field should not be exported because we have a setter.