Skip to content

Commit

Permalink
Handle upstream change of epoch serialization for metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 23, 2025
1 parent 1a6098c commit c863f9b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.8.7:
0.8.8:
- handle upstream change of epoch serialization for metadata
- do not error on deposit transactions containing events without topics

0.8.6:
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import (
)

// ReleaseVersion is the release version for the code.
var ReleaseVersion = "0.8.7"
var ReleaseVersion = "0.8.8"

func main() {
os.Exit(main2())
Expand Down
21 changes: 20 additions & 1 deletion services/summarizer/standard/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ func (s *Service) getMetadata(ctx context.Context) (*metadata, error) {
return md, nil
}
if err := json.Unmarshal(mdJSON, md); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal metadata")
// Assume this is the old format.
omd := &oldmetadata{}
if err := json.Unmarshal(mdJSON, omd); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal metadata")
}
// Convert to new format.
md.LastValidatorEpoch = phase0.Epoch(omd.LastValidatorEpoch)
md.LastBlockEpoch = phase0.Epoch(omd.LastBlockEpoch)
md.LastEpoch = phase0.Epoch(omd.LastEpoch)
md.LastValidatorDay = omd.LastValidatorDay
md.PeriodicValidatorRollups = omd.PeriodicValidatorRollups
}

return md, nil
Expand All @@ -63,3 +73,12 @@ func (s *Service) setMetadata(ctx context.Context, md *metadata) error {
}
return nil
}

// oldmetadata is pre-0.8.8 metadata using unquoted strings for epochs.
type oldmetadata struct {
LastValidatorEpoch uint64 `json:"latest_validator_epoch"`
LastBlockEpoch uint64 `json:"latest_block_epoch"`
LastEpoch uint64 `json:"latest_epoch"`
LastValidatorDay int64 `json:"last_validator_day"`
PeriodicValidatorRollups bool `json:"periodic_validator_rollups"`
}
21 changes: 20 additions & 1 deletion services/validators/standard/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,20 @@ func (s *Service) getMetadata(ctx context.Context) (*metadata, error) {
return md, nil
}
if err := json.Unmarshal(mdJSON, md); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal metadata")
// Assume this is the old format.
omd := &oldmetadata{}
if err := json.Unmarshal(mdJSON, omd); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal metadata")
}
// Convert to new format.
md.LatestEpoch = phase0.Epoch(omd.LatestEpoch)
md.LatestBalancesEpoch = phase0.Epoch(omd.LatestBalancesEpoch)
md.MissedEpochs = make([]phase0.Epoch, len(omd.MissedEpochs))
for i := range omd.MissedEpochs {
md.MissedEpochs[i] = phase0.Epoch(omd.MissedEpochs[i])
}
}

return md, nil
}

Expand All @@ -58,3 +70,10 @@ func (s *Service) setMetadata(ctx context.Context, md *metadata) error {
}
return nil
}

// oldmetadata is pre-0.8.8 metadata using unquoted strings for epochs.
type oldmetadata struct {
LatestEpoch uint64 `json:"latest_epoch"`
LatestBalancesEpoch uint64 `json:"latest_balances_epoch"`
MissedEpochs []uint64 `json:"missed_epochs,omitempty"`
}

0 comments on commit c863f9b

Please sign in to comment.