-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
[GH-491] Channel snapshot
There was a problem hiding this 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 -> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) -> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
@cytadela8 can you approve? |
- offchain_tx - off chain transaction mutually signed by both parties of the channel | ||
""" | ||
defstruct [:channel_id, :offchain_tx] | ||
use ExConstructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed I assume?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_tx not needed
There was a problem hiding this 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?( |
There was a problem hiding this comment.
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?( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
This PR implements channel snapshots and tests for these transactions.
This was made on top of #789.
Resolves #759