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 all 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)
}
25 changes: 24 additions & 1 deletion cmd/tendermint/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ 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"
)

var (
genesisHash []byte
initIPFS bool
)

// AddNodeFlags exposes some common configuration options on the command-line
Expand Down Expand Up @@ -89,6 +91,23 @@ func AddNodeFlags(cmd *cobra.Command) {
"db-dir",
config.DBPath,
"database directory")

cmd.Flags().String(
"ipfs.repo-path",
config.IPFS.RepoPath,
"custom IPFS repository path. Defaults to `.{RootDir}/ipfs`",
)
cmd.Flags().Bool(
"ipfs.serve-api",
config.IPFS.ServeAPI,
"set this to expose IPFS API(useful for debugging)",
)
cmd.Flags().BoolVar(
&initIPFS,
"ipfs.init",
false,
"set this to initialize repository for embedded IPFS node. Flag is ignored if repo is already initialized",
)
}

// NewRunNodeCmd returns the command that allows the CLI to start a node.
Expand All @@ -103,7 +122,11 @@ func NewRunNodeCmd(nodeProvider nm.Provider) *cobra.Command {
return err
}

n, err := nodeProvider(config, logger)
n, err := nodeProvider(
config,
ipfs.Embedded(initIPFS, config.IPFS, logger),
logger,
)
if err != nil {
return fmt.Errorf("failed to create node: %w", err)
}
Expand Down
27 changes: 15 additions & 12 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 @@ -841,16 +844,16 @@ func DefaultConsensusConfig() *ConsensusConfig {
// TestConsensusConfig returns a configuration for testing the consensus service
func TestConsensusConfig() *ConsensusConfig {
cfg := DefaultConsensusConfig()
cfg.TimeoutPropose = 40 * time.Millisecond
cfg.TimeoutProposeDelta = 1 * time.Millisecond
cfg.TimeoutPrevote = 10 * time.Millisecond
cfg.TimeoutPrevoteDelta = 1 * time.Millisecond
cfg.TimeoutPrecommit = 10 * time.Millisecond
cfg.TimeoutPrecommitDelta = 1 * time.Millisecond
cfg.TimeoutPropose = 100 * time.Millisecond
cfg.TimeoutProposeDelta = 10 * time.Millisecond
cfg.TimeoutPrevote = 40 * time.Millisecond
cfg.TimeoutPrevoteDelta = 10 * time.Millisecond
cfg.TimeoutPrecommit = 40 * time.Millisecond
cfg.TimeoutPrecommitDelta = 10 * time.Millisecond
// NOTE: when modifying, make sure to update time_iota_ms (testGenesisFmt) in toml.go
cfg.TimeoutCommit = 10 * time.Millisecond
cfg.TimeoutCommit = 40 * time.Millisecond
cfg.SkipTimeoutCommit = true
cfg.PeerGossipSleepDuration = 5 * time.Millisecond
cfg.PeerGossipSleepDuration = 10 * time.Millisecond
Comment on lines -844 to +856
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwarding my comment from #337 for posterity:
😞 I resorted to increasing the timeouts to get the consensus tests to be more reliable. Perhaps this is needed when github is busy?

I just kinda eyeballed these numbers. I have no reasoning for picking the ones I did other than that they were larger than the originals.

cfg.PeerQueryMaj23SleepDuration = 250 * time.Millisecond
cfg.DoubleSignCheckHeight = int64(0)
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
2 changes: 1 addition & 1 deletion consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type cleanupFunc func()
var (
config *cfg.Config // NOTE: must be reset for each _test.go file
consensusReplayConfig *cfg.Config
ensureTimeout = 600 * time.Millisecond
ensureTimeout = 1000 * time.Millisecond
)

func ensureDir(dir string, mode os.FileMode) {
Expand Down
16 changes: 12 additions & 4 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

"github.com/gogo/protobuf/proto"
ipfsapi "github.com/ipfs/interface-go-ipfs-core"
ipface "github.com/ipfs/interface-go-ipfs-core"
cfg "github.com/lazyledger/lazyledger-core/config"
cstypes "github.com/lazyledger/lazyledger-core/consensus/types"
"github.com/lazyledger/lazyledger-core/crypto"
Expand All @@ -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 @@ -93,7 +94,7 @@ type State struct {
// store blocks and commits
blockStore sm.BlockStore

IpfsAPI ipfsapi.CoreAPI
ipfs ipface.CoreAPI

// create and execute blocks
blockExec *sm.BlockExecutor
Expand Down Expand Up @@ -206,6 +207,13 @@ func NewState(
//----------------------------------------
// Public interface

// SetIPFSApi sets the IPFSAPI
func (cs *State) SetIPFSApi(api ipface.CoreAPI) {
cs.mtx.Lock()
defer cs.mtx.Unlock()
cs.ipfs = api
}

// SetLogger implements Service.
func (cs *State) SetLogger(l log.Logger) {
cs.BaseService.Logger = l
Expand Down Expand Up @@ -1111,12 +1119,12 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {

// post data to ipfs
// TODO(evan): don't hard code context and timeout
if cs.IpfsAPI != nil {
if cs.ipfs != nil {
// longer timeouts result in block proposers failing to propose blocks in time.
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.ipfs.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