Skip to content

Commit a6079b4

Browse files
gupadhyayaGanesha Upadhyaya
and
Ganesha Upadhyaya
authored
set node id using p2p key instead of local host id (cosmos#1074)
Node ID is set using local p2p host which does not match with cosmos-sdk node ID, which is set using the p2p key. Hence, changing the ID on the rollkit side to match with cosmos-sdk. --------- Co-authored-by: Ganesha Upadhyaya <gupadhyaya@Ganeshas-MacBook-Pro-2.local>
1 parent 0f27d04 commit a6079b4

5 files changed

+28
-6
lines changed

node/block_exchange.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,13 @@ func (bExService *BlockExchangeService) Start() error {
127127
return fmt.Errorf("error while starting block store: %w", err)
128128
}
129129

130-
_, _, network := bExService.p2p.Info()
131-
networkIDBlock := network + "-block"
132130
var err error
131+
_, _, network, err := bExService.p2p.Info()
132+
if err != nil {
133+
return fmt.Errorf("error while fetching the network: %w", err)
134+
}
135+
networkIDBlock := network + "-block"
136+
133137
if bExService.p2pServer, err = newBlockP2PServer(bExService.p2p.Host(), bExService.blockStore, networkIDBlock); err != nil {
134138
return fmt.Errorf("error while creating p2p server: %w", err)
135139
}

node/full_client.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,10 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
717717
state.Version.Consensus.Block,
718718
state.Version.Consensus.App,
719719
)
720-
id, addr, network := c.node.P2P.Info()
720+
id, addr, network, err := c.node.P2P.Info()
721+
if err != nil {
722+
return nil, fmt.Errorf("failed to load node p2p2 info: %w", err)
723+
}
721724
txIndexerStatus := "on"
722725

723726
result := &ctypes.ResultStatus{

node/full_client_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package node
33
import (
44
"context"
55
crand "crypto/rand"
6+
"encoding/hex"
67
"fmt"
78
"sync"
89
"testing"
@@ -1099,6 +1100,10 @@ func TestStatus(t *testing.T) {
10991100
res := resp.NodeInfo.Other.TxIndex == tc.other.TxIndex
11001101
assert.Equal(tc.expected, res, tc)
11011102
}
1103+
// check that NodeInfo DefaultNodeID matches the ID derived from p2p key
1104+
rawKey, err := key.GetPublic().Raw()
1105+
assert.NoError(err)
1106+
assert.Equal(p2p.ID(hex.EncodeToString(tmcrypto.AddressHash(rawKey))), resp.NodeInfo.DefaultNodeID)
11021107
}
11031108

11041109
func TestFutureGenesisTime(t *testing.T) {

node/header_exchange.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ func (hExService *HeaderExchangeService) Start() error {
126126
return fmt.Errorf("error while starting header store: %w", err)
127127
}
128128

129-
_, _, network := hExService.p2p.Info()
130129
var err error
130+
_, _, network, err := hExService.p2p.Info()
131+
if err != nil {
132+
return fmt.Errorf("error while fetching the network: %w", err)
133+
}
131134
if hExService.p2pServer, err = newP2PServer(hExService.p2p.Host(), hExService.headerStore, network); err != nil {
132135
return fmt.Errorf("error while creating p2p server: %w", err)
133136
}

p2p/client.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package p2p
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"strings"
78
"time"
@@ -24,6 +25,8 @@ import (
2425
"github.com/tendermint/tendermint/p2p"
2526
"go.uber.org/multierr"
2627

28+
tmcrypto "github.com/tendermint/tendermint/crypto"
29+
2730
"github.com/rollkit/rollkit/config"
2831
"github.com/rollkit/rollkit/log"
2932
)
@@ -186,8 +189,12 @@ func (c *Client) ConnectionGater() *conngater.BasicConnectionGater {
186189
}
187190

188191
// Info returns client ID, ListenAddr, and Network info
189-
func (c *Client) Info() (p2p.ID, string, string) {
190-
return p2p.ID(c.host.ID().String()), c.conf.ListenAddress, c.chainID
192+
func (c *Client) Info() (p2p.ID, string, string, error) {
193+
rawKey, err := c.privKey.GetPublic().Raw()
194+
if err != nil {
195+
return "", "", "", err
196+
}
197+
return p2p.ID(hex.EncodeToString(tmcrypto.AddressHash(rawKey))), c.conf.ListenAddress, c.chainID, nil
191198
}
192199

193200
// PeerConnection describe basic information about P2P connection.

0 commit comments

Comments
 (0)