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

[GH-759] Channel Snapshot #791

Merged
merged 28 commits into from
Nov 26, 2018
Merged

[GH-759] Channel Snapshot #791

merged 28 commits into from
Nov 26, 2018

Conversation

gorbak25
Copy link
Contributor

This PR implements channel snapshots and tests for these transactions.
This was made on top of #789.

Resolves #759

Copy link
Contributor

@cytadela8 cytadela8 left a comment

Choose a reason for hiding this comment

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

Good code, but fixes needed.

@@ -246,9 +271,9 @@ defmodule Aecore.Channel.ChannelStateOnChain do
inspect(Poi.calculate_root_hash(poi))
}"}

channel.sequence >= offchain_tx.sequence ->
channel.sequence > offchain_tx.sequence ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the check changed? I don't think equal sequence is a valid slash.

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked in epoch. As stated in line 107 of aesc_utils.erl I believe we should have >= here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it in order to allow solo closing a channel which was snapshoted(E.g. Peers A and B open a channel, A transfers funds to B, peer B snapshots the state and then disappears). As we have the force progress transaction we can force an update and then solo close with the forced state, but this will require 3 txs instead of 2 txs.

@@ -221,8 +221,14 @@ defmodule Aecore.Channel.Tx.ChannelDepositTx do
!ChannelStateOnChain.active?(channel) ->
{:error, "#{__MODULE__}: Can't deposit from inactive channel."}

!ChannelStateOnChain.is_peer?(channel, depositing_account) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you move this check from ChannelStateOnChain.validate_deposit to transaction?

Copy link
Contributor Author

@gorbak25 gorbak25 Nov 20, 2018

Choose a reason for hiding this comment

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

In order to avoid passing the sender to the on chain channel code as it is used only in one place.

}) do
%ChannelStateOnChain{
channel
| sequence: sequence,

This comment was marked as resolved.

@thepiwo
Copy link
Collaborator

thepiwo commented Nov 22, 2018

@cytadela8 can you approve?
@d-velev could you review as well?

@cytadela8 cytadela8 removed the blocked label Nov 22, 2018
- offchain_tx - off chain transaction mutually signed by both parties of the channel
"""
defstruct [:channel_id, :offchain_tx]
use ExConstructor
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed I assume?

Copy link
Contributor

Choose a reason for hiding this comment

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

@grzegorz225 You might have copied this from some other code. We generally removed ExConstructor from many files as it only provides some functions that we don't use.

@@ -67,6 +68,11 @@ defmodule Aecore.Channel.Worker do
closed(tx)
end

def new_tx_mined(%SignedTx{data: %DataTx{type: ChannelSnapshotSoloTx}} = _tx) do
Copy link
Contributor

Choose a reason for hiding this comment

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

_tx not needed

Copy link
Contributor

@cytadela8 cytadela8 left a comment

Choose a reason for hiding this comment

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

Small comments, I just found while working with your code.

@@ -147,6 +147,31 @@ defmodule Aecore.Channel.ChannelStateOnChain do
{initiator_pubkey, responder_pubkey}
end

@spec is_peer?(ChannelStateOnChain.t(), Keys.pubkey()) :: boolean()
def is_peer?(
Copy link
Contributor

Choose a reason for hiding this comment

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

"is_" is not needed. Boolean-ness is represented by "?". This follows the convention we have in our code. (see: active?, settled?)

end

@spec is_peer_or_delegate?(ChannelStateOnChain.t(), Keys.pubkey()) :: boolean()
def is_peer_or_delegate?(
Copy link
Contributor

Choose a reason for hiding this comment

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

also remove "is_"

@@ -67,6 +68,11 @@ defmodule Aecore.Channel.Worker do
closed(tx)
end

def new_tx_mined(%SignedTx{data: %DataTx{type: ChannelSnapshotSoloTx}} = _tx) do
# ChannelSnapshotSoloTx requires no action
Copy link
Contributor

Choose a reason for hiding this comment

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

Untrue. You have snapshot sequence in ChannelStatePeer

@thepiwo thepiwo merged commit 1a5c469 into master Nov 26, 2018
@thepiwo thepiwo deleted the GH-759 branch November 30, 2018 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants