Skip to content

Commit 59e574e

Browse files
refactor: remove commit type (#1739)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview Resolves #783 Resolves #1050 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Replaced the usage of `Commit` with `Signature` across various components, affecting block creation, saving, and retrieval processes. - Renamed functions and variables to reflect the change from `Commit` to `Signature`. - **Bug Fixes** - Updated serialization and deserialization methods to ensure compatibility with the new `Signature` structure. - **Documentation** - Revised documentation to reflect the changes from `Commit` to `Signature` in block and header handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2dc1e35 commit 59e574e

25 files changed

+233
-562
lines changed

block/manager.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error {
526526
// if call to applyBlock fails, we halt the node, see https://github.com/cometbft/cometbft/pull/496
527527
panic(fmt.Errorf("failed to ApplyBlock: %w", err))
528528
}
529-
err = m.store.SaveBlock(ctx, b, &b.SignedHeader.Commit)
529+
err = m.store.SaveBlock(ctx, b, &b.SignedHeader.Signature)
530530
if err != nil {
531531
return fmt.Errorf("failed to save block: %w", err)
532532
}
@@ -738,16 +738,15 @@ func getRemainingSleep(start time.Time, interval, defaultSleep time.Duration) ti
738738
return sleepDuration
739739
}
740740

741-
func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
741+
func (m *Manager) getSignature(header types.Header) (*types.Signature, error) {
742742
// note: for compatibility with tendermint light client
743743
consensusVote := header.MakeCometBFTVote()
744744
sign, err := m.sign(consensusVote)
745745
if err != nil {
746746
return nil, err
747747
}
748-
return &types.Commit{
749-
Signatures: []types.Signature{sign},
750-
}, nil
748+
signature := types.Signature(sign)
749+
return &signature, nil
751750
}
752751

753752
func (m *Manager) publishBlock(ctx context.Context) error {
@@ -766,17 +765,17 @@ func (m *Manager) publishBlock(ctx context.Context) error {
766765
}
767766

768767
var (
769-
lastCommit *types.Commit
768+
lastSignature *types.Signature
770769
lastHeaderHash types.Hash
771770
err error
772771
)
773772
height := m.store.Height()
774773
newHeight := height + 1
775774
// this is a special case, when first block is produced - there is no previous commit
776775
if newHeight == uint64(m.genesis.InitialHeight) {
777-
lastCommit = &types.Commit{}
776+
lastSignature = &types.Signature{}
778777
} else {
779-
lastCommit, err = m.store.GetCommit(ctx, height)
778+
lastSignature, err = m.store.GetSignature(ctx, height)
780779
if err != nil {
781780
return fmt.Errorf("error while loading last commit: %w", err)
782781
}
@@ -788,7 +787,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
788787
}
789788

790789
var block *types.Block
791-
var commit *types.Commit
790+
var signature *types.Signature
792791

793792
// Check if there's an already stored block at a newer height
794793
// If there is use that instead of creating a new block
@@ -802,14 +801,14 @@ func (m *Manager) publishBlock(ctx context.Context) error {
802801
if err != nil {
803802
return fmt.Errorf("failed to load extended commit for height %d: %w", height, err)
804803
}
805-
block, err = m.createBlock(newHeight, lastCommit, lastHeaderHash, extendedCommit)
804+
block, err = m.createBlock(newHeight, lastSignature, lastHeaderHash, extendedCommit)
806805
if err != nil {
807806
return err
808807
}
809808
m.logger.Debug("block info", "num_tx", len(block.Data.Txs))
810809

811810
/*
812-
here we set the SignedHeader.DataHash, and SignedHeader.Commit as a hack
811+
here we set the SignedHeader.DataHash, and SignedHeader.Signature as a hack
813812
to make the block pass ValidateBasic() when it gets called by applyBlock on line 681
814813
these values get overridden on lines 687-698 after we obtain the IntermediateStateRoots.
815814
*/
@@ -821,14 +820,14 @@ func (m *Manager) publishBlock(ctx context.Context) error {
821820
block.SignedHeader.Validators = m.getLastStateValidators()
822821
block.SignedHeader.ValidatorHash = block.SignedHeader.Validators.Hash()
823822

824-
commit, err = m.getCommit(block.SignedHeader.Header)
823+
signature, err = m.getSignature(block.SignedHeader.Header)
825824
if err != nil {
826825
return err
827826
}
828827

829-
// set the commit to current block's signed header
830-
block.SignedHeader.Commit = *commit
831-
err = m.store.SaveBlock(ctx, block, commit)
828+
// set the signature to current block's signed header
829+
block.SignedHeader.Signature = *signature
830+
err = m.store.SaveBlock(ctx, block, signature)
832831
if err != nil {
833832
return err
834833
}
@@ -848,7 +847,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
848847
return err
849848
}
850849

851-
commit, err = m.getCommit(block.SignedHeader.Header)
850+
signature, err = m.getSignature(block.SignedHeader.Header)
852851
if err != nil {
853852
return err
854853
}
@@ -857,8 +856,8 @@ func (m *Manager) publishBlock(ctx context.Context) error {
857856
return err
858857
}
859858

860-
// set the commit to current block's signed header
861-
block.SignedHeader.Commit = *commit
859+
// set the signature to current block's signed header
860+
block.SignedHeader.Signature = *signature
862861
// Validate the created block before storing
863862
if err := m.executor.Validate(m.lastState, block); err != nil {
864863
return fmt.Errorf("failed to validate block: %w", err)
@@ -872,7 +871,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
872871
m.blockCache.setSeen(blockHash)
873872

874873
// SaveBlock commits the DB tx
875-
err = m.store.SaveBlock(ctx, block, commit)
874+
err = m.store.SaveBlock(ctx, block, signature)
876875
if err != nil {
877876
return err
878877
}
@@ -1144,10 +1143,10 @@ func (m *Manager) getLastBlockTime() time.Time {
11441143
return m.lastState.LastBlockTime
11451144
}
11461145

1147-
func (m *Manager) createBlock(height uint64, lastCommit *types.Commit, lastHeaderHash types.Hash, extendedCommit abci.ExtendedCommitInfo) (*types.Block, error) {
1146+
func (m *Manager) createBlock(height uint64, lastSignature *types.Signature, lastHeaderHash types.Hash, extendedCommit abci.ExtendedCommitInfo) (*types.Block, error) {
11481147
m.lastStateMtx.RLock()
11491148
defer m.lastStateMtx.RUnlock()
1150-
return m.executor.CreateBlock(height, lastCommit, extendedCommit, lastHeaderHash, m.lastState)
1149+
return m.executor.CreateBlock(height, lastSignature, extendedCommit, lastHeaderHash, m.lastState)
11511150
}
11521151

11531152
func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.State, *abci.ResponseFinalizeBlock, error) {

block/manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ func TestSignVerifySignature(t *testing.T) {
147147
signingKey, err := types.PrivKeyToSigningKey(c.input)
148148
require.NoError(err)
149149
m.proposerKey = signingKey
150-
sig, err := m.sign(payload)
150+
signature, err := m.sign(payload)
151151
require.NoError(err)
152-
ok := pubKey.VerifySignature(payload, sig)
152+
ok := pubKey.VerifySignature(payload, signature)
153153
require.True(ok)
154154
})
155155
}
@@ -211,7 +211,7 @@ func TestSubmitBlocksToMockDA(t *testing.T) {
211211
blob, err := block.MarshalBinary()
212212
require.NoError(t, err)
213213

214-
err = m.store.SaveBlock(ctx, block, &types.Commit{})
214+
err = m.store.SaveBlock(ctx, block, &types.Signature{})
215215
require.NoError(t, err)
216216
m.store.SetHeight(ctx, 1)
217217

@@ -327,7 +327,7 @@ func TestSubmitBlocksToDA(t *testing.T) {
327327
t.Run(tc.name, func(t *testing.T) {
328328
// PendingBlocks depend on store, so blocks needs to be saved and height updated
329329
for _, block := range tc.blocks {
330-
require.NoError(m.store.SaveBlock(ctx, block, &types.Commit{}))
330+
require.NoError(m.store.SaveBlock(ctx, block, &types.Signature{}))
331331
}
332332
m.store.SetHeight(ctx, uint64(len(tc.blocks)))
333333

block/pending_blocks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func newPendingBlocks(t *testing.T) *PendingBlocks {
8787

8888
func fillWithBlocks(ctx context.Context, t *testing.T, pb *PendingBlocks) {
8989
for i := uint64(1); i <= numBlocks; i++ {
90-
require.NoError(t, pb.store.SaveBlock(ctx, types.GetRandomBlock(i, 0), &types.Commit{}))
90+
require.NoError(t, pb.store.SaveBlock(ctx, types.GetRandomBlock(i, 0), &types.Signature{}))
9191
pb.store.SetHeight(ctx, i)
9292
}
9393
}

node/full_client.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,6 @@ func (c *FullClient) BlockResults(ctx context.Context, height *int64) (*ctypes.R
488488
// Commit returns signed header (aka commit) at given height.
489489
func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
490490
heightValue := c.normalizeHeight(height)
491-
com, err := c.node.Store.GetCommit(ctx, heightValue)
492-
if err != nil {
493-
return nil, err
494-
}
495491
b, err := c.node.Store.GetBlock(ctx, heightValue)
496492
if err != nil {
497493
return nil, err
@@ -503,7 +499,7 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC
503499
}
504500

505501
val := b.SignedHeader.Validators.Validators[0].Address
506-
commit := com.ToABCICommit(heightValue, b.Hash(), val, b.SignedHeader.Time())
502+
commit := types.GetABCICommit(heightValue, b.Hash(), val, b.SignedHeader.Time(), b.SignedHeader.Signature)
507503

508504
block, err := abciconv.ToABCIBlock(b)
509505
if err != nil {

node/full_client_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func TestGetBlock(t *testing.T) {
315315
startNodeWithCleanup(t, rpc.node)
316316
ctx := context.Background()
317317
block := types.GetRandomBlock(1, 10)
318-
err := rpc.node.Store.SaveBlock(ctx, block, &types.Commit{})
318+
err := rpc.node.Store.SaveBlock(ctx, block, &types.Signature{})
319319
rpc.node.Store.SetHeight(ctx, block.Height())
320320
require.NoError(err)
321321

@@ -338,7 +338,7 @@ func TestGetCommit(t *testing.T) {
338338
startNodeWithCleanup(t, rpc.node)
339339
ctx := context.Background()
340340
for _, b := range blocks {
341-
err := rpc.node.Store.SaveBlock(ctx, b, &types.Commit{})
341+
err := rpc.node.Store.SaveBlock(ctx, b, &types.Signature{})
342342
rpc.node.Store.SetHeight(ctx, b.Height())
343343
require.NoError(err)
344344
}
@@ -383,7 +383,7 @@ func TestCometBFTLightClientCompability(t *testing.T) {
383383

384384
// save the 3 blocks
385385
for _, b := range blocks {
386-
err := rpc.node.Store.SaveBlock(ctx, b, &b.SignedHeader.Commit) // #nosec G601
386+
err := rpc.node.Store.SaveBlock(ctx, b, &b.SignedHeader.Signature) // #nosec G601
387387
rpc.node.Store.SetHeight(ctx, b.Height())
388388
require.NoError(err)
389389
}
@@ -438,7 +438,7 @@ func TestBlockSearch(t *testing.T) {
438438
heights := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
439439
for _, h := range heights {
440440
block := types.GetRandomBlock(uint64(h), 5)
441-
err := rpc.node.Store.SaveBlock(ctx, block, &types.Commit{})
441+
err := rpc.node.Store.SaveBlock(ctx, block, &types.Signature{})
442442
require.NoError(err)
443443
}
444444
indexBlocks(t, rpc, heights)
@@ -497,7 +497,7 @@ func TestGetBlockByHash(t *testing.T) {
497497
startNodeWithCleanup(t, rpc.node)
498498
ctx := context.Background()
499499
block := types.GetRandomBlock(1, 10)
500-
err := rpc.node.Store.SaveBlock(ctx, block, &types.Commit{})
500+
err := rpc.node.Store.SaveBlock(ctx, block, &types.Signature{})
501501
require.NoError(err)
502502
abciBlock, err := abciconv.ToABCIBlock(block)
503503
require.NoError(err)
@@ -695,7 +695,7 @@ func TestBlockchainInfo(t *testing.T) {
695695
heights := []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
696696
for _, h := range heights {
697697
block := types.GetRandomBlock(uint64(h), 5)
698-
err := rpc.node.Store.SaveBlock(ctx, block, &types.Commit{})
698+
err := rpc.node.Store.SaveBlock(ctx, block, &types.Signature{})
699699
rpc.node.Store.SetHeight(ctx, block.Height())
700700
require.NoError(err)
701701
}
@@ -917,7 +917,7 @@ func TestStatus(t *testing.T) {
917917
ProposerAddr: pubKey.Bytes(),
918918
}
919919
earliestBlock, _ := types.GenerateRandomBlockCustom(&config)
920-
err = rpc.node.Store.SaveBlock(ctx, earliestBlock, &types.Commit{})
920+
err = rpc.node.Store.SaveBlock(ctx, earliestBlock, &types.Signature{})
921921
rpc.node.Store.SetHeight(ctx, earliestBlock.Height())
922922
require.NoError(err)
923923

@@ -927,7 +927,7 @@ func TestStatus(t *testing.T) {
927927
ProposerAddr: pubKey.Bytes(),
928928
}
929929
latestBlock, _ := types.GenerateRandomBlockCustom(&config)
930-
err = rpc.node.Store.SaveBlock(ctx, latestBlock, &types.Commit{})
930+
err = rpc.node.Store.SaveBlock(ctx, latestBlock, &types.Signature{})
931931
rpc.node.Store.SetHeight(ctx, latestBlock.Height())
932932
require.NoError(err)
933933

node/full_node_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ func TestInvalidBlocksIgnored(t *testing.T) {
146146
junkProposerBlock.SignedHeader.ProposerAddress = types.GetRandomBytes(32)
147147

148148
// Recompute signature over the block with the invalid proposer address
149-
commit, err := types.GetCommit(junkProposerBlock.SignedHeader.Header, signingKey)
149+
signature, err := types.GetSignature(junkProposerBlock.SignedHeader.Header, signingKey)
150150
require.NoError(t, err)
151-
junkProposerBlock.SignedHeader.Commit = *commit
151+
junkProposerBlock.SignedHeader.Signature = *signature
152152
require.ErrorIs(t, junkProposerBlock.ValidateBasic(), types.ErrProposerAddressMismatch)
153153

154154
// Create a block with an invalid commit
155155
junkCommitBlock := *b1
156-
junkCommitBlock.SignedHeader.Commit.Signatures = []types.Signature{types.GetRandomBytes(32)}
156+
junkCommitBlock.SignedHeader.Signature = types.GetRandomBytes(32)
157157
require.ErrorIs(t, junkCommitBlock.ValidateBasic(), types.ErrSignatureVerificationFailed)
158158

159159
// Validate b1 to make sure it's still valid

proto/rollkit/rollkit.proto

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,9 @@ message Header {
5858
string chain_id = 12;
5959
}
6060

61-
message Commit {
62-
repeated bytes signatures = 1;
63-
}
64-
6561
message SignedHeader {
6662
Header header = 1;
67-
Commit commit = 2;
63+
bytes signature = 2;
6864
tendermint.types.ValidatorSet validators = 3;
6965
}
7066

state/block-executor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The `BlockExecutor` is initialized with a proposer address, `namespace ID`, `cha
2222
- Initial Validator Set using genesis validators
2323
- Initial Height
2424

25-
- `CreateBlock`: This method reaps transactions from the mempool and builds a block. It takes the state, the height of the block, last header hash, and the commit as parameters.
25+
- `CreateBlock`: This method reaps transactions from the mempool and builds a block. It takes the state, the height of the block, last header hash, and the signature as parameters.
2626

2727
- `ApplyBlock`: This method applies the block to the state. Given the current state and block to be applied, it:
2828
- Validates the block, as described in `Validate`.

state/executor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (e *BlockExecutor) InitChain(genesis *cmtypes.GenesisDoc) (*abci.ResponseIn
9393
}
9494

9595
// CreateBlock reaps transactions from mempool and builds a block.
96-
func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, lastExtendedCommit abci.ExtendedCommitInfo, lastHeaderHash types.Hash, state types.State) (*types.Block, error) {
96+
func (e *BlockExecutor) CreateBlock(height uint64, lastSignature *types.Signature, lastExtendedCommit abci.ExtendedCommitInfo, lastHeaderHash types.Hash, state types.State) (*types.Block, error) {
9797
maxBytes := state.ConsensusParams.Block.MaxBytes
9898
emptyMaxBytes := maxBytes == -1
9999
if emptyMaxBytes {
@@ -128,7 +128,7 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las
128128
LastResultsHash: state.LastResultsHash,
129129
ProposerAddress: e.proposerAddress,
130130
},
131-
Commit: *lastCommit,
131+
Signature: *lastSignature,
132132
},
133133
Data: types.Data{
134134
Txs: toRollkitTxs(mempoolTxs),
@@ -169,7 +169,8 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las
169169
}
170170

171171
block.Data.Txs = toRollkitTxs(txl)
172-
block.SignedHeader.LastCommitHash = lastCommit.GetCommitHash(&block.SignedHeader.Header, e.proposerAddress)
172+
// Note: This is hash of an ABCI type commit equivalent of the last signature in the signed header.
173+
block.SignedHeader.LastCommitHash = lastSignature.GetCommitHash(&block.SignedHeader.Header, e.proposerAddress)
173174
block.SignedHeader.LastHeaderHash = lastHeaderHash
174175

175176
return block, nil

0 commit comments

Comments
 (0)