From 8d6d554e86fc64fc86eca7ef6b9801d8c7b5191a Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Fri, 14 Mar 2025 11:31:35 +0100 Subject: [PATCH] feat: add Agent to `Filecoin.Version` --- CHANGELOG.md | 1 + api/api_common.go | 3 +++ build/buildconstants/params.go | 3 +++ build/openrpc/gateway.json | 6 +++++- documentation/en/api-v0-methods-miner.md | 3 ++- documentation/en/api-v0-methods.md | 3 ++- documentation/en/api-v1-unstable-methods.md | 3 ++- node/impl/common/common.go | 1 + node/modules/lp2p/host.go | 3 ++- 9 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e604d5c05..f07dce0ac8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - chore: upgrade drand client - chore: upgrade go-state-types with big.Int{} change that means an empty big.Int is now treated as zero for all operations ([filecoin-project/lotus#12936](https://github.com/filecoin-project/lotus/pull/12936)) - feat: expose `ChainGetMessagesInTipset` in the Lotus Gateway API ([filecoin-project/lotus#12947](https://github.com/filecoin-project/lotus/pull/12947)) +- feat: add `Agent` to the `Filecoin.Version` response ([#12904](https://github.com/filecoin-project/lotus/issues/12904)) that will be used to identify the node type. # UNRELEASED v.1.32.0 diff --git a/api/api_common.go b/api/api_common.go index 2a887a26a75..11f5bddc348 100644 --- a/api/api_common.go +++ b/api/api_common.go @@ -73,6 +73,9 @@ type APIVersion struct { // Seconds BlockDelay uint64 + + // Agent type, as reported to other nodes, e.g. "lotus" + Agent string } func (v APIVersion) String() string { diff --git a/build/buildconstants/params.go b/build/buildconstants/params.go index 2216261cefa..a8279f8179d 100644 --- a/build/buildconstants/params.go +++ b/build/buildconstants/params.go @@ -38,6 +38,9 @@ func BuildTypeString() string { var Devnet = true +// The agent string used by the node and reported to other nodes in the network. +const UserAgent = "lotus" + // Used by tests and some obscure tooling /* inline-gen template const TestNetworkVersion = network.Version{{.latestNetworkVersion}} diff --git a/build/openrpc/gateway.json b/build/openrpc/gateway.json index 4315ea3079a..e044fbd4765 100644 --- a/build/openrpc/gateway.json +++ b/build/openrpc/gateway.json @@ -12117,7 +12117,8 @@ { "Version": "string value", "APIVersion": 131840, - "BlockDelay": 42 + "BlockDelay": 42, + "Agent": "string value" } ], "additionalProperties": false, @@ -12126,6 +12127,9 @@ "title": "number", "type": "number" }, + "Agent": { + "type": "string" + }, "BlockDelay": { "title": "number", "type": "number" diff --git a/documentation/en/api-v0-methods-miner.md b/documentation/en/api-v0-methods-miner.md index f526cce5b99..e3e0dfc74bb 100644 --- a/documentation/en/api-v0-methods-miner.md +++ b/documentation/en/api-v0-methods-miner.md @@ -179,7 +179,8 @@ Response: { "Version": "string value", "APIVersion": 131840, - "BlockDelay": 42 + "BlockDelay": 42, + "Agent": "string value" } ``` diff --git a/documentation/en/api-v0-methods.md b/documentation/en/api-v0-methods.md index fabea3a8bbb..1d50df65058 100644 --- a/documentation/en/api-v0-methods.md +++ b/documentation/en/api-v0-methods.md @@ -276,7 +276,8 @@ Response: { "Version": "string value", "APIVersion": 131840, - "BlockDelay": 42 + "BlockDelay": 42, + "Agent": "string value" } ``` diff --git a/documentation/en/api-v1-unstable-methods.md b/documentation/en/api-v1-unstable-methods.md index c1600e7eeca..ede31f973a1 100644 --- a/documentation/en/api-v1-unstable-methods.md +++ b/documentation/en/api-v1-unstable-methods.md @@ -360,7 +360,8 @@ Response: { "Version": "string value", "APIVersion": 131840, - "BlockDelay": 42 + "BlockDelay": 42, + "Agent": "string value" } ``` diff --git a/node/impl/common/common.go b/node/impl/common/common.go index 5629adcb3bd..ab4c381869e 100644 --- a/node/impl/common/common.go +++ b/node/impl/common/common.go @@ -70,6 +70,7 @@ func (a *CommonAPI) Version(context.Context) (api.APIVersion, error) { APIVersion: v, BlockDelay: buildconstants.BlockDelaySecs, + Agent: buildconstants.UserAgent, }, nil } diff --git a/node/modules/lp2p/host.go b/node/modules/lp2p/host.go index fd723fbb2c4..64050a8bd4c 100644 --- a/node/modules/lp2p/host.go +++ b/node/modules/lp2p/host.go @@ -19,6 +19,7 @@ import ( "go.uber.org/fx" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/build/buildconstants" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/helpers" ) @@ -51,7 +52,7 @@ func Host(mctx helpers.MetricsCtx, buildVersion build.BuildVersion, lc fx.Lifecy libp2p.Peerstore(params.Peerstore), libp2p.NoListenAddrs, libp2p.Ping(true), - libp2p.UserAgent("lotus-" + string(buildVersion)), + libp2p.UserAgent(buildconstants.UserAgent + "-" + string(buildVersion)), } for _, o := range params.Opts { opts = append(opts, o...)