Browse Source

remove viper from blockchain and state

pull/484/head
Ethan Buchman 7 years ago
parent
commit
29c0e6e4f4
4 changed files with 10 additions and 12 deletions
  1. +2
    -6
      blockchain/reactor.go
  2. +2
    -2
      node/node.go
  3. +2
    -3
      state/state.go
  4. +4
    -1
      types/block.go

+ 2
- 6
blockchain/reactor.go View File

@ -6,8 +6,6 @@ import (
"reflect" "reflect"
"time" "time"
"github.com/spf13/viper"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
@ -44,7 +42,6 @@ type consensusReactor interface {
type BlockchainReactor struct { type BlockchainReactor struct {
p2p.BaseReactor p2p.BaseReactor
config *viper.Viper
state *sm.State state *sm.State
proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn proxyAppConn proxy.AppConnConsensus // same as consensus.proxyAppConn
store *BlockStore store *BlockStore
@ -58,7 +55,7 @@ type BlockchainReactor struct {
} }
// NewBlockchainReactor returns new reactor instance. // NewBlockchainReactor returns new reactor instance.
func NewBlockchainReactor(config *viper.Viper, state *sm.State, proxyAppConn proxy.AppConnConsensus, store *BlockStore, fastSync bool) *BlockchainReactor {
func NewBlockchainReactor(state *sm.State, proxyAppConn proxy.AppConnConsensus, store *BlockStore, fastSync bool) *BlockchainReactor {
if state.LastBlockHeight == store.Height()-1 { if state.LastBlockHeight == store.Height()-1 {
store.height-- // XXX HACK, make this better store.height-- // XXX HACK, make this better
} }
@ -73,7 +70,6 @@ func NewBlockchainReactor(config *viper.Viper, state *sm.State, proxyAppConn pro
timeoutsCh, timeoutsCh,
) )
bcR := &BlockchainReactor{ bcR := &BlockchainReactor{
config: config,
state: state, state: state,
proxyAppConn: proxyAppConn, proxyAppConn: proxyAppConn,
store: store, store: store,
@ -226,7 +222,7 @@ FOR_LOOP:
// We need both to sync the first block. // We need both to sync the first block.
break SYNC_LOOP break SYNC_LOOP
} }
firstParts := first.MakePartSet(bcR.config.GetInt("block_part_size")) // TODO: put part size in parts header?
firstParts := first.MakePartSet(types.DefaultPartSetSize)
firstPartsHeader := firstParts.Header() firstPartsHeader := firstParts.Header()
// Finally, verify the first block using the second's commit // Finally, verify the first block using the second's commit
// NOTE: we can probably make this more efficient, but note that calling // NOTE: we can probably make this more efficient, but note that calling


+ 2
- 2
node/node.go View File

@ -73,7 +73,7 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea
// Get State // Get State
stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir")) stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir"))
state := sm.GetState(config, stateDB)
state := sm.GetState(stateDB, config.GetString("genesis_file"))
// add the chainid and number of validators to the global config // add the chainid and number of validators to the global config
config.Set("chain_id", state.ChainID) config.Set("chain_id", state.ChainID)
@ -121,7 +121,7 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea
} }
// Make BlockchainReactor // Make BlockchainReactor
bcReactor := bc.NewBlockchainReactor(config, state.Copy(), proxyApp.Consensus(), blockStore, fastSync)
bcReactor := bc.NewBlockchainReactor(state.Copy(), proxyApp.Consensus(), blockStore, fastSync)
// Make MempoolReactor // Make MempoolReactor
mempool := mempl.NewMempool(config, proxyApp.Mempool()) mempool := mempl.NewMempool(config, proxyApp.Mempool())


+ 2
- 3
state/state.go View File

@ -6,7 +6,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tmlibs/db"
@ -169,10 +168,10 @@ func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet) {
// Load the most recent state from "state" db, // Load the most recent state from "state" db,
// or create a new one (and save) from genesis. // or create a new one (and save) from genesis.
func GetState(config *viper.Viper, stateDB dbm.DB) *State {
func GetState(stateDB dbm.DB, genesisFile string) *State {
state := LoadState(stateDB) state := LoadState(stateDB)
if state == nil { if state == nil {
state = MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
state = MakeGenesisStateFromFile(stateDB, genesisFile)
state.Save() state.Save()
} }


+ 4
- 1
types/block.go View File

@ -14,7 +14,10 @@ import (
"github.com/tendermint/tmlibs/merkle" "github.com/tendermint/tmlibs/merkle"
) )
const MaxBlockSize = 22020096 // 21MB TODO make it configurable
const (
MaxBlockSize = 22020096 // 21MB TODO make it configurable
DefaultPartSetSize = 65536 // 64kB TODO: put part size in parts header?
)
type Block struct { type Block struct {
*Header `json:"header"` *Header `json:"header"`


Loading…
Cancel
Save