Skip to content

Commit d934bcc

Browse files
Merge branch 'main' into dup-batch-handle
2 parents ce26e8f + 490539e commit d934bcc

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

internal/privatemessaging/operations.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2023 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -130,6 +130,7 @@ func (pm *privateMessaging) PrepareOperation(ctx context.Context, op *core.Opera
130130
return nil, err
131131
}
132132
transport := &core.TransportWrapper{Group: group, Batch: batch}
133+
pm.prepareBatchForNetworkTransport(ctx, transport)
133134
return opSendBatch(op, node, transport), nil
134135

135136
default:

internal/privatemessaging/operations_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2022 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -149,6 +149,7 @@ func TestPrepareAndRunBatchSend(t *testing.T) {
149149
assert.Equal(t, node, po.Data.(batchSendData).Node)
150150
assert.Equal(t, group, po.Data.(batchSendData).Transport.Group)
151151
assert.Equal(t, batch, po.Data.(batchSendData).Transport.Batch)
152+
assert.Equal(t, "ns1-remote", po.Data.(batchSendData).Transport.Batch.Namespace) // ensure its set to the network name not the local namespace name
152153

153154
_, phase, err := pm.RunOperation(context.Background(), po)
154155

internal/privatemessaging/privatemessaging.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2024 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -179,12 +179,20 @@ func (pm *privateMessaging) dispatchUnpinnedBatch(ctx context.Context, payload *
179179
return pm.dispatchBatchCommon(ctx, payload)
180180
}
181181

182+
// prepareBatchForNetworkTransport is mainly for documentation purposes, we need to "normalize" a batch before sending
183+
// it over the network to other parties, so that all nodes see the same batch, regardless of what they call their local
184+
// namespace. This is used when we dispatch a batch per the regular messaging flow, and when we retry a private messaging
185+
// send operation.
186+
func (pm *privateMessaging) prepareBatchForNetworkTransport(ctx context.Context, tw *core.TransportWrapper) {
187+
tw.Batch.Namespace = pm.namespace.NetworkName
188+
}
189+
182190
func (pm *privateMessaging) dispatchBatchCommon(ctx context.Context, payload *batch.DispatchPayload) error {
183191
batch := payload.Batch.GenInflight(payload.Messages, payload.Data)
184-
batch.Namespace = pm.namespace.NetworkName
185192
tw := &core.TransportWrapper{
186193
Batch: batch,
187194
}
195+
pm.prepareBatchForNetworkTransport(ctx, tw)
188196

189197
// Retrieve the group
190198
group, nodes, err := pm.groupManager.getGroupNodes(ctx, batch.Group, false /* fail if not found */)

internal/privatemessaging/privatemessaging_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2021 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -84,7 +84,7 @@ func newTestPrivateMessagingCommon(t *testing.T, metricsEnabled bool) (*privateM
8484
mmi.On("IsMetricsEnabled").Return(metricsEnabled)
8585
mom.On("RegisterHandler", mock.Anything, mock.Anything, mock.Anything)
8686

87-
ns := &core.Namespace{Name: "ns1", NetworkName: "ns1"}
87+
ns := &core.Namespace{Name: "ns1", NetworkName: "ns1-remote"}
8888
pm, err := NewPrivateMessaging(ctx, ns, mdi, mdx, mbi, mim, mba, mdm, msa, mmp, mmi, mom, cmi)
8989
assert.NoError(t, err)
9090
cmi.AssertCalled(t, "GetCache", cache.NewCacheConfig(

internal/privatemessaging/recipients_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2021 Kaleido, Inc.
1+
// Copyright © 2025 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -85,7 +85,7 @@ func TestResolveMemberListNewGroupE2E(t *testing.T) {
8585
um.RunFn = func(a mock.Arguments) {
8686
msg := a[1].(*core.Message)
8787
assert.Equal(t, core.MessageTypeGroupInit, msg.Header.Type)
88-
assert.Equal(t, "ns1", msg.Header.Namespace)
88+
assert.Equal(t, "ns1-remote", msg.Header.Namespace) // note this matches the remote network name, not the local namespace
8989
assert.Len(t, msg.Data, 1)
9090
assert.Equal(t, *dataID, *msg.Data[0].ID)
9191
}

0 commit comments

Comments
 (0)