server: fix timestamp comparison in setSelfNode
Fix bug where setSelfNode compared only the seconds component of timestamps instead of the full timestamp. This caused the node to attempt persisting an older timestamp than what existed in the database during restart, resulting in "sql: no rows in result set" errors.
This commit is contained in:
2 files changed
+158
-3
No files matched your search
@@ -5556,6 +5556,20 @@ func (s *server) AttemptRBFCloseUpdate(ctx context.Context,
|
||||
return updates, nil
|
||||
}
|
||||
|
||||
// calculateNodeAnnouncementTimestamp returns the timestamp to use for a node
|
||||
// announcement, ensuring it's at least one second after the previously
|
||||
// persisted timestamp. This ensures BOLT-07 compliance, which requires node
|
||||
// announcements to have strictly increasing timestamps.
|
||||
func calculateNodeAnnouncementTimestamp(persistedTime,
|
||||
currentTime time.Time) time.Time {
|
||||
|
||||
if persistedTime.Unix() >= currentTime.Unix() {
|
||||
return persistedTime.Add(time.Second)
|
||||
}
|
||||
|
||||
return currentTime
|
||||
}
|
||||
|
||||
// setSelfNode configures and sets the server's self node. It sets the node
|
||||
// announcement, signs it, and updates the source node in the graph. When
|
||||
// determining values such as color and alias, the method prioritizes values
|
||||
@@ -5623,9 +5637,9 @@ func (s *server) setSelfNode(ctx context.Context, nodePub route.Vertex,
|
||||
// If we have a source node persisted in the DB already, then we
|
||||
// just need to make sure that the new LastUpdate time is at
|
||||
// least one second after the last update time.
|
||||
if srcNode.LastUpdate.Second() >= nodeLastUpdate.Second() {
|
||||
nodeLastUpdate = srcNode.LastUpdate.Add(time.Second)
|
||||
}
|
||||
nodeLastUpdate = calculateNodeAnnouncementTimestamp(
|
||||
srcNode.LastUpdate, nodeLastUpdate,
|
||||
)
|
||||
|
||||
// If the color is not changed from default, it means that we
|
||||
// didn't specify a different color in the config. We'll use the
|
||||
|
||||
Reference in new issue
Block a user