Proficient in Filecoin: System Startup
commands/daemon.go
file, and its Run
method directly calls the daemonRun
function in the same file for processing. The processing of this function is as follows:
- Call
getRepo
to get the local repositoryrepo.Repo 接口
object. This method internally calls theOpenFSRepo
function of the repository to generate and initialize the repository object. The flow is as follows:- Generates a repository
repo.FSRepo 对象
based on the repository path and version. - Lock the
repo.lock
file of the relevant repository and set thelockfile
property of the repository object to ensure that only one full node can use the repository at the same time in order to maintain the integrity of the repository. - Call the
loadFromDisk
method of the repository object, load the various data of the repository from the disk, and continue to improve the repository object. The flow of this method is as follows:- Call the
readVersion
method of the repository object, read the version number of the repository from the repository file, and compare it with the version number of the repository object itself. If it does not match, an error is thrown. - Call the
loadConfig
method of the repository object and load the repository configuration fileconfig.json
. - Call the
openDatastore
method of the repository object to load the data storage file of the repository. By default, the data storage type isbadgerds
, so the loaded file directory is this directory under the repository. This method generates a repository storage object and saves theds
property of the repository object. - Call the
openKeystore
method of the repository object to open thekeystore
file of the repository. This method generates a private key storage object and saves it in thekeystore
property of the repository object. - Open the wallet data store by calling the
openWalletDatastore
method of the repository object. This method generates a repository storage object and saves thewalletDs
property of the repository object. The directory corresponding to this object iswallet
. - Call the
openChainDatastore
method of the repository object to open theopenChainDatastore
data store. This method generates a repository storage object and saves thechainDs
property of the repository object. The directory corresponding to this object ischain
. - Call the
openDealsDatastore
method of the repository object to open the transaction data store.
This method generates a repository storage object and saves the
dealsDs
property of the repository object. The directory corresponding to this object isdeals
. - Call the
- Generates a repository
- Get the environment variable.
- Get the command line arguments.
- Call the node's
New
method to create a node. First, generate a configuration object, use the option parameters and warehouse objects formed in the previous steps to set the configuration object; then call theBuild
method of the configuration object to build a Filecoin node. When we start without parameters, only the repository object in the configuration object will be set.Build
function execution flow is as follows:- If there is no warehouse object in the configuration object, a memory version of the warehouse object is generated.
- Generate a block storage object.
- 'Invoke the
buildHost
method of the configuration object to generate the libp2p Host object'.buildHost
method calls theNew
method of libp2p, which finally calls theNewNode
method defined inconfig/config.go
. This method:- First, create a swarm object by calling the
NewSwarm
'sNewSwarm
method. - Then, call
basic_host.go
defined inNewHost
to create the host object. In the process of creating the host object, save the swarm object as the network object of the host object, and set the connection handler and stream processor of the swarm to be thenewStreamHandler
method of thenewConnHandler
andnewStreamHandler
of the host object. - Then, call the
AddTransport
'sAddTransport
method to add the specified transport association. - Finally, the host's
Listen
method is called and starts listening for the specified address.
- First, create a swarm object by calling the
- Generate a pinger service object.
- Generate a block validator consensus.DefaultBlockValidator object.
- Generate a bitswap network object using the libp2p Host object and the route object.
- Generates a bitswap object using the bitswap network object and the block storage object.
- A block service object is generated using the block storage object and the bitswap object.
- Generate a get block net.Fetcher object to get data from a remote node.
- ''call the
readGenesisCid
function to get the CID' of the creation block. - Generate a chain.Store object.
- Generate a chain.ChainStateProvider object.
- Generate a
powerTable
object of typepowerTable
object. - Call different method node consensusors depending on whether the configuration object has a reward. If the reward object is empty, the Consensus
consensus/processor.go
NewDefaultProcessor
function is called to generate the consensus; otherwise, theNewConfiguredProcessor
function is called to generate the consensus. Both functions generate a consensus.DefaultProcessor object, and the blocks are in their properties. - Call the
NewExpected
function ofconsensus/NewExpected.go
to generate the consensus.Protocol interface node consensus.Expected object. Depending on whether the configuration object has a proofs.Verifier interface object, different parameters are used during the build process. - Call the
NewFloodSub
function of the go-libp2p-pubsub class library to generate a publish/subscribe pubsub.PubSub objectfsub
that listens for all of its own messages. - Use the
walletDs
property of the repository repo.Repo interface object as the wallet backend to generate the wallet.Wallet object. - Call the
chain/syncer.go
NewSyncer
function to generate the blockchain chain.Syncer synchronization object. - Generate a core.MessagePool object.
- Generate a core.Inbox object.
- Generate a core.MessageQueue object.
- Generate a node.defaultMessagePublisher object. The subject of the message publishing object binding is
/fil/msgs/devnet-3
, which posts a message on this topic. In the startup method of the whole node, the message notification of this topic is subscribed by calling thePubSubSubscribe
method of the porcelain.API object. - Generate a core.Outbox object. The message publishing object created by the object in the previous step, when the
MessageSend
method of the pornelain.API object is called to send a message, internally calls theSend
method of the object to send. The sending method finally calls thePublish
message publishing object, and posts the signed message to the corresponding topic. After the message is sent, other full-node objects will be processed by calling theprocessMessage
of the whole node because they subscribe to the message subject. See the full node startup process for details. - 'Generate a PorcelainAPI object.
- 'Generate a Filecoin node.Node full node object.
- 'Generate the net.Bootstrapper boot object.
- Returns a Filecoin full node object.
- Call the internal function
runAPIAndWait
to start the full node.- ''Invoke the node's
Start
method, start the Filecon node''.- Call the
Load
method of the chain.Store object to load the local existing block. - Call the
miningAddress
method of the full-node object to obtain the miner address; if the miner address is configured, call thesetupMining
method of the node.Node full-node object to set the mining. This method calls theinitSectorBuilderForNode
function, initializes the initialized sector generator, and saves it on thesectorBuilder
property of the full-node object. - Generates a
syncCallBack
synchronization callback function object for handling block synchronization. - Call the
New
function of theprotocol/hello/hello.go
file to perform Hello message processing. The internal processing of this method is as follows:- Generates a hello
HelloSvc
processor object and sets it as theHelloSvc
property of the full node object. - Set the libp2p
/fil/hello/1.0.0
protocol handler to thehandleNewStream
method of the protocol.hello.Handler object. - Set the connection notification for the libp2p network object to be the protocol.hello.helloNotify object.
- Generates a hello
- Set the various definitions by calling the
setupProtocols
method of the Filecoin node. The internal processing of this method is as follows:- Generate a protocol.block.MiningAPI object and save it as the
BlockMiningAPI
property of the full-node object. - Call the
NewAPI
function of theprotocol/retrieval/api.go
file to generate the protocol.retrieval.API object and promote theRetrievalAPI
property of the full-node object. - Call the
NewAPI
function of theprotocol/storage/api.go
file to generate the protocol.storage.API object and promote theStorageAPI
property of the full-node object.
- Generate a protocol.block.MiningAPI object and save it as the
- Using the node object as a parameter, call the
NewMiner
function ofprotocol/retrieval/NewMiner.go
to generate a retrieve miner and set theRetrievalMiner
property of the full node object. This function first generates aSetStreamHandler
method that retrieves the miner, then calls the libp2p Host object of the full-node object, sets the handler for the/fil/retrieval/free/0.0.0
protocol to retrieve the miner'shandleRetrievePieceForFree
method, and finally returns to retrieve the miner. - Call the
PubSubSubscribe
method of the porcelain.API object, subscribe to the block notification of the/fil/blocks/devnet-3
topic, and set it to theBlockSub
property of the full node. - Call the
PubSubSubscribe
method of the porcelain.API object, subscribe to the message notification of the/fil/msgs/devnet-3
topic, and set it to theMessageSub
property of the full node. - Start a coroutine, call the
handleSubscription
method of the whole node in thehandleSubscription
, and process the block notification. The main body of this method is an infinite loop. It reads the topic from the topic specified by the parameter and calls the method specified by the parameter for processing. The block notification is subscribed to/fil/blocks/devnet-3
, and its processing method is theprocessBlock
method of the whole node. - Start a coroutine, call the
handleSubscription
method of the whole node in thehandleSubscription
process the message notification. The message notification is subscribed to/fil/msgs/devnet-3
, and its processing method is theprocessMessage
method of the whole node. This method deserializes the received message and then calls theAdd
method of the core.Inbox object to save the message object in the core.MessagePool object. - Call the
HeadEvents
method of the chain.Store object and subscribe to the new block header topicnew-head
using theSub
method of the publish/subscribe object it returns. - Call the
ChainHead
method of the porcelain.API object, return the function that handles the block chain header, call thehandleNewHeaviestTipSet
method of the whole node in ahandleNewHeaviestTipSet
, and process the block chain header message. - In non-offline mode, start the net.Bootstrapper boot object. The boot object will connect to all boot nodes, and after the connection is successful, call the
Connected
method of the protocol.hello.helloNotify object to send its own top-level block information to the remote node, and the remote node will send us its top level. Block information, thus opening the block synchronization process. - Set up heartbeat services.
- Call the
- Generate a command line environment commands.Env object.
- Generate server configuration variables
- Generate the Go
ServeMux
processor object, set it to handle the/debug/pprof/
request object as Go's ownDefaultServeMux
; handle the/api/
requested go-ipfs-cmds class libraryhandler
object.handler
object holds the environment variables, server configuration variables, etc. generated above. - Create an Http server.
- Start the Http server in a separate thread.
- ''Invoke the node's
We will continue to update Blocking; if you have any questions or suggestions, please contact us!
Was this article helpful?
93 out of 132 found this helpful
Related articles
- Central Bank Shanghai Headquarters issued a document: increase supervision and prevention, and combat virtual currency transactions
- DC/EP makes the US panic? Former government officials organize digital currency war exercises to discuss countermeasures
- Case Study: Most of the victims of cryptocurrency scams come from these four countries. There are three common ways.
- After the listing of Jianan Technology, it broke on the same day, the main business is single, the performance is less than the industry leader 10%
- The $5 trillion brokerage giant will be born, and the bitcoin price may be unexpectedly affected.
- $ 383 million! The Korean government will provide huge incentive funds for blockchain development
- Thoughts on the Development of Stabilizing Coins and the Repositioning of DEX