0

I want to add a new Organization to an existing Channel in Hyperledger Fabric.

First I obtain the channel configuration in JSON format using the following code snippet:

byte[] configBytes = channel.getChannelConfigurationBytes();
String configtxlator = props.getProperty("configtxlator");
HttpPost httppost = new HttpPost(configtxlator + "/protolator/decode/common.Config");
httppost.setEntity(new ByteArrayEntity(configBytes));

HttpClient httpclient = HttpClients.createDefault();
HttpResponse response = httpclient.execute(httppost);
int statuscode = response.getStatusLine().getStatusCode();
if (statuscode == 200) {
    return EntityUtils.toString(response.getEntity());
} else {
    return "";
}

The result is the following JSON string:

{
"channel_group": {
    "groups": {
        "Application": {
            "groups": {
                "Org1MSP": {
                    "groups": {},
                    "mod_policy": "Admins",
                    "policies": {
                        "Admins": {
                            "mod_policy": "Admins",
                            "policy": {
                                "type": 1,
                                "value": {
                                    "identities": [
                                        {
                                            "principal": {
                                                "msp_identifier": "Org1MSP",
                                                "role": "ADMIN"
                                            },
                                            "principal_classification": "ROLE"
                                        }
                                    ],
                                    "rule": {
                                        "n_out_of": {
                                            "n": 1,
                                            "rules": [
                                                {
                                                    "signed_by": 0
                                                }
                                            ]
                                        }
                                    },
                                    "version": 0
                                }
                            },
                            "version": "0"
                        },
                        "Readers": {
                            "mod_policy": "Admins",
                            "policy": {
                                "type": 1,
                                "value": {
                                    "identities": [
                                        {
                                            "principal": {
                                                "msp_identifier": "Org1MSP",
                                                "role": "ADMIN"
                                            },
                                            "principal_classification": "ROLE"
                                        },
                                        {
                                            "principal": {
                                                "msp_identifier": "Org1MSP",
                                                "role": "PEER"
                                            },
                                            "principal_classification": "ROLE"
                                        },
                                        {
                                            "principal": {
                                                "msp_identifier": "Org1MSP",
                                                "role": "CLIENT"
                                            },
                                            "principal_classification": "ROLE"
                                        }
                                    ],
                                    "rule": {
                                        "n_out_of": {
                                            "n": 1,
                                            "rules": [
                                                {
                                                    "signed_by": 0
                                                },
                                                {
                                                    "signed_by": 1
                                                },
                                                {
                                                    "signed_by": 2
                                                }
                                            ]
                                        }
                                    },
                                    "version": 0
                                }
                            },
                            "version": "0"
                        },
                        "Writers": {
                            "mod_policy": "Admins",
                            "policy": {
                                "type": 1,
                                "value": {
                                    "identities": [
                                        {
                                            "principal": {
                                                "msp_identifier": "Org1MSP",
                                                "role": "ADMIN"
                                            },
                                            "principal_classification": "ROLE"
                                        },
                                        {
                                            "principal": {
                                                "msp_identifier": "Org1MSP",
                                                "role": "CLIENT"
                                            },
                                            "principal_classification": "ROLE"
                                        }
                                    ],
                                    "rule": {
                                        "n_out_of": {
                                            "n": 1,
                                            "rules": [
                                                {
                                                    "signed_by": 0
                                                },
                                                {
                                                    "signed_by": 1
                                                }
                                            ]
                                        }
                                    },
                                    "version": 0
                                }
                            },
                            "version": "0"
                        }
                    },
                    "values": {
                        "AnchorPeers": {
                            "mod_policy": "Admins",
                            "value": {
                                "anchor_peers": [
                                    {
                                        "host": "peer1.org1.isprint.com",
                                        "port": 7051
                                    },
                                    {
                                        "host": "peer2.org1.isprint.com",
                                        "port": 7051
                                    }
                                ]
                            },
                            "version": "0"
                        },
                        "MSP": {
                            "mod_policy": "Admins",
                            "value": {
                                "config": {
                                    "admins": [],
                                    "crypto_config": {
                                        "identity_identifier_hash_function": "SHA256",
                                        "signature_hash_family": "SHA2"
                                    },
                                    "fabric_node_ous": {
                                        "admin_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "admin"
                                        },
                                        "client_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "client"
                                        },
                                        "enable": true,
                                        "orderer_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "orderer"
                                        },
                                        "peer_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "peer"
                                        }
                                    },
                                    "intermediate_certs": [],
                                    "name": "Org1MSP",
                                    "organizational_unit_identifiers": [],
                                    "revocation_list": [],
                                    "root_certs": [
                                        "..."
                                    ],
                                    "signing_identity": null,
                                    "tls_intermediate_certs": [],
                                    "tls_root_certs": [
                                        "..."
                                    ]
                                },
                                "type": 0
                            },
                            "version": "0"
                        }
                    },
                    "version": "1"
                }
            },
            "mod_policy": "Admins",
            "policies": {
                "Admins": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "MAJORITY",
                            "sub_policy": "Admins"
                        }
                    },
                    "version": "0"
                },
                "Readers": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "ANY",
                            "sub_policy": "Readers"
                        }
                    },
                    "version": "0"
                },
                "Writers": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "ANY",
                            "sub_policy": "Writers"
                        }
                    },
                    "version": "0"
                }
            },
            "values": {
                "Capabilities": {
                    "mod_policy": "Admins",
                    "value": {
                        "capabilities": {
                            "V1_4_2": {}
                        }
                    },
                    "version": "0"
                }
            },
            "version": "1"
        },
        "Orderer": {
            "groups": {
                "OrdererOrg": {
                    "groups": {},
                    "mod_policy": "Admins",
                    "policies": {
                        "Admins": {
                            "mod_policy": "Admins",
                            "policy": {
                                "type": 1,
                                "value": {
                                    "identities": [
                                        {
                                            "principal": {
                                                "msp_identifier": "OrdererMSP",
                                                "role": "ADMIN"
                                            },
                                            "principal_classification": "ROLE"
                                        }
                                    ],
                                    "rule": {
                                        "n_out_of": {
                                            "n": 1,
                                            "rules": [
                                                {
                                                    "signed_by": 0
                                                }
                                            ]
                                        }
                                    },
                                    "version": 0
                                }
                            },
                            "version": "0"
                        },
                        "Readers": {
                            "mod_policy": "Admins",
                            "policy": {
                                "type": 1,
                                "value": {
                                    "identities": [
                                        {
                                            "principal": {
                                                "msp_identifier": "OrdererMSP",
                                                "role": "MEMBER"
                                            },
                                            "principal_classification": "ROLE"
                                        }
                                    ],
                                    "rule": {
                                        "n_out_of": {
                                            "n": 1,
                                            "rules": [
                                                {
                                                    "signed_by": 0
                                                }
                                            ]
                                        }
                                    },
                                    "version": 0
                                }
                            },
                            "version": "0"
                        },
                        "Writers": {
                            "mod_policy": "Admins",
                            "policy": {
                                "type": 1,
                                "value": {
                                    "identities": [
                                        {
                                            "principal": {
                                                "msp_identifier": "OrdererMSP",
                                                "role": "MEMBER"
                                            },
                                            "principal_classification": "ROLE"
                                        }
                                    ],
                                    "rule": {
                                        "n_out_of": {
                                            "n": 1,
                                            "rules": [
                                                {
                                                    "signed_by": 0
                                                }
                                            ]
                                        }
                                    },
                                    "version": 0
                                }
                            },
                            "version": "0"
                        }
                    },
                    "values": {
                        "MSP": {
                            "mod_policy": "Admins",
                            "value": {
                                "config": {
                                    "admins": [],
                                    "crypto_config": {
                                        "identity_identifier_hash_function": "SHA256",
                                        "signature_hash_family": "SHA2"
                                    },
                                    "fabric_node_ous": {
                                        "admin_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "admin"
                                        },
                                        "client_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "client"
                                        },
                                        "enable": true,
                                        "orderer_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "orderer"
                                        },
                                        "peer_ou_identifier": {
                                            "certificate": "...",
                                            "organizational_unit_identifier": "peer"
                                        }
                                    },
                                    "intermediate_certs": [],
                                    "name": "OrdererMSP",
                                    "organizational_unit_identifiers": [],
                                    "revocation_list": [],
                                    "root_certs": [
                                        "..."
                                    ],
                                    "signing_identity": null,
                                    "tls_intermediate_certs": [],
                                    "tls_root_certs": [
                                        "..."
                                    ]
                                },
                                "type": 0
                            },
                            "version": "0"
                        }
                    },
                    "version": "0"
                }
            },
            "mod_policy": "Admins",
            "policies": {
                "Admins": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "MAJORITY",
                            "sub_policy": "Admins"
                        }
                    },
                    "version": "0"
                },
                "BlockValidation": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "ANY",
                            "sub_policy": "Writers"
                        }
                    },
                    "version": "0"
                },
                "Readers": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "ANY",
                            "sub_policy": "Readers"
                        }
                    },
                    "version": "0"
                },
                "Writers": {
                    "mod_policy": "Admins",
                    "policy": {
                        "type": 3,
                        "value": {
                            "rule": "ANY",
                            "sub_policy": "Writers"
                        }
                    },
                    "version": "0"
                }
            },
            "values": {
                "BatchSize": {
                    "mod_policy": "Admins",
                    "value": {
                        "absolute_max_bytes": 103809024,
                        "max_message_count": 100,
                        "preferred_max_bytes": 524288
                    },
                    "version": "0"
                },
                "BatchTimeout": {
                    "mod_policy": "Admins",
                    "value": {
                        "timeout": "30s"
                    },
                    "version": "0"
                },
                "Capabilities": {
                    "mod_policy": "Admins",
                    "value": {
                        "capabilities": {
                            "V1_4_2": {}
                        }
                    },
                    "version": "0"
                },
                "ChannelRestrictions": {
                    "mod_policy": "Admins",
                    "value": null,
                    "version": "0"
                },
                "ConsensusType": {
                    "mod_policy": "Admins",
                    "value": {
                        "metadata": {
                            "consenters": [
                                {
                                    "client_tls_cert": "...",
                                    "host": "orderer1.isprint.com",
                                    "port": 7050,
                                    "server_tls_cert": "..."
                                },
                                {
                                    "client_tls_cert": "...",
                                    "host": "orderer2.isprint.com",
                                    "port": 7050,
                                    "server_tls_cert": "..."
                                },
                                {
                                    "client_tls_cert": "...",
                                    "host": "orderer3.isprint.com",
                                    "port": 7050,
                                    "server_tls_cert": "..."
                                }
                            ],
                            "options": {
                                "election_tick": 10,
                                "heartbeat_tick": 1,
                                "max_inflight_blocks": 5,
                                "snapshot_interval_size": 20971520,
                                "tick_interval": "500ms"
                            }
                        },
                        "state": "STATE_NORMAL",
                        "type": "etcdraft"
                    },
                    "version": "0"
                }
            },
            "version": "0"
        }
    },
    "mod_policy": "Admins",
    "policies": {
        "Admins": {
            "mod_policy": "Admins",
            "policy": {
                "type": 3,
                "value": {
                    "rule": "MAJORITY",
                    "sub_policy": "Admins"
                }
            },
            "version": "0"
        },
        "Readers": {
            "mod_policy": "Admins",
            "policy": {
                "type": 3,
                "value": {
                    "rule": "ANY",
                    "sub_policy": "Readers"
                }
            },
            "version": "0"
        },
        "Writers": {
            "mod_policy": "Admins",
            "policy": {
                "type": 3,
                "value": {
                    "rule": "ANY",
                    "sub_policy": "Writers"
                }
            },
            "version": "0"
        }
    },
    "values": {
        "BlockDataHashingStructure": {
            "mod_policy": "Admins",
            "value": {
                "width": 4294967295
            },
            "version": "0"
        },
        "Capabilities": {
            "mod_policy": "Admins",
            "value": {
                "capabilities": {
                    "V1_4_3": {}
                }
            },
            "version": "0"
        },
        "Consortium": {
            "mod_policy": "Admins",
            "value": {
                "name": "SampleConsortium"
            },
            "version": "0"
        },
        "HashingAlgorithm": {
            "mod_policy": "Admins",
            "value": {
                "name": "SHA256"
            },
            "version": "0"
        },
        "OrdererAddresses": {
            "mod_policy": "/Channel/Orderer/Admins",
            "value": {
                "addresses": [
                    "orderer1.isprint.com:7050",
                    "orderer2.isprint.com:7050",
                    "orderer3.isprint.com:7050"
                ]
            },
            "version": "0"
        }
    },
    "version": "0"
},
"sequence": "2"
}

I have written a code snippet using JsonPath:

DocumentContext context = JsonPath.parse(json);
String pathOrg1MSP = "$.channel_group.groups.Application.groups.Org1MSP";
Map<String,Object> mapOrg1MSP = context.read(pathOrg1MSP);
Map<String,Object> mapOrg2MSP = new LinkedHashMap<String,Object>();
mapOrg1MSP.forEach((k,v) -> {
        mapOrg2MSP.put(k, v);
});
String pathOrg2MSP = "$.channel_group.groups.Application.groups";
context.put(pathOrg2MSP, "Org2MSP", mapOrg2MSP);

The intention is to create an exact clone first, then change whatever values need to be changed (peers, certs etc), and then splice it into the original Json.

  1. Would this achieve what I intend to do?
  2. What values would I need to change to prevent any possible conflicts with existing organizations?
user10931326
  • 787
  • 2
  • 8
  • 15

1 Answers1

0
  1. Generate crypto materials for Org2
  2. Generate Org2-specific configuration materials
  3. Fetch the latest config block from orderer, trim it down and convert it to JSON (I believe u have done this step already)
  4. Add Org2-specific configuration materials to the JSON
  5. Convert original JSON and newly edited JSON to protobuf format
  6. Compute difference between the new and original block (.pb files)
  7. Convert it to JSON format and add back header
  8. Convert it to protobuf format
  9. Sign transaction by Org1

For the detailed commands, you can refer to this official documentation. https://hyperledger-fabric.readthedocs.io/en/release-1.4/channel_update_tutorial.html