Fix deserialization of similar token networks #2766
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So that turned out to be quite a bug, much more foundational than I initially thought.
From initial debugging with @CosminNechifor we saw that there was a mismatch in the internal network graph which is part of the
TokenNetworkGraphState
. However all tries to reproduce this failed, the correct state changes were written to the WAL and when replaying the WAL everything was right.However, we finally found that we could reproduce this when we started with a snapshot. From here on the problem was easy to track down.
It turns out that that there was a problem during deserialization which made multiple
TokenNetworkState
objects reference the sameTokenNetworkGraphState
. This only happened in really special constrains, so it’s not surprising that we haven’t found this earlier:A snapshot need to be deserialized when there are multiple token networks with the same topology and exactly the same channel participants at the time of the snapshot.
So thanks to the scenario player @CosminNechifor was able to trigger that.
For the fix: It turns out that the
TokenNetworkGraphState
currently doesn’t know which token network it belongs to. We therefore need a breaking change and add the token network identifier to theTokenNetworkGraphState
. With this the objects don’t compare to equal any more and proper instances for each token network are created during deserialization.This is the easy and quick fix, but in the future we might want to move the
TokenNetworkGraphState
in theTokenNetworkState
or remove it all together when the PFS gets introduced.Fixes #2662