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

MultiPartyEscrow contract #39

Merged

Conversation

astroseger
Copy link
Collaborator

MultiPartEscrow contract. Unit tests for MultiPartEscrow contract. js interface for this contract for sender and recipient (in test/sign_mpe_funs.js).

@astroseger astroseger requested review from tiero and vsbogd September 28, 2018 15:10
@tiero tiero requested a review from vforvalerio87 September 28, 2018 15:36
require(amount <= channel.value);
require(msg.sender == channel.recipient);

//"this" will be added later
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this comment further.

@@ -0,0 +1,12 @@
let test1 = artifacts.require("./MultiPartyEscrow.sol");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose renaming it to something verbose.

@astroseger
Copy link
Collaborator Author

I will merge it tomorrow, if nobody is against it.

@vsbogd
Copy link
Member

vsbogd commented Oct 2, 2018

Looks good for me.


contract MultiPartyEscrow {

//it seems we don't need SafeMath
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need. When using the SafeMath library, an error will be thrown stopping the execution of the contract and it conforms to the existent codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using SafeMath for MultiPartyEscrow is a big question. I will open an Issue and explain why. And I don't understand your last part. If there is an error in the contract it must revert, there is not other possible behavior.... Ok we continue in an issue

Copy link
Collaborator

@tiero tiero Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean "codebase"? If it is signet/platform-contract then I am the first who consider using it (please make "grep SafeMath contracts/*"). And please use issue #45 for this discussion...

Copy link
Collaborator Author

@astroseger astroseger Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Marco have you read what I've wrote in #45 ? That we are already checking for it, But still I'm hesitating to use SafeMax ? What's the point to write it here?

struct PaymentChannel {
address sender; // The account sending payments.
address recipient; // The account receiving the payments.
uint256 replica_id; // id of particular service replica
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Style: I think we should adhere to the existent codebase (camelCase) and in general keep code style changes as separated PRs if needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should define the style... (I will follow it, even though I don't like camelCase :) ). I will open an Issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I mean it's not about personal preference. If we decide to refactor the style, let's do it in a separate merge request.

As a "golden" rule, we should follow closely the master practices/styles which already exists, to make it consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiero, do you mean some common Solidity code style practices? If so could you please share link to it at #43.

Copy link
Collaborator

@tiero tiero Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I mean the code already merged in master is the style to follow. Always.

It's better to change the majority of old code to adapt to this PR or make sure this looks consistent with the already merged code? ;)

If @pennachin wants to change the code style and he allows to spend time on that ok to me to work on #43, otherwise let's fix only this PR to match the codebase and move on.

Copy link
Collaborator Author

@astroseger astroseger Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define codestyle in #43 . I cannot fix codestyle without definition of codestyle... What exactly? Only names of public function or what? All those discussions are starting really pulling me backward..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, there are two separate tasks here:

  1. Merge this pull request
  2. Define code-style

The 1 cannot go through here, because we want a consistent code style. This PR has a different style introduced in naming variables/functions like this (name_of_var) instead of the existent nameOfVar camelCase style.

The 2 came out since (maybe) we want to change and write in stone the rules (in order to setup a solidity linter/formatter in CI I presume)

The 1 and 2 can go in parallel, for the 1 the most obvious and quicker solution to me would adhere to the existent codebase, and not the other way. Moreover, I do think it's better to isolate code style changes in a specific PR.

Copy link
Member

@vsbogd vsbogd Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiero , am I right that converting functions and variables names to camelCase will be enough for this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And camelCase is the "official" style advocated by the Solidity docs.

contracts/MultiPartyEscrow.sol Show resolved Hide resolved
contracts/MultiPartyEscrow.sol Show resolved Hide resolved
}


function isValidSignature_open_channel_replaysafe(address recipient, uint256 value, uint256 expiration, uint256 replica_id, uint256 message_nonce, bytes memory signature, address sender)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would decouple the logic of isValidSiganture and move the business logic where is used instead of having a specific function. They are both used once in the whole code, useless as specific helpers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree! And it make contract a little bit cheaper :) (35884 vs 36027 ) ... Will commit this evening. In airport now.

contracts/MultiPartyEscrow.sol Show resolved Hide resolved
{
require(msg.sender == channels[channel_id].sender);
require(now >= channels[channel_id].expiration);
_channel_sendback_and_reopen(channel_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange that we claim the timeout, mostly because the service provider is not reachable or trying to cheat, and we want to open back a channel. Should not be only closed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the main ideas of such design is that we can have single channel for each client/service provider pair and we don't have to close it. When one of the parties gets money then channel none is incremented and channel can be used again. @astroseger please correct me if I am wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but you agree that in this situation, most of the time the sender will not do business again with this recipient. Ok for me to leave the feature but at least we should emit an event at least. It's very important to keep track of this case, for reputation especially cc/ @pennachin (metaphorically, you are opting out your stake from the service provider)

Copy link
Collaborator Author

@astroseger astroseger Oct 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marco! It is the name of function which is confusing you. I will rename it to _channel_sendback_and_suspend . Because it reopen the channel but change value and expiration to zero. So in order to start to use it the client should put money in it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it is actually reopen ... so I will call the function _channel_sendback_and_reopen_suspended

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then.

@astroseger
Copy link
Collaborator Author

astroseger commented Oct 3, 2018

I've opened several issues and I've made several changes... It seems all questions have been answered.

@astroseger
Copy link
Collaborator Author

astroseger commented Oct 4, 2018

Ok guys... I will do the following steps

  1. I will remove open_channel_by_recipient logic for now, and will create an issue with discussion. We are not sure that this functionality will be adopted. So if we decide to adopt it, I will add it again.
  2. I will change the style (but Unfortunately it makes the code much less readable _channelSendbackAndReopenSuspended )
  3. I will merge
    If you'are against item 3. Please scream, but please think twice :)

@astroseger astroseger merged commit 2e52566 into singnet:master Oct 4, 2018
@astroseger astroseger mentioned this pull request Oct 4, 2018
@astroseger astroseger deleted the develop-multiparty-escrow-contracts branch October 4, 2018 14:58
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

Successfully merging this pull request may close these issues.

4 participants