  Stars grow by accreting gas that has an evolving composition owing to the
growth and inward drift of dust (pebble wave), the formation of planetesimals
and planets, and the selective removal of hydrogen and helium by disk winds. We
investigated how the formation of the Solar System may have affected the
composition and structure of the Sun, and whether it plays any role in solving
the solar abundance problem. We simulated the evolution of the Sun from the
protostellar phase to the present age and attempted to reproduce spectroscopic
and helioseismic constraints. We performed chi-squared tests to optimize our
input parameters. We confirmed that, for realistic models, planet formation
occurs when the solar convective zone is still massive; thus, the overall
changes due to planet formation are too small to significantly improve the
chi-square fits. We found that solar models with up-to-date abundances require
an opacity increase of 12% to 18% centered at $T=10^{6.4}$ K to reproduce the
available observational constraints. This is slightly higher than, but is
qualitatively in good agreement with, recent measurements of higher iron
opacities. These models result in better fits to the observations than those
using old abundances; therefore, they are a promising solution to the solar
abundance problem. Using these improved models, we found that planet formation
processes leave a small imprint in the solar core, whose metallicity is
enhanced by up to 5%. This result can be tested by accurately measuring the
solar neutrino flux. In the improved models, the protosolar molecular cloud
core is characterized by a primordial metallicity in the range 0.0127-0.0157
and a helium mass fraction in the range 0.268-0.274. (abridged)
