Skip to content

Commit 188d5f0

Browse files
authored
feat: add config command (#1489)
* add config cmd * refactor, add diff cmd * merge diff func, trim diff output * fix trimming issues
1 parent a1b514f commit 188d5f0

File tree

8 files changed

+489
-123
lines changed

8 files changed

+489
-123
lines changed

cmd/boostd/config.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"path/filepath"
6+
7+
"github.com/filecoin-project/boost/node/config"
8+
"github.com/mitchellh/go-homedir"
9+
"github.com/urfave/cli/v2"
10+
)
11+
12+
var configCmd = &cli.Command{
13+
Name: "config",
14+
Usage: "Display Boost config",
15+
Subcommands: []*cli.Command{
16+
configDefaultCmd,
17+
configUpdateCmd,
18+
},
19+
}
20+
21+
var configDefaultCmd = &cli.Command{
22+
Name: "default",
23+
Usage: "Print config file defaults",
24+
Flags: []cli.Flag{
25+
&cli.BoolFlag{
26+
Name: "no-comment",
27+
Usage: "don't include comments in the output",
28+
},
29+
},
30+
Action: func(cctx *cli.Context) error {
31+
32+
cb, err := config.ConfigUpdate(config.DefaultBoost(), nil, !cctx.Bool("no-comment"), false)
33+
if err != nil {
34+
return err
35+
}
36+
37+
fmt.Println(string(cb))
38+
39+
return nil
40+
},
41+
}
42+
43+
var configUpdateCmd = &cli.Command{
44+
Name: "updated",
45+
Usage: "Print config file with updates (changes from the default config file)",
46+
Flags: []cli.Flag{
47+
&cli.BoolFlag{
48+
Name: "no-comment",
49+
Usage: "don't include commented out default values in the output",
50+
},
51+
&cli.BoolFlag{
52+
Name: "diff",
53+
Usage: "only display values different from default",
54+
},
55+
},
56+
Action: func(cctx *cli.Context) error {
57+
path, err := homedir.Expand(cctx.String(FlagBoostRepo))
58+
if err != nil {
59+
return err
60+
}
61+
62+
configPath := filepath.Join(path, "config.toml")
63+
64+
cfgNode, err := config.FromFile(configPath, config.DefaultBoost())
65+
if err != nil {
66+
return err
67+
}
68+
69+
output, err := config.ConfigUpdate(cfgNode, config.DefaultBoost(), !cctx.Bool("no-comment"), cctx.Bool("diff"))
70+
if err != nil {
71+
return err
72+
}
73+
74+
fmt.Print(string(output))
75+
return nil
76+
},
77+
}

cmd/boostd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func main() {
4141
migrateMarketsCmd,
4242
backupCmd,
4343
restoreCmd,
44+
configCmd,
4445
dummydealCmd,
4546
dataTransfersCmd,
4647
retrievalDealsCmd,

node/config/migrate_test.go

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,156 @@ ConfigVersion = 2
2121
MyNewKey = "Hello"
2222
`
2323

24+
const testConfig = `
25+
ConfigVersion = 4
26+
SealerApiInfo = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.0LyVxqOde8UjLTcHPEo3VEBILtPQqCDNEHcoCbTRQ_Y:/ip4/127.0.0.1/tcp/2345/http"
27+
SectorIndexApiInfo = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.0LyVxqOde8UjLTcHPEo3VEBILtPQqCDNEHcoCbTRQ_Y:/ip4/127.0.0.1/tcp/2345/http"
28+
29+
[API]
30+
ListenAddress = "/ip4/127.0.0.1/tcp/1288/http"
31+
RemoteListenAddress = ""
32+
Timeout = "30s"
33+
34+
[Backup]
35+
DisableMetadataLog = false
36+
37+
[Libp2p]
38+
ListenAddresses = ["/ip4/0.0.0.1/tcp/50000", "/ip6/::/tcp/0"]
39+
AnnounceAddresses = []
40+
NoAnnounceAddresses = []
41+
DisableNatPortMap = false
42+
ConnMgrLow = 150
43+
ConnMgrHigh = 180
44+
ConnMgrGrace = "20s"
45+
46+
[Pubsub]
47+
Bootstrapper = false
48+
RemoteTracer = ""
49+
JsonTracer = ""
50+
ElasticSearchTracer = ""
51+
ElasticSearchIndex = ""
52+
TracerSourceAuth = ""
53+
54+
[Storage]
55+
ParallelFetchLimit = 10
56+
StorageListRefreshDuration = "1h0m0s"
57+
RedeclareOnStorageListRefresh = true
58+
59+
[Dealmaking]
60+
ConsiderOnlineStorageDeals = true
61+
ConsiderOfflineStorageDeals = true
62+
ConsiderOnlineRetrievalDeals = true
63+
ConsiderOfflineRetrievalDeals = true
64+
ConsiderVerifiedStorageDeals = true
65+
ConsiderUnverifiedStorageDeals = true
66+
PieceCidBlocklist = []
67+
ExpectedSealDuration = "24h0m0s"
68+
MaxDealStartDelay = "336h0m0s"
69+
MaxProviderCollateralMultiplier = 2
70+
MaxStagingDealsBytes = 2000000000
71+
MaxStagingDealsPercentPerHost = 0
72+
StartEpochSealingBuffer = 480
73+
DealProposalLogDuration = "24h0m0s"
74+
RetrievalLogDuration = "24h0m0s"
75+
StalledRetrievalTimeout = "30s"
76+
Filter = ""
77+
RetrievalFilter = ""
78+
BlockstoreCacheMaxShards = 20
79+
BlockstoreCacheExpiry = "30s"
80+
IsUnsealedCacheExpiry = "5m0s"
81+
MaxTransferDuration = "24h0m0s"
82+
RemoteCommp = false
83+
MaxConcurrentLocalCommp = 1
84+
HTTPRetrievalMultiaddr = ""
85+
HttpTransferMaxConcurrentDownloads = 20
86+
HttpTransferStallCheckPeriod = "30s"
87+
HttpTransferStallTimeout = "5m0s"
88+
BitswapPeerID = ""
89+
BitswapPrivKeyFile = ""
90+
DealLogDurationDays = 30
91+
SealingPipelineCacheTimeout = "30s"
92+
FundsTaggingEnabled = true
93+
[Dealmaking.RetrievalPricing]
94+
Strategy = "default"
95+
[Dealmaking.RetrievalPricing.Default]
96+
VerifiedDealsFreeTransfer = false
97+
[Dealmaking.RetrievalPricing.External]
98+
Path = ""
99+
100+
[Wallets]
101+
Miner = "t01000"
102+
PublishStorageDeals = "t3rjh3byfhhrlmdl6ofou544rmwuazp4bbqzuleahtn66ejnh73bsaonwyg54qrokvnbv5bmg37dfd5vu2bx4q"
103+
DealCollateral = "t3qa5i54vprhl7gmdfgriubvjc5kdffx7cvbqvumopgvsy2osre5dcjdjhz5coruxp4co3chj3gbtxin7vtoia"
104+
PledgeCollateral = ""
105+
106+
[Graphql]
107+
ListenAddress = "0.0.0.0"
108+
Port = 8080
109+
110+
[Tracing]
111+
Enabled = false
112+
ServiceName = "boostd"
113+
Endpoint = ""
114+
115+
[ContractDeals]
116+
Enabled = false
117+
AllowlistContracts = []
118+
From = "0x0000000000000000000000000000000000000000"
119+
120+
[LotusDealmaking]
121+
ConsiderOnlineStorageDeals = true
122+
ConsiderOfflineStorageDeals = true
123+
ConsiderOnlineRetrievalDeals = true
124+
ConsiderOfflineRetrievalDeals = true
125+
ConsiderVerifiedStorageDeals = true
126+
ConsiderUnverifiedStorageDeals = true
127+
PieceCidBlocklist = []
128+
ExpectedSealDuration = "24h0m0s"
129+
MaxDealStartDelay = "336h0m0s"
130+
PublishMsgPeriod = "1h0m0s"
131+
MaxDealsPerPublishMsg = 8
132+
MaxProviderCollateralMultiplier = 2
133+
MaxStagingDealsBytes = 0
134+
SimultaneousTransfersForStorage = 20
135+
SimultaneousTransfersForStoragePerClient = 0
136+
SimultaneousTransfersForRetrieval = 20
137+
StartEpochSealingBuffer = 480
138+
Filter = ""
139+
RetrievalFilter = ""
140+
[LotusDealmaking.RetrievalPricing]
141+
Strategy = "default"
142+
[LotusDealmaking.RetrievalPricing.Default]
143+
VerifiedDealsFreeTransfer = true
144+
[LotusDealmaking.RetrievalPricing.External]
145+
Path = ""
146+
147+
[LotusFees]
148+
MaxPublishDealsFee = "0.05 FIL"
149+
MaxMarketBalanceAddFee = "0.007 FIL"
150+
151+
[DAGStore]
152+
RootDir = ""
153+
MaxConcurrentIndex = 5
154+
MaxConcurrentReadyFetches = 0
155+
MaxConcurrentUnseals = 0
156+
MaxConcurrencyStorageCalls = 100
157+
GCInterval = "1m0s"
158+
159+
[IndexProvider]
160+
Enable = true
161+
EntriesCacheCapacity = 1024
162+
EntriesChunkSize = 16384
163+
TopicName = ""
164+
PurgeCacheOnStart = false
165+
[IndexProvider.Announce]
166+
AnnounceOverHttp = false
167+
DirectAnnounceURLs = ["https://cid.contact/ingest/announce", "http://localhost:3000"]
168+
[IndexProvider.HttpPublisher]
169+
Enabled = false
170+
PublicHostname = ""
171+
Port = 3104
172+
`
173+
24174
func TestMigrate(t *testing.T) {
25175
// Add a new mock migration so as to be able to test migrating up and down
26176
mockv1Tov2 := func(string) (string, error) {
@@ -101,3 +251,22 @@ func TestMigrate(t *testing.T) {
101251
require.NoError(t, err)
102252
require.Equal(t, v1FileContents, string(bz))
103253
}
254+
255+
func TestConfigDiff(t *testing.T) {
256+
repoDir := t.TempDir()
257+
err := os.WriteFile(path.Join(repoDir, "config.toml"), []byte(testConfig), 0644)
258+
require.NoError(t, err)
259+
260+
cgf, err := FromFile(path.Join(repoDir, "config.toml"), DefaultBoost())
261+
require.NoError(t, err)
262+
263+
s, err := ConfigUpdate(cgf, DefaultBoost(), false, true)
264+
require.NoError(t, err)
265+
266+
require.False(t, strings.Contains(string(s), `The connect string for the sealing RPC API`))
267+
268+
s, err = ConfigUpdate(cgf, DefaultBoost(), true, true)
269+
require.NoError(t, err)
270+
271+
require.True(t, strings.Contains(string(s), `The connect string for the sealing RPC API`))
272+
}

0 commit comments

Comments
 (0)