The author of this article is an original work of the Star Alliance

Filecoin has officially decided to use Lotus as the implementation system for the upcoming December 11 test of the web line.

Lotus, as a good Filecoin implementation, is currently getting the attention of both the authorities and the test miners, and is being prepared to test the web with numerous updates and Bug fixes every day. So understanding the Lotus implementation is important to understanding the Filcoin project as a whole. This article, the first in a series of source code analyses, will take you through the current directory structure of Lotus to give you an intuitive understanding of the Lotus project and a good foundation for further understanding of the source code.


API directory

Provides background services for Lotus commands, most of which need to communicate with background services, often involving on-chain data. This directory abstracts the node definition and defines several go interfaces, such as Common (defining the Common function of the node), FullNode (defining the behavior of a whole node, inherited from Common), StorageMiner (StorageMiner, also inherited from Common), and related functions.

Implementations of several structs (CommonStruct, FullNodeStruct, and StorageMinerStruct) use the proxy mode to simply forward requests to their respective Internal members. Specific functions need to be provided by the user, such as the function to get the list of payment channels:

The build directory

Define functions used to build nodes, including but not limited to: get startup parameters from trusted nodes (located in Paramfetch. Go), generate built-in genesis blocks (located in genesis. Go), etc. Genesis subdirectory: Built-in Genesis block data

Cli directory

The implementation of the Lotus command-line tools relies on the package gopkg.in/urfave/cli.v2, where the go file name is basically the same as the Lotus subcommand. A Command object is defined for each sub-command and subcommand, such as for a Lotus chain Command:

The corresponding Command is defined in the file chain.go:

CMD directory

With various command-line projects, Lotus divides the system into different process modules and defines a project for each module:

directory project instructions
lotus daemon Synchronizing data on the public chain, interacting with the public chain, and so on, is one of the primary lotus processes
lotus-bench Benchmarking tool
lotus-storage-miner The mining process Package information into blocks that store miners
lotus-seal-worker Sealed data process Sealing data is an essential part of mining process, this process is to achieve this function

Chain directory

To realize the interaction function with the chain, mainly divided into sub-directories:

  • Types: Defines the various data structures in Filecoin
  • Store: Public chain stores correlation and handles all local chain states, including headers, messages, and states
  • State: Handles the state tree of Filecoin, internally wrapped with HAMT
  • Actors: Definitions of various actors built into the Filecoin network
  • Vm: The Filecoin virtual machine, which implements tools that call actor methods in Filecoin

Miner directory

Define output block logic and interact with full nodes through APIS

Storage directory

Define storage miner logic for implementing “lotus-storage-miner”

The node directory

Structs and interfaces related to Lotus nodes are defined, and the main subdirectories are as follows:

  • Hello: Implements the Hello protocol
  • Modules: Defines functions that implement node functions, such as:

Create a wallet

func NewWallet(keystore types.KeyStore) (*Wallet, error) {
	w := &Wallet{
		keys:     make(map[address.Address]*Key),
		keystore: keystore,
	}

	return w, nil
}
Copy the code

Chain store:

func ChainStore(lc fx.Lifecycle, bs dtypes.ChainBlockstore, ds dtypes.MetadataDS) *store.ChainStore {
	chain := store.NewChainStore(bs, ds)

	iferr := chain.Load(); err ! = nil { log.Warnf("loading chain state from disk: %s", err)
	}

	return chain
}
Copy the code

Repo: A local repository for on-chain data that interacts with the local file system

Documentation directory

Lotus document directory. Lotus plans to provide documents in both Chinese and English, but the English document is being improved gradually, but the CN directory is empty. The existing documents mainly cover the following aspects:

  • New guidance
  • Hardware requirements
  • Lotus installations on a variety of systems
  • Node Operation Guide
  • How to join the development network
  • Pond was introduced
  • Dig guidance
  • Stores data to the system

Lib directory

Implements functions common to all modules of the Lotus project

  • Crypto: realize data encryption, public key generation, signature and signature verification, etc
  • Jsonrpc: Implements an RPC package that transmits data based on JSON, including a server and a client, to provide complete RPC functionality support for other projects
  • Statestore: Wrap github.com/ipfs/go-datastore for status tracking
  • Sectorbuilder: Implements sector management
  • Bufstore: : package github.com/ipfs/go-ipfs-blockstore, which integrates the read and write functions of Blockstore
  • Cborutil: wrapped github.com/ipfs/go-ipld-cbor to provide an easy way to manipulate CBOR data
  • Auth: implements the HTTP interface of the permission authentication service

Lotuspond directory

Pond project directory, Pond is a UI tool for managing Lotus that can be used to set up a separate local network for easy debugging. Pond starts the node, connects with the specified topology, starts mining, and continuously monitors node health.

Retrieval directory

Realize the function of retrieving miners and clients

Scripts directory

Various run scripts, used for heat nodes, miners, etc., also include some configuration files for startup

conclusion

Believe it or not, blockchain is changing and will continue to change the world around us, and Filecoin, as the star blockchain project of the day, deserves our attention. The Star Alliance will continue to share technology on Filecoin, learning and improving with you, and getting early access to the next storage empire.