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

Update auth cli commands #6717

Merged
merged 72 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9b4a4a1
add utils
sahith-narahari Jul 13, 2020
eaeef54
update sign cmd
sahith-narahari Jul 14, 2020
b2c8997
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 14, 2020
5abd7f1
update multisign cmd
sahith-narahari Jul 14, 2020
0a80caa
Merge branch 'sahith/update-auth-cli' of github.com:cosmos/cosmos-sdk…
sahith-narahari Jul 14, 2020
c2b4cc7
update sign batch cmd
sahith-narahari Jul 14, 2020
d9bbef8
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 15, 2020
d1eb8c1
update genutil cmd
sahith-narahari Jul 15, 2020
2d5335b
add wrap tx builder
sahith-narahari Jul 16, 2020
cc2b7e0
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 18, 2020
688e9cd
update gentx cli
sahith-narahari Jul 19, 2020
d4cbf42
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 19, 2020
425cbfe
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 19, 2020
27a57a5
Merge branch 'sahith/update-auth-cli' of github.com:cosmos/cosmos-sdk…
sahith-narahari Jul 19, 2020
64f7aaf
update validate sigs cmd
sahith-narahari Jul 19, 2020
987af37
fix lint
sahith-narahari Jul 19, 2020
167df15
add flag reader to cli
sahith-narahari Jul 19, 2020
8f82734
update marshaler for batchscan
sahith-narahari Jul 19, 2020
baebff4
add register query server
sahith-narahari Jul 19, 2020
ed36414
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 19, 2020
3122b59
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 20, 2020
57c8798
update to master
sahith-narahari Jul 20, 2020
39bc7f4
remove depricated methods
sahith-narahari Jul 20, 2020
1afa4d3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 20, 2020
d101c34
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 21, 2020
012e320
fix keyring issue
sahith-narahari Jul 21, 2020
e955ca6
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 23, 2020
3dec8f7
update wraptx
sahith-narahari Jul 23, 2020
7a42cfe
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 23, 2020
ac46abe
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 24, 2020
ff733fc
Fix batch scan
sahith-narahari Jul 24, 2020
30bca25
fix register interfaces issue
sahith-narahari Jul 24, 2020
b390579
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 25, 2020
695b77d
update printOutput
sahith-narahari Jul 27, 2020
4be2e51
Update Validate Sigs test
sahith-narahari Jul 27, 2020
b4f8c77
Merge branch 'master' into sahith/update-auth-cli
aaronc Jul 27, 2020
6fe5838
Merge branch 'master' into sahith/update-auth-cli
aaronc Jul 27, 2020
467d692
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into sa…
aaronc Jul 27, 2020
3a0efa5
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 27, 2020
6d3297e
WIP on signature JSON
aaronc Jul 27, 2020
15613cf
Merge remote-tracking branch 'origin/sahith/update-auth-cli' into sah…
aaronc Jul 27, 2020
4f2b71a
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into sa…
aaronc Jul 27, 2020
819aa66
Cleanup
aaronc Jul 27, 2020
07f22b2
Cleanup
aaronc Jul 27, 2020
e004e1b
Test fixes
aaronc Jul 27, 2020
1fe8088
Test fixes
aaronc Jul 27, 2020
2e2099d
Merge branch 'master' into sahith/update-auth-cli
aaronc Jul 27, 2020
88bdb62
Fixes
aaronc Jul 27, 2020
9f04601
WIP on tests
aaronc Jul 28, 2020
013c481
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/upd…
sahith-narahari Jul 28, 2020
1252fbf
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 28, 2020
72d3982
Fix gov tests
sahith-narahari Jul 28, 2020
f95810a
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 28, 2020
28bbc0f
fix lint
sahith-narahari Jul 28, 2020
5aa68e7
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 28, 2020
62ff121
fix MultiSign tests
sahith-narahari Jul 28, 2020
5b3c906
Merge branch 'sahith/update-auth-cli' of github.com:cosmos/cosmos-sdk…
sahith-narahari Jul 28, 2020
6c1a0fa
fix tests
sahith-narahari Jul 28, 2020
29dab69
refactor tests
sahith-narahari Jul 28, 2020
750c5ac
Cleanup
aaronc Jul 29, 2020
074ee7b
Merge branch 'master' into sahith/update-auth-cli
aaronc Jul 29, 2020
0c94f78
Merge branch 'master' into sahith/update-auth-cli
sahith-narahari Jul 29, 2020
7771328
Address review comments
sahith-narahari Jul 29, 2020
423cbcb
Update encode
sahith-narahari Jul 29, 2020
d9b15df
Merge branch 'master' into sahith/update-auth-cli
aaronc Jul 29, 2020
0136c11
Test fix
aaronc Jul 29, 2020
2073e3f
Rename SignData func
sahith-narahari Jul 29, 2020
af89c16
Fix lint
sahith-narahari Jul 29, 2020
c5d7181
Merge branch 'master' into sahith/update-auth-cli
aaronc Jul 29, 2020
c6a7353
Fix lint
sahith-narahari Jul 29, 2020
ecf0679
Revert ReadTxCommandFlags
aaronc Jul 29, 2020
8a4c583
Merge remote-tracking branch 'origin/sahith/update-auth-cli' into sah…
aaronc Jul 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,47 @@ func ReadTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
return clientCtx, err
}

genOnly, _ := flagSet.GetBool(flags.FlagGenerateOnly)
clientCtx = clientCtx.WithGenerateOnly(genOnly)
if flagSet.Changed(flags.FlagGenerateOnly) {
aaronc marked this conversation as resolved.
Show resolved Hide resolved
genOnly, _ := flagSet.GetBool(flags.FlagGenerateOnly)
clientCtx = clientCtx.WithGenerateOnly(genOnly)

dryRun, _ := flagSet.GetBool(flags.FlagDryRun)
clientCtx = clientCtx.WithSimulation(dryRun)
}

offline, _ := flagSet.GetBool(flags.FlagOffline)
clientCtx = clientCtx.WithOffline(offline)
if flagSet.Changed(flags.FlagDryRun) {
dryRun, _ := flagSet.GetBool(flags.FlagDryRun)
clientCtx = clientCtx.WithSimulation(dryRun)
}

useLedger, _ := flagSet.GetBool(flags.FlagUseLedger)
clientCtx = clientCtx.WithUseLedger(useLedger)
if flagSet.Changed(flags.FlagOffline) {
offline, _ := flagSet.GetBool(flags.FlagOffline)
clientCtx = clientCtx.WithOffline(offline)
}

bMode, _ := flagSet.GetString(flags.FlagBroadcastMode)
clientCtx = clientCtx.WithBroadcastMode(bMode)
if flagSet.Changed(flags.FlagUseLedger) {
useLedger, _ := flagSet.GetBool(flags.FlagUseLedger)
clientCtx = clientCtx.WithUseLedger(useLedger)
}

skipConfirm, _ := flagSet.GetBool(flags.FlagSkipConfirmation)
clientCtx = clientCtx.WithSkipConfirmation(skipConfirm)
if flagSet.Changed(flags.FlagBroadcastMode) {
bMode, _ := flagSet.GetString(flags.FlagBroadcastMode)
clientCtx = clientCtx.WithBroadcastMode(bMode)
}

if flagSet.Changed(flags.FlagSkipConfirmation) {
skipConfirm, _ := flagSet.GetBool(flags.FlagSkipConfirmation)
clientCtx = clientCtx.WithSkipConfirmation(skipConfirm)

from, _ := flagSet.GetString(flags.FlagFrom)
fromAddr, fromName, err := GetFromFields(clientCtx.Keyring, from, clientCtx.GenerateOnly)
if err != nil {
return clientCtx, err
}

clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName)
if flagSet.Changed(flags.FlagFrom) {
from, _ := flagSet.GetString(flags.FlagFrom)
fromAddr, fromName, err := GetFromFields(clientCtx.Keyring, from, clientCtx.GenerateOnly)
if err != nil {
return clientCtx, err
}

clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName)
}

return clientCtx, nil
}
Expand Down
11 changes: 11 additions & 0 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ func (ctx Context) WithInterfaceRegistry(interfaceRegistry codectypes.InterfaceR
return ctx
}

// PrintString prints the raw string to ctx.Output or os.Stdout
func (ctx Context) PrintString(str string) error {
writer := ctx.Output
if writer == nil {
writer = os.Stdout
}

_, err := writer.Write([]byte(str))
return err
}

// PrintOutput outputs toPrint to the ctx.Output based on ctx.OutputFormat which is
// either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint
// will be JSON encoded using ctx.JSONMarshaler. An error is returned upon failure.
Expand Down
11 changes: 11 additions & 0 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,14 @@ func (f Factory) WithSimulateAndExecute(sim bool) Factory {
f.simulateAndExecute = sim
return f
}

// SignMode returns the sign mode configured in the Factory
func (f Factory) SignMode() signing.SignMode {
return f.signMode
}

// WithSignMode returns a copy of the Factory with an updated sign mode value.
func (f Factory) WithSignMode(mode signing.SignMode) Factory {
f.signMode = mode
return f
}
7 changes: 6 additions & 1 deletion client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ func GenerateTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
return err
}

return clientCtx.PrintOutput(tx.GetTx())
json, err := clientCtx.TxConfig.TxJSONEncoder()(tx.GetTx())
if err != nil {
return err
}

return clientCtx.PrintString(fmt.Sprintf("%s\n", json))
}

// BroadcastTx attempts to generate, sign and broadcast a transaction with the
Expand Down
2 changes: 2 additions & 0 deletions client/tx_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type (
TxDecoder() sdk.TxDecoder
TxJSONEncoder() sdk.TxEncoder
TxJSONDecoder() sdk.TxDecoder
MarshalSignatureJSON([]signingtypes.SignatureV2) ([]byte, error)
UnmarshalSignatureJSON([]byte) ([]signingtypes.SignatureV2, error)
}

// TxConfig defines an interface a client can utilize to generate an
Expand Down
4 changes: 3 additions & 1 deletion codec/proto_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ type ProtoCodec struct {
anyUnpacker types.AnyUnpacker
}

func NewProtoCodec(anyUnpacker types.AnyUnpacker) Marshaler {
var _ Marshaler = &ProtoCodec{}

func NewProtoCodec(anyUnpacker types.AnyUnpacker) *ProtoCodec {
return &ProtoCodec{anyUnpacker: anyUnpacker}
}

Expand Down
3 changes: 3 additions & 0 deletions crypto/types/multisig/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type PubKey interface {

// GetPubKeys returns the crypto.PubKey's nested within the multi-sig PubKey
GetPubKeys() []crypto.PubKey

// GetThreshold returns the threshold number of signatures that must be obtained to verify a signature.
GetThreshold() uint
}

// GetSignBytesFunc defines a function type which returns sign bytes for a given SignMode or an error.
Expand Down
5 changes: 5 additions & 0 deletions crypto/types/multisig/threshold_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ func (pk PubKeyMultisigThreshold) Equals(other crypto.PubKey) bool {
}
return true
}

// GetThreshold implements the PubKey.GetThreshold method
func (pk PubKeyMultisigThreshold) GetThreshold() uint {
return pk.K
}
48 changes: 48 additions & 0 deletions proto/cosmos/tx/signing/signing.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";
package cosmos.tx.signing;

import "cosmos/crypto/crypto.proto";

option go_package = "github.com/cosmos/cosmos-sdk/types/tx/signing";

// SignMode represents a signing mode with its own security guarantees
Expand All @@ -20,3 +22,49 @@ enum SignMode {
// Amino JSON and will be removed in the future
SIGN_MODE_LEGACY_AMINO_JSON = 127;
}

// SignatureDescriptors wraps multiple SignatureDescriptor's.
message SignatureDescriptors {
// signatures are the signature descriptors
repeated SignatureDescriptor signatures = 1;
}

// SignatureDescriptor is a convenience type which represents the full data for a
// signature including the public key of the signer, signing modes and the signature
// itself. It is primarily used for coordinating signatures between clients.
message SignatureDescriptor {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is super similar to SignatureV2. Could we remove SignatureV2 and use this one everywhere?

Copy link
Member

@aaronc aaronc Jul 29, 2020

Choose a reason for hiding this comment

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

That's fine we can. But it will probably be a decent size refactor. Are you fine with that in this PR?

// public_key is the public key of the signer
cosmos.crypto.PublicKey public_key = 1;

Data data = 2;

// Data represents signature data
message Data {
// sum is the oneof that specifies whether this represents single or multi-signature data
oneof sum {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have message ModeInfo, and if I understand this, this is ModeInfo+Signature. I'm still not 100% aware of protobuf extending types and such, but is there a way to use ModeInfo?

Copy link
Member

@aaronc aaronc Jul 29, 2020

Choose a reason for hiding this comment

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

Not without adding a field on ModeInfo that will be unused in transactions. The challenge is that you still need to distinguish between single and multisigs.

// single represents a single signer
Single single = 1;

// multi represents a multisig signer
Multi multi = 2;
}

// Single is the signature data for a single signer
message Single {
// mode is the signing mode of the single signer
cosmos.tx.signing.SignMode mode = 1;

// signature is the raw signature bytes
bytes signature = 2;
}

// Multi is the signature data for a multisig public key
message Multi {
// bitarray specifies which keys within the multisig are signing
cosmos.crypto.CompactBitArray bitarray = 1;

// signatures is the signatures of the multi-signature
repeated Data signatures = 2;
}
}
}
8 changes: 4 additions & 4 deletions simapp/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
cdc := codec.New()
amino := codec.New()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewHybridCodec(cdc, interfaceRegistry)
txGen := tx.NewTxConfig(interfaceRegistry, std.DefaultPublicKeyCodec{}, tx.DefaultSignModeHandler())
marshaler := codec.NewHybridCodec(amino, interfaceRegistry)
txGen := tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), std.DefaultPublicKeyCodec{}, tx.DefaultSignModeHandler())

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txGen,
Amino: cdc,
Amino: amino,
}
}
3 changes: 1 addition & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"testing"
"time"

"github.com/cosmos/cosmos-sdk/client/tx"

"github.com/stretchr/testify/require"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
Expand All @@ -29,6 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
Expand Down
37 changes: 37 additions & 0 deletions types/tx/sig_desc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 66 additions & 1 deletion types/tx/signing/signature.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package signing

import "github.com/tendermint/tendermint/crypto"
import (
"fmt"

"github.com/tendermint/tendermint/crypto"
)

// SignatureV2 is a convenience type that is easier to use in application logic
// than the protobuf SignerInfo's and raw signature bytes. It goes beyond the
Expand All @@ -15,3 +19,64 @@ type SignatureV2 struct {
// the signatures themselves for either single or multi-signatures.
Data SignatureData
}

// SignatureDataToSignatureDescriptorData converts a SignatureData to SignatureDescriptor_Data.
// SignatureDescriptor_Data is considered an encoding type whereas SignatureData is used for
// business logic.
func SignatureDataToSignatureDescriptorData(data SignatureData) *SignatureDescriptor_Data {
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I would be happy to remove the SignatureData interface (which is just an abstraction to represent oneof SingleSignatureData | MultiSignatureData), and just use the concrete type SignatureDescriptor everywhere in the code

Copy link
Contributor

Choose a reason for hiding this comment

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

I do agree here. I'd go with what @amaurymartiny stated or at the very least, change the nomenclature because it's confusing and the types clobber each other.

Copy link
Member

Choose a reason for hiding this comment

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

What if for the time-being we rename this function to SignatureDataToProto or something like that?

And then maybe in a future PR we just have a single proto generated SignatureData that is used everywhere as @amaurymartiny is suggesting?

This is an example of different encoding/application types btw. I've always questioned that philosophy because of the amount of duplication... Anyway, I think this is a concrete example of that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

SignatureDataToProto is bit confusing as well. I suggest to keep it as it is now and unblock this PR, and address this in a followup PR as @amaurymartiny suggesting

Copy link
Member

Choose a reason for hiding this comment

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

Is that okay @alexanderbez ? It would be good to get a decision either way because this is one of the last critical pieces to enabling proto tx as the default.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we leave it as-is, it's super confusing IMHO. I'd prefer SignatureDataToProto TBH. You're converting a domain-type to a wire-type (i.e. Proto).

Copy link
Member

Choose a reason for hiding this comment

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

Okay, so how about we go with SignatureDataTo/FromProto here? And as a follow-up @amaurymartiny you'll take a look at possible improvements?

Copy link
Contributor

Choose a reason for hiding this comment

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

that sgtm 👍

switch data := data.(type) {
case *SingleSignatureData:
return &SignatureDescriptor_Data{
Sum: &SignatureDescriptor_Data_Single_{
Single: &SignatureDescriptor_Data_Single{
Mode: data.SignMode,
Signature: data.Signature,
},
},
}
case *MultiSignatureData:
descDatas := make([]*SignatureDescriptor_Data, len(data.Signatures))

for j, d := range data.Signatures {
descDatas[j] = SignatureDataToSignatureDescriptorData(d)
}

return &SignatureDescriptor_Data{
Sum: &SignatureDescriptor_Data_Multi_{
Multi: &SignatureDescriptor_Data_Multi{
Bitarray: data.BitArray,
Signatures: descDatas,
},
},
}
default:
panic(fmt.Errorf("unexpected case %+v", data))
}
}

// SignatureDescriptorDataToSignatureData converts a SignatureDescriptor_Data to SignatureData.
// SignatureDescriptor_Data is considered an encoding type whereas SignatureData is used for
// business logic.
func SignatureDescriptorDataToSignatureData(descData *SignatureDescriptor_Data) SignatureData {
switch descData := descData.Sum.(type) {
case *SignatureDescriptor_Data_Single_:
return &SingleSignatureData{
SignMode: descData.Single.Mode,
Signature: descData.Single.Signature,
}
case *SignatureDescriptor_Data_Multi_:
multi := descData.Multi
datas := make([]SignatureData, len(multi.Signatures))

for j, d := range multi.Signatures {
datas[j] = SignatureDescriptorDataToSignatureData(d)
}

return &MultiSignatureData{
BitArray: multi.Bitarray,
Signatures: datas,
}
default:
panic(fmt.Errorf("unexpected case %+v", descData))
}
}
Loading