From 2df024afc6e5d623f49ccdaa789a64a0322db92f Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Thu, 1 Jul 2021 16:50:56 -0500 Subject: [PATCH] Return pubkey with AttestationHistoryForPubKey AttestationRecord response (#9135) * Return pubkey with AttestationHistoryForPubKey AttestationRecord response * Fix tests --- validator/db/kv/attester_protection.go | 1 + validator/slashing-protection/cli_import_export_test.go | 2 +- .../local/standard-protection-format/import_test.go | 4 ++-- .../local/standard-protection-format/round_trip_test.go | 8 ++++---- validator/testing/protection_history.go | 4 +++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/validator/db/kv/attester_protection.go b/validator/db/kv/attester_protection.go index a715d6711bd9..5235e37aa4db 100644 --- a/validator/db/kv/attester_protection.go +++ b/validator/db/kv/attester_protection.go @@ -114,6 +114,7 @@ func (s *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [48]byte sourceEpoch := bytesutil.BytesToEpochBigEndian(sourceBytes) for _, targetEpoch := range targetEpochs { record := &AttestationRecord{ + PubKey: pubKey, Source: sourceEpoch, Target: targetEpoch, } diff --git a/validator/slashing-protection/cli_import_export_test.go b/validator/slashing-protection/cli_import_export_test.go index 3c4aaeadfab9..fcaa3fefb4de 100644 --- a/validator/slashing-protection/cli_import_export_test.go +++ b/validator/slashing-protection/cli_import_export_test.go @@ -46,7 +46,7 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) { // Create some mock slashing protection history. and JSON file pubKeys, err := mocks.CreateRandomPubKeys(numValidators) require.NoError(t, err) - attestingHistory, proposalHistory := mocks.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := mocks.MockAttestingAndProposalHistories(pubKeys) require.NoError(t, err) mockJSON, err := mocks.MockSlashingProtectionJSON(pubKeys, attestingHistory, proposalHistory) require.NoError(t, err) diff --git a/validator/slashing-protection/local/standard-protection-format/import_test.go b/validator/slashing-protection/local/standard-protection-format/import_test.go index 85b070b072d8..1d11b691a829 100644 --- a/validator/slashing-protection/local/standard-protection-format/import_test.go +++ b/validator/slashing-protection/local/standard-protection-format/import_test.go @@ -53,7 +53,7 @@ func TestStore_ImportInterchangeData_BadFormat_PreventsDBWrites(t *testing.T) { // First we setup some mock attesting and proposal histories and create a mock // standard slashing protection format JSON struct. - attestingHistory, proposalHistory := valtest.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := valtest.MockAttestingAndProposalHistories(publicKeys) standardProtectionFormat, err := valtest.MockSlashingProtectionJSON(publicKeys, attestingHistory, proposalHistory) require.NoError(t, err) @@ -111,7 +111,7 @@ func TestStore_ImportInterchangeData_OK(t *testing.T) { // First we setup some mock attesting and proposal histories and create a mock // standard slashing protection format JSON struct. - attestingHistory, proposalHistory := valtest.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := valtest.MockAttestingAndProposalHistories(publicKeys) standardProtectionFormat, err := valtest.MockSlashingProtectionJSON(publicKeys, attestingHistory, proposalHistory) require.NoError(t, err) diff --git a/validator/slashing-protection/local/standard-protection-format/round_trip_test.go b/validator/slashing-protection/local/standard-protection-format/round_trip_test.go index cdfcdb606112..12231e3ce6f2 100644 --- a/validator/slashing-protection/local/standard-protection-format/round_trip_test.go +++ b/validator/slashing-protection/local/standard-protection-format/round_trip_test.go @@ -26,7 +26,7 @@ func TestImportExport_RoundTrip(t *testing.T) { // First we setup some mock attesting and proposal histories and create a mock // standard slashing protection format JSON struct. - attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(publicKeys) require.NoError(t, err) wanted, err := slashtest.MockSlashingProtectionJSON(publicKeys, attestingHistory, proposalHistory) require.NoError(t, err) @@ -137,7 +137,7 @@ func TestImportInterchangeData_OK(t *testing.T) { // First we setup some mock attesting and proposal histories and create a mock // standard slashing protection format JSON struct. - attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(publicKeys) require.NoError(t, err) standardProtectionFormat, err := slashtest.MockSlashingProtectionJSON(publicKeys, attestingHistory, proposalHistory) require.NoError(t, err) @@ -196,7 +196,7 @@ func TestImportInterchangeData_OK_SavesBlacklistedPublicKeys(t *testing.T) { // First we setup some mock attesting and proposal histories and create a mock // standard slashing protection format JSON struct. - attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(publicKeys) require.NoError(t, err) standardProtectionFormat, err := slashtest.MockSlashingProtectionJSON(publicKeys, attestingHistory, proposalHistory) @@ -284,7 +284,7 @@ func TestStore_ImportInterchangeData_BadFormat_PreventsDBWrites(t *testing.T) { // First we setup some mock attesting and proposal histories and create a mock // standard slashing protection format JSON struct. - attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(numValidators) + attestingHistory, proposalHistory := slashtest.MockAttestingAndProposalHistories(publicKeys) require.NoError(t, err) standardProtectionFormat, err := slashtest.MockSlashingProtectionJSON(publicKeys, attestingHistory, proposalHistory) require.NoError(t, err) diff --git a/validator/testing/protection_history.go b/validator/testing/protection_history.go index 5d124726e7fe..22b54133877c 100644 --- a/validator/testing/protection_history.go +++ b/validator/testing/protection_history.go @@ -51,8 +51,9 @@ func MockSlashingProtectionJSON( // MockAttestingAndProposalHistories given a number of validators, creates mock attesting // and proposing histories within WEAK_SUBJECTIVITY_PERIOD bounds. -func MockAttestingAndProposalHistories(numValidators int) ([][]*kv.AttestationRecord, []kv.ProposalHistoryForPubkey) { +func MockAttestingAndProposalHistories(pubkeys [][48]byte) ([][]*kv.AttestationRecord, []kv.ProposalHistoryForPubkey) { // deduplicate and transform them into our internal format. + numValidators := len(pubkeys) attData := make([][]*kv.AttestationRecord, numValidators) proposalData := make([]kv.ProposalHistoryForPubkey, numValidators) gen := rand.NewGenerator() @@ -73,6 +74,7 @@ func MockAttestingAndProposalHistories(numValidators int) ([][]*kv.AttestationRe Source: i - 1, Target: i, SigningRoot: signingRoot, + PubKey: pubkeys[v], }) } for i := types.Epoch(1); i <= latestTarget; i++ {