mimblewimble / grin

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

[PIBD_IMPL] Validation Deadlock Fix #3700

Closed yeastplume closed 2 years ago

yeastplume commented 2 years ago

Surprisingly small fix that took ages to track down - reverses the order in which header_pmmr and tx_hashset are locked during validation, which appears to fix a deadlock.

Why? Because block headers coming in during validation were causing a race condition with the locks in the desegmenter validation (which appears to be why the deadlock worked once in a while): https://github.com/mimblewimble/grin/blob/b08a6dd52807aa5fdc0b5a22d2a834ee46da6f41/chain/src/chain.rs#L465

Needs testing still.

For future reference, parking_lot has a deadlock detector which was very useful for tracking this down: https://amanieu.github.io/parking_lot/parking_lot/deadlock/index.html