gethp2pstart
2020-01-07 13:49:12 0 举报
登录查看完整内容
以太坊工作流程
作者其他创作
大纲/内容
setNodeConfig
go dl.qosTuner() record confidence in d.rttConfidence) in round trip way
txsyncLoop
make some initialization
p2pServer start
setNodeKey
WalletArrived -event.Wallet.Open(WalletOpened-event.Wallet.SelfDerive(WalletDropped-event.Wallet.Close(
startNode
load trusted nodes from trusted-nodes.jsoninit databaseinit p2pServer
ethereum service start
ListenLoop accept incomming connection and setup MeteredConn and call p2pServer SetupConn with the meteredConn + inboundConn flag
downloader.LightSync ?
yes
loop service in node call constructor for the service with current config context: ctx
init netRPCService with p2p server infoadjust maxPeers count
syncereth/sync.go
receive new peer or force synchronize with peer -- call pm.synchronise
pm.eventMux.Subscribe(core.NewMinedBlockEvent{})pm.minedBroadcastLoop()
if enable dashBoard then RegisterDashboardService
generate nodeName
1
startBloomHandlers in eth/bloombits.gostart bloomServiceThreads = 16 thread to handle incoming eth.bloomRequests
node's protocolManager start with maxPeers count
load config info from config file
Loop service in node and start itnormally the eth/backend.go start will be called
init wallevent channel and subscribe it in AccountManageruse node attach to start listen rpc connection
Downloader.synchronize will trittyer syncWithPeer and trigger processFastSyncContent and trigger syncStateand it will make downloader and root hash as parameters into newStateSync and send it to d.stateSyncStart
Node wait for terminal signal from channel
RegisterShhService configures Whisper and adds it to the given node.
discover/table.gonewTable-Table.Loop-Table.doRefresh-Table.loopup-Table.findnode
2
makeFullNode
use commandline or config file to generate nodeKeycrypto.LoadECDSA(file)crypto.HexToECDSA(hex)
setNAT
generate nodeKey
unlock AccountManager; Establish RPC client
crypto.GenerateKey()crypto.LoadECDSA(keyfile);
traverse all peer which don't know the tx.hashcall peer.AsyncSendTransactions(txs)which put the txs to queuedTxsin eth/peer.go there is a boardcast loop which retrieve message from .. to..queuedTxs - SendTransactionsqueuedProps - SendNewBlockqueuedAnns - SendNewBlockHashes
wallet event handling
protocolManager started with 4 go routine1. txBroadcastLoop2. minedBroadcastLoop3. syncer4. txsyncLoop
init a channel pm.txsChcall core/tx_pool.go SubscribeNewTxsEvent with the pm.txsChcall loop to listen pm.txsCh and pm.BroadcastTxs(event.Txs)
node.go Start()
minedBroadcastLoop will send the block hash and Td to those unknown peers's subset(sqrt the number of unknow peers) if propagate then adjust the Td with parentBlock's td
begin to call go routine udp readloop
loadDefaults
rpc message handling
start wallet event listener loop
SetP2PConfig
begin to call go routine udp loop()it listen the income reply and check if match or not and push it in pending list
newStateSync creates a new state trie download scheduler
handling attached rpc messagereturn the channel which reading input message
exit
call go routine p2p server run dialer
use the previous established conn and exterIpAddr with unhandled channel in cfg with bootstrapnodesto init discover service
makeConfigNode
start geth
node/node.go startRPC
go dl.stateFetcher()
in SetupConn call rlpx doEncHandshakewhich will call initiatorEncHandshakewhich will call sealEIP8then use readHandshakeMsg to read message into authRespPacketif handleAuthResp passed call secrets to extracts the connection secrets from the handshake values.after doEncHandshake then doProtoHandshakewhich will send handshakeMsg message to destPeerthen use p2p server checkpoint to wait for addPeer
check args 0
discover/udp.goadd findnode packet to pending channel waiting for reply matchand use udp send out the packet directllyand add the neighbors response's node into table
find all account in glob config need unlockand find the password in password fileenter into loop to call unlock with 3 password trying
loadConfigFile & loadConfigmakeAccountManager
loop service add all protocol into protocol listthen call p2p server start
the service original registered should be :les or eth
pm.txBroadcastLoop
no
sloop():SubscribeNewPeers make a channel listen to newPeerFeed event.Feedwhich is like a message centerin order to call peerSub.Unsubscribe() when exit loop
new downloader
RegisterEthService
handleMessage will handle following message in eth/handler.goGetBlockHeadersMsgBlockHeadersMsgGetBlockBodiesMsgBlockBodiesMsgGetNodeDataMsgNodeDataMsgGetReceiptsMsgReceiptsMsgNewBlockHashesMsgNewBlockMsgTxMsg
peer's TD should be greater than self TDcheck some condition to see if should set mode = downloader.FastSync
newUDP to establish node table
run state sync as go s.run()
pm.fetcher.Start()
pm.minedBroadcastLoop(
load static node from static-nodes.json
runStateSync
after readLoop and pingLoop call peer.go startProtocols1. loop each protocol in peer use the peer's events and protocol's protoRW to init newMsgEventer and use the newMsgEventer with peer as parameter to call protocol's run method 2. the run callbck function is defined in newProtocolManagerthe run callback will call newPeer in eth/handler.go and call eth/peer.go newPeer3. sendOut peer to manager.newPeerCh channel and call handle(peer) to process synchronization logic
fetcher/fetcher.go loop
p2p Server startListerning()
establish UDP listening connectionuse the connect to get addressmake NAT mapping in go routinethen try to get the address from NAT external IP
ready to for call d.runStateSync(next) when receive the stateSyncStart message
(p.from == r.from && p.ptype == r.ptype)
txBroadcastLoop will send tx to those peer who's knownTxs haven't contain the Txand the Tx will be send in channel queuedTxs of the peer
get nodeName from config env or from process name and add version info and os info
srv.quit = make(chan struct{})\tsrv.addpeer = make(chan *conn)\tsrv.delpeer = make(chan peerDrop)\tsrv.posthandshake = make(chan *conn)\tsrv.addstatic = make(chan *discover.Node)\tsrv.removestatic = make(chan *discover.Node)\tsrv.peerOp = make(chan peerOpFunc)\tsrv.peerOpDone = make(chan struct{})
DefaultMaxMessageSize = uint32(1024 * 1024)\tDefaultMinimumPoW = 0.2
end with err prompt
收藏
0 条评论
回复 删除
下一页