mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
properly skipping ommitted values for /eth/v1/config/spec (#15777)
* properly skipping ommitted values * simplifying * Update beacon-chain/rpc/eth/config/handlers.go Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com> * Update beacon-chain/rpc/eth/config/handlers.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * removing omitempty support based on radek's feedback --------- Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
@@ -124,11 +124,21 @@ func convertValueForJSON(v reflect.Value, tag string) interface{} {
|
||||
if !v.Field(i).CanInterface() {
|
||||
continue // unexported
|
||||
}
|
||||
key := f.Tag.Get("json")
|
||||
if key == "" || key == "-" {
|
||||
jsonTag := f.Tag.Get("json")
|
||||
if jsonTag == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse JSON tag options (e.g., "fieldname,omitempty")
|
||||
parts := strings.Split(jsonTag, ",")
|
||||
key := parts[0]
|
||||
|
||||
if key == "" {
|
||||
key = f.Name
|
||||
}
|
||||
m[key] = convertValueForJSON(v.Field(i), tag)
|
||||
|
||||
fieldValue := convertValueForJSON(v.Field(i), tag)
|
||||
m[key] = fieldValue
|
||||
}
|
||||
return m
|
||||
|
||||
|
||||
@@ -692,6 +692,27 @@ func TestGetSpec_BlobSchedule(t *testing.T) {
|
||||
// Check second entry - values should be strings for consistent API output
|
||||
assert.Equal(t, "200", blobSchedule[1]["EPOCH"])
|
||||
assert.Equal(t, "9", blobSchedule[1]["MAX_BLOBS_PER_BLOCK"])
|
||||
|
||||
// Verify that fields with json:"-" are NOT present in the blob schedule entries
|
||||
for i, entry := range blobSchedule {
|
||||
t.Run(fmt.Sprintf("entry_%d_omits_json_dash_fields", i), func(t *testing.T) {
|
||||
// These fields have `json:"-"` in NetworkScheduleEntry and should be omitted
|
||||
_, hasForkVersion := entry["ForkVersion"]
|
||||
assert.Equal(t, false, hasForkVersion, "ForkVersion should be omitted due to json:\"-\"")
|
||||
|
||||
_, hasForkDigest := entry["ForkDigest"]
|
||||
assert.Equal(t, false, hasForkDigest, "ForkDigest should be omitted due to json:\"-\"")
|
||||
|
||||
_, hasBPOEpoch := entry["BPOEpoch"]
|
||||
assert.Equal(t, false, hasBPOEpoch, "BPOEpoch should be omitted due to json:\"-\"")
|
||||
|
||||
_, hasVersionEnum := entry["VersionEnum"]
|
||||
assert.Equal(t, false, hasVersionEnum, "VersionEnum should be omitted due to json:\"-\"")
|
||||
|
||||
_, hasIsFork := entry["isFork"]
|
||||
assert.Equal(t, false, hasIsFork, "isFork should be omitted due to json:\"-\"")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSpec_BlobSchedule_NotFulu(t *testing.T) {
|
||||
|
||||
3
changelog/james-prysm_skip-omit-config-values.md
Normal file
3
changelog/james-prysm_skip-omit-config-values.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### Fixed
|
||||
|
||||
- fix /eth/v1/config/spec endpoint to properly skip omitted values.
|
||||
Reference in New Issue
Block a user