prysm-pulse/validator/slashing-protection/local/standard-protection-format/format.go

45 lines
1.8 KiB
Go
Raw Normal View History

Implement Standard Slashing Protection JSON With Importing Logic (#7675) * Use new attestation protection * tests fixes * fix tests * fix comment * fix TestSetTargetData * fix tests * empty history handling * fix another test * mock domain request * fix empty handling * use far future epoch * use far future epoch * migrate data * copy byte array to resolve sigbus error * init validator protection on pre validation * Import interchange json * Import interchange json * reduce visibility * use return value * raul feedback * rename fixes * import test * checkout att v2 changes * define import method for interchange format in its own package * rename and made operations atomic * eip comment * begin amending test file * finish happy path for import tests * attempt the interchange import tests * fixed tests * happy and sad paths tested * good error messages * fix up comment with proper eip link * tests for helpers * helpers * all tests pass * proper test comment * terence feedback * validate metadata func * versioning check * begin handling duplicatesz * handle duplicate public keys with potentially different data, first pass * better handling of duplicate data * ensure duplicates are taken care of * comprehensive tests for deduplication of signed blocks * tests for deduplication * Update validator/slashing-protection/local/standard-protection-format/helpers_test.go Co-authored-by: Shay Zluf <thezluf@gmail.com> * Update validator/slashing-protection/local/standard-protection-format/helpers_test.go Co-authored-by: Shay Zluf <thezluf@gmail.com> * tests for maxuint64 and package level comment * tests passing * edge cases pass Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2020-11-17 22:37:43 +00:00
// Package interchangeformat defines methods to parse, import, and export slashing protection data
// from a standard JSON file according to EIP-3076 https://eips.ethereum.org/EIPS/eip-3076. This format
// is critical to allow safe interoperability between eth2 clients.
package interchangeformat
import "github.com/sirupsen/logrus"
var log = logrus.WithField("prefix", "slashing-protection-format")
// INTERCHANGE_FORMAT_VERSION specified by https://eips.ethereum.org/EIPS/eip-3076.
// The version Prysm supports is version 5.
const INTERCHANGE_FORMAT_VERSION = "5"
// EIPSlashingProtectionFormat string representation of a standard
// format for representing validator slashing protection db data.
type EIPSlashingProtectionFormat struct {
Metadata struct {
InterchangeFormatVersion string `json:"interchange_format_version"`
GenesisValidatorsRoot string `json:"genesis_validators_root"`
} `json:"metadata"`
Data []*ProtectionData `json:"data"`
}
// ProtectionData field for the standard slashing protection format.
type ProtectionData struct {
Pubkey string `json:"pubkey"`
SignedBlocks []*SignedBlock `json:"signed_blocks"`
SignedAttestations []*SignedAttestation `json:"signed_attestations"`
}
// SignedAttestation in the standard slashing protection format file, including
// a source epoch, target epoch, and an optional signing root.
type SignedAttestation struct {
SourceEpoch string `json:"source_epoch"`
TargetEpoch string `json:"target_epoch"`
SigningRoot string `json:"signing_root,omitempty"`
}
// SignedBlock in the standard slashing protection format, including a slot
// and an optional signing root.
type SignedBlock struct {
Slot string `json:"slot"`
SigningRoot string `json:"signing_root,omitempty"`
}