Skip to content

Commit

Permalink
fix(daemon): check for blank addresses when updating
Browse files Browse the repository at this point in the history
  • Loading branch information
juligasa committed Oct 18, 2024
1 parent 256d45e commit 0d40720
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/mttnet/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (n *Node) connect(ctx context.Context, info peer.AddrInfo, force bool) (err
}
defer release()

if err = sqlitex.Exec(conn, "INSERT INTO peers (pid, addresses, explicitly_connected) VALUES (?, ?, ?) ON CONFLICT(pid) DO UPDATE SET addresses=excluded.addresses, updated_at=strftime('%s', 'now') WHERE addresses!=excluded.addresses;", nil, info.ID.String(), initialAddrs, true); err != nil {
if err = sqlitex.Exec(conn, "INSERT INTO peers (pid, addresses, explicitly_connected) VALUES (?, ?, ?) ON CONFLICT(pid) DO UPDATE SET addresses=excluded.addresses, updated_at=strftime('%s', 'now') WHERE addresses!=excluded.addresses AND excluded.addresses !='';", nil, info.ID.String(), initialAddrs, true); err != nil {
n.log.Warn("Failing to store peer", zap.Error(err))
return err
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func (n *Node) storeRemotePeers(id peer.ID) (err error) {
n.log.Debug("Some of the remote shared peers are not running up to date seed protocol", zap.Uint32("Number of non-seed (outdated) peers", nonSeedPeers), zap.Int("Number of actual Seed-peers at the moment we stopped", len(vals)/4) /*since we insert four params at a time*/, zap.Errors("errors", xerr))
}
if len(vals) != 0 {
sqlStr = sqlStr[0:len(sqlStr)-1] + " ON CONFLICT(pid) DO UPDATE SET addresses=excluded.addresses, updated_at=excluded.updated_at WHERE addresses!=excluded.addresses AND excluded.updated_at > updated_at"
sqlStr = sqlStr[0:len(sqlStr)-1] + " ON CONFLICT(pid) DO UPDATE SET addresses=excluded.addresses, updated_at=excluded.updated_at WHERE addresses!=excluded.addresses AND excluded.addresses !='' AND excluded.updated_at > updated_at"
conn, release, err := n.db.Conn(ctxStore)
if err != nil {
n.log.Warn("Couldn't store shared peers", zap.Error(err))
Expand Down Expand Up @@ -351,7 +351,7 @@ func (n *Node) defaultIdentificationCallback(ctx context.Context, event event.Ev
return
}
defer release()
if err = sqlitex.Exec(conn, "INSERT INTO peers (pid, addresses, explicitly_connected) VALUES (?, ?, ?) ON CONFLICT(pid) DO UPDATE SET addresses=excluded.addresses, updated_at=strftime('%s', 'now') WHERE addresses!=excluded.addresses AND excluded.updated_at > updated_at;", nil, event.Peer.String(), strings.ReplaceAll(strings.Join(addrsString, ","), " ", ""), bootstrapped); err != nil {
if err = sqlitex.Exec(conn, "INSERT INTO peers (pid, addresses, explicitly_connected) VALUES (?, ?, ?) ON CONFLICT(pid) DO UPDATE SET addresses=excluded.addresses, updated_at=strftime('%s', 'now') WHERE addresses!=excluded.addresses AND excluded.addresses !='' AND excluded.updated_at > updated_at;", nil, event.Peer.String(), strings.ReplaceAll(strings.Join(addrsString, ","), " ", ""), bootstrapped); err != nil {
n.log.Warn("Could not store new peer", zap.String("PID", event.Peer.String()), zap.Error(err))
}

Expand Down

0 comments on commit 0d40720

Please sign in to comment.