Skip to content

Commit

Permalink
feat: pass software version from abci to node info (#1036)
Browse files Browse the repository at this point in the history
* pass software version from abci to node info

* Update consensus/replay_test.go

Co-authored-by: Rootul P <rootulp@gmail.com>
  • Loading branch information
cmwaters and rootulp authored Jul 14, 2023
1 parent 3e636bb commit d5cd08c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
10 changes: 5 additions & 5 deletions consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,17 @@ func (h *Handshaker) NBlocks() int {
}

// TODO: retry the handshake/replay if it fails ?
func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
func (h *Handshaker) Handshake(proxyApp proxy.AppConns) (string, error) {

// Handshake is done via ABCI Info on the query conn.
res, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
if err != nil {
return fmt.Errorf("error calling Info: %v", err)
return "", fmt.Errorf("error calling Info: %v", err)
}

blockHeight := res.LastBlockHeight
if blockHeight < 0 {
return fmt.Errorf("got a negative last block height (%d) from the app", blockHeight)
return "", fmt.Errorf("got a negative last block height (%d) from the app", blockHeight)
}
appHash := res.LastBlockAppHash

Expand All @@ -267,15 +267,15 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
// Replay blocks up to the latest in the blockstore.
_, err = h.ReplayBlocks(h.initialState, appHash, blockHeight, proxyApp)
if err != nil {
return fmt.Errorf("error on replay: %v", err)
return "", fmt.Errorf("error on replay: %v", err)
}

h.logger.Info("Completed ABCI Handshake - CometBFT and App are synced",
"appHeight", blockHeight, "appHash", appHash)

// TODO: (on restart) replay mempool

return nil
return res.Version, nil
}

// ReplayBlocks replays all blocks since appBlockHeight and ensures the result
Expand Down
2 changes: 1 addition & 1 deletion consensus/replay_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo

handshaker := NewHandshaker(stateStore, state, blockStore, gdoc)
handshaker.SetEventBus(eventBus)
err = handshaker.Handshake(proxyApp)
_, err = handshaker.Handshake(proxyApp)
if err != nil {
cmtos.Exit(fmt.Sprintf("Error on handshake: %v", err))
}
Expand Down
23 changes: 19 additions & 4 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/state/test/factory"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -754,13 +755,14 @@ func testHandshakeReplay(t *testing.T, config *cfg.Config, nBlocks int, mode uin
}
})

err := handshaker.Handshake(proxyApp)
softwareVersion, err := handshaker.Handshake(proxyApp)
if expectError {
require.Error(t, err)
return
} else if err != nil {
t.Fatalf("Error on abci handshake: %v", err)
}
require.Equal(t, softwareVersion, version.ABCISemVer)

// get the latest app hash from the app
res, err := proxyApp.Query().InfoSync(abci.RequestInfo{Version: ""})
Expand Down Expand Up @@ -932,7 +934,8 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {

assert.Panics(t, func() {
h := NewHandshaker(stateStore, state, store, genDoc)
if err = h.Handshake(proxyApp); err != nil {
_, err = h.Handshake(proxyApp)
if err != nil {
t.Log(err)
}
})
Expand All @@ -956,7 +959,8 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {

assert.Panics(t, func() {
h := NewHandshaker(stateStore, state, store, genDoc)
if err = h.Handshake(proxyApp); err != nil {
_, err = h.Handshake(proxyApp)
if err != nil {
t.Log(err)
}
})
Expand Down Expand Up @@ -1271,9 +1275,12 @@ func TestHandshakeUpdatesValidators(t *testing.T) {
t.Error(err)
}
})
if err := handshaker.Handshake(proxyApp); err != nil {
version, err := handshaker.Handshake(proxyApp)
if err != nil {
t.Fatalf("Error on abci handshake: %v", err)
}
require.Equal(t, customVersion, version)

// reload the state, check the validator set was updated
state, err = stateStore.Load()
require.NoError(t, err)
Expand All @@ -1284,6 +1291,8 @@ func TestHandshakeUpdatesValidators(t *testing.T) {
assert.Equal(t, newValAddr, expectValAddr)
}

const customVersion = "v1.0.0"

// returns the vals on InitChain
type initChainApp struct {
abci.BaseApplication
Expand All @@ -1295,3 +1304,9 @@ func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitC
Validators: ica.vals,
}
}

func (ica *initChainApp) Info(req abci.RequestInfo) abci.ResponseInfo {
return abci.ResponseInfo{
Version: customVersion,
}
}
22 changes: 14 additions & 8 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,11 @@ func doHandshake(
eventBus types.BlockEventPublisher,
proxyApp proxy.AppConns,
consensusLogger log.Logger,
) error {
) (string, error) {
handshaker := cs.NewHandshaker(stateStore, state, blockStore, genDoc)
handshaker.SetLogger(consensusLogger)
handshaker.SetEventBus(eventBus)
if err := handshaker.Handshake(proxyApp); err != nil {
return fmt.Errorf("error during handshake: %v", err)
}
return nil
return handshaker.Handshake(proxyApp)
}

func logNodeStartupInfo(state sm.State, pubKey crypto.PubKey, logger, consensusLogger log.Logger) {
Expand Down Expand Up @@ -814,8 +811,10 @@ func NewNode(config *cfg.Config,
// Create the handshaker, which calls RequestInfo, sets the AppVersion on the state,
// and replays any blocks as necessary to sync CometBFT with the app.
consensusLogger := logger.With("module", "consensus")
var softwareVersion string
if !stateSync {
if err := doHandshake(stateStore, state, blockStore, genDoc, eventBus, proxyApp, consensusLogger); err != nil {
softwareVersion, err = doHandshake(stateStore, state, blockStore, genDoc, eventBus, proxyApp, consensusLogger)
if err != nil {
return nil, err
}

Expand All @@ -826,6 +825,12 @@ func NewNode(config *cfg.Config,
if err != nil {
return nil, fmt.Errorf("cannot load state: %w", err)
}
} else {
resp, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
if err != nil {
return nil, fmt.Errorf("error during info call: %w", err)
}
softwareVersion = resp.Version
}

// Determine whether we should do fast sync. This must happen after the handshake, since the
Expand Down Expand Up @@ -898,7 +903,7 @@ func NewNode(config *cfg.Config,
)
stateSyncReactor.SetLogger(logger.With("module", "statesync"))

nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state)
nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state, softwareVersion)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1383,6 +1388,7 @@ func makeNodeInfo(
txIndexer txindex.TxIndexer,
genDoc *types.GenesisDoc,
state sm.State,
softwareVersion string,
) (p2p.DefaultNodeInfo, error) {
txIndexerStatus := "on"
if _, ok := txIndexer.(*null.TxIndex); ok {
Expand All @@ -1409,7 +1415,7 @@ func makeNodeInfo(
),
DefaultNodeID: nodeKey.ID(),
Network: genDoc.ChainID,
Version: version.TMCoreSemVer,
Version: softwareVersion,
Channels: []byte{
bcChannel,
cs.StateChannel, cs.DataChannel, cs.VoteChannel, cs.VoteSetBitsChannel,
Expand Down

0 comments on commit d5cd08c

Please sign in to comment.