Browse Source

dont use pointers for ConsensusParams

pull/650/head
Ethan Buchman 7 years ago
parent
commit
5feeb65cf0
5 changed files with 26 additions and 23 deletions
  1. +2
    -2
      consensus/replay_test.go
  2. +3
    -1
      state/state.go
  3. +3
    -2
      types/genesis.go
  4. +5
    -5
      types/genesis_test.go
  5. +13
    -13
      types/params.go

+ 2
- 2
consensus/replay_test.go View File

@ -570,13 +570,13 @@ func stateAndStore(config *cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBl
type mockBlockStore struct {
config *cfg.Config
params *types.ConsensusParams
params types.ConsensusParams
chain []*types.Block
commits []*types.Commit
}
// TODO: NewBlockStore(db.NewMemDB) ...
func NewMockBlockStore(config *cfg.Config, params *types.ConsensusParams) *mockBlockStore {
func NewMockBlockStore(config *cfg.Config, params types.ConsensusParams) *mockBlockStore {
return &mockBlockStore{config, params, nil, nil}
}


+ 3
- 1
state/state.go View File

@ -263,7 +263,9 @@ func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet) {
// Params returns the consensus parameters used for
// validating blocks
func (s *State) Params() *types.ConsensusParams {
func (s *State) Params() types.ConsensusParams {
// TODO: this should move into the State proper
// when we allow the app to change it
return s.GenesisDoc.ConsensusParams
}


+ 3
- 2
types/genesis.go View File

@ -26,7 +26,7 @@ type GenesisValidator struct {
type GenesisDoc struct {
GenesisTime time.Time `json:"genesis_time"`
ChainID string `json:"chain_id"`
ConsensusParams *ConsensusParams `json:"consensus_params"`
ConsensusParams ConsensusParams `json:"consensus_params"`
Validators []GenesisValidator `json:"validators"`
AppHash data.Bytes `json:"app_hash"`
}
@ -58,7 +58,8 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
return errors.Errorf("Genesis doc must include non-empty chain_id")
}
if genDoc.ConsensusParams == nil {
var emptyParams ConsensusParams
if genDoc.ConsensusParams == emptyParams {
genDoc.ConsensusParams = DefaultConsensusParams()
} else {
if err := genDoc.ConsensusParams.Validate(); err != nil {


+ 5
- 5
types/genesis_test.go View File

@ -60,10 +60,10 @@ func TestGenesis(t *testing.T) {
assert.Error(t, err, "expected error for genDoc json with block size of 0")
}
func newConsensusParams(blockSize, partSize int) *ConsensusParams {
return &ConsensusParams{
BlockSizeParams: &BlockSizeParams{MaxBytes: blockSize},
BlockGossipParams: &BlockGossipParams{BlockPartSizeBytes: partSize},
func newConsensusParams(blockSize, partSize int) ConsensusParams {
return ConsensusParams{
BlockSizeParams: BlockSizeParams{MaxBytes: blockSize},
BlockGossipParams: BlockGossipParams{BlockPartSizeBytes: partSize},
}
}
@ -71,7 +71,7 @@ func newConsensusParams(blockSize, partSize int) *ConsensusParams {
func TestConsensusParams(t *testing.T) {
testCases := []struct {
params *ConsensusParams
params ConsensusParams
valid bool
}{
{newConsensusParams(1, 1), true},


+ 13
- 13
types/params.go View File

@ -11,9 +11,9 @@ const (
// ConsensusParams contains consensus critical parameters
// that determine the validity of blocks.
type ConsensusParams struct {
*BlockSizeParams `json:"block_size_params"`
*TxSizeParams `json:"tx_size_params"`
*BlockGossipParams `json:"block_gossip_params"`
BlockSizeParams `json:"block_size_params"`
TxSizeParams `json:"tx_size_params"`
BlockGossipParams `json:"block_gossip_params"`
}
// BlockSizeParams contain limits on the block size.
@ -35,8 +35,8 @@ type BlockGossipParams struct {
}
// DefaultConsensusParams returns a default ConsensusParams.
func DefaultConsensusParams() *ConsensusParams {
return &ConsensusParams{
func DefaultConsensusParams() ConsensusParams {
return ConsensusParams{
DefaultBlockSizeParams(),
DefaultTxSizeParams(),
DefaultBlockGossipParams(),
@ -44,8 +44,8 @@ func DefaultConsensusParams() *ConsensusParams {
}
// DefaultBlockSizeParams returns a default BlockSizeParams.
func DefaultBlockSizeParams() *BlockSizeParams {
return &BlockSizeParams{
func DefaultBlockSizeParams() BlockSizeParams {
return BlockSizeParams{
MaxBytes: 22020096, // 21MB
MaxTxs: 100000,
MaxGas: -1,
@ -53,16 +53,16 @@ func DefaultBlockSizeParams() *BlockSizeParams {
}
// DefaultTxSizeParams returns a default TxSizeParams.
func DefaultTxSizeParams() *TxSizeParams {
return &TxSizeParams{
func DefaultTxSizeParams() TxSizeParams {
return TxSizeParams{
MaxBytes: 10240, // 10kB
MaxGas: -1,
}
}
// DefaultBlockGossipParams returns a default BlockGossipParams.
func DefaultBlockGossipParams() *BlockGossipParams {
return &BlockGossipParams{
func DefaultBlockGossipParams() BlockGossipParams {
return BlockGossipParams{
BlockPartSizeBytes: 65536, // 64kB,
}
}
@ -79,9 +79,9 @@ func (params *ConsensusParams) Validate() error {
}
// ensure blocks aren't too big
if cp.BlockSizeParams.MaxBytes > maxBlockSizeBytes {
if params.BlockSizeParams.MaxBytes > maxBlockSizeBytes {
return errors.Errorf("BlockSizeParams.MaxBytes is too big. %d > %d",
cp.BlockSizeParams.MaxBytes, maxBlockSizeBytes)
params.BlockSizeParams.MaxBytes, maxBlockSizeBytes)
}
return nil
}

Loading…
Cancel
Save