Commit graph

25 commits

Author SHA1 Message Date
Blockstream Satellite
5efcbd2418 Extend the states returned by /orders/:state
Previously, the /orders/:state endpoint only returned the "pending",
"queued", and "sent" states. This patch adds the following new states:
"paid", "transmitting", "confirming", "rx-pending", "retransmitting",
and "received". These are mapped directly to the order status, except
for the "rx-pending" and "retransmitting" states, which are inferred
based on other information. The "rx-pending" state returns orders with
sent status only, as opposed to the call to /orders/sent, which returns
orders with sent and received status. The "retransmitting" state returns
any order with entries on the retransmission database.
2023-02-10 14:40:32 -03:00
Blockstream Satellite
432334b2eb Add parameters to filter orders in date range
Previously, it was possible to filter orders before an ISO date only.
With this patch, it is now possible to filter before and after ISO
dates, so a window can be defined (with start and end datetimes). Also,
it is now possible to specify the start and end times of the filtering
window with deltas in seconds relative to the current UTC time. For
instance, with before_delta=60 and after_delta=120, the filtered window
starts 2 min ago and ends 1 min ago.
2023-02-10 10:15:20 -03:00
Blockstream Satellite
31b0d5fa17 Remove uuid from /order/<uuid>/bump response
The uuid is already a request parameter, so no need to include it in the
response.
2023-02-09 17:34:46 -03:00
Blockstream Satellite
ef6074785e Define distinct maximum message sizes per channel 2023-02-06 13:02:32 -03:00
Blockstream Satellite
b2a7c7f394 Drop unused option from test order generation util
The option is not used on tests.
2023-02-02 17:16:12 -03:00
Blockstream Satellite
c10126b7ec Consider different Tx rates per logical channel
Consider these distinct rates when computing the timeout interval for
messages transmitted on each channel.
2023-02-02 17:16:12 -03:00
Blockstream Satellite
b3454d7340 Return more information on GET /admin/order
In addition to the info returned by the regular /order endpoint, return
a few more admin-only fields.
2023-02-02 17:16:12 -03:00
Blockstream Satellite
895d9f785f Bump flask version to 1.1.4 2023-02-02 17:16:12 -03:00
Blockstream Satellite
50df236d6b Support multiple parallel logical message channels
The same server now can handle multiple logical channels, on which the
transmitter logic runs independently. That is, while previously a single
message would be in transmitting state at a time, now multiple messages
can be in transmitting state as long as they belong to distinct logical
channels.

The supported channels each have different permissions. The user channel
is where users can post, get, and delete messages as needed. In
contrast, the other channels do not grant all permissions to users. Some
are read-only (users can get but not post) and there is a channel (the
auth channel) on which users have no permissions (neither get nor post).

For the channels on which users do not have all permissions (get, post,
and delete), this patch adds admin-specific routes, which are prefixed
by /admin/. The /admin/ route is protected via SSL in production and
allows the admin host to send GET/POST/DELETE requests normally. Hence,
for instance, the admin host can post a message on the auth channel
(with POST /admin/order) and read it (with GET /admin/order) for
transmission over satellite, whereas regulars cannot. With this scheme,
the auth channel messages are accessible exclusively over satellite (and
not over the internet).

The admin routes were added to the following endpoints:
- /order/<uuid> (GET and DELETE requests)
- /order (POST request)
- /orders/<state> (GET request)
- /message/<tx_seq_num> (GET request)

The messages posted by the admin are not paid, so this patch removes the
requirement of invoice generation and payment. Only paid orders now
generate an invoice. Thus, the POST request to the /order/ endpoint does
not return an invoice for non-paid (admin-only) messages.

Also, this patch updates the queue page to display the orders separately
for each channel. The query string channel parameter determines which
channel the page shows.

Finally, this patch updates the events published into the Redis db on
transmission. The event includes the corresponding logical channel so
that SSE events can be subscribed independently for each channel.
2023-02-02 17:16:12 -03:00
Blockstream Satellite
76a51eec52 Add missing blank lines around class methods
This verification was added on yapf 0.32 and it follows the pep8
specification.
2021-12-28 12:22:58 -03:00
Blockstream Satellite
da31d10916 Fix error dictionary returned as string
Flask-RESTful returns a JSON response by default when returning a
dictionary. It's not necessary to dump the returning dictionary into a
JSON-serialized string. Otherwise, the client will see a string response
instead of a JSON response.
2021-12-28 11:27:25 -03:00
Blockstream Satellite
1363a3a739 Prevent order bumping if not in pending/paid state
Bumping the bid would be useless if the order is already in the
transmitting, sent, or received states. Hence, prevent such requests.
2021-12-28 10:01:04 -03:00
Blockstream Satellite
f8dfa44c73 Remove pending orders from list of queued orders
An order is only "queued for transmission" after leaving the
pending (payment pending) state.
2021-12-28 10:01:04 -03:00
Blockstream Satellite
5882fddc49 Support retransmission of unconfirmed orders
This change implements a mechanism to retransmit orders if some of the
order's selected regions do not confirm transmission in due time. It
adds a worker to repeatedly check the orders and determine if they need
retransmission. Such orders will be added to a new table named
tx_retries. The tx_start function now first checks if there are regular
new paid orders to transmit. If not, it will check the retransmission
table and retransmit an order from there if one is available.

This patch also introduces a new order state called "retranmission". The
order enters this state while waiting for retransmission.
2021-12-28 10:01:04 -03:00
Blockstream Satellite
21ee2f212b Support API transmissions over selected regions
Users can provide a list of regions to POST /order requests. This list
indicates on which regions the order should be transmitted. It also
determines the expected transmission and reception confirmations.
2021-12-27 12:16:25 -03:00
Blockstream Satellite
2cfc39804e Remove tx loop and rely on tx confirmations
This change removes the infinite transmission loop with sleep periods
between each transmission. Now, a new transmission can start by a call
to "tx_start" on the following two conditions:

1) As soon as the application starts (if there is a previously paid
   order waiting already).
2) As soon as the current transmission ends. The server will immediately
   look for the next order ready for transmission and start it if
   available.

Meanwhile, the condition for ending the current transmission (i.e., for
calling "tx_end(order)") is when all Tx confirmations are received from
all regions.
2021-12-27 12:16:25 -03:00
Blockstream Satellite
e6cd148bc6 Support auth_token given as query string parameter 2021-07-21 14:43:44 -03:00
Blockstream Satellite
876c6de170 Fix line break on invoice callback URL 2021-07-21 13:52:45 -03:00
Blockstream Satellite
69b97e9eae Randomize charge api token's getenv fallback value
If the env var is not defined, fall back to a random string. However,
note the random string won't work over gunicorn if using multiple
workers. In this case, it is necessary to define the env var.
2021-07-20 15:05:11 -03:00
Blockstream Satellite
3d7a5b764d Add expired invoice error and rename paid error
- Add new error: INVOICE_ALREADY_EXPIRED.
- Rename ORDER_ALREADY_PAID to INVOICE_ALREADY_PAID.
2021-07-20 12:28:08 -03:00
Blockstream Satellite
90f7c12783 Remove unused/obsolete API error codes
The new server implementation in Python implements request validation
using the Marshamallow package. With that, some requests are validated
directly by the marshmallow validator and do not return custom error
codes. Drop those error codes and other unused ones. Review the README
docs accordingly.
2021-07-20 12:28:08 -03:00
Blockstream Satellite
24a4c5ccb7 Do not round the order's bid_per_byte value
Store the fractional value on the db. Let the frontend round if
necessary but keep it non-rounded on the backend.
2021-07-20 12:28:08 -03:00
Blockstream Satellite
1568ee54f2 Add a new error code for fetching info
Return a json response with a custom error code like most other API
endpoints.
2021-07-20 12:28:08 -03:00
Blockstream Satellite
d8e7516f01 Add date filter and paging on all orders/ states
- Add date filtering (before parameter) to /queued.
- Add page limit to /sent and /pending.
2021-07-20 12:28:08 -03:00
Blockstream Satellite
9d421771e7 Port the satellite API to python
- Preserve the SQLite database and use SQLAlchemy to wrap db
  interactions.
- Use Alembic for database migrations.
- Organize all the python modules on the new server/ directory.
- Use pytest for unit tests and organize test modules at server/tests/.
2021-07-20 12:28:08 -03:00