Skip to content

Commit

Permalink
feat: add config command (#1489)
Browse files Browse the repository at this point in the history
* add config cmd

* refactor, add diff cmd

* merge diff func, trim diff output

* fix trimming issues
  • Loading branch information
LexLuthr authored Jun 8, 2023
1 parent a1b514f commit 188d5f0
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 123 deletions.
77 changes: 77 additions & 0 deletions cmd/boostd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"fmt"
"path/filepath"

"github.com/filecoin-project/boost/node/config"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"
)

var configCmd = &cli.Command{
Name: "config",
Usage: "Display Boost config",
Subcommands: []*cli.Command{
configDefaultCmd,
configUpdateCmd,
},
}

var configDefaultCmd = &cli.Command{
Name: "default",
Usage: "Print config file defaults",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-comment",
Usage: "don't include comments in the output",
},
},
Action: func(cctx *cli.Context) error {

cb, err := config.ConfigUpdate(config.DefaultBoost(), nil, !cctx.Bool("no-comment"), false)
if err != nil {
return err
}

fmt.Println(string(cb))

return nil
},
}

var configUpdateCmd = &cli.Command{
Name: "updated",
Usage: "Print config file with updates (changes from the default config file)",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-comment",
Usage: "don't include commented out default values in the output",
},
&cli.BoolFlag{
Name: "diff",
Usage: "only display values different from default",
},
},
Action: func(cctx *cli.Context) error {
path, err := homedir.Expand(cctx.String(FlagBoostRepo))
if err != nil {
return err
}

configPath := filepath.Join(path, "config.toml")

cfgNode, err := config.FromFile(configPath, config.DefaultBoost())
if err != nil {
return err
}

output, err := config.ConfigUpdate(cfgNode, config.DefaultBoost(), !cctx.Bool("no-comment"), cctx.Bool("diff"))
if err != nil {
return err
}

fmt.Print(string(output))
return nil
},
}
1 change: 1 addition & 0 deletions cmd/boostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
migrateMarketsCmd,
backupCmd,
restoreCmd,
configCmd,
dummydealCmd,
dataTransfersCmd,
retrievalDealsCmd,
Expand Down
169 changes: 169 additions & 0 deletions node/config/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,156 @@ ConfigVersion = 2
MyNewKey = "Hello"
`

const testConfig = `
ConfigVersion = 4
SealerApiInfo = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.0LyVxqOde8UjLTcHPEo3VEBILtPQqCDNEHcoCbTRQ_Y:/ip4/127.0.0.1/tcp/2345/http"
SectorIndexApiInfo = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.0LyVxqOde8UjLTcHPEo3VEBILtPQqCDNEHcoCbTRQ_Y:/ip4/127.0.0.1/tcp/2345/http"
[API]
ListenAddress = "/ip4/127.0.0.1/tcp/1288/http"
RemoteListenAddress = ""
Timeout = "30s"
[Backup]
DisableMetadataLog = false
[Libp2p]
ListenAddresses = ["/ip4/0.0.0.1/tcp/50000", "/ip6/::/tcp/0"]
AnnounceAddresses = []
NoAnnounceAddresses = []
DisableNatPortMap = false
ConnMgrLow = 150
ConnMgrHigh = 180
ConnMgrGrace = "20s"
[Pubsub]
Bootstrapper = false
RemoteTracer = ""
JsonTracer = ""
ElasticSearchTracer = ""
ElasticSearchIndex = ""
TracerSourceAuth = ""
[Storage]
ParallelFetchLimit = 10
StorageListRefreshDuration = "1h0m0s"
RedeclareOnStorageListRefresh = true
[Dealmaking]
ConsiderOnlineStorageDeals = true
ConsiderOfflineStorageDeals = true
ConsiderOnlineRetrievalDeals = true
ConsiderOfflineRetrievalDeals = true
ConsiderVerifiedStorageDeals = true
ConsiderUnverifiedStorageDeals = true
PieceCidBlocklist = []
ExpectedSealDuration = "24h0m0s"
MaxDealStartDelay = "336h0m0s"
MaxProviderCollateralMultiplier = 2
MaxStagingDealsBytes = 2000000000
MaxStagingDealsPercentPerHost = 0
StartEpochSealingBuffer = 480
DealProposalLogDuration = "24h0m0s"
RetrievalLogDuration = "24h0m0s"
StalledRetrievalTimeout = "30s"
Filter = ""
RetrievalFilter = ""
BlockstoreCacheMaxShards = 20
BlockstoreCacheExpiry = "30s"
IsUnsealedCacheExpiry = "5m0s"
MaxTransferDuration = "24h0m0s"
RemoteCommp = false
MaxConcurrentLocalCommp = 1
HTTPRetrievalMultiaddr = ""
HttpTransferMaxConcurrentDownloads = 20
HttpTransferStallCheckPeriod = "30s"
HttpTransferStallTimeout = "5m0s"
BitswapPeerID = ""
BitswapPrivKeyFile = ""
DealLogDurationDays = 30
SealingPipelineCacheTimeout = "30s"
FundsTaggingEnabled = true
[Dealmaking.RetrievalPricing]
Strategy = "default"
[Dealmaking.RetrievalPricing.Default]
VerifiedDealsFreeTransfer = false
[Dealmaking.RetrievalPricing.External]
Path = ""
[Wallets]
Miner = "t01000"
PublishStorageDeals = "t3rjh3byfhhrlmdl6ofou544rmwuazp4bbqzuleahtn66ejnh73bsaonwyg54qrokvnbv5bmg37dfd5vu2bx4q"
DealCollateral = "t3qa5i54vprhl7gmdfgriubvjc5kdffx7cvbqvumopgvsy2osre5dcjdjhz5coruxp4co3chj3gbtxin7vtoia"
PledgeCollateral = ""
[Graphql]
ListenAddress = "0.0.0.0"
Port = 8080
[Tracing]
Enabled = false
ServiceName = "boostd"
Endpoint = ""
[ContractDeals]
Enabled = false
AllowlistContracts = []
From = "0x0000000000000000000000000000000000000000"
[LotusDealmaking]
ConsiderOnlineStorageDeals = true
ConsiderOfflineStorageDeals = true
ConsiderOnlineRetrievalDeals = true
ConsiderOfflineRetrievalDeals = true
ConsiderVerifiedStorageDeals = true
ConsiderUnverifiedStorageDeals = true
PieceCidBlocklist = []
ExpectedSealDuration = "24h0m0s"
MaxDealStartDelay = "336h0m0s"
PublishMsgPeriod = "1h0m0s"
MaxDealsPerPublishMsg = 8
MaxProviderCollateralMultiplier = 2
MaxStagingDealsBytes = 0
SimultaneousTransfersForStorage = 20
SimultaneousTransfersForStoragePerClient = 0
SimultaneousTransfersForRetrieval = 20
StartEpochSealingBuffer = 480
Filter = ""
RetrievalFilter = ""
[LotusDealmaking.RetrievalPricing]
Strategy = "default"
[LotusDealmaking.RetrievalPricing.Default]
VerifiedDealsFreeTransfer = true
[LotusDealmaking.RetrievalPricing.External]
Path = ""
[LotusFees]
MaxPublishDealsFee = "0.05 FIL"
MaxMarketBalanceAddFee = "0.007 FIL"
[DAGStore]
RootDir = ""
MaxConcurrentIndex = 5
MaxConcurrentReadyFetches = 0
MaxConcurrentUnseals = 0
MaxConcurrencyStorageCalls = 100
GCInterval = "1m0s"
[IndexProvider]
Enable = true
EntriesCacheCapacity = 1024
EntriesChunkSize = 16384
TopicName = ""
PurgeCacheOnStart = false
[IndexProvider.Announce]
AnnounceOverHttp = false
DirectAnnounceURLs = ["https://cid.contact/ingest/announce", "http://localhost:3000"]
[IndexProvider.HttpPublisher]
Enabled = false
PublicHostname = ""
Port = 3104
`

func TestMigrate(t *testing.T) {
// Add a new mock migration so as to be able to test migrating up and down
mockv1Tov2 := func(string) (string, error) {
Expand Down Expand Up @@ -101,3 +251,22 @@ func TestMigrate(t *testing.T) {
require.NoError(t, err)
require.Equal(t, v1FileContents, string(bz))
}

func TestConfigDiff(t *testing.T) {
repoDir := t.TempDir()
err := os.WriteFile(path.Join(repoDir, "config.toml"), []byte(testConfig), 0644)
require.NoError(t, err)

cgf, err := FromFile(path.Join(repoDir, "config.toml"), DefaultBoost())
require.NoError(t, err)

s, err := ConfigUpdate(cgf, DefaultBoost(), false, true)
require.NoError(t, err)

require.False(t, strings.Contains(string(s), `The connect string for the sealing RPC API`))

s, err = ConfigUpdate(cgf, DefaultBoost(), true, true)
require.NoError(t, err)

require.True(t, strings.Contains(string(s), `The connect string for the sealing RPC API`))
}
Loading

0 comments on commit 188d5f0

Please sign in to comment.