(
self,
channels_to_settle: List[NettingChannelState],
retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT,
)
| 906 | ) |
| 907 | |
| 908 | def _batch_coop_settle( |
| 909 | self, |
| 910 | channels_to_settle: List[NettingChannelState], |
| 911 | retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT, |
| 912 | ) -> List[NettingChannelState]: |
| 913 | pfs_proxy = self.raiden.pfs_proxy |
| 914 | coop_settle_state_changes: List[StateChange] = [] |
| 915 | to_coop_settle = set() |
| 916 | for channel_state in channels_to_settle: |
| 917 | recipient_address = channel_state.partner_state.address |
| 918 | try: |
| 919 | metadata = pfs_proxy.query_address_metadata(recipient_address) |
| 920 | except ServiceRequestFailed: |
| 921 | log.error( |
| 922 | "Partner is offline, coop settle not possible", address=recipient_address |
| 923 | ) |
| 924 | continue |
| 925 | to_coop_settle.add(channel_state.canonical_identifier) |
| 926 | coop_settle_state_changes.append( |
| 927 | ActionChannelCoopSettle( |
| 928 | canonical_identifier=channel_state.canonical_identifier, |
| 929 | recipient_metadata=metadata, |
| 930 | ) |
| 931 | ) |
| 932 | |
| 933 | greenlets = set(self.raiden.handle_state_changes(coop_settle_state_changes)) |
| 934 | gevent.joinall(greenlets, raise_error=True) |
| 935 | |
| 936 | # we need to get a new list of channel state objects since the ones we |
| 937 | # have may have become stale |
| 938 | ids = frozenset(ch.canonical_identifier for ch in channels_to_settle) |
| 939 | chain_state = views.state_from_raiden(self.raiden) |
| 940 | channels_to_settle = [ |
| 941 | ch for ch in views.list_all_channelstate(chain_state) if ch.canonical_identifier in ids |
| 942 | ] |
| 943 | |
| 944 | channels_to_conditions = {} |
| 945 | for channel_state in channels_to_settle: |
| 946 | if channel_state.canonical_identifier not in to_coop_settle: |
| 947 | continue |
| 948 | # FIXME is there a race condition when we "get" the total-withdraw-values after they |
| 949 | # have been determined by the state machine? |
| 950 | # --> because the initiated_coop_settle is removed at some point if it expired |
| 951 | # --> also this only works because the initiated_coop_settle is directly set upon |
| 952 | # handling the ActionChannelCoopSettle. If that wasn't the case, |
| 953 | # we first would have to wait several state-machine iterations |
| 954 | # until the coop-settle-state existed on the channel-state |
| 955 | # If this is a problem, the calculation of the max-withdraw amounts |
| 956 | # would have to be done HERE and included in the ActionChannelCoopSettle, |
| 957 | # so that we know them before feeding the action into the state machine |
| 958 | # and can await them easily here... |
| 959 | |
| 960 | # Initiating a cooop settle for this channel did not succeed |
| 961 | # (e.g. due to pending locks or withdraws) so don't wait on it. |
| 962 | # The channel will be closed later in a non-coop manner. |
| 963 | if channel_state.our_state.initiated_coop_settle is None: |
| 964 | continue |
| 965 |
no test coverage detected