diff --git a/block/block.go b/block/block.go index a35afba05..82db10257 100644 --- a/block/block.go +++ b/block/block.go @@ -90,7 +90,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta m.logger.Error("save block blocksync", "err", err) } - responses, err := m.Executor.ExecuteBlock(m.State, block) + responses, err := m.Executor.ExecuteBlock(block) if err != nil { return fmt.Errorf("execute block: %w", err) } @@ -133,14 +133,16 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block.Header.Height, block.Header.Hash()) } - // check if the proposer needs to be changed - switchRole := m.Executor.UpdateProposerFromBlock(m.State, block) + // save the proposer to store to be queried over RPC + proposer := m.State.GetProposer() + if proposer == nil { + return fmt.Errorf("logic error: got nil proposer while applying block") + } - // save sequencers to store to be queried over RPC batch := m.Store.NewBatch() - batch, err = m.Store.SaveSequencers(block.Header.Height, &m.State.Sequencers, batch) + batch, err = m.Store.SaveProposer(block.Header.Height, *proposer, batch) if err != nil { - return fmt.Errorf("save sequencers: %w", err) + return fmt.Errorf("save proposer: %w", err) } batch, err = m.Store.SaveState(m.State, batch) @@ -157,6 +159,9 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta m.blockCache.Delete(block.Header.Height) + // check if the proposer needs to be changed and change it if that's the case + switchRole := m.Executor.UpdateProposerFromBlock(m.State, m.Sequencers, block) + if switchRole { // TODO: graceful role change (https://github.com/dymensionxyz/dymint/issues/1008) m.logger.Info("Node changing to proposer role") diff --git a/block/executor.go b/block/executor.go index 43e50b32f..0ebc135f8 100644 --- a/block/executor.go +++ b/block/executor.go @@ -27,13 +27,15 @@ type ExecutorI interface { CreateBlock(height uint64, lastCommit *types.Commit, lastHeaderHash, nextSeqHash [32]byte, state *types.State, maxBlockDataSizeBytes uint64) *types.Block Commit(state *types.State, block *types.Block, resp *tmstate.ABCIResponses) ([]byte, int64, error) GetAppInfo() (*abci.ResponseInfo, error) - ExecuteBlock(state *types.State, block *types.Block) (*tmstate.ABCIResponses, error) + ExecuteBlock(block *types.Block) (*tmstate.ABCIResponses, error) UpdateStateAfterInitChain(s *types.State, res *abci.ResponseInitChain) UpdateMempoolAfterInitChain(s *types.State) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, height uint64, lastHeaderHash [32]byte) - UpdateProposerFromBlock(s *types.State, block *types.Block) bool + UpdateProposerFromBlock(s *types.State, seqSet *types.SequencerSet, block *types.Block) bool } +var _ ExecutorI = new(Executor) + // Executor creates and applies blocks and maintains state. type Executor struct { localAddress []byte @@ -163,7 +165,7 @@ func (e *Executor) CreateBlock( } copy(block.Header.LastCommitHash[:], types.GetLastCommitHash(lastCommit, &block.Header)) copy(block.Header.DataHash[:], types.GetDataHash(block)) - copy(block.Header.SequencerHash[:], state.Sequencers.ProposerHash()) + copy(block.Header.SequencerHash[:], state.GetProposerHash()) copy(block.Header.NextSequencersHash[:], nextSeqHash[:]) return block @@ -216,7 +218,7 @@ func (e *Executor) commit(state *types.State, block *types.Block, deliverTxs []* } // ExecuteBlock executes the block and returns the ABCIResponses. Block should be valid (passed validation checks). -func (e *Executor) ExecuteBlock(state *types.State, block *types.Block) (*tmstate.ABCIResponses, error) { +func (e *Executor) ExecuteBlock(block *types.Block) (*tmstate.ABCIResponses, error) { abciResponses := new(tmstate.ABCIResponses) abciResponses.DeliverTxs = make([]*abci.ResponseDeliverTx, len(block.Data.Txs)) diff --git a/block/executor_test.go b/block/executor_test.go index fb4e28dc5..afa6bb578 100644 --- a/block/executor_test.go +++ b/block/executor_test.go @@ -63,11 +63,11 @@ func TestCreateBlock(t *testing.T) { // Init state state := &types.State{} - state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1))) + state.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1))) 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) + block := executor.CreateBlock(1, &types.Commit{}, [32]byte{}, [32]byte(state.GetProposerHash()), state, maxBytes) require.NotNil(block) assert.Empty(block.Data.Txs) assert.Equal(uint64(1), block.Header.Height) @@ -75,7 +75,7 @@ func TestCreateBlock(t *testing.T) { // one small Tx err = mpool.CheckTx([]byte{1, 2, 3, 4}, func(r *abci.Response) {}, mempool.TxInfo{}) require.NoError(err) - block = executor.CreateBlock(2, &types.Commit{}, [32]byte{}, [32]byte(state.Sequencers.ProposerHash()), state, maxBytes) + block = executor.CreateBlock(2, &types.Commit{}, [32]byte{}, [32]byte(state.GetProposerHash()), state, maxBytes) require.NotNil(block) assert.Equal(uint64(2), block.Header.Height) assert.Len(block.Data.Txs, 1) @@ -85,7 +85,7 @@ func TestCreateBlock(t *testing.T) { require.NoError(err) err = mpool.CheckTx(make([]byte, 100), func(r *abci.Response) {}, mempool.TxInfo{}) require.NoError(err) - block = executor.CreateBlock(3, &types.Commit{}, [32]byte{}, [32]byte(state.Sequencers.ProposerHash()), state, maxBytes) + block = executor.CreateBlock(3, &types.Commit{}, [32]byte{}, [32]byte(state.GetProposerHash()), state, maxBytes) require.NotNil(block) assert.Len(block.Data.Txs, 2) } @@ -131,11 +131,11 @@ func TestCreateBlockWithConsensusMessages(t *testing.T) { require.NoError(err) state := &types.State{} - state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1))) + state.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1))) state.ConsensusParams.Block.MaxBytes = int64(maxBytes) state.ConsensusParams.Block.MaxGas = 100000 - block := executor.CreateBlock(1, &types.Commit{}, [32]byte{}, [32]byte(state.Sequencers.ProposerHash()[:]), state, maxBytes) + block := executor.CreateBlock(1, &types.Commit{}, [32]byte{}, [32]byte(state.GetProposerHash()[:]), state, maxBytes) require.NotNil(block) assert.Empty(block.Data.Txs) @@ -253,7 +253,7 @@ func TestApplyBlock(t *testing.T) { // Init state state := &types.State{} - state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1))) + state.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(tmPubKey, 1))) state.InitialHeight = 1 state.ChainID = chainID state.SetHeight(0) @@ -266,7 +266,7 @@ func TestApplyBlock(t *testing.T) { // Create first block with one Tx from mempool _ = mpool.CheckTx([]byte{1, 2, 3, 4}, func(r *abci.Response) {}, mempool.TxInfo{}) require.NoError(err) - block := executor.CreateBlock(1, &types.Commit{Height: 0}, [32]byte{0x01}, [32]byte(state.Sequencers.ProposerHash()), state, maxBytes) + block := executor.CreateBlock(1, &types.Commit{Height: 0}, [32]byte{0x01}, [32]byte(state.GetProposerHash()), state, maxBytes) require.NotNil(block) assert.Equal(uint64(1), block.Header.Height) assert.Len(block.Data.Txs, 1) @@ -284,10 +284,10 @@ func TestApplyBlock(t *testing.T) { } // Apply the block - err = types.ValidateProposedTransition(state, block, commit, state.Sequencers.GetProposerPubKey()) + err = types.ValidateProposedTransition(state, block, commit, state.GetProposerPubKey()) require.NoError(err) - resp, err := executor.ExecuteBlock(state, block) + resp, err := executor.ExecuteBlock(block) require.NoError(err) require.NotNil(resp) appHash, _, err := executor.Commit(state, block, resp) @@ -301,7 +301,7 @@ func TestApplyBlock(t *testing.T) { 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, 9990), func(r *abci.Response) {}, mempool.TxInfo{})) - block = executor.CreateBlock(2, commit, block.Header.Hash(), [32]byte(state.Sequencers.ProposerHash()), state, maxBytes) + block = executor.CreateBlock(2, commit, block.Header.Hash(), [32]byte(state.GetProposerHash()), state, maxBytes) require.NotNil(block) assert.Equal(uint64(2), block.Header.Height) assert.Len(block.Data.Txs, 3) @@ -322,7 +322,7 @@ func TestApplyBlock(t *testing.T) { } // Apply the block with an invalid commit - err = types.ValidateProposedTransition(state, block, invalidCommit, state.Sequencers.GetProposerPubKey()) + err = types.ValidateProposedTransition(state, block, invalidCommit, state.GetProposerPubKey()) require.ErrorContains(err, types.ErrInvalidSignature.Error()) // Create a valid commit for the block @@ -335,9 +335,9 @@ func TestApplyBlock(t *testing.T) { } // Apply the block - err = types.ValidateProposedTransition(state, block, commit, state.Sequencers.GetProposerPubKey()) + err = types.ValidateProposedTransition(state, block, commit, state.GetProposerPubKey()) require.NoError(err) - resp, err = executor.ExecuteBlock(state, block) + resp, err = executor.ExecuteBlock(block) require.NoError(err) require.NotNil(resp) _, _, err = executor.Commit(state, block, resp) diff --git a/block/manager.go b/block/manager.go index 8e315d5b5..b57a2b124 100644 --- a/block/manager.go +++ b/block/manager.go @@ -44,9 +44,10 @@ type Manager struct { LocalKey crypto.PrivKey // Store and execution - Store store.Store - State *types.State - Executor ExecutorI + Store store.Store + State *types.State + Executor ExecutorI + Sequencers *types.SequencerSet // Sequencers is the set of sequencers that are currently active on the rollapp // Clients and servers Pubsub *pubsub.Server @@ -143,6 +144,7 @@ func NewManager( Genesis: genesis, Store: store, Executor: exec, + Sequencers: types.NewSequencerSet(), SLClient: settlementClient, indexerService: indexerService, logger: logger.With("module", "block_manager"), @@ -364,7 +366,7 @@ func (m *Manager) updateLastFinalizedHeightFromSettlement() error { } func (m *Manager) GetProposerPubKey() tmcrypto.PubKey { - return m.State.Sequencers.GetProposerPubKey() + return m.State.GetProposerPubKey() } func (m *Manager) UpdateTargetHeight(h uint64) { diff --git a/block/manager_test.go b/block/manager_test.go index 03d08ba74..ebbc016ed 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -204,6 +204,7 @@ func TestProduceOnlyAfterSynced(t *testing.T) { // TestApplyCachedBlocks checks the flow that happens when we are receiving blocks from p2p and some of the blocks // are already cached. This means blocks that were gossiped but are bigger than the expected next block height. +// TODO: this test is flaky! https://github.com/dymensionxyz/dymint/issues/1173 func TestApplyCachedBlocks_WithFraudCheck(t *testing.T) { // Init app app := testutil.GetAppMock(testutil.EndBlock) @@ -464,8 +465,8 @@ func TestProducePendingBlock(t *testing.T) { require.NoError(t, err) // Generate block and commit and save it to the store block := testutil.GetRandomBlock(1, 3) - copy(block.Header.SequencerHash[:], manager.State.Sequencers.ProposerHash()) - copy(block.Header.NextSequencersHash[:], manager.State.Sequencers.ProposerHash()) + copy(block.Header.SequencerHash[:], manager.State.GetProposerHash()) + copy(block.Header.NextSequencersHash[:], manager.State.GetProposerHash()) _, err = manager.Store.SaveBlock(block, &block.LastCommit, nil) require.NoError(t, err) diff --git a/block/produce.go b/block/produce.go index c904adb6a..f46876c41 100644 --- a/block/produce.go +++ b/block/produce.go @@ -149,7 +149,7 @@ func (m *Manager) produceBlock(allowEmpty bool, nextProposerHash *[32]byte) (*ty } maxBlockDataSize := uint64(float64(m.Conf.BatchSubmitBytes) * types.MaxBlockSizeAdjustment) - proposerHashForBlock := [32]byte(m.State.Sequencers.ProposerHash()) + proposerHashForBlock := [32]byte(m.State.GetProposerHash()) // if nextProposerHash is set, we create a last block if nextProposerHash != nil { maxBlockDataSize = 0 diff --git a/block/sequencers.go b/block/sequencers.go index b6df0384f..1cf49e61e 100644 --- a/block/sequencers.go +++ b/block/sequencers.go @@ -6,9 +6,10 @@ import ( "fmt" "time" + "github.com/tendermint/tendermint/libs/pubsub" + "github.com/dymensionxyz/dymint/settlement" "github.com/dymensionxyz/dymint/types" - "github.com/tendermint/tendermint/libs/pubsub" ) func (m *Manager) MonitorSequencerRotation(ctx context.Context, rotateC chan string) error { @@ -66,7 +67,7 @@ func (m *Manager) IsProposer() bool { // check if recovering from halt if l2Proposer == nil && hubProposer != nil { - m.State.Sequencers.SetProposer(hubProposer) + m.State.SetProposer(hubProposer) } // we run sequencer flow if we're proposer on L2 or hub (can be different during rotation phase, before hub receives the last state update) @@ -113,8 +114,8 @@ func (m *Manager) CompleteRotation(ctx context.Context, nextSeqAddr string) erro // validate nextSeq is in the bonded set var nextSeqHash [32]byte if nextSeqAddr != "" { - seq := m.State.Sequencers.GetByAddress(nextSeqAddr) - if seq == nil { + seq, found := m.Sequencers.GetByAddress(nextSeqAddr) + if !found { return types.ErrMissingProposerPubKey } copy(nextSeqHash[:], seq.MustHash()) @@ -170,18 +171,18 @@ func (m *Manager) UpdateSequencerSetFromSL() error { if err != nil { return err } - m.State.Sequencers.SetSequencers(seqs) - m.logger.Debug("Updated bonded sequencer set.", "newSet", m.State.Sequencers.String()) + m.Sequencers.SetSequencers(seqs) + m.logger.Debug("Updated bonded sequencer set.", "newSet", m.Sequencers.String()) return nil } // UpdateProposer updates the proposer from the hub func (m *Manager) UpdateProposer() error { - m.State.Sequencers.SetProposer(m.SLClient.GetProposer()) + m.State.SetProposer(m.SLClient.GetProposer()) return nil } -// UpdateLastSubmittedHeight will update last height submitted height upon events. +// UpdateSequencerSet will update last height submitted height upon events. // This may be necessary in case we crashed/restarted before getting response for our submission to the settlement layer. func (m *Manager) UpdateSequencerSet(event pubsub.Message) { eventData, ok := event.Data().(*settlement.EventDataNewBondedSequencer) @@ -190,7 +191,7 @@ func (m *Manager) UpdateSequencerSet(event pubsub.Message) { return } - if m.State.Sequencers.GetByAddress(eventData.SeqAddr) != nil { + if _, found := m.Sequencers.GetByAddress(eventData.SeqAddr); found { m.logger.Debug("Sequencer not added from new bonded sequencer event because already in the list.") return } @@ -200,6 +201,6 @@ func (m *Manager) UpdateSequencerSet(event pubsub.Message) { m.logger.Error("Unable to add new sequencer from event. err:%w", err) return } - sequencers := append(m.State.Sequencers.Sequencers, newSequencer) - m.State.Sequencers.SetSequencers(sequencers) + + m.Sequencers.AppendSequencer(newSequencer) } diff --git a/block/state.go b/block/state.go index 780e64f76..b423c30d3 100644 --- a/block/state.go +++ b/block/state.go @@ -140,7 +140,7 @@ func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResp // In case of a node that a becomes the proposer, we return true to mark the role change // currently the node will rebooted to apply the new role // TODO: (https://github.com/dymensionxyz/dymint/issues/1008) -func (e *Executor) UpdateProposerFromBlock(s *types.State, block *types.Block) bool { +func (e *Executor) UpdateProposerFromBlock(s *types.State, seqSet *types.SequencerSet, block *types.Block) bool { // no sequencer change if bytes.Equal(block.Header.SequencerHash[:], block.Header.NextSequencersHash[:]) { return false @@ -150,19 +150,21 @@ func (e *Executor) UpdateProposerFromBlock(s *types.State, block *types.Block) b // the chain will be halted until proposer is set // TODO: recover from halt (https://github.com/dymensionxyz/dymint/issues/1021) e.logger.Info("rollapp left with no proposer. chain is halted") - s.Sequencers.SetProposer(nil) + s.SetProposer(nil) return false } - // if hash changed, update the active sequencer - err := s.Sequencers.SetProposerByHash(block.Header.NextSequencersHash[:]) - if err != nil { - e.logger.Error("update new proposer", "err", err) - panic(fmt.Sprintf("failed to update new proposer: %v", err)) + // if hash changed, update the proposer + seq, found := seqSet.GetByHash(block.Header.NextSequencersHash[:]) + if !found { + e.logger.Error("cannot find proposer by hash") + panic("cannot find proposer by hash") } + s.SetProposer(&seq) - localSeq := s.Sequencers.GetByConsAddress(e.localAddress) - if localSeq != nil && bytes.Equal(localSeq.MustHash(), block.Header.NextSequencersHash[:]) { + // check if this node becomes a proposer + localSeq, found := seqSet.GetByConsAddress(e.localAddress) + if found && bytes.Equal(localSeq.MustHash(), block.Header.NextSequencersHash[:]) { return true } diff --git a/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go b/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go index a9b356dae..03eea29dc 100644 --- a/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go +++ b/mocks/github.com/dymensionxyz/dymint/block/mock_ExecutorI.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package block @@ -147,9 +147,9 @@ func (_c *MockExecutorI_CreateBlock_Call) RunAndReturn(run func(uint64, *types.C return _c } -// ExecuteBlock provides a mock function with given fields: _a0, _a1 -func (_m *MockExecutorI) ExecuteBlock(_a0 *types.State, _a1 *types.Block) (*state.ABCIResponses, error) { - ret := _m.Called(_a0, _a1) +// ExecuteBlock provides a mock function with given fields: _a0 +func (_m *MockExecutorI) ExecuteBlock(_a0 *types.Block) (*state.ABCIResponses, error) { + ret := _m.Called(_a0) if len(ret) == 0 { panic("no return value specified for ExecuteBlock") @@ -157,19 +157,19 @@ func (_m *MockExecutorI) ExecuteBlock(_a0 *types.State, _a1 *types.Block) (*stat var r0 *state.ABCIResponses var r1 error - if rf, ok := ret.Get(0).(func(*types.State, *types.Block) (*state.ABCIResponses, error)); ok { - return rf(_a0, _a1) + if rf, ok := ret.Get(0).(func(*types.Block) (*state.ABCIResponses, error)); ok { + return rf(_a0) } - if rf, ok := ret.Get(0).(func(*types.State, *types.Block) *state.ABCIResponses); ok { - r0 = rf(_a0, _a1) + if rf, ok := ret.Get(0).(func(*types.Block) *state.ABCIResponses); ok { + r0 = rf(_a0) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*state.ABCIResponses) } } - if rf, ok := ret.Get(1).(func(*types.State, *types.Block) error); ok { - r1 = rf(_a0, _a1) + if rf, ok := ret.Get(1).(func(*types.Block) error); ok { + r1 = rf(_a0) } else { r1 = ret.Error(1) } @@ -183,15 +183,14 @@ type MockExecutorI_ExecuteBlock_Call struct { } // ExecuteBlock is a helper method to define mock.On call -// - _a0 *types.State -// - _a1 *types.Block -func (_e *MockExecutorI_Expecter) ExecuteBlock(_a0 interface{}, _a1 interface{}) *MockExecutorI_ExecuteBlock_Call { - return &MockExecutorI_ExecuteBlock_Call{Call: _e.mock.On("ExecuteBlock", _a0, _a1)} +// - _a0 *types.Block +func (_e *MockExecutorI_Expecter) ExecuteBlock(_a0 interface{}) *MockExecutorI_ExecuteBlock_Call { + return &MockExecutorI_ExecuteBlock_Call{Call: _e.mock.On("ExecuteBlock", _a0)} } -func (_c *MockExecutorI_ExecuteBlock_Call) Run(run func(_a0 *types.State, _a1 *types.Block)) *MockExecutorI_ExecuteBlock_Call { +func (_c *MockExecutorI_ExecuteBlock_Call) Run(run func(_a0 *types.Block)) *MockExecutorI_ExecuteBlock_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*types.State), args[1].(*types.Block)) + run(args[0].(*types.Block)) }) return _c } @@ -201,7 +200,7 @@ func (_c *MockExecutorI_ExecuteBlock_Call) Return(_a0 *state.ABCIResponses, _a1 return _c } -func (_c *MockExecutorI_ExecuteBlock_Call) RunAndReturn(run func(*types.State, *types.Block) (*state.ABCIResponses, error)) *MockExecutorI_ExecuteBlock_Call { +func (_c *MockExecutorI_ExecuteBlock_Call) RunAndReturn(run func(*types.Block) (*state.ABCIResponses, error)) *MockExecutorI_ExecuteBlock_Call { _c.Call.Return(run) return _c } @@ -355,17 +354,17 @@ func (_c *MockExecutorI_UpdateMempoolAfterInitChain_Call) RunAndReturn(run func( return _c } -// UpdateProposerFromBlock provides a mock function with given fields: s, _a1 -func (_m *MockExecutorI) UpdateProposerFromBlock(s *types.State, _a1 *types.Block) bool { - ret := _m.Called(s, _a1) +// UpdateProposerFromBlock provides a mock function with given fields: s, seqSet, _a2 +func (_m *MockExecutorI) UpdateProposerFromBlock(s *types.State, seqSet *types.SequencerSet, _a2 *types.Block) bool { + ret := _m.Called(s, seqSet, _a2) if len(ret) == 0 { panic("no return value specified for UpdateProposerFromBlock") } var r0 bool - if rf, ok := ret.Get(0).(func(*types.State, *types.Block) bool); ok { - r0 = rf(s, _a1) + if rf, ok := ret.Get(0).(func(*types.State, *types.SequencerSet, *types.Block) bool); ok { + r0 = rf(s, seqSet, _a2) } else { r0 = ret.Get(0).(bool) } @@ -380,14 +379,15 @@ type MockExecutorI_UpdateProposerFromBlock_Call struct { // UpdateProposerFromBlock is a helper method to define mock.On call // - s *types.State -// - _a1 *types.Block -func (_e *MockExecutorI_Expecter) UpdateProposerFromBlock(s interface{}, _a1 interface{}) *MockExecutorI_UpdateProposerFromBlock_Call { - return &MockExecutorI_UpdateProposerFromBlock_Call{Call: _e.mock.On("UpdateProposerFromBlock", s, _a1)} +// - seqSet *types.SequencerSet +// - _a2 *types.Block +func (_e *MockExecutorI_Expecter) UpdateProposerFromBlock(s interface{}, seqSet interface{}, _a2 interface{}) *MockExecutorI_UpdateProposerFromBlock_Call { + return &MockExecutorI_UpdateProposerFromBlock_Call{Call: _e.mock.On("UpdateProposerFromBlock", s, seqSet, _a2)} } -func (_c *MockExecutorI_UpdateProposerFromBlock_Call) Run(run func(s *types.State, _a1 *types.Block)) *MockExecutorI_UpdateProposerFromBlock_Call { +func (_c *MockExecutorI_UpdateProposerFromBlock_Call) Run(run func(s *types.State, seqSet *types.SequencerSet, _a2 *types.Block)) *MockExecutorI_UpdateProposerFromBlock_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*types.State), args[1].(*types.Block)) + run(args[0].(*types.State), args[1].(*types.SequencerSet), args[2].(*types.Block)) }) return _c } @@ -397,7 +397,7 @@ func (_c *MockExecutorI_UpdateProposerFromBlock_Call) Return(_a0 bool) *MockExec return _c } -func (_c *MockExecutorI_UpdateProposerFromBlock_Call) RunAndReturn(run func(*types.State, *types.Block) bool) *MockExecutorI_UpdateProposerFromBlock_Call { +func (_c *MockExecutorI_UpdateProposerFromBlock_Call) RunAndReturn(run func(*types.State, *types.SequencerSet, *types.Block) bool) *MockExecutorI_UpdateProposerFromBlock_Call { _c.Call.Return(run) return _c } diff --git a/mocks/github.com/dymensionxyz/dymint/block/mock_FraudHandler.go b/mocks/github.com/dymensionxyz/dymint/block/mock_FraudHandler.go index 932c51a2e..b9ddec5ac 100644 --- a/mocks/github.com/dymensionxyz/dymint/block/mock_FraudHandler.go +++ b/mocks/github.com/dymensionxyz/dymint/block/mock_FraudHandler.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package block diff --git a/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go b/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go index 6a52c1df8..bba31b087 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go +++ b/mocks/github.com/dymensionxyz/dymint/da/avail/mock_SubstrateApiI.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package avail diff --git a/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go b/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go index 4935cc66a..5994cf817 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go +++ b/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package types diff --git a/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go b/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go index 0e79e172c..3478b4c1a 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go +++ b/mocks/github.com/dymensionxyz/dymint/da/mock_DataAvailabilityLayerClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package da diff --git a/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go b/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go index 52210eec7..03ca2d67a 100644 --- a/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go +++ b/mocks/github.com/dymensionxyz/dymint/settlement/dymension/mock_CosmosClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package dymension diff --git a/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go b/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go index 5aa37eb41..c21146436 100644 --- a/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go +++ b/mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package settlement diff --git a/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go b/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go index a555c6612..0432de012 100644 --- a/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go +++ b/mocks/github.com/dymensionxyz/dymint/store/mock_Store.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package store @@ -473,24 +473,24 @@ func (_c *MockStore_LoadCommitByHash_Call) RunAndReturn(run func([32]byte) (*typ return _c } -// LoadSequencers provides a mock function with given fields: height -func (_m *MockStore) LoadSequencers(height uint64) (*types.SequencerSet, error) { +// LoadProposer provides a mock function with given fields: height +func (_m *MockStore) LoadProposer(height uint64) (*types.Sequencer, error) { ret := _m.Called(height) if len(ret) == 0 { - panic("no return value specified for LoadSequencers") + panic("no return value specified for LoadProposer") } - var r0 *types.SequencerSet + var r0 *types.Sequencer var r1 error - if rf, ok := ret.Get(0).(func(uint64) (*types.SequencerSet, error)); ok { + if rf, ok := ret.Get(0).(func(uint64) (*types.Sequencer, error)); ok { return rf(height) } - if rf, ok := ret.Get(0).(func(uint64) *types.SequencerSet); ok { + if rf, ok := ret.Get(0).(func(uint64) *types.Sequencer); ok { r0 = rf(height) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.SequencerSet) + r0 = ret.Get(0).(*types.Sequencer) } } @@ -503,30 +503,30 @@ func (_m *MockStore) LoadSequencers(height uint64) (*types.SequencerSet, error) return r0, r1 } -// MockStore_LoadSequencers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadSequencers' -type MockStore_LoadSequencers_Call struct { +// MockStore_LoadProposer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadProposer' +type MockStore_LoadProposer_Call struct { *mock.Call } -// LoadSequencers is a helper method to define mock.On call +// LoadProposer is a helper method to define mock.On call // - height uint64 -func (_e *MockStore_Expecter) LoadSequencers(height interface{}) *MockStore_LoadSequencers_Call { - return &MockStore_LoadSequencers_Call{Call: _e.mock.On("LoadSequencers", height)} +func (_e *MockStore_Expecter) LoadProposer(height interface{}) *MockStore_LoadProposer_Call { + return &MockStore_LoadProposer_Call{Call: _e.mock.On("LoadProposer", height)} } -func (_c *MockStore_LoadSequencers_Call) Run(run func(height uint64)) *MockStore_LoadSequencers_Call { +func (_c *MockStore_LoadProposer_Call) Run(run func(height uint64)) *MockStore_LoadProposer_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(uint64)) }) return _c } -func (_c *MockStore_LoadSequencers_Call) Return(_a0 *types.SequencerSet, _a1 error) *MockStore_LoadSequencers_Call { +func (_c *MockStore_LoadProposer_Call) Return(_a0 *types.Sequencer, _a1 error) *MockStore_LoadProposer_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockStore_LoadSequencers_Call) RunAndReturn(run func(uint64) (*types.SequencerSet, error)) *MockStore_LoadSequencers_Call { +func (_c *MockStore_LoadProposer_Call) RunAndReturn(run func(uint64) (*types.Sequencer, error)) *MockStore_LoadProposer_Call { _c.Call.Return(run) return _c } @@ -988,29 +988,29 @@ func (_c *MockStore_SaveBlockSource_Call) RunAndReturn(run func(uint64, types.Bl return _c } -// SaveSequencers provides a mock function with given fields: height, seqSet, batch -func (_m *MockStore) SaveSequencers(height uint64, seqSet *types.SequencerSet, batch store.KVBatch) (store.KVBatch, error) { - ret := _m.Called(height, seqSet, batch) +// SaveProposer provides a mock function with given fields: height, proposer, batch +func (_m *MockStore) SaveProposer(height uint64, proposer *types.Sequencer, batch store.KVBatch) (store.KVBatch, error) { + ret := _m.Called(height, proposer, batch) if len(ret) == 0 { - panic("no return value specified for SaveSequencers") + panic("no return value specified for SaveProposer") } var r0 store.KVBatch var r1 error - if rf, ok := ret.Get(0).(func(uint64, *types.SequencerSet, store.KVBatch) (store.KVBatch, error)); ok { - return rf(height, seqSet, batch) + if rf, ok := ret.Get(0).(func(uint64, *types.Sequencer, store.KVBatch) (store.KVBatch, error)); ok { + return rf(height, proposer, batch) } - if rf, ok := ret.Get(0).(func(uint64, *types.SequencerSet, store.KVBatch) store.KVBatch); ok { - r0 = rf(height, seqSet, batch) + if rf, ok := ret.Get(0).(func(uint64, *types.Sequencer, store.KVBatch) store.KVBatch); ok { + r0 = rf(height, proposer, batch) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(store.KVBatch) } } - if rf, ok := ret.Get(1).(func(uint64, *types.SequencerSet, store.KVBatch) error); ok { - r1 = rf(height, seqSet, batch) + if rf, ok := ret.Get(1).(func(uint64, *types.Sequencer, store.KVBatch) error); ok { + r1 = rf(height, proposer, batch) } else { r1 = ret.Error(1) } @@ -1018,32 +1018,32 @@ func (_m *MockStore) SaveSequencers(height uint64, seqSet *types.SequencerSet, b return r0, r1 } -// MockStore_SaveSequencers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveSequencers' -type MockStore_SaveSequencers_Call struct { +// MockStore_SaveProposer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveProposer' +type MockStore_SaveProposer_Call struct { *mock.Call } -// SaveSequencers is a helper method to define mock.On call +// SaveProposer is a helper method to define mock.On call // - height uint64 -// - seqSet *types.SequencerSet +// - proposer *types.Sequencer // - batch store.KVBatch -func (_e *MockStore_Expecter) SaveSequencers(height interface{}, seqSet interface{}, batch interface{}) *MockStore_SaveSequencers_Call { - return &MockStore_SaveSequencers_Call{Call: _e.mock.On("SaveSequencers", height, seqSet, batch)} +func (_e *MockStore_Expecter) SaveProposer(height interface{}, proposer interface{}, batch interface{}) *MockStore_SaveProposer_Call { + return &MockStore_SaveProposer_Call{Call: _e.mock.On("SaveProposer", height, proposer, batch)} } -func (_c *MockStore_SaveSequencers_Call) Run(run func(height uint64, seqSet *types.SequencerSet, batch store.KVBatch)) *MockStore_SaveSequencers_Call { +func (_c *MockStore_SaveProposer_Call) Run(run func(height uint64, proposer *types.Sequencer, batch store.KVBatch)) *MockStore_SaveProposer_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(uint64), args[1].(*types.SequencerSet), args[2].(store.KVBatch)) + run(args[0].(uint64), args[1].(*types.Sequencer), args[2].(store.KVBatch)) }) return _c } -func (_c *MockStore_SaveSequencers_Call) Return(_a0 store.KVBatch, _a1 error) *MockStore_SaveSequencers_Call { +func (_c *MockStore_SaveProposer_Call) Return(_a0 store.KVBatch, _a1 error) *MockStore_SaveProposer_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockStore_SaveSequencers_Call) RunAndReturn(run func(uint64, *types.SequencerSet, store.KVBatch) (store.KVBatch, error)) *MockStore_SaveSequencers_Call { +func (_c *MockStore_SaveProposer_Call) RunAndReturn(run func(uint64, *types.Sequencer, store.KVBatch) (store.KVBatch, error)) *MockStore_SaveProposer_Call { _c.Call.Return(run) return _c } diff --git a/mocks/github.com/dymensionxyz/dymint/third_party/dymension/sequencer/types/mock_QueryClient.go b/mocks/github.com/dymensionxyz/dymint/third_party/dymension/sequencer/types/mock_QueryClient.go index 24f426b0f..c2ce005b5 100644 --- a/mocks/github.com/dymensionxyz/dymint/third_party/dymension/sequencer/types/mock_QueryClient.go +++ b/mocks/github.com/dymensionxyz/dymint/third_party/dymension/sequencer/types/mock_QueryClient.go @@ -333,7 +333,7 @@ func (_m *MockQueryClient) Sequencers(ctx context.Context, in *types.QuerySequen ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for Sequencers") + panic("no return value specified for sequencers") } var r0 *types.QuerySequencersResponse @@ -368,7 +368,7 @@ type MockQueryClient_Sequencers_Call struct { // - in *types.QuerySequencersRequest // - opts ...grpc.CallOption func (_e *MockQueryClient_Expecter) Sequencers(ctx interface{}, in interface{}, opts ...interface{}) *MockQueryClient_Sequencers_Call { - return &MockQueryClient_Sequencers_Call{Call: _e.mock.On("Sequencers", + return &MockQueryClient_Sequencers_Call{Call: _e.mock.On("sequencers", append([]interface{}{ctx, in}, opts...)...)} } diff --git a/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp/mock_QueryClient.go b/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp/mock_QueryClient.go index 83c174f72..f182218a5 100644 --- a/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp/mock_QueryClient.go +++ b/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp/mock_QueryClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package rollapp diff --git a/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/sequencer/mock_QueryClient.go b/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/sequencer/mock_QueryClient.go index af5bcaf4b..ba704d658 100644 --- a/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/sequencer/mock_QueryClient.go +++ b/mocks/github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/sequencer/mock_QueryClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package sequencer diff --git a/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go b/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go index 7393ef94e..45011bdc9 100644 --- a/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go +++ b/mocks/github.com/tendermint/tendermint/abci/types/mock_Application.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package types diff --git a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go index 9ec6b2d18..9a28054e1 100644 --- a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go +++ b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConnConsensus.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package proxy diff --git a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go index affc90a4e..120c2f698 100644 --- a/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go +++ b/mocks/github.com/tendermint/tendermint/proxy/mock_AppConns.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.3. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package proxy diff --git a/p2p/validator_test.go b/p2p/validator_test.go index aba9372db..1d09b654e 100644 --- a/p2p/validator_test.go +++ b/p2p/validator_test.go @@ -131,12 +131,12 @@ func TestValidator_BlockValidator(t *testing.T) { // Create state maxBytes := uint64(100) state := &types.State{} - state.Sequencers.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(proposerKey.PubKey(), 1))) + state.SetProposer(types.NewSequencerFromValidator(*tmtypes.NewValidator(proposerKey.PubKey(), 1))) 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) + block := executor.CreateBlock(1, &types.Commit{}, [32]byte{}, [32]byte(state.GetProposerHash()), state, maxBytes) getProposer := &p2pmock.MockGetProposerI{} getProposer.On("GetProposerPubKey").Return(proposerKey.PubKey()) diff --git a/proto/types/dymint/dymint.proto b/proto/types/dymint/dymint.proto index baa4436a7..3cb25b644 100755 --- a/proto/types/dymint/dymint.proto +++ b/proto/types/dymint/dymint.proto @@ -1,6 +1,8 @@ syntax = "proto3"; package dymint; option go_package = "github.com/dymensionxyz/dymint/types/pb/dymint"; + +import "gogoproto/gogo.proto"; import "types/tendermint/abci/types.proto"; import "types/tendermint/types/types.proto"; import "types/tendermint/types/validator.proto"; @@ -94,12 +96,7 @@ message Batch { message Sequencer { string settlement_address = 1; - tendermint.types.Validator validator = 2; -} - -message SequencerSet { - repeated Sequencer sequencers = 1; - Sequencer proposer = 2; + tendermint.types.Validator validator = 2 [(gogoproto.nullable) = false]; } message EventKeys { diff --git a/proto/types/dymint/state.proto b/proto/types/dymint/state.proto index e773b34f0..41204766f 100755 --- a/proto/types/dymint/state.proto +++ b/proto/types/dymint/state.proto @@ -42,11 +42,12 @@ message State { uint64 last_store_height = 16 [(gogoproto.customname) = "LastStoreHeight"]; uint64 base_height = 17; - SequencerSet sequencerSet = 18 [(gogoproto.nullable) = false]; - RollappParams rollapp_params = 19 [(gogoproto.nullable) = false]; + RollappParams rollapp_params = 18 [(gogoproto.nullable) = false]; - bytes last_header_hash = 20; + bytes last_header_hash = 19; + // Proposer is a sequencer that acts as a proposer. Can be nil if no proposer is set. + Sequencer proposer = 20; } //rollapp params defined in genesis and updated via gov proposal diff --git a/rpc/client/client.go b/rpc/client/client.go index 66ee8e171..f754cd91a 100644 --- a/rpc/client/client.go +++ b/rpc/client/client.go @@ -520,13 +520,15 @@ func (c *Client) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommi // Validators returns paginated list of validators at given height. func (c *Client) Validators(ctx context.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) { height := c.normalizeHeight(heightPtr) - sequencers, err := c.node.Store.LoadSequencers(height) + + proposer, err := c.node.Store.LoadProposer(height) if err != nil { - return nil, fmt.Errorf("load validators for height %d: %w", height, err) + return nil, fmt.Errorf("load validators: height %d: %w", height, err) } + return &ctypes.ResultValidators{ BlockHeight: int64(height), - Validators: sequencers.Proposer.TMValidators(), + Validators: proposer.TMValidators(), Count: 1, Total: 1, }, nil @@ -709,14 +711,10 @@ func (c *Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) { latestHeight := latest.Header.Height latestBlockTimeNano := latest.Header.Time - sequencers, err := c.node.Store.LoadSequencers(latest.Header.Height) + proposer, err := c.node.Store.LoadProposer(latest.Header.Height) if err != nil { return nil, fmt.Errorf("fetch the validator info at latest block: %w", err) } - proposer := sequencers.Proposer - if proposer == nil { - return nil, fmt.Errorf("find proposer %s in the valSet", string(latest.Header.ProposerAddress)) - } state, err := c.node.Store.LoadState() if err != nil { return nil, fmt.Errorf("load the last saved state: %w", err) diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index d103bbb34..77e0cc252 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -434,10 +434,10 @@ func TestValidatorSetHashConsistency(t *testing.T) { v := tmtypes.NewValidator(ed25519.GenPrivKey().PubKey(), 1) s := types.NewSequencerFromValidator(*v) - node.BlockManager.State.Sequencers.SetProposer(s) + node.BlockManager.State.SetProposer(s) b := getRandomBlock(1, 10) - copy(b.Header.SequencerHash[:], node.BlockManager.State.Sequencers.ProposerHash()) + copy(b.Header.SequencerHash[:], node.BlockManager.State.GetProposerHash()) err := node.Start() require.NoError(err) @@ -447,7 +447,7 @@ func TestValidatorSetHashConsistency(t *testing.T) { require.NoError(err) batch := node.Store.NewBatch() - batch, err = node.Store.SaveSequencers(b.Header.Height, &node.BlockManager.State.Sequencers, batch) + batch, err = node.Store.SaveProposer(b.Header.Height, *node.BlockManager.State.GetProposer(), batch) require.NoError(err) err = batch.Commit() require.NoError(err) diff --git a/store/pruning.go b/store/pruning.go index b1f97facb..93b2c3f11 100644 --- a/store/pruning.go +++ b/store/pruning.go @@ -3,11 +3,12 @@ package store import ( "fmt" - "github.com/dymensionxyz/dymint/types" "github.com/dymensionxyz/gerr-cosmos/gerrc" + + "github.com/dymensionxyz/dymint/types" ) -// PruneStore removes blocks up to (but not including) a height. It returns number of blocks pruned. +// PruneStore removes store items up to (but not including) a height. It returns number of blocks pruned. func (s *DefaultStore) PruneStore(from, to uint64, logger types.Logger) (uint64, error) { if from <= 0 { return 0, fmt.Errorf("from height must be greater than 0: %w", gerrc.ErrInvalidArgument) @@ -27,11 +28,6 @@ func (s *DefaultStore) PruneStore(from, to uint64, logger types.Logger) (uint64, logger.Error("pruning responses", "from", from, "to", to, "responses pruned", prunedResponses, "err", err) } - prunedSequencers, err := s.pruneSequencers(from, to, logger) - if err != nil { - logger.Error("pruning sequencers", "from", from, "to", to, "sequencers pruned", prunedSequencers, "err", err) - } - prunedCids, err := s.pruneCids(from, to, logger) if err != nil { logger.Error("pruning block sync identifiers", "from", from, "to", to, "cids pruned", prunedCids, "err", err) @@ -42,6 +38,11 @@ func (s *DefaultStore) PruneStore(from, to uint64, logger types.Logger) (uint64, logger.Error("pruning drs version", "from", from, "to", to, "drs pruned", prunedDRS, "err", err) } + prunedProposers, err := s.pruneProposers(from, to, logger) + if err != nil { + logger.Error("pruning block sync identifiers", "from", from, "to", to, "proposers pruned", prunedProposers, "err", err) + } + return prunedBlocks, nil } @@ -78,15 +79,6 @@ func (s *DefaultStore) pruneResponses(from, to uint64, logger types.Logger) (uin return prunedResponses, err } -// pruneSequencers prunes sequencers from store -func (s *DefaultStore) pruneSequencers(from, to uint64, logger types.Logger) (uint64, error) { - pruneSequencers := func(batch KVBatch, height uint64) error { - return batch.Delete(getSequencersKey(height)) - } - prunedSequencers, err := s.pruneHeights(from, to, pruneSequencers, logger) - return prunedSequencers, err -} - // pruneCids prunes content identifiers from store func (s *DefaultStore) pruneCids(from, to uint64, logger types.Logger) (uint64, error) { pruneCids := func(batch KVBatch, height uint64) error { @@ -146,3 +138,12 @@ func (s *DefaultStore) pruneHeights(from, to uint64, prune func(batch KVBatch, h return pruned, nil } + +// pruneSequencers prunes proposer from store +func (s *DefaultStore) pruneProposers(from, to uint64, logger types.Logger) (uint64, error) { + pruneProposers := func(batch KVBatch, height uint64) error { + return batch.Delete(getProposerKey(height)) + } + prunedSequencers, err := s.pruneHeights(from, to, pruneProposers, logger) + return prunedSequencers, err +} diff --git a/store/pruning_test.go b/store/pruning_test.go index f9c79f41a..b0d4991d2 100644 --- a/store/pruning_test.go +++ b/store/pruning_test.go @@ -3,15 +3,16 @@ package store_test import ( "testing" - "github.com/dymensionxyz/dymint/store" - "github.com/dymensionxyz/dymint/testutil" - "github.com/dymensionxyz/dymint/types" "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/proto/tendermint/state" "golang.org/x/exp/rand" + + "github.com/dymensionxyz/dymint/store" + "github.com/dymensionxyz/dymint/testutil" + "github.com/dymensionxyz/dymint/types" ) func TestStorePruning(t *testing.T) { @@ -84,7 +85,7 @@ func TestStorePruning(t *testing.T) { // generate and store sequencers randomly for block heights if randBool() { - _, err = bstore.SaveSequencers(block.Header.Height, &types.SequencerSet{}, nil) + _, err = bstore.SaveProposer(block.Header.Height, testutil.GenerateSequencer(), nil) savedSeqHeights[block.Header.Height] = true assert.NoError(err) } @@ -129,7 +130,7 @@ func TestStorePruning(t *testing.T) { } for k := range savedSeqHeights { - _, err := bstore.LoadSequencers(k) + _, err := bstore.LoadProposer(k) assert.NoError(err) } @@ -184,10 +185,10 @@ func TestStorePruning(t *testing.T) { // Validate only sequencers in the range are pruned for k := range savedSeqHeights { if k >= c.from && k < c.to { // k < c.to is the exclusion test - _, err = bstore.LoadSequencers(k) + _, err = bstore.LoadProposer(k) assert.Error(err, "Block cid at height %d should be pruned", k) } else { - _, err = bstore.LoadSequencers(k) + _, err = bstore.LoadProposer(k) assert.NoError(err) } } diff --git a/store/store.go b/store/store.go index 3638d1ef5..4ce428306 100644 --- a/store/store.go +++ b/store/store.go @@ -7,8 +7,6 @@ import ( "github.com/ipfs/go-cid" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtypes "github.com/tendermint/tendermint/types" "go.uber.org/multierr" "github.com/dymensionxyz/dymint/types" @@ -21,7 +19,7 @@ var ( commitPrefix = [1]byte{3} statePrefix = [1]byte{4} responsesPrefix = [1]byte{5} - sequencersPrefix = [1]byte{6} + proposerPrefix = [1]byte{6} cidPrefix = [1]byte{7} sourcePrefix = [1]byte{8} validatedHeightPrefix = [1]byte{9} @@ -119,7 +117,7 @@ func (s *DefaultStore) LoadBlockByHash(hash [32]byte) (*types.Block, error) { return block, nil } -// SaveBlockValidation saves block validation in Store. +// SaveBlockSource saves block validation in Store. func (s *DefaultStore) SaveBlockSource(height uint64, source types.BlockSource, batch KVBatch) (KVBatch, error) { b := make([]byte, 8) binary.LittleEndian.PutUint64(b, uint64(source)) @@ -130,7 +128,7 @@ func (s *DefaultStore) SaveBlockSource(height uint64, source types.BlockSource, return batch, err } -// LoadBlockValidation returns block validation in Store. +// LoadBlockSource returns block validation in Store. func (s *DefaultStore) LoadBlockSource(height uint64) (types.BlockSource, error) { source, err := s.db.Get(getSourceKey(height)) if err != nil { @@ -229,61 +227,42 @@ func (s *DefaultStore) LoadState() (*types.State, error) { return &state, nil } -// SaveSequencers stores sequencerSet for given block height in store. -func (s *DefaultStore) SaveSequencers(height uint64, sequencerSet *types.SequencerSet, batch KVBatch) (KVBatch, error) { - pbValSet, err := sequencerSet.ToProto() +// SaveProposer stores the proposer for given block height in store. +func (s *DefaultStore) SaveProposer(height uint64, proposer types.Sequencer, batch KVBatch) (KVBatch, error) { + pbProposer, err := proposer.ToProto() if err != nil { - return batch, fmt.Errorf("marshal sequencerSet to protobuf: %w", err) + return batch, fmt.Errorf("marshal proposer to protobuf: %w", err) } - blob, err := pbValSet.Marshal() + blob, err := pbProposer.Marshal() if err != nil { - return batch, fmt.Errorf("marshal sequencerSet: %w", err) + return batch, fmt.Errorf("marshal proposer: %w", err) } if batch == nil { - return nil, s.db.Set(getSequencersKey(height), blob) + return nil, s.db.Set(getProposerKey(height), blob) } - err = batch.Set(getSequencersKey(height), blob) + err = batch.Set(getProposerKey(height), blob) return batch, err } -// LoadSequencers loads sequencer set at given block height from store. -func (s *DefaultStore) LoadSequencers(height uint64) (*types.SequencerSet, error) { - blob, err := s.db.Get(getSequencersKey(height)) +// LoadProposer loads proposer at given block height from store. +func (s *DefaultStore) LoadProposer(height uint64) (types.Sequencer, error) { + blob, err := s.db.Get(getProposerKey(height)) if err != nil { - return nil, fmt.Errorf("load sequencers for height %v: %w", height, err) + return types.Sequencer{}, fmt.Errorf("load proposer for height %v: %w", height, err) } - var pbValSet pb.SequencerSet - err = pbValSet.Unmarshal(blob) - if err != nil { - // migration support: try to unmarshal as old ValidatorSet - return parseAsValidatorSet(blob) - } - - var ss types.SequencerSet - err = ss.FromProto(pbValSet) - if err != nil { - return nil, fmt.Errorf("unmarshal from proto: %w", err) - } - - return &ss, nil -} -func parseAsValidatorSet(blob []byte) (*types.SequencerSet, error) { - var ( - ss types.SequencerSet - pbValSetOld tmproto.ValidatorSet - ) - err := pbValSetOld.Unmarshal(blob) + pbProposer := new(pb.Sequencer) + err = pbProposer.Unmarshal(blob) if err != nil { - return nil, fmt.Errorf("unmarshal protobuf: %w", err) + return types.Sequencer{}, fmt.Errorf("parsing blob as proposer: %w", err) } - pbValSet, err := tmtypes.ValidatorSetFromProto(&pbValSetOld) + proposer, err := types.SequencerFromProto(pbProposer) if err != nil { - return nil, fmt.Errorf("unmarshal to ValidatorSet: %w", err) + return types.Sequencer{}, fmt.Errorf("unmarshal proposer from proto: %w", err) } - ss.LoadFromValSet(pbValSet) - return &ss, nil + + return *proposer, nil } func (s *DefaultStore) loadHashFromIndex(height uint64) ([32]byte, error) { @@ -379,12 +358,6 @@ func getResponsesKey(height uint64) []byte { return append(responsesPrefix[:], buf[:]...) } -func getSequencersKey(height uint64) []byte { - buf := make([]byte, 8) - binary.BigEndian.PutUint64(buf, height) - return append(sequencersPrefix[:], buf[:]...) -} - func getCidKey(height uint64) []byte { buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, height) @@ -406,3 +379,9 @@ func getDRSVersionKey(height uint64) []byte { binary.BigEndian.PutUint64(buf, height) return append(drsVersionPrefix[:], buf[:]...) } + +func getProposerKey(height uint64) []byte { + buf := make([]byte, 8) + binary.BigEndian.PutUint64(buf, height) + return append(proposerPrefix[:], buf[:]...) +} diff --git a/store/storeIface.go b/store/storeIface.go index 494b04ef8..d93658805 100644 --- a/store/storeIface.go +++ b/store/storeIface.go @@ -1,9 +1,10 @@ package store import ( - "github.com/dymensionxyz/dymint/types" "github.com/ipfs/go-cid" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + + "github.com/dymensionxyz/dymint/types" ) // KV encapsulates key-value store abstraction, in minimalistic interface. @@ -67,9 +68,9 @@ type Store interface { // LoadState returns last state saved with UpdateState. LoadState() (*types.State, error) - SaveSequencers(height uint64, seqSet *types.SequencerSet, batch KVBatch) (KVBatch, error) + SaveProposer(height uint64, proposer types.Sequencer, batch KVBatch) (KVBatch, error) - LoadSequencers(height uint64) (*types.SequencerSet, error) + LoadProposer(height uint64) (types.Sequencer, error) PruneStore(from, to uint64, logger types.Logger) (uint64, error) diff --git a/store/store_test.go b/store/store_test.go index f7afb7746..62f57bb6f 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -7,16 +7,14 @@ import ( "github.com/dymensionxyz/gerr-cosmos/gerrc" "github.com/ipfs/go-cid" mh "github.com/multiformats/go-multihash" - + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/dymensionxyz/dymint/store" - "github.com/dymensionxyz/dymint/testutil" "github.com/dymensionxyz/dymint/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestStoreLoad(t *testing.T) { @@ -92,13 +90,10 @@ func TestLoadState(t *testing.T) { assert := assert.New(t) - validatorSet := testutil.GenerateRandomValidatorSet() - kv := store.NewDefaultInMemoryKVStore() s1 := store.New(kv) expectedHeight := uint64(10) s := &types.State{} - s.Sequencers.LoadFromValSet(validatorSet) s.SetHeight(expectedHeight) _, err := s1.SaveState(s, nil) @@ -249,3 +244,47 @@ func TestBlockId(t *testing.T) { require.NoError(err) require.Equal(expectedCid, resultCid) } + +func TestProposer(t *testing.T) { + t.Parallel() + + expected := testutil.GenerateSequencer() + + t.Run("happy path", func(t *testing.T) { + t.Parallel() + + s := store.New(store.NewDefaultInMemoryKVStore()) + + _, err := s.SaveProposer(1, expected, nil) + require.NoError(t, err) + + resp, err := s.LoadProposer(1) + require.NoError(t, err) + require.NotNil(t, resp) + require.Equal(t, expected, resp) + }) + + t.Run("proposer not found", func(t *testing.T) { + t.Parallel() + + s := store.New(store.NewDefaultInMemoryKVStore()) + + _, err := s.SaveProposer(2, expected, nil) + require.NoError(t, err) + + _, err = s.LoadProposer(2000) + require.Error(t, err) + }) + + t.Run("empty proposer is invalid", func(t *testing.T) { + t.Parallel() + + s := store.New(store.NewDefaultInMemoryKVStore()) + + _, err := s.SaveProposer(3, types.Sequencer{}, nil) + require.Error(t, err) + + _, err = s.LoadProposer(3) + require.Error(t, err) + }) +} diff --git a/testutil/types.go b/testutil/types.go index dcc8deb8f..aa7325c2c 100644 --- a/testutil/types.go +++ b/testutil/types.go @@ -5,9 +5,7 @@ import ( "math/big" "time" - "github.com/dymensionxyz/dymint/types" - "github.com/dymensionxyz/dymint/types/pb/dymint" - dymintversion "github.com/dymensionxyz/dymint/version" + "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/libp2p/go-libp2p/core/crypto" abci "github.com/tendermint/tendermint/abci/types" tmcrypto "github.com/tendermint/tendermint/crypto" @@ -16,6 +14,10 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" version "github.com/tendermint/tendermint/proto/tendermint/version" tmtypes "github.com/tendermint/tendermint/types" + + "github.com/dymensionxyz/dymint/types" + "github.com/dymensionxyz/dymint/types/pb/dymint" + dymintversion "github.com/dymensionxyz/dymint/version" ) const ( @@ -23,6 +25,8 @@ const ( BlockVersion = 1 // AppVersion is the default app version for testing AppVersion = 2 + + SettlementAccountPrefix = "dym" ) func createRandomHashes() [][32]byte { @@ -50,6 +54,15 @@ func GetRandomBytes(n uint64) []byte { return data } +func GenerateSettlementAddress() string { + addrBytes := ed25519.GenPrivKey().PubKey().Address().Bytes() + addr, err := bech32.ConvertAndEncode(SettlementAccountPrefix, addrBytes) + if err != nil { + panic(err) + } + return addr +} + // generateBlock generates random blocks. func generateBlock(height uint64, proposerHash []byte, lastHeaderHash [32]byte) *types.Block { h := createRandomHashes() @@ -239,6 +252,13 @@ func GenerateRandomValidatorSet() *tmtypes.ValidatorSet { }) } +func GenerateSequencer() types.Sequencer { + return *types.NewSequencer( + tmtypes.NewValidator(ed25519.GenPrivKey().PubKey(), 1).PubKey, + GenerateSettlementAddress(), + ) +} + // GenerateStateWithSequencer generates an initial state for testing. func GenerateStateWithSequencer(initialHeight int64, lastBlockHeight int64, pubkey tmcrypto.PubKey) *types.State { s := &types.State{ @@ -264,7 +284,7 @@ func GenerateStateWithSequencer(initialHeight int64, lastBlockHeight int64, pubk }, }, } - s.Sequencers.SetProposer(types.NewSequencer(pubkey, "")) + s.SetProposer(types.NewSequencer(pubkey, "")) s.SetHeight(uint64(lastBlockHeight)) return s } diff --git a/types/pb/dymint/dymint.pb.go b/types/pb/dymint/dymint.pb.go index eb1bb5942..ad2b1289a 100644 --- a/types/pb/dymint/dymint.pb.go +++ b/types/pb/dymint/dymint.pb.go @@ -5,6 +5,7 @@ package dymint import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types2 "github.com/gogo/protobuf/types" types1 "github.com/tendermint/tendermint/abci/types" @@ -516,8 +517,8 @@ func (m *Batch) GetCommits() []*Commit { } type Sequencer struct { - SettlementAddress string `protobuf:"bytes,1,opt,name=settlement_address,json=settlementAddress,proto3" json:"settlement_address,omitempty"` - Validator *types.Validator `protobuf:"bytes,2,opt,name=validator,proto3" json:"validator,omitempty"` + SettlementAddress string `protobuf:"bytes,1,opt,name=settlement_address,json=settlementAddress,proto3" json:"settlement_address,omitempty"` + Validator types.Validator `protobuf:"bytes,2,opt,name=validator,proto3" json:"validator"` } func (m *Sequencer) Reset() { *m = Sequencer{} } @@ -560,63 +561,11 @@ func (m *Sequencer) GetSettlementAddress() string { return "" } -func (m *Sequencer) GetValidator() *types.Validator { +func (m *Sequencer) GetValidator() types.Validator { if m != nil { return m.Validator } - return nil -} - -type SequencerSet struct { - Sequencers []*Sequencer `protobuf:"bytes,1,rep,name=sequencers,proto3" json:"sequencers,omitempty"` - Proposer *Sequencer `protobuf:"bytes,2,opt,name=proposer,proto3" json:"proposer,omitempty"` -} - -func (m *SequencerSet) Reset() { *m = SequencerSet{} } -func (m *SequencerSet) String() string { return proto.CompactTextString(m) } -func (*SequencerSet) ProtoMessage() {} -func (*SequencerSet) Descriptor() ([]byte, []int) { - return fileDescriptor_fe69c538ded4b87f, []int{7} -} -func (m *SequencerSet) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SequencerSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SequencerSet.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SequencerSet) XXX_Merge(src proto.Message) { - xxx_messageInfo_SequencerSet.Merge(m, src) -} -func (m *SequencerSet) XXX_Size() int { - return m.Size() -} -func (m *SequencerSet) XXX_DiscardUnknown() { - xxx_messageInfo_SequencerSet.DiscardUnknown(m) -} - -var xxx_messageInfo_SequencerSet proto.InternalMessageInfo - -func (m *SequencerSet) GetSequencers() []*Sequencer { - if m != nil { - return m.Sequencers - } - return nil -} - -func (m *SequencerSet) GetProposer() *Sequencer { - if m != nil { - return m.Proposer - } - return nil + return types.Validator{} } type EventKeys struct { @@ -627,7 +576,7 @@ func (m *EventKeys) Reset() { *m = EventKeys{} } func (m *EventKeys) String() string { return proto.CompactTextString(m) } func (*EventKeys) ProtoMessage() {} func (*EventKeys) Descriptor() ([]byte, []int) { - return fileDescriptor_fe69c538ded4b87f, []int{8} + return fileDescriptor_fe69c538ded4b87f, []int{7} } func (m *EventKeys) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -671,68 +620,66 @@ func init() { proto.RegisterType((*Block)(nil), "dymint.Block") proto.RegisterType((*Batch)(nil), "dymint.Batch") proto.RegisterType((*Sequencer)(nil), "dymint.Sequencer") - proto.RegisterType((*SequencerSet)(nil), "dymint.SequencerSet") proto.RegisterType((*EventKeys)(nil), "dymint.EventKeys") } func init() { proto.RegisterFile("types/dymint/dymint.proto", fileDescriptor_fe69c538ded4b87f) } var fileDescriptor_fe69c538ded4b87f = []byte{ - // 864 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x95, 0xcf, 0x6f, 0xdb, 0x36, - 0x14, 0xc7, 0xa3, 0xc4, 0xf1, 0x8f, 0x27, 0x27, 0x8d, 0xb9, 0xa2, 0x90, 0x5b, 0xcc, 0x4d, 0x05, - 0xa4, 0x48, 0x07, 0x54, 0x46, 0x3d, 0x0c, 0xd8, 0x2e, 0x03, 0x9a, 0xae, 0x40, 0x8a, 0x61, 0x17, - 0x19, 0xe8, 0x61, 0x17, 0x83, 0x96, 0xde, 0x2c, 0xa1, 0x16, 0xa5, 0x89, 0x74, 0x10, 0xef, 0xd8, - 0xbf, 0x60, 0xe7, 0xdd, 0xf6, 0xdf, 0xec, 0x34, 0xf4, 0xb8, 0xe3, 0x90, 0xfc, 0x23, 0x03, 0x1f, - 0x49, 0x59, 0xed, 0xd2, 0x4b, 0x22, 0x7e, 0xbf, 0x1f, 0x91, 0xcf, 0xef, 0x07, 0x05, 0x63, 0xb5, - 0xad, 0x50, 0x4e, 0xd3, 0x6d, 0x91, 0x0b, 0x65, 0xff, 0x45, 0x55, 0x5d, 0xaa, 0x92, 0x75, 0xcd, - 0xea, 0xe1, 0x13, 0x83, 0x28, 0x14, 0x29, 0xd6, 0x84, 0xf1, 0x65, 0x92, 0x4f, 0x49, 0x35, 0xe8, - 0xc3, 0xf0, 0x7f, 0x88, 0x15, 0x5a, 0xcc, 0xd3, 0xcf, 0x30, 0x57, 0x7c, 0x9d, 0xa7, 0x5c, 0x95, - 0xb5, 0xe5, 0xc6, 0xab, 0xb2, 0x5c, 0xad, 0x71, 0x4a, 0xab, 0xe5, 0xe6, 0x97, 0x29, 0x17, 0x5b, - 0x63, 0x85, 0x2f, 0xa0, 0xf7, 0x16, 0x6b, 0x99, 0x97, 0x82, 0xdd, 0x87, 0xc3, 0xe5, 0xba, 0x4c, - 0xde, 0x05, 0xde, 0xa9, 0x77, 0xde, 0x89, 0xcd, 0x82, 0x9d, 0xc0, 0x01, 0xaf, 0xaa, 0x60, 0x9f, - 0x34, 0xfd, 0x18, 0xbe, 0xef, 0x40, 0xf7, 0x12, 0x79, 0x8a, 0x35, 0x7b, 0x06, 0xbd, 0x2b, 0xf3, - 0x36, 0xbd, 0xe4, 0xcf, 0xee, 0x45, 0xf6, 0xf7, 0xda, 0x4d, 0x63, 0xe7, 0xb3, 0x33, 0x18, 0x0a, - 0x5e, 0xa0, 0xac, 0x78, 0x82, 0x8b, 0x3c, 0xa5, 0x0d, 0x87, 0x17, 0xfb, 0x81, 0x17, 0xfb, 0x8d, - 0xfe, 0x26, 0x65, 0x0f, 0xa0, 0x9b, 0x61, 0xbe, 0xca, 0x54, 0x70, 0x40, 0x27, 0xda, 0x15, 0x63, - 0xd0, 0x51, 0x79, 0x81, 0x41, 0x87, 0x54, 0x7a, 0x66, 0xe7, 0x70, 0xb2, 0xe6, 0x52, 0x2d, 0x32, - 0x0a, 0x66, 0x91, 0x71, 0x99, 0x05, 0x87, 0x7a, 0xdb, 0xf8, 0x58, 0xeb, 0x26, 0xc6, 0x4b, 0x2e, - 0xb3, 0x86, 0x4c, 0xca, 0xa2, 0xc8, 0x95, 0x21, 0xbb, 0x3b, 0xf2, 0x15, 0xc9, 0x44, 0x3e, 0x82, - 0x41, 0xca, 0x15, 0x37, 0x48, 0x8f, 0x90, 0xbe, 0x16, 0xc8, 0x3c, 0x83, 0xe3, 0xa4, 0x14, 0x12, - 0x85, 0xdc, 0x48, 0x43, 0xf4, 0x89, 0x38, 0x6a, 0x54, 0xc2, 0xc6, 0xd0, 0xe7, 0x55, 0x65, 0x80, - 0x01, 0x01, 0x3d, 0x5e, 0x55, 0x64, 0x7d, 0x05, 0x23, 0x0a, 0xa4, 0x46, 0xb9, 0x59, 0x2b, 0xbb, - 0x09, 0x10, 0x73, 0x4f, 0x1b, 0xb1, 0xd1, 0x89, 0x7d, 0x06, 0x27, 0x55, 0x5d, 0x56, 0xa5, 0xc4, - 0x7a, 0xc1, 0xd3, 0xb4, 0x46, 0x29, 0x03, 0xdf, 0xa0, 0x4e, 0x7f, 0x69, 0x64, 0x1d, 0x98, 0xc4, - 0x5f, 0x37, 0x28, 0x12, 0x97, 0x87, 0xa1, 0x09, 0xac, 0x51, 0x69, 0xc7, 0x08, 0xbe, 0x10, 0x78, - 0xad, 0x16, 0x9f, 0xb0, 0xc7, 0xc4, 0x8e, 0xb4, 0x35, 0xff, 0x88, 0x1f, 0x43, 0x3f, 0xc9, 0x78, - 0x2e, 0x74, 0xbd, 0x8e, 0x4e, 0xbd, 0xf3, 0x41, 0xdc, 0xa3, 0xf5, 0x9b, 0x34, 0xfc, 0xd3, 0x83, - 0xae, 0x49, 0x5b, 0xab, 0x64, 0xde, 0x47, 0x25, 0x7b, 0x0c, 0x7e, 0xbb, 0x32, 0x54, 0xf0, 0x18, - 0xb2, 0x5d, 0x55, 0x26, 0x00, 0x32, 0x5f, 0x09, 0xae, 0x36, 0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0xae, 0xb2, 0xcd, 0x32, 0x4a, 0xca, 0x42, 0x7f, 0x9d, 0x50, 0xe8, - 0xfb, 0xf9, 0x7a, 0xfb, 0x9b, 0xfb, 0x62, 0x99, 0x6f, 0x48, 0xb5, 0xb4, 0xeb, 0x65, 0x97, 0xda, - 0xf2, 0xeb, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xce, 0x06, 0xf3, 0x18, 0xd8, 0x06, 0x00, 0x00, + // 848 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x95, 0xcf, 0x6f, 0xdc, 0x44, + 0x14, 0xc7, 0xe3, 0x64, 0xb3, 0x3f, 0x9e, 0x37, 0x69, 0x32, 0x44, 0x95, 0xb7, 0x15, 0x9b, 0xd4, + 0x52, 0xaa, 0x14, 0x09, 0xaf, 0x08, 0x42, 0xe2, 0x04, 0x6a, 0x4a, 0xa5, 0x54, 0x88, 0x8b, 0x23, + 0xf5, 0xc0, 0x65, 0x35, 0x6b, 0x3f, 0x6c, 0xab, 0xeb, 0x19, 0xe3, 0x99, 0x8d, 0xb2, 0x70, 0xeb, + 0x5f, 0xc0, 0x99, 0x1b, 0xff, 0x4d, 0x4f, 0xa8, 0x47, 0x4e, 0x08, 0x25, 0xff, 0x08, 0x9a, 0x37, + 0x63, 0xaf, 0x1b, 0xe8, 0xa5, 0x9d, 0xf9, 0x7e, 0x3f, 0x33, 0x7e, 0x79, 0x3f, 0x66, 0x61, 0xa2, + 0xd7, 0x15, 0xaa, 0x59, 0xba, 0x2e, 0x0b, 0xa1, 0xdd, 0x7f, 0x51, 0x55, 0x4b, 0x2d, 0x59, 0xdf, + 0xee, 0x1e, 0x1d, 0x65, 0x32, 0x93, 0x24, 0xcd, 0xcc, 0xca, 0xba, 0x8f, 0x9e, 0xd8, 0x83, 0x1a, + 0x45, 0x8a, 0x35, 0x1d, 0xe6, 0x8b, 0xa4, 0x98, 0x91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0x50, 0xa4, 0xce, 0x3e, 0x85, 0x3e, + 0xbd, 0x32, 0xca, 0xa5, 0x72, 0xaf, 0xf9, 0x2e, 0xfd, 0x95, 0xb1, 0x33, 0xd9, 0x19, 0x0c, 0x6c, + 0x78, 0x4d, 0xc6, 0xee, 0xc7, 0xd7, 0xd8, 0xe1, 0xaf, 0x30, 0x6a, 0x5b, 0x98, 0x7d, 0x0e, 0x4c, + 0xa1, 0xd6, 0x4b, 0x2c, 0x51, 0xe8, 0x76, 0x84, 0x3c, 0x6a, 0xe4, 0xc3, 0x8d, 0xd3, 0x0c, 0xd1, + 0xb7, 0x30, 0x6a, 0x1f, 0x4e, 0x97, 0xb0, 0xff, 0xe9, 0xb5, 0xd7, 0x0d, 0x72, 0xd1, 0x7b, 0xf7, + 0xf7, 0xf1, 0x56, 0xbc, 0x39, 0x13, 0x1e, 0xc3, 0xe8, 0xe5, 0x35, 0x0a, 0xfd, 0x3d, 0xae, 0x95, + 0x79, 0xb0, 0xde, 0xe0, 0xba, 0x69, 0x3a, 0x5a, 0x5f, 0x5c, 0xbe, 0xbb, 0x9d, 0x7a, 0xef, 0x6f, + 0xa7, 0xde, 0x3f, 0xb7, 0x53, 0xef, 0xb7, 0xbb, 0xe9, 0xd6, 0xfb, 0xbb, 0xe9, 0xd6, 0x5f, 0x77, + 0xd3, 0xad, 0x1f, 0xa3, 0xac, 0xd0, 0xf9, 0x6a, 0x11, 0x25, 0xb2, 0x34, 0xbf, 0x23, 0x28, 0xcc, + 0x9b, 0x79, 0xb3, 0xfe, 0xa5, 0xf9, 0x6d, 0xb1, 0xef, 0x7a, 0xb5, 0x70, 0xfb, 0x45, 0x9f, 0x5a, + 0xe5, 0xcb, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0x4d, 0x07, 0xa9, 0x82, 0x06, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -1155,18 +1102,16 @@ func (m *Sequencer) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Validator != nil { - { - size, err := m.Validator.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDymint(dAtA, i, uint64(size)) + { + size, err := m.Validator.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintDymint(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if len(m.SettlementAddress) > 0 { i -= len(m.SettlementAddress) copy(dAtA[i:], m.SettlementAddress) @@ -1177,55 +1122,6 @@ func (m *Sequencer) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *SequencerSet) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SequencerSet) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SequencerSet) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Proposer != nil { - { - size, err := m.Proposer.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDymint(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if len(m.Sequencers) > 0 { - for iNdEx := len(m.Sequencers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Sequencers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDymint(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - func (m *EventKeys) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1464,29 +1360,8 @@ func (m *Sequencer) Size() (n int) { if l > 0 { n += 1 + l + sovDymint(uint64(l)) } - if m.Validator != nil { - l = m.Validator.Size() - n += 1 + l + sovDymint(uint64(l)) - } - return n -} - -func (m *SequencerSet) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Sequencers) > 0 { - for _, e := range m.Sequencers { - l = e.Size() - n += 1 + l + sovDymint(uint64(l)) - } - } - if m.Proposer != nil { - l = m.Proposer.Size() - n += 1 + l + sovDymint(uint64(l)) - } + l = m.Validator.Size() + n += 1 + l + sovDymint(uint64(l)) return n } @@ -2852,9 +2727,6 @@ func (m *Sequencer) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Validator == nil { - m.Validator = &types.Validator{} - } if err := m.Validator.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2880,126 +2752,6 @@ func (m *Sequencer) Unmarshal(dAtA []byte) error { } return nil } -func (m *SequencerSet) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDymint - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SequencerSet: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SequencerSet: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sequencers", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDymint - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDymint - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDymint - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Sequencers = append(m.Sequencers, &Sequencer{}) - if err := m.Sequencers[len(m.Sequencers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Proposer", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDymint - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDymint - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDymint - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Proposer == nil { - m.Proposer = &Sequencer{} - } - if err := m.Proposer.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipDymint(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthDymint - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *EventKeys) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/types/pb/dymint/state.pb.go b/types/pb/dymint/state.pb.go index 8c3bf173d..e5ba789c9 100644 --- a/types/pb/dymint/state.pb.go +++ b/types/pb/dymint/state.pb.go @@ -44,9 +44,10 @@ type State struct { AppHash []byte `protobuf:"bytes,15,opt,name=app_hash,json=appHash,proto3" json:"app_hash,omitempty"` LastStoreHeight uint64 `protobuf:"varint,16,opt,name=last_store_height,json=lastStoreHeight,proto3" json:"last_store_height,omitempty"` BaseHeight uint64 `protobuf:"varint,17,opt,name=base_height,json=baseHeight,proto3" json:"base_height,omitempty"` - SequencerSet SequencerSet `protobuf:"bytes,18,opt,name=sequencerSet,proto3" json:"sequencerSet"` - RollappParams RollappParams `protobuf:"bytes,19,opt,name=rollapp_params,json=rollappParams,proto3" json:"rollapp_params"` - LastHeaderHash []byte `protobuf:"bytes,20,opt,name=last_header_hash,json=lastHeaderHash,proto3" json:"last_header_hash,omitempty"` + RollappParams RollappParams `protobuf:"bytes,18,opt,name=rollapp_params,json=rollappParams,proto3" json:"rollapp_params"` + LastHeaderHash []byte `protobuf:"bytes,19,opt,name=last_header_hash,json=lastHeaderHash,proto3" json:"last_header_hash,omitempty"` + // Proposer is a sequencer that acts as a proposer. Can be nil if no proposer is set. + Proposer *Sequencer `protobuf:"bytes,20,opt,name=proposer,proto3" json:"proposer,omitempty"` } func (m *State) Reset() { *m = State{} } @@ -174,13 +175,6 @@ func (m *State) GetBaseHeight() uint64 { return 0 } -func (m *State) GetSequencerSet() SequencerSet { - if m != nil { - return m.SequencerSet - } - return SequencerSet{} -} - func (m *State) GetRollappParams() RollappParams { if m != nil { return m.RollappParams @@ -195,6 +189,13 @@ func (m *State) GetLastHeaderHash() []byte { return nil } +func (m *State) GetProposer() *Sequencer { + if m != nil { + return m.Proposer + } + return nil +} + //rollapp params defined in genesis and updated via gov proposal type RollappParams struct { //data availability type (e.g. celestia) used in the rollapp @@ -258,50 +259,50 @@ func init() { func init() { proto.RegisterFile("types/dymint/state.proto", fileDescriptor_4b679420add07272) } var fileDescriptor_4b679420add07272 = []byte{ - // 686 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x94, 0x4d, 0x4f, 0xdb, 0x3e, - 0x1c, 0xc7, 0x9b, 0x12, 0x68, 0xea, 0xd2, 0x36, 0x18, 0xfe, 0x52, 0xe0, 0x2f, 0xa5, 0x85, 0x69, - 0x53, 0xb5, 0x43, 0x2a, 0x8d, 0xd3, 0x2e, 0x9b, 0x14, 0x38, 0xd0, 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- 0x8d, 0xae, 0xd9, 0x3b, 0x7b, 0x0f, 0xba, 0x6b, 0xdf, 0x81, 0x3d, 0xd0, 0x8c, 0x90, 0xb8, 0x9c, - 0x6d, 0xaf, 0x19, 0x21, 0x68, 0xbd, 0xdc, 0x58, 0x75, 0xf7, 0xd4, 0xd2, 0xbd, 0x7a, 0x58, 0xda, - 0xda, 0xe3, 0xd2, 0xd6, 0xfe, 0x2e, 0x6d, 0xed, 0xfe, 0xd9, 0x6e, 0x3c, 0x3e, 0xdb, 0x8d, 0xdf, - 0xcf, 0x76, 0xe3, 0x8b, 0x13, 0xa7, 0x2c, 0x59, 0x04, 0x4e, 0x48, 0xe6, 0xfc, 0x21, 0xc0, 0x39, - 0xe7, 0x7f, 0xdc, 0xfd, 0xac, 0x1e, 0x07, 0xf5, 0xc2, 0x04, 0x6a, 0x1d, 0xec, 0x89, 0xe9, 0x3f, - 0xff, 0x17, 0x00, 0x00, 0xff, 0xff, 0x34, 0x50, 0x06, 0x1e, 0x54, 0x05, 0x00, 0x00, + // 688 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x94, 0xcf, 0x4e, 0xdb, 0x4a, + 0x14, 0xc6, 0xe3, 0x10, 0x88, 0x33, 0x21, 0x89, 0x19, 0xb8, 0x92, 0xe1, 0x4a, 0x4e, 0xe0, 0xea, + 0x5e, 0x45, 0x57, 0xaa, 0x23, 0x95, 0x55, 0x57, 0x95, 0x0c, 0x0b, 0x12, 0xb1, 0xa8, 0x26, 0x15, + 0x8b, 0x6e, 0xac, 0xb1, 0x3d, 0xb5, 0xad, 0x3a, 0x1e, 0xd7, 0x33, 0x41, 0xa5, 0x2f, 0xd0, 0x2d, + 0x8f, 0xc5, 0x92, 0x65, 0x57, 0xb4, 0x0a, 0x2f, 0x52, 0xcd, 0x1f, 0x9b, 0x44, 0x11, 0xab, 0x64, + 0xbe, 0xf3, 0x9b, 0x6f,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8, 0xfd, + 0x91, 0x31, 0xde, 0x57, 0xad, 0x42, 0x4a, 0xbf, 0xc2, 0x2c, 0x11, 0x83, 0x81, 0x8b, 0x42, 0x21, + 0x03, 0x89, 0xb4, 0x71, 0x51, 0xc8, 0xd0, 0x7b, 0x6d, 0xc3, 0x38, 0x2d, 0x49, 0xd5, 0x71, 0x6b, + 0x64, 0x8c, 0x5b, 0xde, 0xe1, 0xea, 0x69, 0x38, 0x10, 0xad, 0x9a, 0x8b, 0x98, 0xaa, 0x4d, 0x79, + 0xaf, 0x09, 0x70, 0x08, 0xba, 0x01, 0x66, 0xf5, 0xd6, 0x03, 0xb1, 0x15, 0x01, 0x21, 0x69, 0xc0, + 0x03, 0xfd, 0x92, 0x66, 0x99, 0x48, 0x40, 0x97, 0x0e, 0x65, 0xe9, 0x7f, 0xb9, 0x7a, 0xf6, 0x91, + 0x8a, 0x6e, 0x94, 0xdb, 0x2b, 0xd7, 0x45, 0x38, 0x06, 0x96, 0xee, 0x02, 0x8e, 0x48, 0xa9, 0x0a, + 0x39, 0x94, 0x85, 0xf4, 0xd5, 0xbd, 0x0b, 0x59, 0xd6, 0xf3, 0x06, 0x98, 0x45, 0x49, 0x0b, 0xca, + 0x48, 0x69, 0x1f, 0xc9, 0x73, 0x0e, 0xaa, 0x73, 0xe6, 0xe4, 0xeb, 0x92, 0xe4, 0x21, 0x29, 0x51, + 0x8d, 0xcc, 0x5a, 0x66, 0xdb, 0x32, 0x67, 0x2d, 0xd3, 0xb4, 0x3a, 0xb3, 0x96, 0x09, 0xac, 0xee, + 0xac, 0x65, 0xf6, 0xac, 0xfe, 0xd9, 0x3b, 0xd0, 0xdb, 0x48, 0x0b, 0xf6, 0x41, 0x33, 0xc2, 0xf2, + 0x2d, 0x76, 0x50, 0x33, 0xc2, 0xd0, 0x7e, 0x79, 0xa0, 0xfa, 0xa9, 0xe9, 0xa5, 0x77, 0xf5, 0xb0, + 0x72, 0x8c, 0xc7, 0x95, 0x63, 0xfc, 0x5e, 0x39, 0xc6, 0xfd, 0xb3, 0xd3, 0x78, 0x7c, 0x76, 0x1a, + 0x3f, 0x9f, 0x9d, 0xc6, 0x27, 0x37, 0x4e, 0x79, 0xb2, 0x0c, 0xdc, 0x90, 0x2e, 0xc4, 0xbb, 0x27, + 0xb9, 0xe0, 0xbf, 0xdd, 0x7d, 0xaf, 0xbe, 0x05, 0xfa, 0x83, 0x12, 0xe8, 0x75, 0xb0, 0x27, 0x87, + 0xfd, 0xfc, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5d, 0xa1, 0x60, 0x45, 0x43, 0x05, 0x00, 0x00, } func (m *State) Marshal() (dAtA []byte, err error) { @@ -324,6 +325,20 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Proposer != nil { + { + size, err := m.Proposer.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintState(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa2 + } if len(m.LastHeaderHash) > 0 { i -= len(m.LastHeaderHash) copy(dAtA[i:], m.LastHeaderHash) @@ -331,7 +346,7 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1 i-- - dAtA[i] = 0xa2 + dAtA[i] = 0x9a } { size, err := m.RollappParams.MarshalToSizedBuffer(dAtA[:i]) @@ -344,18 +359,6 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1 i-- - dAtA[i] = 0x9a - { - size, err := m.SequencerSet.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintState(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1 - i-- dAtA[i] = 0x92 if m.BaseHeight != 0 { i = encodeVarintState(dAtA, i, uint64(m.BaseHeight)) @@ -557,14 +560,16 @@ func (m *State) Size() (n int) { if m.BaseHeight != 0 { n += 2 + sovState(uint64(m.BaseHeight)) } - l = m.SequencerSet.Size() - n += 2 + l + sovState(uint64(l)) l = m.RollappParams.Size() n += 2 + l + sovState(uint64(l)) l = len(m.LastHeaderHash) if l > 0 { n += 2 + l + sovState(uint64(l)) } + if m.Proposer != nil { + l = m.Proposer.Size() + n += 2 + l + sovState(uint64(l)) + } return n } @@ -988,7 +993,7 @@ func (m *State) Unmarshal(dAtA []byte) error { } case 18: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SequencerSet", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RollappParams", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1015,15 +1020,15 @@ func (m *State) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.SequencerSet.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.RollappParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 19: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RollappParams", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field LastHeaderHash", wireType) } - var msglen int + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowState @@ -1033,30 +1038,31 @@ func (m *State) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + if byteLen < 0 { return ErrInvalidLengthState } - postIndex := iNdEx + msglen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthState } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.RollappParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + m.LastHeaderHash = append(m.LastHeaderHash[:0], dAtA[iNdEx:postIndex]...) + if m.LastHeaderHash == nil { + m.LastHeaderHash = []byte{} } iNdEx = postIndex case 20: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LastHeaderHash", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Proposer", wireType) } - var byteLen int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowState @@ -1066,24 +1072,26 @@ func (m *State) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + if msglen < 0 { return ErrInvalidLengthState } - postIndex := iNdEx + byteLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthState } if postIndex > l { return io.ErrUnexpectedEOF } - m.LastHeaderHash = append(m.LastHeaderHash[:0], dAtA[iNdEx:postIndex]...) - if m.LastHeaderHash == nil { - m.LastHeaderHash = []byte{} + if m.Proposer == nil { + m.Proposer = &Sequencer{} + } + if err := m.Proposer.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: diff --git a/types/sequencer_set.go b/types/sequencer_set.go index d6bb06e26..e8f67dddb 100644 --- a/types/sequencer_set.go +++ b/types/sequencer_set.go @@ -3,17 +3,19 @@ package types import ( "bytes" "fmt" + "slices" + "sync" tmcrypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/types" ) -// sequencer is a struct that holds the sequencer's settlement address and tendermint validator -// it's populated from the SL client -// uses tendermint's validator types for compatibility +// Sequencer is a struct that holds the sequencer's settlement address and tendermint validator. +// It's populated from the SL client. Uses tendermint's validator types for compatibility. type Sequencer struct { // SettlementAddress is the address of the sequencer in the settlement layer (bech32 string) SettlementAddress string `json:"settlement_address"` + // tendermint validator type for compatibility. holds the public key and cons address val types.Validator } @@ -72,113 +74,90 @@ func (s Sequencer) MustHash() []byte { return h } -// SequencerSet is a set of rollapp sequencers and a proposer. +// SequencerSet is a set of rollapp sequencers. It holds the entire set of sequencers +// that were ever associated with the rollapp (including bonded/unbonded/unbonding). +// It is populated from the Hub on start and is periodically updated from the Hub polling. +// This type is thread-safe. type SequencerSet struct { - // Sequencers is the set of sequencers registered in the settlement layer - // it holds the entire set of sequencers, including unbonded sequencers - Sequencers []Sequencer `json:"sequencers"` - // Proposer is the sequencer that is the proposer for the current sequencer set - // can be nil if no proposer is set - // proposer is also included in the sequencers set - Proposer *Sequencer `json:"proposer"` + mu sync.RWMutex + sequencers []Sequencer } -func (s *SequencerSet) GetProposerPubKey() tmcrypto.PubKey { - if s.Proposer == nil { - return nil +func NewSequencerSet(s ...Sequencer) *SequencerSet { + return &SequencerSet{ + mu: sync.RWMutex{}, + sequencers: s, } - return s.Proposer.PubKey() } -// ProposerHash returns the hash of the proposer -func (s *SequencerSet) ProposerHash() []byte { - if s.Proposer == nil { - return make([]byte, 0, 32) - } - return s.Proposer.MustHash() +// SetSequencers sets the sequencers of the sequencer set. +func (s *SequencerSet) SetSequencers(sequencers []Sequencer) { + s.mu.Lock() + defer s.mu.Unlock() + s.sequencers = sequencers } -// SetProposerByHash sets the proposer by hash. -// It returns an error if the hash is not found in the sequencer set -// Used when updating proposer from the L2 blocks (nextSequencerHash header field) -func (s *SequencerSet) SetProposerByHash(hash []byte) error { - for _, seq := range s.Sequencers { - if bytes.Equal(seq.MustHash(), hash) { - s.SetProposer(&seq) - return nil - } - } - // can't find the proposer in the sequencer set - // can happen in cases where the node is not synced with the SL and the sequencer array in the set is not updated - return ErrMissingProposerPubKey +// AppendSequencer appends a new sequencer the sequencer set. +func (s *SequencerSet) AppendSequencer(sequencer Sequencer) { + s.mu.Lock() + defer s.mu.Unlock() + s.sequencers = append(s.sequencers, sequencer) } -// SetProposer sets the proposer and adds it to the sequencer set if not already present. -func (s *SequencerSet) SetProposer(proposer *Sequencer) { - if proposer == nil { - s.Proposer = nil - return - } - s.Proposer = proposer - - // Add proposer to bonded set if not already present - // can happen in cases where the node is not synced with the SL and the sequencer array in the set is not updated - if s.GetByConsAddress(proposer.val.Address) == nil { - s.Sequencers = append(s.Sequencers, *proposer) - } +func (s *SequencerSet) GetAll() []Sequencer { + s.mu.RLock() + defer s.mu.RUnlock() + return slices.Clone(s.sequencers) } -// SetSequencers sets the sequencers of the sequencer set. -func (s *SequencerSet) SetSequencers(sequencers []Sequencer) { - s.Sequencers = sequencers +// GetByHash gets the sequencer by hash. It returns an error if the hash is not found in the sequencer set. +func (s *SequencerSet) GetByHash(hash []byte) (Sequencer, bool) { + s.mu.RLock() + defer s.mu.RUnlock() + for _, seq := range s.sequencers { + if bytes.Equal(seq.MustHash(), hash) { + return seq, true + } + } + return Sequencer{}, false } // GetByAddress returns the sequencer with the given settlement address. // used when handling events from the settlement, where the settlement address is used -func (s *SequencerSet) GetByAddress(settlement_address string) *Sequencer { - for _, seq := range s.Sequencers { - if seq.SettlementAddress == settlement_address { - return &seq +func (s *SequencerSet) GetByAddress(settlementAddress string) (Sequencer, bool) { + s.mu.RLock() + defer s.mu.RUnlock() + for _, seq := range s.sequencers { + if seq.SettlementAddress == settlementAddress { + return seq, true } } - return nil + return Sequencer{}, false } // GetByConsAddress returns the sequencer with the given consensus address. -func (s *SequencerSet) GetByConsAddress(cons_addr []byte) *Sequencer { - for _, seq := range s.Sequencers { - if bytes.Equal(seq.val.Address, cons_addr) { - return &seq +func (s *SequencerSet) GetByConsAddress(consAddr []byte) (Sequencer, bool) { + s.mu.RLock() + defer s.mu.RUnlock() + for _, seq := range s.sequencers { + if bytes.Equal(seq.val.Address, consAddr) { + return seq, true } } - return nil + return Sequencer{}, false } func (s *SequencerSet) String() string { - return fmt.Sprintf("SequencerSet: %v", s.Sequencers) + return fmt.Sprintf("SequencerSet: %v", s.sequencers) } /* -------------------------- backward compatibility ------------------------- */ // old dymint version used tendermint.ValidatorSet for sequencers // these methods are used for backward compatibility + func NewSequencerFromValidator(val types.Validator) *Sequencer { return &Sequencer{ SettlementAddress: "", val: val, } } - -// LoadFromValSet sets the sequencers from a tendermint validator set. -// used for backward compatibility. should be used only for queries (used by rpc/client) -func (s *SequencerSet) LoadFromValSet(valSet *types.ValidatorSet) { - if valSet == nil { - return - } - - sequencers := make([]Sequencer, len(valSet.Validators)) - for i, val := range valSet.Validators { - sequencers[i] = *NewSequencerFromValidator(*val) - } - s.SetSequencers(sequencers) - s.SetProposer(NewSequencerFromValidator(*valSet.Proposer)) -} diff --git a/types/serialization.go b/types/serialization.go index 6dcdb08ac..23480b63c 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -250,9 +250,14 @@ func (c *Commit) FromProto(other *pb.Commit) error { // ToProto converts State into protobuf representation and returns it. func (s *State) ToProto() (*pb.State, error) { - seqsProto, err := s.Sequencers.ToProto() - if err != nil { - return nil, err + var proposerProto *pb.Sequencer + proposer := s.GetProposer() + if proposer != nil { + var err error + proposerProto, err = proposer.ToProto() + if err != nil { + return nil, err + } } return &pb.State{ @@ -260,93 +265,70 @@ func (s *State) ToProto() (*pb.State, error) { ChainId: s.ChainID, InitialHeight: int64(s.InitialHeight), LastBlockHeight: int64(s.Height()), - SequencerSet: *seqsProto, BaseHeight: s.BaseHeight, ConsensusParams: s.ConsensusParams, LastResultsHash: s.LastResultsHash[:], LastHeaderHash: s.LastHeaderHash[:], AppHash: s.AppHash[:], RollappParams: s.RollappParams, + Proposer: proposerProto, }, nil } // FromProto fills State with data from its protobuf representation. func (s *State) FromProto(other *pb.State) error { - var err error s.Version = *other.Version s.ChainID = other.ChainId s.InitialHeight = uint64(other.InitialHeight) s.SetHeight(uint64(other.LastBlockHeight)) s.BaseHeight = other.BaseHeight - err = s.Sequencers.FromProto(other.SequencerSet) - if err != nil { - return err + if other.Proposer != nil { + proposer, err := SequencerFromProto(other.Proposer) + if err != nil { + return err + } + s.SetProposer(proposer) + } else { + // proposer may be nil in the state + s.SetProposer(nil) } s.ConsensusParams = other.ConsensusParams copy(s.LastResultsHash[:], other.LastResultsHash) - copy(s.LastHeaderHash[:], other.LastHeaderHash) copy(s.AppHash[:], other.AppHash) s.RollappParams = other.RollappParams return nil } -// ToProto converts SequencerSet into protobuf representation and returns it. -func (s *SequencerSet) ToProto() (*pb.SequencerSet, error) { - protoSet := new(pb.SequencerSet) - - seqsProto := make([]*pb.Sequencer, len(s.Sequencers)) - for i := 0; i < len(s.Sequencers); i++ { - valp, err := s.Sequencers[i].val.ToProto() - if err != nil { - return nil, fmt.Errorf("ToProto: SequencerSet: %w", err) - } - seq := new(pb.Sequencer) - seq.SettlementAddress = s.Sequencers[i].SettlementAddress - seq.Validator = valp - seqsProto[i] = seq +// ToProto converts Sequencer into protobuf representation and returns it. +func (s *Sequencer) ToProto() (*pb.Sequencer, error) { + if s == nil { + return nil, fmt.Errorf("nil sequencer") } - protoSet.Sequencers = seqsProto - - if s.Proposer != nil { - valp, err := s.Proposer.val.ToProto() - if err != nil { - return nil, fmt.Errorf("ToProto: SequencerSet: %w", err) - } - seq := new(pb.Sequencer) - seq.Validator = valp - seq.SettlementAddress = s.Proposer.SettlementAddress - protoSet.Proposer = seq + protoVal, err := s.val.ToProto() + if err != nil { + return nil, fmt.Errorf("tendermint validator to proto: %w", err) } - - return protoSet, nil + return &pb.Sequencer{ + SettlementAddress: s.SettlementAddress, + Validator: *protoVal, + }, nil } -// FromProto fills SequencerSet with data from its protobuf representation. -func (s *SequencerSet) FromProto(protoSet pb.SequencerSet) error { - seqs := make([]Sequencer, len(protoSet.Sequencers)) - for i, seqProto := range protoSet.Sequencers { - val, err := types.ValidatorFromProto(seqProto.Validator) - if err != nil { - return fmt.Errorf("fromProto: SequencerSet: %w", err) - } - seqs[i].val = *val - seqs[i].SettlementAddress = seqProto.SettlementAddress +// SequencerFromProto fills Sequencer with data from its protobuf representation. +func SequencerFromProto(seq *pb.Sequencer) (*Sequencer, error) { + if seq == nil { + return nil, fmt.Errorf("nil sequencer") } - s.Sequencers = seqs - - if protoSet.Proposer != nil { - valProposer, err := types.ValidatorFromProto(protoSet.Proposer.Validator) - if err != nil { - return fmt.Errorf("fromProto: SequencerSet proposer: %w", err) - } - proposer := new(Sequencer) - proposer.val = *valProposer - proposer.SettlementAddress = protoSet.Proposer.SettlementAddress - s.Proposer = proposer + val, err := types.ValidatorFromProto(&seq.Validator) + if err != nil { + return nil, fmt.Errorf("tendermint validator from proto: %w", err) } - return nil + return &Sequencer{ + SettlementAddress: seq.SettlementAddress, + val: *val, + }, nil } func txsToByteSlices(txs Txs) [][]byte { diff --git a/types/serialization_test.go b/types/serialization_test.go index ff876cee7..26ce537cf 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -11,7 +11,6 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" - "github.com/dymensionxyz/dymint/testutil" "github.com/dymensionxyz/dymint/types" pb "github.com/dymensionxyz/dymint/types/pb/dymint" "github.com/dymensionxyz/dymint/version" @@ -87,8 +86,6 @@ func TestBlockSerializationRoundTrip(t *testing.T) { func TestStateRoundTrip(t *testing.T) { t.Parallel() - valSet := testutil.GenerateRandomValidatorSet() - cases := []struct { name string state types.State @@ -150,8 +147,6 @@ func TestStateRoundTrip(t *testing.T) { require := require.New(t) assert := assert.New(t) - c.state.Sequencers.LoadFromValSet(valSet) - if c.state.InitialHeight != 0 { c.state.SetHeight(986321) } diff --git a/types/state.go b/types/state.go index 0bfd6d093..371388aa7 100644 --- a/types/state.go +++ b/types/state.go @@ -7,9 +7,12 @@ import ( // TODO(tzdybal): copy to local project? - "github.com/dymensionxyz/dymint/types/pb/dymint" + tmcrypto "github.com/tendermint/tendermint/crypto" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/tendermint/tendermint/types" + + "github.com/dymensionxyz/dymint/types/pb/dymint" ) // State contains information about current state of the blockchain. @@ -26,8 +29,8 @@ type State struct { // BaseHeight is the height of the first block we have in store after pruning. BaseHeight uint64 - // Sequencers is the set of sequencers that are currently active on the rollapp. - Sequencers SequencerSet + // Proposer is a sequencer that acts as a proposer. Can be nil if no proposer is set. + Proposer atomic.Pointer[Sequencer] // Consensus parameters used for validating blocks. // Changes returned by EndBlock and updated after Commit. @@ -46,6 +49,46 @@ type State struct { LastHeaderHash [32]byte } +func (s *State) GetProposer() *Sequencer { + return s.Proposer.Load() +} + +func (s *State) GetProposerPubKey() tmcrypto.PubKey { + proposer := s.Proposer.Load() + if proposer == nil { + return nil + } + return proposer.PubKey() +} + +// GetProposerHash returns the hash of the proposer +func (s *State) GetProposerHash() []byte { + proposer := s.Proposer.Load() + if proposer == nil { + return nil + } + return proposer.MustHash() +} + +// SetProposer sets the proposer. It may set the proposer to nil. +func (s *State) SetProposer(proposer *Sequencer) { + s.Proposer.Store(proposer) +} + +// LoadFromValSet sets the sequencers from a tendermint validator set. +// Used for backward compatibility. Should be used only for queries (used by rpc/client). +func (s *State) LoadFromValSet(valSet *types.ValidatorSet) { + if valSet == nil { + return + } + + sequencers := make([]Sequencer, len(valSet.Validators)) + for i, val := range valSet.Validators { + sequencers[i] = *NewSequencerFromValidator(*val) + } + s.SetProposer(NewSequencerFromValidator(*valSet.Proposer)) +} + func (s *State) IsGenesis() bool { return s.Height() == 0 } diff --git a/types/validation.go b/types/validation.go index 8661fc914..5734a636e 100644 --- a/types/validation.go +++ b/types/validation.go @@ -77,8 +77,9 @@ func (b *Block) ValidateWithState(state *State) error { return NewErrFraudHeightMismatch(state.NextHeight(), b.Header.Height, b) } - if !bytes.Equal(b.Header.NextSequencersHash[:], state.Sequencers.ProposerHash()) { - return NewErrInvalidNextSequencersHashFraud([32]byte(state.Sequencers.ProposerHash()), b.Header.NextSequencersHash) + proposerHash := state.GetProposerHash() + if !bytes.Equal(b.Header.NextSequencersHash[:], proposerHash) { + return NewErrInvalidNextSequencersHashFraud([32]byte(proposerHash), b.Header.NextSequencersHash) } if !bytes.Equal(b.Header.AppHash[:], state.AppHash[:]) { diff --git a/types/validation_test.go b/types/validation_test.go index d22a3b04b..c95ae9d68 100644 --- a/types/validation_test.go +++ b/types/validation_test.go @@ -8,13 +8,12 @@ import ( "github.com/cometbft/cometbft/libs/math" "github.com/dymensionxyz/gerr-cosmos/gerrc" - "github.com/tendermint/tendermint/crypto/ed25519" - tmtypes "github.com/tendermint/tendermint/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/ed25519" tmstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/tendermint/tendermint/proto/tendermint/version" + tmtypes "github.com/tendermint/tendermint/types" ) func TestBlock_ValidateWithState(t *testing.T) { @@ -33,11 +32,9 @@ func TestBlock_ValidateWithState(t *testing.T) { LastResultsHash: [32]byte{4, 5, 6}, LastHeaderHash: [32]byte{7, 8, 9}, ChainID: "chainID", - Sequencers: SequencerSet{ - Proposer: proposer, - }, } validState.LastBlockHeight.Store(9) + validState.SetProposer(proposer) validBlock := &Block{ Header: Header{