MCPcopy Create free account
hub / github.com/ethereum/node-crawler / UpdateNodes

Function UpdateNodes

pkg/crawlerdb/db.go:26–142  ·  view source on GitHub ↗
(db *sql.DB, geoipDB *geoip2.Reader, nodes []common.NodeJSON)

Source from the content-addressed store, hash-verified

24func (v ETH2) ENRKey() string { return "eth2" }
25
26func UpdateNodes(db *sql.DB, geoipDB *geoip2.Reader, nodes []common.NodeJSON) error {
27 log.Info("Writing nodes to db", "nodes", len(nodes))
28
29 now := time.Now()
30 tx, err := db.Begin()
31 if err != nil {
32 return err
33 }
34 stmt, err := tx.Prepare(
35 `INSERT INTO nodes(
36 ID,
37 Now,
38 ClientType,
39 PK,
40 SoftwareVersion,
41 Capabilities,
42 NetworkID,
43 ForkID,
44 Blockheight,
45 TotalDifficulty,
46 HeadHash,
47 IP,
48 Country,
49 City,
50 Coordinates,
51 FirstSeen,
52 LastSeen,
53 Seq,
54 Score,
55 ConnType
56 ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
57 )
58 if err != nil {
59 return err
60 }
61 defer stmt.Close()
62
63 for _, n := range nodes {
64 info := &common.ClientInfo{}
65 if n.Info != nil {
66 info = n.Info
67 }
68
69 if info.ClientType == "" && n.TooManyPeers {
70 info.ClientType = "tmp"
71 }
72 connType := ""
73 var portUDP enr.UDP
74 if n.N.Load(&portUDP) == nil {
75 connType = "UDP"
76 }
77 var portTCP enr.TCP
78 if n.N.Load(&portTCP) == nil {
79 connType = "TCP"
80 }
81 fid := fmt.Sprintf("Hash: %v, Next %v", info.ForkID.Hash, info.ForkID.Next)
82
83 var eth2 ETH2

Callers 1

CrawlRoundMethod · 0.92

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected