Repository: hyperledger/firefly (go)

Issue:
Definition broadcasts are not using unique topics
Looks to have been introduced by the enhancements for https://github.com/hyperledger/firefly/issues/1220.

The topic for definition messages is generated from a few items in the definition - normally the object type, namespace, and name:
https://github.com/hyperledger/firefly/blob/fbd88de171e513eb6074ee5a6ae440a6c3f60acc/pkg/core/tokenpool.go#L96

However, for definitions that have a "network name" now, the local "name" is actually cleared before broadcasting. Therefore the topic for the broadcast should probably be derived from the network name instead of the name (otherwise all definitions with that namespace/type will end up with an identical topic).

Pull request:
Use NetworkName instead of Name for definition topics
Fixes #1349

Related fix that will also need to be integrated: https://github.com/hyperledger/firefly-common/pull/76

Patch:
diff --git a/go.mod b/go.mod
index bc55f48ca..9916f7608 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
 	github.com/golang-migrate/migrate/v4 v4.15.2
 	github.com/gorilla/mux v1.8.0
 	github.com/gorilla/websocket v1.5.0
-	github.com/hyperledger/firefly-common v1.2.15
+	github.com/hyperledger/firefly-common v1.2.17
 	github.com/hyperledger/firefly-signer v1.1.8
 	github.com/jarcoal/httpmock v1.2.0
 	github.com/karlseguin/ccache v2.0.3+incompatible
@@ -85,4 +85,4 @@ require (
 	gopkg.in/ini.v1 v1.67.0 // indirect
 	gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
-)
\ No newline at end of file
+)
diff --git a/go.sum b/go.sum
index 2303f73d7..aad9968cb 100644
--- a/go.sum
+++ b/go.sum
@@ -676,10 +676,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
 github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
 github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
-github.com/hyperledger/firefly-common v1.2.14 h1:HON9GJZXvrL0l2AG5DWHSGiBh05hElgFS5lm1OPR83M=
-github.com/hyperledger/firefly-common v1.2.14/go.mod h1:17lOH4YufiPy82LpKm8fPa/YXJ0pUyq01zK1CmklJwM=
-github.com/hyperledger/firefly-common v1.2.15 h1:WdNB65IJvIyiOhVW3nxB3sQKqtJbdJ7ie0PJIM11CSU=
-github.com/hyperledger/firefly-common v1.2.15/go.mod h1:17lOH4YufiPy82LpKm8fPa/YXJ0pUyq01zK1CmklJwM=
+github.com/hyperledger/firefly-common v1.2.17 h1:l1fVt7zk+ysJWVN2SWr1kVrV2a/3cIh1yajpGRPf9iw=
+github.com/hyperledger/firefly-common v1.2.17/go.mod h1:17lOH4YufiPy82LpKm8fPa/YXJ0pUyq01zK1CmklJwM=
 github.com/hyperledger/firefly-signer v1.1.8 h1:XyJjZXesih2dWYG31m5ZYt4irH7/PdkRutMPld7AqKE=
 github.com/hyperledger/firefly-signer v1.1.8/go.mod h1:vNbbROziwqkOmO0b+9ky3devjcFg0JIkR2M1KG7seTQ=
 github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
diff --git a/pkg/core/contracts.go b/pkg/core/contracts.go
index 6ef80d6ac..b9c1adb2b 100644
--- a/pkg/core/contracts.go
+++ b/pkg/core/contracts.go
@@ -87,7 +87,7 @@ func (c *ContractAPI) Validate(ctx context.Context) (err error) {
 }
 
 func (c *ContractAPI) Topic() string {
-	return fftypes.TypeNamespaceNameTopicHash("contractapi", c.Namespace, c.Name)
+	return fftypes.TypeNamespaceNameTopicHash("contractapi", c.Namespace, c.NetworkName)
 }
 
 func (c *ContractAPI) SetBroadcastMessage(msgID *fftypes.UUID) {
diff --git a/pkg/core/tokenpool.go b/pkg/core/tokenpool.go
index 0b97ff3db..9b70f248b 100644
--- a/pkg/core/tokenpool.go
+++ b/pkg/core/tokenpool.go
@@ -93,7 +93,7 @@ func (t *TokenPool) Validate(ctx context.Context) (err error) {
 }
 
 func (t *TokenPoolDefinition) Topic() string {
-	return fftypes.TypeNamespaceNameTopicHash("tokenpool", t.Pool.Namespace, t.Pool.Name)
+	return fftypes.TypeNamespaceNameTopicHash("tokenpool", t.Pool.Namespace, t.Pool.NetworkName)
 }
 
 func (t *TokenPoolDefinition) SetBroadcastMessage(msgID *fftypes.UUID) {


Test patch:
diff --git a/pkg/core/contracts_test.go b/pkg/core/contracts_test.go
index 19ac95dfe..829f1b924 100644
--- a/pkg/core/contracts_test.go
+++ b/pkg/core/contracts_test.go
@@ -59,9 +59,10 @@ func TestValidateInvalidContractAPI(t *testing.T) {
 
 func TestContractAPITopic(t *testing.T) {
 	api := &ContractAPI{
-		Namespace: "ns1",
+		Namespace:   "ns1",
+		NetworkName: "banana",
 	}
-	assert.Equal(t, "4cccc66c1f0eebcf578f1e63b73a2047d4eb4c84c0a00c69b0e00c7490403d20", api.Topic())
+	assert.Equal(t, "a2f42ab7c9ef44ec08a103c565041b48b4cff4e4176e5faacfe8512c361e4f2c", api.Topic())
 }
 
 func TestContractAPISetBroadCastMessage(t *testing.T) {
diff --git a/pkg/core/tokenpool_test.go b/pkg/core/tokenpool_test.go
index 01acddf8e..e2cafdceb 100644
--- a/pkg/core/tokenpool_test.go
+++ b/pkg/core/tokenpool_test.go
@@ -50,8 +50,8 @@ func TestTokenPoolValidation(t *testing.T) {
 
 func TestTokenPoolDefinition(t *testing.T) {
 	pool := &TokenPool{
-		Namespace: "ok",
-		Name:      "ok",
+		Namespace:   "ok",
+		NetworkName: "ok",
 	}
 	var def Definition = &TokenPoolDefinition{Pool: pool}
 	assert.Equal(t, "73008386c5579b7015385528eb892f7773e13a20015c692f6b90b26e413fe8a4", def.Topic())