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

Stop embedding an IPFS node #514

Merged
merged 11 commits into from
Aug 25, 2021
8 changes: 1 addition & 7 deletions abci/example/dummyapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
cmd "github.com/celestiaorg/celestia-core/cmd/tendermint/commands"
"github.com/celestiaorg/celestia-core/cmd/tendermint/commands/debug"
cfg "github.com/celestiaorg/celestia-core/config"
"github.com/celestiaorg/celestia-core/ipfs"
"github.com/celestiaorg/celestia-core/libs/cli"
"github.com/celestiaorg/celestia-core/libs/log"
"github.com/celestiaorg/celestia-core/node"
Expand Down Expand Up @@ -78,11 +77,7 @@ func main() {
}

// DummyNode implements NodeProvider.
func DummyNode(config *cfg.Config, provider ipfs.NodeProvider, logger log.Logger) (*node.Node, error) {
if err := ipfs.InitRepo(config.IPFS.Path(), logger); err != nil {
return nil, fmt.Errorf("failed to initialize IPFS repo at path %s: %v", config.IPFS.Path(), err)
}

func DummyNode(config *cfg.Config, logger log.Logger) (*node.Node, error) {
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
if err != nil {
return nil, fmt.Errorf("failed to load or gen node key %s: %w", config.NodeKeyFile(), err)
Expand All @@ -103,7 +98,6 @@ func DummyNode(config *cfg.Config, provider ipfs.NodeProvider, logger log.Logger
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(config),
node.DefaultDBProvider,
provider,
node.DefaultMetricsProvider(config.Instrumentation),
logger,
)
Expand Down
13 changes: 3 additions & 10 deletions blockchain/v0/reactor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v0

import (
"context"
"fmt"
"reflect"
"time"
Expand Down Expand Up @@ -179,10 +178,7 @@ func (bcR *BlockchainReactor) RemovePeer(peer p2p.Peer, reason interface{}) {
func (bcR *BlockchainReactor) respondToPeer(msg *bcproto.BlockRequest,
src p2p.Peer) (queued bool) {

block, err := bcR.store.LoadBlock(context.TODO(), msg.Height)
if err != nil {
panic(err)
}
block := bcR.store.LoadBlock(msg.Height)
if block != nil {
bl, err := block.ToProto()
if err != nil {
Expand Down Expand Up @@ -422,14 +418,11 @@ FOR_LOOP:
bcR.pool.PopRequest()

// TODO: batch saves so we dont persist to disk every block
err := bcR.store.SaveBlock(context.TODO(), first, firstParts, second.LastCommit)
if err != nil {
// an error is only returned if something with the local IPFS blockstore is seriously wrong
panic(err)
}
bcR.store.SaveBlock(first, firstParts, second.LastCommit)

// TODO: same thing for app - but we would need a way to get the hash
// without persisting the state.
var err error
state, _, err = bcR.blockExec.ApplyBlock(state, firstID, first)
if err != nil {
// TODO This is bad, are we zombie?
Expand Down
19 changes: 5 additions & 14 deletions blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v0

import (
"context"
"crypto/sha256"
"fmt"
"os"
Expand Down Expand Up @@ -69,9 +68,10 @@ func newBlockchainReactor(
panic(fmt.Errorf("error start app: %w", err))
}

blockDB := memdb.NewDB()
stateDB := memdb.NewDB()
stateStore := sm.NewStore(stateDB)
blockStore := store.MockBlockStore(nil)
blockStore := store.NewBlockStore(blockDB)

state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
if err != nil {
Expand Down Expand Up @@ -99,10 +99,7 @@ func newBlockchainReactor(
lastCommit := types.NewCommit(blockHeight-1, 0, types.BlockID{}, nil)
if blockHeight > 1 {
lastBlockMeta := blockStore.LoadBlockMeta(blockHeight - 1)
lastBlock, err := blockStore.LoadBlock(context.TODO(), blockHeight-1)
if err != nil {
panic(err)
}
lastBlock := blockStore.LoadBlock(blockHeight - 1)

vote, err := types.MakeVote(
lastBlock.Header.Height,
Expand All @@ -129,10 +126,7 @@ func newBlockchainReactor(
panic(fmt.Errorf("error apply block: %w", err))
}

err := blockStore.SaveBlock(context.TODO(), thisBlock, thisParts, lastCommit)
if err != nil {
panic(err)
}
blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
}

bcReactor := NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
Expand Down Expand Up @@ -189,10 +183,7 @@ func TestNoBlockResponse(t *testing.T) {
assert.Equal(t, maxBlockHeight, reactorPairs[0].reactor.store.Height())

for _, tt := range tests {
block, err := reactorPairs[1].reactor.store.LoadBlock(context.TODO(), tt.height)
if err != nil {
panic(err)
}
block := reactorPairs[1].reactor.store.LoadBlock(tt.height)
if tt.existent {
assert.True(t, block != nil)
} else {
Expand Down
4 changes: 1 addition & 3 deletions cmd/tendermint/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/spf13/cobra"

cfg "github.com/celestiaorg/celestia-core/config"
"github.com/celestiaorg/celestia-core/ipfs"
tmos "github.com/celestiaorg/celestia-core/libs/os"
tmrand "github.com/celestiaorg/celestia-core/libs/rand"
"github.com/celestiaorg/celestia-core/p2p"
Expand Down Expand Up @@ -99,6 +98,5 @@ func initFilesWithConfig(config *cfg.Config) error {
logger.Info("Generated genesis file", "path", genFile)
}

// TODO(ismail): add counter part in ResetAllCmd
return ipfs.InitRepo(config.IPFS.Path(), logger)
return nil
}
19 changes: 0 additions & 19 deletions cmd/tendermint/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import (
"github.com/spf13/cobra"

cfg "github.com/celestiaorg/celestia-core/config"
"github.com/celestiaorg/celestia-core/ipfs"
tmos "github.com/celestiaorg/celestia-core/libs/os"
nm "github.com/celestiaorg/celestia-core/node"
)

var (
genesisHash []byte
initIPFS bool
)

// AddNodeFlags exposes some common configuration options on the command-line
Expand Down Expand Up @@ -91,22 +89,6 @@ func AddNodeFlags(cmd *cobra.Command) {
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 @@ -123,7 +105,6 @@ func NewRunNodeCmd(nodeProvider nm.Provider) *cobra.Command {

n, err := nodeProvider(
config,
ipfs.Embedded(initIPFS, config.IPFS, logger),
logger,
)
if err != nil {
Expand Down
13 changes: 1 addition & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"os"
"path/filepath"
"time"

"github.com/celestiaorg/celestia-core/ipfs"
)

const (
Expand Down Expand Up @@ -67,8 +65,6 @@ type Config struct {
Consensus *ConsensusConfig `mapstructure:"consensus"`
TxIndex *TxIndexConfig `mapstructure:"tx-index"`
Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"`
// Options for IPFS service
IPFS *ipfs.Config `mapstructure:"ipfs"`
}

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

Expand All @@ -99,7 +94,6 @@ func TestConfig() *Config {
Consensus: TestConsensusConfig(),
TxIndex: TestTxIndexConfig(),
Instrumentation: TestInstrumentationConfig(),
IPFS: TetsIpfsConfig(),
}
}

Expand All @@ -110,7 +104,6 @@ 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 @@ -847,7 +840,7 @@ func TestConsensusConfig() *ConsensusConfig {
cfg.TimeoutProposeDelta = 20 * time.Millisecond
cfg.TimeoutPrevote = 80 * time.Millisecond
cfg.TimeoutPrevoteDelta = 20 * time.Millisecond
cfg.TimeoutPrecommit = 160 * time.Millisecond
cfg.TimeoutPrecommit = 80 * time.Millisecond
cfg.TimeoutPrecommitDelta = 20 * time.Millisecond
// NOTE: when modifying, make sure to update time_iota_ms (testGenesisFmt) in toml.go
cfg.TimeoutCommit = 80 * time.Millisecond
Expand Down Expand Up @@ -1009,10 +1002,6 @@ func DefaultInstrumentationConfig() *InstrumentationConfig {
}
}

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

// TestInstrumentationConfig returns a default configuration for metrics
// reporting.
func TestInstrumentationConfig() *InstrumentationConfig {
Expand Down
9 changes: 0 additions & 9 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,6 @@ max-open-connections = {{ .Instrumentation.MaxOpenConnections }}

# Instrumentation namespace
namespace = "{{ .Instrumentation.Namespace }}"

#######################################################
### IPFS Configuration Options ###
#######################################################
[ipfs]

# IPFS related configuration
repo-path = "{{ .IPFS.RepoPath}}"
serve-api = "{{ .IPFS.ServeAPI}}"
`

/****** these are for test settings ***********/
Expand Down
10 changes: 2 additions & 8 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ import (
"testing"
"time"

"github.com/ipfs/go-blockservice"
offline "github.com/ipfs/go-ipfs-exchange-offline"
"github.com/ipfs/go-merkledag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

abcicli "github.com/celestiaorg/celestia-core/abci/client"
abci "github.com/celestiaorg/celestia-core/abci/types"
"github.com/celestiaorg/celestia-core/evidence"
"github.com/celestiaorg/celestia-core/ipfs"
"github.com/celestiaorg/celestia-core/libs/db/memdb"
"github.com/celestiaorg/celestia-core/libs/log"
"github.com/celestiaorg/celestia-core/libs/service"
Expand Down Expand Up @@ -59,9 +55,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
app.InitChain(abci.RequestInitChain{Validators: vals})

blockDB := memdb.NewDB()
bs := ipfs.MockBlockStore()
dag := merkledag.NewDAGService(blockservice.New(bs, offline.Exchange(bs)))
blockStore := store.NewBlockStore(blockDB, bs, log.TestingLogger())
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
mtx := new(tmsync.Mutex)
Expand All @@ -84,7 +78,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
// Make State
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
cs := NewState(thisConfig.Consensus, state, blockExec, blockStore,
mempool, dag, ipfs.MockRouting(), evpool)
mempool, evpool)
cs.SetLogger(cs.Logger)
// set private validator
pv := privVals[i]
Expand Down
20 changes: 6 additions & 14 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import (
"time"

"github.com/go-kit/kit/log/term"
"github.com/ipfs/go-blockservice"
offline "github.com/ipfs/go-ipfs-exchange-offline"
format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/require"

abcicli "github.com/celestiaorg/celestia-core/abci/client"
Expand All @@ -27,7 +22,6 @@ import (
abci "github.com/celestiaorg/celestia-core/abci/types"
cfg "github.com/celestiaorg/celestia-core/config"
cstypes "github.com/celestiaorg/celestia-core/consensus/types"
"github.com/celestiaorg/celestia-core/ipfs"
tmbytes "github.com/celestiaorg/celestia-core/libs/bytes"
dbm "github.com/celestiaorg/celestia-core/libs/db"
"github.com/celestiaorg/celestia-core/libs/db/memdb"
Expand All @@ -53,11 +47,11 @@ const (
// test.
type cleanupFunc func()

// genesis, chain_id, priv_val, ipfsAPI
// genesis, chain_id, priv_val
var (
config *cfg.Config // NOTE: must be reset for each _test.go file
consensusReplayConfig *cfg.Config
ensureTimeout = 4 * time.Second
ensureTimeout = 2 * time.Second
)

func ensureDir(dir string, mode os.FileMode) {
Expand Down Expand Up @@ -357,7 +351,7 @@ func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message {
//-------------------------------------------------------------------------------
// consensus states

func newState(state sm.State, pv types.PrivValidator, app abci.Application, ipfsDagAPI format.DAGService) *State {
func newState(state sm.State, pv types.PrivValidator, app abci.Application) *State {
config := cfg.ResetTestRoot("consensus_state_test")
return newStateWithConfig(config, state, pv, app)
}
Expand All @@ -380,9 +374,7 @@ func newStateWithConfigAndBlockStore(
blockDB dbm.DB,
) *State {
// Get BlockStore
bs := ipfs.MockBlockStore()
dag := merkledag.NewDAGService(blockservice.New(bs, offline.Exchange(bs)))
blockStore := store.NewBlockStore(blockDB, bs, log.TestingLogger())
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
mtx := new(tmsync.Mutex)
Expand All @@ -406,7 +398,7 @@ func newStateWithConfigAndBlockStore(
}

blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, dag, ipfs.MockRouting(), evpool)
cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
cs.SetLogger(log.TestingLogger().With("module", "consensus"))
cs.SetPrivValidator(pv)

Expand Down Expand Up @@ -438,7 +430,7 @@ func randState(nValidators int) (*State, []*validatorStub) {

vss := make([]*validatorStub, nValidators)

cs := newState(state, privVals[0], counter.NewApplication(true), mdutils.Mock())
cs := newState(state, privVals[0], counter.NewApplication(true))

for i := 0; i < nValidators; i++ {
vss[i] = newValidatorStub(privVals[i], int32(i))
Expand Down
Loading