func (s *Service) OnFinalityCheckpointReceived(
	ctx context.Context,
	epoch phase0.Epoch,
	blockRoot phase0.Root,
	stateRoot phase0.Root,
) {
	log := log.With().Uint64("epoch", uint64(epoch)).Logger()
	log.Trace().
		Str("block_root", fmt.Sprintf("%#x", blockRoot)).
		Str("state_root", fmt.Sprintf("%#x", stateRoot)).
		Msg("Handler called")
	acquired := s.activitySem.TryAcquire(1)
	if !acquired {
		log.Debug().Msg("Another handler running")
		return
	}
	defer s.activitySem.Release(1)
	finality, err := s.eth2Client.(eth2client.FinalityProvider).Finality(ctx, "head")
	if err != nil {
		log.Error().Err(err).Msg("failed to obtain finality")
		return
	}
	opCtx, cancel, err := s.chainDB.BeginTx(ctx)
	if err != nil {
		log.Error().Err(err).Msg("Failed to begin transaction on finality")
		return
	}
	log.Trace().Msg("Updating canonical blocks on finality")
	if err := s.updateCanonicalBlocks(opCtx, finality.Justified.Root); err != nil {
		log.Warn().Err(err).Msg("Failed to update canonical blocks on finality")
	}
	log.Trace().Msg("Updating attestation votes on finality")
	if err := s.updateAttestations(opCtx, epoch-1); err != nil {
		log.Debug().Err(err).Msg("Failed to update attestations on finality")
	}
	if err := s.chainDB.CommitTx(opCtx); err != nil {
		cancel()
		log.Error().Err(err).Msg("Failed to commit transaction on finality")
		return
	}
	monitorEpochProcessed(epoch)
	log.Trace().Msg("Finished handling finality checkpoint")
	for _, finalityHandler := range s.finalityHandlers {
		go finalityHandler.OnFinalityUpdated(ctx, epoch)
	}
}
OnFinalityCheckpointReceived receives finality checkpoint notifications.
package standard
import (
	"bytes"
	"context"
	"fmt"
	eth2client "github.com/attestantio/go-eth2-client"
	"github.com/attestantio/go-eth2-client/spec"
	"github.com/attestantio/go-eth2-client/spec/phase0"
	"github.com/jackc/pgx/v4"
	"github.com/pkg/errors"
	"github.com/wealdtech/chaind/services/chaindb"
)