Closed SimonSK closed 6 years ago
After performing DAO fork check through BlockHeaders/GetBlockHeaders exchange, dao_fork
field on the database and DAOForkSupport
field in the Info
struct are updated.
bool
to a signed int. 1 = true (mainnet), 0 (or NULL on db) = unknown, -1 = false (classic).eth/node_info.go
storeDAOForkSupportInfo
): if current DAOForkSupport
is 0, then simply update the existing entry as it is the first time we learned about the node's DAOForkSupport
status. Otherwise, if the DAOForkSupport
status changed for some reason, add a new entry, copying all other information from the previous entry.If any part of the initial sql preparation (p2p/server.go:385
) returns error, the client goes through proper shutdown procedures.
If the db handle exists but a prepared statement variable is null, the client immediately exits using log.Crit
.
If the client fails to execute a prepared statement, it logs the error as well as the values that were supposed to be added to the db.
After the changes,
Another TODO added to #15 is removing case-study style log messages from node-finder. That was the first thing I brought from case-study thinking it would be useful, but now I find it too much. I plan to remove them in the next PR, which will also include the following two:
All commits so far. I was going to submit multiple PRs, but branches kept diverging, so here it is. I will try my best to summarize them below.
Minor changes and other changes related to the last PRs (#13, #14):
mysql/mysqldb.py
: some changes to sql table schemesp2p/discover
: sql related functions inudp.go
are now moved tosql_stmt.go
.addNodeMetaInfo
is removed as we don't actually care about the node addresses fromNeighbors
packets.DEVp2p Hello (
p2p
package):p2p/node_info.go
Info
struct contains a node's DEVp2p Hello and Ethereum Status info and also keeps track of the most recent db entry's row ID.knownNodeInfos
is a struct that wraps a map ofInfo
s. It contains a mutex lock.storeNodeInfo
does the following: If a new node (not in the in-memory database): 1. add a new entry to the sql db, 2. get the entry's row ID, 3. store the information in-memory, 4. add the node as a new static node. Else, check if any information (except timestamp and remote_port) changed. If changed, treat it as a new node; otherwise, update the existing db entry.KnownNodes
is called by the Javascript Console to print out all node information. I implemented it for debugging purpose.p2p/rlpx.go
doProtoHandshake
andreadProtocolHandshake
inp2p/rlpx.go
are modified to return the message received time.doProtoHandshake
behavior changed to attempt to read the peer's Hello message before we send out ours. This change is to avoid situations where the peers reject us based on our information before their information reach us.p2p/rlpx_test.go
p2p/rlpx.go
p2p/server.go
GetRowIDStmt
is made public because the Ethereum protocol manager also uses it.p2p/sql_stmt.go:initSql
sets up db connection and prepares statements when the p2p server starts.p2p/sql_stmt.go:CloseSql
closes the statements and db connection when the server stops. It is made public becausenode
package also needs to call it when the p2p server fails to start properly.p2p/node_info.go:storeNodeInfo
is called insideSetupConn
. This is where storing to mysql db and updating in-memory database occur.p2p/sql_stmt.go:addNodeMetaInfo
is manually called if the handshake fails because the peer said "TooManyPeers".p2p/sql_stmt.go
: sql related functionsloadKnownNodeInfos
is called to fill the in-memory database with the known information from our sql db. While loading, each node address is added toStaticNodes
so that they are re-dialed automatically (currently at the default hardcoded frequency 30s).Ethereum Status (
eth
package):eth/backend.go
GetRowIDStmt
andKnownNodeInfos
(in-memory database). It directly accesses the map of node infos (not theknownNodeInfos
wrapper) because it won't need the mutex lock (it does not change/add anything new to the map).eth/handler.go
eth/sql_stmt.go:prepareSqlStmts
prepares statements when the eth protocol manager starts.eth/sql_stmt.go:closeSqlStmts
closes the statements when the manager stops.statusDataWrapper
is used to pass the peer's status info (with received timestamp and handshake failure error) to the protocol manager.eth/node_info.go:storeEthNodeInfo
is called. This is where storing to mysql db and updating in-memory database occur.eth/node_info.go:storeEthNodeInfo
is called when unexpected Status messages arrive.eth/node_info.go
storeEthNodeInfo
only considers nodes that are present in the in-memory database. If the current information contains no Eth Status information, add them to the existing node entry. If eth information changed: 1. add a new node entry to the sql db, 2. get the rowid; else, just update the eth information of the existing entry.eth/peer.go
validStatus
returns true if the peer's status resulted in error because of the specified mismatches.Handshake
andreadStatus
modified to handlestatusDataWrapper
eth/sql_stmt.go
: sql related functionsinternal/web3ext/web3ext.go
andnode/api.go
: to allow callingKnownNodes
through the Javascript consoleTODOs (added to #15):