Skip to content

Commit 102fee2

Browse files
committed
updated the peerid for pool discovery to ipfs cluster
1 parent 1149b59 commit 102fee2

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

blockchain/blockchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ func (bl *FxBlockchain) discoverPoolAndChain(ctx context.Context, poolID uint32)
11981198

11991199
// Check if our peer ID is a member of this pool on this chain
12001200
membershipReq := IsMemberOfPoolRequest{
1201-
PeerID: bl.selfPeerID.String(),
1201+
PeerID: bl.clusterPeerID.String(),
12021202
PoolID: poolID,
12031203
ChainName: chainName,
12041204
}

blockchain/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type (
3333
rpc *rpc.HttpApi
3434
ipfsClusterApi ipfsCluster.Client
3535
selfPeerID peer.ID // Peer ID derived from private key, used for authorization checks
36+
clusterPeerID peer.ID // IPFS cluster peer ID (original identity), used for on-chain pool membership
3637
signingKey crypto.PrivKey // Private key for signing outgoing requests (mobile client)
3738
clientProtocolID string // Protocol ID for kubo p2p forwarding (e.g. "/x/fula-blockchain")
3839
}
@@ -226,6 +227,15 @@ func WithSelfPeerID(id peer.ID) Option {
226227
}
227228
}
228229

230+
// WithClusterPeerID sets the IPFS cluster peer ID (original identity, not HMAC-derived).
231+
// This is the peer ID registered on-chain for pool membership checks.
232+
func WithClusterPeerID(id peer.ID) Option {
233+
return func(o *options) error {
234+
o.clusterPeerID = id
235+
return nil
236+
}
237+
}
238+
229239
// WithRequestSigning enables signed request headers on outgoing HTTP requests.
230240
// The private key is used to sign requests so the receiving go-fula can verify the caller.
231241
func WithRequestSigning(key crypto.PrivKey) Option {

blox/blox.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func New(o ...Option) (*Blox, error) {
8181
blockchain.WithBlockchainEndPoint(p.blockchainEndpoint),
8282
blockchain.WithSecretsPath(p.secretsPath),
8383
blockchain.WithSelfPeerID(p.selfPeerID),
84+
blockchain.WithClusterPeerID(p.clusterPeerID),
8485
blockchain.WithTimeout(65),
8586
blockchain.WithWg(p.wg),
8687
blockchain.WithFetchFrequency(1*time.Minute),
@@ -456,7 +457,7 @@ func (p *Blox) Start(ctx context.Context) error {
456457

457458
for {
458459
attempt++
459-
log.Infow("Starting pool discovery", "attempt", attempt, "PeerID", p.selfPeerID.String())
460+
log.Infow("Starting pool discovery", "attempt", attempt, "PeerID", p.selfPeerID.String(), "clusterPeerID", p.clusterPeerID.String())
460461

461462
// Try each chain
462463
for _, chainName := range chainList {
@@ -481,7 +482,7 @@ func (p *Blox) Start(ctx context.Context) error {
481482

482483
// peerID format for membership check
483484
membershipReq := blockchain.IsMemberOfPoolRequest{
484-
PeerID: p.selfPeerID.String(),
485+
PeerID: p.clusterPeerID.String(),
485486
PoolID: pool.ID,
486487
ChainName: chainName,
487488
}
@@ -537,7 +538,7 @@ func (p *Blox) Start(ctx context.Context) error {
537538
}
538539

539540
if !found {
540-
log.Warnw("Could not find pool membership on any chain", "peerID", p.selfPeerID.String(), "chains", chainList)
541+
log.Warnw("Could not find pool membership on any chain", "clusterPeerID", p.clusterPeerID.String(), "chains", chainList)
541542
}
542543
}
543544

blox/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type (
2424
PoolNameGetter func() string
2525
options struct {
2626
selfPeerID peer.ID
27+
clusterPeerID peer.ID
2728
name string
2829
topicName string
2930
chainName string
@@ -125,6 +126,15 @@ func WithSelfPeerID(id peer.ID) Option {
125126
}
126127
}
127128

129+
// WithClusterPeerID sets the IPFS cluster peer ID (original identity, not HMAC-derived).
130+
// This is the peer ID registered on-chain for pool membership.
131+
func WithClusterPeerID(id peer.ID) Option {
132+
return func(o *options) error {
133+
o.clusterPeerID = id
134+
return nil
135+
}
136+
}
137+
128138
// WithPoolName sets a human readable name for the pool that the blox should join or create.
129139
// Required.
130140
func WithPoolName(n string) Option {

cmd/blox/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,22 @@ func action(ctx *cli.Context) error {
10871087
}
10881088
logger.Infow("Derived kubo peer ID from private key", "peerID", selfPeerID.String())
10891089

1090+
// Compute cluster peer ID — the original identity (not HMAC-derived).
1091+
// This is the peer ID registered on-chain for pool membership.
1092+
clusterPrivKeyBytes, err := base64.StdEncoding.DecodeString(app.config.Identity)
1093+
if err != nil {
1094+
return fmt.Errorf("decoding cluster private key: %w", err)
1095+
}
1096+
clusterPrivKey, err := crypto.UnmarshalPrivateKey(clusterPrivKeyBytes)
1097+
if err != nil {
1098+
return fmt.Errorf("unmarshaling cluster private key: %w", err)
1099+
}
1100+
clusterPeerID, err := peer.IDFromPrivateKey(clusterPrivKey)
1101+
if err != nil {
1102+
return fmt.Errorf("deriving cluster peer ID: %w", err)
1103+
}
1104+
logger.Infow("Computed cluster peer ID (on-chain identity)", "clusterPeerID", clusterPeerID.String())
1105+
10901106
linkSystem := cidlink.DefaultLinkSystem()
10911107
linkSystem.StorageReadOpener = CustomStorageReadOpenerNone
10921108
linkSystem.StorageWriteOpener = CustomStorageWriteOpenerNone
@@ -1133,6 +1149,7 @@ func action(ctx *cli.Context) error {
11331149

11341150
bb, err := blox.New(
11351151
blox.WithSelfPeerID(selfPeerID),
1152+
blox.WithClusterPeerID(clusterPeerID),
11361153
blox.WithAuthorizer(authorizerPeerID),
11371154
blox.WithWg(&wg),
11381155
blox.WithLinkSystem(&linkSystem),

0 commit comments

Comments
 (0)