mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 14:12:27 +02:00
sqldb+graph/db: fix UpsertNode bug
Account for the last_update field being null.
This commit is contained in:
@ -3361,18 +3361,7 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
|
|||||||
require.ErrorIs(t, err, ErrEdgeAlreadyExist)
|
require.ErrorIs(t, err, ErrEdgeAlreadyExist)
|
||||||
|
|
||||||
// Show that updating the shell node to a full node record works.
|
// Show that updating the shell node to a full node record works.
|
||||||
err = graph.AddLightningNode(node2)
|
require.NoError(t, graph.AddLightningNode(node2))
|
||||||
_, ok := graph.V1Store.(*KVStore)
|
|
||||||
if ok {
|
|
||||||
require.NoError(t, err)
|
|
||||||
} else {
|
|
||||||
// Currently the SQL UpsertNode query prevents us from updating
|
|
||||||
// the node record if the current record's last_update field
|
|
||||||
// is null (which is the case for node2). This is a bug that
|
|
||||||
// will be fixed in the following commit.
|
|
||||||
require.ErrorContains(t, graph.AddLightningNode(node2),
|
|
||||||
"sql: no rows in result set")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed
|
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed
|
||||||
|
@ -542,7 +542,8 @@ ON CONFLICT (pub_key, version)
|
|||||||
last_update = EXCLUDED.last_update,
|
last_update = EXCLUDED.last_update,
|
||||||
color = EXCLUDED.color,
|
color = EXCLUDED.color,
|
||||||
signature = EXCLUDED.signature
|
signature = EXCLUDED.signature
|
||||||
WHERE EXCLUDED.last_update > nodes.last_update
|
WHERE nodes.last_update IS NULL
|
||||||
|
OR EXCLUDED.last_update > nodes.last_update
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ ON CONFLICT (pub_key, version)
|
|||||||
last_update = EXCLUDED.last_update,
|
last_update = EXCLUDED.last_update,
|
||||||
color = EXCLUDED.color,
|
color = EXCLUDED.color,
|
||||||
signature = EXCLUDED.signature
|
signature = EXCLUDED.signature
|
||||||
WHERE EXCLUDED.last_update > nodes.last_update
|
WHERE nodes.last_update IS NULL
|
||||||
|
OR EXCLUDED.last_update > nodes.last_update
|
||||||
RETURNING id;
|
RETURNING id;
|
||||||
|
|
||||||
-- name: GetNodeByPubKey :one
|
-- name: GetNodeByPubKey :one
|
||||||
|
Reference in New Issue
Block a user