Commit graph

73 commits

Author SHA1 Message Date
Joseph Goulden
3fd4f41325
Allow watchtower client to call https endoints 2025-09-27 15:29:37 +01:00
dzdidi
b3a621a781
Update dependencies
- Add toolchain
- Common:
  - bitcoin v0.32.0;
  - lightning v0.1.0
- TEOS:
  - bitcoin v0.32.0;
  - bitcoincore-rpc v0.19.0;
  - lightning v0.1.0;
  - lightning-net-tokio v0.1.0;
  - lightning-block-sync v0.1.0
- Watchtower-Plugin:
  - bitcoin v0.32.0;
  - cln-plugin v0.3.0
2025-03-25 12:06:21 +01:00
Sergi Delgado Segura
cc0d18393d
plugin: replaces map_err for inspect_err in cases where we were only logging and returning 2024-09-05 17:19:12 -04:00
Sergi Delgado Segura
81a659c0f6
Bumps tonic to 0.11 and prost to 0.12, adapts Cargo files accordingly
Bumping tonic required cargo file edition to be bumped to 2021
2024-07-29 16:27:32 -04:00
Sergi Delgado Segura
d30fc7d121
Fixes clippy issues 2024-07-29 13:12:27 -04:00
daywalker90
f6decde5ff
modernize cln tests and CI 2024-07-29 16:28:19 +02:00
Sergi Delgado Segura
534d6390ba
watchtower-plugin: fixes pyln-client version
`pyln-testing` depends on `pyln-client`, and the API for the latter has changed
in version 24.0. Fix our dependency to 23.11 to prevent test from breaking
2024-03-28 09:30:29 +01:00
Sergi Delgado Segura
e6495c31aa
Fixes clippy issues
Clippy is complaining about using `.get(0)` instead of `.fist()` in methods
where we are getting more than just the first item. Suppress those warning.

Also fixes some actual issues.
2024-01-08 14:18:59 -05:00
Sergi Delgado Segura
7093882f47
Properly patches sendrawtransaction so it does not crash
Currently, when mocking sendrawtransaction so it does nothing, the client will raise an exception
given the picked lambda does not accept any params (and sendrawtransaction has some). Patches it
so this does not happen.

This patch is pretty minimal, given the behavior wrt CLN does not change, but it feels better not to
except here.
2023-07-18 14:08:00 -04:00
Anmol Agrawal
2229251702
Implements ping/pong logic for the tower and CLN plugin
Implements ping/pong logic for the tower and CLN plugin
Modification in test as suggested and some more

Some fixed

Signed-off-by: Anmol Agrawal <anmol2002.aa1@gmail.com>
2023-05-02 07:49:24 +05:30
Sergi Delgado Segura
7dc3fcd2cc
Replaces httpmock with mockito
Also:

- Replaced time based waits for loops with the expected conditions to
get given the former is way more error prone.
- Updates tests that needed a response based on the request (main reason why
    were're switching to mockito)
2023-03-08 12:11:49 +01:00
Sergi Delgado Segura
f628b358db
Replaces Result<T, E> for Option<T> in DBM load methods
The `DBM` methods related to loading data return `Result<T, E>` where `E` is always `dbm::Error::NotFound`.

It may makes more sense make them return `Option<T>`.
2023-02-20 11:26:38 +01:00
Sergi Delgado Segura
4bcfbf7c5d
Formats strings to use inline params when possible 2023-02-06 22:56:09 +01:00
Sergi Delgado Segura
73a9bff9fa
Defines Retrier polling waiting time as a constant and fixes tests
The pooling time for the Retrier was hardcoded to 1, let's at least use a constant for that.

Also, `retrier::tests::test_manage_retry_while_idle` was randomly failing (for Ubuntu) when checking whether the Retrier was
idle after giving up on a retry. This is due to the time of running a round not being taken into account.
2023-01-27 11:11:00 -05:00
Sergi Delgado Segura
5cf9029fe9
Bumps teos version to 0.2 in preparation for code release 2023-01-23 17:45:20 -05:00
Sergi Delgado Segura
f18237bb3e
Remove unused defaults, document new ones and updates defaults
- `watchtower-proxy` was still part of constants but it was not being used anymore
- `watchtower-auto-retry-delay` was not part of the README

Also redefines defaults so a retry strategy lasts at most 1h, every interval is at most 15 minutes
and automatic retries are triggered every 8 hours.
2023-01-23 13:15:05 -05:00
Sergi Delgado Segura
197ae93534
Updates readmes 2023-01-20 14:42:20 -05:00
Sergi Delgado Segura
44df8bb6f3
Defines Endpoint enum to avoid using hardcoded strings as endpoints
Useful for both the tower API and the clients
2023-01-20 08:55:22 -05:00
Sergi Delgado Segura
d50ce639bf
Improves tor flag logic in watchtower-plugin
The `watchtower-plugin` was specifying a custom tor flag to signal whether Tor may be used by the client. This was due to `cln-plugin (v0.1.1-)` not allowing plugins to access the CoreLN configuration options and, therefore, our plugin was unable to fetch the `proxy` / `always-use-proxy` options.

This fetches the aforementioned options and revamps the logic to comply with the `always-use-proxy` requirements, that is, if the flag is set all communications must be performed using Tor. Also, it replaces some of the currently used `String`s for more meaningful types to store network data (such as `AddressType`, `NetAddress`, or `ProxyInfo`).

This drops our custom `watchtower-proxy` config option
2023-01-20 08:37:03 -05:00
Sergi Delgado Segura
1a076f92ea
Fixes auto-retry-delay type
`auto-retry-delay` was set to be u16, but its default value was beyond u16::MAX.
2023-01-11 11:27:35 +01:00
Sergi Delgado Segura
6920c9bf98
Simplifies the cln plugin option parsing
Options include helper functions to convert them to their proper type after
`cln-plugin=0.1.2`. Use that to reduce the option parsing boilerplate.

Also move all names, descriptions and default values for options, rpc_methods and hooks
to a new file.
2023-01-10 15:26:42 +01:00
Sergi Delgado Segura
c3b735dec7
Bumps cln-plugin version to v0.1.2 in watchtower-plugin 2023-01-10 14:05:26 +01:00
Sergi Delgado Segura
31defe24f7
Patches watchtower-plugin test_get_appointment e2e
test_get_appointment fails when the plugin is asked about a given tracker before the
tower is able to process the appointment to tracker transition. This doesn't happen consistently,
but we've seen the error popping up every now and then.

Simply add a log based waiting to make sure the state transition is performed before asserting.
2023-01-10 13:50:58 +01:00
Sergi Delgado Segura
09b65ef513
Fixes bug regarding re-registering
The re-register logic had a bug where the `TowerSummary` that was kept in memory
after re-registering was sweeping the references to both the pending and invalid appointments.

While this data was still in the database, re-registering may have made it look like the data was not there.
2023-01-10 13:20:27 +01:00
Sergi Delgado Segura
cc7acf6201
Adds watchtower-plugin autoretry tests 2023-01-10 13:20:26 +01:00
Sergi Delgado Segura
07caee2dbd
Revamps the cln-pugin to support retrying towers automatically
- Updates `Retrier::run` to return more meaningful errors. `Retrier::run` used to simply return a message,
revamps it to return RetryError variants so we can handle return cases better.

- Adds an additional state to `RetrierStatus`: Idle. Retries that fail due to an accumulation of transient errors will be flagged
as Idle instead of Failed and retried later on (based on `auto_retry_delay`). Notice Retrier data is not kept in memory while a retrier is Idle. Instead, data is cleared and loaded again from the database when the `Retrier` is ready to run again.

- Revamps how revocation data is sent to the `RetryManager`: The RetrierManager used to received locators one by one via unreachable_towers. This is due to them being mainly fed by `on_commitment_revocation`, which generates them one by one. However, both when manually retrying or when bootstrapping from an already populated database, multiple appointments may be pending for the same tower, hence needing to call `unreachable_towers.send` multiple times for the same tower. This itself was not a big deal, given we didn't really needed to differentiate between the cases. We do now though.
In order to implement periodic retries while allowing manual retries we need to be able to signal the state transition to the
`Retrier` without providing any new data:

- If a Retrier is idle and we receive data trough `on_commitment_revocation` we need to append that data to the `Retrier`.
- If a Retrier is iddle and we receive data trough a manual retry, we need to change the state of the `Retrier` without
  adding any new data to it.

In order to implement this we've added an additional map to `WTClient` that reports the state of the active retriers. Retriers are active only if they are running or idle.

- Also reworks `WTClient::set_tower_status` to update the status only if the new one does not match the old one.
This is simply to reduce the boiler plate of having to perform this check in other pats of the plugin codebase.
2023-01-10 13:20:26 +01:00
Sergi Delgado Segura
d0a476d4af
Adds named arguments to CoreLN plugin 2022-12-14 11:59:19 -06:00
Sergi Delgado Segura
e816d9e152
Adds a helper fn to get tower_status from WTClient
This helps reducing some of the WTClient is queried only to get the tower status
2022-12-12 10:30:59 -06:00
Sergi Delgado Segura
a6ef6946ab
Implements auto-register for the watchtower-plugin 2022-12-12 10:30:56 -06:00
Sergi Delgado Segura
b5f9a1e037
into() -> to_owned() for Strings
`to_owned` is more explicit.
2022-12-11 11:15:50 -06:00
Sergi Delgado Segura
f7153c4933
Replaces net_addr params from String to &str 2022-12-11 11:15:50 -06:00
Jonathan Plasse
f7d144c6f3
Refactor to avoid using SELECT * 2022-12-11 16:19:16 +01:00
Jonathan Plasse
1e295e1661
Replace server.address() by server.base_url()
Signed-off-by: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com>
2022-12-10 16:27:27 +01:00
Sergi Delgado Segura
14176bd31d
Fixes #156
`TeosD` outputDir was being set to the same directory use by the test suite.
That cause it to be logging in the same log file, potentially colluding for
read/write operations. Setting the outputDir to it's own location fixed the issue.
2022-12-09 17:18:36 -06:00
Sergi Delgado Segura
5177446629
Replaces sleep based waiting for log entry lookups
Replaces time.sleep in the `watchtower-plugin` tests to wait for certain things to happen
on the backend by wait_for_logs, which should be less error prone

Also does some reformating and removes unnecessary imports
2022-12-09 16:23:02 -06:00
Sergi Delgado Segura
da3daddba8
Avoids setting the state of unregistered towers 2022-12-08 05:57:31 -05:00
Sergi Delgado Segura
246511d0bc
Removes redundant sanity check for Retrier::start 2022-11-30 10:31:33 +01:00
Sergi Delgado Segura
f63738e038
Adds a fixed sleep so TeosD has time to bootstrap in the watchtower-plugin tests
This is a hotfix and should be properly fix
2022-11-24 17:19:09 +01:00
Sergi Delgado Segura
6c6d423054
Minimal changes to make the plugin compatible with cln-plugin 0.1.1 2022-11-22 18:26:01 +01:00
Omer Yacine
d212aae0da
use --locked with cargo install
Using --locked with cargo install(s) will instruct cargo to use the lock file in the repo (Cargo.lock).
So all the users' builds will be identical to builds in the master branch.

Signed-off-by: Omer Yacine <mariocynicys@gmail.com>
2022-11-12 20:32:10 +02:00
Sergi Delgado Segura
a20065567f
Changes rpc commands naming from snake case to lower case 2022-11-08 14:13:27 +01:00
Sergi Delgado Segura
fc9145b1b7
Change log level for failed post requests in CoreLN plugin
Let's be less dramatic, specially given connection timeouts fall under this category.
2022-11-01 15:17:04 +01:00
Sergi Delgado Segura
b6e223a4ed
Bumps version to 0.1.2
Makes it so the .rs files pull the version info from the Cargo files so it is always consistent
2022-09-20 12:41:59 +00:00
Sergi Delgado Segura
35a15b14eb
fix: Arc retriers so we reduce the cloning + antipatern
One thing I really disliked about #89 was having a method that cloned its caller to be able to work around spawning a task inside it that called a method of the same class.

Turns out you can have self as Arc<Self> which would completely prevent having to do such a thing, plus it also reduces the number of things being cloned.
2022-09-20 12:25:00 +00:00
meryacine
f0f9879338
watchtower-plugin: get rid of unnecessary arc<mutex< in WTClient 2022-09-17 14:55:35 +02:00
meryacine
f6a60a9655 Rework the retrier
This is an attempt to rework the retrier logic to simplify how it works
and make it less error prone. This is done by making the retry manager
object responsible for both:
1- adding new retriers and extending current ones
2- removing retriers when they finish their work

This way, we don't need a mutex to gaurd the retriers hashmap & we are
sure there is no adding/extending retriers and removing them happending
at the same time, because only the retry manager does it and not
single retriers (i.e. retriers can't remove themselves from the retriers
hashmap).

The retry manager logic goes as follows:
1- drain the unreachable towers channel till it's empty, and store the pending appointments (locators to be exact) in the pending appointments set for each retrier.
2- remove any finished retrier (ones that succeeded and have no more pending appointments) and failed retriers (ones that failed to send their appointments).
3- start all the non-running retriers left after removing failed and finished retrieres.

Retriers will signal thier status so that the retry manager could
determine which retriers to keep, which to remove, and which to re-start.

We also set tower as unreachable when destroying the tower's retrier
and not after completing backoff. This makes it so that the tower is
unreachable until its retrier is destroyed, thus manual tower retry
by the user will fail with an error till the tower's retrier is destroyed.

If we were to set the unreachable tower status after the backoff, then manual
user retries might get discarded completely without an error because retrier
set the tower state to unreachable too early thus allowing the user to
perform manual retries, but if the user does manual retry, it won't get
carried out, since the retry manager will remove that retrier anyway as
it failed to deliver its pending appointments.
2022-09-16 23:44:43 +02:00
Sergi Delgado Segura
c5f9c3a8c4 Fix #84 and revamps the retrier 2022-09-16 23:44:21 +02:00
Sergi Delgado Segura
21c82dcc87 Fixes E2E test test_watchtower
`watchtower-plugin::tests::test::test_watchtower` was not properly checking that
an appointment could not be found after resolving. This was due to an off-by-one error
that made the resolution not actually happening.
2022-09-02 08:48:13 +03:00
Sergi Delgado Segura
4ce991fae0 Updates the plugin README with Tor info 2022-08-29 16:06:27 +02:00
Sergi Delgado Segura
c2bc0d6106 Remove unexpected_error tests 2022-08-29 14:41:00 +02:00