如何使用 Node SDK 向 Orderer 发送更新通道配置请求?

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

更新频道配置的过程中有03个主要阶段:

我在第 (3) 步尝试调用 updateChannel() 函数时遇到错误:

{ 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' }

我遵循了 hyperledger-sdk-node repo 中关于频道更新的代码 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"

更多相关代码:

    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);
    }

如果您需要更多信息,请告诉我!任何想法都应该有所帮助

我找到了让这个东西起作用的方法!

在我的例子中,我想修改订购者配置的BatchSize 属性,这需要大多数订购组织的管理员(more detail)的签名。

修改完成后,我需要订购者的管理员签署请求

以下代码包括:

(1) 获取orderer管理员的keycertificate:

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) 将签名身份分配给 client:

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

现在可以签名并发送给订购者了!

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 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;
}