| 1141 | |
| 1142 | # This helper sends all money to a peer until even 1 msat can't get through. |
| 1143 | def drain(self, peer): |
| 1144 | total = 0 |
| 1145 | msat = 4294967295 # Max payment size in some configs |
| 1146 | while msat != 0: |
| 1147 | try: |
| 1148 | logging.debug("Drain step with size={}".format(msat)) |
| 1149 | self.pay(peer, msat) |
| 1150 | total += msat |
| 1151 | except RpcError as e: |
| 1152 | logging.debug("Got an exception while draining channel: {}".format(e)) |
| 1153 | msat //= 2 |
| 1154 | logging.debug("Draining complete after sending a total of {}msats".format(total)) |
| 1155 | return total |
| 1156 | |
| 1157 | # Note: this feeds through the smoother in update_feerate, so changing |
| 1158 | # it on a running daemon may not give expected result! |