From 789a0743c595861a6e371aee7e7a376aa7c613d1 Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Mon, 18 May 2020 17:29:54 +0530 Subject: [PATCH 1/7] #309 - Concurrency ( state service and get token Support) --- escrow/state_service.proto | 11 +++++++ escrow/token_service.proto | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 escrow/token_service.proto diff --git a/escrow/state_service.proto b/escrow/state_service.proto index a2ce9aa5..d3c97119 100644 --- a/escrow/state_service.proto +++ b/escrow/state_service.proto @@ -50,6 +50,16 @@ message ChannelStateReply { // last signature sent by client with nonce = current_nonce - 1 bytes old_nonce_signature = 5; + + //If the client / user chooses to sign upfront , the planned amount in cogs will be indicative of this. + //For pay per use, this will be zero + uint64 planned_amount = 6; + + //If the client / user chooses to sign upfront , the usage amount in cogs will be indicative of how much of the + //planned amount has actually been used. + //For pay per use, this will be zero + uint64 usage_amount = 7; + } //Used to determine free calls available for a given user. @@ -79,3 +89,4 @@ message FreeCallStateReply { //Balance number of free calls available uint64 free_calls_available = 2; } + diff --git a/escrow/token_service.proto b/escrow/token_service.proto new file mode 100644 index 00000000..8b92d02d --- /dev/null +++ b/escrow/token_service.proto @@ -0,0 +1,62 @@ +syntax = "proto3"; + +package escrow; + +option java_package = "io.singularitynet.daemon.escrow"; +//It is expected that the user would call the GetChannelState to Determine the Current state of the Channel +//Based on the usage forecast, the user/client will have to sign for an amount L + U , where L is the last amount Signed +//and U is the amount based on expected usage. +//Please be aware that the Signing up an amount upfront ( Pre Paid) does come with a risk and hence the +//user must exercise caution on the amount signed specially with new service providers. +//If there is no need of making concurrent calls then you may consider pay per mode. +//Using a Token, the Client can now make concurrent calls, which was not supported previously with the pay per mode. +//However the pay per mode is a lot secure than the pre-paid mode. +service TokenService { + // GetToken method checks the Signature sent and returns a Token + // 1) The Signature is valid and has to be signed in the below format + //"__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount + //Signature is to let the Service Provider make a claim + // 2) Signed amount >= Last amount Signed. + //planned amount 10 , usage 5 , this signed 10 cogs + // if Signed amount == Last Signed amount , then check if planned_amount < used_amount + // if Signed amount > Last Signed amount , then update the planned amount = planned amount + Signed Amount + // if Signed amount < Last Signed amount , then an error is returned back stating invalid amount + // GetToken method in a way behaves as a renew Token too!. + rpc GetToken(TokenRequest) returns (TokenReply) {} + + + +} + +// TokenRequest is a request for getting a valid token. +message TokenRequest { + // channel_id contains id of the channel which state is requested. + uint64 channel_id = 1; + // current_nonce is a latest nonce of the payment channel. + uint64 current_nonce = 2; + //signed_amount is the amount signed by client with current_nonce + //it could be absent if none message was signed with current_nonce + uint64 signed_amount = 3; + // signature is a client signature of the message which contains + //"__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount + bytes signature = 4; + +} + +// TokenReply message contains a latest channel state. current_nonce and +message TokenReply { + // current_nonce is a latest nonce of the payment channel. + uint64 channel_id = 1; + + // current_signed_amount is a last amount which were signed by client with current_nonce + //it could be absent if none message was signed with current_nonce + bytes token = 2; + + //If the client / user chooses to sign upfront , the planned amount in cogs will be indicative of this. + uint64 planned_amount = 3; + + //If the client / user chooses to sign upfront , the used amount in cogs will be indicative of how much of the + //planned amount has actually been used. + uint64 used_amount = 4; + +} From ab397d5b8e00eb29354123607d6fa4dc539d7d30 Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Mon, 18 May 2020 17:31:21 +0530 Subject: [PATCH 2/7] #309 - Corrected typo from usage to used --- escrow/state_service.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escrow/state_service.proto b/escrow/state_service.proto index d3c97119..aa45e53c 100644 --- a/escrow/state_service.proto +++ b/escrow/state_service.proto @@ -58,7 +58,7 @@ message ChannelStateReply { //If the client / user chooses to sign upfront , the usage amount in cogs will be indicative of how much of the //planned amount has actually been used. //For pay per use, this will be zero - uint64 usage_amount = 7; + uint64 used_amount = 7; } From b036f2410dd9a547ed155088b680437214e1a16c Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Mon, 18 May 2020 17:39:32 +0530 Subject: [PATCH 3/7] #309 - Corrected typo in comment --- escrow/token_service.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/escrow/token_service.proto b/escrow/token_service.proto index 8b92d02d..074bd59c 100644 --- a/escrow/token_service.proto +++ b/escrow/token_service.proto @@ -35,7 +35,6 @@ message TokenRequest { // current_nonce is a latest nonce of the payment channel. uint64 current_nonce = 2; //signed_amount is the amount signed by client with current_nonce - //it could be absent if none message was signed with current_nonce uint64 signed_amount = 3; // signature is a client signature of the message which contains //"__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount From d537f934184b4cd9bb4d45f29db05d0b46ca09aa Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Wed, 20 May 2020 10:09:53 +0530 Subject: [PATCH 4/7] #309 - Corrected typo in comment --- escrow/token_service.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/escrow/token_service.proto b/escrow/token_service.proto index 074bd59c..c32dd69d 100644 --- a/escrow/token_service.proto +++ b/escrow/token_service.proto @@ -47,7 +47,6 @@ message TokenReply { // current_nonce is a latest nonce of the payment channel. uint64 channel_id = 1; - // current_signed_amount is a last amount which were signed by client with current_nonce //it could be absent if none message was signed with current_nonce bytes token = 2; From 066365eaa27c8f921bbfdf894b26d1b10ba81334 Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Wed, 20 May 2020 15:38:18 +0530 Subject: [PATCH 5/7] #309 - Corrected typo in formula in the comments section --- escrow/token_service.proto | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/escrow/token_service.proto b/escrow/token_service.proto index c32dd69d..9c7bb57d 100644 --- a/escrow/token_service.proto +++ b/escrow/token_service.proto @@ -17,15 +17,10 @@ service TokenService { //"__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount //Signature is to let the Service Provider make a claim // 2) Signed amount >= Last amount Signed. - //planned amount 10 , usage 5 , this signed 10 cogs // if Signed amount == Last Signed amount , then check if planned_amount < used_amount - // if Signed amount > Last Signed amount , then update the planned amount = planned amount + Signed Amount + // if Signed amount > Last Signed amount , then update the planned amount = Signed Amount // if Signed amount < Last Signed amount , then an error is returned back stating invalid amount // GetToken method in a way behaves as a renew Token too!. - rpc GetToken(TokenRequest) returns (TokenReply) {} - - - } // TokenRequest is a request for getting a valid token. From cd0cc93967f44612bae2000ab0e2040a69e8b7af Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Wed, 20 May 2020 16:00:14 +0530 Subject: [PATCH 6/7] #309 - Removed confusing comment --- escrow/token_service.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/escrow/token_service.proto b/escrow/token_service.proto index 9c7bb57d..04e4f1d8 100644 --- a/escrow/token_service.proto +++ b/escrow/token_service.proto @@ -19,7 +19,6 @@ service TokenService { // 2) Signed amount >= Last amount Signed. // if Signed amount == Last Signed amount , then check if planned_amount < used_amount // if Signed amount > Last Signed amount , then update the planned amount = Signed Amount - // if Signed amount < Last Signed amount , then an error is returned back stating invalid amount // GetToken method in a way behaves as a renew Token too!. } From a1af91e3063fc1813753f2356353da0b34940357 Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Fri, 22 May 2020 14:52:35 +0530 Subject: [PATCH 7/7] #309 -we need authorize user each time when token is requested. --- escrow/token_service.proto | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/escrow/token_service.proto b/escrow/token_service.proto index 04e4f1d8..156f2c49 100644 --- a/escrow/token_service.proto +++ b/escrow/token_service.proto @@ -6,7 +6,7 @@ option java_package = "io.singularitynet.daemon.escrow"; //It is expected that the user would call the GetChannelState to Determine the Current state of the Channel //Based on the usage forecast, the user/client will have to sign for an amount L + U , where L is the last amount Signed //and U is the amount based on expected usage. -//Please be aware that the Signing up an amount upfront ( Pre Paid) does come with a risk and hence the +//Please be aware that the Signing up an amount upfront ( Pre Paid) does come with a risk and hence the //user must exercise caution on the amount signed specially with new service providers. //If there is no need of making concurrent calls then you may consider pay per mode. //Using a Token, the Client can now make concurrent calls, which was not supported previously with the pay per mode. @@ -20,6 +20,10 @@ service TokenService { // if Signed amount == Last Signed amount , then check if planned_amount < used_amount // if Signed amount > Last Signed amount , then update the planned amount = Signed Amount // GetToken method in a way behaves as a renew Token too!. + rpc GetToken(TokenRequest) returns (TokenReply) {} + + + } // TokenRequest is a request for getting a valid token. @@ -30,9 +34,12 @@ message TokenRequest { uint64 current_nonce = 2; //signed_amount is the amount signed by client with current_nonce uint64 signed_amount = 3; - // signature is a client signature of the message which contains - //"__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount + // Signature is a client signature of the message which contains 2 parts + //Part 1 : MPE Signature "__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount + //Part 2 : Current Block Number bytes signature = 4; + //current block number (signature will be valid only for short time around this block number) + uint64 current_block = 5; }