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: fee recipient api #10850

Merged
merged 82 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
e7acddd
initial commit wip
james-prysm Apr 22, 2022
ac5f25b
setting protos for fee recipient
james-prysm Apr 22, 2022
ec3e73e
updating proto based on specs
james-prysm May 9, 2022
5bcb713
updating apimiddleware
james-prysm May 9, 2022
88f64be
generated APIs
james-prysm May 9, 2022
c6191f9
updating proto to fit spec
james-prysm May 23, 2022
d946061
fixing naming of fields
james-prysm May 23, 2022
a66ae3c
fixing endpoint_factory and associated structs
james-prysm May 23, 2022
d27f065
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 8, 2022
b00c002
fixing imports
james-prysm Jun 8, 2022
1376772
adding in custom http types to grpc gateway
james-prysm Jun 9, 2022
222ce1a
adding import options
james-prysm Jun 9, 2022
b65a472
changing package option
james-prysm Jun 9, 2022
d93aedc
still testing protos
james-prysm Jun 9, 2022
e1533bd
adding to bazel
james-prysm Jun 9, 2022
e43a502
testing dependency changes
james-prysm Jun 9, 2022
b4bb525
more tests
james-prysm Jun 9, 2022
580ce8c
more tests
james-prysm Jun 9, 2022
b296914
more tests
james-prysm Jun 9, 2022
12859d6
more tests
james-prysm Jun 9, 2022
4d62322
more tests
james-prysm Jun 9, 2022
69e784f
more tests
james-prysm Jun 9, 2022
f51e668
testing changing repo dep
james-prysm Jun 9, 2022
90be29b
testing deps
james-prysm Jun 9, 2022
e7e3341
testing deps
james-prysm Jun 9, 2022
8807a57
testing deps
james-prysm Jun 9, 2022
a30f1f5
testing deps
james-prysm Jun 9, 2022
f63a05d
testing deps
james-prysm Jun 9, 2022
98476fc
testing deps
james-prysm Jun 9, 2022
732b940
reverting
james-prysm Jun 9, 2022
b64ee9d
testing import
james-prysm Jun 9, 2022
8804d93
testing bazel
james-prysm Jun 9, 2022
6df733f
bazel test
james-prysm Jun 9, 2022
ed97fa3
testing
james-prysm Jun 9, 2022
a4e02d2
testing
james-prysm Jun 9, 2022
5386c6a
testing import
james-prysm Jun 9, 2022
d03afdb
updating generated proto code
james-prysm Jun 9, 2022
96912c3
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 12, 2022
b2d6be6
wip set fee recipient by pubkey
james-prysm Jun 13, 2022
e1a4ae0
adding list fee recipient logic
james-prysm Jun 13, 2022
73b4c78
fixing thrown error
james-prysm Jun 13, 2022
c92c78d
fixing bug with API
james-prysm Jun 13, 2022
03d5581
fee recipient delete function
james-prysm Jun 13, 2022
795fedd
updating generated proto logic
james-prysm Jun 13, 2022
e969c5d
fixing deposit api and adding postman tests
james-prysm Jun 13, 2022
50e9002
fixing proto imports
james-prysm Jun 13, 2022
c151df7
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 13, 2022
f5e387b
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 13, 2022
b7ef7d3
fixing unit tests and checksums
james-prysm Jun 14, 2022
b511d09
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 14, 2022
6d89075
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 14, 2022
6f860fd
fixing test
james-prysm Jun 14, 2022
bea1ab7
adding unit tests
james-prysm Jun 14, 2022
6ef5e6a
fixing bazel
james-prysm Jun 14, 2022
c846d30
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 14, 2022
030c62f
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 15, 2022
41751b0
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 15, 2022
60b7866
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 15, 2022
f0b0e07
Update validator/rpc/standard_api.go
james-prysm Jun 15, 2022
6cfc938
Update validator/rpc/standard_api.go
james-prysm Jun 15, 2022
47821d7
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 15, 2022
9b781b7
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 15, 2022
b3c03f4
resolving review comments
james-prysm Jun 15, 2022
80296a8
fixing return
james-prysm Jun 15, 2022
c24f6f9
Update config/validator/service/proposer-settings.go
james-prysm Jun 15, 2022
541d75e
Update validator/rpc/standard_api.go
james-prysm Jun 15, 2022
3ca894a
Update validator/rpc/standard_api.go
james-prysm Jun 15, 2022
7327a02
updating proto
james-prysm Jun 15, 2022
93e9cff
updating message name
james-prysm Jun 15, 2022
5e5dede
fixing imports
james-prysm Jun 15, 2022
d7933ad
updating based on review comments
james-prysm Jun 15, 2022
679a6fc
adding middleware unit tests
james-prysm Jun 15, 2022
e092e12
capitalizing errors
james-prysm Jun 15, 2022
27e296e
using error instead of errorf
james-prysm Jun 15, 2022
fed4183
fixing missed unit test variable rename
james-prysm Jun 15, 2022
1b4821f
fixing format variable
james-prysm Jun 15, 2022
66be1d8
fixing unit test
james-prysm Jun 15, 2022
7180227
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 15, 2022
e997bb8
Merge branch 'develop' into fee-recipient-api
james-prysm Jun 16, 2022
19439f8
Update validator/rpc/standard_api.go
rkapka Jun 16, 2022
f8ed886
Update validator/rpc/standard_api.go
rkapka Jun 16, 2022
bf7181b
Merge refs/heads/develop into fee-recipient-api
prylabs-bulldozer[bot] Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/gateway/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"gateway.go",
"log.go",
"modifiers.go",
"options.go",
],
importpath = "github.com/prysmaticlabs/prysm/api/gateway",
Expand All @@ -23,6 +24,7 @@ go_library(
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//connectivity:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

Expand Down
1 change: 1 addition & 0 deletions api/gateway/apimiddleware/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
deps = [
"//api/grpc:go_default_library",
"//encoding/bytesutil:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_gorilla_mux//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion api/gateway/apimiddleware/api_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (m *ApiProxyMiddleware) WithMiddleware(path string) http.HandlerFunc {
}
}

if req.Method == "DELETE" {
if req.Method == "DELETE" && req.Body != http.NoBody {
rkapka marked this conversation as resolved.
Show resolved Hide resolved
if errJson := handleDeleteRequestForEndpoint(endpoint, req); errJson != nil {
WriteError(w, errJson, nil)
return
Expand Down
15 changes: 15 additions & 0 deletions api/gateway/apimiddleware/process_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/wealdtech/go-bytesutil"
Expand Down Expand Up @@ -100,6 +101,20 @@ func base64ToHexProcessor(v reflect.Value) error {
return nil
}

func base64ToChecksumAddressProcessor(v reflect.Value) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add unit tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to process_request_test.go

if v.String() == "" {
// Empty hex values are represented as "0x".
v.SetString("0x")
return nil
}
b, err := base64.StdEncoding.DecodeString(v.String())
if err != nil {
return err
}
v.SetString(common.BytesToAddress(b).Hex())
return nil
}

func base64ToUint256Processor(v reflect.Value) error {
if v.String() == "" {
return nil
Expand Down
4 changes: 4 additions & 0 deletions api/gateway/apimiddleware/process_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func ProcessMiddlewareResponseFields(responseContainer interface{}) ErrorJson {
tag: "hex",
f: base64ToHexProcessor,
},
{
tag: "address",
f: base64ToChecksumAddressProcessor,
},
{
tag: "enum",
f: enumToLowercaseProcessor,
Expand Down
30 changes: 18 additions & 12 deletions api/gateway/apimiddleware/process_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ func defaultRequestContainer() *testRequestContainer {
}

type testResponseContainer struct {
TestString string
TestHex string `hex:"true"`
TestEmptyHex string `hex:"true"`
TestUint256 string `uint256:"true"`
TestEnum string `enum:"true"`
TestTime string `time:"true"`
TestString string
TestHex string `hex:"true"`
TestEmptyHex string `hex:"true"`
TestAddress string `address:"true"`
TestEmptyAddress string `address:"true"`
TestUint256 string `uint256:"true"`
TestEnum string `enum:"true"`
TestTime string `time:"true"`
}

func defaultResponseContainer() *testResponseContainer {
return &testResponseContainer{
TestString: "test string",
TestHex: "Zm9v", // base64 encoding of "foo"
TestEmptyHex: "",
TestEnum: "Test Enum",
TestTime: "2006-01-02T15:04:05Z",
TestString: "test string",
TestHex: "Zm9v", // base64 encoding of "foo"
TestEmptyHex: "",
TestAddress: "Zm9v",
TestEmptyAddress: "",
TestEnum: "Test Enum",
TestTime: "2006-01-02T15:04:05Z",

// base64 encoding of 4196 in little-endian
TestUint256: "ZBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
Expand Down Expand Up @@ -247,6 +251,8 @@ func TestProcessMiddlewareResponseFields(t *testing.T) {
require.Equal(t, true, errJson == nil)
assert.Equal(t, "0x666f6f", container.TestHex)
assert.Equal(t, "0x", container.TestEmptyHex)
assert.Equal(t, "0x0000000000000000000000000000000000666F6f", container.TestAddress)
assert.Equal(t, "0x", container.TestEmptyAddress)
assert.Equal(t, "4196", container.TestUint256)
assert.Equal(t, "test enum", container.TestEnum)
assert.Equal(t, "1136214245", container.TestTime)
Expand Down Expand Up @@ -292,7 +298,7 @@ func TestWriteMiddlewareResponseHeadersAndBody(t *testing.T) {
v, ok = writer.Header()["Content-Length"]
require.Equal(t, true, ok, "header not found")
require.Equal(t, 1, len(v), "wrong number of header values")
assert.Equal(t, "181", v[0])
assert.Equal(t, "224", v[0])
assert.Equal(t, 204, writer.Code)
assert.DeepEqual(t, responseJson, writer.Body.Bytes())
})
Expand Down
30 changes: 30 additions & 0 deletions api/gateway/modifiers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gateway

import (
"context"
"net/http"
"strconv"

gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/protobuf/proto"
)

func HttpResponseModifier(ctx context.Context, w http.ResponseWriter, resp proto.Message) error {
md, ok := gwruntime.ServerMetadataFromContext(ctx)
if !ok {
return nil
}
// set http status code
if vals := md.HeaderMD.Get("x-http-code"); len(vals) > 0 {
code, err := strconv.Atoi(vals[0])
if err != nil {
return err
}
// delete the headers to not expose any grpc-metadata in http response
delete(md.HeaderMD, "x-http-code")
delete(w.Header(), "Grpc-Metadata-X-Http-Code")
w.WriteHeader(code)
}

return nil
}
1 change: 1 addition & 0 deletions config/validator/service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
],
)
9 changes: 9 additions & 0 deletions config/validator/service/proposer-settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validator_service_config
import (
"github.com/ethereum/go-ethereum/common"
field_params "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params"
)

// ProposerSettingsPayload is the struct representation of the JSON or YAML payload set in the validator through the CLI.
Expand Down Expand Up @@ -33,3 +34,11 @@ type ProposerOption struct {
FeeRecipient common.Address
GasLimit uint64
}

// DefaultProposerOption returns a Proposer Option with defaults filled
func DefaultProposerOption() ProposerOption {
return ProposerOption{
FeeRecipient: params.BeaconConfig().DefaultFeeRecipient,
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
}
}
112 changes: 112 additions & 0 deletions hack/keymanager-api/keymanager-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,118 @@
}
},
"response": []
},
{
"name": "get fee recipient",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.ck3J6tcvHcI74IiFjyJqcBH-MmNAq-fMr0ncyZkGvFM",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "default"
}
],
"url": {
"raw": "localhost:7500/eth/v1/validator/0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591494/feerecipient",
"host": [
"localhost"
],
"port": "7500",
"path": [
"eth",
"v1",
"validator",
"0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591494",
"feerecipient"
]
}
},
"response": []
},
{
"name": "set fee recipient",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.ck3J6tcvHcI74IiFjyJqcBH-MmNAq-fMr0ncyZkGvFM",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"ethaddress\":\"0x046FB65722E7b2455012bfebF6177F4d2e9738D9\"\n}\n"
},
"url": {
"raw": "localhost:7500/eth/v1/validator/0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591494/feerecipient",
"host": [
"localhost"
],
"port": "7500",
"path": [
"eth",
"v1",
"validator",
"0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591494",
"feerecipient"
]
}
},
"response": []
},
{
"name": "delete fee recipient",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.ck3J6tcvHcI74IiFjyJqcBH-MmNAq-fMr0ncyZkGvFM",
"type": "string"
}
]
},
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "default"
}
],
"url": {
"raw": "localhost:7500/eth/v1/validator/0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591494/feerecipient",
"host": [
"localhost"
],
"port": "7500",
"path": [
"eth",
"v1",
"validator",
"0xaf2e7ba294e03438ea819bd4033c6c1bf6b04320ee2075b77273c08d02f8a61bcc303c2c06bd3713cb442072ae591494",
"feerecipient"
]
}
},
"response": []
}
]
}
Loading