Skip to content

Commit c7fdc9e

Browse files
Ferret-sanGanesha Upadhyaya
andauthored
Replace tendermint with cometbft (#793)
use commetbft types in rollkit in order to comply with cosmos-sdk 0.47.0 by replacing tendermint with cometbft, and then replacing cometbft with the rollkit fork of tendermint --------- Co-authored-by: Ganesha Upadhyaya <[email protected]>
1 parent a836166 commit c7fdc9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1627
-770
lines changed

block/manager.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import (
1010
"time"
1111

1212
"github.com/celestiaorg/go-fraud/fraudserv"
13+
abci "github.com/cometbft/cometbft/abci/types"
14+
cmcrypto "github.com/cometbft/cometbft/crypto"
15+
"github.com/cometbft/cometbft/crypto/merkle"
16+
cmstate "github.com/cometbft/cometbft/proto/tendermint/state"
17+
"github.com/cometbft/cometbft/proxy"
18+
cmtypes "github.com/cometbft/cometbft/types"
1319
"github.com/libp2p/go-libp2p/core/crypto"
14-
abci "github.com/tendermint/tendermint/abci/types"
15-
tmcrypto "github.com/tendermint/tendermint/crypto"
16-
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
17-
18-
"github.com/tendermint/tendermint/crypto/merkle"
19-
"github.com/tendermint/tendermint/proxy"
20-
tmtypes "github.com/tendermint/tendermint/types"
2120
"go.uber.org/multierr"
2221

2322
"github.com/rollkit/rollkit/config"
@@ -51,8 +50,9 @@ type Manager struct {
5150
lastStateMtx *sync.RWMutex
5251
store store.Store
5352

54-
conf config.BlockManagerConfig
55-
genesis *tmtypes.GenesisDoc
53+
conf config.BlockManagerConfig
54+
genesis *cmtypes.GenesisDoc
55+
5656
proposerKey crypto.PrivKey
5757

5858
executor *state.BlockExecutor
@@ -81,7 +81,7 @@ type Manager struct {
8181
}
8282

8383
// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
84-
func getInitialState(store store.Store, genesis *tmtypes.GenesisDoc) (types.State, error) {
84+
func getInitialState(store store.Store, genesis *cmtypes.GenesisDoc) (types.State, error) {
8585
s, err := store.LoadState()
8686
if err != nil {
8787
s, err = types.NewFromGenesisDoc(genesis)
@@ -93,12 +93,12 @@ func getInitialState(store store.Store, genesis *tmtypes.GenesisDoc) (types.Stat
9393
func NewManager(
9494
proposerKey crypto.PrivKey,
9595
conf config.BlockManagerConfig,
96-
genesis *tmtypes.GenesisDoc,
96+
genesis *cmtypes.GenesisDoc,
9797
store store.Store,
9898
mempool mempool.Mempool,
9999
proxyApp proxy.AppConnConsensus,
100100
dalc da.DataAvailabilityLayerClient,
101-
eventBus *tmtypes.EventBus,
101+
eventBus *cmtypes.EventBus,
102102
logger log.Logger,
103103
doneBuildingCh chan struct{},
104104
) (*Manager, error) {
@@ -172,7 +172,7 @@ func getAddress(key crypto.PrivKey) ([]byte, error) {
172172
if err != nil {
173173
return nil, err
174174
}
175-
return tmcrypto.AddressHash(rawKey), nil
175+
return cmcrypto.AddressHash(rawKey), nil
176176
}
177177

178178
// SetDALC is used to set DataAvailabilityLayerClient used by Manager.
@@ -670,7 +670,7 @@ func (m *Manager) saveValidatorsToStore(height uint64) error {
670670
return m.store.SaveValidators(height, m.lastState.Validators)
671671
}
672672

673-
func (m *Manager) getLastStateValidators() *tmtypes.ValidatorSet {
673+
func (m *Manager) getLastStateValidators() *cmtypes.ValidatorSet {
674674
m.lastStateMtx.RLock()
675675
defer m.lastStateMtx.RUnlock()
676676
return m.lastState.Validators
@@ -688,7 +688,7 @@ func (m *Manager) createBlock(height uint64, lastCommit *types.Commit, lastHeade
688688
return m.executor.CreateBlock(height, lastCommit, lastHeaderHash, m.lastState)
689689
}
690690

691-
func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.State, *tmstate.ABCIResponses, error) {
691+
func (m *Manager) applyBlock(ctx context.Context, block *types.Block) (types.State, *cmstate.ABCIResponses, error) {
692692
m.lastStateMtx.RLock()
693693
defer m.lastStateMtx.RUnlock()
694694
return m.executor.ApplyBlock(ctx, m.lastState, block)
@@ -718,20 +718,20 @@ func updateState(s *types.State, res *abci.ResponseInitChain) {
718718
s.ConsensusParams.Validator.PubKeyTypes = append([]string{}, params.Validator.PubKeyTypes...)
719719
}
720720
if params.Version != nil {
721-
s.ConsensusParams.Version.AppVersion = params.Version.AppVersion
721+
s.ConsensusParams.Version.App = params.Version.App
722722
}
723-
s.Version.Consensus.App = s.ConsensusParams.Version.AppVersion
723+
s.Version.Consensus.App = s.ConsensusParams.Version.App
724724
}
725725
// We update the last results hash with the empty hash, to conform with RFC-6962.
726726
s.LastResultsHash = merkle.HashFromByteSlices(nil)
727727

728728
if len(res.Validators) > 0 {
729-
vals, err := tmtypes.PB2TM.ValidatorUpdates(res.Validators)
729+
vals, err := cmtypes.PB2TM.ValidatorUpdates(res.Validators)
730730
if err != nil {
731731
// TODO(tzdybal): handle error properly
732732
panic(err)
733733
}
734-
s.Validators = tmtypes.NewValidatorSet(vals)
735-
s.NextValidators = tmtypes.NewValidatorSet(vals).CopyIncrementProposerPriority(1)
734+
s.Validators = cmtypes.NewValidatorSet(vals)
735+
s.NextValidators = cmtypes.NewValidatorSet(vals).CopyIncrementProposerPriority(1)
736736
}
737737
}

block/manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"testing"
77
"time"
88

9+
"github.com/cometbft/cometbft/libs/log"
10+
cmtypes "github.com/cometbft/cometbft/types"
911
"github.com/libp2p/go-libp2p/core/crypto"
1012
"github.com/stretchr/testify/assert"
1113
"github.com/stretchr/testify/require"
12-
"github.com/tendermint/tendermint/libs/log"
13-
tmtypes "github.com/tendermint/tendermint/types"
1414

1515
"github.com/rollkit/rollkit/config"
1616
"github.com/rollkit/rollkit/da"
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
func TestInitialState(t *testing.T) {
23-
genesis := &tmtypes.GenesisDoc{
23+
genesis := &cmtypes.GenesisDoc{
2424
ChainID: "genesis id",
2525
InitialHeight: 100,
2626
}
@@ -46,7 +46,7 @@ func TestInitialState(t *testing.T) {
4646
cases := []struct {
4747
name string
4848
store store.Store
49-
genesis *tmtypes.GenesisDoc
49+
genesis *cmtypes.GenesisDoc
5050
expectedInitialHeight int64
5151
expectedLastBlockHeight int64
5252
expectedChainID string

conv/abci/block.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
package abci
22

33
import (
4-
tmbytes "github.com/tendermint/tendermint/libs/bytes"
5-
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
6-
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
7-
tmtypes "github.com/tendermint/tendermint/types"
4+
cmbytes "github.com/cometbft/cometbft/libs/bytes"
5+
cmproto "github.com/cometbft/cometbft/proto/tendermint/types"
6+
cmversion "github.com/cometbft/cometbft/proto/tendermint/version"
7+
cmtypes "github.com/cometbft/cometbft/types"
88

99
"github.com/rollkit/rollkit/types"
1010
)
1111

1212
// ToABCIHeaderPB converts Rollkit header to Header format defined in ABCI.
1313
// Caller should fill all the fields that are not available in Rollkit header (like ChainID).
14-
func ToABCIHeaderPB(header *types.Header) (tmproto.Header, error) {
15-
return tmproto.Header{
16-
Version: tmversion.Consensus{
14+
func ToABCIHeaderPB(header *types.Header) (cmproto.Header, error) {
15+
return cmproto.Header{
16+
Version: cmversion.Consensus{
1717
Block: header.Version.Block,
1818
App: header.Version.App,
1919
},
2020
Height: int64(header.Height()),
2121
Time: header.Time(),
22-
LastBlockId: tmproto.BlockID{
22+
LastBlockId: cmproto.BlockID{
2323
Hash: header.LastHeaderHash[:],
24-
PartSetHeader: tmproto.PartSetHeader{
24+
PartSetHeader: cmproto.PartSetHeader{
2525
Total: 0,
2626
Hash: nil,
2727
},
2828
},
29-
LastCommitHash: header.LastCommitHash[:],
29+
LastCommitHash: header.LastHeaderHash[:],
3030
DataHash: header.DataHash[:],
3131
ValidatorsHash: header.AggregatorsHash[:],
3232
NextValidatorsHash: nil,
3333
ConsensusHash: header.ConsensusHash[:],
3434
AppHash: header.AppHash[:],
3535
LastResultsHash: header.LastResultsHash[:],
36-
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
36+
EvidenceHash: new(cmtypes.EvidenceData).Hash(),
3737
ProposerAddress: header.ProposerAddress,
3838
ChainID: header.ChainID(),
3939
}, nil
4040
}
4141

4242
// ToABCIHeader converts Rollkit header to Header format defined in ABCI.
4343
// Caller should fill all the fields that are not available in Rollkit header (like ChainID).
44-
func ToABCIHeader(header *types.Header) (tmtypes.Header, error) {
45-
return tmtypes.Header{
46-
Version: tmversion.Consensus{
44+
func ToABCIHeader(header *types.Header) (cmtypes.Header, error) {
45+
return cmtypes.Header{
46+
Version: cmversion.Consensus{
4747
Block: header.Version.Block,
4848
App: header.Version.App,
4949
},
5050
Height: int64(header.Height()),
5151
Time: header.Time(),
52-
LastBlockID: tmtypes.BlockID{
53-
Hash: tmbytes.HexBytes(header.LastHeaderHash),
54-
PartSetHeader: tmtypes.PartSetHeader{
52+
LastBlockID: cmtypes.BlockID{
53+
Hash: cmbytes.HexBytes(header.LastHeaderHash[:]),
54+
PartSetHeader: cmtypes.PartSetHeader{
5555
Total: 0,
5656
Hash: nil,
5757
},
5858
},
59-
LastCommitHash: tmbytes.HexBytes(header.LastCommitHash),
60-
DataHash: tmbytes.HexBytes(header.DataHash),
61-
ValidatorsHash: tmbytes.HexBytes(header.AggregatorsHash),
59+
LastCommitHash: cmbytes.HexBytes(header.LastCommitHash),
60+
DataHash: cmbytes.HexBytes(header.DataHash),
61+
ValidatorsHash: cmbytes.HexBytes(header.AggregatorsHash),
6262
NextValidatorsHash: nil,
63-
ConsensusHash: tmbytes.HexBytes(header.ConsensusHash),
64-
AppHash: tmbytes.HexBytes(header.AppHash),
65-
LastResultsHash: tmbytes.HexBytes(header.LastResultsHash),
66-
EvidenceHash: new(tmtypes.EvidenceData).Hash(),
63+
ConsensusHash: cmbytes.HexBytes(header.ConsensusHash),
64+
AppHash: cmbytes.HexBytes(header.AppHash),
65+
LastResultsHash: cmbytes.HexBytes(header.LastResultsHash),
66+
EvidenceHash: new(cmtypes.EvidenceData).Hash(),
6767
ProposerAddress: header.ProposerAddress,
6868
ChainID: header.ChainID(),
6969
}, nil
7070
}
7171

7272
// ToABCIBlock converts Rolkit block into block format defined by ABCI.
7373
// Returned block should pass `ValidateBasic`.
74-
func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) {
74+
func ToABCIBlock(block *types.Block) (*cmtypes.Block, error) {
7575
abciHeader, err := ToABCIHeader(&block.SignedHeader.Header)
7676
if err != nil {
7777
return nil, err
@@ -81,34 +81,34 @@ func ToABCIBlock(block *types.Block) (*tmtypes.Block, error) {
8181
if len(abciCommit.Signatures) == 1 {
8282
abciCommit.Signatures[0].ValidatorAddress = block.SignedHeader.Header.ProposerAddress
8383
}
84-
abciBlock := tmtypes.Block{
84+
abciBlock := cmtypes.Block{
8585
Header: abciHeader,
86-
Evidence: tmtypes.EvidenceData{
86+
Evidence: cmtypes.EvidenceData{
8787
Evidence: nil,
8888
},
8989
LastCommit: abciCommit,
9090
}
91-
abciBlock.Data.Txs = make([]tmtypes.Tx, len(block.Data.Txs))
91+
abciBlock.Data.Txs = make([]cmtypes.Tx, len(block.Data.Txs))
9292
for i := range block.Data.Txs {
93-
abciBlock.Data.Txs[i] = tmtypes.Tx(block.Data.Txs[i])
93+
abciBlock.Data.Txs[i] = cmtypes.Tx(block.Data.Txs[i])
9494
}
95-
abciBlock.Header.DataHash = tmbytes.HexBytes(block.SignedHeader.Header.DataHash)
95+
abciBlock.Header.DataHash = cmbytes.HexBytes(block.SignedHeader.Header.DataHash)
9696

9797
return &abciBlock, nil
9898
}
9999

100100
// ToABCIBlockMeta converts Rollkit block into BlockMeta format defined by ABCI
101-
func ToABCIBlockMeta(block *types.Block) (*tmtypes.BlockMeta, error) {
102-
tmblock, err := ToABCIBlock(block)
101+
func ToABCIBlockMeta(block *types.Block) (*cmtypes.BlockMeta, error) {
102+
cmblock, err := ToABCIBlock(block)
103103
if err != nil {
104104
return nil, err
105105
}
106-
blockID := tmtypes.BlockID{Hash: tmblock.Hash()}
106+
blockID := cmtypes.BlockID{Hash: cmblock.Hash()}
107107

108-
return &tmtypes.BlockMeta{
108+
return &cmtypes.BlockMeta{
109109
BlockID: blockID,
110-
BlockSize: tmblock.Size(),
111-
Header: tmblock.Header,
112-
NumTxs: len(tmblock.Txs),
110+
BlockSize: cmblock.Size(),
111+
Header: cmblock.Header,
112+
NumTxs: len(cmblock.Txs),
113113
}, nil
114114
}

conv/config.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package conv
22

33
import (
4-
tmcfg "github.com/tendermint/tendermint/config"
4+
cmcfg "github.com/cometbft/cometbft/config"
55

66
"github.com/rollkit/rollkit/config"
77
)
@@ -10,22 +10,22 @@ import (
1010
//
1111
// This method only translates configuration, and doesn't verify it. If some option is missing in Tendermint's
1212
// config, it's skipped during translation.
13-
func GetNodeConfig(nodeConf *config.NodeConfig, tmConf *tmcfg.Config) {
14-
if tmConf != nil {
15-
nodeConf.RootDir = tmConf.RootDir
16-
nodeConf.DBPath = tmConf.DBPath
17-
if tmConf.P2P != nil {
18-
nodeConf.P2P.ListenAddress = tmConf.P2P.ListenAddress
19-
nodeConf.P2P.Seeds = tmConf.P2P.Seeds
13+
func GetNodeConfig(nodeConf *config.NodeConfig, cmConf *cmcfg.Config) {
14+
if cmConf != nil {
15+
nodeConf.RootDir = cmConf.RootDir
16+
nodeConf.DBPath = cmConf.DBPath
17+
if cmConf.P2P != nil {
18+
nodeConf.P2P.ListenAddress = cmConf.P2P.ListenAddress
19+
nodeConf.P2P.Seeds = cmConf.P2P.Seeds
2020
}
21-
if tmConf.RPC != nil {
22-
nodeConf.RPC.ListenAddress = tmConf.RPC.ListenAddress
23-
nodeConf.RPC.CORSAllowedOrigins = tmConf.RPC.CORSAllowedOrigins
24-
nodeConf.RPC.CORSAllowedMethods = tmConf.RPC.CORSAllowedMethods
25-
nodeConf.RPC.CORSAllowedHeaders = tmConf.RPC.CORSAllowedHeaders
26-
nodeConf.RPC.MaxOpenConnections = tmConf.RPC.MaxOpenConnections
27-
nodeConf.RPC.TLSCertFile = tmConf.RPC.TLSCertFile
28-
nodeConf.RPC.TLSKeyFile = tmConf.RPC.TLSKeyFile
21+
if cmConf.RPC != nil {
22+
nodeConf.RPC.ListenAddress = cmConf.RPC.ListenAddress
23+
nodeConf.RPC.CORSAllowedOrigins = cmConf.RPC.CORSAllowedOrigins
24+
nodeConf.RPC.CORSAllowedMethods = cmConf.RPC.CORSAllowedMethods
25+
nodeConf.RPC.CORSAllowedHeaders = cmConf.RPC.CORSAllowedHeaders
26+
nodeConf.RPC.MaxOpenConnections = cmConf.RPC.MaxOpenConnections
27+
nodeConf.RPC.TLSCertFile = cmConf.RPC.TLSCertFile
28+
nodeConf.RPC.TLSKeyFile = cmConf.RPC.TLSKeyFile
2929
}
3030
}
3131
}

conv/config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/stretchr/testify/assert"
77

8-
tmcfg "github.com/tendermint/tendermint/config"
8+
cmcfg "github.com/cometbft/cometbft/config"
99

1010
"github.com/rollkit/rollkit/config"
1111
)
@@ -15,14 +15,14 @@ func TestGetNodeConfig(t *testing.T) {
1515

1616
cases := []struct {
1717
name string
18-
input *tmcfg.Config
18+
input *cmcfg.Config
1919
expected config.NodeConfig
2020
}{
2121
{"empty", nil, config.NodeConfig{}},
22-
{"Seeds", &tmcfg.Config{P2P: &tmcfg.P2PConfig{Seeds: "seeds"}}, config.NodeConfig{P2P: config.P2PConfig{Seeds: "seeds"}}},
23-
{"ListenAddress", &tmcfg.Config{P2P: &tmcfg.P2PConfig{ListenAddress: "127.0.0.1:7676"}}, config.NodeConfig{P2P: config.P2PConfig{ListenAddress: "127.0.0.1:7676"}}},
24-
{"RootDir", &tmcfg.Config{BaseConfig: tmcfg.BaseConfig{RootDir: "~/root"}}, config.NodeConfig{RootDir: "~/root"}},
25-
{"DBPath", &tmcfg.Config{BaseConfig: tmcfg.BaseConfig{DBPath: "./database"}}, config.NodeConfig{DBPath: "./database"}},
22+
{"Seeds", &cmcfg.Config{P2P: &cmcfg.P2PConfig{Seeds: "seeds"}}, config.NodeConfig{P2P: config.P2PConfig{Seeds: "seeds"}}},
23+
{"ListenAddress", &cmcfg.Config{P2P: &cmcfg.P2PConfig{ListenAddress: "127.0.0.1:7676"}}, config.NodeConfig{P2P: config.P2PConfig{ListenAddress: "127.0.0.1:7676"}}},
24+
{"RootDir", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{RootDir: "~/root"}}, config.NodeConfig{RootDir: "~/root"}},
25+
{"DBPath", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{DBPath: "./database"}}, config.NodeConfig{DBPath: "./database"}},
2626
}
2727

2828
for _, c := range cases {

conv/crypto.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import (
44
"errors"
55
"fmt"
66

7+
p2p "github.com/cometbft/cometbft/p2p"
78
"github.com/libp2p/go-libp2p/core/crypto"
8-
9-
"github.com/tendermint/tendermint/p2p"
109
)
1110

1211
var (

conv/crypto_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"github.com/stretchr/testify/assert"
77
"github.com/stretchr/testify/require"
88

9+
"github.com/cometbft/cometbft/crypto/ed25519"
10+
"github.com/cometbft/cometbft/crypto/secp256k1"
11+
"github.com/cometbft/cometbft/p2p"
912
pb "github.com/libp2p/go-libp2p/core/crypto/pb"
10-
"github.com/tendermint/tendermint/crypto/ed25519"
11-
"github.com/tendermint/tendermint/crypto/secp256k1"
12-
"github.com/tendermint/tendermint/p2p"
1313
)
1414

1515
func TestGetNodeKey(t *testing.T) {

0 commit comments

Comments
 (0)