diff --git a/validator/db/kv/proposal_history_v2.go b/validator/db/kv/proposal_history_v2.go index 561656161..1af911ee3 100644 --- a/validator/db/kv/proposal_history_v2.go +++ b/validator/db/kv/proposal_history_v2.go @@ -51,11 +51,11 @@ func (store *Store) ProposalHistoryForSlot(ctx context.Context, publicKey [48]by var err error var proposalExists bool signingRoot := [32]byte{} - err = store.view(func(tx *bolt.Tx) error { + err = store.update(func(tx *bolt.Tx) error { bucket := tx.Bucket(newHistoricProposalsBucket) - valBucket := bucket.Bucket(publicKey[:]) - if valBucket == nil { - return fmt.Errorf("validator history empty for public key: %#x", publicKey) + valBucket, err := bucket.CreateBucketIfNotExists(publicKey[:]) + if err != nil { + return fmt.Errorf("could not create bucket for public key %#x", publicKey[:]) } signingRootBytes := valBucket.Get(bytesutil.Uint64ToBytesBigEndian(slot)) if signingRootBytes == nil { diff --git a/validator/db/kv/proposal_history_v2_test.go b/validator/db/kv/proposal_history_v2_test.go index 24da0fb4b..1d92399de 100644 --- a/validator/db/kv/proposal_history_v2_test.go +++ b/validator/db/kv/proposal_history_v2_test.go @@ -22,12 +22,13 @@ func TestProposalHistoryForSlot_InitializesNewPubKeys(t *testing.T) { } } -func TestNewProposalHistoryForSlot_NilDB(t *testing.T) { +func TestNewProposalHistoryForSlot_ReturnsNilIfNoHistory(t *testing.T) { valPubkey := [48]byte{1, 2, 3} db := setupDB(t, [][48]byte{}) - _, _, err := db.ProposalHistoryForSlot(context.Background(), valPubkey, 0) - require.ErrorContains(t, "validator history empty for public key", err, "Unexpected error for nil DB") + _, proposalExists, err := db.ProposalHistoryForSlot(context.Background(), valPubkey, 0) + require.NoError(t, err) + assert.Equal(t, false, proposalExists) } func TestSaveProposalHistoryForSlot_OK(t *testing.T) {