public <C extends ConsensusContext> Optional<C> safeConsensusContext(final Class<C> klass) {
    return Optional.ofNullable(consensusContext)
        .filter(c -> klass.isAssignableFrom(c.getClass()))
        .map(klass::cast);
  }
Gets the safe consensus context of the protocol context.

@param <C> the type of the consensus context
@param klass the klass
@return the consensus context of the protocol context
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java