There is a data race where UpdateAvalancheStatistics() may be called while
receiving an AVAHELLO message, where m_avalanche_state is initialized.
A similar race exists if addavalanchenode is called during
UpdateAvalancheStatistics().
This patch fixes the race and also fixes the design flaw that enabled it. The
design flaw resulted in:
- No lock around the m_avalanche_state structure since it resided within the structure itself.
- Initialization of m_avalanche_state on receipt of AVAHELLO instead of first use (attempt to poll the peer for the first time), resulting in unused memory initialized for poll-only peers.
- Unclear intent of m_avalanche_state since it was also used to determine whether a peer had avalanche enabled.
With this patch, the intent is now more clear and the state is only initialized
for peers where it will be used.
Depends on D12325