Commit graph

64 commits

Author SHA1 Message Date
bitromortac
cf7e53842a firewall: optimize CryptoRandIntn with sync.Pool
Utilize a sync.Pool for *big.Int instances in CryptoRandIntn to avoid
frequent heap allocations. This significantly reduces garbage collection
pressure when randomizing timestamps, amounts, and fees inside loops
(e.g. iterating over forwarding history responses).
2026-07-21 12:04:33 +00:00
bitromortac
6d89f07037 firewall: fix 32-bit int truncation
Upgrade the randIntn function signature from int to int64 to prevent
unpredictable integer truncation on 32-bit systems (e.g., Raspberry Pi).
This ensures UnixNano timestamps in hideTimestamp and large amounts in
hideAmount do not cause unexpected runtime failures when calling
ForwardingHistory.
2026-07-21 12:04:33 +00:00
Viktor Torstensson
51f33086be
firewall: add request logger disable flag
This introduces a new firewall.request-logger.disable config option to
completely disable request logging. When disabled, the request logger
interceptor is not instantiated, avoiding all logging overhead including
database writes and request processing.

This is implemented as a separate disable flag rather than adding a new
log level because the goal is to bypass the logging system entirely for
performance reasons, not just filter events. A log level would still
process and filter each request through the interceptor.

The change also adds validation to ensure autopilot remains enabled only
when request logging is active, since autopilot relies on action logs
for rule enforcement and auditing.
2026-02-12 17:14:01 +01:00
ffranr
a0e63124c0
multi: reformat long lines for readability
- Replace occurrences of `// nolint:lll` with `// nolint:ll` across
  files for consistency.
- Reformat multiline strings, comments, and function parameters to
  improve clarity and adhere to style guidelines.
- Add `// nolint:ll` comments where necessary to prevent linter
  warnings.
2025-12-09 16:12:03 +00:00
Viktor Torstensson
01bc36ca41
multi: remove AddActionReq MacaroonIdentifier
As the `MacaroonRootKeyID` field of the `AddActionReq` struct also
contains the 4 bytes of the `MacaroonIdentifier`, we change all
call sites to instead use the last 4 bytes of the `MacaroonRootKeyID`
field. As the `MacaroonIdentifier` field therefore becomes redundant,
we also remove it.
2025-10-03 11:44:05 +02:00
Viktor Torstensson
651cc678fc
multi: persist full mac root key in sql actions db
When migrating the actions store from kvdb to sql, we will update the
existing actions to include the full mac root key, instead of just the
last 4 bytes (currently called `MacaroonIdentifier`). In order to do so,
we change the sql implementation of the `actions` store to persist the
full mac root key, instead of just the last 4 bytes. As no production
data in the sql actions store exists for users yet, it's fine for us to
change this without having to address old sql actions which only stored
the last 4 bytes.

Note though that since old actions stored in the kvdb implementation
only have the last 4 bytes of the mac root key persisted, we will only
ever persist the last 4 byte of the mac root key ID for kvdb actions.
When the actions are later read back from the kvdb store, the first 4
bytes of the mac root key ID will be padded with zeroes to make up the
full 8 bytes.
As no call site currently utilizes the full 8 bytes of the mac root key
ID, this is okay for now. When we later deprecate and remove the kvdb
implementation, we can then update the rest of `litd` to also use the
full mac root key ID.
2025-10-03 11:44:04 +02:00
Elle Mouton
b99a4f8fa2
firewall+firewalldb: move mac ID serialisation to kvdb impl
For our kvdb firewalldb, we use an empty 4 byte array as the macaroon
identifier even if no macaroon was used to create the action. This is so
that we have some sort of "session ID" bucket to store these set of
actions under. For our SQL impl, however, this is not needed and we will
likely just use a nullable field for the macaroon ID. So in preparation
for this, we move the kvdb specific logic to the kvdb impl.
2025-05-27 15:22:24 +02:00
Elle Mouton
26d028f4a5
firewall+firewalldb: extract Account ID and pass to AddActionReq
In this commit we add an optional AccountID to the RequestInfo type.
Then, we populate it if the caveat of the macaroon being used contains
an accounts caveat.

We also add an unused AccountID type to the AddActionReq and pass in the
value from the RequestLogger.
2025-05-21 14:14:13 +02:00
Elle Mouton
a89b3502e4
firewall: extract SessionID from gRPC metadata
In this commit, we update our various firewall interceptors so that they
rely on the session ID passed via gRPC metadata to extract a session ID.
For the PrivacyMapper and RuleEnforcer, these _MUST_ always contain a
session ID and so we error out if one was not found. For the request
logger, the session ID is optional and so we pass it to the new
SessionID field in the AddActionReq - our bbolt actions DB will not make
use of this field on persistence (but our incoming SQL version will).
2025-05-16 11:57:39 +02:00
Elle Mouton
3e963c04b4
multi: rename Action.SessionID to MacaroonIdentifier
To make it very clear what the data is actually derived from. Then also
add an optional Session.ID. Our bbolt db wont store this real session ID
and will populate it in a best effort manner by casting the persisted
MacaroonIdentifier.
2025-05-13 09:05:12 +02:00
Elle Mouton
8f7312f53a
firewalldb: introduce AddActionReq
Instead of passing an `Action` to the AddAction method, we introduce an
`AddActionReq` type which only holds the fields that are needed to
create a new Action. The rest of the info is determined by the DB layer.
2025-05-13 09:04:56 +02:00
Elle Mouton
2cb10d28b1
firewalldb: abstract ActionLocator
The current ActionLocator is very specific to how actions are stored in
the bbolt db. In our SQL implementation, we will simply have an
auto-incrementing int64 that we will use as our locator for any action.
In preparation for this, we make ActionLocator an abstract interface and
implement our bbolt version of it.
2025-05-09 16:27:33 +02:00
Elle Mouton
c1ee884626
multi: let most ActionDB methods take a context 2025-05-09 16:16:34 +02:00
Elle Mouton
7edb614e12
firewall: remove redundant session ID param from AddAction method
The SessionID is already present in the Action itself and so this does
not need to be passed in as its own parameter.
2025-05-07 13:30:55 +02:00
Elle Mouton
b9ad66471d
multi+refactor: remove unnecessary type alias
Remove the `NewPrivacyMapDB` type alias. It is not needed.
2025-04-22 06:10:48 +02:00
Elle
4cc7bf2b37
Merge pull request #1002 from ellemouton/sql24
[sql-24] firewalldb: thread contexts through for privacy mapper interfaces
2025-03-27 18:42:56 +02:00
Elle Mouton
dbec9da31b
multi: update LND and friends
This commit updates:
- LND
- pool
- loop
- taproot-assets
- faraday
- lighting-node-connect
- aperture
- lndclient
- btclog

We start using the new btclog v2 library and the associated breaking
changes in the lnd/build package.

With this commit, we deprecate the `--remote.lit-maxlogfiles` and
`--remote.lit-maxlogfilesize` options and introduce new logging options
under the `--remote.lit-logging` namespace.

Finally, the LND update introduced a new `MaxBlocksMinedPerTest`
variable in the `lntest` package that we now need to override in order
for our itests to pass.
2025-03-26 09:20:52 -05:00
Elle Mouton
ef93611489
firewalldb: thread contexts to FetchAllPairs
Update the FetchAllPairs method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
5b31f16446
firewalldb: thread context to RealToPseudo
Update the RealToPseudo method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
7e8e4a9920
firewalldb: thread context to PseudoToReal
Update the PseudoToReal method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
197ee3b5ba
firewalldb: thread context to PrivMap NewPair
Update the NewPair method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
7ce36d7e7d
multi: thread contexts through privacy map interfaces
Update the PrivacyMapDB interface methods to take contexts (both the
methods themselves and the call-back params) and then ensure all
implementations are updated and all call-sites pass contexts through
correctly.
2025-03-25 18:10:52 +02:00
Elle Mouton
190d3dc828
multi: rename GetSessionByID to GetSession
By default, we fetch records by an ID.
2025-03-04 17:34:31 +02:00
Elle Mouton
9642ce1656
session+firewall: pass context to GetSessionByID 2025-02-28 09:26:02 +02:00
Elle Mouton
a22689ce16
golangci: enable line length linter 2025-02-13 15:50:48 +02:00
Elle Mouton
21983bab75
rules: thread context through 2025-01-13 09:23:20 +02:00
bitromortac
66e6d63349
firewall: obfuscate ConnectPeer
Also adds a privacy flag that controls obfuscation of network addresses.
2024-07-02 18:21:42 +02:00
bitromortac
bca729a5af
firewall: obfuscate OpenChannelSync 2024-07-02 18:21:42 +02:00
bitromortac
275a882e96
firewall: obfuscate BatchOpenChannel
We obfuscate fields from the batch channel open requests and
responses.
2024-07-02 18:21:42 +02:00
bitromortac
e797abd2a8
firewall: obfuscate PendingChannels
Only obfuscate pending open channels for now.
2024-07-02 18:21:42 +02:00
bitromortac
ef84753f6b
firewall: obfuscate ClosedChannels
For closes we need to know the close type and settle balances to know
which peers should be avoided in the future.
2024-07-02 18:21:42 +02:00
bitromortac
a7246e1dae
firewall: obfuscate WalletBalance 2024-07-02 18:21:41 +02:00
bitromortac
203d0b7234
firewall: refactor privacy mapper tests
Pull out transaction related constants to the top of the test.
Adds a debug comment that is useful for this code. It is often needed to
check the human readable representation of a message.
2024-07-02 18:21:41 +02:00
bitromortac
7489f0a0b2
rules: pass in lnd connection identifier
We pass a random lnd connection identifier to the rule enforcer that is
unique per lnd connection lifetime. It is used to generate unique
request identifiers that amend the non-unique request identifiers that
are passed from lnd.
2024-07-02 15:04:26 +02:00
bitromortac
916ddec0d7
firewall: return altered intercepted message
This allows us to rewrite a request.
2024-07-02 15:04:25 +02:00
bitromortac
962d6667a8
firewall: error back for streaming rpcs 2024-07-02 15:04:25 +02:00
bitromortac
8f2ab273bb
rules: handle interfering rule violations
We collect errors of all rule enforcers, handling errors in all of them
should an error occur. This is to roll back state consistently.
2024-07-02 15:04:25 +02:00
bitromortac
07bcfe19c0
firewall: intercept with privacy flags
gRPC message interception depends now on privacy flags.
2024-04-25 14:49:46 +02:00
bitromortac
c961472789
firewall: obfuscate config depending on flags 2024-04-25 14:49:46 +02:00
bitromortac
1636bb2bd6
firewall+rules: map with privacy flags
We change the rule mapping to accept the newly added privacy flags. Peer
and channel restrictions can be controlled with privacy flags.
2024-04-25 14:49:46 +02:00
bitromortac
cb542a5015
firewall+firewalldb: add SessionDB interface
SessionDB is an interface that gives helper methods for how privacy
mapping should be done. A mock for SessionDB is added to save on some
code repetition, the privacy flags functionality is used in a later
test.
2024-04-25 14:49:45 +02:00
shuoer86
ab47cd64f7
firewall+firewalldb: fix typos 2023-11-25 10:31:03 +08:00
Oliver Gugger
b3c0d0e9b1
multi: bump lnd to v0.17.0-beta 2023-10-03 19:51:57 +02:00
bitromortac
eb58941e76
rpcserver+firewall: obfuscate configuration
We obfuscate pubkeys, channel points and ids entered in configurations.

The channel id lengths for different block heights can be checked with:
```python
len(str(1 << 40 | 2923 << 16 | 30))
len(str(10_000_000 << 40 | 2923 << 16 | 30))
```
2023-09-05 13:03:58 +02:00
bitromortac
5580d6861d
firewalldb: export DecodeChannelPoint and restrict 2023-09-01 08:03:21 +02:00
Elle Mouton
d0bc3c37f1
firewalldb: add FetchAllPairs to PrivacyMapTx interface
This commit adds a new FetchAllPairs to the PrivacyMapTx interface. This
method returns a new PrivacyMapPairs struct which is an in-memory
privacy map DB. The PrivacyMapPairs struct implements a new
PrivacyMapReader interface which can be used to pass around read only
access to the PrivacyMapPairs struct.
2023-08-31 16:56:59 +02:00
Elle Mouton
a14d7ae17b
firewall: map session ID to group ID in privacy mapper interceptor 2023-08-30 12:34:29 +02:00
Elle Mouton
3c837a9bc6
firewall: map session ID to group ID 2023-08-30 12:34:29 +02:00
Elle Mouton
921874608c
firewall: update ActionsReadDB to get group actions 2023-08-30 12:34:29 +02:00
positiveblue
c267ef64eb
multi: update lnd dependency to v0.16.0-beta.rc3
- Bump lnd and other module dependencies.
- Bump Go build version & RPCs
- Refactor itests to use the new lnd itest framework.
2023-03-15 08:36:23 -07:00