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

[WIP] Add broadcast confirm sig logic #188

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

wesgraham
Copy link
Contributor

@wesgraham wesgraham commented Mar 8, 2020

(Fixes #148)

Adds the ability to broadcast confirm signatures without spending inputs. Requesting feedback on signature requirements, confirmSigMsg struct, and information to be stored in datastore. Tests pending.

@wesgraham wesgraham requested a review from hamdiallam March 8, 2020 22:29
handlers/anteHandler.go Outdated Show resolved Hide resolved
handlers/anteHandler.go Outdated Show resolved Hide resolved
msgs/confirmSigMsg.go Outdated Show resolved Hide resolved

// GetSignBytes returns the Keccak256 hash of the transaction.
func (msg ConfirmSigMsg) GetSignBytes() []byte {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

I hope the sdk doesn't complain about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for include deposit message right now so i'm assuming we won't have a problem?

Copy link
Member

@hamdiallam hamdiallam left a comment

Choose a reason for hiding this comment

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

left first thoughts

@wesgraham
Copy link
Contributor Author

wesgraham commented Mar 17, 2020

Applying above changes. Also removing ability to broadcast arbitrary confirm sigs via flags for now as there is no natural mechanism for validating such signatures

@codecov-io
Copy link

Codecov Report

Merging #188 into develop will decrease coverage by 2.58%.
The diff coverage is 2.73%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #188      +/-   ##
===========================================
- Coverage    52.02%   49.44%   -2.59%     
===========================================
  Files           28       30       +2     
  Lines         1359     1430      +71     
===========================================
  Hits           707      707              
- Misses         538      609      +71     
  Partials       114      114              
Impacted Files Coverage Δ
handlers/confirmSigHandler.go 0.00% <0.00%> (ø)
msgs/confirmSigMsg.go 0.00% <0.00%> (ø)
msgs/errors.go 33.33% <0.00%> (-16.67%) ⬇️
handlers/anteHandler.go 53.12% <5.71%> (-18.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfea376...c828a0d. Read the comment docs.

return includeCmd
}

var broadcastSigsCmd = &cobra.Command{
Copy link
Member

Choose a reason for hiding this comment

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

Although the anteHandler for this msg will fail if the sig is wrong, we should do client side validation here before sending off the message.

Copy link
Member

@hamdiallam hamdiallam left a comment

Choose a reason for hiding this comment

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

Shaping up great! The flow looks correct to me.

}

// validate inputs/confirmation signatures if not a fee utxo or deposit utxo
if !input.IsDeposit() && !input.IsFee() {
Copy link
Member

Choose a reason for hiding this comment

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

If the input is a deposit or fee, we should not return sdk.Result{}. It should be an error. There are no confirm signature for these kinds of inputs. Otherwise this will get sent to the handler

return ErrInvalidSignature("invalid signature provided").Result()
}

_, ok := ds.GetOutput(ctx, input.Position)
Copy link
Member

Choose a reason for hiding this comment

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

do we need this if we're already doing GetTxWithPoisition?

if err != nil {
return ErrInvalidInput(fmt.Sprintf("failed to retrieve exit information on input, %v", in.Position)).Result()
} else if exited {
return ErrExitedInput(fmt.Sprintf("a parent of the input has exited. Position: %v", in.Position)).Result()
Copy link
Member

Choose a reason for hiding this comment

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

can we make this message better w.r.t confirm signatures? like 'cannot include confirm signatures of a input transaction that has exited..."

sdk "github.com/cosmos/cosmos-sdk/types"
)

// NewSpendHandler sets the inputs of a spend msg to spent and creates new
Copy link
Member

Choose a reason for hiding this comment

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

incorrect doc

return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
confirmSigMsg, ok := msg.(msgs.ConfirmSigMsg)
if !ok {
panic("Msg does not implement SpendMsg")
Copy link
Member

Choose a reason for hiding this comment

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

msg


for i := 0; i < len(tx1.Transaction.Inputs); i++ {
// TODO: Is TxIndex sufficient? Also should likely check output index?
if tx1.Transaction.Inputs[i].Position.TxIndex != confirmSigMsg.Input1.Position.TxIndex {
Copy link
Member

Choose a reason for hiding this comment

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

can we add an Equals method to Input and simply to if tx1.Transaction.Input[i].Position.Equals(...) { do the thing}.

Typically do not want to use continue. Should wrap the state updates within the if block for when it should happen. Makes it easier to read.

panic("Msg does not implement SpendMsg")
}

/* Get tx, update tx data with confirm sigs, and store updated tx object */
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing single comments like this. Can you break that up and comment the places where each point occurs


// SpendMsg implements the RLP interface through `Transaction`
type ConfirmSigMsg struct {
Input1 plasma.Input
Copy link
Member

Choose a reason for hiding this comment

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

do we have to restrict to 2 inputs. Why not include as many inputs as someone likes. []Input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to broadcast signatures onchain
3 participants