mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 12:51:22 +00:00
dont use pointers for ConsensusParams
This commit is contained in:
@ -570,13 +570,13 @@ func stateAndStore(config *cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBl
|
|||||||
|
|
||||||
type mockBlockStore struct {
|
type mockBlockStore struct {
|
||||||
config *cfg.Config
|
config *cfg.Config
|
||||||
params *types.ConsensusParams
|
params types.ConsensusParams
|
||||||
chain []*types.Block
|
chain []*types.Block
|
||||||
commits []*types.Commit
|
commits []*types.Commit
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: NewBlockStore(db.NewMemDB) ...
|
// 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}
|
return &mockBlockStore{config, params, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +263,9 @@ func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet) {
|
|||||||
|
|
||||||
// Params returns the consensus parameters used for
|
// Params returns the consensus parameters used for
|
||||||
// validating blocks
|
// 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
|
return s.GenesisDoc.ConsensusParams
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ type GenesisValidator struct {
|
|||||||
type GenesisDoc struct {
|
type GenesisDoc struct {
|
||||||
GenesisTime time.Time `json:"genesis_time"`
|
GenesisTime time.Time `json:"genesis_time"`
|
||||||
ChainID string `json:"chain_id"`
|
ChainID string `json:"chain_id"`
|
||||||
ConsensusParams *ConsensusParams `json:"consensus_params"`
|
ConsensusParams ConsensusParams `json:"consensus_params"`
|
||||||
Validators []GenesisValidator `json:"validators"`
|
Validators []GenesisValidator `json:"validators"`
|
||||||
AppHash data.Bytes `json:"app_hash"`
|
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")
|
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()
|
genDoc.ConsensusParams = DefaultConsensusParams()
|
||||||
} else {
|
} else {
|
||||||
if err := genDoc.ConsensusParams.Validate(); err != nil {
|
if err := genDoc.ConsensusParams.Validate(); err != nil {
|
||||||
|
@ -60,10 +60,10 @@ func TestGenesis(t *testing.T) {
|
|||||||
assert.Error(t, err, "expected error for genDoc json with block size of 0")
|
assert.Error(t, err, "expected error for genDoc json with block size of 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConsensusParams(blockSize, partSize int) *ConsensusParams {
|
func newConsensusParams(blockSize, partSize int) ConsensusParams {
|
||||||
return &ConsensusParams{
|
return ConsensusParams{
|
||||||
BlockSizeParams: &BlockSizeParams{MaxBytes: blockSize},
|
BlockSizeParams: BlockSizeParams{MaxBytes: blockSize},
|
||||||
BlockGossipParams: &BlockGossipParams{BlockPartSizeBytes: partSize},
|
BlockGossipParams: BlockGossipParams{BlockPartSizeBytes: partSize},
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ func newConsensusParams(blockSize, partSize int) *ConsensusParams {
|
|||||||
func TestConsensusParams(t *testing.T) {
|
func TestConsensusParams(t *testing.T) {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
params *ConsensusParams
|
params ConsensusParams
|
||||||
valid bool
|
valid bool
|
||||||
}{
|
}{
|
||||||
{newConsensusParams(1, 1), true},
|
{newConsensusParams(1, 1), true},
|
||||||
|
@ -11,9 +11,9 @@ const (
|
|||||||
// ConsensusParams contains consensus critical parameters
|
// ConsensusParams contains consensus critical parameters
|
||||||
// that determine the validity of blocks.
|
// that determine the validity of blocks.
|
||||||
type ConsensusParams struct {
|
type ConsensusParams struct {
|
||||||
*BlockSizeParams `json:"block_size_params"`
|
BlockSizeParams `json:"block_size_params"`
|
||||||
*TxSizeParams `json:"tx_size_params"`
|
TxSizeParams `json:"tx_size_params"`
|
||||||
*BlockGossipParams `json:"block_gossip_params"`
|
BlockGossipParams `json:"block_gossip_params"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockSizeParams contain limits on the block size.
|
// BlockSizeParams contain limits on the block size.
|
||||||
@ -35,8 +35,8 @@ type BlockGossipParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConsensusParams returns a default ConsensusParams.
|
// DefaultConsensusParams returns a default ConsensusParams.
|
||||||
func DefaultConsensusParams() *ConsensusParams {
|
func DefaultConsensusParams() ConsensusParams {
|
||||||
return &ConsensusParams{
|
return ConsensusParams{
|
||||||
DefaultBlockSizeParams(),
|
DefaultBlockSizeParams(),
|
||||||
DefaultTxSizeParams(),
|
DefaultTxSizeParams(),
|
||||||
DefaultBlockGossipParams(),
|
DefaultBlockGossipParams(),
|
||||||
@ -44,8 +44,8 @@ func DefaultConsensusParams() *ConsensusParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBlockSizeParams returns a default BlockSizeParams.
|
// DefaultBlockSizeParams returns a default BlockSizeParams.
|
||||||
func DefaultBlockSizeParams() *BlockSizeParams {
|
func DefaultBlockSizeParams() BlockSizeParams {
|
||||||
return &BlockSizeParams{
|
return BlockSizeParams{
|
||||||
MaxBytes: 22020096, // 21MB
|
MaxBytes: 22020096, // 21MB
|
||||||
MaxTxs: 100000,
|
MaxTxs: 100000,
|
||||||
MaxGas: -1,
|
MaxGas: -1,
|
||||||
@ -53,16 +53,16 @@ func DefaultBlockSizeParams() *BlockSizeParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DefaultTxSizeParams returns a default TxSizeParams.
|
// DefaultTxSizeParams returns a default TxSizeParams.
|
||||||
func DefaultTxSizeParams() *TxSizeParams {
|
func DefaultTxSizeParams() TxSizeParams {
|
||||||
return &TxSizeParams{
|
return TxSizeParams{
|
||||||
MaxBytes: 10240, // 10kB
|
MaxBytes: 10240, // 10kB
|
||||||
MaxGas: -1,
|
MaxGas: -1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBlockGossipParams returns a default BlockGossipParams.
|
// DefaultBlockGossipParams returns a default BlockGossipParams.
|
||||||
func DefaultBlockGossipParams() *BlockGossipParams {
|
func DefaultBlockGossipParams() BlockGossipParams {
|
||||||
return &BlockGossipParams{
|
return BlockGossipParams{
|
||||||
BlockPartSizeBytes: 65536, // 64kB,
|
BlockPartSizeBytes: 65536, // 64kB,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,9 +79,9 @@ func (params *ConsensusParams) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure blocks aren't too big
|
// 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",
|
return errors.Errorf("BlockSizeParams.MaxBytes is too big. %d > %d",
|
||||||
cp.BlockSizeParams.MaxBytes, maxBlockSizeBytes)
|
params.BlockSizeParams.MaxBytes, maxBlockSizeBytes)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user