Commit Graph

406 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
f94a67a26d
discovery: properly set the isRemote field for validated networkMsg
This wasn't set properly, leading to some test failures after the prior
change.
2022-12-15 11:56:44 -08:00
Olaoluwa Osuntokun
52451b37af
discovery: ensure we prioritize sending out our own local announcements
In this commit, we modify our gossip broadcast logic to ensure that we
always will send out our own gossip messages regardless of the
filtering/feature policies of the peer.

Before this commit, it was possible that when we went to broadcast an
announcement, none of our peers actually had us as a syncer peer (lnd
terminology). In this case, the FilterGossipMsg function wouldn't do
anything, as they don't have an active timestamp filter set. When we go
to them merge the syncer map, we'd add all these peers we didn't send
to, meaning we would skip them when it came to broadcast time.

In this commit, we now split things into two phases: we'll broadcast
_our_ own announcements to all our peers, but then do the normal
filtering and chunking for the announcements we got from a remote peer.

Fixes https://github.com/lightningnetwork/lnd/issues/6531
Fixes https://github.com/lightningnetwork/lnd/issues/7223
Fixes https://github.com/lightningnetwork/lnd/issues/7073
2022-12-15 11:56:41 -08:00
Olaoluwa Osuntokun
9a4701d709
discovery: add new msgsToBroadcast struct
This struct will be used to later on do filtering when we go to
broadcast, based on if a message was locally sourced or granted from a
remote peer.
2022-12-15 11:56:38 -08:00
Olaoluwa Osuntokun
e8177ea427
discovery: add isLocal bool to msgWithSenders
This lets us keep track of which messages we created ourselves vs the
messages that originated remotely from a peer.
2022-12-15 11:56:36 -08:00
yyforyongyu
443095a907
discovery: signal allow for ignored channel announcements
This commit makes the `handleChanAnnouncement` always returning `true`
for messages processed but ignored by router, even when the extracted
announcements are empty.
Previously we'd return false when the announcements are empty, which
could cause `ChannelUpdate`s being ignored since the validation barrier
will signal deny for the jobs. This can easily be trigger using
following setup,
1. Alice connects to Bob and open a channel.
2. Alice connects to Carol, Bob connects to Carol.
3. Once the channel is open, Alice and Bob will both announce it to Carol.

At some point, we'd have the following messages in Carol's node,
- Alice's ChannelAnnouncement
- Alice's ChannelUpdates, for both directions
- Bob's ChannelAnnouncement
- Bob's ChannelUpdates, for both directions

And a bug could happen, if,
- Alice's ChannelAnnouncement is processed by router, hence added to db,
  but not reporting back to gossiper yet, so the validation barrier
  hasn't sent signal allow.
- Bob's ChannelAnnouncement is processed by router, and returned
  `ErrIgnored` as the edge info is already in db, and reported back to
  gossiper, the validation barrier will signal deny to all the
  ChannelUpdates jobs.
- Depending on how fast Alice's ChannelAnnouncement is processed, we may
  get zero to four denies to the above ChannelUpdates, causing a channel
  edge policy never being updated.
2022-12-08 17:57:02 +08:00
yyforyongyu
716c685f10
discovery+peer: add logs to reveal shutdown flow
Also adds a `TODO` for checking the err chan.
2022-12-08 17:57:01 +08:00
yyforyongyu
152a438fbe
discovery: move shouldBroadcast inside goroutine
This commit moves the `shouldBroadcast` logic closer to the execution
logic of deciding whether we want to broadcast the announcements. This
is a pure code refactor and should make no difference in announcing
message unless the `d.syncMgr.IsGraphSynced()` gives different results
inside the goroutine.
2022-12-08 17:57:01 +08:00
yyforyongyu
b237dbfd74
discovery: add method handleNetworkMessages to process messages 2022-12-08 17:57:01 +08:00
yyforyongyu
26d1a41926
discovery+routing: add more logs to reveal channel update flow 2022-12-08 17:57:01 +08:00
Oliver Gugger
55b53555e9
multi: improve readability of goroutine defers
This commit fixes the readability of some of the defer calls in
goroutines by making sure the defer stands out properly.
2022-11-21 13:54:24 +01:00
Eng Zer Jun
dbf3cf62fe
discovery: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 08:58:16 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
Olaoluwa Osuntokun
08f1c2e93a
chainntfns: add new option for conf notifications to send block
In this commit, we add a new option for the existing confirmation
notification system that optionally allows the caller to specify that a
block should be included as well.

The only quirk w/ the implementation here is the neutrino backend:
usually we get filtered blocks, we so need to first fetch the block
again so we can deliver the full block to the notifier. On the notifier
end, it'll only be checking for the transactions we care about, to
sending a full block doesn't affect the correctness.

We also extend the `testBatchConfirmationNotification` test to assert
that a block is only included if the caller specifies it.
2022-08-01 19:59:21 -07:00
eugene
01f28ba540
server+discovery: alias-handling in gossiper
An OptionalMsgField has been added that allows outside subsystems
to provide a short channel id we should insert into a ChannelUpdate
that we then sign and send to our peer.

When the gossiper receives a ChannelUpdate, it will query the
alias manager by the passed-in FindBaseByAlias function to determine
if the short channel id in the ChannelUpdate points to a known
channel. If this lookup returns an error, we'll fallback to using
the original id in the ChannelUpdate when querying the router.
The lookup and potential fallback must occur in order to properly
lock the multimutex, query the correct router channels, and rate
limit the correct short channel id. An unfortunate side effect of
receiving ChannelUpdates from our peer that reference on of our
aliases rather than the real SCID is that we must store this policy.
Yet it is not broadcast-able. Care has been taken to ensure the
gossiper does not broadcast *any* ChannelUpdate with an alias SCID.

The cachedNetworkMsg uses the new processedNetworkMsg struct. This
is necessary so that delete-and-reinsert in the funding manager
doesn't process a ChannelUpdate twice and end up in a deadlock since
the err chan is no longer being used.
2022-07-07 17:10:28 -04:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Olaoluwa Osuntokun
a90dfff9a5
build: update to Go 1.18 2022-04-12 16:14:04 -07:00
eugene
932c5f1a7b
discovery: move ann sig handling to handleAnnSig 2022-03-15 14:35:27 -04:00
eugene
1e9220dab6
discovery: move channel update handling to handleChanUpdate 2022-03-15 14:35:27 -04:00
eugene
914c96d2cf
discovery: move channel ann handling to handleChanAnnouncement 2022-03-15 14:35:27 -04:00
eugene
3bdf0a437d
discovery: move node ann code to handleNodeAnnouncement 2022-03-15 14:35:25 -04:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
yyforyongyu
1ad6bbfbc2
multi: add logs when subservers are starting
Also unified the log messages.
2022-02-11 21:17:03 +08:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
eugene
ead414c689
discovery: use source instead of peer for accurate rejectCache 2022-01-05 04:27:33 +08:00
yyforyongyu
17938b08ac
discovery: resend premature messages when new blocks arrive
This commit adds a method to resend premature when new blocks arrive.
Previously when a message has specified a block+delta in the future, we
would ignore the message and never process it again, causing an open
channel never being broadcast under fast blocks generation. This commit
fixes it by saving the future messages and resending them once the
required block height is reached.
2022-01-05 04:27:33 +08:00
yyforyongyu
8d0cae5e18
discovery: sync blocks in a dedicated goroutine
This commit moves syncing blocks into a dedicated goroutine to avoid the
race condition where several go channels are ready and the block height
update is pushed after a network message is processed.
2022-01-05 04:27:33 +08:00
yyforyongyu
dd74486b59
routing+discovery: uniform error codes in routing 2022-01-05 04:27:33 +08:00
yyforyongyu
c15c8a1f0b
discovery: transit all inactive syncers when needed 2022-01-05 04:27:32 +08:00
yyforyongyu
2250cb752b
discovery: shorten mutex locking closure 2022-01-05 04:27:32 +08:00
yyforyongyu
c1175dcabe
discovery: add verbose network messages related logs 2022-01-05 04:27:32 +08:00
yyforyongyu
46050fc631
multi: enhance logging for debugging peer connection 2021-12-23 15:14:37 +08:00
Olaoluwa Osuntokun
5a8255550b
discovery: revamp recent rejects map
Similar to the prior commit, in this commit, we move to using a basic
LRU cache to store the set of prior rejected messages.
2021-11-04 15:21:20 -07:00
Olaoluwa Osuntokun
8627b5d128
discovery: revamp premature update map
Turns out we need it right now to handle some low latency race
conditions in our integration tests, so we'll opt to simply cap the size
of it to a low amount. We use a basic LRU caching mechainsm.

Fixes https://github.com/lightningnetwork/lnd/issues/5076
2021-11-04 15:21:18 -07:00
Oliver Gugger
e79d59dd4c
multi: use key locator for lnwallet.MessageSigner
To simplify the message signing API even further, we refactor the
lnwallet.MessageSigner interface to use a key locator instead of the
public key to identify which key should be signed with.
2021-10-08 12:06:52 +02:00
Andras Banki-Horvath
11cf4216e4
multi: move all channelstate operations to ChannelStateDB 2021-09-29 17:00:03 +02:00
yyforyongyu
3204e2d74b
multi: add shutdown logs in subservers
This commit adds a simple shutdown to every subserver to assist
debugging.
2021-09-15 19:52:03 +08:00
Joost Jager
3f775778c3
channeldb+routing: add tx parameter
Adds an optional tx parameter to ForAllOutgoingChannels and FetchChannel
so that data can be queried within the context of an existing database
transaction.
2021-08-24 13:43:24 +02:00
Wilmer Paulino
186237ca73
discovery: demote err log to debug from processZombieUpdate
This log can be "spammy" while nodes throughout the network have yet to
upgrade to v0.13.0-beta, which includes several enhancements to prevent
the broadcast of zombie edges/updates.
2021-05-26 13:33:41 -07:00
Andras Banki-Horvath
14c851c8fc
kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
Wilmer Paulino
0ada2288cc
discovery: prevent logging certain validation barrier errors 2021-04-29 15:53:07 -07:00
Olaoluwa Osuntokun
5d1574f566
Merge pull request #2522 from roeierez/cleanup_server_error
Cleanup in case of server failed to start
2021-04-22 13:00:22 -07:00
Olaoluwa Osuntokun
a9f1b341be
discovery: update zombie resurrection test w/ new logic
In this commit, we update the existing zombie resurrection test to
ensure that if we prune an edge and another pubkey is marked as nil,
that we only accept a resurrection channel update from the node the we
originally pruned if the pruning decision was one sided.
2021-04-21 13:56:35 -05:00
Conner Fromknecht
f28a98aa6f
discovery/gossiper: only parse zombie pubkey if non-empty 2021-04-21 13:56:16 -05:00
Conner Fromknecht
4baee9537b
discovery/gossiper: move zombie handling to helper 2021-04-21 13:56:11 -05:00
Olaoluwa Osuntokun
bb6aca1130
discovery: add unit tests for chan anns in the reject cache 2021-04-14 15:19:27 -07:00
Olaoluwa Osuntokun
c959ecc4c9
discovery: always add chan announcements to the reject cache if err != ErrIgnored
In this commit, we make a change to always add chan announcements to the
reject cache if we didn't reject them for already existing.  Without
this change, if we end up rejecting a channel announcement say because
the channel is already spent or the funding transaction doesn't exist,
then we'll end up continually re-validating the same set of channels we
know will fail, when they're sent to us by peers.

Fixes #5191
2021-04-14 15:19:14 -07:00
Roei Erez
3223df74e5 channelnotifier+discover+invoices: return error in Stop functions
In order to be consistent with other sub systems an error is now
returned from the Stop functions.
This also allows writing a generic cleanup mechanism to stop all
sub systems in case of a failure.
2021-04-13 13:26:01 +03:00
Wilmer Paulino
393111cea9
discovery+routing: cancel dependent jobs if parent validation fails
Previously, we would always allow dependent jobs to be processed,
regardless of the result of its parent job's validation. This isn't
correct, as a parent job contains actions necessary to successfully
process a dependent job. A prime example of this can be found within the
AuthenticatedGossiper, where an incoming channel announcement and update
are both processed, but if the channel announcement job fails to
complete, then the gossiper is unable to properly validate the update.
This commit aims to address this by preventing the dependent jobs to
run.
2021-03-23 11:56:51 -07:00
Wilmer Paulino
e713205eea
discovery: add missing error channel sends in processNetworkAnnouncement
Without the error channel sends, we would block the gossip message
stream upon receiving a premature channel announcement.
2021-03-23 11:56:31 -07:00