-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging neighbors, devp2p hello, eth status info into mysql #16
Conversation
interaction with sql db yet).
address, should allow default NULL value
reduced to MaxDial/3
previously recorded tcpPort is not 0
fixed some logging messages variables renamed
p2p/server.go
Outdated
&sqlObj.p2pVersion, &sqlObj.clientId, &sqlObj.caps, &sqlObj.listenPort, | ||
&sqlObj.firstHelloAt, &sqlObj.lastHelloAt, &sqlObj.protocolVersion, &sqlObj.networkId, | ||
&sqlObj.firstReceivedTd, &sqlObj.lastReceivedTd, &sqlObj.bestHash, &sqlObj.genesisHash, | ||
&sqlObj.daoForkSupport, &sqlObj.firstStatusAt, &sqlObj.lastStatusAt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just found out I screwed up the order here. This does not match the order used in line 987. &sqlObj.daoForkSupport
should be the last column. I will push this change shortly.
…ate files function names renamed bug fix
8da924f
to
078d872
Compare
10d954a
to
a4e152d
Compare
8b0aa09
to
a10c7ec
Compare
After performing DAO fork check through BlockHeaders/GetBlockHeaders exchange,
|
If any part of the initial sql preparation ( After the changes,
|
@@ -285,13 +296,19 @@ func (p *peer) readStatus(network uint64, status *statusData, genesis common.Has | |||
|
|||
p.Log().Proto("<<"+ethCodeToString[msg.Code], "receivedAt", unixTime, "obj", status, "size", int(msg.Size), "peer", p.ID()) | |||
|
|||
statusWrapper.ReceivedAt = &msg.ReceivedAt | |||
statusWrapper.Status = &status | |||
|
|||
if status.GenesisBlock != genesis { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zzma I decided to keep this behavior (as well as checking the error code again in eth/handler.go:216
) for now. If these 3 mismatch checks are removed, our node will assume the peer is compatible (e.g. on the same blockchain) and resume other behaviors, such as DAO fork check through BlockHeader exchange. I assume the peer will do the same checks and disconnect us anyways, but I am not sure if that assumption is enough to remove the checks.
Another TODO added to #15 is removing case-study style log messages from node-finder.
|
prepared stmt checking done in each stmt exec function
and total difficulty values total difficulty value is limited to 65 digits, max allowed in the field on the mysql table
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):
make re-dial frequency as an configurable optionupdate daofork check