Skip to content

Commit

Permalink
feat(manager): decouple drs version from commit (#1182)
Browse files Browse the repository at this point in the history
Co-authored-by: Omri <[email protected]>
  • Loading branch information
srene and omritoptix authored Oct 31, 2024
1 parent 787fd09 commit 346edea
Show file tree
Hide file tree
Showing 31 changed files with 346 additions and 338 deletions.
2 changes: 1 addition & 1 deletion block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
return fmt.Errorf("save block source: %w", err)
}

_, err = m.Store.SaveDRSVersion(block.Header.Height, responses.EndBlock.RollappParamUpdates.Version, nil)
_, err = m.Store.SaveDRSVersion(block.Header.Height, responses.EndBlock.RollappParamUpdates.DrsVersion, nil)
if err != nil {
return fmt.Errorf("add drs version: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions block/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func TestApplyBlock(t *testing.T) {
app.On("DeliverTx", mock.Anything).Return(abci.ResponseDeliverTx{})
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "celestia",
Version: "abcde",
Da: "celestia",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestApplyBlock(t *testing.T) {

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

Expand Down
9 changes: 7 additions & 2 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strconv"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -383,8 +384,12 @@ 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.RollappParams.Version {
return fmt.Errorf("binary version mismatch. rollapp param: %s binary used:%s", m.State.RollappParams.Version, version.Commit)
drsVersion, err := strconv.ParseUint(version.DrsVersion, 10, 32)
if err != nil {
return fmt.Errorf("unable to parse drs version")
}
if uint32(drsVersion) != m.State.RollappParams.DrsVersion {
return fmt.Errorf("DRS version mismatch. rollapp param: %d binary used:%d", m.State.RollappParams.DrsVersion, drsVersion)
}

if da.Client(m.State.RollappParams.Da) != m.DAClient.GetClientType() {
Expand Down
37 changes: 18 additions & 19 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp"
"github.com/dymensionxyz/dymint/version"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
Expand Down Expand Up @@ -136,8 +135,8 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -211,8 +210,8 @@ func TestApplyCachedBlocks_WithFraudCheck(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -299,8 +298,8 @@ func TestApplyLocalBlock_WithFraudCheck(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -418,8 +417,8 @@ func TestProduceNewBlock(t *testing.T) {
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{Data: commitHash[:]})
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -451,8 +450,8 @@ func TestProducePendingBlock(t *testing.T) {
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{Data: commitHash[:]})
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -564,8 +563,8 @@ func TestProduceBlockFailAfterCommit(t *testing.T) {
})
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -596,8 +595,8 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -678,8 +677,8 @@ func TestDAFetch(t *testing.T) {
app := testutil.GetAppMock(testutil.Info, testutil.Commit, testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -774,8 +773,8 @@ func TestManager_ApplyBatchFromSL_FraudHandling(t *testing.T) {
app := testutil.GetAppMock(testutil.Info, testutil.Commit, testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down
17 changes: 8 additions & 9 deletions block/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
uchannel "github.com/dymensionxyz/dymint/utils/channel"
uevent "github.com/dymensionxyz/dymint/utils/event"
protoutils "github.com/dymensionxyz/dymint/utils/proto"
"github.com/dymensionxyz/dymint/version"
)

// TODO: test producing lastBlock
Expand All @@ -48,8 +47,8 @@ func TestCreateEmptyBlocksEnableDisable(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -212,8 +211,8 @@ func TestStopBlockProduction(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -296,8 +295,8 @@ func TestUpdateInitialSequencerSet(t *testing.T) {
ctx := context.Background()
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -402,8 +401,8 @@ func TestUpdateExistingSequencerSet(t *testing.T) {
ctx := context.Background()
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down
5 changes: 2 additions & 3 deletions block/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/version"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -21,8 +20,8 @@ func TestPruningRetainHeight(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down
3 changes: 1 addition & 2 deletions block/slvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ func (v *SettlementValidator) NextValidationHeight() uint64 {
}

// validateDRS compares the DRS version stored for the specific height, obtained from rollapp params.
// DRS checks will work only for non-finalized heights, since it does not store the whole history, but it will never validate finalized heights.
func (v *SettlementValidator) validateDRS(stateIndex uint64, height uint64, version string) error {
func (v *SettlementValidator) validateDRS(stateIndex uint64, height uint64, version uint32) error {
drs, err := v.blockManager.Store.LoadDRSVersion(height)
if err != nil {
return err
Expand Down
20 changes: 7 additions & 13 deletions block/slvalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp"
"github.com/dymensionxyz/dymint/version"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -33,8 +32,8 @@ func TestStateUpdateValidator_ValidateStateUpdate(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -225,9 +224,7 @@ func TestStateUpdateValidator_ValidateStateUpdate(t *testing.T) {
switch tc.stateUpdateFraud {
case "drs":
// set different bd drs version
version, err := testutil.CreateRandomVersionCommit()
require.NoError(t, err)
slBatch.BlockDescriptors[0].DrsVersion = version
slBatch.BlockDescriptors[0].DrsVersion = 2
case "batchnumblocks":
// set wrong numblocks in state update
slBatch.NumBlocks = 11
Expand Down Expand Up @@ -270,8 +267,8 @@ func TestStateUpdateValidator_ValidateDAFraud(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -403,15 +400,12 @@ func getBlockDescriptors(batch *types.Batch) ([]rollapp.BlockDescriptor, error)
// Create block descriptors
var bds []rollapp.BlockDescriptor
for _, block := range batch.Blocks {
version, err := testutil.CreateRandomVersionCommit()
if err != nil {
return nil, err
}

bd := rollapp.BlockDescriptor{
Height: block.Header.Height,
StateRoot: block.Header.AppHash[:],
Timestamp: block.Header.GetTimestamp(),
DrsVersion: version,
DrsVersion: 0,
}
bds = append(bds, bd)
}
Expand Down
2 changes: 1 addition & 1 deletion block/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResp
}
if resp.EndBlock.RollappParamUpdates != nil {
s.RollappParams.Da = resp.EndBlock.RollappParamUpdates.Da
s.RollappParams.Version = resp.EndBlock.RollappParamUpdates.Version
s.RollappParams.DrsVersion = resp.EndBlock.RollappParamUpdates.DrsVersion
}
}

Expand Down
19 changes: 10 additions & 9 deletions block/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
slmocks "github.com/dymensionxyz/dymint/mocks/github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/dymint/version"
)

// TestBatchOverhead tests the scenario where we have a single block that is very large, and occupies the entire batch size.
Expand Down Expand Up @@ -106,15 +105,16 @@ func TestBatchSubmissionHappyFlow(t *testing.T) {
require := require.New(t)
app := testutil.GetAppMock(testutil.EndBlock)
ctx := context.Background()

// Create proxy app
clientCreator := proxy.NewLocalClientCreator(app)
proxyApp := proxy.NewAppConns(clientCreator)
err := proxyApp.Start()
require.NoError(err)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -149,10 +149,11 @@ func TestBatchSubmissionFailedSubmission(t *testing.T) {
require := require.New(t)
app := testutil.GetAppMock(testutil.EndBlock)
ctx := context.Background()

app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -227,8 +228,8 @@ func TestSubmissionByTime(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down Expand Up @@ -310,8 +311,8 @@ func TestSubmissionByBatchSize(t *testing.T) {
app := testutil.GetAppMock(testutil.EndBlock)
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{
RollappParamUpdates: &abci.RollappParams{
Da: "mock",
Version: version.Commit,
Da: "mock",
DrsVersion: 0,
},
ConsensusParamUpdates: &abci.ConsensusParams{
Block: &abci.BlockParams{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ replace (
github.com/evmos/evmos/v12 => github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.3
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.20241008141942-63af9d24107f
github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20241030154748-3f9dfa21d17b
)

replace github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.2
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ 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.20241008141942-63af9d24107f h1:CclWJWRydsd8D4/R1IegIkcWtL4wqTA3MWtXrx1a6y4=
github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/dymensionxyz/cometbft v0.34.29-0.20241030154748-3f9dfa21d17b h1:rxkH+9cBG2nnReMavb2FqQXwDLjKcz0/KB8/6SV5Xlo=
github.com/dymensionxyz/cometbft v0.34.29-0.20241030154748-3f9dfa21d17b/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/evmos/v12 v12.1.6-dymension-v0.3 h1:vmAdUGUc4rTIiO3Phezr7vGq+0uPDVKSA4WAe8+yl6w=
Expand Down
1 change: 1 addition & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

// simply check that node is starting and stopping without panicking
func TestStartup(t *testing.T) {

assert := assert.New(t)
require := require.New(t)

Expand Down
Loading

0 comments on commit 346edea

Please sign in to comment.