### Install ABCI-CLI and Example Applications Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/app-dev/abci-cli.md Installs the abci-cli tool and example applications. Ensure Go is installed before running. ```sh git clone https://github.com/cometbft/cometbft.git cd cometbft make install_abci ``` -------------------------------- ### Build Binary and Install Source: https://github.com/celestiaorg/celestia-core/blob/main/CLAUDE.md Use 'make build' to compile the binary into the build/cometbft directory. Use 'make install' to install the binary to your GOBIN. ```bash make build make install ``` -------------------------------- ### Initialize and Start CometBFT Node Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/app-dev/getting-started.md Initialize CometBFT if it's your first time running it, then start a node. Ensure you have the CometBFT binary installed. ```sh cometbft init cometbft node ``` -------------------------------- ### Verify Go Installation Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Check your current Go version. Ensure you have the latest version installed by referring to the official Go installation guide. ```bash $ go version go version go1.25.1 darwin/amd64 ``` -------------------------------- ### Compile and Install CometBFT from Source Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/install.md Builds and installs the CometBFT binary into the Go bin directory. Ensure you are in the CometBFT project directory. ```sh make install ``` -------------------------------- ### Start a Local Node with KVStore App Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/quick-start.md Start CometBFT with a simple in-process application. Use `--proxy_app=persistent_kvstore` for an application with persistence. ```sh cometbft node --proxy_app=kvstore ``` -------------------------------- ### Install CometBFT and ABCI CLI Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/app-dev/getting-started.md Install the CometBFT library and the ABCI CLI tool. This prepares your environment to run ABCI applications. ```bash go get github.com/cometbft/cometbft cd $GOPATH/src/github.com/cometbft/cometbft make install_abci ``` -------------------------------- ### Install Dependencies Source: https://github.com/celestiaorg/celestia-core/blob/main/scripts/qa/reporting/README.md Installs project dependencies listed in the requirements.txt file into the activated virtual environment. ```bash pip install -r requirements.txt ``` -------------------------------- ### Reactor Implementation Example Source: https://github.com/celestiaorg/celestia-core/blob/main/spec/p2p/legacy-docs/connection.md An example demonstrating how to implement a Reactor to handle incoming messages on specific channels. ```APIDOC ## Switch/Reactor The `Switch` handles peer connections and exposes an API to receive incoming messages on `Reactors`. Each `Reactor` is responsible for handling incoming messages of one or more `Channels`. So while sending outgoing messages is typically performed on the peer, incoming messages are received on the reactor. ```go // Declare a MyReactor reactor that handles messages on MyChannelID. type MyReactor struct{} func (reactor MyReactor) GetChannels() []*ChannelDescriptor { return []*ChannelDescriptor{ChannelDescriptor{ID:MyChannelID, Priority: 1}} } func (reactor MyReactor) Receive(chID byte, peer *Peer, msgBytes []byte) { r, n, err := bytes.NewBuffer(msgBytes), new(int64), new(error) msgString := ReadString(r, n, err) fmt.Println(msgString) } // Other Reactor methods omitted for brevity ... switch := NewSwitch([]Reactor{MyReactor{}}) ... // Send a random message to all outbound connections for _, peer := range switch.Peers().List() { if peer.IsOutbound() { peer.Send(MyChannelID, "Here's a random message") } } ``` ``` -------------------------------- ### Start Celestia Node with E2E Proxy Source: https://github.com/celestiaorg/celestia-core/blob/main/test/e2e/README.md Run the `cometbft start` command with the `--proxy-app e2e` flag to use the e2e application. This offers less configurability compared to running a dedicated node binary. ```bash cometbft start --proxy-app e2e ``` -------------------------------- ### Run Go Program Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Navigate into your project directory and run the main.go file to see the output. This confirms your Go setup is working. ```bash cd kvstore $ go run main.go Hello, CometBFT ``` -------------------------------- ### Example Git commit message Source: https://github.com/celestiaorg/celestia-core/blob/main/CONTRIBUTING.md Follow the Go style guide for commit messages. Start with the package name, followed by a concise description that completes the sentence 'This change modifies CometBFT to...'. Include a longer description in the body if necessary and reference any related issues. ```git cmd/debug: execute p.Signal only when p is not nil [potentially longer description in the body] Fixes #nnnn ``` -------------------------------- ### IPFS Daemon Initialization Override Example Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/celestia-architecture/adr-004-mvp-light-client.md Demonstrates how default initialization in the IPFS daemon command can be overridden, providing a pattern for customizing light client initialization. ```go func daemonFunc(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() // Load the node nd, err := ipfs.Load(ctx) if err != nil { return fmt.Errorf("failed to load ipfs node: %w", err) } // Attach the node to the command so that the other commands can use it cmd.Root.Long = "" cmd.Root.RunE = func(cmd *cobra.Command, args []string) error { return cmd.Help() // If no subcommand is specified, show help. } // Start the node log.SetOutput(io.Discard) return nd.Online(ctx) } ``` -------------------------------- ### Initialize KVStoreApplication Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Demonstrates the invocation of the KVStoreApplication constructor in the main application flow. Currently accepts nil for the database handle. ```go _ = NewKVStoreApplication(nil) ``` -------------------------------- ### Reset CometBFT Data and Start Node Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/app-dev/getting-started.md If you have used CometBFT before, reset its data for a new blockchain and then start the node. Refer to the CometBFT guide for more details. ```sh cometbft unsafe-reset-all cometbft node ``` -------------------------------- ### Get CometBFT Source Code Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/install.md Clones the CometBFT repository and navigates into the project directory. Requires Git to be installed. ```sh git clone https://github.com/cometbft/cometbft.git cd cometbft ``` -------------------------------- ### IPFS Daemon Command Example Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/celestia-architecture/adr-004-mvp-light-client.md Illustrates how to run an IPFS daemon, serving as a reference for creating a similar command for the Celestia light client. Note the overridable default initialization. ```go func init() { cmd.Root.AddCommand(daemonCmd) } var daemonCmd = &cobra.Command{ Use: "daemon", Short: "Start a daemon that serves the IPFS network", Long: `A daemon is a long-running background process that serves IPFS data to the network and provides access to the IPFS API. To start an IPFS daemon, run: $ ipfs daemon This will start an IPFS node in your default repo and connect it to the network. It will then listen for commands on the API socket. `, RunE: daemonFunc, } func daemonFunc(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() // Load the node nd, err := ipfs.Load(ctx) if err != nil { return fmt.Errorf("failed to load ipfs node: %w", err) } // Attach the node to the command so that the other commands can use it cmd.Root.Long = "" cmd.Root.RunE = func(cmd *cobra.Command, args []string) error { return cmd.Help() // If no subcommand is specified, show help. } // Start the node log.SetOutput(io.Discard) return nd.Online(ctx) } ``` -------------------------------- ### Run the KVStore Application Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Start your KVStore application by executing the built binary and specifying the home directory for its data. ```bash ./kvstore -kv-home /tmp/badger-home ``` -------------------------------- ### Generate Node IDs for Cluster Setup Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/quick-start.md Before starting a cluster, obtain the unique node ID for each machine. This is required for setting up persistent peer connections. ```sh cometbft show_node_id --home ./mytestnet/node0 ``` ```sh cometbft show_node_id --home ./mytestnet/node1 ``` ```sh cometbft show_node_id --home ./mytestnet/node2 ``` ```sh cometbft show_node_id --home ./mytestnet/node3 ``` -------------------------------- ### Create main.go File Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Create a main.go file with basic 'Hello, CometBFT' output. This serves as the entry point for your application. ```go package main import ( "fmt" ) func main() { fmt.Println("Hello, CometBFT") } ``` -------------------------------- ### Install Latest CometBFT Go Package Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/install.md Installs the latest version of the CometBFT Go package. Ensure Go is installed and configured. ```sh go install github.com/cometbft/cometbft/cmd/cometbft@latest ``` -------------------------------- ### Create New Go Project Directory Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Start a new Go project by creating a directory for your application. ```bash mkdir kvstore ``` -------------------------------- ### Start Peer Grammar Source: https://github.com/celestiaorg/celestia-core/blob/main/spec/p2p/reactor-api/reactor.md Details the possible outcomes when starting a peer's communication routines. It includes successful connection and potential start errors. ```abnf start-peer = [*receive] (connected-peer / start-error) connected-peer = add-peer *receive ``` -------------------------------- ### Subscription Usage Example Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/architecture/tendermint-core/adr-033-pubsub.md Demonstrates how to use the `Subscription` struct to receive messages and handle subscription termination. ```go subscription, err := pubsub.Subscribe(...) if err != nil { // ... } for { select { case msgAndTags <- subscription.Out(): // ... case <-subscription.Canceled(): return subscription.Err() } } ``` -------------------------------- ### Install Celestia Core Binary Source: https://github.com/celestiaorg/celestia-core/blob/main/README.md This command installs the CometBFT binary to your system. ```sh # Install CometBFT binary make install ``` -------------------------------- ### Start KVStore Application Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/app-dev/abci-cli.md Starts the kvstore ABCI application. This is a prerequisite for sending messages to it. ```sh abci-cli kvstore ``` -------------------------------- ### Initialize BadgerDB and KVStore App Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Initializes the BadgerDB database and creates an instance of the KVStore application. Ensure the database path is correctly configured. ```go dbPath := filepath.Join(homeDir, "badger") db, err := badger.Open(badger.DefaultOptions(dbPath)) if err != nil { log.Fatalf("Opening database: %v", err) } defer func() { if err := db.Close(); err != nil { log.Fatalf("Closing database: %v", err) } }() app := NewKVStoreApplication(db) ``` -------------------------------- ### Initialize BadgerDB for Light Client Storage Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/celestia-architecture/adr-004-mvp-light-client.md Demonstrates how to initialize a badgerdb instance for storing light client data. This DB instance can potentially be reused for the local ipld store. ```go db, err := badgerdb.NewDB("light-client-db", dir) ``` -------------------------------- ### Verify CometBFT Installation Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/install.md Checks if the CometBFT binary is installed correctly and accessible in the system's PATH. ```sh cometbft version ``` -------------------------------- ### Initialize KVStoreApplication in main Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Modifies the main function to create an instance of the KVStoreApplication. This is a necessary step before running the application. ```go func main() { fmt.Println("Hello, CometBFT") _ = NewKVStoreApplication() } ``` -------------------------------- ### Commit Response Example Source: https://github.com/celestiaorg/celestia-core/blob/main/spec/rpc/README.md Example JSON response for the commit RPC call, containing the signed header and commit details. ```json { "jsonrpc": "2.0", "id": 0, "result": { "signed_header": { "header": { "version": { "block": "10", "app": "0" }, "chain_id": "cosmoshub-2", "height": "12", "time": "2019-04-22T17:01:51.701356223Z", "last_block_id": { "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7", "parts": { "total": 1, "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD" } }, "last_commit_hash": "21B9BC845AD2CB2C4193CDD17BFC506F1EBE5A7402E84AD96E64171287A34812", "data_hash": "970886F99E77ED0D60DA8FCE0447C2676E59F2F77302B0C4AA10E1D02F18EF73", "validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0", "next_validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0", "consensus_hash": "0F2908883A105C793B74495EB7D6DF2EEA479ED7FC9349206A65CB0F9987A0B8", "app_hash": "223BF64D4A01074DC523A80E76B9BBC786C791FB0A1893AC5B14866356FCFD6C", "last_results_hash": "", "evidence_hash": "", "proposer_address": "D540AB022088612AC74B287D076DBFBC4A377A2E" }, "commit": { "height": "1311801", "round": 0, "block_id": { "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7", "parts": { "total": 1, "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD" } }, "signatures": [ { "block_id_flag": 2, "validator_address": "000001E443FD237E4B616E2FA69DF4EE3D49A94F", "timestamp": "2019-04-22T17:01:58.376629719Z", "signature": "14jaTQXYRt8kbLKEhdHq7AXycrFImiLuZx50uOjs2+Zv+2i7RTG/jnObD07Jo2ubZ8xd7bNBJMqkgtkd0oQHAw==" } ] } }, "canonical": true } } ``` -------------------------------- ### Run KVStore Application Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go-built-in.md Execute your built application, specifying the CometBFT home directory. ```bash ./kvstore -cmt-home /tmp/cometbft-home ``` -------------------------------- ### NetInfo Response Example Source: https://github.com/celestiaorg/celestia-core/blob/main/spec/rpc/README.md An example JSON response for the net_info endpoint, showing network listening status and peer information. ```json { "id": 0, "jsonrpc": "2.0", "result": { "listening": true, "listeners": [ "Listener(@)" ], "n_peers": "1", "peers": [ { "node_id": "5576458aef205977e18fd50b274e9b5d9014525a", "url": "tcp://5576458aef205977e18fd50b274e9b5d9014525a@95.179.155.35:26656" } ] } } ``` -------------------------------- ### JSON Formatter Example Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/architecture/tendermint-core/adr-001-logging.md An example of a JSON formatted log entry, showing a structured alternative to the default text-based format. ```json { "level": "notice", "time": "2017-04-25 14:45:08.562471297 -0400 EDT", "module": "consensus", "msg": "ABCI Replay Blocks", "appHeight": 0, "storeHeight": 0, "stateHeight": 0 } ``` -------------------------------- ### Tendermint Logger Usage Example Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/architecture/tendermint-core/adr-001-logging.md Demonstrates how to initialize a Tendermint logger, set its log level from configuration, and apply it to a node with a specific name. ```go logger := log.NewTmLogger(os.Stdout) logger.SetLevel(config.GetString("log_level")) node.SetLogger(log.With(logger, "node", Name)) ``` -------------------------------- ### Initialize CometBFT with kvstore app Source: https://github.com/celestiaorg/celestia-core/blob/main/DOCKER/README.md Run a Docker container to initialize CometBFT with the kvstore application. Mounts a local directory to persist data. ```sh docker run -it --rm -v "/tmp:/cometbft" cometbft/cometbft init ``` -------------------------------- ### Starting Connections Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/core/how-to-read-logs.md Logs indicating the initialization of various connections to the application, including mempool, consensus, and query clients. ```sh I[10-04|13:54:27.364] Starting multiAppConn module=proxy impl=multiAppConn I[10-04|13:54:27.366] Starting localClient module=abci-client connection=query impl=localClient I[10-04|13:54:27.366] Starting localClient module=abci-client connection=mempool impl=localClient I[10-04|13:54:27.367] Starting localClient module=abci-client connection=consensus impl=localClient ``` -------------------------------- ### List Configuration Files Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/quick-start.md After initialization, these are the files found in the `$HOME/.cometbft` directory. No further configuration is needed for a single local node. ```sh $ ls $HOME/.cometbft config data ``` ```sh $ ls $HOME/.cometbft/config/ config.toml genesis.json node_key.json priv_validator.json ``` -------------------------------- ### ABCI Grammar: Start Sequence Source: https://github.com/celestiaorg/celestia-core/blob/main/spec/abci/abci++_comet_expected_behavior.md Defines the initial entry points for a CometBFT process, distinguishing between a clean start and a recovery scenario. ```abnf start = clean-start / recovery ``` -------------------------------- ### Initialize CometBFT Configuration Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/guides/go.md Use this command to create the CometBFT configuration files in the specified directory. This is a prerequisite for running the application. ```bash go run github.com/cometbft/cometbft/cmd/cometbft@v0.38.0 init --home /tmp/cometbft-home ``` -------------------------------- ### Blockchain Response Example Source: https://github.com/celestiaorg/celestia-core/blob/main/spec/rpc/README.md An example of the JSON response structure when requesting blockchain data, including block metadata and header information. ```json { "id": 0, "jsonrpc": "2.0", "result": { "last_height": "1276718", "block_metas": [ { "block_id": { "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7", "parts": { "total": 1, "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD" } }, "block_size": 1000000, "header": { "version": { "block": "10", "app": "0" }, "chain_id": "cosmoshub-2", "height": "12", "time": "2019-04-22T17:01:51.701356223Z", "last_block_id": { "hash": "112BC173FD838FB68EB43476816CD7B4C6661B6884A9E357B417EE957E1CF8F7", "parts": { "total": 1, "hash": "38D4B26B5B725C4F13571EFE022C030390E4C33C8CF6F88EDD142EA769642DBD" } }, "last_commit_hash": "21B9BC845AD2CB2C4193CDD17BFC506F1EBE5A7402E84AD96E64171287A34812", "data_hash": "970886F99E77ED0D60DA8FCE0447C2676E59F2F77302B0C4AA10E1D02F18EF73", "validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0", "next_validators_hash": "D658BFD100CA8025CFD3BECFE86194322731D387286FBD26E059115FD5F2BCA0", "consensus_hash": "0F2908883A105C793B74495EB7D6DF2EEA479ED7FC9349206A65CB0F9987A0B8", "app_hash": "223BF64D4A01074DC523A80E76B9BBC786C791FB0A1893AC5B14866356FCFD6C", "last_results_hash": "", "evidence_hash": "", "proposer_address": "D540AB022088612AC74B287D076DBFBC4A377A2E" }, "num_txs": "54" } ] } } ``` -------------------------------- ### Go Logger Instantiation with Custom Coloring Source: https://github.com/celestiaorg/celestia-core/blob/main/docs/architecture/tendermint-core/adr-001-logging.md Demonstrates how to create a Tendermint logger with custom colorization logic based on key-value pairs, specifically for the 'instance' field. ```go colorFn := func(keyvals ...interface{}) term.FgBgColor { for i := 1; i < len(keyvals); i += 2 { if keyvals[i] == "instance" && keyvals[i+1] == "1" { return term.FgBgColor{Fg: term.Blue} } else if keyvals[i] == "instance" && keyvals[i+1] == "1" { return term.FgBgColor{Fg: term.Red} } } return term.FgBgColor{} } logger := term.NewLogger(os.Stdout, log.NewTmLogger, colorFn) c1 := NewConsensusReactor(...) c1.SetLogger(log.With(logger, "instance", 1)) c2 := NewConsensusReactor(...) c2.SetLogger(log.With(logger, "instance", 2)) ```