Skip to content

Commit 0862ba3

Browse files
committed
server: ensure newer node announcement timestamp
On startup, we currently blindly overwrite our node announcement info for our source node. This includes overwriting the existing LastUpdate timestamp. This can cause an issue with our new SQL backends in the case that the new timestamp is not greater than the previously written timestamp. So here, we first fetch the source node and make sure to use a timestamp that is greater than the previosly set one.
1 parent 8cf567b commit 0862ba3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

server.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,35 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
950950
if err != nil {
951951
return nil, err
952952
}
953+
954+
// TODO(elle): All previously persisted node announcement fields (ie,
955+
// not just LastUpdate) should be consulted here to ensure that we
956+
// aren't overwriting any fields that may have been set during the
957+
// last run of lnd.
958+
nodeLastUpdate := time.Now()
959+
srcNode, err := dbs.GraphDB.SourceNode(ctx)
960+
switch {
961+
// If we have a source node persisted in the DB already, then we just
962+
// need to make sure that the new LastUpdate time is at least one
963+
// second after the last update time.
964+
case err == nil:
965+
if srcNode.LastUpdate.Second() >= nodeLastUpdate.Second() {
966+
nodeLastUpdate = srcNode.LastUpdate.Add(time.Second)
967+
}
968+
969+
// If we don't have a source node persisted in the DB, then we'll
970+
// create a new one with the current time as the LastUpdate.
971+
case errors.Is(err, graphdb.ErrSourceNodeNotSet):
972+
973+
// If the above cases are not matched, then we have an unhandled non
974+
// nil error.
975+
default:
976+
return nil, fmt.Errorf("unable to fetch source node: %w", err)
977+
}
978+
953979
selfNode := &models.LightningNode{
954980
HaveNodeAnnouncement: true,
955-
LastUpdate: time.Now(),
981+
LastUpdate: nodeLastUpdate,
956982
Addresses: selfAddrs,
957983
Alias: nodeAlias.String(),
958984
Features: s.featureMgr.Get(feature.SetNodeAnn),

0 commit comments

Comments
 (0)