Skip to content

Commit

Permalink
rollback to maxgas and maxbytes in cons params
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Aug 27, 2024
1 parent 34a5cad commit 8a73bb9
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 234 deletions.
30 changes: 24 additions & 6 deletions block/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 Down Expand Up @@ -59,11 +60,28 @@ 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,
Expand All @@ -72,10 +90,10 @@ func (e *Executor) InitChain(genesis *tmtypes.GenesisDoc, valset []*tmtypes.Vali

// 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 uint64) *types.Block {
if state.ConsensusParams.Blockmaxsize > 0 {
maxBlockDataSizeBytes = min(maxBlockDataSizeBytes, uint64(state.ConsensusParams.Blockmaxsize))
if state.ConsensusParams.Block.MaxBytes > 0 {
maxBlockDataSizeBytes = min(maxBlockDataSizeBytes, uint64(state.ConsensusParams.Block.MaxBytes))
}
mempoolTxs := e.mempool.ReapMaxBytesMaxGas(int64(maxBlockDataSizeBytes), state.ConsensusParams.Blockmaxgas)
mempoolTxs := e.mempool.ReapMaxBytesMaxGas(int64(maxBlockDataSizeBytes), state.ConsensusParams.Block.MaxGas)

block := &types.Block{
Header: types.Header{
Expand Down Expand Up @@ -142,8 +160,8 @@ func (e *Executor) commit(state *types.State, block *types.Block, deliverTxs []*
return nil, 0, err
}

maxBytes := state.ConsensusParams.Blockmaxsize
maxGas := state.ConsensusParams.Blockmaxgas
maxBytes := state.ConsensusParams.Block.MaxBytes
maxGas := state.ConsensusParams.Block.MaxGas
err = e.mempool.Update(int64(block.Header.Height), fromDymintTxs(block.Data.Txs), deliverTxs)
if err != nil {
return nil, 0, err
Expand Down
25 changes: 9 additions & 16 deletions block/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/dymensionxyz/dymint/block"
"github.com/dymensionxyz/dymint/types/pb/dymint"

cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand Down Expand Up @@ -61,11 +60,8 @@ func TestCreateBlock(t *testing.T) {
// Init state
state := &types.State{}
state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1)))
state.ConsensusParams = dymint.RollappConsensusParams{
Blockmaxsize: int64(maxBytes),
Blockmaxgas: 100000,
}

state.ConsensusParams.Block.MaxBytes = int64(maxBytes)
state.ConsensusParams.Block.MaxGas = 100000
// empty block
block := executor.CreateBlock(1, &types.Commit{}, [32]byte{}, [32]byte(state.Sequencers.ProposerHash()[:]), state, maxBytes)
require.NotNil(block)
Expand Down Expand Up @@ -168,12 +164,9 @@ func TestApplyBlock(t *testing.T) {
state.InitialHeight = 1
state.SetHeight(0)
maxBytes := uint64(1000)
state.ConsensusParams = dymint.RollappConsensusParams{
Blockmaxgas: 100000,
Blockmaxsize: int64(maxBytes),
Da: "mock",
Version: "",
}
state.ConsensusParams.Block.MaxBytes = int64(maxBytes)
state.ConsensusParams.Block.MaxGas = 100000
state.RollappParams.Da = "mock"

// Create first block with one Tx from mempool
_ = mpool.CheckTx([]byte{1, 2, 3, 4}, func(r *abci.Response) {}, mempool.TxInfo{})
Expand Down Expand Up @@ -258,10 +251,10 @@ func TestApplyBlock(t *testing.T) {
assert.Equal(uint64(2), state.Height())

// check rollapp params update
assert.Equal(state.ConsensusParams.Da, "celestia")
assert.Equal(state.ConsensusParams.Version, "abcde")
assert.Equal(state.ConsensusParams.Blockmaxsize, int64(100))
assert.Equal(state.ConsensusParams.Blockmaxgas, int64(100))
assert.Equal(state.RollappParams.Da, "celestia")
assert.Equal(state.RollappParams.Version, "abcde")
assert.Equal(state.ConsensusParams.Block.MaxBytes, int64(100))
assert.Equal(state.ConsensusParams.Block.MaxGas, int64(100))

// wait for at least 4 Tx events, for up to 3 second.
// 3 seconds is a fail-scenario only
Expand Down
14 changes: 7 additions & 7 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,28 @@ func (m *Manager) UpdateTargetHeight(h uint64) {

// ValidateConfigWithRollappParams checks the configuration params are consistent with the params in the dymint state (e.g. DA and version)
func (m *Manager) ValidateConfigWithRollappParams() error {
if version.Commit != m.State.ConsensusParams.Version {
return fmt.Errorf("binary version mismatch. rollapp param: %s binary used:%s", m.State.ConsensusParams.Version, version.Commit)
if version.Commit != m.State.RollappParams.Version {
return fmt.Errorf("binary version mismatch. rollapp param: %s binary used:%s", m.State.RollappParams.Version, version.Commit)
}

if da.Client(m.State.ConsensusParams.Da) != m.DAClient.GetClientType() {
return fmt.Errorf("da client mismatch. rollapp param: %s da configured: %s", m.State.ConsensusParams.Da, m.DAClient.GetClientType())
if da.Client(m.State.RollappParams.Da) != m.DAClient.GetClientType() {
return fmt.Errorf("da client mismatch. rollapp param: %s da configured: %s", m.State.RollappParams.Da, m.DAClient.GetClientType())
}

if m.Conf.BatchSubmitBytes > uint64(m.DAClient.GetMaxBlobSizeBytes()) {
return fmt.Errorf("batch size above limit: batch size: %d limit: %d: DA %s", m.Conf.BatchSubmitBytes, m.DAClient.GetMaxBlobSizeBytes(), m.DAClient.GetClientType())
}

if m.State.ConsensusParams.Blockmaxsize > int64(m.DAClient.GetMaxBlobSizeBytes()) {
return fmt.Errorf("max block size above limit: block size: %d limit: %d: DA: %s", m.State.ConsensusParams.Blockmaxsize, int64(m.DAClient.GetMaxBlobSizeBytes()), m.DAClient.GetClientType())
if m.State.ConsensusParams.Block.MaxBytes > int64(m.DAClient.GetMaxBlobSizeBytes()) {
return fmt.Errorf("max block size above limit: block size: %d limit: %d: DA: %s", m.State.ConsensusParams.Block.MaxBytes, int64(m.DAClient.GetMaxBlobSizeBytes()), m.DAClient.GetClientType())
}

return nil
}

// setDA initializes DA client in blockmanager according to DA type set in genesis or stored in state
func (m *Manager) setDA(daconfig string, dalcKV store.KV, logger log.Logger) error {
daLayer := m.State.ConsensusParams.Da
daLayer := m.State.RollappParams.Da
dalc := registry.GetClient(daLayer)
if dalc == nil {
return fmt.Errorf("get data availability client named '%s'", daLayer)
Expand Down
14 changes: 7 additions & 7 deletions block/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewStateFromGenesis(genDoc *tmtypes.GenesisDoc) (*types.State, error) {
s.SetHeight(0)
copy(s.AppHash[:], genDoc.AppHash)

err = s.SetConsensusParamsFromGenesis(genDoc.AppState)
err = s.SetRollappParamsFromGenesis(genDoc.AppState)
if err != nil {
return nil, fmt.Errorf("in genesis doc: %w", err)
}
Expand Down Expand Up @@ -106,8 +106,8 @@ func (e *Executor) UpdateStateAfterInitChain(s *types.State, res *abci.ResponseI
}

func (e *Executor) UpdateMempoolAfterInitChain(s *types.State) {
e.mempool.SetPreCheckFn(mempool.PreCheckMaxBytes(s.ConsensusParams.Blockmaxsize))
e.mempool.SetPostCheckFn(mempool.PostCheckMaxGas(s.ConsensusParams.Blockmaxgas))
e.mempool.SetPreCheckFn(mempool.PreCheckMaxBytes(s.ConsensusParams.Block.MaxBytes))
e.mempool.SetPostCheckFn(mempool.PostCheckMaxGas(s.ConsensusParams.Block.MaxGas))
}

// UpdateStateAfterCommit updates the state with the app hash and last results hash
Expand All @@ -121,10 +121,10 @@ func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResp
return
}

s.ConsensusParams.Blockmaxsize = resp.EndBlock.RollappConsensusParamUpdates.Block.MaxBytes
s.ConsensusParams.Blockmaxgas = resp.EndBlock.RollappConsensusParamUpdates.Block.MaxGas
s.ConsensusParams.Da = resp.EndBlock.RollappConsensusParamUpdates.Da
s.ConsensusParams.Version = resp.EndBlock.RollappConsensusParamUpdates.Version
s.ConsensusParams.Block.MaxBytes = resp.EndBlock.ConsensusParamUpdates.Block.MaxBytes
s.ConsensusParams.Block.MaxGas = resp.EndBlock.ConsensusParamUpdates.Block.MaxGas
s.RollappParams.Da = resp.EndBlock.RollappConsensusParamUpdates.Da
s.RollappParams.Version = resp.EndBlock.RollappConsensusParamUpdates.Version
}

// UpdateProposerFromBlock updates the proposer from the block
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ require (

replace (
github.com/centrifuge/go-substrate-rpc-client/v4 => github.com/availproject/go-substrate-rpc-client/v4 v4.0.12-avail-1.4.0-rc1-5e286e3
github.com/dymensionxyz/dymension-rdk => github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240826142931-65043da2cae9
github.com/dymensionxyz/dymension-rdk => github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240827102903-08636e7ab3f8
github.com/evmos/evmos/v12 => github.com/dymensionxyz/evmos/v12 v12.1.7-0.20240826143159-0ea2ad7d5dab
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
github.com/gorilla/rpc => github.com/dymensionxyz/rpc v1.3.1
github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20240826103935-3b56e9ae1680
github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20240827102743-fafae27f8527
)

replace github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.2
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM=
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/cometbft v0.34.29-0.20240826103935-3b56e9ae1680 h1:g992HU2HzVTEywlFTGW4JzGR7B4tdPDXSsUoXm4ae4Q=
github.com/dymensionxyz/cometbft v0.34.29-0.20240826103935-3b56e9ae1680/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/dymensionxyz/cometbft v0.34.29-0.20240827102743-fafae27f8527 h1:ueS52CpkFmlu2indSCa78e4WkjiEZuhy2gBTkFI5F20=
github.com/dymensionxyz/cometbft v0.34.29-0.20240827102743-fafae27f8527/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13 h1:u5yeve5jZR6TdRjjR+vYT/8PWKbhwCZxUmAu+/Tnxyg=
github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13/go.mod h1:jabDQYXrccscSE0fXkh7eQFYPWJCRiuWKonFGObVq6s=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240826142931-65043da2cae9 h1:XMpiKUhuLfzichlCzjGIKNREg3e0aVoLczPUbdwzp/w=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240826142931-65043da2cae9/go.mod h1:u2hWbOUUe1ZdtD+SKnGe/8OIZlnRfZHILu8m9U1wKq8=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240827102903-08636e7ab3f8 h1:xQTdVaSzt1pISkoeX7tERxtYkofU8arGxv9espDtlHY=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240827102903-08636e7ab3f8/go.mod h1:iNL7uKYZ6EVzLbrOymohTTmkGVRqj3nGXhtcdcnW/+A=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240411195658-f7cd96f53b56 h1:cmpJYdRviuUfmlJdHrcAND8Jd6JIY4rp63bWAQzPr54=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240411195658-f7cd96f53b56/go.mod h1:3Pfrr8j/BR9ztNKztGfC5PqDiO6CcrzMLCJtFtPEVW4=
github.com/dymensionxyz/evmos/v12 v12.1.7-0.20240826143159-0ea2ad7d5dab h1:3EKn/QwlS3rRKJtyyWqDgpvIyfLC5zeff4cebgkaNuY=
Expand Down
8 changes: 3 additions & 5 deletions p2p/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

mempoolv1 "github.com/dymensionxyz/dymint/mempool/v1"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/pb/dymint"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -133,10 +132,9 @@ func TestValidator_BlockValidator(t *testing.T) {
maxBytes := uint64(100)
state := &types.State{}
state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(proposerKey.PubKey(), 1)))
state.ConsensusParams = dymint.RollappConsensusParams{
Blockmaxgas: 100000,
Blockmaxsize: int64(maxBytes),
}
state.ConsensusParams.Block.MaxGas = 100000
state.ConsensusParams.Block.MaxBytes = int64(maxBytes)

// Create empty block
block := executor.CreateBlock(1, &types.Commit{}, [32]byte{}, [32]byte(state.Sequencers.ProposerHash()), state, maxBytes)

Expand Down
13 changes: 5 additions & 8 deletions proto/types/dymint/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ message State {
int64 last_height_validators_changed = 11;


reserved 12;
tendermint.types.ConsensusParams consensus_params = 12 [(gogoproto.nullable) = false];
int64 last_height_consensus_params_changed = 13;

bytes last_results_hash = 14;
Expand All @@ -43,18 +43,15 @@ message State {
uint64 base_height = 17;

SequencerSet sequencerSet = 18 [(gogoproto.nullable) = false];
RollappConsensusParams consensus_params = 19 [(gogoproto.nullable) = false];
RollappConsensusParams rollapp_params = 19 [(gogoproto.nullable) = false];

}

//rollapp params defined in genesis and updated via gov proposal
message RollappConsensusParams {
//maximum amount of gas that all transactions included in a block can use
int64 blockmaxgas = 1;
//maximum allowed block size
int64 blockmaxsize = 2;

//data availability type (e.g. celestia) used in the rollapp
string da = 3 ;
string da = 1 ;
//commit used for the rollapp executable
string version = 4 ;
string version = 2 ;
}
4 changes: 2 additions & 2 deletions testutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func GenerateStateWithSequencer(initialHeight int64, lastBlockHeight int64, pubk
App: AppVersion,
},
},
ConsensusParams: dymint.RollappConsensusParams{
RollappParams: dymint.RollappConsensusParams{
Da: "mock",
Version: dymintversion.Commit,
},
Expand Down Expand Up @@ -268,7 +268,7 @@ func GenerateGenesis(initialHeight int64) *tmtypes.GenesisDoc {
AppVersion: AppVersion,
},
},
AppState: []byte("{\"rollappparams\": {\"params\": {\"da\": \"mock\",\"version\": \"" + dymintversion.Commit + "\",\"blockmaxgas\":\"400000000\",\"blockmaxsize\":500000}}}"),
AppState: []byte("{\"rollappparams\": {\"params\": {\"da\": \"mock\",\"version\": \"" + dymintversion.Commit + "\"}}}"),
}
}

Expand Down
Loading

0 comments on commit 8a73bb9

Please sign in to comment.