Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager): use block params from consensus param #1042

Merged
merged 19 commits into from
Sep 6, 2024
1 change: 0 additions & 1 deletion block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
// Update the state with the new app hash, and store height from the commit.
// Every one of those, if happens before commit, prevents us from re-executing the block in case failed during commit.
m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block.Header.Height)
m.ValidateConsensusBlockParams()
}

// check if the proposer needs to be changed
Expand Down
37 changes: 11 additions & 26 deletions block/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmcrypto "github.com/tendermint/tendermint/crypto/encoding"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proxy"
tmtypes "github.com/tendermint/tendermint/types"
"go.uber.org/multierr"
Expand All @@ -16,6 +15,9 @@ import (
"github.com/dymensionxyz/dymint/types"
)

// default minimum block max size allowed. not specific reason to set it to 10K, but we need to avoid no transactions can be included in a block.
const minBlockMaxBytes = 10000

// Executor creates and applies blocks and maintains state.
type Executor struct {
localAddress []byte
Expand Down Expand Up @@ -60,37 +62,20 @@ func (e *Executor) InitChain(genesis *tmtypes.GenesisDoc, valset []*tmtypes.Vali
Power: validator.VotingPower,
})
}
params := genesis.ConsensusParams

return e.proxyAppConsensusConn.InitChainSync(abci.RequestInitChain{
Time: genesis.GenesisTime,
ChainId: genesis.ChainID,
ConsensusParams: &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: params.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: params.Evidence.MaxAgeDuration,
MaxBytes: params.Evidence.MaxBytes,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: params.Validator.PubKeyTypes,
},
Version: &tmproto.VersionParams{
AppVersion: params.Version.AppVersion,
},
},
Validators: valUpdates,
AppStateBytes: genesis.AppState,
InitialHeight: genesis.InitialHeight,
Time: genesis.GenesisTime,
ChainId: genesis.ChainID,
ConsensusParams: &abci.ConsensusParams{},
omritoptix marked this conversation as resolved.
Show resolved Hide resolved
Validators: valUpdates,
AppStateBytes: genesis.AppState,
InitialHeight: genesis.InitialHeight,
})
}

// CreateBlock reaps transactions from mempool and builds a block.
func (e *Executor) CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash, nextSeqHash [32]byte, state *types.State, maxBlockDataSizeBytes uint32) *types.Block {
maxBlockDataSizeBytes = min(maxBlockDataSizeBytes, uint32(state.ConsensusParams.Block.MaxBytes))
func (e *Executor) CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash, nextSeqHash [32]byte, state *types.State, maxBlockDataSizeBytes uint64) *types.Block {
maxBlockDataSizeBytes = min(maxBlockDataSizeBytes, uint64(max(minBlockMaxBytes, state.ConsensusParams.Block.MaxBytes)))
mempoolTxs := e.mempool.ReapMaxBytesMaxGas(int64(maxBlockDataSizeBytes), state.ConsensusParams.Block.MaxGas)

block := &types.Block{
Expand Down
6 changes: 3 additions & 3 deletions block/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCreateBlock(t *testing.T) {
executor, err := block.NewExecutor([]byte("test address"), "test", mpool, proxy.NewAppConns(clientCreator), nil, logger)
assert.NoError(err)

maxBytes := uint32(100)
maxBytes := uint64(100)

// Create a valid proposer for the block
proposerKey := ed25519.GenPrivKey()
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestApplyBlock(t *testing.T) {
state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1)))
state.InitialHeight = 1
state.SetHeight(0)
maxBytes := uint32(1000)
maxBytes := uint64(10000)
state.ConsensusParams.Block.MaxBytes = int64(maxBytes)
state.ConsensusParams.Block.MaxGas = 100000
state.RollappParams.Da = "mock"
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestApplyBlock(t *testing.T) {
require.NoError(mpool.CheckTx([]byte{0, 1, 2, 3, 4}, func(r *abci.Response) {}, mempool.TxInfo{}))
require.NoError(mpool.CheckTx([]byte{5, 6, 7, 8, 9}, func(r *abci.Response) {}, mempool.TxInfo{}))
require.NoError(mpool.CheckTx([]byte{1, 2, 3, 4, 5}, func(r *abci.Response) {}, mempool.TxInfo{}))
require.NoError(mpool.CheckTx(make([]byte, 90), func(r *abci.Response) {}, mempool.TxInfo{}))
require.NoError(mpool.CheckTx(make([]byte, 9990), func(r *abci.Response) {}, mempool.TxInfo{}))
block = executor.CreateBlock(2, commit, [32]byte{}, [32]byte(state.Sequencers.ProposerHash()), state, maxBytes)
require.NotNil(block)
assert.Equal(uint64(2), block.Header.Height)
Expand Down
1 change: 0 additions & 1 deletion block/initchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func (m *Manager) RunInitChain(ctx context.Context) error {
}
// update the state with only the consensus pubkey
m.Executor.UpdateStateAfterInitChain(m.State, res)
m.ValidateConsensusBlockParams()
m.Executor.UpdateMempoolAfterInitChain(m.State)
if _, err := m.Store.SaveState(m.State, nil); err != nil {
return err
Expand Down
14 changes: 0 additions & 14 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ import (
"github.com/dymensionxyz/dymint/types"
)

// default minimum block max size allowed. not specific reason to set it to 10K, but we need to avoid no transactions can be included in a block.
const minBlockMaxBytes = 10000

// Manager is responsible for aggregating transactions into blocks.
type Manager struct {
logger types.Logger
Expand Down Expand Up @@ -327,14 +324,3 @@ func (m *Manager) setDA(daconfig string, dalcKV store.KV, logger log.Logger) err
m.Retriever = retriever
return nil
}

func (m *Manager) ValidateConsensusBlockParams() {
if m.State.ConsensusParams.Block.MaxBytes < minBlockMaxBytes {
m.logger.Info("Block max bytes in consensus params lower than minimum accepted in consensus params. Using minimum accepted as max block bytes.", "block_max_bytes", m.State.ConsensusParams.Block.MaxBytes, "min_max_bytes", minBlockMaxBytes)
m.State.ConsensusParams.Block.MaxBytes = minBlockMaxBytes
}
if m.State.ConsensusParams.Block.MaxBytes > int64(m.Conf.BatchSubmitBytes) {
m.logger.Info("Block max bytes in consensus params higher than DA batch size. Using DA batch size as max block bytes.", "block_max_bytes", m.State.ConsensusParams.Block.MaxBytes, "DA_batch_size", m.Conf.BatchSubmitBytes)
m.State.ConsensusParams.Block.MaxBytes = minBlockMaxBytes
}
}
2 changes: 1 addition & 1 deletion block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (m *Manager) produceBlock(allowEmpty bool, nextProposerHash *[32]byte) (*ty
return nil, nil, fmt.Errorf("load block: height: %d: %w: %w", newHeight, err, ErrNonRecoverable)
}

maxBlockDataSize := uint32(float64(m.Conf.BatchSubmitBytes) * types.MaxBlockSizeAdjustment)
maxBlockDataSize := uint64(float64(m.Conf.BatchSubmitBytes) * types.MaxBlockSizeAdjustment)
proposerHashForBlock := [32]byte(m.State.Sequencers.ProposerHash())
// if nextProposerHash is set, we create a last block
if nextProposerHash != nil {
Expand Down
15 changes: 0 additions & 15 deletions block/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (m *Manager) UpdateStateFromApp() error {

// update the state with the app hashes created on the app commit
m.Executor.UpdateStateAfterCommit(m.State, resp, proxyAppInfo.LastBlockAppHash, appHeight)
m.ValidateConsensusBlockParams()

return nil
}
Expand All @@ -108,20 +107,6 @@ func (e *Executor) UpdateStateAfterInitChain(s *types.State, res *abci.ResponseI
s.ConsensusParams.Block.MaxBytes = params.Block.MaxBytes
s.ConsensusParams.Block.MaxGas = params.Block.MaxGas
}
if params.Evidence != nil {
s.ConsensusParams.Evidence.MaxAgeNumBlocks = params.Evidence.MaxAgeNumBlocks
s.ConsensusParams.Evidence.MaxAgeDuration = params.Evidence.MaxAgeDuration
s.ConsensusParams.Evidence.MaxBytes = params.Evidence.MaxBytes
}
if params.Validator != nil {
// Copy params.Validator.PubkeyTypes, and set result's value to the copy.
// This avoids having to initialize the slice to 0 values, and then write to it again.
s.ConsensusParams.Validator.PubKeyTypes = append([]string{}, params.Validator.PubKeyTypes...)
}
if params.Version != nil {
s.ConsensusParams.Version.AppVersion = params.Version.AppVersion
}
s.Version.Consensus.App = s.ConsensusParams.Version.AppVersion
}
// We update the last results hash with the empty hash, to conform with RFC-6962.
copy(s.LastResultsHash[:], merkle.HashFromByteSlices(nil))
Expand Down
2 changes: 1 addition & 1 deletion p2p/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestValidator_BlockValidator(t *testing.T) {
assert.NoError(t, err)

// Create state
maxBytes := uint32(100)
maxBytes := uint64(100)
state := &types.State{}
state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(proposerKey.PubKey(), 1)))
state.ConsensusParams.Block.MaxGas = 100000
Expand Down
Loading