How can I send the update channel configuration request to the Orderer using node SDK?

荒凉一梦 提交于 2020-06-28 05:12:02

问题


There are 03 main phases in the process of updating the channel configuration:

  • (1) Get the latest configuration from the Orderer.
  • (2) Modify the configuration.
  • (3) Sign and send a transaction to the Orderer to update channel configuration.

I got an error at step (3) while trying to call updateChannel() function which is:

{ status: 'BAD_REQUEST',

info: 'error authorizing update: error validating DeltaSet: policy for [Value] /Channel/Orderer/BatchSize not satisfied: Failed to reach implicit threshold of 1 sub-policies, required 1 remaining' }

I followed the code from hyperledger-sdk-node repo about Channel update here

The policy of the Orderer of the network looks like this (I'm not sure about the problem I've got here)

# Policies defines the set of policies at this level of the config tree
# For Orderer policies, their canonical path is
#   /Channel/Orderer/<PolicyName>
Policies:
    Readers:
        Type: ImplicitMeta
        Rule: "ANY Readers"
    Writers:
        Type: ImplicitMeta
        Rule: "ANY Writers"
    Admins:
        Type: ImplicitMeta
        Rule: "MAJORITY Admins"
    # BlockValidation specifies what signatures must be included in the block
    # from the orderer for the peer to validate it.
    BlockValidation:
        Type: ImplicitMeta
        Rule: "ANY Writers"

More about the relevant code:

    let signatures = [];
    signatures.push(client.signChannelConfig(config_proto));


    let request = {
        name: channelName,
        // orderer: channel.getOrderer("orderer.example.com"), // Do I really need this?
        config: config_proto, // response from requesting configtxlator/compute
        txId: client.newTransactionID(),
        signatures: signatures
    };

    try {
        let result = await client.updateChannel(request); // ERROR HERE
        console.log("result", result);
    } catch (error) {
        console.log(error);
    }

If you need more information, just tell me! Any ideas should be helpful


回答1:


I found a way to make this thing works!

In my case, I want to modify the BatchSize property of the orderer's configuration, which requires the signatures of a majority of the ordering organizations’ admins (more detail).

After the modification is completed, I need to sign the request by the orderer's admin.

The following code includes:

(1) Get the key and certificate of orderer's admin:

const keyPath = path.join(__dirname, '../../fabric/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore');
const keyPEM = Buffer.from(readAllFiles(keyPath)[0]).toString();
const certPath = path.join(__dirname, '../../fabric/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/signcerts');
const certPEM = readAllFiles(certPath)[0];

(2) Assign signing identity to client:

client.setAdminSigningIdentity(keyPEM.toString(), certPEM.toString(), "OrdererMSP");

Now it's ready to be signed and send to orderer!

let signatures = [];
signatures.push(client.signChannelConfig(config_proto));

let request = {
    name: channelName,
    config: config_proto, // response from requesting configtxlator/compute
    txId: client.newTransactionID(),
    signatures: signatures
};

try {
    let result = await client.updateChannel(request);
    console.log("result", result);
} catch (error) {
    console.log(error);
}

readAllFiles function:

function readAllFiles(dir) {
    const files = fs.readdirSync(dir);
    const certs = [];
    files.forEach((file_name) => {
        const file_path = path.join(dir, file_name);
        logger.debug(' looking at file ::' + file_path);
        const data = fs.readFileSync(file_path);
        certs.push(data);
    });
    return certs;
}


来源:https://stackoverflow.com/questions/55416155/how-can-i-send-the-update-channel-configuration-request-to-the-orderer-using-nod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!