Skip to content

Commit d5cd08c

Browse files
cmwatersrootulp
andauthored
feat: pass software version from abci to node info (#1036)
* pass software version from abci to node info * Update consensus/replay_test.go Co-authored-by: Rootul P <[email protected]>
1 parent 3e636bb commit d5cd08c

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

consensus/replay.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,17 @@ func (h *Handshaker) NBlocks() int {
238238
}
239239

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

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

249249
blockHeight := res.LastBlockHeight
250250
if blockHeight < 0 {
251-
return fmt.Errorf("got a negative last block height (%d) from the app", blockHeight)
251+
return "", fmt.Errorf("got a negative last block height (%d) from the app", blockHeight)
252252
}
253253
appHash := res.LastBlockAppHash
254254

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

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

276276
// TODO: (on restart) replay mempool
277277

278-
return nil
278+
return res.Version, nil
279279
}
280280

281281
// ReplayBlocks replays all blocks since appBlockHeight and ensures the result

consensus/replay_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
324324

325325
handshaker := NewHandshaker(stateStore, state, blockStore, gdoc)
326326
handshaker.SetEventBus(eventBus)
327-
err = handshaker.Handshake(proxyApp)
327+
_, err = handshaker.Handshake(proxyApp)
328328
if err != nil {
329329
cmtos.Exit(fmt.Sprintf("Error on handshake: %v", err))
330330
}

consensus/replay_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
sm "github.com/tendermint/tendermint/state"
3333
"github.com/tendermint/tendermint/state/test/factory"
3434
"github.com/tendermint/tendermint/types"
35+
"github.com/tendermint/tendermint/version"
3536
)
3637

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

757-
err := handshaker.Handshake(proxyApp)
758+
softwareVersion, err := handshaker.Handshake(proxyApp)
758759
if expectError {
759760
require.Error(t, err)
760761
return
761762
} else if err != nil {
762763
t.Fatalf("Error on abci handshake: %v", err)
763764
}
765+
require.Equal(t, softwareVersion, version.ABCISemVer)
764766

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

933935
assert.Panics(t, func() {
934936
h := NewHandshaker(stateStore, state, store, genDoc)
935-
if err = h.Handshake(proxyApp); err != nil {
937+
_, err = h.Handshake(proxyApp)
938+
if err != nil {
936939
t.Log(err)
937940
}
938941
})
@@ -956,7 +959,8 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {
956959

957960
assert.Panics(t, func() {
958961
h := NewHandshaker(stateStore, state, store, genDoc)
959-
if err = h.Handshake(proxyApp); err != nil {
962+
_, err = h.Handshake(proxyApp)
963+
if err != nil {
960964
t.Log(err)
961965
}
962966
})
@@ -1271,9 +1275,12 @@ func TestHandshakeUpdatesValidators(t *testing.T) {
12711275
t.Error(err)
12721276
}
12731277
})
1274-
if err := handshaker.Handshake(proxyApp); err != nil {
1278+
version, err := handshaker.Handshake(proxyApp)
1279+
if err != nil {
12751280
t.Fatalf("Error on abci handshake: %v", err)
12761281
}
1282+
require.Equal(t, customVersion, version)
1283+
12771284
// reload the state, check the validator set was updated
12781285
state, err = stateStore.Load()
12791286
require.NoError(t, err)
@@ -1284,6 +1291,8 @@ func TestHandshakeUpdatesValidators(t *testing.T) {
12841291
assert.Equal(t, newValAddr, expectValAddr)
12851292
}
12861293

1294+
const customVersion = "v1.0.0"
1295+
12871296
// returns the vals on InitChain
12881297
type initChainApp struct {
12891298
abci.BaseApplication
@@ -1295,3 +1304,9 @@ func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitC
12951304
Validators: ica.vals,
12961305
}
12971306
}
1307+
1308+
func (ica *initChainApp) Info(req abci.RequestInfo) abci.ResponseInfo {
1309+
return abci.ResponseInfo{
1310+
Version: customVersion,
1311+
}
1312+
}

node/node.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,11 @@ func doHandshake(
325325
eventBus types.BlockEventPublisher,
326326
proxyApp proxy.AppConns,
327327
consensusLogger log.Logger,
328-
) error {
328+
) (string, error) {
329329
handshaker := cs.NewHandshaker(stateStore, state, blockStore, genDoc)
330330
handshaker.SetLogger(consensusLogger)
331331
handshaker.SetEventBus(eventBus)
332-
if err := handshaker.Handshake(proxyApp); err != nil {
333-
return fmt.Errorf("error during handshake: %v", err)
334-
}
335-
return nil
332+
return handshaker.Handshake(proxyApp)
336333
}
337334

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

@@ -826,6 +825,12 @@ func NewNode(config *cfg.Config,
826825
if err != nil {
827826
return nil, fmt.Errorf("cannot load state: %w", err)
828827
}
828+
} else {
829+
resp, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
830+
if err != nil {
831+
return nil, fmt.Errorf("error during info call: %w", err)
832+
}
833+
softwareVersion = resp.Version
829834
}
830835

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

901-
nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state)
906+
nodeInfo, err := makeNodeInfo(config, nodeKey, txIndexer, genDoc, state, softwareVersion)
902907
if err != nil {
903908
return nil, err
904909
}
@@ -1383,6 +1388,7 @@ func makeNodeInfo(
13831388
txIndexer txindex.TxIndexer,
13841389
genDoc *types.GenesisDoc,
13851390
state sm.State,
1391+
softwareVersion string,
13861392
) (p2p.DefaultNodeInfo, error) {
13871393
txIndexerStatus := "on"
13881394
if _, ok := txIndexer.(*null.TxIndex); ok {
@@ -1409,7 +1415,7 @@ func makeNodeInfo(
14091415
),
14101416
DefaultNodeID: nodeKey.ID(),
14111417
Network: genDoc.ChainID,
1412-
Version: version.TMCoreSemVer,
1418+
Version: softwareVersion,
14131419
Channels: []byte{
14141420
bcChannel,
14151421
cs.StateChannel, cs.DataChannel, cs.VoteChannel, cs.VoteSetBitsChannel,

0 commit comments

Comments
 (0)