Skip to content

Commit

Permalink
Merge branch 'main' into marston/ipfs-folders-again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Nov 28, 2024
2 parents 8bd852a + 8f8fb52 commit 5406a81
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- uses: actions/setup-go@v5
with:
go-version: 1.22.2 # The Go version to download (if necessary) and use.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2

# Runs djdefi/cloc-action
- name: Count Lines of Code (cloc)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- uses: actions/setup-go@v5
with:
go-version: 1.22.0 # The Go version to download (if necessary) and use.
Expand All @@ -30,7 +30,7 @@ jobs:
go tool cover -func coverage3.out
rm coverage2.out
rm coverage.out
- uses: codecov/codecov-action@v4.5.0
- uses: codecov/codecov-action@v5.0.7
with:
token: ${{ secrets.CODECOV }}

2 changes: 1 addition & 1 deletion .github/workflows/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.22.2
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
os: [ubuntu-20.04, macos-latest]
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- uses: actions/setup-go@v5
with:
go-version: 1.22.2 # The Go version to download (if necessary) and use.
Expand All @@ -36,7 +36,7 @@ jobs:
[native-build-cli]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/checkout@v4.2.2
- uses: actions/setup-go@v5
with:
go-version: 1.22.2 # The Go version to download (if necessary) and use.
Expand Down
16 changes: 16 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func init() {
Expand Down Expand Up @@ -156,6 +157,21 @@ func RootCmd() *cobra.Command {

r.PersistentFlags().String(types.FlagHome, types.DefaultHome, "sets the home directory for sequoia")
r.PersistentFlags().String(types.FlagLogLevel, types.DefaultLogLevel, "log level. info|error|debug")
r.PersistentFlags().Int("restart-attempt", defaultMaxRestartAttempt, "attempt to restart <restart-attempt> times when the provider fails to start")
r.PersistentFlags().String("domain", "http://example.com", "provider comain")
r.PersistentFlags().Int64("api_config.port", 3333, "port to serve api requests")
r.PersistentFlags().Int("api_config.ipfs_port", 4005, "port for IPFS")
r.PersistentFlags().String("api_config.ipfs_domain", "dns4/ipfs.example.com/tcp/4001", "IPFS domain")
r.PersistentFlags().Int64("proof_threads", 1000, "maximum threads for proofs")
r.PersistentFlags().String("data_directory", "$HOME/.sequoia/data", "directory to store database files")
r.PersistentFlags().Int64("queue_interval", 10, "seconds to wait until next cycle to flush the transaction queue")
r.PersistentFlags().Int64("proof_interval", 120, "seconds to wait until next cycle to post proofs")
r.PersistentFlags().Int64("total_bytes_offered", 1092616192, "maximum storage space to provide in bytes")

err := viper.BindPFlags(r.PersistentFlags())
if err != nil {
panic(err)
}

r.AddCommand(StartCmd(), wallet.WalletCmd(), InitCmd(), VersionCmd(), IPFSCmd(), SalvageCmd(), ShutdownCmd())

Expand Down
1 change: 0 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ func StartCmd() *cobra.Command {
},
}

cmd.Flags().Int("restart-attempt", defaultMaxRestartAttempt, "attempt to restart <restart-attempt> times when the provider fails to start")
return cmd
}
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func ReadConfig(data []byte) (*Config, error) {
// not using a default config to detect badger ds users
config := Config{}

err := yaml.Unmarshal(data, &config)
if err != nil {
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, err
}

Expand Down
39 changes: 34 additions & 5 deletions config/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import (
"errors"
"os"
"path"

"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)

const ConfigFileName = "config.yaml"
const (
ConfigName = "config"
ConfigType = "yaml"
ConfigFileName = ConfigName + "." + ConfigType
)

func createIfNotExists(directory string, fileName string, contents []byte) (bool, error) {
filePath := path.Join(directory, fileName)
Expand Down Expand Up @@ -62,7 +69,6 @@ func ReadConfigFile(directory string) (*Config, error) {
if err != nil {
return nil, err
}

return config, nil
}

Expand All @@ -74,10 +80,33 @@ func Init(home string) (*Config, error) {
return nil, err
}

err = createFiles(directory)
if err != nil {
viper.SetConfigName(ConfigName)
viper.SetConfigType(ConfigType)
viper.AddConfigPath(directory)

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
err := createFiles(directory)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}
/*
config, err := ReadConfigFile(directory)
if err != nil {
return nil, err
}
*/
var config Config

if err := viper.Unmarshal(&config); err != nil {
return nil, err
}

return ReadConfigFile(directory)
log.Debug().Object("config", config)

return &config, nil
}
157 changes: 110 additions & 47 deletions config/types.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,87 @@
package config

import (
"github.com/desmos-labs/cosmos-go-wallet/types"
"github.com/rs/zerolog"
"github.com/spf13/viper"
)

type Seed struct {
SeedPhrase string `json:"seed_phrase"`
DerivationPath string `json:"derivation_path"`
}

// required for the mapstructure tag
type ChainConfig struct {
Bech32Prefix string `yaml:"bech32_prefix" mapstructure:"bech32_prefix"`
RPCAddr string `yaml:"rpc_addr" mapstructure:"rpc_addr"`
GRPCAddr string `yaml:"grpc_addr" mapstructure:"grpc_addr"`
GasPrice string `yaml:"gas_price" mapstructure:"gas_price"`
GasAdjustment float64 `yaml:"gas_adjustment" mapstructure:"gas_adjustment"`
}

type Config struct {
QueueInterval int64 `yaml:"queue_interval"`
ProofInterval int64 `yaml:"proof_interval"`
StrayManagerCfg StrayManagerConfig `yaml:"stray_manager"`
ChainCfg types.ChainConfig `yaml:"chain_config"`
Ip string `yaml:"domain"`
TotalSpace int64 `yaml:"total_bytes_offered"`
DataDirectory string `yaml:"data_directory"`
APICfg APIConfig `yaml:"api_config"`
ProofThreads int64 `yaml:"proof_threads"`
BlockStoreConfig BlockStoreConfig `yaml:"block_store_config"`
QueueInterval int64 `yaml:"queue_interval" mapstructure:"queue_interval"`
ProofInterval int64 `yaml:"proof_interval" mapstructure:"proof_interval"`
StrayManagerCfg StrayManagerConfig `yaml:"stray_manager" mapstructure:"stray_manager"`
ChainCfg ChainConfig `yaml:"chain_config" mapstructure:"chain_config"`
Ip string `yaml:"domain" mapstructure:"domain"`
TotalSpace int64 `yaml:"total_bytes_offered" mapstructure:"total_bytes_offered"`
DataDirectory string `yaml:"data_directory" mapstructure:"data_directory"`
APICfg APIConfig `yaml:"api_config" mapstructure:"api_config"`
ProofThreads int16 `yaml:"proof_threads" mapstructure:"proof_threads"`
BlockStoreConfig BlockStoreConfig `yaml:"block_store_config" mapstructure:"block_store_config"`
}

func DefaultQueueInterval() int64 {
return 10
}

func DefaultProofInterval() int64 {
return 120
}

func DefaultIP() string {
return "https://example.com"
}

func DefaultTotalSpace() int64 {
return 1092616192
}

func DefaultDataDirectory() string {
return "$HOME/.sequoia/data"
}

func DefaultProofThreads() int16 {
return 1000
}

type StrayManagerConfig struct {
CheckInterval int64 `yaml:"check_interval"`
RefreshInterval int64 `yaml:"refresh_interval"`
HandCount int `yaml:"hands"`
CheckInterval int64 `yaml:"check_interval" mapstructure:"check_interval"`
RefreshInterval int64 `yaml:"refresh_interval" mapstructure:"refresh_interval"`
HandCount int `yaml:"hands" mapstructure:"hands"`
}

func DefaultStrayManagerConfig() StrayManagerConfig {
return StrayManagerConfig{
CheckInterval: 30,
RefreshInterval: 120,
HandCount: 2,
}
}

type APIConfig struct {
Port int64 `yaml:"port"`
IPFSPort int `yaml:"ipfs_port"`
IPFSDomain string `yaml:"ipfs_domain"`
Port int64 `yaml:"port" mapstructure:"port"`
IPFSPort int `yaml:"ipfs_port" mapstructure:"ipfs_port"`
IPFSDomain string `yaml:"ipfs_domain" mapstructure:"ipfs_domain"`
}

func DefaultAPIConfig() APIConfig {
return APIConfig{
Port: 3333,
IPFSPort: 4005,
IPFSDomain: "dns4/ipfs.example.com/tcp/4001",
}
}

const (
Expand All @@ -42,9 +92,16 @@ const (
type BlockStoreConfig struct {
// *choosing badgerdb as block store will need to use the same directory
// for data directory
Directory string `yaml:"directory"`
Directory string `yaml:"directory" mapstructure:"directory"`
// data store options: flatfs, badgerdb
Type string `yaml:"type"`
Type string `yaml:"type" mapstructure:"type"`
}

func DefaultBlockStoreConfig() BlockStoreConfig {
return BlockStoreConfig{
Directory: "$HOME/.sequoia/blockstore",
Type: OptFlatFS,
}
}

// LegacyWallet handles keys from earlier versions of storage providers.
Expand All @@ -56,35 +113,28 @@ type LegacyWallet struct {
Address string `json:"address"`
}

func DefaultChainConfig() ChainConfig {
return ChainConfig{
RPCAddr: "http://localhost:26657",
GRPCAddr: "localhost:9090",
GasPrice: "0.02ujkl",
GasAdjustment: 1.5,
Bech32Prefix: "jkl",
}
}

func DefaultConfig() *Config {
return &Config{
QueueInterval: 10,
ProofInterval: 120,
StrayManagerCfg: StrayManagerConfig{
CheckInterval: 30,
RefreshInterval: 120,
HandCount: 2,
},
ChainCfg: types.ChainConfig{
RPCAddr: "http://localhost:26657",
GRPCAddr: "localhost:9090",
GasPrice: "0.02ujkl",
GasAdjustment: 1.5,
Bech32Prefix: "jkl",
},
Ip: "https://example.com",
TotalSpace: 1092616192, // 1 gib default
DataDirectory: "$HOME/.sequoia/data",
APICfg: APIConfig{
Port: 3333,
IPFSPort: 4005,
IPFSDomain: "dns4/ipfs.example.com/tcp/4001",
},
ProofThreads: 1000,
BlockStoreConfig: BlockStoreConfig{
Directory: "$HOME/.sequoia/blockstore",
Type: OptFlatFS,
},
QueueInterval: DefaultQueueInterval(),
ProofInterval: DefaultProofInterval(),
StrayManagerCfg: DefaultStrayManagerConfig(),
ChainCfg: DefaultChainConfig(),
Ip: DefaultIP(),
TotalSpace: DefaultTotalSpace(), // 1 gib default
DataDirectory: DefaultDataDirectory(),
APICfg: DefaultAPIConfig(),
ProofThreads: DefaultProofThreads(),
BlockStoreConfig: DefaultBlockStoreConfig(),
}
}

Expand All @@ -104,6 +154,19 @@ func (c Config) MarshalZerologObject(e *zerolog.Event) {
Int64("APIPort", c.APICfg.Port).
Int("APIIPFSPort", c.APICfg.IPFSPort).
Str("APIIPFSDomain", c.APICfg.IPFSDomain).
Int64("ProofThreads", c.ProofThreads).
Int16("ProofThreads", c.ProofThreads).
Str("BlockstoreBackend", c.BlockStoreConfig.Type)
}

func init() {
viper.SetDefault("QueueInterval", DefaultQueueInterval())
viper.SetDefault("ProofInterval", DefaultProofInterval())
viper.SetDefault("StrayManagerCfg", DefaultStrayManagerConfig())
viper.SetDefault("ChainCfg", DefaultChainConfig())
viper.SetDefault("Ip", DefaultIP())
viper.SetDefault("TotalSpace", DefaultTotalSpace()) // 1 gib defaul
viper.SetDefault("DataDirectory", DefaultDataDirectory())
viper.SetDefault("APICfg", DefaultAPIConfig())
viper.SetDefault("ProofThreads", DefaultProofThreads())
viper.SetDefault("BlockStoreConfig", DefaultBlockStoreConfig())
}
Loading

0 comments on commit 5406a81

Please sign in to comment.