Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendSignProposalを調べる #13

Closed
shohu opened this issue Jun 19, 2019 · 3 comments
Closed

sendSignProposalを調べる #13

shohu opened this issue Jun 19, 2019 · 3 comments

Comments

@shohu
Copy link
Owner

shohu commented Jun 19, 2019

No description provided.

@shohu
Copy link
Owner Author

shohu commented Jun 19, 2019

Channel.js

/**
 * Send signed transaction proposal to peer
 *
 * @param {SignedProposal} request signed endorse transaction proposal, this signed
 * proposal would be send to peer directly.
 * @param {number} timeout the timeout setting passed on sendSignedProposal
 */
async sendSignedProposal(request, timeout) {
  return Channel.sendSignedProposal(request, timeout);
}

/**
 * Send signed transaction proposal to peer
 *
 * @param {SignedProposal} request signed endorse transaction proposal, this signed
 * proposal would be send to peer directly.
 * @param {number} timeout the timeout setting passed on sendSignedProposal
 */
static async sendSignedProposal(request, timeout) {
  const responses = await client_utils.sendPeersProposal(request.targets, request.signedProposal, timeout);
  return responses;
}

client-utils.js

/*
 * This function will return one Promise when sending a proposal to many peers
 */
module.exports.sendPeersProposal = async (peers, proposal, timeout) => {
	let targets = peers;
	if (!Array.isArray(peers)) {
		targets = [peers];
	}
	// create array of promises mapping peers array to peer parameter
	// settle all the promises and return array of responses
	const promises = targets.map(async (peer) => {
		return peer.sendProposal(proposal, timeout);
	});
	const responses = [];
	const results = await settle(promises);
	results.forEach((result) => {
		if (result.isFulfilled()) {
			logger.debug(`sendPeersProposal - Promise is fulfilled: ${result.value()}`);
			responses.push(result.value());
		} else {
			logger.debug(`sendPeersProposal - Promise is rejected: ${result.reason()}`);
			responses.push(result.reason());
		}
	});
	return responses;
};

@shohu
Copy link
Owner Author

shohu commented Jun 19, 2019

sendPeersProposal は、どうも fabcar の queryByChaincode でも使われているため
offlineの時と、onlineの時で何がちがっているか調べる。

responseが変わる意味がわかるかもしれない

log挿入場所

module.exports.sendPeersProposal = async (peers, proposal, timeout) => {
	let targets = peers;
	if (!Array.isArray(peers)) {
		targets = [peers];
	}
	// create array of promises mapping peers array to peer parameter
	// settle all the promises and return array of responses
	const promises = targets.map(async (peer) => {
		return peer.sendProposal(proposal, timeout);
	});
	const responses = [];
	const results = await settle(promises);
	results.forEach((result) => {
		if (result.isFulfilled()) {
			logger.debug(`sendPeersProposal - Promise is fulfilled: ${result.value()}`);
			responses.push(result.value());
		} else {
			logger.debug(`sendPeersProposal - Promise is rejected: ${result.reason()}`);
			responses.push(result.reason());
		}
	});
	console.log('====sendPeersProposal==== responses', responses);
	console.log('====sendPeersProposal==== responses.response', responses[0].response.payload.toString());
	return responses;
};

fabcar online

[ { version: 1,
    timestamp: null,
    response:
     { status: 200,
       message: '',
       payload: <Buffer 22 5b 7b 5c 22 4b 65 79 5c 22 3a 5c 22 43 41 52 30 5c 22 2c 5c 22 52 65 63 6f 72 64 5c 22 3a 7b 5c 22 63 6f 6c 6f 72 5c 22 3a 5c 22 62 6c 75 65 5c 22 ... > },
    payload: <Buffer 0a 20 da 35 77 f8 75 b6 7b 7a fb 50 b2 e0 62 c9 91 c1 d7 ef eb ef da 09 40 8e 66 83 74 fa 04 af 61 53 12 8c 0d 0a c1 01 12 a6 01 0a 06 66 61 62 63 61 ... >,
    endorsement:
     { endorser: <Buffer 0a 07 4f 72 67 31 4d 53 50 12 aa 06 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 43 4b 44 43 43 41 63 ... >,
       signature: <Buffer 30 45 02 21 00 83 42 02 fe b0 27 45 a9 0b 1d b3 4a ed 75 d2 fc d2 12 49 e6 a3 23 ae 9d e5 66 1c 6e 60 2c 86 27 02 20 75 ba 17 b5 b4 ff 45 4f 6e 12 2c ... > },
    peer:
     { url: 'grpcs://localhost:7051',
       name: 'localhost:7051',
       options: [Object] } } ]
Query has completed, checking results

fabcar offline

[ { version: 1,
    timestamp: null,
    response:
     { status: 200,
       message: '',
       payload: <Buffer 22 5b 7b 5c 22 4b 65 79 5c 22 3a 5c 22 43 41 52 30 5c 22 2c 5c 22 52 65 63 6f 72 64 5c 22 3a 7b 5c 22 63 6f 6c 6f 72 5c 22 3a 5c 22 62 6c 75 65 5c 22 ... > },
    payload: <Buffer 0a 20 55 37 f5 fa c7 ce 0f 83 bf 82 45 a6 c4 22 c9 b9 e7 65 a6 c2 41 0a 04 60 72 ed e5 14 ca 4c 0b b2 12 8c 0d 0a c1 01 12 a6 01 0a 06 66 61 62 63 61 ... >,
    endorsement:
     { endorser: <Buffer 0a 07 4f 72 67 31 4d 53 50 12 aa 06 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 43 4b 44 43 43 41 63 ... >,
       signature: <Buffer 30 44 02 20 79 cd 4e 5d 79 cc 64 9a 5e 7b d6 96 a9 6f 01 21 0c 8d e3 54 16 1b a1 f0 38 61 d2 aa 7c 94 fb 0f 02 20 58 e1 63 66 8d 20 b8 86 d1 08 5b 5d ... > },
    peer:
     { url: 'grpcs://localhost:7051',
       name: 'localhost:7051',
       options: [Object] } } ]

とおもったら、いっしょのが返ってきたっぽい?
sendPeersProposal の段階ではデータ返ってきているが、
sendSignedTransaction の responseはちゃんと返ってきていないのは、、、なぜz?

以下場所で 
==== sendSignedProposal === Promise { }
になってしまう。これが原因。

	async sendSignedProposal(request, timeout) {
		const responses = Channel.sendSignedProposal(request, timeout);
		console.log('==== sendSignedProposal ===', responses);
		// console.log('1====sendSignedProposal==== responses.response', responses[0].response.payload.toString());
		return responses;
	}

@shohu
Copy link
Owner Author

shohu commented Jun 19, 2019

と、色々書いたが以下のメソッドのresponseで拾えていた 😓

  const proposalResponses = await channel.sendSignedProposal(sendSignedProposalReq)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant