Skip to content

Commit

Permalink
Revert "Add the ipfs dag api object in Blockstore (#356)" and get rid…
Browse files Browse the repository at this point in the history
… of embedded ipfs objects

This reverts commit 40acb17.
  • Loading branch information
evan-forbes committed Aug 24, 2021
1 parent 27bfd13 commit 225ee8b
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 113 deletions.
3 changes: 1 addition & 2 deletions blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"
"time"

mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -72,7 +71,7 @@ func newBlockchainReactor(
blockDB := memdb.NewDB()
stateDB := memdb.NewDB()
stateStore := sm.NewStore(stateDB)
blockStore := store.NewBlockStore(blockDB, mdutils.Mock())
blockStore := store.NewBlockStore(blockDB)

state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,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
7 changes: 2 additions & 5 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import (
"testing"
"time"

mdutils "github.com/ipfs/go-merkledag/test"
"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 @@ -57,8 +55,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
app.InitChain(abci.RequestInitChain{Validators: vals})

blockDB := memdb.NewDB()
dag := mdutils.Mock()
blockStore := store.NewBlockStore(blockDB, dag)
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
mtx := new(tmsync.Mutex)
Expand All @@ -81,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
23 changes: 9 additions & 14 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"time"

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

abcicli "github.com/celestiaorg/celestia-core/abci/client"
Expand All @@ -24,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 Down Expand Up @@ -54,7 +51,7 @@ type cleanupFunc func()
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 @@ -354,20 +351,19 @@ 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, ipfsDagAPI)
return newStateWithConfig(config, state, pv, app)
}

func newStateWithConfig(
thisConfig *cfg.Config,
state sm.State,
pv types.PrivValidator,
app abci.Application,
ipfsDagAPI format.DAGService,
) *State {
blockDB := memdb.NewDB()
return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB, ipfsDagAPI)
return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB)
}

func newStateWithConfigAndBlockStore(
Expand All @@ -376,10 +372,9 @@ func newStateWithConfigAndBlockStore(
pv types.PrivValidator,
app abci.Application,
blockDB dbm.DB,
dag format.DAGService,
) *State {
// Get BlockStore
blockStore := store.NewBlockStore(blockDB, dag)
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
mtx := new(tmsync.Mutex)
Expand All @@ -403,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 @@ -435,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 Expand Up @@ -708,7 +703,7 @@ func randConsensusNet(
vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{Validators: vals})

css[i] = newStateWithConfigAndBlockStore(thisConfig, state, privVals[i], app, stateDB, mdutils.Mock())
css[i] = newStateWithConfigAndBlockStore(thisConfig, state, privVals[i], app, stateDB)
css[i].SetTimeoutTicker(tickerFunc())
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
}
Expand Down Expand Up @@ -771,7 +766,7 @@ func randConsensusNetWithPeers(
app.InitChain(abci.RequestInitChain{Validators: vals})
// sm.SaveState(stateDB,state) //height 1's validatorsInfo already saved in LoadStateFromDBOrGenesisDoc above

css[i] = newStateWithConfig(thisConfig, state, privVal, app, mdutils.Mock())
css[i] = newStateWithConfig(thisConfig, state, privVal, app)
css[i].SetTimeoutTicker(tickerFunc())
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
}
Expand Down
11 changes: 5 additions & 6 deletions consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -30,7 +29,7 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) {

config.Consensus.CreateEmptyBlocks = false
state, privVals := randGenesisState(1, false, 10)
cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), mdutils.Mock())
cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication())
assertMempool(cs.txNotifier).EnableTxsAvailable()
height, round := cs.Height, cs.Round
newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock)
Expand All @@ -50,7 +49,7 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) {

config.Consensus.CreateEmptyBlocksInterval = ensureTimeout
state, privVals := randGenesisState(1, false, 10)
cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), mdutils.Mock())
cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication())

assertMempool(cs.txNotifier).EnableTxsAvailable()

Expand All @@ -68,7 +67,7 @@ func TestMempoolProgressInHigherRound(t *testing.T) {

config.Consensus.CreateEmptyBlocks = false
state, privVals := randGenesisState(1, false, 10)
cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), mdutils.Mock())
cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication())

assertMempool(cs.txNotifier).EnableTxsAvailable()
height, round := cs.Height, cs.Round
Expand Down Expand Up @@ -118,7 +117,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) {
blockDB := memdb.NewDB()
stateStore := sm.NewStore(blockDB)

cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB, mdutils.Mock())
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB)
err := stateStore.Save(state)
require.NoError(t, err)
newBlockHeaderCh := subscribe(cs.eventBus, types.EventQueryNewBlockHeader)
Expand All @@ -144,7 +143,7 @@ func TestMempoolRmBadTx(t *testing.T) {
blockDB := memdb.NewDB()

stateStore := sm.NewStore(blockDB)
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB, mdutils.Mock())
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB)
err := stateStore.Save(state)
require.NoError(t, err)

Expand Down
9 changes: 3 additions & 6 deletions consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"testing"
"time"

mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -23,7 +22,6 @@ import (
cstypes "github.com/celestiaorg/celestia-core/consensus/types"
cryptoenc "github.com/celestiaorg/celestia-core/crypto/encoding"
"github.com/celestiaorg/celestia-core/crypto/tmhash"
"github.com/celestiaorg/celestia-core/ipfs"
"github.com/celestiaorg/celestia-core/libs/bits"
"github.com/celestiaorg/celestia-core/libs/bytes"
"github.com/celestiaorg/celestia-core/libs/db/memdb"
Expand Down Expand Up @@ -156,8 +154,7 @@ func TestReactorWithEvidence(t *testing.T) {
// css[i] = newStateWithConfig(thisConfig, state, privVals[i], app)

blockDB := memdb.NewDB()
dag := mdutils.Mock()
blockStore := store.NewBlockStore(blockDB, dag)
blockStore := store.NewBlockStore(blockDB)

// one for mempool, one for consensus
mtx := new(tmsync.Mutex)
Expand Down Expand Up @@ -186,7 +183,7 @@ func TestReactorWithEvidence(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(), evpool2)
mempool, evpool2)
cs.SetLogger(log.TestingLogger().With("module", "consensus"))
cs.SetPrivValidator(pv)

Expand Down Expand Up @@ -673,7 +670,7 @@ func timeoutWaitGroup(t *testing.T, n int, f func(int), css []*State) {

// we're running many nodes in-process, possibly in in a virtual machine,
// and spewing debug messages - making a block could take a while,
timeout := time.Minute * 8
timeout := time.Minute * 4

select {
case <-done:
Expand Down
9 changes: 3 additions & 6 deletions consensus/replay_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"strings"

cfg "github.com/celestiaorg/celestia-core/config"
"github.com/celestiaorg/celestia-core/ipfs"
"github.com/celestiaorg/celestia-core/libs/db/badgerdb"
"github.com/celestiaorg/celestia-core/libs/log"
tmos "github.com/celestiaorg/celestia-core/libs/os"
"github.com/celestiaorg/celestia-core/proxy"
sm "github.com/celestiaorg/celestia-core/state"
"github.com/celestiaorg/celestia-core/store"
"github.com/celestiaorg/celestia-core/types"
mdutils "github.com/ipfs/go-merkledag/test"
)

const (
Expand Down Expand Up @@ -131,7 +129,7 @@ func (pb *playback) replayReset(count int, newStepSub types.Subscription) error
pb.cs.Wait()

newCS := NewState(pb.cs.config, pb.genesisState.Copy(), pb.cs.blockExec,
pb.cs.blockStore, pb.cs.txNotifier, mdutils.Mock(), ipfs.MockRouting(), pb.cs.evpool)
pb.cs.blockStore, pb.cs.txNotifier, pb.cs.evpool)
newCS.SetEventBus(pb.cs.eventBus)
newCS.startForReplay()

Expand Down Expand Up @@ -290,8 +288,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
if err != nil {
tmos.Exit(err.Error())
}
dag := mdutils.Mock()
blockStore := store.NewBlockStore(blockStoreDB, dag)
blockStore := store.NewBlockStore(blockStoreDB)

// Get State
stateDB, err := badgerdb.NewDB("state", config.DBDir())
Expand Down Expand Up @@ -332,7 +329,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)

consensusState := NewState(csConfig, state.Copy(), blockExec,
blockStore, mempool, dag, ipfs.MockRouting(), evpool)
blockStore, mempool, evpool)
consensusState.SetEventBus(eventBus)
return consensusState
}
20 changes: 8 additions & 12 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"time"

"github.com/gogo/protobuf/proto"
format "github.com/ipfs/go-ipld-format"
mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -79,7 +77,6 @@ func startNewStateAndWaitForBlock(t *testing.T, consensusReplayConfig *cfg.Confi
privValidator,
kvstore.NewApplication(),
blockDB,
mdutils.Mock(),
)
cs.SetLogger(logger)

Expand Down Expand Up @@ -132,7 +129,8 @@ func TestWALCrash(t *testing.T) {
heightToStop int64
}{
{"empty block",
func(stateDB dbm.DB, cs *State, ctx context.Context) {},
func(stateDB dbm.DB, cs *State, ctx context.Context) {
},
1},
{"many non-empty blocks",
func(stateDB dbm.DB, cs *State, ctx context.Context) {
Expand Down Expand Up @@ -174,7 +172,6 @@ LOOP:
privValidator,
kvstore.NewApplication(),
blockDB,
mdutils.Mock(),
)
cs.SetLogger(logger)

Expand Down Expand Up @@ -1182,17 +1179,16 @@ func stateAndStore(
// mock block store

type mockBlockStore struct {
config *cfg.Config
params tmproto.ConsensusParams
chain []*types.Block
commits []*types.Commit
base int64
ipfsDagAPI format.DAGService
config *cfg.Config
params tmproto.ConsensusParams
chain []*types.Block
commits []*types.Commit
base int64
}

// TODO: NewBlockStore(db.NewMemDB) ...
func newMockBlockStore(config *cfg.Config, params tmproto.ConsensusParams) *mockBlockStore {
return &mockBlockStore{config, params, nil, nil, 0, mdutils.Mock()}
return &mockBlockStore{config, params, nil, nil, 0}
}

func (bs *mockBlockStore) Height() int64 { return int64(len(bs.chain)) }
Expand Down
9 changes: 0 additions & 9 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"time"

"github.com/gogo/protobuf/proto"
format "github.com/ipfs/go-ipld-format"
"github.com/libp2p/go-libp2p-core/routing"

cfg "github.com/celestiaorg/celestia-core/config"
cstypes "github.com/celestiaorg/celestia-core/consensus/types"
Expand Down Expand Up @@ -94,9 +92,6 @@ type State struct {
// store blocks and commits
blockStore sm.BlockStore

dag format.DAGService
croute routing.ContentRouting

// create and execute blocks
blockExec *sm.BlockExecutor

Expand Down Expand Up @@ -164,17 +159,13 @@ func NewState(
blockExec *sm.BlockExecutor,
blockStore sm.BlockStore,
txNotifier txNotifier,
dag format.DAGService,
croute routing.ContentRouting,
evpool evidencePool,
options ...StateOption,
) *State {
cs := &State{
config: config,
blockExec: blockExec,
blockStore: blockStore,
dag: dag,
croute: croute,
txNotifier: txNotifier,
peerMsgQueue: make(chan msgInfo, msgQueueSize),
internalMsgQueue: make(chan msgInfo, msgQueueSize),
Expand Down
Loading

0 comments on commit 225ee8b

Please sign in to comment.