Mtng
Mtng

Reputation: 61

Fabric Node SDK - Instantiation policy violation: signature set did not satisfy policy

I have a hyperledger fabric testnet with 2 orgs, 3 peers in org1 and 2 peers in org2. The peer0 of each organization is the anchor peer.

When I try to instantiate a chaincode I have the following error:

Error: instantiation policy violation: signature set did not satisfy policy

The code is the following

async function main() {
    try {

        // Create a new CA client for interacting with the CA.
        const caInfo = ccp.certificateAuthorities['ca.org1.example.com'];
        const caTLSCACerts = caInfo.tlsCACerts.pem;
        const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);

        // Create a new file system based wallet for managing identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet = new FileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);
        const enrollment = await ca.enroll({ enrollmentID: 'adminCA', enrollmentSecret: 'adminpw' });
        const identity = X509WalletMixin.createIdentity('org1MSP', enrollment.certificate, enrollment.key.toBytes());
        await wallet.import('adminCA', identity);
        console.log('Successfully enrolled admin user "admin" and imported it into the wallet');


        // Create a new gateway for connecting to our peer node.
        const gateway = new Gateway();
        await gateway.connect(ccpPath, { wallet, identity: 'adminCA', discovery: { enabled: true, asLocalhost: true } });



        let client = gateway.getClient()

        var cryptoSuite = Client.newCryptoSuite();
        cryptoSuite.setCryptoKeyStore(Client.newCryptoKeyStore({ path: '/tmp' }));
        client.setCryptoSuite(cryptoSuite);
        const pathCert = path.resolve('/Users/mtng/go1.10/src/github.com/hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/admincerts/[email protected]')

        const pathKey = path.resolve('/Users/mtng/go1.10/src/github.com/hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/0d0ed5f38a1084b1ca12d0836c0e4b011e8a97ca93d919a9d4d4275b147b3e30_sk')
        let cert = fs.readFileSync(pathCert)
        let pk = fs.readFileSync(pathKey)


        const channel = client.newChannel('channel')
        client.setAdminSigningIdentity(pk, cert, 'org1MSP')


        let targets = [];
        let json = peersConfig.peers
        for (var key in json) {
            console.log(json[key])
            let data = fs.readFileSync(json[key].tlsCACerts.path)
            let peer = client.newPeer(json[key].url, {
                pem: Buffer.from(data).toString(),
                'ssl-target-name-override': json[key].grpcOptions['ssl-target-name-override']
            })
            channel.addPeer(peer)
            targets.push(peer)

        }



        await channel.initialize({ discover: false })

        let request = {
            targets: targets,
            chaincodePath: 'chaincode_example02',
            chaincodeId: 'mycc2',
            chaincodeType: 'golang',
            chaincodeVersion: '1',
            channelName: ['channel']
        };
        const res = await client.installChaincode(request);

        const tx_id = client.newTransactionID();

        const requestIntantiate = {
            chaincodePath: 'chaincode_example02',
            chaincodeId: 'mycc2',
            chaincodeType: 'golang',
            chaincodeVersion: '1',
            channelName: ['channel'],
            fcn: 'init',
            args: ['a', '100', 'b', '200'],
            txId: tx_id,

            'endorsement-policy': {
                identities: [
                    { role: { name: "member", mspId: "org1MSP" } },
                ],
                policy: {
                    "1-of": [{ "signed-by": 0 }, { "signed-by": 1 }]
                }
            }


        }

        const resInst = await channel.sendInstantiateProposal(requestIntantiate)
        console.log(resInst)


    } catch (error) {
        console.error(`Failed to enroll admin user "admin": ${error}`);

        process.exit(1);
    }
}


Here's is my config file: https://gist.github.com/mtnieto/3442cbd5d2617fcfafcabbf13fb6953c

How can I solve this? Why is this happening?

Upvotes: 0

Views: 361

Answers (2)

Mtng
Mtng

Reputation: 61

It was necessary to use an admin parameter when you create the transaction id.

const tx_id = client.newTransactionID(true);

And also create a user with the admin certificates generated with the crypto-gen

    const pathCert = path.resolve('hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]')
    const pathKey = path.resolve('hf-dev/hyperledgerfabrictestnet/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/d52b5370d5fe1657cad43a3828978a2bebf528e838462c9236801e774229e311_sk')
    let cert = fs.readFileSync(pathCert)
    let pk = fs.readFileSync(pathKey)


 const user = await client.createUser({
        username: 'peerUser',
        mspid: 'org1MSP',
        cryptoContent: {
            privateKeyPEM: pk.toString('utf8'),
            signedCertPEM: cert.toString('utf8')
        }
    });

Upvotes: 1

Narendranath Reddy
Narendranath Reddy

Reputation: 4133

There is a slight mistake

check below

var request = {
  chaincodeId: this.chaincodeName,
  chaincodeType: this.chaincodeType,
  chaincodeVersion: this.chaincodeVersion,
  args: args,
  txId: tx_id,
  'collections-config': collectionsConfigPath
};

You must mention collections-config

Upvotes: 0

Related Questions