From 6b64e5f1842a748dae750d7cb2642ea3677f5738 Mon Sep 17 00:00:00 2001 From: nashqueue Date: Mon, 13 Mar 2023 10:20:19 +0100 Subject: [PATCH 1/9] Header -> Signed Header --- block/manager.go | 30 +++---- conv/abci/block.go | 8 +- da/mock/mock.go | 6 +- da/test/da_test.go | 15 ++-- node/full_client.go | 20 ++--- node/full_client_test.go | 51 +++++------ proto/rollkit/rollkit.proto | 3 +- state/executor.go | 72 +++++++-------- state/executor_test.go | 8 +- store/store.go | 4 +- store/store_test.go | 33 +++---- types/block.go | 5 +- types/hashing.go | 2 +- types/pb/rollkit/rollkit.pb.go | 160 +++++++++++---------------------- types/serialization.go | 13 +-- types/serialization_test.go | 45 +++++----- types/validation.go | 4 +- 17 files changed, 208 insertions(+), 271 deletions(-) diff --git a/block/manager.go b/block/manager.go index 990b8634b3..958e686700 100644 --- a/block/manager.go +++ b/block/manager.go @@ -287,11 +287,11 @@ func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) { block := blockEvent.block daHeight := blockEvent.daHeight m.logger.Debug("block body retrieved from DALC", - "height", block.Header.Height(), + "height", block.SignedHeader.Header.Height(), "daHeight", daHeight, "hash", block.Hash(), ) - m.syncCache[block.Header.BaseHeader.Height] = block + m.syncCache[block.SignedHeader.Header.BaseHeader.Height] = block m.retrieveCond.Signal() err := m.trySyncNextBlock(ctx, daHeight) @@ -346,7 +346,7 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error { b2, ok2 := m.syncCache[currentHeight+2] if ok2 { m.logger.Debug("using last commit from next block") - commit = &b2.LastCommit + commit = &b2.SignedHeader.Commit } else { lastCommit := m.getLastCommit() if lastCommit != nil && lastCommit.Height == currentHeight+1 { @@ -356,7 +356,7 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error { } if b1 != nil && commit != nil { - m.logger.Info("Syncing block", "height", b1.Header.Height()) + m.logger.Info("Syncing block", "height", b1.SignedHeader.Header.Height()) newState, responses, err := m.executor.ApplyBlock(ctx, m.lastState, b1) if err != nil { return fmt.Errorf("failed to ApplyBlock: %w", err) @@ -369,9 +369,9 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error { if err != nil { return fmt.Errorf("failed to Commit: %w", err) } - m.store.SetHeight(uint64(b1.Header.Height())) + m.store.SetHeight(uint64(b1.SignedHeader.Header.Height())) - err = m.store.SaveBlockResponses(uint64(b1.Header.Height()), responses) + err = m.store.SaveBlockResponses(uint64(b1.SignedHeader.Header.Height()), responses) if err != nil { return fmt.Errorf("failed to save block responses: %w", err) } @@ -514,7 +514,7 @@ func (m *Manager) publishBlock(ctx context.Context) error { if err != nil { return fmt.Errorf("error while loading last block: %w", err) } - lastHeaderHash = lastBlock.Header.Hash() + lastHeaderHash = lastBlock.SignedHeader.Header.Hash() } var block *types.Block @@ -531,7 +531,7 @@ func (m *Manager) publishBlock(ctx context.Context) error { block = m.executor.CreateBlock(newHeight, lastCommit, lastHeaderHash, m.lastState) m.logger.Debug("block info", "num_tx", len(block.Data.Txs)) - commit, err = m.getCommit(block.Header) + commit, err = m.getCommit(block.SignedHeader.Header) if err != nil { return err } @@ -550,7 +550,7 @@ func (m *Manager) publishBlock(ctx context.Context) error { } if commit == nil { - commit, err = m.getCommit(block.Header) + commit, err = m.getCommit(block.SignedHeader.Header) if err != nil { return err } @@ -575,7 +575,7 @@ func (m *Manager) publishBlock(ctx context.Context) error { } // SaveBlockResponses commits the DB tx - err = m.store.SaveBlockResponses(uint64(block.Header.Height()), responses) + err = m.store.SaveBlockResponses(uint64(block.SignedHeader.Header.Height()), responses) if err != nil { return err } @@ -591,13 +591,13 @@ func (m *Manager) publishBlock(ctx context.Context) error { } // SaveValidators commits the DB tx - err = m.store.SaveValidators(uint64(block.Header.Height()), m.lastState.Validators) + err = m.store.SaveValidators(uint64(block.SignedHeader.Header.Height()), m.lastState.Validators) if err != nil { return err } // Only update the stored height after successfully submitting to DA layer and committing to the DB - m.store.SetHeight(uint64(block.Header.Height())) + m.store.SetHeight(uint64(block.SignedHeader.Header.Height())) m.publishSignedHeader(block, commit) @@ -605,14 +605,14 @@ func (m *Manager) publishBlock(ctx context.Context) error { } func (m *Manager) submitBlockToDA(ctx context.Context, block *types.Block) error { - m.logger.Info("submitting block to DA layer", "height", block.Header.Height()) + m.logger.Info("submitting block to DA layer", "height", block.SignedHeader.Header.Height()) submitted := false backoff := initialBackoff for attempt := 1; ctx.Err() == nil && !submitted && attempt <= maxSubmitAttempts; attempt++ { res := m.dalc.SubmitBlock(ctx, block) if res.Code == da.StatusSuccess { - m.logger.Info("successfully submitted Rollkit block to DA layer", "rollkitHeight", block.Header.Height(), "daHeight", res.DAHeight) + m.logger.Info("successfully submitted Rollkit block to DA layer", "rollkitHeight", block.SignedHeader.Header.Height(), "daHeight", res.DAHeight) submitted = true } else { m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt) @@ -638,7 +638,7 @@ func (m *Manager) exponentialBackoff(backoff time.Duration) time.Duration { // TODO(tzdybal): consider inlining func (m *Manager) publishSignedHeader(block *types.Block, commit *types.Commit) { - m.HeaderOutCh <- &types.SignedHeader{Header: block.Header, Commit: *commit} + m.HeaderOutCh <- &types.SignedHeader{Header: block.SignedHeader.Header, Commit: *commit} } func updateState(s *types.State, res *abci.ResponseInitChain) { diff --git a/conv/abci/block.go b/conv/abci/block.go index a20ebd52cf..9d672d535d 100644 --- a/conv/abci/block.go +++ b/conv/abci/block.go @@ -72,14 +72,14 @@ func ToABCIHeader(header *types.Header) (tmtypes.Header, error) { // ToABCIBlock converts Rolkit block into block format defined by ABCI. // Returned block should pass `ValidateBasic`. func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) { - abciHeader, err := ToABCIHeader(&block.Header) + abciHeader, err := ToABCIHeader(&block.SignedHeader.Header) if err != nil { return nil, err } - abciCommit := ToABCICommit(&block.LastCommit) + abciCommit := ToABCICommit(&block.SignedHeader.Commit) // This assumes that we have only one signature if len(abciCommit.Signatures) == 1 { - abciCommit.Signatures[0].ValidatorAddress = block.Header.ProposerAddress + abciCommit.Signatures[0].ValidatorAddress = block.SignedHeader.Header.ProposerAddress } abciBlock := tmtypes.Block{ Header: abciHeader, @@ -92,7 +92,7 @@ func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) { for i := range block.Data.Txs { abciBlock.Data.Txs[i] = tmtypes.Tx(block.Data.Txs[i]) } - abciBlock.Header.DataHash = tmbytes.HexBytes(block.Header.DataHash) + abciBlock.Header.DataHash = tmbytes.HexBytes(block.SignedHeader.Header.DataHash) return &abciBlock, nil } diff --git a/da/mock/mock.go b/da/mock/mock.go index c9f22a886a..7bb77c81e5 100644 --- a/da/mock/mock.go +++ b/da/mock/mock.go @@ -73,15 +73,15 @@ func (m *DataAvailabilityLayerClient) Stop() error { // triggers a state transition in the DA layer. func (m *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *types.Block) da.ResultSubmitBlock { daHeight := atomic.LoadUint64(&m.daHeight) - m.logger.Debug("Submitting block to DA layer!", "height", block.Header.Height(), "dataLayerHeight", daHeight) + m.logger.Debug("Submitting block to DA layer!", "height", block.SignedHeader.Header.Height(), "dataLayerHeight", daHeight) - hash := block.Header.Hash() + hash := block.SignedHeader.Header.Hash() blob, err := block.MarshalBinary() if err != nil { return da.ResultSubmitBlock{BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()}} } - err = m.dalcKV.Put(ctx, getKey(daHeight, uint64(block.Header.Height())), hash[:]) + err = m.dalcKV.Put(ctx, getKey(daHeight, uint64(block.SignedHeader.Header.Height())), hash[:]) if err != nil { return da.ResultSubmitBlock{BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()}} } diff --git a/da/test/da_test.go b/da/test/da_test.go index cc5e6b55e7..0f168332f0 100644 --- a/da/test/da_test.go +++ b/da/test/da_test.go @@ -240,12 +240,13 @@ func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) { // copy-pasted from store/store_test.go func getRandomBlock(height uint64, nTxs int) *types.Block { block := &types.Block{ - Header: types.Header{ - BaseHeader: types.BaseHeader{ - Height: height, - }, - AggregatorsHash: make([]byte, 32), - }, + SignedHeader: types.SignedHeader{ + Header: types.Header{ + BaseHeader: types.BaseHeader{ + Height: height, + }, + AggregatorsHash: make([]byte, 32), + }}, Data: types.Data{ Txs: make(types.Txs, nTxs), IntermediateStateRoots: types.IntermediateStateRoots{ @@ -253,7 +254,7 @@ func getRandomBlock(height uint64, nTxs int) *types.Block { }, }, } - block.Header.AppHash = getRandomBytes(32) + block.SignedHeader.Header.AppHash = getRandomBytes(32) for i := 0; i < nTxs; i++ { block.Data.Txs[i] = getRandomTx() diff --git a/node/full_client.go b/node/full_client.go index 6ac25224d8..8cc379eb8a 100644 --- a/node/full_client.go +++ b/node/full_client.go @@ -703,11 +703,11 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { return nil, fmt.Errorf("failed to find earliest block: %w", err) } - validators, err := c.node.Store.LoadValidators(uint64(latest.Header.Height())) + validators, err := c.node.Store.LoadValidators(uint64(latest.SignedHeader.Header.Height())) if err != nil { return nil, fmt.Errorf("failed to fetch the validator info at latest block: %w", err) } - _, validator := validators.GetByAddress(latest.Header.ProposerAddress) + _, validator := validators.GetByAddress(latest.SignedHeader.Header.ProposerAddress) state, err := c.node.Store.LoadState() if err != nil { @@ -735,14 +735,14 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) { }, }, SyncInfo: ctypes.SyncInfo{ - LatestBlockHash: tmbytes.HexBytes(latest.Header.DataHash), - LatestAppHash: tmbytes.HexBytes(latest.Header.AppHash), - LatestBlockHeight: latest.Header.Height(), - LatestBlockTime: latest.Header.Time(), - EarliestBlockHash: tmbytes.HexBytes(initial.Header.DataHash), - EarliestAppHash: tmbytes.HexBytes(initial.Header.AppHash), - EarliestBlockHeight: initial.Header.Height(), - EarliestBlockTime: initial.Header.Time(), + LatestBlockHash: tmbytes.HexBytes(latest.SignedHeader.Header.DataHash), + LatestAppHash: tmbytes.HexBytes(latest.SignedHeader.Header.AppHash), + LatestBlockHeight: latest.SignedHeader.Header.Height(), + LatestBlockTime: latest.SignedHeader.Header.Time(), + EarliestBlockHash: tmbytes.HexBytes(initial.SignedHeader.Header.DataHash), + EarliestAppHash: tmbytes.HexBytes(initial.SignedHeader.Header.AppHash), + EarliestBlockHeight: initial.SignedHeader.Header.Height(), + EarliestBlockTime: initial.SignedHeader.Header.Time(), CatchingUp: true, // the client is always syncing in the background to the latest height }, ValidatorInfo: ctypes.ValidatorInfo{ diff --git a/node/full_client_test.go b/node/full_client_test.go index 7badd10600..f74d500b2f 100644 --- a/node/full_client_test.go +++ b/node/full_client_test.go @@ -247,7 +247,7 @@ func TestGetBlock(t *testing.T) { block := getRandomBlock(1, 10) err = rpc.node.Store.SaveBlock(block, &types.Commit{}) - rpc.node.Store.SetHeight(uint64(block.Header.Height())) + rpc.node.Store.SetHeight(uint64(block.SignedHeader.Header.Height())) require.NoError(err) blockResp, err := rpc.Block(context.Background(), nil) @@ -273,17 +273,17 @@ func TestGetCommit(t *testing.T) { require.NoError(err) for _, b := range blocks { - err = rpc.node.Store.SaveBlock(b, &types.Commit{Height: uint64(b.Header.Height())}) - rpc.node.Store.SetHeight(uint64(b.Header.Height())) + err = rpc.node.Store.SaveBlock(b, &types.Commit{Height: uint64(b.SignedHeader.Header.Height())}) + rpc.node.Store.SetHeight(uint64(b.SignedHeader.Header.Height())) require.NoError(err) } t.Run("Fetch all commits", func(t *testing.T) { for _, b := range blocks { - h := b.Header.Height() + h := b.SignedHeader.Header.Height() commit, err := rpc.Commit(context.Background(), &h) require.NoError(err) require.NotNil(commit) - assert.Equal(b.Header.Height(), commit.Height) + assert.Equal(b.SignedHeader.Header.Height(), commit.Height) } }) @@ -291,7 +291,7 @@ func TestGetCommit(t *testing.T) { commit, err := rpc.Commit(context.Background(), nil) require.NoError(err) require.NotNil(commit) - assert.Equal(blocks[3].Header.Height(), commit.Height) + assert.Equal(blocks[3].SignedHeader.Header.Height(), commit.Height) }) err = rpc.node.Stop() @@ -310,7 +310,7 @@ func TestBlockSearch(t *testing.T) { block := getRandomBlock(uint64(h), 5) err := rpc.node.Store.SaveBlock(block, &types.Commit{ Height: uint64(h), - HeaderHash: block.Header.Hash(), + HeaderHash: block.SignedHeader.Header.Hash(), }) require.NoError(err) } @@ -377,14 +377,14 @@ func TestGetBlockByHash(t *testing.T) { abciBlock, err := abciconv.ToABCIBlock(block) require.NoError(err) - height := block.Header.Height() + height := block.SignedHeader.Header.Height() retrievedBlock, err := rpc.Block(context.Background(), &height) require.NoError(err) require.NotNil(retrievedBlock) assert.Equal(abciBlock, retrievedBlock.Block) assert.Equal(abciBlock.Hash(), retrievedBlock.Block.Hash()) - blockHash := block.Header.Hash() + blockHash := block.SignedHeader.Header.Hash() blockResp, err := rpc.BlockByHash(context.Background(), blockHash[:]) require.NoError(err) require.NotNil(blockResp) @@ -564,9 +564,9 @@ func TestBlockchainInfo(t *testing.T) { block := getRandomBlock(uint64(h), 5) err := rpc.node.Store.SaveBlock(block, &types.Commit{ Height: uint64(h), - HeaderHash: block.Header.Hash(), + HeaderHash: block.SignedHeader.Header.Hash(), }) - rpc.node.Store.SetHeight(uint64(block.Header.Height())) + rpc.node.Store.SetHeight(uint64(block.SignedHeader.Header.Height())) require.NoError(err) } @@ -719,14 +719,15 @@ func getRandomBlock(height uint64, nTxs int) *types.Block { func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *types.Block { block := &types.Block{ - Header: types.Header{ - BaseHeader: types.BaseHeader{ - Height: height, - }, - Version: types.Version{Block: types.InitStateVersion.Consensus.Block}, - ProposerAddress: proposerAddr, - AggregatorsHash: make([]byte, 32), - }, + SignedHeader: types.SignedHeader{ + Header: types.Header{ + BaseHeader: types.BaseHeader{ + Height: height, + }, + Version: types.Version{Block: types.InitStateVersion.Consensus.Block}, + ProposerAddress: proposerAddr, + AggregatorsHash: make([]byte, 32), + }}, Data: types.Data{ Txs: make(types.Txs, nTxs), IntermediateStateRoots: types.IntermediateStateRoots{ @@ -734,7 +735,7 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t }, }, } - block.Header.AppHash = getRandomBytes(32) + block.SignedHeader.Header.AppHash = getRandomBytes(32) for i := 0; i < nTxs; i++ { block.Data.Txs[i] = getRandomTx() @@ -753,7 +754,7 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t } lastCommitHash := make(types.Hash, 32) copy(lastCommitHash, tmprotoLC.Hash().Bytes()) - block.Header.LastCommitHash = lastCommitHash + block.SignedHeader.Header.LastCommitHash = lastCommitHash return block } @@ -987,13 +988,13 @@ func TestStatus(t *testing.T) { assert.NotNil(rpc) earliestBlock := getRandomBlockWithProposer(1, 1, validators[0].Address.Bytes()) - err = rpc.node.Store.SaveBlock(earliestBlock, &types.Commit{Height: uint64(earliestBlock.Header.Height())}) - rpc.node.Store.SetHeight(uint64(earliestBlock.Header.Height())) + err = rpc.node.Store.SaveBlock(earliestBlock, &types.Commit{Height: uint64(earliestBlock.SignedHeader.Header.Height())}) + rpc.node.Store.SetHeight(uint64(earliestBlock.SignedHeader.Header.Height())) require.NoError(err) latestBlock := getRandomBlockWithProposer(2, 1, validators[1].Address.Bytes()) - err = rpc.node.Store.SaveBlock(latestBlock, &types.Commit{Height: uint64(latestBlock.Header.Height())}) - rpc.node.Store.SetHeight(uint64(latestBlock.Header.Height())) + err = rpc.node.Store.SaveBlock(latestBlock, &types.Commit{Height: uint64(latestBlock.SignedHeader.Header.Height())}) + rpc.node.Store.SetHeight(uint64(latestBlock.SignedHeader.Header.Height())) require.NoError(err) err = node.Start() diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index abd174f272..75127cdbe5 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -76,7 +76,6 @@ message Data { } message Block { - Header header = 1; + SignedHeader signedHeader = 1; Data data = 2; - Commit last_commit = 3; } diff --git a/state/executor.go b/state/executor.go index fe466cda44..ab825d5d25 100644 --- a/state/executor.go +++ b/state/executor.go @@ -99,34 +99,36 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las mempoolTxs := e.mempool.ReapMaxBytesMaxGas(maxBytes, maxGas) block := &types.Block{ - Header: types.Header{ - Version: types.Version{ - Block: state.Version.Consensus.Block, - App: state.Version.Consensus.App, + SignedHeader: types.SignedHeader{ + Header: types.Header{ + Version: types.Version{ + Block: state.Version.Consensus.Block, + App: state.Version.Consensus.App, + }, + BaseHeader: types.BaseHeader{ + ChainID: e.chainID, + Height: height, + Time: uint64(time.Now().Unix()), // TODO(tzdybal): how to get TAI64? + }, + //LastHeaderHash: lastHeaderHash, + //LastCommitHash: lastCommitHash, + DataHash: make(types.Hash, 32), + ConsensusHash: make(types.Hash, 32), + AppHash: state.AppHash, + LastResultsHash: state.LastResultsHash, + ProposerAddress: e.proposerAddress, }, - BaseHeader: types.BaseHeader{ - ChainID: e.chainID, - Height: height, - Time: uint64(time.Now().Unix()), // TODO(tzdybal): how to get TAI64? - }, - //LastHeaderHash: lastHeaderHash, - //LastCommitHash: lastCommitHash, - DataHash: make(types.Hash, 32), - ConsensusHash: make(types.Hash, 32), - AppHash: state.AppHash, - LastResultsHash: state.LastResultsHash, - ProposerAddress: e.proposerAddress, + Commit: *lastCommit, }, Data: types.Data{ Txs: toRollkitTxs(mempoolTxs), IntermediateStateRoots: types.IntermediateStateRoots{RawRootsList: nil}, Evidence: types.EvidenceData{Evidence: nil}, }, - LastCommit: *lastCommit, } - block.Header.LastCommitHash = e.getLastCommitHash(lastCommit, &block.Header) - block.Header.LastHeaderHash = lastHeaderHash - block.Header.AggregatorsHash = state.Validators.Hash() + block.SignedHeader.Header.LastCommitHash = e.getLastCommitHash(lastCommit, &block.SignedHeader.Header) + block.SignedHeader.Header.LastHeaderHash = lastHeaderHash + block.SignedHeader.Header.AggregatorsHash = state.Validators.Hash() return block } @@ -211,7 +213,7 @@ func (e *BlockExecutor) updateState(state types.State, block *types.Block, abciR return state, nil } // Change results from this height but only applies to the next next height. - lastHeightValSetChanged = block.Header.Height() + 1 + 1 + lastHeightValSetChanged = block.SignedHeader.Header.Height() + 1 + 1 } // TODO(tzdybal): right now, it's for backward compatibility, may need to change this @@ -222,10 +224,10 @@ func (e *BlockExecutor) updateState(state types.State, block *types.Block, abciR Version: state.Version, ChainID: state.ChainID, InitialHeight: state.InitialHeight, - LastBlockHeight: block.Header.Height(), - LastBlockTime: block.Header.Time(), + LastBlockHeight: block.SignedHeader.Header.Height(), + LastBlockTime: block.SignedHeader.Header.Time(), LastBlockID: tmtypes.BlockID{ - Hash: tmbytes.HexBytes(block.Header.Hash()), + Hash: tmbytes.HexBytes(block.SignedHeader.Header.Hash()), // for now, we don't care about part set headers }, NextValidators: nValSet, @@ -257,7 +259,7 @@ func (e *BlockExecutor) commit(ctx context.Context, state types.State, block *ty maxBytes := state.ConsensusParams.Block.MaxBytes maxGas := state.ConsensusParams.Block.MaxGas - err = e.mempool.Update(int64(block.Header.Height()), fromRollkitTxs(block.Data.Txs), deliverTxs, mempool.PreCheckMaxBytes(maxBytes), mempool.PostCheckMaxGas(maxGas)) + err = e.mempool.Update(int64(block.SignedHeader.Header.Height()), fromRollkitTxs(block.Data.Txs), deliverTxs, mempool.PreCheckMaxBytes(maxBytes), mempool.PostCheckMaxGas(maxGas)) if err != nil { return nil, 0, err } @@ -270,21 +272,21 @@ func (e *BlockExecutor) validate(state types.State, block *types.Block) error { if err != nil { return err } - if block.Header.Version.App != state.Version.Consensus.App || - block.Header.Version.Block != state.Version.Consensus.Block { + if block.SignedHeader.Header.Version.App != state.Version.Consensus.App || + block.SignedHeader.Header.Version.Block != state.Version.Consensus.Block { return errors.New("block version mismatch") } - if state.LastBlockHeight <= 0 && block.Header.Height() != state.InitialHeight { + if state.LastBlockHeight <= 0 && block.SignedHeader.Header.Height() != state.InitialHeight { return errors.New("initial block height mismatch") } - if state.LastBlockHeight > 0 && block.Header.Height() != state.LastBlockHeight+1 { + if state.LastBlockHeight > 0 && block.SignedHeader.Header.Height() != state.LastBlockHeight+1 { return errors.New("block height mismatch") } - if !bytes.Equal(block.Header.AppHash[:], state.AppHash[:]) { + if !bytes.Equal(block.SignedHeader.Header.AppHash[:], state.AppHash[:]) { return errors.New("AppHash mismatch") } - if !bytes.Equal(block.Header.LastResultsHash[:], state.LastResultsHash[:]) { + if !bytes.Equal(block.SignedHeader.Header.LastResultsHash[:], state.LastResultsHash[:]) { return errors.New("LastResultsHash mismatch") } @@ -351,7 +353,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t } hash := block.Hash() - abciHeader, err := abciconv.ToABCIHeaderPB(&block.Header) + abciHeader, err := abciconv.ToABCIHeaderPB(&block.SignedHeader.Header) if err != nil { return nil, err } @@ -390,7 +392,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t return nil, err } } - endBlockRequest := abci.RequestEndBlock{Height: block.Header.Height()} + endBlockRequest := abci.RequestEndBlock{Height: block.SignedHeader.Header.Height()} abciResponses.EndBlock, err = e.proxyApp.EndBlockSync(endBlockRequest) if err != nil { return nil, err @@ -477,13 +479,13 @@ func (e *BlockExecutor) publishEvents(resp *tmstate.ABCIResponses, block *types. for _, ev := range abciBlock.Evidence.Evidence { err = multierr.Append(err, e.eventBus.PublishEventNewEvidence(tmtypes.EventDataNewEvidence{ Evidence: ev, - Height: block.Header.Height(), + Height: block.SignedHeader.Header.Height(), })) } for i, dtx := range resp.DeliverTxs { err = multierr.Append(err, e.eventBus.PublishEventTx(tmtypes.EventDataTx{ TxResult: abci.TxResult{ - Height: block.Header.Height(), + Height: block.SignedHeader.Header.Height(), Index: uint32(i), Tx: abciBlock.Data.Txs[i], Result: *dtx, diff --git a/state/executor_test.go b/state/executor_test.go index 65d154a276..bb0a978810 100644 --- a/state/executor_test.go +++ b/state/executor_test.go @@ -50,14 +50,14 @@ func doTestCreateBlock(t *testing.T, fraudProofsEnabled bool) { block := executor.CreateBlock(1, &types.Commit{}, []byte{}, state) require.NotNil(block) assert.Empty(block.Data.Txs) - assert.Equal(int64(1), block.Header.Height()) + assert.Equal(int64(1), block.SignedHeader.Header.Height()) // 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{}, []byte{}, state) require.NotNil(block) - assert.Equal(int64(2), block.Header.Height()) + assert.Equal(int64(2), block.SignedHeader.Header.Height()) assert.Len(block.Data.Txs, 1) // now there are 3 Txs, and only two can fit into single block @@ -138,7 +138,7 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) { require.NoError(err) block := executor.CreateBlock(1, &types.Commit{}, []byte{}, state) require.NotNil(block) - assert.Equal(int64(1), block.Header.Height()) + assert.Equal(int64(1), block.SignedHeader.Header.Height()) assert.Len(block.Data.Txs, 1) newState, resp, err := executor.ApplyBlock(context.Background(), state, block) @@ -156,7 +156,7 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) { require.NoError(mpool.CheckTx(make([]byte, 90), func(r *abci.Response) {}, mempool.TxInfo{})) block = executor.CreateBlock(2, &types.Commit{}, []byte{}, newState) require.NotNil(block) - assert.Equal(int64(2), block.Header.Height()) + assert.Equal(int64(2), block.SignedHeader.Header.Height()) assert.Len(block.Data.Txs, 3) newState, resp, err = executor.ApplyBlock(context.Background(), newState, block) diff --git a/store/store.go b/store/store.go index cd6629a49a..34070944d3 100644 --- a/store/store.go +++ b/store/store.go @@ -62,7 +62,7 @@ func (s *DefaultStore) Height() uint64 { // SaveBlock adds block to the store along with corresponding commit. // Stored height is updated if block height is greater than stored value. func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit) error { - hash := block.Header.Hash() + hash := block.SignedHeader.Header.Hash() blockBlob, err := block.MarshalBinary() if err != nil { return fmt.Errorf("failed to marshal Block to binary: %w", err) @@ -80,7 +80,7 @@ func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit) error err = multierr.Append(err, bb.Put(s.ctx, ds.NewKey(getBlockKey(hash)), blockBlob)) err = multierr.Append(err, bb.Put(s.ctx, ds.NewKey(getCommitKey(hash)), commitBlob)) - err = multierr.Append(err, bb.Put(s.ctx, ds.NewKey(getIndexKey(uint64(block.Header.Height()))), hash[:])) + err = multierr.Append(err, bb.Put(s.ctx, ds.NewKey(getIndexKey(uint64(block.SignedHeader.Header.Height()))), hash[:])) if err != nil { bb.Discard(s.ctx) diff --git a/store/store_test.go b/store/store_test.go index a2902def92..95188cc93c 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -51,7 +51,7 @@ func TestStoreHeight(t *testing.T) { for _, block := range c.blocks { err := bstore.SaveBlock(block, &types.Commit{}) - bstore.SetHeight(uint64(block.Header.Height())) + bstore.SetHeight(uint64(block.SignedHeader.Header.Height())) assert.NoError(err) } @@ -102,27 +102,27 @@ func TestStoreLoad(t *testing.T) { lastCommit := &types.Commit{} for _, block := range c.blocks { - commit := &types.Commit{Height: uint64(block.Header.Height()), HeaderHash: block.Header.Hash()} - block.LastCommit = *lastCommit + commit := &types.Commit{Height: uint64(block.SignedHeader.Header.Height()), HeaderHash: block.SignedHeader.Header.Hash()} + block.SignedHeader.Commit = *lastCommit err := bstore.SaveBlock(block, commit) require.NoError(err) lastCommit = commit } for _, expected := range c.blocks { - block, err := bstore.LoadBlock(uint64(expected.Header.Height())) + block, err := bstore.LoadBlock(uint64(expected.SignedHeader.Header.Height())) assert.NoError(err) assert.NotNil(block) assert.Equal(expected, block) - assert.Equal(expected.Header.Height()-1, int64(block.LastCommit.Height)) - assert.Equal(expected.LastCommit.Height, block.LastCommit.Height) - assert.Equal(expected.LastCommit.HeaderHash, block.LastCommit.HeaderHash) + assert.Equal(expected.SignedHeader.Header.Height()-1, int64(block.SignedHeader.Commit.Height)) + assert.Equal(expected.SignedHeader.Commit.Height, block.SignedHeader.Commit.Height) + assert.Equal(expected.SignedHeader.Commit.HeaderHash, block.SignedHeader.Commit.HeaderHash) - commit, err := bstore.LoadCommit(uint64(expected.Header.Height())) + commit, err := bstore.LoadCommit(uint64(expected.SignedHeader.Header.Height())) assert.NoError(err) assert.NotNil(commit) - assert.Equal(uint64(expected.Header.Height()), commit.Height) - headerHash := expected.Header.Hash() + assert.Equal(uint64(expected.SignedHeader.Header.Height()), commit.Height) + headerHash := expected.SignedHeader.Header.Hash() assert.Equal(headerHash, commit.HeaderHash) } }) @@ -201,12 +201,13 @@ func TestBlockResponses(t *testing.T) { func getRandomBlock(height uint64, nTxs int) *types.Block { block := &types.Block{ - Header: types.Header{ - BaseHeader: types.BaseHeader{ - Height: height, - }, - AggregatorsHash: make([]byte, 32), - }, + SignedHeader: types.SignedHeader{ + Header: types.Header{ + BaseHeader: types.BaseHeader{ + Height: height, + }, + AggregatorsHash: make([]byte, 32), + }}, Data: types.Data{ Txs: make(types.Txs, nTxs), IntermediateStateRoots: types.IntermediateStateRoots{ diff --git a/types/block.go b/types/block.go index 6948e90ed0..118c86b565 100644 --- a/types/block.go +++ b/types/block.go @@ -17,9 +17,8 @@ type Version struct { // Block defines the structure of Rollkit block. type Block struct { - Header Header - Data Data - LastCommit Commit + SignedHeader SignedHeader + Data Data } var _ encoding.BinaryMarshaler = &Block{} diff --git a/types/hashing.go b/types/hashing.go index 80530740ee..01ed4d8d17 100644 --- a/types/hashing.go +++ b/types/hashing.go @@ -38,5 +38,5 @@ func (h *Header) Hash() Hash { // Hash returns ABCI-compatible hash of a block. func (b *Block) Hash() Hash { - return b.Header.Hash() + return b.SignedHeader.Header.Hash() } diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index 862d343264..bc8a1476fc 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -403,9 +403,8 @@ func (m *Data) GetEvidence() []*types.Evidence { } type Block struct { - Header *Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - Data *Data `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` - LastCommit *Commit `protobuf:"bytes,3,opt,name=last_commit,json=lastCommit,proto3" json:"last_commit,omitempty"` + SignedHeader *SignedHeader `protobuf:"bytes,1,opt,name=signedHeader,proto3" json:"signedHeader,omitempty"` + Data *Data `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` } func (m *Block) Reset() { *m = Block{} } @@ -441,9 +440,9 @@ func (m *Block) XXX_DiscardUnknown() { var xxx_messageInfo_Block proto.InternalMessageInfo -func (m *Block) GetHeader() *Header { +func (m *Block) GetSignedHeader() *SignedHeader { if m != nil { - return m.Header + return m.SignedHeader } return nil } @@ -455,13 +454,6 @@ func (m *Block) GetData() *Data { return nil } -func (m *Block) GetLastCommit() *Commit { - if m != nil { - return m.LastCommit - } - return nil -} - func init() { proto.RegisterType((*Version)(nil), "rollkit.Version") proto.RegisterType((*Header)(nil), "rollkit.Header") @@ -474,44 +466,44 @@ func init() { func init() { proto.RegisterFile("rollkit/rollkit.proto", fileDescriptor_ed489fb7f4d78b3f) } var fileDescriptor_ed489fb7f4d78b3f = []byte{ - // 587 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x97, 0xb5, 0x6b, 0xda, 0xd7, 0x6e, 0x2b, 0x11, 0x4c, 0x19, 0x93, 0x42, 0x89, 0x84, - 0x28, 0x43, 0x4a, 0x61, 0x08, 0x89, 0x2b, 0x83, 0x49, 0xe3, 0x9a, 0x49, 0x1c, 0xb8, 0x14, 0x37, - 0xb1, 0x12, 0x6b, 0x4d, 0x6c, 0xd9, 0xee, 0x04, 0x1f, 0x80, 0x03, 0x37, 0x3e, 0x0a, 0x1f, 0x83, - 0xe3, 0x8e, 0x1c, 0x51, 0xfb, 0x45, 0x90, 0x9f, 0xdd, 0x36, 0x20, 0x0e, 0x5c, 0x5a, 0xfb, 0xff, - 0xff, 0xc5, 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x4e, 0x95, 0x36, - 0xbf, 0x92, 0x73, 0xad, 0xc2, 0x5d, 0xc4, 0x8e, 0x9a, 0xfe, 0x95, 0xb1, 0x53, 0xe3, 0x06, 0x2f, - 0xa1, 0x4b, 0x6f, 0x58, 0x4e, 0xeb, 0x8c, 0xe2, 0xa6, 0xfa, 0x67, 0xc7, 0xc9, 0xb6, 0x5f, 0x12, - 0xd3, 0x2f, 0xc9, 0x85, 0x03, 0xd2, 0x0d, 0x1a, 0x7f, 0xf1, 0x60, 0xef, 0x1c, 0xfb, 0xe3, 0xbf, - 0xf7, 0xf9, 0x10, 0xda, 0xa6, 0xdc, 0xdc, 0x2e, 0xf7, 0x37, 0x98, 0xd9, 0x52, 0x8a, 0x56, 0xf0, - 0x0c, 0xfa, 0x8d, 0x62, 0xc6, 0x8e, 0xf8, 0xc7, 0x79, 0xc0, 0xb6, 0xb0, 0xcf, 0x2f, 0x7e, 0x2c, - 0x23, 0xef, 0x76, 0x19, 0x79, 0xbf, 0x96, 0x91, 0xf7, 0x6d, 0x15, 0xed, 0xdc, 0xae, 0xa2, 0x9d, - 0x9f, 0xab, 0x68, 0xe7, 0xc3, 0xd3, 0x82, 0xe9, 0x72, 0x31, 0x4b, 0x32, 0x5e, 0x4d, 0xfe, 0x7a, - 0x20, 0xec, 0x03, 0x30, 0x11, 0xb3, 0xb5, 0x30, 0xeb, 0xe0, 0x63, 0xf0, 0xe2, 0x77, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x10, 0x12, 0xe8, 0xcc, 0x4b, 0x04, 0x00, 0x00, + // 583 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xc7, 0xe3, 0xfc, 0x73, 0x32, 0x49, 0xdb, 0xfc, 0xac, 0x5f, 0x2b, 0x97, 0x4a, 0x26, 0x58, + 0x42, 0x84, 0x22, 0x39, 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00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -821,18 +813,6 @@ func (m *Block) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.LastCommit != nil { - { - size, err := m.LastCommit.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRollkit(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } if m.Data != nil { { size, err := m.Data.MarshalToSizedBuffer(dAtA[:i]) @@ -845,9 +825,9 @@ func (m *Block) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if m.Header != nil { + if m.SignedHeader != nil { { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.SignedHeader.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -1013,18 +993,14 @@ func (m *Block) Size() (n int) { } var l int _ = l - if m.Header != nil { - l = m.Header.Size() + if m.SignedHeader != nil { + l = m.SignedHeader.Size() n += 1 + l + sovRollkit(uint64(l)) } if m.Data != nil { l = m.Data.Size() n += 1 + l + sovRollkit(uint64(l)) } - if m.LastCommit != nil { - l = m.LastCommit.Size() - n += 1 + l + sovRollkit(uint64(l)) - } return n } @@ -1986,7 +1962,7 @@ func (m *Block) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SignedHeader", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -2013,10 +1989,10 @@ func (m *Block) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Header == nil { - m.Header = &Header{} + if m.SignedHeader == nil { + m.SignedHeader = &SignedHeader{} } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.SignedHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -2056,42 +2032,6 @@ func (m *Block) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LastCommit", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRollkit - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRollkit - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRollkit - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LastCommit == nil { - m.LastCommit = &Commit{} - } - if err := m.LastCommit.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRollkit(dAtA[iNdEx:]) diff --git a/types/serialization.go b/types/serialization.go index 7206d9f251..a18133e9e2 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -146,9 +146,8 @@ func (h *Header) FromProto(other *pb.Header) error { // ToProto converts Block into protobuf representation and returns it. func (b *Block) ToProto() *pb.Block { return &pb.Block{ - Header: b.Header.ToProto(), - Data: b.Data.ToProto(), - LastCommit: b.LastCommit.ToProto(), + SignedHeader: b.SignedHeader.ToProto(), + Data: b.Data.ToProto(), } } @@ -163,19 +162,13 @@ func (d *Data) ToProto() *pb.Data { // FromProto fills Block with data from its protobuf representation. func (b *Block) FromProto(other *pb.Block) error { - err := b.Header.FromProto(other.Header) + err := b.SignedHeader.FromProto(other.SignedHeader) if err != nil { return err } b.Data.Txs = byteSlicesToTxs(other.Data.Txs) b.Data.IntermediateStateRoots.RawRootsList = other.Data.IntermediateStateRoots b.Data.Evidence = evidenceFromProto(other.Data.Evidence) - if other.LastCommit != nil { - err := b.LastCommit.FromProto(other.LastCommit) - if err != nil { - return err - } - } return nil } diff --git a/types/serialization_test.go b/types/serialization_test.go index 1a09b2d6d3..de57afb5f6 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -38,35 +38,36 @@ func TestBlockSerializationRoundTrip(t *testing.T) { }{ {"empty block", &Block{}}, {"full", &Block{ - Header: Header{ - Version: Version{ - Block: 1, - App: 2, - }, - BaseHeader: BaseHeader{ - Height: 3, - Time: 4567, + SignedHeader: SignedHeader{ + Header: Header{ + Version: Version{ + Block: 1, + App: 2, + }, + BaseHeader: BaseHeader{ + Height: 3, + Time: 4567, + }, + LastHeaderHash: h[0], + LastCommitHash: h[1], + DataHash: h[2], + ConsensusHash: h[3], + AppHash: h[4], + LastResultsHash: h[5], + ProposerAddress: []byte{4, 3, 2, 1}, + AggregatorsHash: h[6], }, - LastHeaderHash: h[0], - LastCommitHash: h[1], - DataHash: h[2], - ConsensusHash: h[3], - AppHash: h[4], - LastResultsHash: h[5], - ProposerAddress: []byte{4, 3, 2, 1}, - AggregatorsHash: h[6], - }, + Commit: Commit{ + Height: 8, + HeaderHash: h[7][:], + Signatures: []Signature{Signature([]byte{1, 1, 1}), Signature([]byte{2, 2, 2})}, + }}, Data: Data{ Txs: nil, IntermediateStateRoots: IntermediateStateRoots{RawRootsList: [][]byte{{0x1}}}, // TODO(tzdybal): update when we have actual evidence types Evidence: EvidenceData{Evidence: nil}, }, - LastCommit: Commit{ - Height: 8, - HeaderHash: h[7][:], - Signatures: []Signature{Signature([]byte{1, 1, 1}), Signature([]byte{2, 2, 2})}, - }, }}, } diff --git a/types/validation.go b/types/validation.go index ee8503956c..2d99df277b 100644 --- a/types/validation.go +++ b/types/validation.go @@ -9,7 +9,7 @@ import ( // ValidateBasic performs basic validation of a block. func (b *Block) ValidateBasic() error { - err := b.Header.ValidateBasic() + err := b.SignedHeader.Header.ValidateBasic() if err != nil { return err } @@ -19,7 +19,7 @@ func (b *Block) ValidateBasic() error { return err } - err = b.LastCommit.ValidateBasic() + err = b.SignedHeader.Commit.ValidateBasic() if err != nil { return err } From 3ee01eaaa8bc080323161247a46801254c284f08 Mon Sep 17 00:00:00 2001 From: nashqueue Date: Mon, 13 Mar 2023 20:59:05 +0100 Subject: [PATCH 2/9] remove hash and height from commit --- proto/rollkit/rollkit.proto | 3 - store/store_test.go | 8 +- types/pb/rollkit/rollkit.pb.go | 164 ++++++++------------------------- types/serialization.go | 4 - types/serialization_test.go | 2 - 5 files changed, 38 insertions(+), 143 deletions(-) diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index 75127cdbe5..2570f0d160 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -58,9 +58,6 @@ message Header { } message Commit { - uint64 height = 1; - bytes header_hash = 2; - // Note: most of the time this will be a single sinature repeated bytes signatures = 3; } diff --git a/store/store_test.go b/store/store_test.go index 95188cc93c..e24271c537 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -102,7 +102,7 @@ func TestStoreLoad(t *testing.T) { lastCommit := &types.Commit{} for _, block := range c.blocks { - commit := &types.Commit{Height: uint64(block.SignedHeader.Header.Height()), HeaderHash: block.SignedHeader.Header.Hash()} + commit := &types.Commit{} block.SignedHeader.Commit = *lastCommit err := bstore.SaveBlock(block, commit) require.NoError(err) @@ -114,16 +114,10 @@ func TestStoreLoad(t *testing.T) { assert.NoError(err) assert.NotNil(block) assert.Equal(expected, block) - assert.Equal(expected.SignedHeader.Header.Height()-1, int64(block.SignedHeader.Commit.Height)) - assert.Equal(expected.SignedHeader.Commit.Height, block.SignedHeader.Commit.Height) - assert.Equal(expected.SignedHeader.Commit.HeaderHash, block.SignedHeader.Commit.HeaderHash) commit, err := bstore.LoadCommit(uint64(expected.SignedHeader.Header.Height())) assert.NoError(err) assert.NotNil(commit) - assert.Equal(uint64(expected.SignedHeader.Header.Height()), commit.Height) - headerHash := expected.SignedHeader.Header.Hash() - assert.Equal(headerHash, commit.HeaderHash) } }) } diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index bc8a1476fc..8cf7b24d07 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -230,9 +230,6 @@ func (m *Header) GetChainId() string { } type Commit struct { - Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` - HeaderHash []byte `protobuf:"bytes,2,opt,name=header_hash,json=headerHash,proto3" json:"header_hash,omitempty"` - // Note: most of the time this will be a single sinature Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` } @@ -269,20 +266,6 @@ func (m *Commit) XXX_DiscardUnknown() { var xxx_messageInfo_Commit proto.InternalMessageInfo -func (m *Commit) GetHeight() uint64 { - if m != nil { - return m.Height - } - return 0 -} - -func (m *Commit) GetHeaderHash() []byte { - if m != nil { - return m.HeaderHash - } - return nil -} - func (m *Commit) GetSignatures() [][]byte { if m != nil { return m.Signatures @@ -466,44 +449,43 @@ func init() { func init() { proto.RegisterFile("rollkit/rollkit.proto", fileDescriptor_ed489fb7f4d78b3f) } var fileDescriptor_ed489fb7f4d78b3f = []byte{ - // 583 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xc7, 0xe3, 0xfc, 0x73, 0x32, 0x49, 0xdb, 0xfc, 0xac, 0x5f, 0x2b, 0x97, 0x4a, 0x26, 0x58, - 0x42, 0x84, 0x22, 0x39, 0xa2, 0x08, 0x09, 0x8e, 0x14, 0x2a, 0x95, 0xab, 0x2b, 0x71, 0xe0, 0x12, - 0x36, 0xf6, 0xca, 0x5e, 0x35, 0xf6, 0x5a, 0xbb, 0x9b, 0x0a, 0x1e, 0x81, 0x1b, 0x8f, 0xc2, 0x63, - 0x70, 0xec, 0x91, 0x23, 0x4a, 0x5e, 0x04, 0xed, 0xec, 0xc6, 0x71, 0xb9, 0x24, 0xbb, 0xdf, 0xef, - 0xc7, 0x3b, 0x33, 0xbb, 0x33, 0x70, 0x2c,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0xe9, 0xb7, 0x11, 0x3b, 0x69, 0xfa, 0x37, 0xda, 0x8e, 0xb5, 0xeb, 0xbd, 0x86, - 0x01, 0xbd, 0x63, 0x29, 0x2d, 0x13, 0x8a, 0x45, 0x8d, 0x2e, 0x4e, 0xa3, 0xfd, 0xbc, 0x44, 0x7a, - 0x5e, 0xa2, 0x2b, 0x0b, 0xc4, 0x35, 0x1a, 0x52, 0xe8, 0x5d, 0xe2, 0x78, 0xbc, 0x85, 0xb1, 0x6c, - 0x94, 0x6d, 0x8b, 0x3d, 0xae, 0x6b, 0x68, 0xde, 0x49, 0xfc, 0x00, 0xf5, 0x9e, 0x40, 0x57, 0xf7, - 0x9f, 0x2d, 0xfb, 0xa0, 0xfe, 0x44, 0xd7, 0x18, 0xa3, 0x75, 0x79, 0xf5, 0x6b, 0x13, 0x38, 0xf7, - 0x9b, 0xc0, 0xf9, 0xb3, 0x09, 0x9c, 0x1f, 0xdb, 0xa0, 0x75, 0xbf, 0x0d, 0x5a, 0xbf, 0xb7, 0x41, - 0xeb, 0xf3, 0x8b, 0x8c, 0xa9, 0x7c, 0xbd, 0x8c, 0x12, 0x5e, 0xcc, 0xff, 0x99, 0x7f, 0x33, 0xdf, - 0xf3, 0x6a, 0xb9, 0x13, 0x96, 0x7d, 0x9c, 0xf5, 0x57, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x62, - 0x32, 0x43, 0x12, 0x2a, 0x04, 0x00, 0x00, + // 568 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0xd1, 0x6e, 0xd3, 0x3c, + 0x14, 0xc7, 0x97, 0xb5, 0x6b, 0xbb, 0xb3, 0x6e, 0xeb, 0x67, 0x7d, 0x9b, 0x32, 0x26, 0x45, 0x25, + 0x12, 0x22, 0x0c, 0x29, 0x15, 0x43, 0x48, 0x70, 0xc9, 0x60, 0xd2, 0xb8, 0xf5, 0x24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x09, 0xe3, 0xc8, 0x9d, 0x07, 0xf2, 0x1d, 0xca, 0x48, 0x9e, 0xc2, 0x6e, 0xce, + 0x0c, 0x73, 0xc8, 0x00, 0x91, 0x91, 0x15, 0xd0, 0x7c, 0x02, 0x07, 0x99, 0xac, 0x35, 0xaf, 0xf5, + 0x4a, 0x3b, 0x62, 0x88, 0xc4, 0x7e, 0xab, 0x22, 0x76, 0x02, 0x23, 0xd6, 0x34, 0x0e, 0x18, 0x21, + 0x30, 0x64, 0x4d, 0x83, 0xd6, 0x19, 0xfc, 0x87, 0x89, 0x28, 0xae, 0x57, 0x4b, 0xe3, 0x83, 0xec, + 0x22, 0x73, 0x68, 0x0d, 0xea, 0x74, 0x64, 0x9f, 0xc1, 0xa4, 0x51, 0xb2, 0x91, 0x9a, 0xab, 0x39, + 0xcb, 0x73, 0xc5, 0xb5, 0x0e, 0xc1, 0xa1, 0x1b, 0xfd, 0xad, 0x93, 0x2d, 0xca, 0x8a, 0x42, 0xf1, + 0x82, 0x19, 0xa9, 0x7c, 0xd4, 0x3d, 0x87, 0x76, 0xf4, 0x4d, 0x72, 0x59, 0xc9, 0x44, 0x3d, 0x17, + 0x79, 0x38, 0x9e, 0x06, 0xc9, 0x2e, 0x1d, 0xe2, 0xfe, 0x43, 0x1e, 0x27, 0x30, 0x70, 0x5f, 0x82, + 0x44, 0x00, 0x5a, 0x14, 0x35, 0x33, 0x2b, 0xc5, 0x75, 0xd8, 0x9b, 0xf6, 0x92, 0x31, 0xed, 0x28, + 0xf1, 0x67, 0x18, 0x5f, 0x8b, 0xa2, 0xe6, 0xb9, 0xef, 0xf0, 0x53, 0xdb, 0x35, 0xbb, 0xf2, 0x0d, + 0x3e, 0x6c, 0x1b, 0xec, 0x00, 0xea, 0x6d, 0x0b, 0xba, 0x1e, 0x60, 0x7b, 0xbb, 0xa0, 0xbb, 0x99, + 0x7a, 0x3b, 0xfe, 0x16, 0x40, 0xff, 0x3d, 0x33, 0xcc, 0x4e, 0x96, 0xf9, 0xa2, 0xc3, 0x00, 0x73, + 0xb0, 0x4b, 0xf2, 0x1a, 0x42, 0x51, 0x1b, 0xae, 0x2a, 0x9e, 0x0b, 0x66, 0xf8, 0x5c, 0x1b, 0xfb, + 0xab, 0xa4, 0x34, 0x3a, 0xdc, 0x46, 0xec, 0xb8, 0xeb, 0x5f, 0x5b, 0x9b, 0x5a, 0x97, 0xbc, 0x82, + 0x11, 0xbf, 0x15, 0x39, 0xaf, 0x33, 0x8e, 0x45, 0xed, 0x9d, 0x9f, 0xa4, 0x0f, 0x63, 0x9f, 0xda, + 0xb1, 0x4f, 0x2f, 0x3d, 0x40, 0x5b, 0x34, 0xe6, 0xb0, 0x73, 0x81, 0x53, 0xfe, 0x06, 0xc6, 0xba, + 0x53, 0xb6, 0x2f, 0xf6, 0xa8, 0xad, 0xa1, 0xfb, 0x4d, 0xe8, 0x5f, 0x28, 0x79, 0x0c, 0x7d, 0x3b, + 0x46, 0xbe, 0xec, 0xfd, 0xf6, 0x88, 0xad, 0x91, 0xa2, 0x75, 0x71, 0xf9, 0xf3, 0x3e, 0x0a, 0xee, + 0xee, 0xa3, 0xe0, 0xf7, 0x7d, 0x14, 0x7c, 0x5f, 0x47, 0x5b, 0x77, 0xeb, 0x68, 0xeb, 0xd7, 0x3a, + 0xda, 0xfa, 0xf4, 0xbc, 0x10, 0xa6, 0x5c, 0x2d, 0xd2, 0x4c, 0x56, 0xb3, 0x7f, 0x9e, 0xb1, 0x7b, + 0xa6, 0xb3, 0x66, 0xb1, 0x11, 0x16, 0x03, 0x7c, 0xb2, 0x2f, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, + 0x99, 0x09, 0x4e, 0xec, 0xf1, 0x03, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -676,18 +658,6 @@ func (m *Commit) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x1a } } - if len(m.HeaderHash) > 0 { - i -= len(m.HeaderHash) - copy(dAtA[i:], m.HeaderHash) - i = encodeVarintRollkit(dAtA, i, uint64(len(m.HeaderHash))) - i-- - dAtA[i] = 0x12 - } - if m.Height != 0 { - i = encodeVarintRollkit(dAtA, i, uint64(m.Height)) - i-- - dAtA[i] = 0x8 - } return len(dAtA) - i, nil } @@ -927,13 +897,6 @@ func (m *Commit) Size() (n int) { } var l int _ = l - if m.Height != 0 { - n += 1 + sovRollkit(uint64(m.Height)) - } - l = len(m.HeaderHash) - if l > 0 { - n += 1 + l + sovRollkit(uint64(l)) - } if len(m.Signatures) > 0 { for _, b := range m.Signatures { l = len(b) @@ -1555,59 +1518,6 @@ func (m *Commit) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Commit: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) - } - m.Height = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRollkit - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Height |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HeaderHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRollkit - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRollkit - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRollkit - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.HeaderHash = append(m.HeaderHash[:0], dAtA[iNdEx:postIndex]...) - if m.HeaderHash == nil { - m.HeaderHash = []byte{} - } - iNdEx = postIndex case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) diff --git a/types/serialization.go b/types/serialization.go index a18133e9e2..f5c2d9d547 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -176,16 +176,12 @@ func (b *Block) FromProto(other *pb.Block) error { // ToProto converts Commit into protobuf representation and returns it. func (c *Commit) ToProto() *pb.Commit { return &pb.Commit{ - Height: c.Height, - HeaderHash: c.HeaderHash, Signatures: signaturesToByteSlices(c.Signatures), } } // FromProto fills Commit with data from its protobuf representation. func (c *Commit) FromProto(other *pb.Commit) error { - c.Height = other.Height - c.HeaderHash = other.HeaderHash c.Signatures = byteSlicesToSignatures(other.Signatures) return nil diff --git a/types/serialization_test.go b/types/serialization_test.go index de57afb5f6..5443255266 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -58,8 +58,6 @@ func TestBlockSerializationRoundTrip(t *testing.T) { AggregatorsHash: h[6], }, Commit: Commit{ - Height: 8, - HeaderHash: h[7][:], Signatures: []Signature{Signature([]byte{1, 1, 1}), Signature([]byte{2, 2, 2})}, }}, Data: Data{ From d9393afd2b82f59c3aff02213018a5ba5dc6405b Mon Sep 17 00:00:00 2001 From: nashqueue Date: Mon, 13 Mar 2023 21:19:36 +0100 Subject: [PATCH 3/9] add proposer_public_key --- proto/rollkit/rollkit.proto | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index 2570f0d160..ecd45ce031 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -49,12 +49,15 @@ message Header { // pubkey can't be recovered by the signature (e.g. ed25519). bytes proposer_address = 10; + //public key of the proposer so we can verify the signature + bytes proposer_public_key = 11; + // Hash of block aggregator set, at a time of block creation - bytes aggregators_hash = 11; + bytes aggregators_hash = 12; // Chain ID the block belongs to - string chain_id = 12; + string chain_id = 13; } message Commit { From ffb880998e27a3cfbf04f966b57c8551be41463a Mon Sep 17 00:00:00 2001 From: nashqueue Date: Mon, 13 Mar 2023 21:25:00 +0100 Subject: [PATCH 4/9] update proto --- types/pb/rollkit/rollkit.pb.go | 137 +++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 41 deletions(-) diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index 8cf7b24d07..60fcbc624b 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -106,10 +106,12 @@ type Header struct { // We keep this in case users choose another signature format where the // pubkey can't be recovered by the signature (e.g. ed25519). ProposerAddress []byte `protobuf:"bytes,10,opt,name=proposer_address,json=proposerAddress,proto3" json:"proposer_address,omitempty"` + //public key of the proposer so we can verify the signature + ProposerPublicKey []byte `protobuf:"bytes,11,opt,name=proposer_public_key,json=proposerPublicKey,proto3" json:"proposer_public_key,omitempty"` // Hash of block aggregator set, at a time of block creation - AggregatorsHash []byte `protobuf:"bytes,11,opt,name=aggregators_hash,json=aggregatorsHash,proto3" json:"aggregators_hash,omitempty"` + AggregatorsHash []byte `protobuf:"bytes,12,opt,name=aggregators_hash,json=aggregatorsHash,proto3" json:"aggregators_hash,omitempty"` // Chain ID the block belongs to - ChainId string `protobuf:"bytes,12,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + ChainId string `protobuf:"bytes,13,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` } func (m *Header) Reset() { *m = Header{} } @@ -215,6 +217,13 @@ func (m *Header) GetProposerAddress() []byte { return nil } +func (m *Header) GetProposerPublicKey() []byte { + if m != nil { + return m.ProposerPublicKey + } + return nil +} + func (m *Header) GetAggregatorsHash() []byte { if m != nil { return m.AggregatorsHash @@ -449,43 +458,44 @@ func init() { func init() { proto.RegisterFile("rollkit/rollkit.proto", fileDescriptor_ed489fb7f4d78b3f) } var fileDescriptor_ed489fb7f4d78b3f = []byte{ - // 568 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0xd1, 0x6e, 0xd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e2, 0x9a, 0x24, 0x30, 0x59, 0x32, 0x6d, 0xe6, 0x25, 0x5e, 0x33, 0x2f, - 0x99, 0x2e, 0xc3, 0xfe, 0x34, 0x48, 0xc6, 0xf4, 0xc0, 0xea, 0xee, 0xf6, 0x2b, 0xa6, 0xcb, 0x96, - 0xcc, 0x64, 0x55, 0x09, 0xe3, 0xc8, 0x9d, 0x07, 0xf2, 0x1d, 0xca, 0x48, 0x9e, 0xc2, 0x6e, 0xce, - 0x0c, 0x73, 0xc8, 0x00, 0x91, 0x91, 0x15, 0xd0, 0x7c, 0x02, 0x07, 0x99, 0xac, 0x35, 0xaf, 0xf5, - 0x4a, 0x3b, 0x62, 0x88, 0xc4, 0x7e, 0xab, 0x22, 0x76, 0x02, 0x23, 0xd6, 0x34, 0x0e, 0x18, 0x21, - 0x30, 0x64, 0x4d, 0x83, 0xd6, 0x19, 0xfc, 0x87, 0x89, 0x28, 0xae, 0x57, 0x4b, 0xe3, 0x83, 0xec, - 0x22, 0x73, 0x68, 0x0d, 0xea, 0x74, 0x64, 0x9f, 0xc1, 0xa4, 0x51, 0xb2, 0x91, 0x9a, 0xab, 0x39, - 0xcb, 0x73, 0xc5, 0xb5, 0x0e, 0xc1, 0xa1, 0x1b, 0xfd, 0xad, 0x93, 0x2d, 0xca, 0x8a, 0x42, 0xf1, - 0x82, 0x19, 0xa9, 0x7c, 0xd4, 0x3d, 0x87, 0x76, 0xf4, 0x4d, 0x72, 0x59, 0xc9, 0x44, 0x3d, 0x17, - 0x79, 0x38, 0x9e, 0x06, 0xc9, 0x2e, 0x1d, 0xe2, 0xfe, 0x43, 0x1e, 0x27, 0x30, 0x70, 0x5f, 0x82, - 0x44, 0x00, 0x5a, 0x14, 0x35, 0x33, 0x2b, 0xc5, 0x75, 0xd8, 0x9b, 0xf6, 0x92, 0x31, 0xed, 0x28, - 0xf1, 0x67, 0x18, 0x5f, 0x8b, 0xa2, 0xe6, 0xb9, 0xef, 0xf0, 0x53, 0xdb, 0x35, 0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09, 0x4e, 0xec, 0xf1, 0x03, 0x00, 0x00, + // 591 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x97, 0xb5, 0x6b, 0xbb, 0xb7, 0x6e, 0xeb, 0x0c, 0x9b, 0x32, 0x26, 0x45, 0xa5, 0x12, + 0xa2, 0x0c, 0x29, 0x15, 0x43, 0x48, 0x70, 0x64, 0x30, 0x69, 0x88, 0x0b, 0xca, 0x24, 0x0e, 0x5c, + 0x8a, 0x9b, 0x3c, 0x25, 0xd6, 0xda, 0x38, 0xb2, 0xdd, 0x89, 0x7d, 0x04, 0x6e, 0x7c, 0x2c, 0x8e, + 0x3b, 0x72, 0x9c, 0xb6, 0x2f, 0x82, 0xfc, 0xec, 0x66, 0x81, 0x4b, 0x6b, 0xff, 0xff, 0x3f, 0x3f, + 0xbf, 0x17, 0xbf, 0x07, 0xfb, 0x4a, 0xce, 0xe7, 0x97, 0xc2, 0x4c, 0xfc, 0x7f, 0x5c, 0x29, 0x69, + 0x24, 0xeb, 0xfa, 0xed, 0x93, 0x23, 0x83, 0x65, 0x86, 0x6a, 0x21, 0x4a, 0x33, 0xe1, 0xb3, 0x54, + 0x4c, 0xcc, 0x75, 0x85, 0xda, 0x51, 0xa3, 0x57, 0xd0, 0xfd, 0x8a, 0x4a, 0x0b, 0x59, 0xb2, 0xc7, + 0xb0, 0x31, 0x9b, 0xcb, 0xf4, 0x32, 0x0c, 0x86, 0xc1, 0xb8, 0x9d, 0xb8, 0x0d, 0x1b, 0x40, 0x8b, + 0x57, 0x55, 0xb8, 0x4e, 0x9a, 0x5d, 0x8e, 0x6e, 0x5b, 0xd0, 0x39, 0x47, 0x9e, 0xa1, 0x62, 0xc7, + 0xd0, 0xbd, 0x72, 0xa7, 0xe9, 0xd0, 0xd6, 0xc9, 0x20, 0x5e, 0x25, 0xe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x05, 0xb7, 0x77, 0x51, 0xf0, 0xeb, 0x3e, + 0x5a, 0xbb, 0xb9, 0x8f, 0xd6, 0xfe, 0xdc, 0x47, 0x6b, 0xdf, 0x5e, 0xe6, 0xc2, 0x14, 0xcb, 0x59, + 0x9c, 0xca, 0xc5, 0xe4, 0xbf, 0xb1, 0x77, 0x63, 0x3d, 0xa9, 0x66, 0x2b, 0x61, 0xd6, 0xa1, 0x11, + 0x7f, 0xfd, 0x37, 0x00, 0x00, 0xff, 0xff, 0x6a, 0x00, 0x18, 0xcf, 0x21, 0x04, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -546,13 +556,20 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.ChainId) i = encodeVarintRollkit(dAtA, i, uint64(len(m.ChainId))) i-- - dAtA[i] = 0x62 + dAtA[i] = 0x6a } if len(m.AggregatorsHash) > 0 { i -= len(m.AggregatorsHash) copy(dAtA[i:], m.AggregatorsHash) i = encodeVarintRollkit(dAtA, i, uint64(len(m.AggregatorsHash))) i-- + dAtA[i] = 0x62 + } + if len(m.ProposerPublicKey) > 0 { + i -= len(m.ProposerPublicKey) + copy(dAtA[i:], m.ProposerPublicKey) + i = encodeVarintRollkit(dAtA, i, uint64(len(m.ProposerPublicKey))) + i-- dAtA[i] = 0x5a } if len(m.ProposerAddress) > 0 { @@ -880,6 +897,10 @@ func (m *Header) Size() (n int) { if l > 0 { n += 1 + l + sovRollkit(uint64(l)) } + l = len(m.ProposerPublicKey) + if l > 0 { + n += 1 + l + sovRollkit(uint64(l)) + } l = len(m.AggregatorsHash) if l > 0 { n += 1 + l + sovRollkit(uint64(l)) @@ -1403,6 +1424,40 @@ func (m *Header) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProposerPublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRollkit + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthRollkit + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthRollkit + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProposerPublicKey = append(m.ProposerPublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.ProposerPublicKey == nil { + m.ProposerPublicKey = []byte{} + } + iNdEx = postIndex + case 12: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AggregatorsHash", wireType) } @@ -1436,7 +1491,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { m.AggregatorsHash = []byte{} } iNdEx = postIndex - case 12: + case 13: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ChainId", wireType) } From 8e098e363ebac202a0dfeeb6454ff88a3c80ea41 Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Mon, 13 Mar 2023 15:45:05 -0700 Subject: [PATCH 5/9] minor fix to rollkit.proto --- proto/rollkit/rollkit.proto | 2 +- types/pb/rollkit/rollkit.pb.go | 76 +++++++++++++++++----------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index ecd45ce031..4413dba090 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -61,7 +61,7 @@ message Header { } message Commit { - repeated bytes signatures = 3; + repeated bytes signatures = 1; } message SignedHeader { diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index 60fcbc624b..f5bcd52813 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -239,7 +239,7 @@ func (m *Header) GetChainId() string { } type Commit struct { - Signatures [][]byte `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` + Signatures [][]byte `protobuf:"bytes,1,rep,name=signatures,proto3" json:"signatures,omitempty"` } func (m *Commit) Reset() { *m = Commit{} } @@ -461,41 +461,41 @@ var fileDescriptor_ed489fb7f4d78b3f = []byte{ // 591 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0x41, 0x6f, 0xd3, 0x30, 0x14, 0xc7, 0x97, 0xb5, 0x6b, 0xbb, 0xb7, 0x6e, 0xeb, 0x0c, 0x9b, 0x32, 0x26, 0x45, 0xa5, 0x12, - 0xa2, 0x0c, 0x29, 0x15, 0x43, 0x48, 0x70, 0x64, 0x30, 0x69, 0x88, 0x0b, 0xca, 0x24, 0x0e, 0x5c, - 0x8a, 0x9b, 0x3c, 0x25, 0xd6, 0xda, 0x38, 0xb2, 0xdd, 0x89, 0x7d, 0x04, 0x6e, 0x7c, 0x2c, 0x8e, - 0x3b, 0x72, 0x9c, 0xb6, 0x2f, 0x82, 0xfc, 0xec, 0x66, 0x81, 0x4b, 0x6b, 0xff, 0xff, 0x3f, 0x3f, - 0xbf, 0x17, 0xbf, 0x07, 0xfb, 0x4a, 0xce, 0xe7, 0x97, 0xc2, 0x4c, 0xfc, 0x7f, 0x5c, 0x29, 0x69, - 0x24, 0xeb, 0xfa, 0xed, 0x93, 0x23, 0x83, 0x65, 0x86, 0x6a, 0x21, 0x4a, 0x33, 0xe1, 0xb3, 0x54, - 0x4c, 0xcc, 0x75, 0x85, 0xda, 0x51, 0xa3, 0x57, 0xd0, 0xfd, 0x8a, 0x4a, 0x0b, 0x59, 0xb2, 0xc7, - 0xb0, 0x31, 0x9b, 0xcb, 0xf4, 0x32, 0x0c, 0x86, 0xc1, 0xb8, 0x9d, 0xb8, 0x0d, 0x1b, 0x40, 0x8b, - 0x57, 0x55, 0xb8, 0x4e, 0x9a, 0x5d, 0x8e, 0x6e, 0x5b, 0xd0, 0x39, 0x47, 0x9e, 0xa1,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d, 0x07, 0x25, 0x4f, 0xa1, 0x6b, 0xdb, 0xce, 0x97, 0xbd, 0xdd, 0x1c, 0xb1, 0x35, 0xa6, 0x68, + 0x9d, 0x9e, 0xfd, 0xbe, 0x8b, 0x82, 0x9b, 0xbb, 0x28, 0xb8, 0xbd, 0x8b, 0x82, 0x5f, 0xf7, 0xd1, + 0xda, 0xcd, 0x7d, 0xb4, 0xf6, 0xe7, 0x3e, 0x5a, 0xfb, 0xf6, 0xb2, 0xe0, 0xa6, 0x5c, 0xcd, 0x93, + 0x4c, 0x2c, 0xa7, 0xff, 0x8d, 0xbd, 0x1b, 0xeb, 0xa9, 0x9c, 0xd7, 0xc2, 0xbc, 0x87, 0x23, 0xfe, + 0xfa, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x60, 0x78, 0xc4, 0x21, 0x04, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -672,7 +672,7 @@ func (m *Commit) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Signatures[iNdEx]) i = encodeVarintRollkit(dAtA, i, uint64(len(m.Signatures[iNdEx]))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0xa } } return len(dAtA) - i, nil @@ -1573,7 +1573,7 @@ func (m *Commit) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Commit: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 3: + case 1: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) } From c515036fa1ee4b4abac1eb3ad38b6a4c6e6111fc Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Mon, 13 Mar 2023 20:50:04 -0700 Subject: [PATCH 6/9] fix commit deserialization issue and add current commit to block --- block/manager.go | 3 +++ types/serialization.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/block/manager.go b/block/manager.go index 958e686700..65cfe98444 100644 --- a/block/manager.go +++ b/block/manager.go @@ -536,6 +536,9 @@ func (m *Manager) publishBlock(ctx context.Context) error { return err } + // set the commit to current block's signed header + block.SignedHeader.Commit = *commit + // SaveBlock commits the DB tx err = m.store.SaveBlock(block, commit) if err != nil { diff --git a/types/serialization.go b/types/serialization.go index f5c2d9d547..7b2d891f34 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -78,6 +78,8 @@ func (h *SignedHeader) FromProto(other *pb.SignedHeader) error { if err != nil { return err } + h.Commit.HeaderHash = h.Header.Hash() + h.Commit.Height = uint64(h.Header.Height()) return nil } From 618789c4de673bc2e72cc30a1bf682af29e3378d Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Mon, 13 Mar 2023 21:26:18 -0700 Subject: [PATCH 7/9] add height and hash to commit during deserialization only for non-nil commit case --- types/serialization.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/types/serialization.go b/types/serialization.go index 7b2d891f34..e49bb7e4b1 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -78,8 +78,12 @@ func (h *SignedHeader) FromProto(other *pb.SignedHeader) error { if err != nil { return err } - h.Commit.HeaderHash = h.Header.Hash() - h.Commit.Height = uint64(h.Header.Height()) + + if len(h.Commit.Signatures) > 0 { + h.Commit.HeaderHash = h.Header.Hash() + h.Commit.Height = uint64(h.Header.Height()) + } + return nil } From b1840ca325b79e4910842da7d02d9f2ecdf83b2a Mon Sep 17 00:00:00 2001 From: Ganesha Upadhyaya Date: Mon, 13 Mar 2023 21:44:44 -0700 Subject: [PATCH 8/9] fix the serialization test --- types/serialization_test.go | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/types/serialization_test.go b/types/serialization_test.go index 5443255266..8274b2db18 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -32,6 +32,25 @@ func TestBlockSerializationRoundTrip(t *testing.T) { h = append(h, h1) } + h1 := Header{ + Version: Version{ + Block: 1, + App: 2, + }, + BaseHeader: BaseHeader{ + Height: 3, + Time: 4567, + }, + LastHeaderHash: h[0], + LastCommitHash: h[1], + DataHash: h[2], + ConsensusHash: h[3], + AppHash: h[4], + LastResultsHash: h[5], + ProposerAddress: []byte{4, 3, 2, 1}, + AggregatorsHash: h[6], + } + cases := []struct { name string input *Block @@ -39,25 +58,10 @@ func TestBlockSerializationRoundTrip(t *testing.T) { {"empty block", &Block{}}, {"full", &Block{ SignedHeader: SignedHeader{ - Header: Header{ - Version: Version{ - Block: 1, - App: 2, - }, - BaseHeader: BaseHeader{ - Height: 3, - Time: 4567, - }, - LastHeaderHash: h[0], - LastCommitHash: h[1], - DataHash: h[2], - ConsensusHash: h[3], - AppHash: h[4], - LastResultsHash: h[5], - ProposerAddress: []byte{4, 3, 2, 1}, - AggregatorsHash: h[6], - }, + Header: h1, Commit: Commit{ + Height: 3, + HeaderHash: h1.Hash(), Signatures: []Signature{Signature([]byte{1, 1, 1}), Signature([]byte{2, 2, 2})}, }}, Data: Data{ From 172372e5c02fcb918d63f6d88c9023fcfe4bfee1 Mon Sep 17 00:00:00 2001 From: nashqueue Date: Wed, 15 Mar 2023 18:19:18 +0100 Subject: [PATCH 9/9] javed nits --- proto/rollkit/rollkit.proto | 4 +- types/pb/rollkit/rollkit.pb.go | 81 +++++++++++++++++----------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index 4413dba090..f959c39543 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -49,7 +49,7 @@ message Header { // pubkey can't be recovered by the signature (e.g. ed25519). bytes proposer_address = 10; - //public key of the proposer so we can verify the signature + // public key of the proposer so we can verify the signature bytes proposer_public_key = 11; @@ -76,6 +76,6 @@ message Data { } message Block { - SignedHeader signedHeader = 1; + SignedHeader signed_header = 1; Data data = 2; } diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index f5bcd52813..41d5f29602 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -106,7 +106,7 @@ type Header struct { // We keep this in case users choose another signature format where the // pubkey can't be recovered by the signature (e.g. ed25519). ProposerAddress []byte `protobuf:"bytes,10,opt,name=proposer_address,json=proposerAddress,proto3" json:"proposer_address,omitempty"` - //public key of the proposer so we can verify the signature + // public key of the proposer so we can verify the signature ProposerPublicKey []byte `protobuf:"bytes,11,opt,name=proposer_public_key,json=proposerPublicKey,proto3" json:"proposer_public_key,omitempty"` // Hash of block aggregator set, at a time of block creation AggregatorsHash []byte `protobuf:"bytes,12,opt,name=aggregators_hash,json=aggregatorsHash,proto3" json:"aggregators_hash,omitempty"` @@ -395,7 +395,7 @@ func (m *Data) GetEvidence() []*types.Evidence { } type Block struct { - SignedHeader *SignedHeader `protobuf:"bytes,1,opt,name=signedHeader,proto3" json:"signedHeader,omitempty"` + SignedHeader *SignedHeader `protobuf:"bytes,1,opt,name=signed_header,json=signedHeader,proto3" json:"signed_header,omitempty"` Data *Data `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` } @@ -458,44 +458,45 @@ func init() { func init() { proto.RegisterFile("rollkit/rollkit.proto", fileDescriptor_ed489fb7f4d78b3f) } var fileDescriptor_ed489fb7f4d78b3f = []byte{ - // 591 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x97, 0xb5, 0x6b, 0xbb, 0xb7, 0x6e, 0xeb, 0x0c, 0x9b, 0x32, 0x26, 0x45, 0xa5, 0x12, - 0x22, 0x0c, 0x29, 0x15, 0x43, 0x48, 0x70, 0x64, 0x30, 0x69, 0x88, 0x0b, 0xca, 0x24, 0x0e, 0x5c, - 0x8a, 0x9b, 0x58, 0x89, 0xb5, 0x36, 0xb6, 0x6c, 0x77, 0x62, 0x1f, 0x81, 0x1b, 0x1f, 0x8b, 0xe3, - 0x8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43, 0x6d, - 0x27, 0x9a, 0x1f, 0x75, 0x0e, 0x76, 0x49, 0xde, 0x42, 0xc8, 0x2b, 0xc3, 0xd4, 0x92, 0xe5, 0x9c, - 0x1a, 0x36, 0xd3, 0xc6, 0xfe, 0x2a, 0x21, 0x8c, 0x0e, 0xd7, 0x11, 0x3b, 0x68, 0xfb, 0x17, 0xd6, - 0x4e, 0xad, 0x4b, 0xde, 0xc0, 0x80, 0x5d, 0xf1, 0x9c, 0x55, 0x99, 0x6d, 0xbc, 0x4e, 0xbc, 0x75, - 0x72, 0x98, 0x3c, 0x8c, 0x49, 0x62, 0xc7, 0x24, 0x39, 0xf3, 0x40, 0xda, 0xa0, 0x13, 0x06, 0x1b, - 0xa7, 0x38, 0x15, 0xef, 0x60, 0xa8, 0x5b, 0x65, 0xfb, 0x62, 0xf7, 0x9b, 0x1a, 0xda, 0xdf, 0x24, - 0xfd, 0x07, 0x25, 0x4f, 0xa1, 0x6b, 0xdb, 0xce, 0x97, 0xbd, 0xdd, 0x1c, 0xb1, 0x35, 0xa6, 0x68, - 0x9d, 0x9e, 0xfd, 0xbe, 0x8b, 0x82, 0x9b, 0xbb, 0x28, 0xb8, 0xbd, 0x8b, 0x82, 0x5f, 0xf7, 0xd1, - 0xda, 0xcd, 0x7d, 0xb4, 0xf6, 0xe7, 0x3e, 0x5a, 0xfb, 0xf6, 0xb2, 0xe0, 0xa6, 0x5c, 0xcd, 0x93, - 0x4c, 0x2c, 0xa7, 0xff, 0x8d, 0xbd, 0x1b, 0xeb, 0xa9, 0x9c, 0xd7, 0xc2, 0xbc, 0x87, 0x23, 0xfe, - 0xfa, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x60, 0x78, 0xc4, 0x21, 0x04, 0x00, 0x00, + // 595 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0xc1, 0x6f, 0xd3, 0x3e, + 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ae, 0xfd, 0x08, 0xc6, 0x0b, 0xa2, 0x74, 0x5a, 0xe2, 0x35, 0x69, + 0x49, 0x54, 0x19, 0x74, 0x27, 0x5e, 0x34, 0x4c, 0x76, 0x8d, 0x6e, 0x6f, 0xbf, 0x20, 0xaa, 0x6c, + 0xc8, 0x8c, 0x2f, 0x97, 0x4c, 0x5b, 0x72, 0xeb, 0x81, 0x7c, 0x87, 0x32, 0x92, 0xc7, 0xb0, 0x9d, + 0x13, 0x4d, 0x2c, 0xd2, 0x43, 0x64, 0x60, 0x04, 0x34, 0x9f, 0xc0, 0x6e, 0xc6, 0x2b, 0x45, 0x2b, + 0xb5, 0x52, 0x96, 0xe8, 0x23, 0x31, 0x6a, 0x54, 0xc4, 0x8e, 0x60, 0x40, 0x84, 0xb0, 0xc0, 0x00, + 0x81, 0x3e, 0x11, 0x02, 0xad, 0x13, 0xd8, 0xc7, 0x44, 0x24, 0x55, 0xab, 0x85, 0x76, 0x41, 0xb6, + 0x91, 0xd9, 0x33, 0x46, 0x62, 0x75, 0x64, 0x9f, 0xc1, 0x58, 0x48, 0x2e, 0xb8, 0xa2, 0x32, 0x25, + 0x79, 0x2e, 0xa9, 0x52, 0x01, 0x58, 0xb4, 0xd6, 0xdf, 0x5a, 0xd9, 0x8f, 0xe1, 0xbf, 0x06, 0x15, + 0xab, 0xf9, 0x82, 0x65, 0xe9, 0x15, 0xbd, 0x09, 0x76, 0x90, 0xde, 0xaf, 0xad, 0x4f, 0xe8, 0x7c, + 0xa4, 0x37, 0x26, 0x34, 0x29, 0x0a, 0x49, 0x0b, 0xa2, 0xb9, 0x74, 0x59, 0x0c, 0x6d, 0xe8, 0x96, + 0x5e, 0x17, 0x93, 0x95, 0x84, 0x55, 0x29, 0xcb, 0x83, 0xd1, 0xc4, 0x8b, 0xb6, 0x93, 0x3e, 0xee, + 0x3f, 0xe4, 0xd3, 0x08, 0x7a, 0xf6, 0xe5, 0xfc, 0x10, 0x40, 0xb1, 0xa2, 0x22, 0x7a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xe6, 0x71, 0xc6, 0x97, 0xb3, 0x7f, 0xe6, 0xde, 0xce, 0xf5, 0x4c, 0xcc, 0x6b, + 0x61, 0xde, 0xc3, 0x19, 0x7f, 0xf9, 0x27, 0x00, 0x00, 0xff, 0xff, 0x4a, 0x6d, 0x58, 0xf2, 0x22, + 0x04, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) {