diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 598c8888b3..70e3c0df66 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,6 +8,3 @@ # codeowner specified below. For this reason, the global codeowners # are often repeated in package-level definitions. * @celestiaorg/celestia-core - -# Overrides for tooling packages -docs/celestia-architecture @liamsi @adlerjohn diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index b36de99cf6..d0ede9e361 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -43,7 +43,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.22.2" + go-version: "1.22.5" - uses: actions/checkout@v4 with: diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6dc0b8e24c..7fe8d4cfae 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: "1.22.2" + go-version: "1.22.5" - name: Create a file with all the pkgs run: go list ./... > pkgs.txt - name: Split pkgs into 4 files @@ -48,8 +48,8 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.22.2" - - uses: actions/checkout@v4 + go-version: "1.22.5" + - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: PATTERNS: | @@ -70,8 +70,8 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.22.2" - - uses: actions/checkout@v4 + go-version: "1.22.5" + - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: PATTERNS: | diff --git a/.github/workflows/e2e-manual.yml b/.github/workflows/e2e-manual.yml index aa0fdbe9b2..6d791d3bff 100644 --- a/.github/workflows/e2e-manual.yml +++ b/.github/workflows/e2e-manual.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' - uses: actions/checkout@v4 diff --git a/.github/workflows/e2e-nightly-34x.yml b/.github/workflows/e2e-nightly-34x.yml index fbc0d1c074..7c02930675 100644 --- a/.github/workflows/e2e-nightly-34x.yml +++ b/.github/workflows/e2e-nightly-34x.yml @@ -23,7 +23,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' - uses: actions/checkout@v4 with: diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index f15ae6efbb..f31e283270 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: diff --git a/.github/workflows/fuzz-nightly.yml b/.github/workflows/fuzz-nightly.yml index 43a5130e58..f07ad176cc 100644 --- a/.github/workflows/fuzz-nightly.yml +++ b/.github/workflows/fuzz-nightly.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' - uses: actions/checkout@v4 diff --git a/.github/workflows/govulncheck.yml b/.github/workflows/govulncheck.yml index 2456c89e3a..b379872850 100644 --- a/.github/workflows/govulncheck.yml +++ b/.github/workflows/govulncheck.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: "1.22.2" + go-version: "1.22.5" - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c53cd9f62a..d0f0c99070 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,9 +10,18 @@ name: Golang Linter on: pull_request: + paths: + - '**/*.go' + - 'go.mod' + - 'go.sum' push: branches: - v[0-9]+.[0-9]+.x-celestia + paths: + - '**/*.go' + - 'go.mod' + - 'go.sum' + jobs: golangci: name: golangci-lint @@ -20,16 +29,12 @@ jobs: timeout-minutes: 8 steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: '1.22.2' - - uses: technote-space/get-diff-action@v6 + + - uses: actions/setup-go@v5 with: - PATTERNS: | - **/**.go - go.mod - go.sum - - uses: golangci/golangci-lint-action@v3.2.0 + go-version-file: 'go.mod' + + - uses: golangci/golangci-lint-action@v4.0.0 with: # Required: the version of golangci-lint is required and # must be specified without patch version: we always use the @@ -37,4 +42,3 @@ jobs: version: v1.56.2 args: --timeout 10m github-token: ${{ secrets.github_token }} - if: env.GIT_DIFF diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 2a6cd29807..019d65dc01 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' # Similar check to ./release-version.yml, but enforces this when pushing # tags. The ./release-version.yml check can be bypassed and is mainly diff --git a/.github/workflows/release-version.yml b/.github/workflows/release-version.yml index a080834af5..fd30563828 100644 --- a/.github/workflows/release-version.yml +++ b/.github/workflows/release-version.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' - name: Check version run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 32687945f3..28ae574803 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.22.5' - name: Generate release notes run: | diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f4cde15b2f..7a5b80c268 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,7 +25,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: "1.22.2" + go-version: "1.22.5" - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v6 with: @@ -121,7 +121,7 @@ jobs: # steps: # - uses: actions/setup-go@v3 # with: - # go-version: "1.22.2" + # go-version: "1.22.5" # - uses: actions/checkout@v3 # - uses: technote-space/get-diff-action@v6 # with: diff --git a/DOCKER/Dockerfile b/DOCKER/Dockerfile index c1ee8ad8e7..f642c24315 100644 --- a/DOCKER/Dockerfile +++ b/DOCKER/Dockerfile @@ -1,6 +1,6 @@ # Use a build arg to ensure that both stages use the same, # hopefully current, go version. -ARG GOLANG_BASE_IMAGE=golang:1.22.4-alpine +ARG GOLANG_BASE_IMAGE=golang:1.22.5-alpine # stage 1 Generate CometBFT Binary FROM --platform=$BUILDPLATFORM $GOLANG_BASE_IMAGE as builder diff --git a/Makefile b/Makefile index 9350998c71..8f155e16c1 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)" HTTPS_GIT := https://github.com/cometbft/cometbft.git CGO_ENABLED ?= 0 +BUF_VERSION := v1.31.0 # handle nostrip ifeq (,$(findstring nostrip,$(COMETBFT_BUILD_OPTIONS))) BUILD_FLAGS += -trimpath @@ -154,7 +155,7 @@ endif proto-gen: check-proto-deps @echo "Generating Protobuf files" - @go run github.com/bufbuild/buf/cmd/buf@v1.29.0 generate + @go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) generate @mv ./proto/tendermint/abci/types.pb.go ./abci/types/ @cp ./proto/tendermint/rpc/grpc/types.pb.go ./rpc/grpc .PHONY: proto-gen @@ -163,7 +164,7 @@ proto-gen: check-proto-deps # execution only. proto-lint: check-proto-deps @echo "Linting Protobuf files" - @go run github.com/bufbuild/buf/cmd/buf@v1.29.0 lint + @go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) lint .PHONY: proto-lint proto-format: check-proto-format-deps @@ -176,11 +177,11 @@ proto-check-breaking: check-proto-deps @echo "Note: This is only useful if your changes have not yet been committed." @echo " Otherwise read up on buf's \"breaking\" command usage:" @echo " https://docs.buf.build/breaking/usage" - @go run github.com/bufbuild/buf/cmd/buf@v1.29.0 breaking --against ".git" + @go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) breaking --against ".git" .PHONY: proto-check-breaking proto-check-breaking-ci: - @go run github.com/bufbuild/buf/cmd/buf@v1.29.0 breaking --against $(HTTPS_GIT)#branch=v0.34.x-celestia + @go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) breaking --against $(HTTPS_GIT)#branch=v0.34.x-celestia .PHONY: proto-check-breaking-ci ############################################################################### diff --git a/README.md b/README.md index 8bf3f2a7e8..5d26b933d6 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ This repo intends on preserving the minimal possible diff with [cometbft/cometbf - **specific to Celestia**: consider if [celestia-app](https://github.com/celestiaorg/celestia-app) is a better target - **not specific to Celestia**: consider making the contribution upstream in CometBFT -1. [Install Go](https://go.dev/doc/install) 1.22.4+ +1. [Install Go](https://go.dev/doc/install) 1.22.5+ 2. Fork this repo 3. Clone your fork 4. Find an issue to work on (see [good first issues](https://github.com/celestiaorg/celestia-core/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)) diff --git a/go.mod b/go.mod index 7da31d49b7..0b770cedf9 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/tendermint/tendermint -go 1.22.4 +go 1.22.5 require ( github.com/BurntSushi/toml v1.2.1 diff --git a/scripts/proto-gen.sh b/scripts/proto-gen.sh index 4cf0656326..545648045d 100755 --- a/scripts/proto-gen.sh +++ b/scripts/proto-gen.sh @@ -10,7 +10,7 @@ cd "$(git rev-parse --show-toplevel)" # Run inside Docker to install the correct versions of the required tools # without polluting the local system. -docker run --rm -i -v "$PWD":/w --workdir=/w golang:1.22.4-alpine sh <<"EOF" +docker run --rm -i -v "$PWD":/w --workdir=/w golang:1.22.5-alpine sh <<"EOF" apk add git make go install github.com/bufbuild/buf/cmd/buf diff --git a/spec/p2p/reactors/mempool-v1.md b/spec/p2p/reactors/mempool-v1.md new file mode 100644 index 0000000000..16186adb92 --- /dev/null +++ b/spec/p2p/reactors/mempool-v1.md @@ -0,0 +1,91 @@ +# Mempool V1 Reactor + +## Overview + +The Celestia-core's p2p layer, which is a fork of CometBFT, consists of channels and reactors. Peers establish connections within specific channels, effectively forming peer-to-peer groups (each channel represents such a group). The transmission of messages within a channel is governed by the associated reactor, essentially containing the protocol rules for that channel. + +One notable channel is the mempool channel, identified as [`MempoolChannel`](https://github.com/celestiaorg/celestia-core/blob/3f3b7cc57f5cfc5e846ce781a9a407920e54fb72/mempool/mempool.go#L14) with a specific channel ID of [`0x30`](https://github.com/celestiaorg/celestia-core/blob/3f3b7cc57f5cfc5e846ce781a9a407920e54fb72/mempool/mempool.go#L14). The mempool reactor manages the dissemination of transactions across the network. It's important to highlight that there's a direct correspondence between reactors and the channels they are connected to. Consequently, the mempool reactor is the exclusive reactor linked to the mempool channel with ID `0x30`. This document will provide an overview of the protocol implemented by the mempool v1 reactor along with its traffic analysis. + +## Transaction Flow and Lifecycle in a Node + +A node can receive a transaction through one of two pathways: either a user initiates the transaction directly to the node, or the node acquires a transaction from another peer. Upon receiving a transaction, the following steps occur: + +1. The transaction's validity is assessed, and if it passes the validation criteria, it is added to the mempool. Furthermore, the height at which the transaction is received is set to the current block height. This information will later be useful in purging old transactions from the mempool once their time-to-live (TTL) has elapsed and have not been included in any blocks. +2. **Peer Tracking**: In the event that the transaction originates from another peer, the sending peer is marked to prevent redundant transmission of the same transaction. +Subsequently, there are two concurrent processes underway, namely, the _mempool management_ and _broadcast process_, as explained in the remaining items below. +3. **Mempool Management**: + + - Transactions that find their way into the mempool remain there until one of two conditions is met: either the mempool reaches its capacity limit or a new block is committed. + - When a [block is committed](https://github.com/celestiaorg/celestia-core/blob/367caa33ef5ab618ea357189e88044dbdbd17776/state/execution.go#L324): + - The transactions within that block that are successfully delivered to the app are removed from the mempool ([ref](https://github.com/celestiaorg/celestia-core/blob/993c1228977f206c80cb0f87ac1d4f002826e904/mempool/v1/mempool.go#L418)). They are also placed in the mempool cache ([ref](https://github.com/celestiaorg/celestia-core/blob/993c1228977f206c80cb0f87ac1d4f002826e904/mempool/v1/mempool.go#L411-L412)). + - The remaining transactions are subjected to two checks: + - Their Time-to-Live (TTL) is examined ([ref](https://github.com/celestiaorg/celestia-core/blob/993c1228977f206c80cb0f87ac1d4f002826e904/mempool/v1/mempool.go#L421)), and any transactions that have expired are promptly removed from the mempool ([ref](https://github.com/celestiaorg/celestia-core/blob/993c1228977f206c80cb0f87ac1d4f002826e904/mempool/v1/mempool.go#L743)). + - Next, the remaining transactions are re-evaluated for validity against the updated state ([ref](https://github.com/celestiaorg/celestia-core/blob/993c1228977f206c80cb0f87ac1d4f002826e904/mempool/v1/mempool.go#L429-L430)) due to the mempool [`recheck` config](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L708) that is set to `true` ([ref](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L761)). Any transactions that are found to be invalid are removed from the mempool. +4. **Broadcast Process**: + For each peer and for every transaction residing in the mempool, the following actions are taken ([ref](https://github.com/celestiaorg/celestia-core/blob/64cd9ab7c67c945d755fb4fbd5afb2d352874eea/mempool/v1/reactor.go#L244)): + - A copy of the transaction is dispatched to that peer if the peer + - is online + - supports the mempool channel ID ([ref](https://github.com/celestiaorg/celestia-core/blob/ad660fee8f186d6f7e5e567ea23ea813f5038d90/p2p/peer.go#L319)) + - has a height difference of one (meaning it lags behind the transaction by a single block). If the height difference is greater, a waiting period is observed to allow the peer to catch up ([ref](https://github.com/celestiaorg/celestia-core/blob/64cd9ab7c67c945d755fb4fbd5afb2d352874eea/mempool/v1/reactor.go#L286-L289)). + - **Peer Tracking**: Each transaction is sent to a peer only once, and the recipient peer is marked to prevent the retransmission of the same transaction ([ref](https://github.com/celestiaorg/celestia-core/blob/64cd9ab7c67c945d755fb4fbd5afb2d352874eea/mempool/v1/reactor.go#L304)). + +## Constraints and Configurations + +The relevant constraints and configurations for the mempool are as follows ([ref](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L758)): + +- `Size`: This parameter specifies the total number of transactions that the mempool can hold. It is a configurable setting, with a default value of `5000`. +- `MaxTxsBytes`: The `MaxTxsBytes` parameter defines the maximum size of the mempool in bytes, with a default value of `1GB`. +- `MaxTxBytes`: The `MaxTxBytes` parameter specifies the maximum size of an individual transaction, which is set to `1MB`. +- `TTLNumBlocks` and `TTLDuration` : These settings determine the number of blocks and time after which a transaction is removed from the mempool if it has not been included in a block. The default is set to zero, however, on [celestia-app side](https://github.com/celestiaorg/celestia-app/blob/ccfb3e5e87d05d75a92ad85ab199d4f0c4879a0a/app/default_overrides.go#L221-L222) these values are over-written to `5` and `5*15 s`, respectively. + +For each peer-to-peer connection, the following limits apply to the aggregate traffic rate of all the channels ([ref](https://github.com/celestiaorg/celestia-core/blob/3f3b7cc57f5cfc5e846ce781a9a407920e54fb72/libs/flowrate/flowrate.go#L177)): + +- `SendRate`: The `SendRate` parameter enforces a default sending rate of [`5120000 B= 5MB/s`](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L615). It ensures that data is sent at this maximum rate. This parameter does not seem to be overwritten by the celestia-app. +- `RecvRate`: The `RecvRate` parameter enforces a default receiving rate of [`5120000 B= 5MB/s`](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L616). It ensures that data is received at this maximum rate. This parameter does not seem to be overwritten by the celestia-app. +- `MaxPacketMsgPayloadSize`: The `MaxPacketMsgPayloadSize` parameter sets the maximum payload size for packet messages to `1024` bytes. + + + + +Other P2P configs ([ref](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L524)) that would be relevant to the traffic analysis are: + +- [`max_num_inbound_peers` and `max_num_outbound_peers`](https://github.com/celestiaorg/celestia-core/blob/37f950717381e8d8f6393437624652693e4775b8/config/config.go#L604-L605): These parameters indicate the total number of inbound and outbound peers, respectively. The default values are `40` for inbound peers and `10` for outbound peers ([excluding persistent peers](https://github.com/celestiaorg/celestia-core/blob/2f93fc823f17c36c7090f84694880c85d3244764/config/config.go#L553-L554)). + + +## Traffic Rate Analysis + +In the analysis provided below, we consider the knowledge of the following network parameters: + +- `d`: Node degree (total incoming and outgoing connections) +- `transaction_rate` which specifies that total size of transactions in bytes per second submitted to the network. + +Transactions are assumed to comply with the transaction size, are valid and are accepted by the mempool. We also assume all the peers are up and running. + +### Traffic Rate Analysis for a Node + +We distinguish between the incoming and outgoing traffic rate, and denote them by `incoming_traffic_rate` and `outgoing_traffic_rate`, respectively. + +- **Worst case scenario**: a transaction is exchanged by the two ends of +connection simultaneously, contributing to both incoming and outgoing traffic. +In a network, with transaction rate `transaction_rate` and a node with `d` degree, the traffic rates are calculated as follows: +`incoming_traffic_rate = d * transaction_rate` +`outgoing_traffic_rate = d * transaction_rate` + +These max rates are further constrained by the `SendRate` and `RecvRate`. +`incoming_traffic_rate = d * min(transaction_rate, RecvRate)` +`outgoing_traffic_rate = d * min(transaction_rate, SendRate)` + +- **Best case scenario**: a transaction is exchanged only once, contributing to either incoming or outgoing traffic. This is because both ends of the connection keep track of the transactions they have seen on a connection (whether via sending or receiving). If one peer sends a transaction before the other, they both mark it as sent/received, ensuring they do not redundantly transmit it to each other. +In a network, with transaction rate `transaction_rate` and a node with degree of `d`, the node's traffic rate in best case would be: +`traffic_rate (=incoming_traffic_rate + outgoing_traffic_rate) = d * transaction_rate` + +We can draw the following conclusions (to be extended and verified): + +- With a known given transaction rate `transaction_rate`, a node's (in + out) traffic rate should range from `d * transaction_rate` to `2 * d * transaction_rate`. +- To handle a particular `transaction_rate` (network throughput), the node's `SendRate` and `RecvRate` should be at least `transaction_rate` to handle the worst case scenario (this is only to undertake the load incurred by the mempool reactor). + +### Impact of mempool on other network aspects + +- **Block size**: One immediate impact of mempool, is the size of mempool on the block size. Block size can not exceed the mempool size. In the current setting, the mempool size is at max `1GB` meaning Celestia blocks can get as large as that (excluding block header). +- **Network throughput**: TBC +- **Block Time**: TBC diff --git a/test/docker/Dockerfile b/test/docker/Dockerfile index 364589845a..23b66cd6ca 100644 --- a/test/docker/Dockerfile +++ b/test/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.4 +FROM golang:1.22.5 # Grab deps (jq, hexdump, xxd, killall) RUN apt-get update && \ diff --git a/test/e2e/docker/Dockerfile b/test/e2e/docker/Dockerfile index 41d0fc4937..c90a7e29ef 100644 --- a/test/e2e/docker/Dockerfile +++ b/test/e2e/docker/Dockerfile @@ -1,7 +1,7 @@ # We need to build in a Linux environment to support C libraries, e.g. RocksDB. # We use Debian instead of Alpine, so that we can use binary database packages # instead of spending time compiling them. -FROM golang:1.22.4-bullseye +FROM golang:1.22.5-bullseye RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null RUN apt-get -qq install -y libleveldb-dev librocksdb-dev >/dev/null