From aabfd03cd90bda84766164b7229d757de993ee82 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Tue, 25 May 2021 21:58:46 -0500 Subject: [PATCH 01/25] add the ipfs object to the blockstore and remove if from the state object --- blockchain/v0/reactor_test.go | 4 +++- consensus/byzantine_test.go | 6 ++++-- consensus/common_test.go | 19 +++++++++---------- consensus/mempool_test.go | 17 +++++++---------- consensus/reactor_test.go | 3 +-- consensus/replay_file.go | 4 +++- consensus/replay_test.go | 21 +++++++++++++++------ consensus/state.go | 12 +----------- consensus/state_test.go | 9 +++------ consensus/wal_test.go | 3 +-- evidence/pool_test.go | 5 ++++- node/node.go | 18 +++++++++--------- node/node_test.go | 3 ++- rpc/core/blocks_test.go | 2 ++ state/services.go | 3 +++ store/store.go | 18 ++++++++++++++---- store/store_test.go | 20 +++++++++++++------- 17 files changed, 94 insertions(+), 73 deletions(-) diff --git a/blockchain/v0/reactor_test.go b/blockchain/v0/reactor_test.go index ffa842cc33..bed0295360 100644 --- a/blockchain/v0/reactor_test.go +++ b/blockchain/v0/reactor_test.go @@ -13,6 +13,7 @@ import ( abci "github.com/lazyledger/lazyledger-core/abci/types" cfg "github.com/lazyledger/lazyledger-core/config" + "github.com/lazyledger/lazyledger-core/ipfs" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" "github.com/lazyledger/lazyledger-core/mempool/mock" @@ -71,7 +72,8 @@ func newBlockchainReactor( blockDB := memdb.NewDB() stateDB := memdb.NewDB() stateStore := sm.NewStore(stateDB) - blockStore := store.NewBlockStore(blockDB) + ipfsAPI, _, _ := ipfs.Mock()() + blockStore := store.NewBlockStore(blockDB, ipfsAPI) state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc) if err != nil { diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 1561c7af92..9abd87ab09 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -15,6 +15,7 @@ import ( abcicli "github.com/lazyledger/lazyledger-core/abci/client" abci "github.com/lazyledger/lazyledger-core/abci/types" "github.com/lazyledger/lazyledger-core/evidence" + "github.com/lazyledger/lazyledger-core/ipfs" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" "github.com/lazyledger/lazyledger-core/libs/service" @@ -42,6 +43,8 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { genDoc, privVals := randGenesisDoc(nValidators, false, 30) css := make([]*State, nValidators) + ipfsAPI, _, _ := ipfs.Mock()() + for i := 0; i < nValidators; i++ { logger := consensusLogger().With("test", "byzantine", "validator", i) stateDB := memdb.NewDB() // each state needs its own db @@ -55,7 +58,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { app.InitChain(abci.RequestInitChain{Validators: vals}) blockDB := memdb.NewDB() - blockStore := store.NewBlockStore(blockDB) + blockStore := store.NewBlockStore(blockDB, ipfsAPI) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -91,7 +94,6 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { cs.SetTimeoutTicker(tickerFunc()) cs.SetLogger(logger) - cs.SetIPFSApi(ipfsTestAPI) css[i] = cs } diff --git a/consensus/common_test.go b/consensus/common_test.go index b2ff6b834d..c87c88ee29 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -370,9 +370,9 @@ func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message { //------------------------------------------------------------------------------- // consensus states -func newState(state sm.State, pv types.PrivValidator, app abci.Application) *State { +func newState(state sm.State, pv types.PrivValidator, app abci.Application, ipfsAPI iface.CoreAPI) *State { config := cfg.ResetTestRoot("consensus_state_test") - return newStateWithConfig(config, state, pv, app) + return newStateWithConfig(config, state, pv, app, ipfsAPI) } func newStateWithConfig( @@ -380,9 +380,10 @@ func newStateWithConfig( state sm.State, pv types.PrivValidator, app abci.Application, + ipfsAPI iface.CoreAPI, ) *State { blockDB := memdb.NewDB() - return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB) + return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB, ipfsAPI) } func newStateWithConfigAndBlockStore( @@ -391,9 +392,10 @@ func newStateWithConfigAndBlockStore( pv types.PrivValidator, app abci.Application, blockDB dbm.DB, + ipfsAPI iface.CoreAPI, ) *State { // Get BlockStore - blockStore := store.NewBlockStore(blockDB) + blockStore := store.NewBlockStore(blockDB, ipfsAPI) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -449,8 +451,7 @@ func randState(nValidators int) (*State, []*validatorStub) { vss := make([]*validatorStub, nValidators) - cs := newState(state, privVals[0], counter.NewApplication(true)) - cs.SetIPFSApi(ipfsTestAPI) + cs := newState(state, privVals[0], counter.NewApplication(true), ipfsTestAPI) for i := 0; i < nValidators; i++ { vss[i] = newValidatorStub(privVals[i], int32(i)) @@ -723,10 +724,9 @@ func randConsensusNet( vals := types.TM2PB.ValidatorUpdates(state.Validators) app.InitChain(abci.RequestInitChain{Validators: vals}) - css[i] = newStateWithConfigAndBlockStore(thisConfig, state, privVals[i], app, stateDB) + css[i] = newStateWithConfigAndBlockStore(thisConfig, state, privVals[i], app, stateDB, ipfsTestAPI) css[i].SetTimeoutTicker(tickerFunc()) css[i].SetLogger(logger.With("validator", i, "module", "consensus")) - css[i].SetIPFSApi(ipfsTestAPI) } return css, func() { for _, dir := range configRootDirs { @@ -787,10 +787,9 @@ 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) + css[i] = newStateWithConfig(thisConfig, state, privVal, app, ipfsTestAPI) css[i].SetTimeoutTicker(tickerFunc()) css[i].SetLogger(logger.With("validator", i, "module", "consensus")) - css[i].SetIPFSApi(ipfsTestAPI) } return css, genDoc, peer0Config, func() { for _, dir := range configRootDirs { diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index 2e527788f2..efeeb201f2 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -12,6 +12,7 @@ import ( "github.com/lazyledger/lazyledger-core/abci/example/code" abci "github.com/lazyledger/lazyledger-core/abci/types" + "github.com/lazyledger/lazyledger-core/ipfs" "github.com/lazyledger/lazyledger-core/libs/db/memdb" mempl "github.com/lazyledger/lazyledger-core/mempool" sm "github.com/lazyledger/lazyledger-core/state" @@ -29,8 +30,8 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) { config.Consensus.CreateEmptyBlocks = false state, privVals := randGenesisState(1, false, 10) - cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication()) - cs.SetIPFSApi(ipfsTestAPI) + ipfsAPI, _, _ := ipfs.Mock()() + cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsAPI) assertMempool(cs.txNotifier).EnableTxsAvailable() height, round := cs.Height, cs.Round newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock) @@ -50,8 +51,7 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) { config.Consensus.CreateEmptyBlocksInterval = ensureTimeout state, privVals := randGenesisState(1, false, 10) - cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication()) - cs.SetIPFSApi(ipfsTestAPI) + cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsTestAPI) assertMempool(cs.txNotifier).EnableTxsAvailable() @@ -69,8 +69,7 @@ func TestMempoolProgressInHigherRound(t *testing.T) { config.Consensus.CreateEmptyBlocks = false state, privVals := randGenesisState(1, false, 10) - cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication()) - cs.SetIPFSApi(ipfsTestAPI) + cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsTestAPI) assertMempool(cs.txNotifier).EnableTxsAvailable() height, round := cs.Height, cs.Round @@ -120,8 +119,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) { blockDB := memdb.NewDB() stateStore := sm.NewStore(blockDB) - cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB) - cs.SetIPFSApi(ipfsTestAPI) + cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB, ipfsTestAPI) err := stateStore.Save(state) require.NoError(t, err) newBlockHeaderCh := subscribe(cs.eventBus, types.EventQueryNewBlockHeader) @@ -147,8 +145,7 @@ func TestMempoolRmBadTx(t *testing.T) { blockDB := memdb.NewDB() stateStore := sm.NewStore(blockDB) - cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB) - cs.SetIPFSApi(ipfsTestAPI) + cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB, ipfsTestAPI) err := stateStore.Save(state) require.NoError(t, err) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 4fb7f156f6..c6ebf9c1d5 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -154,7 +154,7 @@ func TestReactorWithEvidence(t *testing.T) { // css[i] = newStateWithConfig(thisConfig, state, privVals[i], app) blockDB := memdb.NewDB() - blockStore := store.NewBlockStore(blockDB) + blockStore := store.NewBlockStore(blockDB, ipfsTestAPI) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -185,7 +185,6 @@ func TestReactorWithEvidence(t *testing.T) { cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool2) cs.SetLogger(log.TestingLogger().With("module", "consensus")) cs.SetPrivValidator(pv) - cs.SetIPFSApi(ipfsTestAPI) eventBus := types.NewEventBus() eventBus.SetLogger(log.TestingLogger().With("module", "events")) diff --git a/consensus/replay_file.go b/consensus/replay_file.go index af2a38c4c2..c40ae3ece7 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -11,6 +11,7 @@ import ( "strings" cfg "github.com/lazyledger/lazyledger-core/config" + "github.com/lazyledger/lazyledger-core/ipfs" "github.com/lazyledger/lazyledger-core/libs/db/badgerdb" "github.com/lazyledger/lazyledger-core/libs/log" tmos "github.com/lazyledger/lazyledger-core/libs/os" @@ -288,7 +289,8 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo if err != nil { tmos.Exit(err.Error()) } - blockStore := store.NewBlockStore(blockStoreDB) + ipfsAPI, _, _ := ipfs.Mock()() + blockStore := store.NewBlockStore(blockStoreDB, ipfsAPI) // Get State stateDB, err := badgerdb.NewDB("state", config.DBDir()) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index db94063a57..830e66950a 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/gogo/protobuf/proto" + iface "github.com/ipfs/interface-go-ipfs-core" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -22,6 +23,7 @@ import ( cfg "github.com/lazyledger/lazyledger-core/config" "github.com/lazyledger/lazyledger-core/crypto" cryptoenc "github.com/lazyledger/lazyledger-core/crypto/encoding" + "github.com/lazyledger/lazyledger-core/ipfs" dbm "github.com/lazyledger/lazyledger-core/libs/db" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" @@ -79,9 +81,9 @@ func startNewStateAndWaitForBlock(t *testing.T, consensusReplayConfig *cfg.Confi privValidator, kvstore.NewApplication(), blockDB, + ipfsTestAPI, ) cs.SetLogger(logger) - cs.SetIPFSApi(ipfsTestAPI) bytes, _ := ioutil.ReadFile(cs.config.WalFile()) t.Logf("====== WAL: \n\r%X\n", bytes) @@ -132,13 +134,10 @@ func TestWALCrash(t *testing.T) { heightToStop int64 }{ {"empty block", - func(stateDB dbm.DB, cs *State, ctx context.Context) { - cs.SetIPFSApi(ipfsTestAPI) - }, + func(stateDB dbm.DB, cs *State, ctx context.Context) {}, 1}, {"many non-empty blocks", func(stateDB dbm.DB, cs *State, ctx context.Context) { - cs.SetIPFSApi(ipfsTestAPI) go sendTxs(ctx, cs) }, 3}, @@ -177,6 +176,7 @@ LOOP: privValidator, kvstore.NewApplication(), blockDB, + ipfsTestAPI, ) cs.SetLogger(logger) @@ -1189,11 +1189,16 @@ type mockBlockStore struct { chain []*types.Block commits []*types.Commit base int64 + ipfsAPI iface.CoreAPI } // TODO: NewBlockStore(db.NewMemDB) ... func newMockBlockStore(config *cfg.Config, params tmproto.ConsensusParams) *mockBlockStore { - return &mockBlockStore{config, params, nil, nil, 0} + api, _, err := ipfs.Mock()() + if err != nil { + panic("failure to create mock IPFS object") + } + return &mockBlockStore{config, params, nil, nil, 0, api} } func (bs *mockBlockStore) Height() int64 { return int64(len(bs.chain)) } @@ -1232,6 +1237,10 @@ func (bs *mockBlockStore) PruneBlocks(height int64) (uint64, error) { return pruned, nil } +func (bs *mockBlockStore) IpfsAPI() iface.CoreAPI { + return bs.ipfsAPI +} + //--------------------------------------- // Test handshake/init chain diff --git a/consensus/state.go b/consensus/state.go index 93b226cc21..48eedfc64b 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -12,7 +12,6 @@ import ( "time" "github.com/gogo/protobuf/proto" - 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" @@ -94,8 +93,6 @@ type State struct { // store blocks and commits blockStore sm.BlockStore - ipfs ipface.CoreAPI - // create and execute blocks blockExec *sm.BlockExecutor @@ -207,13 +204,6 @@ 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 @@ -1126,7 +1116,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) { defer cancel() cs.Logger.Info("Putting Block to ipfs", "height", block.Height) // TODO: post data to IPFS in a goroutine - err = ipld.PutBlock(ctx, cs.ipfs.Dag(), block) + err = ipld.PutBlock(ctx, cs.blockStore.IpfsAPI().Dag(), block) if err != nil { // If PutBlock fails we will be the only node that has the data // this means something is seriously wrong and we can not recover diff --git a/consensus/state_test.go b/consensus/state_test.go index 77fab5e6b5..7af9f54411 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -639,8 +639,7 @@ func TestStateLockPOLRelock(t *testing.T) { signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal - cs2 := newState(cs1.state, vs2, counter.NewApplication(true)) - cs2.SetIPFSApi(ipfsTestAPI) + cs2 := newState(cs1.state, vs2, counter.NewApplication(true), ipfsTestAPI) prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") @@ -826,8 +825,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal - cs2 := newState(cs1.state, vs2, counter.NewApplication(true)) - cs2.SetIPFSApi(ipfsTestAPI) + cs2 := newState(cs1.state, vs2, counter.NewApplication(true), ipfsTestAPI) prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") @@ -871,8 +869,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal - cs3 := newState(cs1.state, vs3, counter.NewApplication(true)) - cs3.SetIPFSApi(ipfsTestAPI) + cs3 := newState(cs1.state, vs3, counter.NewApplication(true), ipfsTestAPI) prop, propBlock = decideProposal(cs3, vs3, vs3.Height, vs3.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") diff --git a/consensus/wal_test.go b/consensus/wal_test.go index 40d49c0d1e..53903aabef 100644 --- a/consensus/wal_test.go +++ b/consensus/wal_test.go @@ -311,7 +311,7 @@ func walGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { t.Error(err) } - blockStore := store.NewBlockStore(blockStoreDB) + blockStore := store.NewBlockStore(blockStoreDB, ipfsTestAPI) proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app)) proxyApp.SetLogger(logger.With("module", "proxy")) @@ -339,7 +339,6 @@ func walGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) require.NoError(t, err) consensusState := NewState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool) - consensusState.SetIPFSApi(ipfsTestAPI) consensusState.SetLogger(logger) consensusState.SetEventBus(eventBus) if privValidator != nil && privValidator != (*privval.FilePV)(nil) { diff --git a/evidence/pool_test.go b/evidence/pool_test.go index 2f8af65eb6..14464b87bb 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -11,6 +11,7 @@ import ( "github.com/lazyledger/lazyledger-core/evidence" "github.com/lazyledger/lazyledger-core/evidence/mocks" + "github.com/lazyledger/lazyledger-core/ipfs" dbm "github.com/lazyledger/lazyledger-core/libs/db" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" @@ -395,7 +396,9 @@ func initializeValidatorState(privVal types.PrivValidator, height int64) sm.Stor // initializeBlockStore creates a block storage and populates it w/ a dummy // block at +height+. func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) *store.BlockStore { - blockStore := store.NewBlockStore(db) + ipfsAPI, _, _ := ipfs.Mock()() + + blockStore := store.NewBlockStore(db, ipfsAPI) for i := int64(1); i <= state.LastBlockHeight; i++ { lastCommit := makeCommit(i-1, valAddr) diff --git a/node/node.go b/node/node.go index 35e6938538..4d9e490bc5 100644 --- a/node/node.go +++ b/node/node.go @@ -12,6 +12,7 @@ import ( "strings" "time" + iface "github.com/ipfs/interface-go-ipfs-core" ipface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -219,13 +220,13 @@ type Node struct { ipfsClose io.Closer } -func initDBs(config *cfg.Config, dbProvider DBProvider) (blockStore *store.BlockStore, stateDB dbm.DB, err error) { +func initDBs(config *cfg.Config, dbProvider DBProvider, ipfsAPI iface.CoreAPI) (blockStore *store.BlockStore, stateDB dbm.DB, err error) { var blockStoreDB dbm.DB blockStoreDB, err = dbProvider(&DBContext{"blockstore", config}) if err != nil { return } - blockStore = store.NewBlockStore(blockStoreDB) + blockStore = store.NewBlockStore(blockStoreDB, ipfsAPI) stateDB, err = dbProvider(&DBContext{"state", config}) if err != nil { @@ -407,7 +408,6 @@ func createConsensusReactor(config *cfg.Config, evidencePool, cs.StateMetrics(csMetrics), ) - consensusState.SetIPFSApi(ipfs) consensusState.SetLogger(consensusLogger) if privValidator != nil { consensusState.SetPrivValidator(privValidator) @@ -638,7 +638,12 @@ func NewNode(config *cfg.Config, logger log.Logger, options ...Option) (*Node, error) { - blockStore, stateDB, err := initDBs(config, dbProvider) + ipfs, ipfsclose, err := ipfsProvider() + if err != nil { + return nil, err + } + + blockStore, stateDB, err := initDBs(config, dbProvider, ipfs) if err != nil { return nil, err } @@ -737,11 +742,6 @@ func NewNode(config *cfg.Config, sm.BlockExecutorWithMetrics(smMetrics), ) - ipfs, ipfsclose, err := ipfsProvider() - if err != nil { - return nil, err - } - // Make BlockchainReactor. Don't start fast sync if we're doing a state sync first. bcReactor, err := createBlockchainReactor(config, state, blockExec, blockStore, fastSync && !stateSync, logger) if err != nil { diff --git a/node/node_test.go b/node/node_test.go index 8fde86ae87..de171f95cf 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -283,7 +283,8 @@ func TestCreateProposalBlock(t *testing.T) { // Make EvidencePool evidenceDB := memdb.NewDB() - blockStore := store.NewBlockStore(memdb.NewDB()) + ipfsAPI, _, _ := ipfs.Mock()() + blockStore := store.NewBlockStore(memdb.NewDB(), ipfsAPI) evidencePool, err := evidence.NewPool(evidenceDB, stateStore, blockStore) require.NoError(t, err) evidencePool.SetLogger(logger) diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index 996c83c43e..8285742a39 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + iface "github.com/ipfs/interface-go-ipfs-core" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -131,3 +132,4 @@ func (mockBlockStore) LoadSeenCommit(height int64) *types.Commit { retur func (mockBlockStore) PruneBlocks(height int64) (uint64, error) { return 0, nil } func (mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) { } +func (mockBlockStore) IpfsAPI() iface.CoreAPI { return nil } diff --git a/state/services.go b/state/services.go index eef7dc854d..3bf940114a 100644 --- a/state/services.go +++ b/state/services.go @@ -1,6 +1,7 @@ package state import ( + iface "github.com/ipfs/interface-go-ipfs-core" "github.com/lazyledger/lazyledger-core/types" ) @@ -31,6 +32,8 @@ type BlockStore interface { LoadBlockCommit(height int64) *types.Commit LoadSeenCommit(height int64) *types.Commit + + IpfsAPI() iface.CoreAPI } //----------------------------------------------------------------------------- diff --git a/store/store.go b/store/store.go index fa5dca3421..a57567282f 100644 --- a/store/store.go +++ b/store/store.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/gogo/protobuf/proto" + iface "github.com/ipfs/interface-go-ipfs-core" dbm "github.com/lazyledger/lazyledger-core/libs/db" tmsync "github.com/lazyledger/lazyledger-core/libs/sync" @@ -41,16 +42,19 @@ type BlockStore struct { mtx tmsync.RWMutex base int64 height int64 + + ipfsAPI iface.CoreAPI } // NewBlockStore returns a new BlockStore with the given DB, // initialized to the last height that was committed to the DB. -func NewBlockStore(db dbm.DB) *BlockStore { +func NewBlockStore(db dbm.DB, ipfsAPI iface.CoreAPI) *BlockStore { bs := LoadBlockStoreState(db) return &BlockStore{ - base: bs.Base, - height: bs.Height, - db: db, + base: bs.Base, + height: bs.Height, + db: db, + ipfsAPI: ipfsAPI, } } @@ -424,6 +428,12 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err return bs.db.Set(calcSeenCommitKey(height), seenCommitBytes) } +// IpfsAPI returns the ipfs api object of the BlockStore. Fullfills the +// state.BlockStore interface. +func (bs *BlockStore) IpfsAPI() iface.CoreAPI { + return bs.ipfsAPI +} + //----------------------------------------------------------------------------- func calcBlockMetaKey(height int64) []byte { diff --git a/store/store_test.go b/store/store_test.go index 1f45a018ec..b96ed7cf8f 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -16,6 +16,7 @@ import ( cfg "github.com/lazyledger/lazyledger-core/config" "github.com/lazyledger/lazyledger-core/crypto" + "github.com/lazyledger/lazyledger-core/ipfs" dbm "github.com/lazyledger/lazyledger-core/libs/db" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" @@ -73,7 +74,8 @@ func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFu if err != nil { panic(fmt.Errorf("error constructing state from genesis file: %w", err)) } - return state, NewBlockStore(blockDB), func() { os.RemoveAll(config.RootDir) } + api, _, _ := ipfs.Mock()() + return state, NewBlockStore(blockDB, api), func() { os.RemoveAll(config.RootDir) } } func TestLoadBlockStoreState(t *testing.T) { @@ -105,7 +107,8 @@ func TestNewBlockStore(t *testing.T) { bz, _ := proto.Marshal(&bss) err := db.Set(blockStoreKey, bz) require.NoError(t, err) - bs := NewBlockStore(db) + ipfsAPI, _, _ := ipfs.Mock()() + bs := NewBlockStore(db, ipfsAPI) require.Equal(t, int64(100), bs.Base(), "failed to properly parse blockstore") require.Equal(t, int64(10000), bs.Height(), "failed to properly parse blockstore") @@ -123,7 +126,7 @@ func TestNewBlockStore(t *testing.T) { _, _, panicErr := doFn(func() (interface{}, error) { err := db.Set(blockStoreKey, tt.data) require.NoError(t, err) - _ = NewBlockStore(db) + _ = NewBlockStore(db, ipfsAPI) return nil, nil }) require.NotNil(t, panicErr, "#%d panicCauser: %q expected a panic", i, tt.data) @@ -132,13 +135,14 @@ func TestNewBlockStore(t *testing.T) { err = db.Set(blockStoreKey, []byte{}) require.NoError(t, err) - bs = NewBlockStore(db) + bs = NewBlockStore(db, ipfsAPI) assert.Equal(t, bs.Height(), int64(0), "expecting empty bytes to be unmarshaled alright") } func freshBlockStore() (*BlockStore, dbm.DB) { db := memdb.NewDB() - return NewBlockStore(db), db + ipfsAPI, _, _ := ipfs.Mock()() + return NewBlockStore(db, ipfsAPI), db } var ( @@ -380,7 +384,8 @@ func TestLoadBaseMeta(t *testing.T) { stateStore := sm.NewStore(memdb.NewDB()) state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile()) require.NoError(t, err) - bs := NewBlockStore(memdb.NewDB()) + ipfsAPI, _, _ := ipfs.Mock()() + bs := NewBlockStore(memdb.NewDB(), ipfsAPI) for h := int64(1); h <= 10; h++ { block := makeBlock(h, state, new(types.Commit)) @@ -436,8 +441,9 @@ func TestPruneBlocks(t *testing.T) { stateStore := sm.NewStore(memdb.NewDB()) state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile()) require.NoError(t, err) + ipfsAPI, _, _ := ipfs.Mock()() db := memdb.NewDB() - bs := NewBlockStore(db) + bs := NewBlockStore(db, ipfsAPI) assert.EqualValues(t, 0, bs.Base()) assert.EqualValues(t, 0, bs.Height()) assert.EqualValues(t, 0, bs.Size()) From 5c63080df71f4d1ff7a2644dedfd41f4ad5859c9 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Tue, 25 May 2021 22:09:28 -0500 Subject: [PATCH 02/25] fix linter's complaints --- node/node.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/node/node.go b/node/node.go index 4d9e490bc5..56562fd87c 100644 --- a/node/node.go +++ b/node/node.go @@ -13,7 +13,6 @@ import ( "time" iface "github.com/ipfs/interface-go-ipfs-core" - ipface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rs/cors" @@ -216,11 +215,15 @@ type Node struct { indexerService *txindex.IndexerService prometheusSrv *http.Server - ipfsAPI ipface.CoreAPI + ipfsAPI iface.CoreAPI ipfsClose io.Closer } -func initDBs(config *cfg.Config, dbProvider DBProvider, ipfsAPI iface.CoreAPI) (blockStore *store.BlockStore, stateDB dbm.DB, err error) { +func initDBs( + config *cfg.Config, + dbProvider DBProvider, + ipfsAPI iface.CoreAPI, +) (blockStore *store.BlockStore, stateDB dbm.DB, err error) { var blockStoreDB dbm.DB blockStoreDB, err = dbProvider(&DBContext{"blockstore", config}) if err != nil { @@ -396,7 +399,7 @@ func createConsensusReactor(config *cfg.Config, csMetrics *cs.Metrics, waitSync bool, eventBus *types.EventBus, - ipfs ipface.CoreAPI, + ipfs iface.CoreAPI, consensusLogger log.Logger) (*cs.Reactor, *cs.State) { consensusState := cs.NewState( From f0a8a3475923e7a96f6e65fb896e612fcee36991 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Tue, 25 May 2021 22:39:55 -0500 Subject: [PATCH 03/25] increase TestReactorSelectiveBroadcast sleep times --- evidence/reactor_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index f533621534..147dbe9b96 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -130,7 +130,7 @@ func TestReactorsGossipNoCommittedEvidence(t *testing.T) { pools[0].Update(state, evList) require.EqualValues(t, uint32(0), pools[0].Size()) - time.Sleep(100 * time.Millisecond) + time.Sleep(200 * time.Millisecond) peer := reactors[0].Switch.Peers().List()[0] ps := peerState{height - 2} @@ -141,7 +141,7 @@ func TestReactorsGossipNoCommittedEvidence(t *testing.T) { peer.Set(types.PeerStateKey, ps) // wait to see that no evidence comes through - time.Sleep(300 * time.Millisecond) + time.Sleep(600 * time.Millisecond) // the second pool should not have received any evidence because it has already been committed assert.Equal(t, uint32(0), pools[1].Size(), "second reactor should not have received evidence") @@ -157,7 +157,7 @@ func TestReactorsGossipNoCommittedEvidence(t *testing.T) { } // wait to see that only one evidence is sent - time.Sleep(300 * time.Millisecond) + time.Sleep(600 * time.Millisecond) // the second pool should only have received the first evidence because it is behind peerEv, _ := pools[1].PendingEvidence(10000) @@ -178,7 +178,7 @@ func TestReactorsGossipNoCommittedEvidence(t *testing.T) { peer.Set(types.PeerStateKey, ps) // wait to see that only two evidence is sent - time.Sleep(300 * time.Millisecond) + time.Sleep(600 * time.Millisecond) peerEv, _ = pools[1].PendingEvidence(1000) assert.EqualValues(t, []types.Evidence{evList[0], evList[1]}, peerEv) From e32ce9dfbd75b5c3bf50be5d70077cbd122795da Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Tue, 25 May 2021 22:47:17 -0500 Subject: [PATCH 04/25] increase ensureTimeout to 4 seconds --- consensus/common_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/common_test.go b/consensus/common_test.go index c87c88ee29..1b1bc6efa4 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -54,7 +54,7 @@ type cleanupFunc func() var ( config *cfg.Config // NOTE: must be reset for each _test.go file consensusReplayConfig *cfg.Config - ensureTimeout = 2 * time.Second + ensureTimeout = 4 * time.Second ipfsTestAPI iface.CoreAPI ipfsCloser io.Closer From 0c06595e141fc4d08cfc1709fc1c11a1ee089212 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 13:57:34 -0500 Subject: [PATCH 05/25] only use the dag api object instead of the entire ipfs api object --- blockchain/v0/reactor_test.go | 2 +- consensus/byzantine_test.go | 2 +- consensus/common_test.go | 18 +++++++++--------- consensus/mempool_test.go | 10 +++++----- consensus/reactor_test.go | 2 +- consensus/replay_file.go | 2 +- consensus/replay_test.go | 22 +++++++++++----------- consensus/state.go | 2 +- consensus/state_test.go | 6 +++--- consensus/wal_test.go | 2 +- evidence/pool_test.go | 2 +- node/node.go | 2 +- node/node_test.go | 2 +- rpc/core/blocks_test.go | 2 +- state/services.go | 2 +- store/store.go | 16 ++++++++-------- store/store_test.go | 14 +++++++------- 17 files changed, 54 insertions(+), 54 deletions(-) diff --git a/blockchain/v0/reactor_test.go b/blockchain/v0/reactor_test.go index bed0295360..8ccd8aa9d9 100644 --- a/blockchain/v0/reactor_test.go +++ b/blockchain/v0/reactor_test.go @@ -73,7 +73,7 @@ func newBlockchainReactor( stateDB := memdb.NewDB() stateStore := sm.NewStore(stateDB) ipfsAPI, _, _ := ipfs.Mock()() - blockStore := store.NewBlockStore(blockDB, ipfsAPI) + blockStore := store.NewBlockStore(blockDB, ipfsAPI.Dag()) state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc) if err != nil { diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 9abd87ab09..38397e87b3 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -58,7 +58,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { app.InitChain(abci.RequestInitChain{Validators: vals}) blockDB := memdb.NewDB() - blockStore := store.NewBlockStore(blockDB, ipfsAPI) + blockStore := store.NewBlockStore(blockDB, ipfsAPI.Dag()) // one for mempool, one for consensus mtx := new(tmsync.Mutex) diff --git a/consensus/common_test.go b/consensus/common_test.go index 1b1bc6efa4..c17521c6a5 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -370,9 +370,9 @@ func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message { //------------------------------------------------------------------------------- // consensus states -func newState(state sm.State, pv types.PrivValidator, app abci.Application, ipfsAPI iface.CoreAPI) *State { +func newState(state sm.State, pv types.PrivValidator, app abci.Application, ipfsDagAPI iface.APIDagService) *State { config := cfg.ResetTestRoot("consensus_state_test") - return newStateWithConfig(config, state, pv, app, ipfsAPI) + return newStateWithConfig(config, state, pv, app, ipfsDagAPI) } func newStateWithConfig( @@ -380,10 +380,10 @@ func newStateWithConfig( state sm.State, pv types.PrivValidator, app abci.Application, - ipfsAPI iface.CoreAPI, + ipfsDagAPI iface.APIDagService, ) *State { blockDB := memdb.NewDB() - return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB, ipfsAPI) + return newStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB, ipfsDagAPI) } func newStateWithConfigAndBlockStore( @@ -392,10 +392,10 @@ func newStateWithConfigAndBlockStore( pv types.PrivValidator, app abci.Application, blockDB dbm.DB, - ipfsAPI iface.CoreAPI, + ipfsDagAPI iface.APIDagService, ) *State { // Get BlockStore - blockStore := store.NewBlockStore(blockDB, ipfsAPI) + blockStore := store.NewBlockStore(blockDB, ipfsDagAPI) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -451,7 +451,7 @@ func randState(nValidators int) (*State, []*validatorStub) { vss := make([]*validatorStub, nValidators) - cs := newState(state, privVals[0], counter.NewApplication(true), ipfsTestAPI) + cs := newState(state, privVals[0], counter.NewApplication(true), ipfsTestAPI.Dag()) for i := 0; i < nValidators; i++ { vss[i] = newValidatorStub(privVals[i], int32(i)) @@ -724,7 +724,7 @@ func randConsensusNet( vals := types.TM2PB.ValidatorUpdates(state.Validators) app.InitChain(abci.RequestInitChain{Validators: vals}) - css[i] = newStateWithConfigAndBlockStore(thisConfig, state, privVals[i], app, stateDB, ipfsTestAPI) + css[i] = newStateWithConfigAndBlockStore(thisConfig, state, privVals[i], app, stateDB, ipfsTestAPI.Dag()) css[i].SetTimeoutTicker(tickerFunc()) css[i].SetLogger(logger.With("validator", i, "module", "consensus")) } @@ -787,7 +787,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, ipfsTestAPI) + css[i] = newStateWithConfig(thisConfig, state, privVal, app, ipfsTestAPI.Dag()) css[i].SetTimeoutTicker(tickerFunc()) css[i].SetLogger(logger.With("validator", i, "module", "consensus")) } diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index efeeb201f2..7198c2977b 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -31,7 +31,7 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) { config.Consensus.CreateEmptyBlocks = false state, privVals := randGenesisState(1, false, 10) ipfsAPI, _, _ := ipfs.Mock()() - cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsAPI) + cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsAPI.Dag()) assertMempool(cs.txNotifier).EnableTxsAvailable() height, round := cs.Height, cs.Round newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock) @@ -51,7 +51,7 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) { config.Consensus.CreateEmptyBlocksInterval = ensureTimeout state, privVals := randGenesisState(1, false, 10) - cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsTestAPI) + cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsTestAPI.Dag()) assertMempool(cs.txNotifier).EnableTxsAvailable() @@ -69,7 +69,7 @@ func TestMempoolProgressInHigherRound(t *testing.T) { config.Consensus.CreateEmptyBlocks = false state, privVals := randGenesisState(1, false, 10) - cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsTestAPI) + cs := newStateWithConfig(config, state, privVals[0], NewCounterApplication(), ipfsTestAPI.Dag()) assertMempool(cs.txNotifier).EnableTxsAvailable() height, round := cs.Height, cs.Round @@ -119,7 +119,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) { blockDB := memdb.NewDB() stateStore := sm.NewStore(blockDB) - cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB, ipfsTestAPI) + cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB, ipfsTestAPI.Dag()) err := stateStore.Save(state) require.NoError(t, err) newBlockHeaderCh := subscribe(cs.eventBus, types.EventQueryNewBlockHeader) @@ -145,7 +145,7 @@ func TestMempoolRmBadTx(t *testing.T) { blockDB := memdb.NewDB() stateStore := sm.NewStore(blockDB) - cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB, ipfsTestAPI) + cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB, ipfsTestAPI.Dag()) err := stateStore.Save(state) require.NoError(t, err) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index c6ebf9c1d5..0c50103094 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -154,7 +154,7 @@ func TestReactorWithEvidence(t *testing.T) { // css[i] = newStateWithConfig(thisConfig, state, privVals[i], app) blockDB := memdb.NewDB() - blockStore := store.NewBlockStore(blockDB, ipfsTestAPI) + blockStore := store.NewBlockStore(blockDB, ipfsTestAPI.Dag()) // one for mempool, one for consensus mtx := new(tmsync.Mutex) diff --git a/consensus/replay_file.go b/consensus/replay_file.go index c40ae3ece7..a34c6e343c 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -290,7 +290,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo tmos.Exit(err.Error()) } ipfsAPI, _, _ := ipfs.Mock()() - blockStore := store.NewBlockStore(blockStoreDB, ipfsAPI) + blockStore := store.NewBlockStore(blockStoreDB, ipfsAPI.Dag()) // Get State stateDB, err := badgerdb.NewDB("state", config.DBDir()) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 830e66950a..514ab8170d 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -81,7 +81,7 @@ func startNewStateAndWaitForBlock(t *testing.T, consensusReplayConfig *cfg.Confi privValidator, kvstore.NewApplication(), blockDB, - ipfsTestAPI, + ipfsTestAPI.Dag(), ) cs.SetLogger(logger) @@ -176,7 +176,7 @@ LOOP: privValidator, kvstore.NewApplication(), blockDB, - ipfsTestAPI, + ipfsTestAPI.Dag(), ) cs.SetLogger(logger) @@ -1184,12 +1184,12 @@ func stateAndStore( // mock block store type mockBlockStore struct { - config *cfg.Config - params tmproto.ConsensusParams - chain []*types.Block - commits []*types.Commit - base int64 - ipfsAPI iface.CoreAPI + config *cfg.Config + params tmproto.ConsensusParams + chain []*types.Block + commits []*types.Commit + base int64 + ipfsDagAPI iface.APIDagService } // TODO: NewBlockStore(db.NewMemDB) ... @@ -1198,7 +1198,7 @@ func newMockBlockStore(config *cfg.Config, params tmproto.ConsensusParams) *mock if err != nil { panic("failure to create mock IPFS object") } - return &mockBlockStore{config, params, nil, nil, 0, api} + return &mockBlockStore{config, params, nil, nil, 0, api.Dag()} } func (bs *mockBlockStore) Height() int64 { return int64(len(bs.chain)) } @@ -1237,8 +1237,8 @@ func (bs *mockBlockStore) PruneBlocks(height int64) (uint64, error) { return pruned, nil } -func (bs *mockBlockStore) IpfsAPI() iface.CoreAPI { - return bs.ipfsAPI +func (bs *mockBlockStore) IpfsDagAPI() iface.APIDagService { + return bs.ipfsDagAPI } //--------------------------------------- diff --git a/consensus/state.go b/consensus/state.go index 48eedfc64b..0cef19e2fc 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1116,7 +1116,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) { defer cancel() cs.Logger.Info("Putting Block to ipfs", "height", block.Height) // TODO: post data to IPFS in a goroutine - err = ipld.PutBlock(ctx, cs.blockStore.IpfsAPI().Dag(), block) + err = ipld.PutBlock(ctx, cs.blockStore.IpfsDagAPI(), block) if err != nil { // If PutBlock fails we will be the only node that has the data // this means something is seriously wrong and we can not recover diff --git a/consensus/state_test.go b/consensus/state_test.go index 7af9f54411..1cbf56066d 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -639,7 +639,7 @@ func TestStateLockPOLRelock(t *testing.T) { signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal - cs2 := newState(cs1.state, vs2, counter.NewApplication(true), ipfsTestAPI) + cs2 := newState(cs1.state, vs2, counter.NewApplication(true), ipfsTestAPI.Dag()) prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") @@ -825,7 +825,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal - cs2 := newState(cs1.state, vs2, counter.NewApplication(true), ipfsTestAPI) + cs2 := newState(cs1.state, vs2, counter.NewApplication(true), ipfsTestAPI.Dag()) prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") @@ -869,7 +869,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal - cs3 := newState(cs1.state, vs3, counter.NewApplication(true), ipfsTestAPI) + cs3 := newState(cs1.state, vs3, counter.NewApplication(true), ipfsTestAPI.Dag()) prop, propBlock = decideProposal(cs3, vs3, vs3.Height, vs3.Round+1) if prop == nil || propBlock == nil { t.Fatal("Failed to create proposal block with vs2") diff --git a/consensus/wal_test.go b/consensus/wal_test.go index 53903aabef..ed710d1faa 100644 --- a/consensus/wal_test.go +++ b/consensus/wal_test.go @@ -311,7 +311,7 @@ func walGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { t.Error(err) } - blockStore := store.NewBlockStore(blockStoreDB, ipfsTestAPI) + blockStore := store.NewBlockStore(blockStoreDB, ipfsTestAPI.Dag()) proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app)) proxyApp.SetLogger(logger.With("module", "proxy")) diff --git a/evidence/pool_test.go b/evidence/pool_test.go index 14464b87bb..b4992308cd 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -398,7 +398,7 @@ func initializeValidatorState(privVal types.PrivValidator, height int64) sm.Stor func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) *store.BlockStore { ipfsAPI, _, _ := ipfs.Mock()() - blockStore := store.NewBlockStore(db, ipfsAPI) + blockStore := store.NewBlockStore(db, ipfsAPI.Dag()) for i := int64(1); i <= state.LastBlockHeight; i++ { lastCommit := makeCommit(i-1, valAddr) diff --git a/node/node.go b/node/node.go index 56562fd87c..a33988a07a 100644 --- a/node/node.go +++ b/node/node.go @@ -229,7 +229,7 @@ func initDBs( if err != nil { return } - blockStore = store.NewBlockStore(blockStoreDB, ipfsAPI) + blockStore = store.NewBlockStore(blockStoreDB, ipfsAPI.Dag()) stateDB, err = dbProvider(&DBContext{"state", config}) if err != nil { diff --git a/node/node_test.go b/node/node_test.go index de171f95cf..0ad3749f20 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -284,7 +284,7 @@ func TestCreateProposalBlock(t *testing.T) { // Make EvidencePool evidenceDB := memdb.NewDB() ipfsAPI, _, _ := ipfs.Mock()() - blockStore := store.NewBlockStore(memdb.NewDB(), ipfsAPI) + blockStore := store.NewBlockStore(memdb.NewDB(), ipfsAPI.Dag()) evidencePool, err := evidence.NewPool(evidenceDB, stateStore, blockStore) require.NoError(t, err) evidencePool.SetLogger(logger) diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index 8285742a39..299edcee0a 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -132,4 +132,4 @@ func (mockBlockStore) LoadSeenCommit(height int64) *types.Commit { retur func (mockBlockStore) PruneBlocks(height int64) (uint64, error) { return 0, nil } func (mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) { } -func (mockBlockStore) IpfsAPI() iface.CoreAPI { return nil } +func (mockBlockStore) IpfsDagAPI() iface.APIDagService { return nil } diff --git a/state/services.go b/state/services.go index 3bf940114a..6b438f60bb 100644 --- a/state/services.go +++ b/state/services.go @@ -33,7 +33,7 @@ type BlockStore interface { LoadBlockCommit(height int64) *types.Commit LoadSeenCommit(height int64) *types.Commit - IpfsAPI() iface.CoreAPI + IpfsDagAPI() iface.APIDagService } //----------------------------------------------------------------------------- diff --git a/store/store.go b/store/store.go index a57567282f..8ae5333269 100644 --- a/store/store.go +++ b/store/store.go @@ -43,18 +43,18 @@ type BlockStore struct { base int64 height int64 - ipfsAPI iface.CoreAPI + ipfsDagAPI iface.APIDagService } // NewBlockStore returns a new BlockStore with the given DB, // initialized to the last height that was committed to the DB. -func NewBlockStore(db dbm.DB, ipfsAPI iface.CoreAPI) *BlockStore { +func NewBlockStore(db dbm.DB, dagAPI iface.APIDagService) *BlockStore { bs := LoadBlockStoreState(db) return &BlockStore{ - base: bs.Base, - height: bs.Height, - db: db, - ipfsAPI: ipfsAPI, + base: bs.Base, + height: bs.Height, + db: db, + ipfsDagAPI: dagAPI, } } @@ -430,8 +430,8 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err // IpfsAPI returns the ipfs api object of the BlockStore. Fullfills the // state.BlockStore interface. -func (bs *BlockStore) IpfsAPI() iface.CoreAPI { - return bs.ipfsAPI +func (bs *BlockStore) IpfsDagAPI() iface.APIDagService { + return bs.ipfsDagAPI } //----------------------------------------------------------------------------- diff --git a/store/store_test.go b/store/store_test.go index b96ed7cf8f..45f2d0e97c 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -75,7 +75,7 @@ func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFu panic(fmt.Errorf("error constructing state from genesis file: %w", err)) } api, _, _ := ipfs.Mock()() - return state, NewBlockStore(blockDB, api), func() { os.RemoveAll(config.RootDir) } + return state, NewBlockStore(blockDB, api.Dag()), func() { os.RemoveAll(config.RootDir) } } func TestLoadBlockStoreState(t *testing.T) { @@ -108,7 +108,7 @@ func TestNewBlockStore(t *testing.T) { err := db.Set(blockStoreKey, bz) require.NoError(t, err) ipfsAPI, _, _ := ipfs.Mock()() - bs := NewBlockStore(db, ipfsAPI) + bs := NewBlockStore(db, ipfsAPI.Dag()) require.Equal(t, int64(100), bs.Base(), "failed to properly parse blockstore") require.Equal(t, int64(10000), bs.Height(), "failed to properly parse blockstore") @@ -126,7 +126,7 @@ func TestNewBlockStore(t *testing.T) { _, _, panicErr := doFn(func() (interface{}, error) { err := db.Set(blockStoreKey, tt.data) require.NoError(t, err) - _ = NewBlockStore(db, ipfsAPI) + _ = NewBlockStore(db, ipfsAPI.Dag()) return nil, nil }) require.NotNil(t, panicErr, "#%d panicCauser: %q expected a panic", i, tt.data) @@ -135,14 +135,14 @@ func TestNewBlockStore(t *testing.T) { err = db.Set(blockStoreKey, []byte{}) require.NoError(t, err) - bs = NewBlockStore(db, ipfsAPI) + bs = NewBlockStore(db, ipfsAPI.Dag()) assert.Equal(t, bs.Height(), int64(0), "expecting empty bytes to be unmarshaled alright") } func freshBlockStore() (*BlockStore, dbm.DB) { db := memdb.NewDB() ipfsAPI, _, _ := ipfs.Mock()() - return NewBlockStore(db, ipfsAPI), db + return NewBlockStore(db, ipfsAPI.Dag()), db } var ( @@ -385,7 +385,7 @@ func TestLoadBaseMeta(t *testing.T) { state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile()) require.NoError(t, err) ipfsAPI, _, _ := ipfs.Mock()() - bs := NewBlockStore(memdb.NewDB(), ipfsAPI) + bs := NewBlockStore(memdb.NewDB(), ipfsAPI.Dag()) for h := int64(1); h <= 10; h++ { block := makeBlock(h, state, new(types.Commit)) @@ -443,7 +443,7 @@ func TestPruneBlocks(t *testing.T) { require.NoError(t, err) ipfsAPI, _, _ := ipfs.Mock()() db := memdb.NewDB() - bs := NewBlockStore(db, ipfsAPI) + bs := NewBlockStore(db, ipfsAPI.Dag()) assert.EqualValues(t, 0, bs.Base()) assert.EqualValues(t, 0, bs.Height()) assert.EqualValues(t, 0, bs.Size()) From 0517ac2918a01087c2fb02cee4aff0afe3db35ee Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 14:08:25 -0500 Subject: [PATCH 06/25] increase TestNodeSetPrivValIPC timeout to 400ms --- node/node_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node_test.go b/node/node_test.go index 0ad3749f20..59c286c719 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -218,7 +218,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { log.TestingLogger(), dialer, ) - privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint) + privval.SignerDialerEndpointTimeoutReadWrite(400 * time.Millisecond)(dialerEndpoint) pvsc := privval.NewSignerServer( dialerEndpoint, From ac48a99f0fbef52a880718cdd0452000c721938a Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 16:52:18 -0500 Subject: [PATCH 07/25] increase time waited for TestReactorsGossipNoCommittedEvidence again --- evidence/reactor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index 147dbe9b96..a28e76e014 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -178,7 +178,7 @@ func TestReactorsGossipNoCommittedEvidence(t *testing.T) { peer.Set(types.PeerStateKey, ps) // wait to see that only two evidence is sent - time.Sleep(600 * time.Millisecond) + time.Sleep(1200 * time.Millisecond) peerEv, _ = pools[1].PendingEvidence(1000) assert.EqualValues(t, []types.Evidence{evList[0], evList[1]}, peerEv) From 87fae071839e345793e35dd70b0f0049e0fbd816 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 16:53:15 -0500 Subject: [PATCH 08/25] increase TestNodeSetPrivValIPC timeout again --- node/node_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node_test.go b/node/node_test.go index 59c286c719..4f25a8a362 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -218,7 +218,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { log.TestingLogger(), dialer, ) - privval.SignerDialerEndpointTimeoutReadWrite(400 * time.Millisecond)(dialerEndpoint) + privval.SignerDialerEndpointTimeoutReadWrite(1000 * time.Millisecond)(dialerEndpoint) pvsc := privval.NewSignerServer( dialerEndpoint, From eed5e8906cc192c13618cdb58764da0277dd2c7e Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 17:20:12 -0500 Subject: [PATCH 09/25] timeout increase --- consensus/common_test.go | 2 +- consensus/reactor_test.go | 2 +- node/node_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/common_test.go b/consensus/common_test.go index f48b98d042..1234fdf8ec 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -53,7 +53,7 @@ type cleanupFunc func() var ( config *cfg.Config // NOTE: must be reset for each _test.go file consensusReplayConfig *cfg.Config - ensureTimeout = 2 * time.Second + ensureTimeout = 4 * time.Second ) func ensureDir(dir string, mode os.FileMode) { diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 190c9e9ed6..93c410ff3b 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -670,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 * 4 + timeout := time.Minute * 6 select { case <-done: diff --git a/node/node_test.go b/node/node_test.go index 4f25a8a362..c5bec0729a 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -218,7 +218,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { log.TestingLogger(), dialer, ) - privval.SignerDialerEndpointTimeoutReadWrite(1000 * time.Millisecond)(dialerEndpoint) + privval.SignerDialerEndpointTimeoutReadWrite(4 * time.Second)(dialerEndpoint) pvsc := privval.NewSignerServer( dialerEndpoint, From 8d5debe42d21205d2853d1117fd10fa536f8eadb Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 17:26:40 -0500 Subject: [PATCH 10/25] cleanup remainging mocks --- blockchain/v0/reactor_test.go | 5 ++--- consensus/replay_test.go | 7 +------ evidence/pool_test.go | 6 ++---- node/node_test.go | 4 ++-- store/store_test.go | 21 ++++++++------------- 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/blockchain/v0/reactor_test.go b/blockchain/v0/reactor_test.go index 8ccd8aa9d9..218caf0b43 100644 --- a/blockchain/v0/reactor_test.go +++ b/blockchain/v0/reactor_test.go @@ -8,12 +8,12 @@ import ( "testing" "time" + mdutils "github.com/ipfs/go-merkledag/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/lazyledger/lazyledger-core/abci/types" cfg "github.com/lazyledger/lazyledger-core/config" - "github.com/lazyledger/lazyledger-core/ipfs" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" "github.com/lazyledger/lazyledger-core/mempool/mock" @@ -72,8 +72,7 @@ func newBlockchainReactor( blockDB := memdb.NewDB() stateDB := memdb.NewDB() stateStore := sm.NewStore(stateDB) - ipfsAPI, _, _ := ipfs.Mock()() - blockStore := store.NewBlockStore(blockDB, ipfsAPI.Dag()) + blockStore := store.NewBlockStore(blockDB, mdutils.Mock()) state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc) if err != nil { diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 72ced57f5e..2c06eccfc3 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -24,7 +24,6 @@ import ( cfg "github.com/lazyledger/lazyledger-core/config" "github.com/lazyledger/lazyledger-core/crypto" cryptoenc "github.com/lazyledger/lazyledger-core/crypto/encoding" - "github.com/lazyledger/lazyledger-core/ipfs" dbm "github.com/lazyledger/lazyledger-core/libs/db" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" @@ -1193,11 +1192,7 @@ type mockBlockStore struct { // TODO: NewBlockStore(db.NewMemDB) ... func newMockBlockStore(config *cfg.Config, params tmproto.ConsensusParams) *mockBlockStore { - api, _, err := ipfs.Mock()() - if err != nil { - panic("failure to create mock IPFS object") - } - return &mockBlockStore{config, params, nil, nil, 0, api.Dag()} + return &mockBlockStore{config, params, nil, nil, 0, mdutils.Mock()} } func (bs *mockBlockStore) Height() int64 { return int64(len(bs.chain)) } diff --git a/evidence/pool_test.go b/evidence/pool_test.go index b4992308cd..0c5a64a51f 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -5,13 +5,13 @@ 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" "github.com/lazyledger/lazyledger-core/evidence" "github.com/lazyledger/lazyledger-core/evidence/mocks" - "github.com/lazyledger/lazyledger-core/ipfs" dbm "github.com/lazyledger/lazyledger-core/libs/db" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" @@ -396,9 +396,7 @@ func initializeValidatorState(privVal types.PrivValidator, height int64) sm.Stor // initializeBlockStore creates a block storage and populates it w/ a dummy // block at +height+. func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) *store.BlockStore { - ipfsAPI, _, _ := ipfs.Mock()() - - blockStore := store.NewBlockStore(db, ipfsAPI.Dag()) + blockStore := store.NewBlockStore(db, mdutils.Mock()) for i := int64(1); i <= state.LastBlockHeight; i++ { lastCommit := makeCommit(i-1, valAddr) diff --git a/node/node_test.go b/node/node_test.go index c5bec0729a..7f20df1130 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + mdutils "github.com/ipfs/go-merkledag/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -283,8 +284,7 @@ func TestCreateProposalBlock(t *testing.T) { // Make EvidencePool evidenceDB := memdb.NewDB() - ipfsAPI, _, _ := ipfs.Mock()() - blockStore := store.NewBlockStore(memdb.NewDB(), ipfsAPI.Dag()) + blockStore := store.NewBlockStore(memdb.NewDB(), mdutils.Mock()) evidencePool, err := evidence.NewPool(evidenceDB, stateStore, blockStore) require.NoError(t, err) evidencePool.SetLogger(logger) diff --git a/store/store_test.go b/store/store_test.go index 45f2d0e97c..f290510ff0 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -11,12 +11,12 @@ import ( "time" "github.com/gogo/protobuf/proto" + mdutils "github.com/ipfs/go-merkledag/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" cfg "github.com/lazyledger/lazyledger-core/config" "github.com/lazyledger/lazyledger-core/crypto" - "github.com/lazyledger/lazyledger-core/ipfs" dbm "github.com/lazyledger/lazyledger-core/libs/db" "github.com/lazyledger/lazyledger-core/libs/db/memdb" "github.com/lazyledger/lazyledger-core/libs/log" @@ -74,8 +74,7 @@ func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFu if err != nil { panic(fmt.Errorf("error constructing state from genesis file: %w", err)) } - api, _, _ := ipfs.Mock()() - return state, NewBlockStore(blockDB, api.Dag()), func() { os.RemoveAll(config.RootDir) } + return state, NewBlockStore(blockDB, mdutils.Mock()), func() { os.RemoveAll(config.RootDir) } } func TestLoadBlockStoreState(t *testing.T) { @@ -107,8 +106,7 @@ func TestNewBlockStore(t *testing.T) { bz, _ := proto.Marshal(&bss) err := db.Set(blockStoreKey, bz) require.NoError(t, err) - ipfsAPI, _, _ := ipfs.Mock()() - bs := NewBlockStore(db, ipfsAPI.Dag()) + bs := NewBlockStore(db, mdutils.Mock()) require.Equal(t, int64(100), bs.Base(), "failed to properly parse blockstore") require.Equal(t, int64(10000), bs.Height(), "failed to properly parse blockstore") @@ -126,7 +124,7 @@ func TestNewBlockStore(t *testing.T) { _, _, panicErr := doFn(func() (interface{}, error) { err := db.Set(blockStoreKey, tt.data) require.NoError(t, err) - _ = NewBlockStore(db, ipfsAPI.Dag()) + _ = NewBlockStore(db, mdutils.Mock()) return nil, nil }) require.NotNil(t, panicErr, "#%d panicCauser: %q expected a panic", i, tt.data) @@ -135,14 +133,13 @@ func TestNewBlockStore(t *testing.T) { err = db.Set(blockStoreKey, []byte{}) require.NoError(t, err) - bs = NewBlockStore(db, ipfsAPI.Dag()) + bs = NewBlockStore(db, mdutils.Mock()) assert.Equal(t, bs.Height(), int64(0), "expecting empty bytes to be unmarshaled alright") } func freshBlockStore() (*BlockStore, dbm.DB) { db := memdb.NewDB() - ipfsAPI, _, _ := ipfs.Mock()() - return NewBlockStore(db, ipfsAPI.Dag()), db + return NewBlockStore(db, mdutils.Mock()), db } var ( @@ -384,8 +381,7 @@ func TestLoadBaseMeta(t *testing.T) { stateStore := sm.NewStore(memdb.NewDB()) state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile()) require.NoError(t, err) - ipfsAPI, _, _ := ipfs.Mock()() - bs := NewBlockStore(memdb.NewDB(), ipfsAPI.Dag()) + bs := NewBlockStore(memdb.NewDB(), mdutils.Mock()) for h := int64(1); h <= 10; h++ { block := makeBlock(h, state, new(types.Commit)) @@ -441,9 +437,8 @@ func TestPruneBlocks(t *testing.T) { stateStore := sm.NewStore(memdb.NewDB()) state, err := stateStore.LoadFromDBOrGenesisFile(config.GenesisFile()) require.NoError(t, err) - ipfsAPI, _, _ := ipfs.Mock()() db := memdb.NewDB() - bs := NewBlockStore(db, ipfsAPI.Dag()) + bs := NewBlockStore(db, mdutils.Mock()) assert.EqualValues(t, 0, bs.Base()) assert.EqualValues(t, 0, bs.Height()) assert.EqualValues(t, 0, bs.Size()) From 617406395ab62b39ed96a62ef9229b9ae2658db4 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 17:37:14 -0500 Subject: [PATCH 11/25] try insane timeout for TestNodeSetPrivValIPC --- node/node_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node_test.go b/node/node_test.go index 7f20df1130..4c3a3ccbb1 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -219,7 +219,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { log.TestingLogger(), dialer, ) - privval.SignerDialerEndpointTimeoutReadWrite(4 * time.Second)(dialerEndpoint) + privval.SignerDialerEndpointTimeoutReadWrite(20 * time.Second)(dialerEndpoint) pvsc := privval.NewSignerServer( dialerEndpoint, From fbfab50f1b51a52ca7c64a306794ec1526d5f4fa Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 17:54:57 -0500 Subject: [PATCH 12/25] increase the failing precommit timeout --- config/config.go | 2 +- node/node_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index cd1a6c2776..90bbc90c39 100644 --- a/config/config.go +++ b/config/config.go @@ -847,7 +847,7 @@ func TestConsensusConfig() *ConsensusConfig { cfg.TimeoutProposeDelta = 20 * time.Millisecond cfg.TimeoutPrevote = 80 * time.Millisecond cfg.TimeoutPrevoteDelta = 20 * time.Millisecond - cfg.TimeoutPrecommit = 80 * time.Millisecond + cfg.TimeoutPrecommit = 160 * 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 diff --git a/node/node_test.go b/node/node_test.go index 4c3a3ccbb1..152d0b826e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -219,7 +219,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { log.TestingLogger(), dialer, ) - privval.SignerDialerEndpointTimeoutReadWrite(20 * time.Second)(dialerEndpoint) + privval.SignerDialerEndpointTimeoutReadWrite(80 * time.Second)(dialerEndpoint) pvsc := privval.NewSignerServer( dialerEndpoint, From 2bb033bfce8361b05e5fa9789a2bf221c47b39ab Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 18:47:04 -0500 Subject: [PATCH 13/25] more cleanup --- node/node.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/node/node.go b/node/node.go index 367bd05d89..23ec7a24dc 100644 --- a/node/node.go +++ b/node/node.go @@ -12,7 +12,6 @@ import ( "strings" "time" - format "github.com/ipfs/go-ipld-format" iface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -400,7 +399,6 @@ func createConsensusReactor(config *cfg.Config, csMetrics *cs.Metrics, waitSync bool, eventBus *types.EventBus, - dag format.DAGService, consensusLogger log.Logger) (*cs.Reactor, *cs.State) { consensusState := cs.NewState( @@ -761,7 +759,7 @@ func NewNode(config *cfg.Config, } consensusReactor, consensusState := createConsensusReactor( config, state, blockExec, blockStore, mempool, evidencePool, - privValidator, csMetrics, stateSync || fastSync, eventBus, ipfs.Dag(), consensusLogger, + privValidator, csMetrics, stateSync || fastSync, eventBus, consensusLogger, ) // Set up state sync reactor, and schedule a sync if requested. From 210e690966ca32dc6d1bef6a9829b02df2342c1a Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 19:11:34 -0500 Subject: [PATCH 14/25] remove the unused ipfsAPI from the node --- node/node.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/node/node.go b/node/node.go index 23ec7a24dc..edfc99c9c2 100644 --- a/node/node.go +++ b/node/node.go @@ -215,7 +215,6 @@ type Node struct { indexerService *txindex.IndexerService prometheusSrv *http.Server - ipfsAPI iface.CoreAPI ipfsClose io.Closer } @@ -860,7 +859,6 @@ func NewNode(config *cfg.Config, txIndexer: txIndexer, indexerService: indexerService, eventBus: eventBus, - ipfsAPI: ipfs, ipfsClose: ipfsclose, } node.BaseService = *service.NewBaseService(logger, "Node", node) @@ -1411,8 +1409,8 @@ func createAndStartPrivValidatorSocketClient( } const ( - retries = 50 // 50 * 100ms = 5s total - timeout = 100 * time.Millisecond + retries = 50 // 50 * 200ms = 10s total + timeout = 200 * time.Millisecond ) pvscWithRetries := privval.NewRetrySignerClient(pvsc, retries, timeout) From e914706d22bab5bb21bf26ce3e920594dc267cb4 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 19:33:18 -0500 Subject: [PATCH 15/25] try a test node that doesn't use the full mocked ipfs node --- node/node.go | 245 +++++++++++++++++++++++++++++++++++++++++++++- node/node_test.go | 3 +- 2 files changed, 244 insertions(+), 4 deletions(-) diff --git a/node/node.go b/node/node.go index edfc99c9c2..9fd06cbe18 100644 --- a/node/node.go +++ b/node/node.go @@ -12,6 +12,7 @@ import ( "strings" "time" + mdutils "github.com/ipfs/go-merkledag/test" iface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -870,6 +871,244 @@ func NewNode(config *cfg.Config, return node, nil } +// NewNode returns a new, ready to go, Tendermint Node. +func NewTestNode(config *cfg.Config, + privValidator types.PrivValidator, + nodeKey p2p.NodeKey, + clientCreator proxy.ClientCreator, + genesisDocProvider GenesisDocProvider, + dbProvider DBProvider, + metricsProvider MetricsProvider, + logger log.Logger, + options ...Option) (*Node, error) { + + stateDB, err := dbProvider(&DBContext{"state", config}) + if err != nil { + return nil, err + } + + blockStore := store.NewBlockStore(stateDB, mdutils.Mock()) + + stateStore := sm.NewStore(stateDB) + + state, genDoc, err := LoadStateFromDBOrGenesisDocProvider(stateDB, genesisDocProvider) + if err != nil { + return nil, err + } + + // Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query). + proxyApp, err := createAndStartProxyAppConns(clientCreator, logger) + if err != nil { + return nil, err + } + + // EventBus and IndexerService must be started before the handshake because + // we might need to index the txs of the replayed block as this might not have happened + // when the node stopped last time (i.e. the node stopped after it saved the block + // but before it indexed the txs, or, endblocker panicked) + eventBus, err := createAndStartEventBus(logger) + if err != nil { + return nil, err + } + + // Transaction indexing + indexerService, txIndexer, err := createAndStartIndexerService(config, dbProvider, eventBus, logger) + if err != nil { + return nil, err + } + + // If an address is provided, listen on the socket for a connection from an + // external signing process. + if config.PrivValidatorListenAddr != "" { + // FIXME: we should start services inside OnStart + privValidator, err = createAndStartPrivValidatorSocketClient(config.PrivValidatorListenAddr, genDoc.ChainID, logger) + if err != nil { + return nil, fmt.Errorf("error with private validator socket client: %w", err) + } + } + + pubKey, err := privValidator.GetPubKey() + if err != nil { + return nil, fmt.Errorf("can't get pubkey: %w", err) + } + + // Determine whether we should attempt state sync. + stateSync := config.StateSync.Enable && !onlyValidatorIsUs(state, pubKey) + if stateSync && state.LastBlockHeight > 0 { + logger.Info("Found local state with non-zero height, skipping state sync") + stateSync = false + } + + // Create the handshaker, which calls RequestInfo, sets the AppVersion on the state, + // and replays any blocks as necessary to sync tendermint with the app. + consensusLogger := logger.With("module", "consensus") + if !stateSync { + if err := doHandshake(stateStore, state, blockStore, genDoc, eventBus, proxyApp, consensusLogger); err != nil { + return nil, err + } + + // Reload the state. It will have the Version.Consensus.App set by the + // Handshake, and may have other modifications as well (ie. depending on + // what happened during block replay). + state, err = stateStore.Load() + if err != nil { + return nil, fmt.Errorf("cannot load state: %w", err) + } + } + + // Determine whether we should do fast sync. This must happen after the handshake, since the + // app may modify the validator set, specifying ourself as the only validator. + fastSync := config.FastSyncMode && !onlyValidatorIsUs(state, pubKey) + + logNodeStartupInfo(state, pubKey, logger, consensusLogger) + + csMetrics, p2pMetrics, memplMetrics, smMetrics := metricsProvider(genDoc.ChainID) + + // Make MempoolReactor + mempoolReactor, mempool := createMempoolAndMempoolReactor(config, proxyApp, state, memplMetrics, logger) + + // Make Evidence Reactor + evidenceReactor, evidencePool, err := createEvidenceReactor(config, dbProvider, stateDB, blockStore, logger) + if err != nil { + return nil, err + } + + // make block executor for consensus and blockchain reactors to execute blocks + blockExec := sm.NewBlockExecutor( + stateStore, + logger.With("module", "state"), + proxyApp.Consensus(), + mempool, + evidencePool, + sm.BlockExecutorWithMetrics(smMetrics), + ) + + // Make BlockchainReactor. Don't start fast sync if we're doing a state sync first. + bcReactor, err := createBlockchainReactor(config, state, blockExec, blockStore, fastSync && !stateSync, logger) + if err != nil { + return nil, fmt.Errorf("could not create blockchain reactor: %w", err) + } + + // Make ConsensusReactor. Don't enable fully if doing a state sync and/or fast sync first. + // FIXME We need to update metrics here, since other reactors don't have access to them. + if stateSync { + csMetrics.StateSyncing.Set(1) + } else if fastSync { + csMetrics.FastSyncing.Set(1) + } + consensusReactor, consensusState := createConsensusReactor( + config, state, blockExec, blockStore, mempool, evidencePool, + privValidator, csMetrics, stateSync || fastSync, eventBus, consensusLogger, + ) + + // Set up state sync reactor, and schedule a sync if requested. + // FIXME The way we do phased startups (e.g. replay -> fast sync -> consensus) is very messy, + // we should clean this whole thing up. See: + // https://github.com/tendermint/tendermint/issues/4644 + stateSyncReactorShim := p2p.NewReactorShim("StateSyncShim", statesync.ChannelShims) + stateSyncReactorShim.SetLogger(logger.With("module", "statesync")) + + stateSyncReactor := statesync.NewReactor( + stateSyncReactorShim.Logger, + proxyApp.Snapshot(), + proxyApp.Query(), + stateSyncReactorShim.GetChannel(statesync.SnapshotChannel), + stateSyncReactorShim.GetChannel(statesync.ChunkChannel), + stateSyncReactorShim.PeerUpdates, + config.StateSync.TempDir, + ) + + nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state) + if err != nil { + return nil, err + } + + // Setup Transport. + transport, peerFilters := createTransport(config, nodeInfo, nodeKey, proxyApp) + + // Setup Switch. + p2pLogger := logger.With("module", "p2p") + sw := createSwitch( + config, transport, p2pMetrics, peerFilters, mempoolReactor, bcReactor, + stateSyncReactorShim, consensusReactor, evidenceReactor, nodeInfo, nodeKey, p2pLogger, + ) + + err = sw.AddPersistentPeers(splitAndTrimEmpty(config.P2P.PersistentPeers, ",", " ")) + if err != nil { + return nil, fmt.Errorf("could not add peers from persistent_peers field: %w", err) + } + + err = sw.AddUnconditionalPeerIDs(splitAndTrimEmpty(config.P2P.UnconditionalPeerIDs, ",", " ")) + if err != nil { + return nil, fmt.Errorf("could not add peer ids from unconditional_peer_ids field: %w", err) + } + + addrBook, err := createAddrBookAndSetOnSwitch(config, sw, p2pLogger, nodeKey) + if err != nil { + return nil, fmt.Errorf("could not create addrbook: %w", err) + } + + // Optionally, start the pex reactor + // + // TODO: + // + // We need to set Seeds and PersistentPeers on the switch, + // since it needs to be able to use these (and their DNS names) + // even if the PEX is off. We can include the DNS name in the NetAddress, + // but it would still be nice to have a clear list of the current "PersistentPeers" + // somewhere that we can return with net_info. + // + // If PEX is on, it should handle dialing the seeds. Otherwise the switch does it. + // Note we currently use the addrBook regardless at least for AddOurAddress + var pexReactor *pex.Reactor + if config.P2P.PexReactor { + pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger) + } + + if config.RPC.PprofListenAddress != "" { + go func() { + logger.Info("Starting pprof server", "laddr", config.RPC.PprofListenAddress) + logger.Error("pprof server error", "err", http.ListenAndServe(config.RPC.PprofListenAddress, nil)) + }() + } + + node := &Node{ + config: config, + genesisDoc: genDoc, + privValidator: privValidator, + + transport: transport, + sw: sw, + addrBook: addrBook, + nodeInfo: nodeInfo, + nodeKey: nodeKey, + + stateStore: stateStore, + blockStore: blockStore, + bcReactor: bcReactor, + mempoolReactor: mempoolReactor, + mempool: mempool, + consensusState: consensusState, + consensusReactor: consensusReactor, + stateSyncReactor: stateSyncReactor, + stateSync: stateSync, + stateSyncGenesis: state, // Shouldn't be necessary, but need a way to pass the genesis state + pexReactor: pexReactor, + evidencePool: evidencePool, + proxyApp: proxyApp, + txIndexer: txIndexer, + indexerService: indexerService, + eventBus: eventBus, + } + node.BaseService = *service.NewBaseService(logger, "Node", node) + + for _, option := range options { + option(node) + } + + return node, nil +} + // OnStart starts the Node. It implements service.Service. func (n *Node) OnStart() error { now := tmtime.Now() @@ -1004,8 +1243,10 @@ func (n *Node) OnStop() { } } - if err := n.ipfsClose.Close(); err != nil { - n.Logger.Error("ipfsClose.Close()", err) + if n.ipfsClose != nil { + if err := n.ipfsClose.Close(); err != nil { + n.Logger.Error("ipfsClose.Close()", err) + } } } diff --git a/node/node_test.go b/node/node_test.go index 152d0b826e..d0a4e71fca 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -47,13 +47,12 @@ func defaultNewTestNode(config *cfg.Config, logger log.Logger) (*Node, error) { return nil, err } - return NewNode(config, + return NewTestNode(config, pval, nodeKey, proxy.DefaultClientCreator(config.ProxyApp, config.DBDir()), DefaultGenesisDocProviderFunc(config), InMemDBProvider, - ipfs.Mock(), DefaultMetricsProvider(config.Instrumentation), logger, ) From cb645cb06470acdc7949d6755c761d80b226833a Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 22:21:17 -0500 Subject: [PATCH 16/25] implement and use a dag only api provider --- ipfs/mock.go | 43 ++++++++ node/node.go | 245 +------------------------------------------- node/node_test.go | 5 +- rpc/test/helpers.go | 2 +- 4 files changed, 49 insertions(+), 246 deletions(-) diff --git a/ipfs/mock.go b/ipfs/mock.go index 1be81c7517..a8960e2313 100644 --- a/ipfs/mock.go +++ b/ipfs/mock.go @@ -1,11 +1,16 @@ package ipfs import ( + "context" "io" "github.com/ipfs/go-ipfs/core/coreapi" coremock "github.com/ipfs/go-ipfs/core/mock" + format "github.com/ipfs/go-ipld-format" + mdutils "github.com/ipfs/go-merkledag/test" coreiface "github.com/ipfs/interface-go-ipfs-core" + "github.com/ipfs/interface-go-ipfs-core/options" + "github.com/ipfs/interface-go-ipfs-core/path" "github.com/lazyledger/lazyledger-core/ipfs/plugin" ) @@ -28,3 +33,41 @@ func Mock() APIProvider { return api, nd, nil } } + +// DagOnlyMock provides an empty APIProvider that only mocks the DAG portion of +// the ipfs api object. This is much lighter than the full IPFS node and should +// be favored for CI testing +func DagOnlyMock() APIProvider { + mockAPI := dagOnlyMock{mdutils.Mock()} + return func() (coreiface.CoreAPI, io.Closer, error) { + return mockAPI, mockAPI, nil + } +} + +var _ coreiface.CoreAPI = dagOnlyMock{} + +type dagOnlyMock struct { + format.DAGService +} + +func (dom dagOnlyMock) Dag() coreiface.APIDagService { return mockAPIDagService{dom.DAGService} } + +func (dagOnlyMock) Unixfs() coreiface.UnixfsAPI { return nil } +func (dagOnlyMock) Block() coreiface.BlockAPI { return nil } +func (dagOnlyMock) Name() coreiface.NameAPI { return nil } +func (dagOnlyMock) Key() coreiface.KeyAPI { return nil } +func (dagOnlyMock) Pin() coreiface.PinAPI { return nil } +func (dagOnlyMock) Object() coreiface.ObjectAPI { return nil } +func (dagOnlyMock) Dht() coreiface.DhtAPI { return nil } +func (dagOnlyMock) Swarm() coreiface.SwarmAPI { return nil } +func (dagOnlyMock) PubSub() coreiface.PubSubAPI { return nil } +func (dagOnlyMock) ResolvePath(context.Context, path.Path) (path.Resolved, error) { return nil, nil } +func (dagOnlyMock) ResolveNode(context.Context, path.Path) (format.Node, error) { return nil, nil } +func (dagOnlyMock) WithOptions(...options.ApiOption) (coreiface.CoreAPI, error) { return nil, nil } +func (dagOnlyMock) Close() error { return nil } + +type mockAPIDagService struct { + format.DAGService +} + +func (mockAPIDagService) Pinning() format.NodeAdder { return nil } diff --git a/node/node.go b/node/node.go index 9fd06cbe18..edfc99c9c2 100644 --- a/node/node.go +++ b/node/node.go @@ -12,7 +12,6 @@ import ( "strings" "time" - mdutils "github.com/ipfs/go-merkledag/test" iface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -871,244 +870,6 @@ func NewNode(config *cfg.Config, return node, nil } -// NewNode returns a new, ready to go, Tendermint Node. -func NewTestNode(config *cfg.Config, - privValidator types.PrivValidator, - nodeKey p2p.NodeKey, - clientCreator proxy.ClientCreator, - genesisDocProvider GenesisDocProvider, - dbProvider DBProvider, - metricsProvider MetricsProvider, - logger log.Logger, - options ...Option) (*Node, error) { - - stateDB, err := dbProvider(&DBContext{"state", config}) - if err != nil { - return nil, err - } - - blockStore := store.NewBlockStore(stateDB, mdutils.Mock()) - - stateStore := sm.NewStore(stateDB) - - state, genDoc, err := LoadStateFromDBOrGenesisDocProvider(stateDB, genesisDocProvider) - if err != nil { - return nil, err - } - - // Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query). - proxyApp, err := createAndStartProxyAppConns(clientCreator, logger) - if err != nil { - return nil, err - } - - // EventBus and IndexerService must be started before the handshake because - // we might need to index the txs of the replayed block as this might not have happened - // when the node stopped last time (i.e. the node stopped after it saved the block - // but before it indexed the txs, or, endblocker panicked) - eventBus, err := createAndStartEventBus(logger) - if err != nil { - return nil, err - } - - // Transaction indexing - indexerService, txIndexer, err := createAndStartIndexerService(config, dbProvider, eventBus, logger) - if err != nil { - return nil, err - } - - // If an address is provided, listen on the socket for a connection from an - // external signing process. - if config.PrivValidatorListenAddr != "" { - // FIXME: we should start services inside OnStart - privValidator, err = createAndStartPrivValidatorSocketClient(config.PrivValidatorListenAddr, genDoc.ChainID, logger) - if err != nil { - return nil, fmt.Errorf("error with private validator socket client: %w", err) - } - } - - pubKey, err := privValidator.GetPubKey() - if err != nil { - return nil, fmt.Errorf("can't get pubkey: %w", err) - } - - // Determine whether we should attempt state sync. - stateSync := config.StateSync.Enable && !onlyValidatorIsUs(state, pubKey) - if stateSync && state.LastBlockHeight > 0 { - logger.Info("Found local state with non-zero height, skipping state sync") - stateSync = false - } - - // Create the handshaker, which calls RequestInfo, sets the AppVersion on the state, - // and replays any blocks as necessary to sync tendermint with the app. - consensusLogger := logger.With("module", "consensus") - if !stateSync { - if err := doHandshake(stateStore, state, blockStore, genDoc, eventBus, proxyApp, consensusLogger); err != nil { - return nil, err - } - - // Reload the state. It will have the Version.Consensus.App set by the - // Handshake, and may have other modifications as well (ie. depending on - // what happened during block replay). - state, err = stateStore.Load() - if err != nil { - return nil, fmt.Errorf("cannot load state: %w", err) - } - } - - // Determine whether we should do fast sync. This must happen after the handshake, since the - // app may modify the validator set, specifying ourself as the only validator. - fastSync := config.FastSyncMode && !onlyValidatorIsUs(state, pubKey) - - logNodeStartupInfo(state, pubKey, logger, consensusLogger) - - csMetrics, p2pMetrics, memplMetrics, smMetrics := metricsProvider(genDoc.ChainID) - - // Make MempoolReactor - mempoolReactor, mempool := createMempoolAndMempoolReactor(config, proxyApp, state, memplMetrics, logger) - - // Make Evidence Reactor - evidenceReactor, evidencePool, err := createEvidenceReactor(config, dbProvider, stateDB, blockStore, logger) - if err != nil { - return nil, err - } - - // make block executor for consensus and blockchain reactors to execute blocks - blockExec := sm.NewBlockExecutor( - stateStore, - logger.With("module", "state"), - proxyApp.Consensus(), - mempool, - evidencePool, - sm.BlockExecutorWithMetrics(smMetrics), - ) - - // Make BlockchainReactor. Don't start fast sync if we're doing a state sync first. - bcReactor, err := createBlockchainReactor(config, state, blockExec, blockStore, fastSync && !stateSync, logger) - if err != nil { - return nil, fmt.Errorf("could not create blockchain reactor: %w", err) - } - - // Make ConsensusReactor. Don't enable fully if doing a state sync and/or fast sync first. - // FIXME We need to update metrics here, since other reactors don't have access to them. - if stateSync { - csMetrics.StateSyncing.Set(1) - } else if fastSync { - csMetrics.FastSyncing.Set(1) - } - consensusReactor, consensusState := createConsensusReactor( - config, state, blockExec, blockStore, mempool, evidencePool, - privValidator, csMetrics, stateSync || fastSync, eventBus, consensusLogger, - ) - - // Set up state sync reactor, and schedule a sync if requested. - // FIXME The way we do phased startups (e.g. replay -> fast sync -> consensus) is very messy, - // we should clean this whole thing up. See: - // https://github.com/tendermint/tendermint/issues/4644 - stateSyncReactorShim := p2p.NewReactorShim("StateSyncShim", statesync.ChannelShims) - stateSyncReactorShim.SetLogger(logger.With("module", "statesync")) - - stateSyncReactor := statesync.NewReactor( - stateSyncReactorShim.Logger, - proxyApp.Snapshot(), - proxyApp.Query(), - stateSyncReactorShim.GetChannel(statesync.SnapshotChannel), - stateSyncReactorShim.GetChannel(statesync.ChunkChannel), - stateSyncReactorShim.PeerUpdates, - config.StateSync.TempDir, - ) - - nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state) - if err != nil { - return nil, err - } - - // Setup Transport. - transport, peerFilters := createTransport(config, nodeInfo, nodeKey, proxyApp) - - // Setup Switch. - p2pLogger := logger.With("module", "p2p") - sw := createSwitch( - config, transport, p2pMetrics, peerFilters, mempoolReactor, bcReactor, - stateSyncReactorShim, consensusReactor, evidenceReactor, nodeInfo, nodeKey, p2pLogger, - ) - - err = sw.AddPersistentPeers(splitAndTrimEmpty(config.P2P.PersistentPeers, ",", " ")) - if err != nil { - return nil, fmt.Errorf("could not add peers from persistent_peers field: %w", err) - } - - err = sw.AddUnconditionalPeerIDs(splitAndTrimEmpty(config.P2P.UnconditionalPeerIDs, ",", " ")) - if err != nil { - return nil, fmt.Errorf("could not add peer ids from unconditional_peer_ids field: %w", err) - } - - addrBook, err := createAddrBookAndSetOnSwitch(config, sw, p2pLogger, nodeKey) - if err != nil { - return nil, fmt.Errorf("could not create addrbook: %w", err) - } - - // Optionally, start the pex reactor - // - // TODO: - // - // We need to set Seeds and PersistentPeers on the switch, - // since it needs to be able to use these (and their DNS names) - // even if the PEX is off. We can include the DNS name in the NetAddress, - // but it would still be nice to have a clear list of the current "PersistentPeers" - // somewhere that we can return with net_info. - // - // If PEX is on, it should handle dialing the seeds. Otherwise the switch does it. - // Note we currently use the addrBook regardless at least for AddOurAddress - var pexReactor *pex.Reactor - if config.P2P.PexReactor { - pexReactor = createPEXReactorAndAddToSwitch(addrBook, config, sw, logger) - } - - if config.RPC.PprofListenAddress != "" { - go func() { - logger.Info("Starting pprof server", "laddr", config.RPC.PprofListenAddress) - logger.Error("pprof server error", "err", http.ListenAndServe(config.RPC.PprofListenAddress, nil)) - }() - } - - node := &Node{ - config: config, - genesisDoc: genDoc, - privValidator: privValidator, - - transport: transport, - sw: sw, - addrBook: addrBook, - nodeInfo: nodeInfo, - nodeKey: nodeKey, - - stateStore: stateStore, - blockStore: blockStore, - bcReactor: bcReactor, - mempoolReactor: mempoolReactor, - mempool: mempool, - consensusState: consensusState, - consensusReactor: consensusReactor, - stateSyncReactor: stateSyncReactor, - stateSync: stateSync, - stateSyncGenesis: state, // Shouldn't be necessary, but need a way to pass the genesis state - pexReactor: pexReactor, - evidencePool: evidencePool, - proxyApp: proxyApp, - txIndexer: txIndexer, - indexerService: indexerService, - eventBus: eventBus, - } - node.BaseService = *service.NewBaseService(logger, "Node", node) - - for _, option := range options { - option(node) - } - - return node, nil -} - // OnStart starts the Node. It implements service.Service. func (n *Node) OnStart() error { now := tmtime.Now() @@ -1243,10 +1004,8 @@ func (n *Node) OnStop() { } } - if n.ipfsClose != nil { - if err := n.ipfsClose.Close(); err != nil { - n.Logger.Error("ipfsClose.Close()", err) - } + if err := n.ipfsClose.Close(); err != nil { + n.Logger.Error("ipfsClose.Close()", err) } } diff --git a/node/node_test.go b/node/node_test.go index d0a4e71fca..aa50c39125 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -47,12 +47,13 @@ func defaultNewTestNode(config *cfg.Config, logger log.Logger) (*Node, error) { return nil, err } - return NewTestNode(config, + return NewNode(config, pval, nodeKey, proxy.DefaultClientCreator(config.ProxyApp, config.DBDir()), DefaultGenesisDocProviderFunc(config), InMemDBProvider, + ipfs.DagOnlyMock(), DefaultMetricsProvider(config.Instrumentation), logger, ) @@ -539,7 +540,7 @@ func TestNodeNewNodeCustomReactors(t *testing.T) { proxy.DefaultClientCreator(config.ProxyApp, config.DBDir()), DefaultGenesisDocProviderFunc(config), InMemDBProvider, - ipfs.Mock(), + ipfs.DagOnlyMock(), DefaultMetricsProvider(config.Instrumentation), log.TestingLogger(), CustomReactors(map[string]p2p.Reactor{"FOO": cr, "BLOCKCHAIN": customBlockchainReactor}), diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 5a8b8e747a..5db5728859 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -176,7 +176,7 @@ func NewTendermint(app abci.Application, opts *Options) *nm.Node { node, err := nm.NewNode(config, pv, nodeKey, papp, nm.DefaultGenesisDocProviderFunc(config), nm.InMemDBProvider, - ipfs.Mock(), + ipfs.DagOnlyMock(), nm.DefaultMetricsProvider(config.Instrumentation), logger, ) From 00d3af0cce0a08014e9caa61bb4adad8fa1bf626 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 22:22:49 -0500 Subject: [PATCH 17/25] revert crazy timeout --- node/node_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/node_test.go b/node/node_test.go index aa50c39125..b83e993037 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -219,7 +219,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { log.TestingLogger(), dialer, ) - privval.SignerDialerEndpointTimeoutReadWrite(80 * time.Second)(dialerEndpoint) + privval.SignerDialerEndpointTimeoutReadWrite(400 * time.Millisecond)(dialerEndpoint) pvsc := privval.NewSignerServer( dialerEndpoint, From 2e5a7e4d943675791c6e6e9d93c4919ee5c733d6 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 26 May 2021 22:27:39 -0500 Subject: [PATCH 18/25] simplify dag only mock --- ipfs/mock.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ipfs/mock.go b/ipfs/mock.go index a8960e2313..8d2f9d4f95 100644 --- a/ipfs/mock.go +++ b/ipfs/mock.go @@ -50,7 +50,7 @@ type dagOnlyMock struct { format.DAGService } -func (dom dagOnlyMock) Dag() coreiface.APIDagService { return mockAPIDagService{dom.DAGService} } +func (dom dagOnlyMock) Dag() coreiface.APIDagService { return dom } func (dagOnlyMock) Unixfs() coreiface.UnixfsAPI { return nil } func (dagOnlyMock) Block() coreiface.BlockAPI { return nil } @@ -65,9 +65,4 @@ func (dagOnlyMock) ResolvePath(context.Context, path.Path) (path.Resolved, error func (dagOnlyMock) ResolveNode(context.Context, path.Path) (format.Node, error) { return nil, nil } func (dagOnlyMock) WithOptions(...options.ApiOption) (coreiface.CoreAPI, error) { return nil, nil } func (dagOnlyMock) Close() error { return nil } - -type mockAPIDagService struct { - format.DAGService -} - -func (mockAPIDagService) Pinning() format.NodeAdder { return nil } +func (dagOnlyMock) Pinning() format.NodeAdder { return nil } From c11b9fe524a5125c3c287ddfc9a54b68fdb27104 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 07:38:03 -0500 Subject: [PATCH 19/25] remove accidental file --- test-output2.txt | 148 ----------------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 test-output2.txt diff --git a/test-output2.txt b/test-output2.txt deleted file mode 100644 index 16284616e3..0000000000 --- a/test-output2.txt +++ /dev/null @@ -1,148 +0,0 @@ ---> Running go test -? github.com/lazyledger/lazyledger-core/abci/client [no test files] -? github.com/lazyledger/lazyledger-core/abci/client/mocks [no test files] -? github.com/lazyledger/lazyledger-core/abci/example/code [no test files] -? github.com/lazyledger/lazyledger-core/abci/example/counter [no test files] -? github.com/lazyledger/lazyledger-core/abci/example/dummyapp [no test files] -? github.com/lazyledger/lazyledger-core/abci/example/dummyapp/app [no test files] -ok github.com/lazyledger/lazyledger-core/abci/example/kvstore (cached) -? github.com/lazyledger/lazyledger-core/abci/tests [no test files] -? github.com/lazyledger/lazyledger-core/abci/tests/benchmarks [no test files] -? github.com/lazyledger/lazyledger-core/abci/tests/benchmarks/parallel [no test files] -? github.com/lazyledger/lazyledger-core/abci/tests/benchmarks/simple [no test files] -? github.com/lazyledger/lazyledger-core/abci/tests/server [no test files] -ok github.com/lazyledger/lazyledger-core/abci/types (cached) -? github.com/lazyledger/lazyledger-core/abci/version [no test files] -ok github.com/lazyledger/lazyledger-core/behaviour (cached) -ok github.com/lazyledger/lazyledger-core/blockchain (cached) -ok github.com/lazyledger/lazyledger-core/blockchain/v0 6.054s -? github.com/lazyledger/lazyledger-core/cmd/contract_tests [no test files] -? github.com/lazyledger/lazyledger-core/cmd/priv_val_server [no test files] -? github.com/lazyledger/lazyledger-core/cmd/tendermint [no test files] -ok github.com/lazyledger/lazyledger-core/cmd/tendermint/commands 0.076s -? github.com/lazyledger/lazyledger-core/cmd/tendermint/commands/debug [no test files] -ok github.com/lazyledger/lazyledger-core/config (cached) -ok github.com/lazyledger/lazyledger-core/consensus 43.838s -ok github.com/lazyledger/lazyledger-core/consensus/types (cached) -ok github.com/lazyledger/lazyledger-core/crypto (cached) -ok github.com/lazyledger/lazyledger-core/crypto/armor (cached) -ok github.com/lazyledger/lazyledger-core/crypto/ed25519 (cached) -? github.com/lazyledger/lazyledger-core/crypto/encoding [no test files] -? github.com/lazyledger/lazyledger-core/crypto/internal/benchmarking [no test files] -ok github.com/lazyledger/lazyledger-core/crypto/merkle (cached) -ok github.com/lazyledger/lazyledger-core/crypto/secp256k1 (cached) -ok github.com/lazyledger/lazyledger-core/crypto/sr25519 (cached) -ok github.com/lazyledger/lazyledger-core/crypto/tmhash (cached) -ok github.com/lazyledger/lazyledger-core/crypto/xchacha20poly1305 (cached) -ok github.com/lazyledger/lazyledger-core/crypto/xsalsa20symmetric (cached) -ok github.com/lazyledger/lazyledger-core/evidence 3.732s -? github.com/lazyledger/lazyledger-core/evidence/mocks [no test files] -? github.com/lazyledger/lazyledger-core/ipfs [no test files] -ok github.com/lazyledger/lazyledger-core/ipfs/plugin (cached) -? github.com/lazyledger/lazyledger-core/ipfs/plugin/main [no test files] -ok github.com/lazyledger/lazyledger-core/libs/async (cached) -ok github.com/lazyledger/lazyledger-core/libs/autofile (cached) -? github.com/lazyledger/lazyledger-core/libs/autofile/cmd [no test files] -ok github.com/lazyledger/lazyledger-core/libs/bits (cached) -ok github.com/lazyledger/lazyledger-core/libs/bytes (cached) -ok github.com/lazyledger/lazyledger-core/libs/cli (cached) -ok github.com/lazyledger/lazyledger-core/libs/cli/flags (cached) -ok github.com/lazyledger/lazyledger-core/libs/clist (cached) -ok github.com/lazyledger/lazyledger-core/libs/cmap (cached) -? github.com/lazyledger/lazyledger-core/libs/db [no test files] -ok github.com/lazyledger/lazyledger-core/libs/db/badgerdb (cached) -? github.com/lazyledger/lazyledger-core/libs/db/internal/dbtest [no test files] -ok github.com/lazyledger/lazyledger-core/libs/db/memdb (cached) [no tests to run] -ok github.com/lazyledger/lazyledger-core/libs/events (cached) -? github.com/lazyledger/lazyledger-core/libs/fail [no test files] -ok github.com/lazyledger/lazyledger-core/libs/flowrate (cached) -ok github.com/lazyledger/lazyledger-core/libs/json (cached) -ok github.com/lazyledger/lazyledger-core/libs/log (cached) -ok github.com/lazyledger/lazyledger-core/libs/math (cached) -ok github.com/lazyledger/lazyledger-core/libs/net (cached) -ok github.com/lazyledger/lazyledger-core/libs/os (cached) -ok github.com/lazyledger/lazyledger-core/libs/protoio (cached) -ok github.com/lazyledger/lazyledger-core/libs/pubsub (cached) -ok github.com/lazyledger/lazyledger-core/libs/pubsub/query (cached) -? github.com/lazyledger/lazyledger-core/libs/pubsub/query/fuzz_test [no test files] -ok github.com/lazyledger/lazyledger-core/libs/rand (cached) -ok github.com/lazyledger/lazyledger-core/libs/service (cached) -ok github.com/lazyledger/lazyledger-core/libs/strings (cached) -? github.com/lazyledger/lazyledger-core/libs/sync [no test files] -ok github.com/lazyledger/lazyledger-core/libs/tempfile (cached) -? github.com/lazyledger/lazyledger-core/libs/test [no test files] -ok github.com/lazyledger/lazyledger-core/libs/timer (cached) -ok github.com/lazyledger/lazyledger-core/light 18.630s -ok github.com/lazyledger/lazyledger-core/light/mbt 0.066s -? github.com/lazyledger/lazyledger-core/light/provider [no test files] -ok github.com/lazyledger/lazyledger-core/light/provider/http 9.801s -? github.com/lazyledger/lazyledger-core/light/provider/mock [no test files] -? github.com/lazyledger/lazyledger-core/light/proxy [no test files] -? github.com/lazyledger/lazyledger-core/light/rpc [no test files] -? github.com/lazyledger/lazyledger-core/light/rpc/mocks [no test files] -? github.com/lazyledger/lazyledger-core/light/store [no test files] -ok github.com/lazyledger/lazyledger-core/light/store/db (cached) -ok github.com/lazyledger/lazyledger-core/mempool (cached) -? github.com/lazyledger/lazyledger-core/mempool/mock [no test files] -ok github.com/lazyledger/lazyledger-core/node 8.193s -ok github.com/lazyledger/lazyledger-core/p2p (cached) -ok github.com/lazyledger/lazyledger-core/p2p/conn (cached) -ok github.com/lazyledger/lazyledger-core/p2p/ipld 3.593s -ok github.com/lazyledger/lazyledger-core/p2p/ipld/wrapper (cached) -? github.com/lazyledger/lazyledger-core/p2p/mock [no test files] -? github.com/lazyledger/lazyledger-core/p2p/mocks [no test files] -ok github.com/lazyledger/lazyledger-core/p2p/pex (cached) -ok github.com/lazyledger/lazyledger-core/p2p/trust (cached) -? github.com/lazyledger/lazyledger-core/p2p/upnp [no test files] -ok github.com/lazyledger/lazyledger-core/privval (cached) -? github.com/lazyledger/lazyledger-core/proto/tendermint/blockchain [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/consensus [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/crypto [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/libs/bits [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/mempool [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/p2p [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/privval [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/state [no test files] -ok github.com/lazyledger/lazyledger-core/proto/tendermint/statesync (cached) -? github.com/lazyledger/lazyledger-core/proto/tendermint/store [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/types [no test files] -? github.com/lazyledger/lazyledger-core/proto/tendermint/version [no test files] -ok github.com/lazyledger/lazyledger-core/proxy (cached) -? github.com/lazyledger/lazyledger-core/proxy/mocks [no test files] -ok github.com/lazyledger/lazyledger-core/rpc/client 9.836s -? github.com/lazyledger/lazyledger-core/rpc/client/http [no test files] -? github.com/lazyledger/lazyledger-core/rpc/client/local [no test files] -ok github.com/lazyledger/lazyledger-core/rpc/client/mock 0.063s -? github.com/lazyledger/lazyledger-core/rpc/client/mocks [no test files] -ok github.com/lazyledger/lazyledger-core/rpc/core 0.068s -ok github.com/lazyledger/lazyledger-core/rpc/core/types (cached) -ok github.com/lazyledger/lazyledger-core/rpc/grpc 0.452s -ok github.com/lazyledger/lazyledger-core/rpc/jsonrpc (cached) -ok github.com/lazyledger/lazyledger-core/rpc/jsonrpc/client (cached) -ok github.com/lazyledger/lazyledger-core/rpc/jsonrpc/server (cached) -? github.com/lazyledger/lazyledger-core/rpc/jsonrpc/test [no test files] -ok github.com/lazyledger/lazyledger-core/rpc/jsonrpc/types (cached) -? github.com/lazyledger/lazyledger-core/rpc/test [no test files] -? github.com/lazyledger/lazyledger-core/scripts/json2wal [no test files] -? github.com/lazyledger/lazyledger-core/scripts/wal2json [no test files] -ok github.com/lazyledger/lazyledger-core/state 2.796s -? github.com/lazyledger/lazyledger-core/state/mocks [no test files] -ok github.com/lazyledger/lazyledger-core/state/txindex (cached) -ok github.com/lazyledger/lazyledger-core/state/txindex/kv (cached) -? github.com/lazyledger/lazyledger-core/state/txindex/null [no test files] -ok github.com/lazyledger/lazyledger-core/statesync 2.662s -? github.com/lazyledger/lazyledger-core/statesync/mocks [no test files] -ok github.com/lazyledger/lazyledger-core/store 10.785s -? github.com/lazyledger/lazyledger-core/test/app [no test files] -? github.com/lazyledger/lazyledger-core/test/e2e/app [no test files] -ok github.com/lazyledger/lazyledger-core/test/e2e/generator (cached) -? github.com/lazyledger/lazyledger-core/test/e2e/pkg [no test files] -? github.com/lazyledger/lazyledger-core/test/e2e/runner [no test files] -ok github.com/lazyledger/lazyledger-core/test/e2e/tests (cached) -? github.com/lazyledger/lazyledger-core/test/maverick/consensus [no test files] -? github.com/lazyledger/lazyledger-core/tools/tm-signer-harness [no test files] -ok github.com/lazyledger/lazyledger-core/tools/tm-signer-harness/internal 0.098s -ok github.com/lazyledger/lazyledger-core/types (cached) -? github.com/lazyledger/lazyledger-core/types/consts [no test files] -ok github.com/lazyledger/lazyledger-core/types/time (cached) -? github.com/lazyledger/lazyledger-core/version [no test files] From e55d9251a928f9c4fdd13895fe0778824b1425df Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 07:58:59 -0500 Subject: [PATCH 20/25] try to make TestReactorsGossipNoCommittedEvidence less flaky --- evidence/reactor_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index a28e76e014..703d542284 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -178,9 +178,9 @@ func TestReactorsGossipNoCommittedEvidence(t *testing.T) { peer.Set(types.PeerStateKey, ps) // wait to see that only two evidence is sent - time.Sleep(1200 * time.Millisecond) + time.Sleep(1800 * time.Millisecond) - peerEv, _ = pools[1].PendingEvidence(1000) + peerEv, _ = pools[1].PendingEvidence(2000) assert.EqualValues(t, []types.Evidence{evList[0], evList[1]}, peerEv) } From b2469cccbfed2e68d07bfe765a8a69cf9373cc96 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 12:58:33 -0500 Subject: [PATCH 21/25] use ipld alias instead of format --- store/store.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/store/store.go b/store/store.go index 7f2bca9dc1..19a0aa250f 100644 --- a/store/store.go +++ b/store/store.go @@ -5,7 +5,7 @@ import ( "strconv" "github.com/gogo/protobuf/proto" - format "github.com/ipfs/go-ipld-format" + ipld "github.com/ipfs/go-ipld-format" dbm "github.com/lazyledger/lazyledger-core/libs/db" tmsync "github.com/lazyledger/lazyledger-core/libs/sync" @@ -43,12 +43,12 @@ type BlockStore struct { base int64 height int64 - ipfsDagAPI format.DAGService + ipfsDagAPI ipld.DAGService } // NewBlockStore returns a new BlockStore with the given DB, // initialized to the last height that was committed to the DB. -func NewBlockStore(db dbm.DB, dagAPI format.DAGService) *BlockStore { +func NewBlockStore(db dbm.DB, dagAPI ipld.DAGService) *BlockStore { bs := LoadBlockStoreState(db) return &BlockStore{ base: bs.Base, @@ -430,7 +430,7 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err // IpfsAPI returns the ipfs api object of the BlockStore. Fullfills the // state.BlockStore interface. -func (bs *BlockStore) IpfsDagAPI() format.DAGService { +func (bs *BlockStore) IpfsDagAPI() ipld.DAGService { return bs.ipfsDagAPI } From 8a4026c912c8e60eca5070d92c0a0a41fd30147d Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 13:08:25 -0500 Subject: [PATCH 22/25] remove access to the IPFS dag from the blockstore and add it back to consensus state --- consensus/replay_test.go | 4 ---- consensus/state.go | 5 ++++- rpc/core/blocks_test.go | 2 -- state/services.go | 3 --- store/store.go | 6 ------ 5 files changed, 4 insertions(+), 16 deletions(-) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 2c06eccfc3..781aaa38d9 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -1231,10 +1231,6 @@ func (bs *mockBlockStore) PruneBlocks(height int64) (uint64, error) { return pruned, nil } -func (bs *mockBlockStore) IpfsDagAPI() format.DAGService { - return bs.ipfsDagAPI -} - //--------------------------------------- // Test handshake/init chain diff --git a/consensus/state.go b/consensus/state.go index 0cef19e2fc..8fc5b5205d 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -12,6 +12,7 @@ import ( "time" "github.com/gogo/protobuf/proto" + format "github.com/ipfs/go-ipld-format" cfg "github.com/lazyledger/lazyledger-core/config" cstypes "github.com/lazyledger/lazyledger-core/consensus/types" "github.com/lazyledger/lazyledger-core/crypto" @@ -93,6 +94,8 @@ type State struct { // store blocks and commits blockStore sm.BlockStore + dag format.DAGService + // create and execute blocks blockExec *sm.BlockExecutor @@ -1116,7 +1119,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) { defer cancel() cs.Logger.Info("Putting Block to ipfs", "height", block.Height) // TODO: post data to IPFS in a goroutine - err = ipld.PutBlock(ctx, cs.blockStore.IpfsDagAPI(), block) + err = ipld.PutBlock(ctx, cs.dag, block) if err != nil { // If PutBlock fails we will be the only node that has the data // this means something is seriously wrong and we can not recover diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index f3fc033d99..996c83c43e 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -4,7 +4,6 @@ import ( "fmt" "testing" - format "github.com/ipfs/go-ipld-format" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -132,4 +131,3 @@ func (mockBlockStore) LoadSeenCommit(height int64) *types.Commit { retur func (mockBlockStore) PruneBlocks(height int64) (uint64, error) { return 0, nil } func (mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) { } -func (mockBlockStore) IpfsDagAPI() format.DAGService { return nil } diff --git a/state/services.go b/state/services.go index 9d9c01874b..eef7dc854d 100644 --- a/state/services.go +++ b/state/services.go @@ -1,7 +1,6 @@ package state import ( - format "github.com/ipfs/go-ipld-format" "github.com/lazyledger/lazyledger-core/types" ) @@ -32,8 +31,6 @@ type BlockStore interface { LoadBlockCommit(height int64) *types.Commit LoadSeenCommit(height int64) *types.Commit - - IpfsDagAPI() format.DAGService } //----------------------------------------------------------------------------- diff --git a/store/store.go b/store/store.go index 19a0aa250f..33e86b95fc 100644 --- a/store/store.go +++ b/store/store.go @@ -428,12 +428,6 @@ func (bs *BlockStore) SaveSeenCommit(height int64, seenCommit *types.Commit) err return bs.db.Set(calcSeenCommitKey(height), seenCommitBytes) } -// IpfsAPI returns the ipfs api object of the BlockStore. Fullfills the -// state.BlockStore interface. -func (bs *BlockStore) IpfsDagAPI() ipld.DAGService { - return bs.ipfsDagAPI -} - //----------------------------------------------------------------------------- func calcBlockMetaKey(height int64) []byte { From 1bddff26a78a02675d5118f8310f40cbad831e4e Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 13:59:32 -0500 Subject: [PATCH 23/25] change api provider to only use the dag instead of the core api object --- cmd/tendermint/commands/light.go | 6 ++-- consensus/byzantine_test.go | 5 +-- consensus/common_test.go | 6 ++-- consensus/reactor_test.go | 5 +-- consensus/replay_file.go | 7 ++-- consensus/state.go | 2 ++ consensus/wal_test.go | 6 ++-- ipfs/embedded.go | 4 +-- ipfs/mock.go | 56 ++++---------------------------- ipfs/provider.go | 2 +- light/client.go | 10 +++--- node/node.go | 16 +++++---- node/node_test.go | 4 +-- rpc/test/helpers.go | 2 +- 14 files changed, 49 insertions(+), 82 deletions(-) diff --git a/cmd/tendermint/commands/light.go b/cmd/tendermint/commands/light.go index 57332b7f0d..a1501e2b10 100644 --- a/cmd/tendermint/commands/light.go +++ b/cmd/tendermint/commands/light.go @@ -186,12 +186,12 @@ func runProxy(cmd *cobra.Command, args []string) error { cfg.RootDir = dir // TODO(ismail): share badger instance apiProvider := ipfs.Embedded(true, cfg, logger) - var coreAPI coreiface.CoreAPI - coreAPI, ipfsCloser, err = apiProvider() + var dag coreiface.APIDagService + dag, ipfsCloser, err = apiProvider() if err != nil { return fmt.Errorf("could not start ipfs API: %w", err) } - options = append(options, light.DataAvailabilitySampling(numSamples, coreAPI)) + options = append(options, light.DataAvailabilitySampling(numSamples, dag)) case sequential: options = append(options, light.SequentialVerification()) default: diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 9952363459..6876dbebba 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -56,7 +56,8 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { app.InitChain(abci.RequestInitChain{Validators: vals}) blockDB := memdb.NewDB() - blockStore := store.NewBlockStore(blockDB, mdutils.Mock()) + dag := mdutils.Mock() + blockStore := store.NewBlockStore(blockDB, dag) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -78,7 +79,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, evpool) + cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, dag, evpool) cs.SetLogger(cs.Logger) // set private validator pv := privVals[i] diff --git a/consensus/common_test.go b/consensus/common_test.go index 1234fdf8ec..6120de4e85 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -375,10 +375,10 @@ func newStateWithConfigAndBlockStore( pv types.PrivValidator, app abci.Application, blockDB dbm.DB, - ipfsDagAPI format.DAGService, + dag format.DAGService, ) *State { // Get BlockStore - blockStore := store.NewBlockStore(blockDB, ipfsDagAPI) + blockStore := store.NewBlockStore(blockDB, dag) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -402,7 +402,7 @@ func newStateWithConfigAndBlockStore( } blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyAppConnCon, mempool, evpool) - cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool) + cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, dag, evpool) cs.SetLogger(log.TestingLogger().With("module", "consensus")) cs.SetPrivValidator(pv) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 93c410ff3b..eebd78fb26 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -155,7 +155,8 @@ func TestReactorWithEvidence(t *testing.T) { // css[i] = newStateWithConfig(thisConfig, state, privVals[i], app) blockDB := memdb.NewDB() - blockStore := store.NewBlockStore(blockDB, mdutils.Mock()) + dag := mdutils.Mock() + blockStore := store.NewBlockStore(blockDB, dag) // one for mempool, one for consensus mtx := new(tmsync.Mutex) @@ -183,7 +184,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, evpool2) + cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, dag, evpool2) cs.SetLogger(log.TestingLogger().With("module", "consensus")) cs.SetPrivValidator(pv) diff --git a/consensus/replay_file.go b/consensus/replay_file.go index ab491f8437..6e2bb44ee1 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -130,7 +130,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, pb.cs.evpool) + pb.cs.blockStore, pb.cs.txNotifier, mdutils.Mock(), pb.cs.evpool) newCS.SetEventBus(pb.cs.eventBus) newCS.startForReplay() @@ -289,7 +289,8 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo if err != nil { tmos.Exit(err.Error()) } - blockStore := store.NewBlockStore(blockStoreDB, mdutils.Mock()) + dag := mdutils.Mock() + blockStore := store.NewBlockStore(blockStoreDB, dag) // Get State stateDB, err := badgerdb.NewDB("state", config.DBDir()) @@ -330,7 +331,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, evpool) + blockStore, mempool, dag, evpool) consensusState.SetEventBus(eventBus) return consensusState diff --git a/consensus/state.go b/consensus/state.go index 8fc5b5205d..e83d5cb192 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -163,6 +163,7 @@ func NewState( blockExec *sm.BlockExecutor, blockStore sm.BlockStore, txNotifier txNotifier, + dag format.DAGService, evpool evidencePool, options ...StateOption, ) *State { @@ -170,6 +171,7 @@ func NewState( config: config, blockExec: blockExec, blockStore: blockStore, + dag: dag, txNotifier: txNotifier, peerMsgQueue: make(chan msgInfo, msgQueueSize), internalMsgQueue: make(chan msgInfo, msgQueueSize), diff --git a/consensus/wal_test.go b/consensus/wal_test.go index b950c4ff02..3ab6402466 100644 --- a/consensus/wal_test.go +++ b/consensus/wal_test.go @@ -311,8 +311,8 @@ func walGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { if err = stateStore.Save(state); err != nil { t.Error(err) } - - blockStore := store.NewBlockStore(blockStoreDB, mdutils.Mock()) + dag := mdutils.Mock() + blockStore := store.NewBlockStore(blockStoreDB, dag) proxyApp := proxy.NewAppConns(proxy.NewLocalClientCreator(app)) proxyApp.SetLogger(logger.With("module", "proxy")) @@ -339,7 +339,7 @@ func walGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) { evpool := sm.EmptyEvidencePool{} blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) require.NoError(t, err) - consensusState := NewState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool) + consensusState := NewState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, dag, evpool) consensusState.SetLogger(logger) consensusState.SetEventBus(eventBus) if privValidator != nil && privValidator != (*privval.FilePV)(nil) { diff --git a/ipfs/embedded.go b/ipfs/embedded.go index 27f0fc14ec..d318f3200f 100644 --- a/ipfs/embedded.go +++ b/ipfs/embedded.go @@ -26,7 +26,7 @@ import ( // Embedded is the provider that embeds IPFS node within the same process. // It also returns closable for graceful node shutdown. func Embedded(init bool, cfg *Config, logger log.Logger) APIProvider { - return func() (coreiface.CoreAPI, io.Closer, error) { + return func() (coreiface.APIDagService, io.Closer, error) { path := cfg.Path() defer os.Setenv(ipfscfg.EnvDir, path) @@ -87,7 +87,7 @@ func Embedded(init bool, cfg *Config, logger log.Logger) APIProvider { } logger.Info("Successfully created embedded IPFS node", "ipfs-repo", path) - return api, node, nil + return api.Dag(), node, nil } } diff --git a/ipfs/mock.go b/ipfs/mock.go index 8d2f9d4f95..e7e7282c62 100644 --- a/ipfs/mock.go +++ b/ipfs/mock.go @@ -1,68 +1,26 @@ package ipfs import ( - "context" "io" - "github.com/ipfs/go-ipfs/core/coreapi" - coremock "github.com/ipfs/go-ipfs/core/mock" - format "github.com/ipfs/go-ipld-format" + ipld "github.com/ipfs/go-ipld-format" mdutils "github.com/ipfs/go-merkledag/test" coreiface "github.com/ipfs/interface-go-ipfs-core" - "github.com/ipfs/interface-go-ipfs-core/options" - "github.com/ipfs/interface-go-ipfs-core/path" - - "github.com/lazyledger/lazyledger-core/ipfs/plugin" ) // Mock provides simple mock IPFS API useful for testing func Mock() APIProvider { - return func() (coreiface.CoreAPI, io.Closer, error) { - plugin.EnableNMT() - - nd, err := coremock.NewMockNode() - if err != nil { - return nil, nil, err - } - - api, err := coreapi.NewCoreAPI(nd) - if err != nil { - return nil, nil, err - } - - return api, nd, nil - } -} + return func() (coreiface.APIDagService, io.Closer, error) { + dom := dagOnlyMock{mdutils.Mock()} -// DagOnlyMock provides an empty APIProvider that only mocks the DAG portion of -// the ipfs api object. This is much lighter than the full IPFS node and should -// be favored for CI testing -func DagOnlyMock() APIProvider { - mockAPI := dagOnlyMock{mdutils.Mock()} - return func() (coreiface.CoreAPI, io.Closer, error) { - return mockAPI, mockAPI, nil + return dom, dom, nil } } -var _ coreiface.CoreAPI = dagOnlyMock{} - type dagOnlyMock struct { - format.DAGService + ipld.DAGService } func (dom dagOnlyMock) Dag() coreiface.APIDagService { return dom } - -func (dagOnlyMock) Unixfs() coreiface.UnixfsAPI { return nil } -func (dagOnlyMock) Block() coreiface.BlockAPI { return nil } -func (dagOnlyMock) Name() coreiface.NameAPI { return nil } -func (dagOnlyMock) Key() coreiface.KeyAPI { return nil } -func (dagOnlyMock) Pin() coreiface.PinAPI { return nil } -func (dagOnlyMock) Object() coreiface.ObjectAPI { return nil } -func (dagOnlyMock) Dht() coreiface.DhtAPI { return nil } -func (dagOnlyMock) Swarm() coreiface.SwarmAPI { return nil } -func (dagOnlyMock) PubSub() coreiface.PubSubAPI { return nil } -func (dagOnlyMock) ResolvePath(context.Context, path.Path) (path.Resolved, error) { return nil, nil } -func (dagOnlyMock) ResolveNode(context.Context, path.Path) (format.Node, error) { return nil, nil } -func (dagOnlyMock) WithOptions(...options.ApiOption) (coreiface.CoreAPI, error) { return nil, nil } -func (dagOnlyMock) Close() error { return nil } -func (dagOnlyMock) Pinning() format.NodeAdder { return nil } +func (dagOnlyMock) Close() error { return nil } +func (dom dagOnlyMock) Pinning() ipld.NodeAdder { return dom } diff --git a/ipfs/provider.go b/ipfs/provider.go index 9266350c19..d7575526ae 100644 --- a/ipfs/provider.go +++ b/ipfs/provider.go @@ -7,4 +7,4 @@ import ( ) // APIProvider allows customizable IPFS core APIs. -type APIProvider func() (coreiface.CoreAPI, io.Closer, error) +type APIProvider func() (coreiface.APIDagService, io.Closer, error) diff --git a/light/client.go b/light/client.go index 06f9d2360b..d0a38a2c18 100644 --- a/light/client.go +++ b/light/client.go @@ -71,12 +71,12 @@ func SkippingVerification(trustLevel tmmath.Fraction) Option { } } -func DataAvailabilitySampling(numSamples uint32, ipfsAPI coreiface.CoreAPI) Option { +func DataAvailabilitySampling(numSamples uint32, ipfsAPI coreiface.APIDagService) Option { return func(c *Client) { c.verificationMode = dataAvailabilitySampling c.numSamples = numSamples - c.ipfsCoreAPI = ipfsAPI - c.dag = merkledag.NewSession(context.TODO(), ipfsAPI.Dag()) + c.dag = ipfsAPI + c.sessionDAG = merkledag.NewSession(context.TODO(), ipfsAPI) } } @@ -157,8 +157,8 @@ type Client struct { logger log.Logger - ipfsCoreAPI coreiface.CoreAPI - dag format.NodeGetter + dag coreiface.APIDagService + sessionDAG format.NodeGetter } // NewClient returns a new light client. It returns an error if it fails to diff --git a/node/node.go b/node/node.go index edfc99c9c2..3d123f8a32 100644 --- a/node/node.go +++ b/node/node.go @@ -12,6 +12,7 @@ import ( "strings" "time" + format "github.com/ipfs/go-ipld-format" iface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -221,14 +222,14 @@ type Node struct { func initDBs( config *cfg.Config, dbProvider DBProvider, - ipfsAPI iface.CoreAPI, + dag iface.APIDagService, ) (blockStore *store.BlockStore, stateDB dbm.DB, err error) { var blockStoreDB dbm.DB blockStoreDB, err = dbProvider(&DBContext{"blockstore", config}) if err != nil { return } - blockStore = store.NewBlockStore(blockStoreDB, ipfsAPI.Dag()) + blockStore = store.NewBlockStore(blockStoreDB, dag) stateDB, err = dbProvider(&DBContext{"state", config}) if err != nil { @@ -388,7 +389,8 @@ func createBlockchainReactor(config *cfg.Config, return bcReactor, nil } -func createConsensusReactor(config *cfg.Config, +func createConsensusReactor( + config *cfg.Config, state sm.State, blockExec *sm.BlockExecutor, blockStore sm.BlockStore, @@ -398,6 +400,7 @@ func createConsensusReactor(config *cfg.Config, csMetrics *cs.Metrics, waitSync bool, eventBus *types.EventBus, + dag format.DAGService, consensusLogger log.Logger) (*cs.Reactor, *cs.State) { consensusState := cs.NewState( @@ -406,6 +409,7 @@ func createConsensusReactor(config *cfg.Config, blockExec, blockStore, mempool, + dag, evidencePool, cs.StateMetrics(csMetrics), ) @@ -639,12 +643,12 @@ func NewNode(config *cfg.Config, logger log.Logger, options ...Option) (*Node, error) { - ipfs, ipfsclose, err := ipfsProvider() + dag, ipfsclose, err := ipfsProvider() if err != nil { return nil, err } - blockStore, stateDB, err := initDBs(config, dbProvider, ipfs) + blockStore, stateDB, err := initDBs(config, dbProvider, dag) if err != nil { return nil, err } @@ -758,7 +762,7 @@ func NewNode(config *cfg.Config, } consensusReactor, consensusState := createConsensusReactor( config, state, blockExec, blockStore, mempool, evidencePool, - privValidator, csMetrics, stateSync || fastSync, eventBus, consensusLogger, + privValidator, csMetrics, stateSync || fastSync, eventBus, dag, consensusLogger, ) // Set up state sync reactor, and schedule a sync if requested. diff --git a/node/node_test.go b/node/node_test.go index b83e993037..b2d4d560a2 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -53,7 +53,7 @@ func defaultNewTestNode(config *cfg.Config, logger log.Logger) (*Node, error) { proxy.DefaultClientCreator(config.ProxyApp, config.DBDir()), DefaultGenesisDocProviderFunc(config), InMemDBProvider, - ipfs.DagOnlyMock(), + ipfs.Mock(), DefaultMetricsProvider(config.Instrumentation), logger, ) @@ -540,7 +540,7 @@ func TestNodeNewNodeCustomReactors(t *testing.T) { proxy.DefaultClientCreator(config.ProxyApp, config.DBDir()), DefaultGenesisDocProviderFunc(config), InMemDBProvider, - ipfs.DagOnlyMock(), + ipfs.Mock(), DefaultMetricsProvider(config.Instrumentation), log.TestingLogger(), CustomReactors(map[string]p2p.Reactor{"FOO": cr, "BLOCKCHAIN": customBlockchainReactor}), diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 5db5728859..5a8b8e747a 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -176,7 +176,7 @@ func NewTendermint(app abci.Application, opts *Options) *nm.Node { node, err := nm.NewNode(config, pv, nodeKey, papp, nm.DefaultGenesisDocProviderFunc(config), nm.InMemDBProvider, - ipfs.DagOnlyMock(), + ipfs.Mock(), nm.DefaultMetricsProvider(config.Instrumentation), logger, ) From 71bcef769e54039c6a13738c001266bcbcbb61e0 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 14:06:21 -0500 Subject: [PATCH 24/25] change alias to ipld in node package --- node/node.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/node.go b/node/node.go index 3d123f8a32..00ed08bf98 100644 --- a/node/node.go +++ b/node/node.go @@ -12,7 +12,7 @@ import ( "strings" "time" - format "github.com/ipfs/go-ipld-format" + ipld "github.com/ipfs/go-ipld-format" iface "github.com/ipfs/interface-go-ipfs-core" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -400,7 +400,7 @@ func createConsensusReactor( csMetrics *cs.Metrics, waitSync bool, eventBus *types.EventBus, - dag format.DAGService, + dag ipld.DAGService, consensusLogger log.Logger) (*cs.Reactor, *cs.State) { consensusState := cs.NewState( From 0ce8cec83961f32772dd72b5f8a7e210188f868b Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 27 May 2021 14:19:57 -0500 Subject: [PATCH 25/25] increase timeouts for TestWALTruncate and timeoutWaitGroup for CI --- consensus/reactor_test.go | 2 +- consensus/wal_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index eebd78fb26..25b090835a 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -671,7 +671,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 * 6 + timeout := time.Minute * 8 select { case <-done: diff --git a/consensus/wal_test.go b/consensus/wal_test.go index 3ab6402466..3dc0170219 100644 --- a/consensus/wal_test.go +++ b/consensus/wal_test.go @@ -67,7 +67,7 @@ func TestWALTruncate(t *testing.T) { err = walGenerateNBlocks(t, wal.Group(), 60) require.NoError(t, err) - time.Sleep(1 * time.Millisecond) // wait groupCheckDuration, make sure RotateFile run + time.Sleep(5 * time.Millisecond) // wait groupCheckDuration, make sure RotateFile run if err := wal.FlushAndSync(); err != nil { t.Error(err)