From d21f39160f8196efde81a85816a6739a35e51295 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 13 Dec 2017 18:34:17 +0100 Subject: [PATCH] Apply ConsensusParamChanges to state/State --- state/state.go | 10 ++++++++-- types/params.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/state/state.go b/state/state.go index 3c9333b75..3b04cd69c 100644 --- a/state/state.go +++ b/state/state.go @@ -251,17 +251,22 @@ func (s *State) SetBlockAndValidators(header *types.Header, blockPartsHeader typ // Update validator accums and set state variables nextValSet.IncrementAccum(1) + nextParams := s.Params.ApplyChanges( + abciResponses.EndBlock.ConsensusParamChanges) + s.setBlockAndValidators(header.Height, header.NumTxs, types.BlockID{header.Hash(), blockPartsHeader}, header.Time, - prevValSet, nextValSet) + prevValSet, nextValSet, + nextParams) } func (s *State) setBlockAndValidators(height int64, newTxs int64, blockID types.BlockID, blockTime time.Time, - prevValSet, nextValSet *types.ValidatorSet) { + prevValSet, nextValSet *types.ValidatorSet, + nextParams types.ConsensusParams) { s.LastBlockHeight = height s.LastBlockTotalTx += newTxs @@ -269,6 +274,7 @@ func (s *State) setBlockAndValidators(height int64, s.LastBlockTime = blockTime s.Validators = nextValSet s.LastValidators = prevValSet + s.Params = nextParams } // GetValidators returns the last and current validator sets. diff --git a/types/params.go b/types/params.go index 322cba612..4047913c3 100644 --- a/types/params.go +++ b/types/params.go @@ -2,6 +2,8 @@ package types import ( "github.com/pkg/errors" + + abci "github.com/tendermint/abci/types" ) const ( @@ -16,6 +18,42 @@ type ConsensusParams struct { BlockGossipParams `json:"block_gossip_params"` } +// ApplyChanges returns a new param set, overriding any +// parameter that is non-zero in argument +func (p ConsensusParams) ApplyChanges(c *abci.ConsensusParams) ConsensusParams { + if c == nil { + return p + } + res := p + // we must defensively consider any structs may be nil + if c.BlockSizeParams != nil { + + if c.BlockSizeParams.MaxBytes != 0 { + res.BlockSizeParams.MaxBytes = int(c.BlockSizeParams.MaxBytes) + } + if c.BlockSizeParams.MaxTxs != 0 { + res.BlockSizeParams.MaxTxs = int(c.BlockSizeParams.MaxTxs) + } + if c.BlockSizeParams.MaxGas != 0 { + res.BlockSizeParams.MaxGas = int(c.BlockSizeParams.MaxGas) + } + } + if c.TxSizeParams != nil { + if c.TxSizeParams.MaxBytes != 0 { + res.TxSizeParams.MaxBytes = int(c.TxSizeParams.MaxBytes) + } + if c.TxSizeParams.MaxGas != 0 { + res.TxSizeParams.MaxGas = int(c.TxSizeParams.MaxGas) + } + } + if c.BlockGossipParams != nil { + if c.BlockGossipParams.BlockPartSizeBytes != 0 { + res.BlockGossipParams.BlockPartSizeBytes = int(c.BlockGossipParams.BlockPartSizeBytes) + } + } + return res +} + // BlockSizeParams contain limits on the block size. type BlockSizeParams struct { MaxBytes int `json:"max_bytes"` // NOTE: must not be 0 nor greater than 100MB