lnd/graph
Elle Mouton c207461aca
graph/db: fix SetSourceNode race with lenient upsert
This commit fixes a race condition where multiple goroutines call
SetSourceNode concurrently during startup, causing sql.ErrNoRows
errors. The race occurs when multiple code paths (setSelfNode,
createNewHiddenService, RPC updates) read the same old timestamp,
independently increment it to the same new value (T+1), and race to
write.

The fix uses the new UpsertSourceNode SQL query (without strict
timestamp constraint) instead of UpsertNode. This allows
last-write-wins semantics for our own node, ensuring all parameter
changes persist even when timestamps collide.

Refactored sql_store.go for reusability:
- upsertNodeAncillaryData: common logic for features/addresses/extras
- populateNodeParams: common parameter building with callback pattern
- buildNodeUpsertParams: builds params for strict UpsertNode
- buildSourceNodeUpsertParams: builds params for lenient UpsertSourceNode
- upsertSourceNode: new function using lenient query

Updated TestSetSourceNodeSameTimestamp to verify that concurrent
updates with the same timestamp now succeed and parameter changes
persist.

Fixes the itest error:
"unable to upsert source node: upserting node(...): sql: no rows in
result set"
2025-12-04 12:21:40 +02:00
..
db graph/db: fix SetSourceNode race with lenient upsert 2025-12-04 12:21:40 +02:00
testdata refactor: move various duties from ChannelRouter to graph.Builder 2024-07-15 15:56:33 +02:00
builder.go graph: fix log formatting 2025-10-06 10:59:39 +02:00
builder_test.go multi: rename AddLightningNode methods 2025-09-03 10:14:35 +02:00
errors.go multi: use the "errors" package everywhere 2025-06-30 09:46:55 +02:00
interfaces.go graph+discovery: update graph/db gossip backlog interfaces to use iter.Seq2 2025-09-26 17:01:11 -07:00
log.go multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
notifications_test.go multi: rename models.LightningNode to models.Node 2025-09-03 10:14:35 +02:00
setup_test.go refactor: move various duties from ChannelRouter to graph.Builder 2024-07-15 15:56:33 +02:00
stats.go graph: rename routerStats to builderStats 2025-02-07 13:01:39 +02:00