Skip to content
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

Merged
merged 57 commits into from Mar 18, 2024
Merged

Conversation

james-prysm
Copy link
Contributor

@james-prysm james-prysm commented Jan 16, 2024

What type of PR is this?

Feature

What does this PR do? Why is it needed?

https://ethereum.github.io/keymanager-APIs/?urls.primaryName=dev#/Graffiti

this PR introduces the graffiti keymanager API endpoints ( GET,POST,DELETE ). The approach taken here is adding graffiti to the proposer settings to persist. This also means that only the proposer settings will be saved, if a graffiti is passed via flag it will continue even if the keymanager API is called to delete. That being said the proposer settings now take priority and you will be able to see that in the GetGraffiti function.

tests

curl -X POST "http://localhost:7500/eth/v1/validator/0x82f4fca8aacccd676beebda99d662d2e346adcd4f89acb142671f30ded77dda64fc760ef8ed6e62b7bf8cb53dc285778/graffiti" -H "Content-Type: application/json" -d '{"graffiti":"plain text here"}' -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.1cIoNTAywQNDzFT4_f285omZXuzvSnxLozjtDKxqx-E"
curl -X GET "http://localhost:7500/eth/v1/validator/0x82f4fca8aacccd676beebda99d662d2e346adcd4f89acb142671f30ded77dda64fc760ef8ed6e62b7bf8cb53dc285778/graffiti" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.1cIoNTAywQNDzFT4_f285omZXuzvSnxLozjtDKxqx-E"
{"data":{"pubkey":"0x82f4fca8aacccd676beebda99d662d2e346adcd4f89acb142671f30ded77dda64fc760ef8ed6e62b7bf8cb53dc285778","graffiti":"plain text here"}}

Which issues(s) does this PR fix?

Fixes #13188

Other notes for review

@james-prysm james-prysm added API Api related tasks Keymanager-API keymanager-api-standards labels Jan 16, 2024
@james-prysm james-prysm marked this pull request as ready for review January 18, 2024 19:59
@james-prysm james-prysm requested a review from a team as a code owner January 18, 2024 19:59
Copy link
Contributor

@rkapka rkapka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove half-written test

@@ -90,6 +91,7 @@ func (_ *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerC
type Validator struct {
Km keymanager.IKeymanager
proposerSettings *validatorserviceconfig.ProposerSettings
Graffiti string
Copy link
Contributor

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.

Comment on lines 220 to 222
if m.Graffiti == "" {
return nil, errors.New("graffiti is missing ")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would not having a graffiti produce an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

validator/client/propose.go Outdated Show resolved Hide resolved
validator/client/propose.go Outdated Show resolved Hide resolved
@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually handle error conditions first. I would rewrite the code as

if v.proposerSettings == nil {
  // error
}
if v.proposerSettings.ProposeConfig == nil {
  // error
}
ps := v.proposerSettings.Clone()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yeah i should do it this way

}

func (v *validator) DeleteGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) error {
if v.proposerSettings != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -55,6 +55,7 @@ type FakeValidator struct {
proposerSettings *validatorserviceconfig.ProposerSettings
ProposerSettingWait time.Duration
Km keymanager.IKeymanager
Graffiti string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export

validator/rpc/handlers_keymanager.go Outdated Show resolved Hide resolved
validator/rpc/handlers_keymanager_test.go Outdated Show resolved Hide resolved
james-prysm and others added 2 commits January 22, 2024 11:52
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
return v.SetProposerSettings(ctx, settings)
}
ps := settings.Clone()
var option *proposer.Option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed.

option.GraffitiConfig = &proposer.GraffitiConfig{
Graffiti: string(graffiti),
}
ps.ProposeConfig[pubkey] = option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line does not break any test.

@@ -264,6 +264,7 @@ func (c *ValidatorClient) initializeFromCLI(cliCtx *cli.Context, router *mux.Rou
if isWeb3SignerURLFlagSet {
c.wallet = wallet.NewWalletForWeb3Signer()
} else {
fmt.Println("initializeFromCLI asking for wallet")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a fmt.Println?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a mistake from debugging , should remove

nalepae
nalepae previously approved these changes Mar 13, 2024
@james-prysm james-prysm requested a review from rkapka March 13, 2024 12:57
@james-prysm james-prysm added this pull request to the merge queue Mar 18, 2024
Merged via the queue into develop with commit 7f931bf Mar 18, 2024
16 of 17 checks passed
@james-prysm james-prysm deleted the graffiti-keymanager-api branch March 18, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Keymanager-API keymanager-api-standards
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keymanager API: GET,POST,DELETE Graffiti
4 participants