Commit 89f921f
committed
Merge bitcoindevkit/rust-electrum-client#160: fix: fix batch ordering issue
a3488f4ff9007f0682f8e08cdedb6302498ac190 ci: bump actions/cache to v4 (valued mammal)
0ee0a6ad7ac335847cefd19c41c5522023be0be0 test: add batch response ordering test (marshallyale)
6721929f22be6243e8bcaa71de9d3372e4a3fbba fix: fix batch ordering issue (marshallyale)
Pull request description:
Fixes issue #75
This is my first open source pull request so I apologize for any formatting issues. Additionally, I don't know the repository as well as others so there may be a better way to implement the fix.
I believe I found the root cause of this. I added a pull request to fix, but I'm going to copy/paste what I believe is causing the error.
The main issue in the code is inside raw_client.rs inside the `recv` method implementation (snippet below):
https://github.com/bitcoindevkit/rust-electrum-client/blob/805ea0af307e6465f23c2d7f25a32d7ff61fe7ec/src/raw_client.rs#L671-L685
When this is first called, the `self._reader_thread` will run. Inside the `self._reader_thread`, if the request id matches the response id, everything works fine. However, if the request id does not match the response id, we run the following code:
https://github.com/bitcoindevkit/rust-electrum-client/blob/805ea0af307e6465f23c2d7f25a32d7ff61fe7ec/src/raw_client.rs#L602-L612
The channel that the response is sent back into is not unique, but rather all the channels share the same sender.clone() and receiver. The only validation that is done is to check that the request id is still being searched for inside `self.waiting_map`. This means that the receiver channel receives whatever the next response is into the channel without any validation that it matches the request id which happens here `match receiver.recv()?`.
This is fixed by implementing unique channels for every request id. This fix can be verified with the code johnzweng used to show the issue
If you run this with the initial code, it will error out after 1-10 cycles normally. However, after the fix this runs indefinitely.
ACKs for top commit:
ValuedMammal:
reACK a3488f4ff9007f0682f8e08cdedb6302498ac190
Tree-SHA512: c56d572c0d9e709352fde0c0438103fe4c0338e4b591d5290468b1658d6d73dbc818044e1b7ea6307e449a8d4380d9deba6adf2b89eb1dcbc119cec277fd721c2 files changed
+36
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
547 | 546 | | |
548 | 547 | | |
549 | 548 | | |
| |||
762 | 761 | | |
763 | 762 | | |
764 | 763 | | |
765 | | - | |
| 764 | + | |
766 | 765 | | |
767 | 766 | | |
768 | | - | |
769 | | - | |
770 | | - | |
| 767 | + | |
771 | 768 | | |
772 | 769 | | |
773 | 770 | | |
774 | 771 | | |
775 | 772 | | |
776 | 773 | | |
777 | 774 | | |
778 | | - | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
779 | 779 | | |
780 | | - | |
| 780 | + | |
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
| |||
796 | 796 | | |
797 | 797 | | |
798 | 798 | | |
799 | | - | |
800 | | - | |
| 799 | + | |
| 800 | + | |
801 | 801 | | |
802 | 802 | | |
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
806 | 806 | | |
807 | 807 | | |
808 | | - | |
| 808 | + | |
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
| |||
1190 | 1190 | | |
1191 | 1191 | | |
1192 | 1192 | | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
1193 | 1213 | | |
1194 | 1214 | | |
1195 | 1215 | | |
| |||
0 commit comments