-
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-757] Add delegates to Channel.Worker #809
base: master
Are you sure you want to change the base?
Conversation
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.
looks good to me, didn't check in detail
@@ -779,6 +818,10 @@ defmodule Aecore.Channel.ChannelStatePeer do | |||
Retrieves our offchain account balance from the latest offchain chainstate | |||
""" | |||
@spec our_offchain_account_balance(ChannelStatePeer.t()) :: non_neg_integer() | |||
def our_offchain_account_balance(%ChannelStatePeer{role: :delegate}) do | |||
throw({:error, "#{__MODULE__}: Delagate doesn't have a balance"}) |
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.
Are the throws handled anywhere and can they be replaced with regular {:error, _} returns?
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.
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.
This should only throw due to programmer error. It doesn't make sense to take a balance of delegate. It makes even less sens to get foreign_offchain_account_balance
when ChannelStatePeer is for 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.
We use this functions only in places where it's know the ChannelStatePeer.role is not 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.
Good code, some small typos.
def receive_half_signed_tx(_, _, _, _opts \\ %{}) | ||
|
||
def receive_half_signed_tx(%ChannelStatePeer{role: :delegate}, _, _, _) do | ||
{:error, "#{__MODULE__}: Deleagte can't handle half_signed_txs"} |
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.
Deleagte -> Delegate
def receive_half_signed_tx( | ||
%ChannelStatePeer{fsm_state: :open} = peer_state, | ||
tx, | ||
privkey, | ||
opts \\ %{} | ||
opts |
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.
By default no additional options should be passed for update validation.
@@ -927,6 +978,10 @@ defmodule Aecore.Channel.ChannelStatePeer do | |||
{non_neg_integer(), non_neg_integer()}, | |||
Keys.sign_priv_key() | |||
) :: {:ok, ChannelStatePeer.t(), SignedTx.t()} | error() | |||
def receive_close_tx(%ChannelStatePeer{role: :delegate}, _, _, _, _) do | |||
{:error, "#{__MODULE__}: Deleagte can't receive close tx"} |
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.
Deleagte -> Delegate
@@ -1002,6 +1057,10 @@ defmodule Aecore.Channel.ChannelStatePeer do | |||
non_neg_integer(), | |||
Keys.sign_priv_key() | |||
) :: {:ok, ChannelStatePeer.t(), SignedTx.t()} | error() | |||
def solo_close(%ChannelStatePeer{role: :delegate}, _, _, _) do | |||
{:error, "#{__MODULE__}: Delagate can't solo close"} |
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.
Delagate -> Delegate
@@ -1060,7 +1125,7 @@ defmodule Aecore.Channel.ChannelStatePeer do | |||
poi: dispute_poi_for_latest_state(peer_state), | |||
offchain_tx: ChannelTransaction.dispute_payload(most_recent_tx) | |||
}, | |||
our_pubkey(peer_state), | |||
pubkey, |
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.
If the role is :initiator or :responder we should check that pubkey == our_pubkey(peer_state)
@@ -1090,6 +1156,7 @@ defmodule Aecore.Channel.ChannelStatePeer do | |||
}, | |||
fee, | |||
nonce, | |||
pubkey, |
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.
Same as above
@@ -1180,6 +1251,10 @@ defmodule Aecore.Channel.ChannelStatePeer do | |||
""" | |||
@spec settle(ChannelStatePeer.t(), non_neg_integer(), non_neg_integer(), Keys.sign_priv_key()) :: | |||
{:ok, SignedTx.t()} | error() | |||
def settle(%ChannelStatePeer{role: :delegate}, _, _, _) do | |||
{:error, "#{__MODULE__}: Deleagte can't settle"} |
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.
Deleagte -> Delegate
Resolves #757