Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework IPFS Node/API loading along with plugin updates #334

Merged
merged 32 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7fb09d9
feat(ipfs): introduce new 'ipfs' package which encapsulates all IPFS …
Wondertan May 16, 2021
8f8837a
refactor(ipld,types): use new ipfs package with some logic segregation
Wondertan May 16, 2021
da642e2
fix(config): rework IPFS configuration
Wondertan May 16, 2021
a5c17db
fix(cmd,node): rework node starting with configurable IPFS
Wondertan May 16, 2021
e7c4c28
go mod tidy
Wondertan May 16, 2021
d60738b
fix(consensus,rpc,test)
Wondertan May 16, 2021
fe58690
Debugg CI for #334 (#337)
evan-forbes May 17, 2021
5891bac
fix(ipfs): move IPFS flags back to cmd
Wondertan May 17, 2021
cc80cc1
fix(node): init IPFS node in constructor not in OnStart
Wondertan May 17, 2021
2c13dda
move out Mock provider in a separate file
Wondertan May 17, 2021
15ab9ef
fix(ipld): export Data in leaf nmt node and make PutBlock param more …
Wondertan May 17, 2021
0bc3263
Update test/e2e/app/main.go
Wondertan May 18, 2021
9bfe2d6
fix(ipfs): optinate initialization through params
Wondertan May 18, 2021
60583ad
increase timeout to make CI happy
Wondertan May 18, 2021
4b47034
fix(ipfs): set ReqLog values to IPFS Context to avoid panics; set IPF…
Wondertan May 19, 2021
1f96496
feat(ipfs): add default configuration for embedded IPFS in FullNode
Wondertan May 19, 2021
0a92b42
try using embedded node instead of mock to try fix the CI
Wondertan May 19, 2021
07e2ede
another CI fix attempt
Wondertan May 19, 2021
0a7d7dc
Update ipfs/defaults.go
Wondertan May 19, 2021
d1b1c0a
Update ipfs/defaults.go
Wondertan May 19, 2021
e68ed79
Update ipfs/defaults.go
Wondertan May 19, 2021
debfadc
Update ipfs/defaults.go
Wondertan May 19, 2021
62fea11
resolve review comments
Wondertan May 19, 2021
e15271a
Merge pull request #340 from lazyledger/hlib/default-ipfs-config
Wondertan May 19, 2021
a55bf10
Revert "increase timeout to make CI happy"
Wondertan May 20, 2021
11d1529
node tests: Use in memory badger in unit tests
liamsi May 20, 2021
a0f4ae9
give the handshake some time
liamsi May 20, 2021
c3df6dd
timeout in TestNodeSetPrivValTCP: moar time
liamsi May 20, 2021
c46e4ba
TestNodeSetPrivValTCP: skip until we use a mock conn :-/
liamsi May 20, 2021
69b9715
Update node/node_test.go
liamsi May 20, 2021
47927cf
Update node/node_test.go
liamsi May 20, 2021
f828736
Merge pull request #347 from lazyledger/ismail/use-badger-in-memory
liamsi May 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 3 additions & 94 deletions cmd/tendermint/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ package commands

import (
"fmt"
"os"
"path/filepath"
"sync"

ipfscfg "github.com/ipfs/go-ipfs-config"
"github.com/ipfs/go-ipfs/plugin/loader"
"github.com/ipfs/go-ipfs/repo/fsrepo"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/spf13/cobra"

cfg "github.com/lazyledger/lazyledger-core/config"
"github.com/lazyledger/lazyledger-core/ipfs"
tmos "github.com/lazyledger/lazyledger-core/libs/os"
tmrand "github.com/lazyledger/lazyledger-core/libs/rand"
"github.com/lazyledger/lazyledger-core/p2p"
Expand Down Expand Up @@ -79,7 +73,6 @@ func initFilesWithConfig(config *cfg.Config) error {
if tmos.FileExists(genFile) {
logger.Info("Found genesis file", "path", genFile)
} else {

genDoc := types.GenesisDoc{
ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)),
GenesisTime: tmtime.Now(),
Expand All @@ -106,90 +99,6 @@ func initFilesWithConfig(config *cfg.Config) error {
logger.Info("Generated genesis file", "path", genFile)
}

if err := InitIpfs(config); err != nil {
return err
}

return nil
}

// InitIpfs takes a few config flags from the tendermint config.IPFS
// and applies them to the freshly created IPFS repo.
// The IPFS config will stored under config.IPFS.ConfigRootPath.
// TODO(ismail) move into separate file, and consider making IPFS initialization
// independent from the `tendermint init` subcommand.
// TODO(ismail): add counter part in ResetAllCmd
func InitIpfs(config *cfg.Config) error {
repoRoot := config.IPFSRepoRoot()
if fsrepo.IsInitialized(repoRoot) {
logger.Info("IPFS was already initialized", "ipfs-path", repoRoot)
return nil
}
var conf *ipfscfg.Config

identity, err := ipfscfg.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Type(options.Ed25519Key),
})
if err != nil {
return err
}

logger.Info("initializing IPFS node", "ipfs-path", repoRoot)

if err := tmos.EnsureDir(repoRoot, 0700); err != nil {
return err
}

conf, err = ipfscfg.InitWithIdentity(identity)
if err != nil {
return err
}

applyFromTmConfig(conf, config.IPFS)
if err := setupPlugins(repoRoot); err != nil {
return err
}

if err := fsrepo.Init(repoRoot, conf); err != nil {
return err
}
return nil
}

// Inject replies on several global vars internally.
// For instance fsrepo.AddDatastoreConfigHandler will error
// if called multiple times with the same datastore.
// But for CI and integration tests, we want to setup the plugins
// for each repo but only inject once s.t. we can init multiple
// repos from the same runtime.
// TODO(ismail): find a more elegant way to achieve the same.
var injectPluginsOnce sync.Once

func setupPlugins(path string) error {
// Load plugins. This will skip the repo if not available.
plugins, err := loader.NewPluginLoader(filepath.Join(path, "plugins"))
if err != nil {
return fmt.Errorf("error loading plugins: %s", err)
}

if err := plugins.Initialize(); err != nil {
return fmt.Errorf("error initializing plugins: %s", err)
}

injectPluginsOnce.Do(func() {
err = plugins.Inject()
})
if err != nil {
return fmt.Errorf("error injecting plugins once: %w", err)
}

return nil
}

func applyFromTmConfig(ipfsConf *ipfscfg.Config, tmConf *cfg.IPFSConfig) {
ipfsConf.Addresses.API = ipfscfg.Strings{tmConf.API}
ipfsConf.Addresses.Gateway = ipfscfg.Strings{tmConf.Gateway}
ipfsConf.Addresses.Swarm = tmConf.Swarm
ipfsConf.Addresses.Announce = tmConf.Announce
ipfsConf.Addresses.NoAnnounce = tmConf.NoAnnounce
// TODO(ismail): add counter part in ResetAllCmd
return ipfs.InitRepo(config.IPFS.Path(), logger)
}
3 changes: 3 additions & 0 deletions cmd/tendermint/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"

cfg "github.com/lazyledger/lazyledger-core/config"
"github.com/lazyledger/lazyledger-core/ipfs"
tmos "github.com/lazyledger/lazyledger-core/libs/os"
nm "github.com/lazyledger/lazyledger-core/node"
)
Expand Down Expand Up @@ -89,6 +90,8 @@ func AddNodeFlags(cmd *cobra.Command) {
"db-dir",
config.DBPath,
"database directory")

ipfs.AddFlags(cmd, config.IPFS)
}

// NewRunNodeCmd returns the command that allows the CLI to start a node.
Expand Down
11 changes: 7 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"
"time"

"github.com/lazyledger/lazyledger-core/ipfs"
)

const (
Expand Down Expand Up @@ -66,7 +68,7 @@ type Config struct {
TxIndex *TxIndexConfig `mapstructure:"tx-index"`
Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"`
// Options for IPFS service
IPFS *IPFSConfig `mapstructure:"ipfs"`
IPFS *ipfs.Config `mapstructure:"ipfs"`
}

// DefaultConfig returns a default configuration for a Tendermint node
Expand All @@ -81,7 +83,7 @@ func DefaultConfig() *Config {
Consensus: DefaultConsensusConfig(),
TxIndex: DefaultTxIndexConfig(),
Instrumentation: DefaultInstrumentationConfig(),
IPFS: DefaultIPFSConfig(),
IPFS: ipfs.DefaultConfig(),
}
}

Expand All @@ -108,6 +110,7 @@ func (cfg *Config) SetRoot(root string) *Config {
cfg.P2P.RootDir = root
cfg.Mempool.RootDir = root
cfg.Consensus.RootDir = root
cfg.IPFS.RootDir = root
return cfg
}

Expand Down Expand Up @@ -1007,8 +1010,8 @@ func DefaultInstrumentationConfig() *InstrumentationConfig {
}
}

func TetsIpfsConfig() *IPFSConfig {
return DefaultIPFSConfig()
func TetsIpfsConfig() *ipfs.Config {
return ipfs.DefaultConfig()
}

// TestInstrumentationConfig returns a default configuration for metrics
Expand Down
34 changes: 0 additions & 34 deletions config/ipfs_config.go

This file was deleted.

20 changes: 3 additions & 17 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,23 +439,9 @@ namespace = "{{ .Instrumentation.Namespace }}"
#######################################################
[ipfs]

# IPFS repo root.
repo-root = "{{ .IPFS.ConfigRootPath}}"

## Below options will be passed to ipfs when initializing an ipfs repo.
## They will be written into the repo-root/config on init.
## To modify the generated config, edit repo-root/config accordingly.

# Address for the local API (RPC).
api = "{{ .IPFS.API }}"
# Address to listen on for IPFS HTTP object gateway.
gateway = "{{ .IPFS.Gateway }}"
# Addresses for the swarm to listen on
swarm = [{{ range .IPFS.Swarm }}{{ printf "%q, " . }}{{end}}]
# Swarm addresses to announce to the network
announce = [{{ range .IPFS.Announce }}{{ printf "%q, " . }}{{end}}]
# Swarm addresses not to announce to the network
no-announce = [{{ range .IPFS.NoAnnounce }}{{ printf "%q, " . }}{{end}}]
# IPFS related configuration
repo-path = "{{ .IPFS.RepoPath}}"
serve-api = "{{ .IPFS.ServeAPI}}"
Wondertan marked this conversation as resolved.
Show resolved Hide resolved
`

/****** these are for test settings ***********/
Expand Down
3 changes: 2 additions & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/lazyledger/lazyledger-core/libs/service"
tmsync "github.com/lazyledger/lazyledger-core/libs/sync"
"github.com/lazyledger/lazyledger-core/p2p"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
tmproto "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
sm "github.com/lazyledger/lazyledger-core/state"
"github.com/lazyledger/lazyledger-core/types"
Expand Down Expand Up @@ -1116,7 +1117,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*1500)
defer cancel()
// TODO: post data to IPFS in a goroutine
err := block.PutBlock(ctx, cs.IpfsAPI.Dag())
err := ipld.PutBlock(ctx, cs.IpfsAPI.Dag(), block)
if err != nil {
cs.Logger.Error(fmt.Sprintf("failure to post block data to IPFS: %s", err.Error()))
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-ipfs v0.8.0
github.com/ipfs/go-ipfs-api v0.2.0
github.com/ipfs/go-ipfs-config v0.12.0
github.com/ipfs/go-ipfs-config v0.11.0
Wondertan marked this conversation as resolved.
Show resolved Hide resolved
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-path v0.0.9 // indirect
github.com/ipfs/go-verifcid v0.0.1
Expand All @@ -30,6 +30,7 @@ require (
github.com/lazyledger/rsmt2d v0.2.0
github.com/libp2p/go-buffer-pool v0.0.2
github.com/minio/highwayhash v1.0.1
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multihash v0.0.14
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1
Expand Down
Loading