mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 992 forks source link

p2p: Replace Load&Store with CAS to avoid possible atomicity violation #3588

Open BurtonQin opened 3 years ago

BurtonQin commented 3 years ago

Describe the bug https://github.com/mimblewimble/grin/blob/35740204a1b212131afea502b49af4632aec8913/p2p/src/protocol.rs#L260-L265 Perhaps we can use compare_exchange() to replace the separate load() and store() to avoid atomicity violation ( load() and store() interleaved by another store() from another thread).

To Reproduce Found it through static analysis.

Relevant Information None

Screenshots None

Desktop (please complete the following information):

Additional context None

antiochp commented 3 years ago

Hi @BurtonQin thanks for the issue! Let us look into this but I think your suggestion makes a lot of sense.