lnpeer: some rework of error/warning message handling#7720
Merged
Conversation
- rm the `_get_channel_ids` abstraction as each of its usages needs subtle differences. Some code duplication is preferable in this case. - raise exceptions in `wait_for_message`, so that callers such as the GUI can show user-feedback - on_error/on_warning were dropping messages with temp_chan_ids if they were not stored in `temp_id_to_id` - which was only done once the mapping was known (so the normal chan_id was known). To fix this, we now store temp_chan_ids into `temp_id_to_id` early. - `schedule_force_closing` only works if the chan_id is already in `channels` related: spesmilo#7645 (and related commits) ----- example before commit: ``` D/P | lnpeer.Peer.[LNWallet, 03933884aa-3b53e4ab] | Sending OPEN_CHANNEL D/P | lnpeer.Peer.[LNWallet, 03933884aa-3b53e4ab] | Received ERROR I/P | lnpeer.Peer.[LNWallet, 03933884aa-3b53e4ab] | remote peer sent error [DO NOT TRUST THIS MESSAGE]: invalid funding_satoshis=10000 sat (min=400000 sat max=1500000000 sat) E | gui.qt.main_window.[test_segwit_2] | Could not open channel Traceback (most recent call last): File "...\electrum\electrum\util.py", line 1160, in wrapper return await func(*args, **kwargs) File "...\electrum\electrum\lnpeer.py", line 661, in wrapper return await func(self, *args, **kwargs) File "...\electrum\electrum\lnpeer.py", line 742, in channel_establishment_flow payload = await self.wait_for_message('accept_channel', temp_channel_id) # File "...\electrum\electrum\lnpeer.py", line 315, in wait_for_message name, payload = await asyncio.wait_for(q.get(), LN_P2P_NETWORK_TIMEOUT) File "...\Python39\lib\asyncio\tasks.py", line 468, in wait_for await waiter asyncio.exceptions.CancelledError During handling of the above exception, another exception occurred: Traceback (most recent call last): File "...\Python39\lib\asyncio\tasks.py", line 492, in wait_for fut.result() asyncio.exceptions.CancelledError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "...\electrum\electrum\gui\qt\util.py", line 914, in run result = task.task() File "...\electrum\electrum\gui\qt\main_window.py", line 1875, in task return self.wallet.lnworker.open_channel( File "...\electrum\electrum\lnworker.py", line 1075, in open_channel chan, funding_tx = fut.result() File "...\Python39\lib\concurrent\futures\_base.py", line 445, in result return self.__get_result() File "...\Python39\lib\concurrent\futures\_base.py", line 390, in __get_result raise self._exception File "...\electrum\electrum\util.py", line 1160, in wrapper return await func(*args, **kwargs) File "...\electrum\electrum\lnworker.py", line 1006, in _open_channel_coroutine chan, funding_tx = await asyncio.wait_for(coro, LN_P2P_NETWORK_TIMEOUT) File "...\Python39\lib\asyncio\tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError ``` example after commit: ``` D/P | lnpeer.Peer.[LNWallet, 03933884aa-ff3a866f] | Sending OPEN_CHANNEL D/P | lnpeer.Peer.[LNWallet, 03933884aa-ff3a866f] | Received ERROR I/P | lnpeer.Peer.[LNWallet, 03933884aa-ff3a866f] | remote peer sent error [DO NOT TRUST THIS MESSAGE]: invalid funding_satoshis=10000 sat (min=400000 sat max=1500000000 sat). chan_id=124ca21fa6aa2993430ad71f465f0d44731ef87f7478e4b31327e4459b5a3988 E | lnworker.LNWallet.[test_segwit_2] | Exception in _open_channel_coroutine: GracefulDisconnect('remote peer sent error [DO NOT TRUST THIS MESSAGE]: invalid funding_satoshis=10000 sat (min=400000 sat max=1500000000 sat)') Traceback (most recent call last): File "...\electrum\electrum\util.py", line 1160, in wrapper return await func(*args, **kwargs) File "...\electrum\electrum\lnworker.py", line 1006, in _open_channel_coroutine chan, funding_tx = await asyncio.wait_for(coro, LN_P2P_NETWORK_TIMEOUT) File "...\Python39\lib\asyncio\tasks.py", line 481, in wait_for return fut.result() File "...\electrum\electrum\lnpeer.py", line 673, in wrapper return await func(self, *args, **kwargs) File "...\electrum\electrum\lnpeer.py", line 755, in channel_establishment_flow payload = await self.wait_for_message('accept_channel', temp_channel_id) File "...\electrum\electrum\lnpeer.py", line 326, in wait_for_message raise GracefulDisconnect( electrum.interface.GracefulDisconnect: remote peer sent error [DO NOT TRUST THIS MESSAGE]: invalid funding_satoshis=10000 sat (min=400000 sat max=1500000000 sat) I/P | lnpeer.Peer.[LNWallet, 03933884aa-ff3a866f] | Disconnecting: GracefulDisconnect() ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
_get_channel_idsabstraction as each of its usages needs subtle differences.Some code duplication is preferable in this case.
wait_for_message, so that callers such as the GUI can show user-feedbacktemp_id_to_id- which was only done once the mapping was known (so the normal chan_id was known).To fix this, we now store temp_chan_ids into
temp_id_to_idearly.schedule_force_closingonly works if the chan_id is already inchannelsrelated:
#7645 (and related commits)
example before commit:
example after commit: