Finns love to tell the Winter War as the story of a small innocent country attacked out of nowhere. Moscow had very concrete reasons to see it differently.
Stalin remembered 1918–19: Mannerheim offering to fight alongside the British in exchange for Petrozavodsk, Finland joining the blockade of Baltic states that made peace with Soviet Russia. By the late 1930s came the Åland affair coordinated with Britain and Germany, the submarine program for the Kriegsmarine, the secret talks with Göring. If war with Germany came, Leningrad, about 32 km from the Finnish border, would be exposed from the north.
So in 1939 Stalin proposed a territorial exchange: move the border away from Leningrad in return for larger tracts of Soviet Karelia. He even offered to lease the territory instead. The goal was to keep the USSR's second capital, with its millions of people and critical industry, out of artillery range of a Finland aligned with Germany.
Helsinki rejected every compromise, and that told Moscow exactly where Finland had placed its bet. The Winter War was the brutal outcome of a security problem Stalin tried, and failed, to solve through negotiation.