From 4815e2ae211855589e6b22a105477101ee4325a2 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 4 Feb 2021 19:15:10 -0600 Subject: [PATCH 01/10] implement PayForMessage fix bug left from sdk that stops proto-gen from working properly add access to the tx encoder and decoder add all the basic proto messages needed for PayForMessage run make protoc-gen --- app/app.go | 6 + go.mod | 3 +- go.sum | 2 + proto/lazyledgerapp/tx.proto | 84 ++ scripts/protocgen.sh | 4 +- x/lazyledgerapp/types/genesis.pb.go | 18 +- x/lazyledgerapp/types/query.pb.go | 24 +- x/lazyledgerapp/types/tx.pb.go | 1852 +++++++++++++++++++++++++++ x/lazyledgerapp/types/tx.pb.gw.go | 166 +++ 9 files changed, 2135 insertions(+), 24 deletions(-) create mode 100644 proto/lazyledgerapp/tx.proto create mode 100644 x/lazyledgerapp/types/tx.pb.go create mode 100644 x/lazyledgerapp/types/tx.pb.gw.go diff --git a/app/app.go b/app/app.go index 3abe42c2e5..2e225e701b 100644 --- a/app/app.go +++ b/app/app.go @@ -144,6 +144,8 @@ type App struct { cdc *codec.LegacyAmino appCodec codec.Marshaler + txDecoder sdk.TxDecoder + txEncoder sdk.TxEncoder interfaceRegistry types.InterfaceRegistry invCheckPeriod uint @@ -191,6 +193,8 @@ func New( appCodec := encodingConfig.Marshaler cdc := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry + txDecoder := encodingConfig.TxConfig.TxDecoder() + txEncoder := encodingConfig.TxConfig.TxEncoder() bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) @@ -213,6 +217,8 @@ func New( appName: appName, cdc: cdc, appCodec: appCodec, + txDecoder: txDecoder, + txEncoder: txEncoder, interfaceRegistry: interfaceRegistry, invCheckPeriod: invCheckPeriod, keys: keys, diff --git a/go.mod b/go.mod index a2129a97de..5efad213d0 100644 --- a/go.mod +++ b/go.mod @@ -11,11 +11,12 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/lazyledger/lazyledger-core v0.0.0-20210122184344-b83e6766973c github.com/pelletier/go-toml v1.8.0 - github.com/regen-network/cosmos-proto v0.3.0 + github.com/regen-network/cosmos-proto v0.3.1 github.com/rs/zerolog v1.20.0 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.1 github.com/spf13/pflag v1.0.5 + github.com/stretchr/testify v1.6.1 github.com/tendermint/tm-db v0.6.3 golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect diff --git a/go.sum b/go.sum index ab940db3fb..86cf0b989e 100644 --- a/go.sum +++ b/go.sum @@ -538,6 +538,8 @@ github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVsc github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVscPl0ga4Eoub0= github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= +github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg= +github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM= github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQDLUaq15LjNE83nRzkyrLAMcPewig= diff --git a/proto/lazyledgerapp/tx.proto b/proto/lazyledgerapp/tx.proto new file mode 100644 index 0000000000..cc1057d1ef --- /dev/null +++ b/proto/lazyledgerapp/tx.proto @@ -0,0 +1,84 @@ +syntax = "proto3"; +package lazyledgerapp; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; + +option go_package = "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types"; + + +// Msg defines the bank Msg service. +service Msg { + // PayForMessage allows the user to post data to made be available. + rpc PayForMessage(MsgWirePayForMessage) returns (MsgWirePayForMessageResponse) { + option (google.api.http).get = "/layzyledger/lazyledgerapp/payformessage"; + } + } + +// WirePayForMessage describes the format of data that is sent over the wire for +// each PayForMessage +message MsgWirePayForMessage { + TransactionFee fee = 1; + uint64 nonce = 2; + bytes message_name_space_id = 3; // assume this is 8 bytes! + uint64 message_size = 4; + bytes message = 5; + repeated ShareCommitAndSignature message_share_commitment = 6 [(gogoproto.nullable) = false]; + bytes from = 7; // should this be included? +} + +// WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage +message MsgWirePayForMessageResponse { + string error = 1; + bytes hash = 2; +} + +// ShareCommitAndSignature defines the +message ShareCommitAndSignature { + bytes share_commitment = 1; + bytes signature = 2; // signature on one SignedTransactionPayForMessage +} + +// SignedTransactionsDataPayForMessage is what gets signed by users when +// creating ShareCommitSignatures. Multiple versions are signed and included. +message SignedTransactionDataPayForMessage { + TransactionType type = 1; + TransactionFee fee = 2; + uint64 nonce = 3; + bytes message_namespace_id = 4; + uint64 message_size = 5; + bytes message_share_commitment = 6; +} + +// TransactionFee contains the base and tip rates. +message TransactionFee { + uint64 base_rate_max = 1; + uint64 tip_rate_max = 2; +} + +// the different types of valid transactions in lazyledger +enum TransactionType { + option (gogoproto.goproto_enum_stringer) = true; + option (gogoproto.goproto_enum_prefix) = false; + + // Unknown transaction type + TRANSACTION_TYPE_UNSPECIFIED = 0; + // Transfer moves tokens from one address to another + TRANSACTION_TYPE_TRANSFER = 1; + // PayForMessage removes funds from the account paying for the message + TRANSACTION_TYPE_PAY_FOR_MESSAGE = 2; + // CreateValidator creates a new validator + TRANSACTION_TYPE_CREATE_VALIDATOR = 3; + // BeginUnbondingValidator is meant to signal a validator's desire to unbond + TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR = 4; + // UnbondValidator unbonds + TRANSACTION_TYPE_UNBOND_VALIDATOR = 5; + // CreateDelegation begins the process of delegation to a bonded validator + TRANSACTION_TYPE_CREATE_DELEGATION = 6; + // BeginUnbondingDelegation starts the process to stop delegating + TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION = 7; + // UnbondDelegation finalizes stopping delegation + TRANSACTION_TYPE_UNBOND_DELEGATION = 8; + // Burn burns tokens from one account + TRANSACTION_TYPE_BURN = 9; +} \ No newline at end of file diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 5340319d03..f9192dbb7c 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -19,12 +19,12 @@ for dir in $proto_dirs; do -I "proto" \ -I "third_party/proto" \ --gocosmos_out=plugins=interfacetype+grpc,\ -Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ +Mgoogle/protobuf/any.proto=github.com/lazyledger/lazyledger-app/codec/types:. \ --grpc-gateway_out=logtostderr=true:. \ $(find "${dir}" -maxdepth 1 -name '*.proto') done # move proto files to the right places -cp -r github.com/cosmos/cosmos-sdk/* ./ +cp -r github.com/lazyledger/lazyledger-app/* ./ rm -rf github.com diff --git a/x/lazyledgerapp/types/genesis.pb.go b/x/lazyledgerapp/types/genesis.pb.go index 17263f3bf7..1169dcd468 100644 --- a/x/lazyledgerapp/types/genesis.pb.go +++ b/x/lazyledgerapp/types/genesis.pb.go @@ -60,22 +60,22 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo func init() { - proto.RegisterType((*GenesisState)(nil), "lazyledger.lazyledgerapp.lazyledgerapp.GenesisState") + proto.RegisterType((*GenesisState)(nil), "lazyledgerapp.GenesisState") } func init() { proto.RegisterFile("lazyledgerapp/genesis.proto", fileDescriptor_13cb3aa937de0877) } var fileDescriptor_13cb3aa937de0877 = []byte{ - // 136 bytes of a gzipped FileDescriptorProto + // 131 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xce, 0x49, 0xac, 0xaa, 0xcc, 0x49, 0x4d, 0x49, 0x4f, 0x2d, 0x4a, 0x2c, 0x28, 0xd0, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, - 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x43, 0x48, 0xea, 0xa1, 0xa8, 0x43, 0xe5, - 0x29, 0xf1, 0x71, 0xf1, 0xb8, 0x43, 0x34, 0x06, 0x97, 0x24, 0x96, 0xa4, 0x3a, 0x85, 0x9c, 0x78, - 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, - 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x55, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, - 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xc2, 0x0c, 0x24, 0xa6, 0x2e, 0xc8, 0x15, 0x15, 0xfa, 0xa8, 0xae, - 0x2a, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x3b, 0xca, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, - 0xf3, 0x1c, 0x7e, 0x44, 0xb3, 0x00, 0x00, 0x00, + 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x45, 0x91, 0x54, 0xe2, 0xe3, 0xe2, 0x71, + 0x87, 0xc8, 0x07, 0x97, 0x24, 0x96, 0xa4, 0x3a, 0x85, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, + 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, + 0xb1, 0x1c, 0x43, 0x94, 0x55, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, + 0xc2, 0x0c, 0x24, 0xa6, 0x2e, 0xc8, 0xb2, 0x0a, 0x7d, 0x54, 0xcb, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, + 0x93, 0xd8, 0xc0, 0x76, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x0d, 0x3a, 0x17, 0x61, 0x9a, + 0x00, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/lazyledgerapp/types/query.pb.go b/x/lazyledgerapp/types/query.pb.go index a6be1b030d..2d0ea8f3b6 100644 --- a/x/lazyledgerapp/types/query.pb.go +++ b/x/lazyledgerapp/types/query.pb.go @@ -28,19 +28,19 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package func init() { proto.RegisterFile("lazyledgerapp/query.proto", fileDescriptor_5e248d35cd763ec8) } var fileDescriptor_5e248d35cd763ec8 = []byte{ - // 189 bytes of a gzipped FileDescriptorProto + // 184 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0x49, 0xac, 0xaa, 0xcc, 0x49, 0x4d, 0x49, 0x4f, 0x2d, 0x4a, 0x2c, 0x28, 0xd0, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x43, 0x48, 0xe9, 0xa1, 0xa8, 0x42, 0xe5, 0x49, 0xc9, - 0xa4, 0xe7, 0xe7, 0xa7, 0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 0x4e, + 0x85, 0x98, 0xa2, 0x5f, 0x66, 0x98, 0x94, 0x5a, 0x92, 0x68, 0xa8, 0x5f, 0x90, 0x98, 0x9e, 0x99, + 0x07, 0x56, 0x0c, 0x51, 0x6b, 0xc4, 0xce, 0xc5, 0x1a, 0x08, 0x52, 0xe1, 0x14, 0x72, 0xe2, 0x91, + 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, + 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x56, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, + 0xc9, 0xf9, 0xb9, 0xfa, 0x08, 0x67, 0x20, 0x31, 0x75, 0x41, 0xae, 0xad, 0xd0, 0x47, 0x75, 0x7d, + 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x16, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xa0, 0xe8, 0x5d, 0xb5, 0xdb, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -78,7 +78,7 @@ func RegisterQueryServer(s grpc1.Server, srv QueryServer) { } var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "lazyledger.lazyledgerapp.lazyledgerapp.Query", + ServiceName: "lazyledgerapp.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{}, Streams: []grpc.StreamDesc{}, diff --git a/x/lazyledgerapp/types/tx.pb.go b/x/lazyledgerapp/types/tx.pb.go new file mode 100644 index 0000000000..7ed455cb30 --- /dev/null +++ b/x/lazyledgerapp/types/tx.pb.go @@ -0,0 +1,1852 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: lazyledgerapp/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// the different types of valid transactions in lazyledger +type TransactionType int32 + +const ( + // Unknown transaction type + TRANSACTION_TYPE_UNSPECIFIED TransactionType = 0 + // Transfer moves tokens from one address to another + TRANSACTION_TYPE_TRANSFER TransactionType = 1 + // PayForMessage removes funds from the account paying for the message + TRANSACTION_TYPE_PAY_FOR_MESSAGE TransactionType = 2 + // CreateValidator creates a new validator + TRANSACTION_TYPE_CREATE_VALIDATOR TransactionType = 3 + // BeginUnbondingValidator is meant to signal a validator's desire to unbond + TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR TransactionType = 4 + // UnbondValidator unbonds + TRANSACTION_TYPE_UNBOND_VALIDATOR TransactionType = 5 + // CreateDelegation begins the process of delegation to a bonded validator + TRANSACTION_TYPE_CREATE_DELEGATION TransactionType = 6 + // BeginUnbondingDelegation starts the process to stop delegating + TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION TransactionType = 7 + // UnbondDelegation finalizes stopping delegation + TRANSACTION_TYPE_UNBOND_DELEGATION TransactionType = 8 + // Burn burns tokens from one account + TRANSACTION_TYPE_BURN TransactionType = 9 +) + +var TransactionType_name = map[int32]string{ + 0: "TRANSACTION_TYPE_UNSPECIFIED", + 1: "TRANSACTION_TYPE_TRANSFER", + 2: "TRANSACTION_TYPE_PAY_FOR_MESSAGE", + 3: "TRANSACTION_TYPE_CREATE_VALIDATOR", + 4: "TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR", + 5: "TRANSACTION_TYPE_UNBOND_VALIDATOR", + 6: "TRANSACTION_TYPE_CREATE_DELEGATION", + 7: "TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION", + 8: "TRANSACTION_TYPE_UNBOND_DELEGATION", + 9: "TRANSACTION_TYPE_BURN", +} + +var TransactionType_value = map[string]int32{ + "TRANSACTION_TYPE_UNSPECIFIED": 0, + "TRANSACTION_TYPE_TRANSFER": 1, + "TRANSACTION_TYPE_PAY_FOR_MESSAGE": 2, + "TRANSACTION_TYPE_CREATE_VALIDATOR": 3, + "TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR": 4, + "TRANSACTION_TYPE_UNBOND_VALIDATOR": 5, + "TRANSACTION_TYPE_CREATE_DELEGATION": 6, + "TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION": 7, + "TRANSACTION_TYPE_UNBOND_DELEGATION": 8, + "TRANSACTION_TYPE_BURN": 9, +} + +func (x TransactionType) String() string { + return proto.EnumName(TransactionType_name, int32(x)) +} + +func (TransactionType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{0} +} + +// WirePayForMessage describes the format of data that is sent over the wire for +// each PayForMessage +type MsgWirePayForMessage struct { + Fee *TransactionFee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + Nonce uint64 `protobuf:"varint,2,opt,name=nonce,proto3" json:"nonce,omitempty"` + MessageNameSpaceId []byte `protobuf:"bytes,3,opt,name=message_name_space_id,json=messageNameSpaceId,proto3" json:"message_name_space_id,omitempty"` + MessageSize uint64 `protobuf:"varint,4,opt,name=message_size,json=messageSize,proto3" json:"message_size,omitempty"` + Message []byte `protobuf:"bytes,5,opt,name=message,proto3" json:"message,omitempty"` + MessageShareCommitment []ShareCommitAndSignature `protobuf:"bytes,6,rep,name=message_share_commitment,json=messageShareCommitment,proto3" json:"message_share_commitment"` + From []byte `protobuf:"bytes,7,opt,name=from,proto3" json:"from,omitempty"` +} + +func (m *MsgWirePayForMessage) Reset() { *m = MsgWirePayForMessage{} } +func (m *MsgWirePayForMessage) String() string { return proto.CompactTextString(m) } +func (*MsgWirePayForMessage) ProtoMessage() {} +func (*MsgWirePayForMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{0} +} +func (m *MsgWirePayForMessage) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWirePayForMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWirePayForMessage.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWirePayForMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWirePayForMessage.Merge(m, src) +} +func (m *MsgWirePayForMessage) XXX_Size() int { + return m.Size() +} +func (m *MsgWirePayForMessage) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWirePayForMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWirePayForMessage proto.InternalMessageInfo + +func (m *MsgWirePayForMessage) GetFee() *TransactionFee { + if m != nil { + return m.Fee + } + return nil +} + +func (m *MsgWirePayForMessage) GetNonce() uint64 { + if m != nil { + return m.Nonce + } + return 0 +} + +func (m *MsgWirePayForMessage) GetMessageNameSpaceId() []byte { + if m != nil { + return m.MessageNameSpaceId + } + return nil +} + +func (m *MsgWirePayForMessage) GetMessageSize() uint64 { + if m != nil { + return m.MessageSize + } + return 0 +} + +func (m *MsgWirePayForMessage) GetMessage() []byte { + if m != nil { + return m.Message + } + return nil +} + +func (m *MsgWirePayForMessage) GetMessageShareCommitment() []ShareCommitAndSignature { + if m != nil { + return m.MessageShareCommitment + } + return nil +} + +func (m *MsgWirePayForMessage) GetFrom() []byte { + if m != nil { + return m.From + } + return nil +} + +// WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage +type MsgWirePayForMessageResponse struct { + Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` + Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"` +} + +func (m *MsgWirePayForMessageResponse) Reset() { *m = MsgWirePayForMessageResponse{} } +func (m *MsgWirePayForMessageResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWirePayForMessageResponse) ProtoMessage() {} +func (*MsgWirePayForMessageResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{1} +} +func (m *MsgWirePayForMessageResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWirePayForMessageResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWirePayForMessageResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWirePayForMessageResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWirePayForMessageResponse.Merge(m, src) +} +func (m *MsgWirePayForMessageResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWirePayForMessageResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWirePayForMessageResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWirePayForMessageResponse proto.InternalMessageInfo + +func (m *MsgWirePayForMessageResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (m *MsgWirePayForMessageResponse) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +// ShareCommitAndSignature defines the +type ShareCommitAndSignature struct { + ShareCommitment []byte `protobuf:"bytes,1,opt,name=share_commitment,json=shareCommitment,proto3" json:"share_commitment,omitempty"` + Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *ShareCommitAndSignature) Reset() { *m = ShareCommitAndSignature{} } +func (m *ShareCommitAndSignature) String() string { return proto.CompactTextString(m) } +func (*ShareCommitAndSignature) ProtoMessage() {} +func (*ShareCommitAndSignature) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{2} +} +func (m *ShareCommitAndSignature) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ShareCommitAndSignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ShareCommitAndSignature.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ShareCommitAndSignature) XXX_Merge(src proto.Message) { + xxx_messageInfo_ShareCommitAndSignature.Merge(m, src) +} +func (m *ShareCommitAndSignature) XXX_Size() int { + return m.Size() +} +func (m *ShareCommitAndSignature) XXX_DiscardUnknown() { + xxx_messageInfo_ShareCommitAndSignature.DiscardUnknown(m) +} + +var xxx_messageInfo_ShareCommitAndSignature proto.InternalMessageInfo + +func (m *ShareCommitAndSignature) GetShareCommitment() []byte { + if m != nil { + return m.ShareCommitment + } + return nil +} + +func (m *ShareCommitAndSignature) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +// SignedTransactionsDataPayForMessage is what gets signed by users when +// creating ShareCommitSignatures. Multiple versions are signed and included. +type SignedTransactionDataPayForMessage struct { + Type TransactionType `protobuf:"varint,1,opt,name=type,proto3,enum=lazyledgerapp.TransactionType" json:"type,omitempty"` + Fee *TransactionFee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` + Nonce uint64 `protobuf:"varint,3,opt,name=nonce,proto3" json:"nonce,omitempty"` + MessageNamespaceId []byte `protobuf:"bytes,4,opt,name=message_namespace_id,json=messageNamespaceId,proto3" json:"message_namespace_id,omitempty"` + MessageSize uint64 `protobuf:"varint,5,opt,name=message_size,json=messageSize,proto3" json:"message_size,omitempty"` + MessageShareCommitment []byte `protobuf:"bytes,6,opt,name=message_share_commitment,json=messageShareCommitment,proto3" json:"message_share_commitment,omitempty"` +} + +func (m *SignedTransactionDataPayForMessage) Reset() { *m = SignedTransactionDataPayForMessage{} } +func (m *SignedTransactionDataPayForMessage) String() string { return proto.CompactTextString(m) } +func (*SignedTransactionDataPayForMessage) ProtoMessage() {} +func (*SignedTransactionDataPayForMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{3} +} +func (m *SignedTransactionDataPayForMessage) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignedTransactionDataPayForMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignedTransactionDataPayForMessage.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SignedTransactionDataPayForMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignedTransactionDataPayForMessage.Merge(m, src) +} +func (m *SignedTransactionDataPayForMessage) XXX_Size() int { + return m.Size() +} +func (m *SignedTransactionDataPayForMessage) XXX_DiscardUnknown() { + xxx_messageInfo_SignedTransactionDataPayForMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_SignedTransactionDataPayForMessage proto.InternalMessageInfo + +func (m *SignedTransactionDataPayForMessage) GetType() TransactionType { + if m != nil { + return m.Type + } + return TRANSACTION_TYPE_UNSPECIFIED +} + +func (m *SignedTransactionDataPayForMessage) GetFee() *TransactionFee { + if m != nil { + return m.Fee + } + return nil +} + +func (m *SignedTransactionDataPayForMessage) GetNonce() uint64 { + if m != nil { + return m.Nonce + } + return 0 +} + +func (m *SignedTransactionDataPayForMessage) GetMessageNamespaceId() []byte { + if m != nil { + return m.MessageNamespaceId + } + return nil +} + +func (m *SignedTransactionDataPayForMessage) GetMessageSize() uint64 { + if m != nil { + return m.MessageSize + } + return 0 +} + +func (m *SignedTransactionDataPayForMessage) GetMessageShareCommitment() []byte { + if m != nil { + return m.MessageShareCommitment + } + return nil +} + +// TransactionFee contains the base and tip rates. +type TransactionFee struct { + BaseRateMax uint64 `protobuf:"varint,1,opt,name=base_rate_max,json=baseRateMax,proto3" json:"base_rate_max,omitempty"` + TipRateMax uint64 `protobuf:"varint,2,opt,name=tip_rate_max,json=tipRateMax,proto3" json:"tip_rate_max,omitempty"` +} + +func (m *TransactionFee) Reset() { *m = TransactionFee{} } +func (m *TransactionFee) String() string { return proto.CompactTextString(m) } +func (*TransactionFee) ProtoMessage() {} +func (*TransactionFee) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{4} +} +func (m *TransactionFee) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TransactionFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TransactionFee.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TransactionFee) XXX_Merge(src proto.Message) { + xxx_messageInfo_TransactionFee.Merge(m, src) +} +func (m *TransactionFee) XXX_Size() int { + return m.Size() +} +func (m *TransactionFee) XXX_DiscardUnknown() { + xxx_messageInfo_TransactionFee.DiscardUnknown(m) +} + +var xxx_messageInfo_TransactionFee proto.InternalMessageInfo + +func (m *TransactionFee) GetBaseRateMax() uint64 { + if m != nil { + return m.BaseRateMax + } + return 0 +} + +func (m *TransactionFee) GetTipRateMax() uint64 { + if m != nil { + return m.TipRateMax + } + return 0 +} + +func init() { + proto.RegisterEnum("lazyledgerapp.TransactionType", TransactionType_name, TransactionType_value) + proto.RegisterType((*MsgWirePayForMessage)(nil), "lazyledgerapp.MsgWirePayForMessage") + proto.RegisterType((*MsgWirePayForMessageResponse)(nil), "lazyledgerapp.MsgWirePayForMessageResponse") + proto.RegisterType((*ShareCommitAndSignature)(nil), "lazyledgerapp.ShareCommitAndSignature") + proto.RegisterType((*SignedTransactionDataPayForMessage)(nil), "lazyledgerapp.SignedTransactionDataPayForMessage") + proto.RegisterType((*TransactionFee)(nil), "lazyledgerapp.TransactionFee") +} + +func init() { proto.RegisterFile("lazyledgerapp/tx.proto", fileDescriptor_4a525bbab69d1e80) } + +var fileDescriptor_4a525bbab69d1e80 = []byte{ + // 778 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x95, 0xcf, 0x8f, 0xda, 0x46, + 0x14, 0xc7, 0x31, 0x98, 0xdd, 0xec, 0xc0, 0x26, 0x68, 0x44, 0x52, 0x07, 0x11, 0x97, 0xb8, 0x6d, + 0x44, 0x37, 0x2a, 0x4e, 0xe9, 0xa5, 0xea, 0xcd, 0x80, 0xa1, 0x48, 0xc1, 0xa0, 0xb1, 0x37, 0x55, + 0x7a, 0xb1, 0x06, 0x18, 0x8c, 0x25, 0xec, 0xb1, 0x3c, 0x8e, 0x04, 0x7b, 0xec, 0xa9, 0xc7, 0x4a, + 0x7b, 0x6c, 0x6f, 0xed, 0xa1, 0xa7, 0xfe, 0x1d, 0xdb, 0xdb, 0x4a, 0xbd, 0xf4, 0x54, 0x55, 0xbb, + 0xfd, 0x43, 0x2a, 0xdb, 0xb0, 0x6b, 0x30, 0xf4, 0xc7, 0x6d, 0xe6, 0xbd, 0xcf, 0xfb, 0xbe, 0xf1, + 0xf3, 0x77, 0x6c, 0xf0, 0x64, 0x81, 0x2f, 0x56, 0x0b, 0x32, 0xb5, 0x88, 0x8f, 0x3d, 0x4f, 0x0e, + 0x96, 0x0d, 0xcf, 0xa7, 0x01, 0x85, 0xa7, 0x5b, 0xf1, 0x4a, 0xd9, 0xa2, 0x16, 0x8d, 0x32, 0x72, + 0xb8, 0x8a, 0xa1, 0x4a, 0xd5, 0xa2, 0xd4, 0x5a, 0x10, 0x19, 0x7b, 0xb6, 0x8c, 0x5d, 0x97, 0x06, + 0x38, 0xb0, 0xa9, 0xcb, 0xe2, 0xac, 0xf4, 0x6b, 0x16, 0x94, 0x07, 0xcc, 0xfa, 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 0xaf, + 0xbf, 0x87, 0x57, 0x33, 0xea, 0xaf, 0x3d, 0xda, 0x32, 0xae, 0x6e, 0x44, 0xee, 0xfa, 0x46, 0xe4, + 0xfe, 0xbc, 0x11, 0xb9, 0xef, 0x6e, 0xc5, 0xcc, 0xf5, 0xad, 0x98, 0xf9, 0xfd, 0x56, 0xcc, 0x7c, + 0xfd, 0x85, 0x65, 0x07, 0xf3, 0x77, 0xe3, 0xc6, 0x84, 0x3a, 0x09, 0x85, 0xc4, 0xf2, 0x93, 0x50, + 0x6d, 0xb9, 0xa3, 0x1e, 0xde, 0x5f, 0x36, 0x3e, 0x8a, 0x7e, 0x0e, 0x9f, 0xfd, 0x1d, 0x00, 0x00, + 0xff, 0xff, 0xaf, 0x90, 0xc0, 0x7f, 0x79, 0x06, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // PayForMessage allows the user to post data to made be available. + PayForMessage(ctx context.Context, in *MsgWirePayForMessage, opts ...grpc.CallOption) (*MsgWirePayForMessageResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) PayForMessage(ctx context.Context, in *MsgWirePayForMessage, opts ...grpc.CallOption) (*MsgWirePayForMessageResponse, error) { + out := new(MsgWirePayForMessageResponse) + err := c.cc.Invoke(ctx, "/lazyledgerapp.Msg/PayForMessage", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // PayForMessage allows the user to post data to made be available. + PayForMessage(context.Context, *MsgWirePayForMessage) (*MsgWirePayForMessageResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) PayForMessage(ctx context.Context, req *MsgWirePayForMessage) (*MsgWirePayForMessageResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PayForMessage not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_PayForMessage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWirePayForMessage) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).PayForMessage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lazyledgerapp.Msg/PayForMessage", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).PayForMessage(ctx, req.(*MsgWirePayForMessage)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "lazyledgerapp.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "PayForMessage", + Handler: _Msg_PayForMessage_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "lazyledgerapp/tx.proto", +} + +func (m *MsgWirePayForMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWirePayForMessage) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWirePayForMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.From) > 0 { + i -= len(m.From) + copy(dAtA[i:], m.From) + i = encodeVarintTx(dAtA, i, uint64(len(m.From))) + i-- + dAtA[i] = 0x3a + } + if len(m.MessageShareCommitment) > 0 { + for iNdEx := len(m.MessageShareCommitment) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.MessageShareCommitment[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.Message) > 0 { + i -= len(m.Message) + copy(dAtA[i:], m.Message) + i = encodeVarintTx(dAtA, i, uint64(len(m.Message))) + i-- + dAtA[i] = 0x2a + } + if m.MessageSize != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.MessageSize)) + i-- + dAtA[i] = 0x20 + } + if len(m.MessageNameSpaceId) > 0 { + i -= len(m.MessageNameSpaceId) + copy(dAtA[i:], m.MessageNameSpaceId) + i = encodeVarintTx(dAtA, i, uint64(len(m.MessageNameSpaceId))) + i-- + dAtA[i] = 0x1a + } + if m.Nonce != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Nonce)) + i-- + dAtA[i] = 0x10 + } + if m.Fee != nil { + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWirePayForMessageResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWirePayForMessageResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWirePayForMessageResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintTx(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0x12 + } + if len(m.Error) > 0 { + i -= len(m.Error) + copy(dAtA[i:], m.Error) + i = encodeVarintTx(dAtA, i, uint64(len(m.Error))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ShareCommitAndSignature) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ShareCommitAndSignature) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ShareCommitAndSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x12 + } + if len(m.ShareCommitment) > 0 { + i -= len(m.ShareCommitment) + copy(dAtA[i:], m.ShareCommitment) + i = encodeVarintTx(dAtA, i, uint64(len(m.ShareCommitment))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SignedTransactionDataPayForMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SignedTransactionDataPayForMessage) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignedTransactionDataPayForMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MessageShareCommitment) > 0 { + i -= len(m.MessageShareCommitment) + copy(dAtA[i:], m.MessageShareCommitment) + i = encodeVarintTx(dAtA, i, uint64(len(m.MessageShareCommitment))) + i-- + dAtA[i] = 0x32 + } + if m.MessageSize != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.MessageSize)) + i-- + dAtA[i] = 0x28 + } + if len(m.MessageNamespaceId) > 0 { + i -= len(m.MessageNamespaceId) + copy(dAtA[i:], m.MessageNamespaceId) + i = encodeVarintTx(dAtA, i, uint64(len(m.MessageNamespaceId))) + i-- + dAtA[i] = 0x22 + } + if m.Nonce != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Nonce)) + i-- + dAtA[i] = 0x18 + } + if m.Fee != nil { + { + size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Type != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *TransactionFee) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TransactionFee) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TransactionFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TipRateMax != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TipRateMax)) + i-- + dAtA[i] = 0x10 + } + if m.BaseRateMax != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.BaseRateMax)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgWirePayForMessage) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Fee != nil { + l = m.Fee.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Nonce != 0 { + n += 1 + sovTx(uint64(m.Nonce)) + } + l = len(m.MessageNameSpaceId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.MessageSize != 0 { + n += 1 + sovTx(uint64(m.MessageSize)) + } + l = len(m.Message) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.MessageShareCommitment) > 0 { + for _, e := range m.MessageShareCommitment { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.From) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWirePayForMessageResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Error) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *ShareCommitAndSignature) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ShareCommitment) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *SignedTransactionDataPayForMessage) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovTx(uint64(m.Type)) + } + if m.Fee != nil { + l = m.Fee.Size() + n += 1 + l + sovTx(uint64(l)) + } + if m.Nonce != 0 { + n += 1 + sovTx(uint64(m.Nonce)) + } + l = len(m.MessageNamespaceId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.MessageSize != 0 { + n += 1 + sovTx(uint64(m.MessageSize)) + } + l = len(m.MessageShareCommitment) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *TransactionFee) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseRateMax != 0 { + n += 1 + sovTx(uint64(m.BaseRateMax)) + } + if m.TipRateMax != 0 { + n += 1 + sovTx(uint64(m.TipRateMax)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgWirePayForMessage) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWirePayForMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWirePayForMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Fee == nil { + m.Fee = &TransactionFee{} + } + if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Nonce", wireType) + } + m.Nonce = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Nonce |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageNameSpaceId", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MessageNameSpaceId = append(m.MessageNameSpaceId[:0], dAtA[iNdEx:postIndex]...) + if m.MessageNameSpaceId == nil { + m.MessageNameSpaceId = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageSize", wireType) + } + m.MessageSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MessageSize |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = append(m.Message[:0], dAtA[iNdEx:postIndex]...) + if m.Message == nil { + m.Message = []byte{} + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageShareCommitment", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MessageShareCommitment = append(m.MessageShareCommitment, ShareCommitAndSignature{}) + if err := m.MessageShareCommitment[len(m.MessageShareCommitment)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field From", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.From = append(m.From[:0], dAtA[iNdEx:postIndex]...) + if m.From == nil { + m.From = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWirePayForMessageResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWirePayForMessageResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Error = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ShareCommitAndSignature) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ShareCommitAndSignature: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ShareCommitAndSignature: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ShareCommitment", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ShareCommitment = append(m.ShareCommitment[:0], dAtA[iNdEx:postIndex]...) + if m.ShareCommitment == nil { + m.ShareCommitment = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignedTransactionDataPayForMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignedTransactionDataPayForMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= TransactionType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Fee == nil { + m.Fee = &TransactionFee{} + } + if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Nonce", wireType) + } + m.Nonce = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Nonce |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageNamespaceId", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MessageNamespaceId = append(m.MessageNamespaceId[:0], dAtA[iNdEx:postIndex]...) + if m.MessageNamespaceId == nil { + m.MessageNamespaceId = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageSize", wireType) + } + m.MessageSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MessageSize |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MessageShareCommitment", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MessageShareCommitment = append(m.MessageShareCommitment[:0], dAtA[iNdEx:postIndex]...) + if m.MessageShareCommitment == nil { + m.MessageShareCommitment = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TransactionFee) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TransactionFee: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TransactionFee: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseRateMax", wireType) + } + m.BaseRateMax = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BaseRateMax |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TipRateMax", wireType) + } + m.TipRateMax = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TipRateMax |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/lazyledgerapp/types/tx.pb.gw.go b/x/lazyledgerapp/types/tx.pb.gw.go new file mode 100644 index 0000000000..dfadd14b4d --- /dev/null +++ b/x/lazyledgerapp/types/tx.pb.gw.go @@ -0,0 +1,166 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lazyledgerapp/tx.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage + +var ( + filter_Msg_PayForMessage_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Msg_PayForMessage_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgWirePayForMessage + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_PayForMessage_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PayForMessage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Msg_PayForMessage_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgWirePayForMessage + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_PayForMessage_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PayForMessage(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". +// UnaryRPC :call MsgServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { + + mux.Handle("GET", pattern_Msg_PayForMessage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Msg_PayForMessage_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_PayForMessage_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterMsgHandlerFromEndpoint is same as RegisterMsgHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterMsgHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterMsgHandler(ctx, mux, conn) +} + +// RegisterMsgHandler registers the http handlers for service Msg to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterMsgHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterMsgHandlerClient(ctx, mux, NewMsgClient(conn)) +} + +// RegisterMsgHandlerClient registers the http handlers for service Msg +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MsgClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MsgClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "MsgClient" to call the correct interceptors. +func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgClient) error { + + mux.Handle("GET", pattern_Msg_PayForMessage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Msg_PayForMessage_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_PayForMessage_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Msg_PayForMessage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"layzyledger", "lazyledgerapp", "payformessage"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Msg_PayForMessage_0 = runtime.ForwardResponseMessage +) From a829d80043807e73cc3419f2e5b4714cced13ae2 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Sat, 6 Feb 2021 01:08:51 -0600 Subject: [PATCH 02/10] implement PreprocessTxs remove placeholder type that causes a compilation error lazyledgerapp: add pay for message to the handler added verification methods to payformessage connected payformessage to rest of sdk refactored preprocessing update the branch of the sdk that allows for running tx outside of DeliverTx proto: use the users public key instead their address keeper: remove burning fees verify signatures using public key added notes for next todo remove compile time error proto: remove enums that are not going to be used for the mvp proto: added tx type for pay for message lazyledgerapp/types: fleshed out and finalized PayForMessage types --- app/abci.go | 87 +++ app/abci_test.go | 138 +++++ app/app.go | 23 +- go.mod | 7 +- go.sum | 14 +- proto/lazyledgerapp/tx.proto | 58 +- x/lazyledgerapp/handler.go | 6 +- x/lazyledgerapp/keeper/keeper.go | 34 +- x/lazyledgerapp/keeper/msg_server.go | 15 + x/lazyledgerapp/types/payformessage.go | 292 ++++++++++ x/lazyledgerapp/types/payformessage_test.go | 120 ++++ x/lazyledgerapp/types/tx.pb.go | 584 ++++++++++++-------- x/lazyledgerapp/types/tx.pb.gw.go | 7 +- 13 files changed, 1085 insertions(+), 300 deletions(-) create mode 100644 app/abci.go create mode 100644 app/abci_test.go create mode 100644 x/lazyledgerapp/keeper/msg_server.go create mode 100644 x/lazyledgerapp/types/payformessage.go create mode 100644 x/lazyledgerapp/types/payformessage_test.go diff --git a/app/abci.go b/app/abci.go new file mode 100644 index 0000000000..74b9223642 --- /dev/null +++ b/app/abci.go @@ -0,0 +1,87 @@ +package app + +import ( + "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" + abci "github.com/lazyledger/lazyledger-core/abci/types" + core "github.com/lazyledger/lazyledger-core/proto/tendermint/types" +) + +// This file should contain all of the althered ABCI methods + +// PreprocessTxs fullfills the lazyledger-core version of the ACBI interface, by +// performing basic validation for the incoming txs, and by cleanly separating +// share messages from transactions +// todo(evan): refactor out a for loop. +func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePreprocessTxs { + var shareMsgs []*core.Message + for _, rawTx := range txs.Txs { + // decode the Tx + tx, err := app.txDecoder(rawTx) + if err != nil { + continue + } + + // run basic validation on the transaction + err = tx.ValidateBasic() + if err != nil { + continue + } + + // don't allow transactions with multiple messages to be ran + if len(tx.GetMsgs()) != 1 { + continue + } + + msg := tx.GetMsgs()[0] + + // run basic validation on the msg + err = msg.ValidateBasic() + if err != nil { + continue + } + + // quickly check the stated type of the message + if msg.Type() != types.TypeMsgPayforMessage { + continue + } + + // double check the actual type of the message + wireMsg, ok := msg.(*types.MsgWirePayForMessage) + if !ok { + continue + } + + // todo(evan): this needs to turn the transaction into a SignedTransactionDataPayForMessage + // // discard the share commitments that won't be used + // var shareCommit types.ShareCommitAndSignature + // for _, commit := range wireMsg.MessageShareCommitment { + // if commit.K == app.SquareSize() { + // shareCommit = commit + // break + // } + // } + + // make sure to get rid of excess txs or do something with them + + // execute the tx in runTxModeDeliver mode (3) + // execution includes all validation checks burning fees + _, _, err = app.BaseApp.TxRunner()(3, rawTx) + if err != nil { + continue + } + + // the message is valid and paid for, include it in the response + shareMsgs = append( + shareMsgs, + &core.Message{ + NamespaceId: wireMsg.GetMessageNameSpaceId(), + Data: wireMsg.Message, + }, + ) + } + + return abci.ResponsePreprocessTxs{ + Txs: txs.Txs, + Messages: &core.Messages{MessagesList: shareMsgs}, + } +} diff --git a/app/abci_test.go b/app/abci_test.go new file mode 100644 index 0000000000..c857a0f116 --- /dev/null +++ b/app/abci_test.go @@ -0,0 +1,138 @@ +package app + +import ( + "os" + "testing" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/server" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" + abci "github.com/lazyledger/lazyledger-core/abci/types" + "github.com/lazyledger/lazyledger-core/libs/log" + "github.com/spf13/cast" + "github.com/stretchr/testify/assert" + dbm "github.com/tendermint/tm-db" +) + +// this test doesn't currently test anything, but it's a good starting template +func TestPreProcessTxs(t *testing.T) { + testApp := setupApp() + basicTx := &types.MsgWirePayForMessage{ + MessageSize: 4, + Message: []byte{1, 2, 3, 4}, + MessageNameSpaceId: []byte{1, 2, 3, 4}, + From: "cosmos1tg66f06v0jh42g5wxnht9a5fqqj0lu78n37ss5", + } + rawBasicTx, err := testApp.txEncoder(txTest{[]sdk.Msg{basicTx}}) + if err != nil { + t.Error(err) + } + tests := []struct { + name string + args abci.RequestPreprocessTxs + want abci.ResponsePreprocessTxs + }{ + { + name: "basic", + args: abci.RequestPreprocessTxs{ + Txs: [][]byte{rawBasicTx}, + }, + }, + } + for _, tt := range tests { + result := testApp.PreprocessTxs(tt.args) + assert.Equal(t, tt.want, result, tt.name) + } +} + +func generateTxs() [][]byte { + return [][]byte{} +} + +func setupApp() *App { + // var cache sdk.MultiStorePersistentCache + // EmptyAppOptions is a stub implementing AppOptions + emptyOpts := emptyAppOptions{} + db := dbm.NewMemDB() + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + + skipUpgradeHeights := make(map[int64]bool) + + return New( + "test-app", logger, db, nil, true, skipUpgradeHeights, + cast.ToString(emptyOpts.Get(flags.FlagHome)), + cast.ToUint(emptyOpts.Get(server.FlagInvCheckPeriod)), + MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd. + emptyOpts, + ) +} + +type emptyAppOptions struct{} + +// Get implements AppOptions +func (ao emptyAppOptions) Get(o string) interface{} { + return nil +} + +///////////////////////////// +// Generate Txs +///////////////////////////// + +func generateRawTxs(t *testing.T, count int, txEncoder sdk.TxEncoder) [][]byte { + output := make([][]byte, count) + for i := 0; i < count; i++ { + // create the tx + tx := newTxCounter(int64(i), int64(i)) + // encode the tx + raw, err := txEncoder(tx) + if err != nil { + t.Error(err) + } + output[i] = raw + } + return output +} + +// Simple tx with a list of Msgs. +type txTest struct { + Msgs []sdk.Msg +} + +// Implements Tx +func (tx txTest) GetMsgs() []sdk.Msg { return tx.Msgs } +func (tx txTest) ValidateBasic() error { return nil } + +// ValidateBasic() fails on negative counters. +// Otherwise it's up to the handlers +type msgCounter struct { + Counter int64 + FailOnHandler bool +} + +// dummy implementation of proto.Message +func (msg msgCounter) Reset() {} +func (msg msgCounter) String() string { return "TODO" } +func (msg msgCounter) ProtoMessage() {} + +// Implements Msg +func (msg msgCounter) Route() string { return "lazyledgerapp" } +func (msg msgCounter) Type() string { return types.TypeMsgPayforMessage } +func (msg msgCounter) GetSignBytes() []byte { return nil } +func (msg msgCounter) GetSigners() []sdk.AccAddress { return nil } +func (msg msgCounter) ValidateBasic() error { + if msg.Counter >= 0 { + return nil + } + return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "counter should be a non-negative integer") +} + +func newTxCounter(counter int64, msgCounters ...int64) *txTest { + msgs := make([]sdk.Msg, 0, len(msgCounters)) + for _, c := range msgCounters { + msgs = append(msgs, msgCounter{c, false}) + } + + return &txTest{msgs} +} diff --git a/app/app.go b/app/app.go index 2e225e701b..612ce6f3c0 100644 --- a/app/app.go +++ b/app/app.go @@ -2,6 +2,7 @@ package app import ( "io" + "math/big" "os" "path/filepath" @@ -140,7 +141,8 @@ var ( type App struct { *baseapp.BaseApp - appName string + appName string + squareSize uint64 cdc *codec.LegacyAmino appCodec codec.Marshaler @@ -213,8 +215,10 @@ func New( memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) app := &App{ - BaseApp: bApp, - appName: appName, + BaseApp: bApp, + appName: appName, + // todo(evan): don't hardcode square size + squareSize: 64, cdc: cdc, appCodec: appCodec, txDecoder: txDecoder, @@ -273,7 +277,6 @@ func New( // ... other modules keepers // Create IBC Keeper - // TODO(evan): fix this so ibcClientSubspace := paramstypes.NewSubspace(appCodec, cdc, keys[ibchost.StoreKey], keys[ibchost.StoreKey], "ibc") app.IBCKeeper = ibckeeper.NewKeeper( appCodec, keys[ibchost.StoreKey], ibcClientSubspace, app.StakingKeeper, scopedIBCKeeper, @@ -312,7 +315,11 @@ func New( app.EvidenceKeeper = *evidenceKeeper app.lazyledgerappKeeper = *lazyledgerappkeeper.NewKeeper( - appCodec, keys[lazyledgerapptypes.StoreKey], keys[lazyledgerapptypes.MemStoreKey], + appCodec, + app.BankKeeper, + keys[lazyledgerapptypes.StoreKey], + keys[lazyledgerapptypes.MemStoreKey], + sdk.NewIntFromBigInt(big.NewInt(1000)), ) // this line is used by starport scaffolding # stargate/app/keeperDefinition @@ -558,6 +565,12 @@ func (app *App) RegisterTxService(clientCtx client.Context) { // TODO(evan): fill in to actually register the service func (app *App) RegisterTendermintService(clientCtx client.Context) {} +// SquareSize returns the current square size. Currently, the square size is +// hardcoded. todo(evan): don't hardcode the square size +func (app *App) SquareSize() uint64 { + return app.squareSize +} + // GetMaccPerms returns a copy of the module account permissions func GetMaccPerms() map[string][]string { dupMaccPerms := make(map[string][]string) diff --git a/go.mod b/go.mod index 5efad213d0..5b16ad4435 100644 --- a/go.mod +++ b/go.mod @@ -10,23 +10,24 @@ require ( github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/lazyledger/lazyledger-core v0.0.0-20210122184344-b83e6766973c + github.com/lazyledger/nmt v0.1.0 github.com/pelletier/go-toml v1.8.0 github.com/regen-network/cosmos-proto v0.3.1 github.com/rs/zerolog v1.20.0 github.com/spf13/cast v1.3.1 - github.com/spf13/cobra v1.1.1 + github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.6.1 github.com/tendermint/tm-db v0.6.3 golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect - google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f + google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea google.golang.org/grpc v1.33.2 ) replace ( - github.com/cosmos/cosmos-sdk => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210121152417-3addd7f65d1c + github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210210133003-f5820a7732ed github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 ) diff --git a/go.sum b/go.sum index 86cf0b989e..514377d17c 100644 --- a/go.sum +++ b/go.sum @@ -369,8 +369,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210121152417-3addd7f65d1c h1:OFw8rVLTYvM2QDz8OMcnJEXm/+dCUTkBOyAPVccsLiU= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210121152417-3addd7f65d1c/go.mod h1:pPx3/tAjdExEctV+nKzvNeedZcvuys5fUD0A3r5XX20= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210210133003-f5820a7732ed h1:gkJ4Iu1ku7gfwx0Uh3GRzzH8wDqybAITbcl0INr3vu8= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210210133003-f5820a7732ed/go.mod h1:JVWmoRJFlFZthbwocA6GVFvS6cwoZgw02vGJr2qj6Cc= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181 h1:mUeCGuCgjZVadW4CzA2dMBq7p2BqaoCfpnKjxMmSaSE= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181/go.mod h1:v1o1CRihQ9i7hizx23KK4aR79lxA6VDUIzUCfDva0XQ= github.com/lazyledger/lazyledger-core v0.0.0-20210115223437-eff282ad2592/go.mod h1:yNWM9NVGWzSqRS56TL5cVdD6fS0eoxZlCZNHRvxjneE= @@ -534,10 +534,6 @@ github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Ung github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVscPl0ga4Eoub0= -github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVscPl0ga4Eoub0= -github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= -github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg= github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM= github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= @@ -591,6 +587,8 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -900,8 +898,8 @@ google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4 h1:Rt0FRalMgdSlXAVJvX4pr65KfqaxHXSLkSJRD9pw6g0= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f h1:izedQ6yVIc5mZsRuXzmSreCOlzI0lCU1HpG8yEdMiKw= -google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea h1:N98SvVh7Hdle2lgUVFuIkf0B3u29CUakMUQa7Hwz8Wc= +google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= diff --git a/proto/lazyledgerapp/tx.proto b/proto/lazyledgerapp/tx.proto index cc1057d1ef..1bf4a518ea 100644 --- a/proto/lazyledgerapp/tx.proto +++ b/proto/lazyledgerapp/tx.proto @@ -24,30 +24,35 @@ message MsgWirePayForMessage { uint64 message_size = 4; bytes message = 5; repeated ShareCommitAndSignature message_share_commitment = 6 [(gogoproto.nullable) = false]; - bytes from = 7; // should this be included? + bytes public_key = 7; } // WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage -message MsgWirePayForMessageResponse { - string error = 1; - bytes hash = 2; -} +message MsgWirePayForMessageResponse {} // ShareCommitAndSignature defines the message ShareCommitAndSignature { - bytes share_commitment = 1; - bytes signature = 2; // signature on one SignedTransactionPayForMessage + uint64 k = 1; + bytes share_commitment = 2; + bytes signature = 3; // signature on one SignedTransactionPayForMessage +} + +// TxSignedTransactionDataPayForMessage is a wrapper around +// SignedTransactionDataPayForMessage that fullfills the sdk.Tx interface +message TxSignedTransactionDataPayForMessage { + SignedTransactionDataPayForMessage message = 1; + bytes signature = 2; + bytes public_key = 3; } // SignedTransactionsDataPayForMessage is what gets signed by users when // creating ShareCommitSignatures. Multiple versions are signed and included. message SignedTransactionDataPayForMessage { - TransactionType type = 1; - TransactionFee fee = 2; - uint64 nonce = 3; - bytes message_namespace_id = 4; - uint64 message_size = 5; - bytes message_share_commitment = 6; + TransactionFee fee = 1; + uint64 nonce = 2; + bytes message_namespace_id = 3; + uint64 message_size = 4; + bytes message_share_commitment = 5; } // TransactionFee contains the base and tip rates. @@ -55,30 +60,3 @@ message TransactionFee { uint64 base_rate_max = 1; uint64 tip_rate_max = 2; } - -// the different types of valid transactions in lazyledger -enum TransactionType { - option (gogoproto.goproto_enum_stringer) = true; - option (gogoproto.goproto_enum_prefix) = false; - - // Unknown transaction type - TRANSACTION_TYPE_UNSPECIFIED = 0; - // Transfer moves tokens from one address to another - TRANSACTION_TYPE_TRANSFER = 1; - // PayForMessage removes funds from the account paying for the message - TRANSACTION_TYPE_PAY_FOR_MESSAGE = 2; - // CreateValidator creates a new validator - TRANSACTION_TYPE_CREATE_VALIDATOR = 3; - // BeginUnbondingValidator is meant to signal a validator's desire to unbond - TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR = 4; - // UnbondValidator unbonds - TRANSACTION_TYPE_UNBOND_VALIDATOR = 5; - // CreateDelegation begins the process of delegation to a bonded validator - TRANSACTION_TYPE_CREATE_DELEGATION = 6; - // BeginUnbondingDelegation starts the process to stop delegating - TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION = 7; - // UnbondDelegation finalizes stopping delegation - TRANSACTION_TYPE_UNBOND_DELEGATION = 8; - // Burn burns tokens from one account - TRANSACTION_TYPE_BURN = 9; -} \ No newline at end of file diff --git a/x/lazyledgerapp/handler.go b/x/lazyledgerapp/handler.go index facbb41ae0..101e04b2c1 100644 --- a/x/lazyledgerapp/handler.go +++ b/x/lazyledgerapp/handler.go @@ -11,11 +11,15 @@ import ( // NewHandler ... func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(k) + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { - // this line is used by starport scaffolding # 1 + case *types.MsgWirePayForMessage: + res, err := msgServer.PayForMessage(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) diff --git a/x/lazyledgerapp/keeper/keeper.go b/x/lazyledgerapp/keeper/keeper.go index 7481db7215..d32676e0be 100644 --- a/x/lazyledgerapp/keeper/keeper.go +++ b/x/lazyledgerapp/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "github.com/lazyledger/lazyledger-core/libs/log" @@ -10,22 +11,41 @@ import ( "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" ) -type ( - Keeper struct { - cdc codec.Marshaler - storeKey sdk.StoreKey - memKey sdk.StoreKey - } +// todo(evan): move these somewhere else +const ( + TokenDenomination = "token" ) -func NewKeeper(cdc codec.Marshaler, storeKey, memKey sdk.StoreKey) *Keeper { +type Keeper struct { + cdc codec.Marshaler + storeKey sdk.StoreKey + memKey sdk.StoreKey + bank BankKeeper + baseFee sdk.Int +} + +func NewKeeper(cdc codec.Marshaler, bank BankKeeper, storeKey, memKey sdk.StoreKey, baseFee sdk.Int) *Keeper { return &Keeper{ cdc: cdc, storeKey: storeKey, memKey: memKey, + bank: bank, + baseFee: baseFee, } } func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// PayForMessage moves a user's coins to the module address and burns them. +func (k Keeper) PayForMessage(goCtx context.Context, msg *types.MsgWirePayForMessage) (*types.MsgWirePayForMessageResponse, error) { + // don't pay for fees for the first version + return &types.MsgWirePayForMessageResponse{}, nil +} + +// BankKeeper restricts the funtionality of the bank keeper used in the lazyledgerapp keeper +type BankKeeper interface { + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error +} diff --git a/x/lazyledgerapp/keeper/msg_server.go b/x/lazyledgerapp/keeper/msg_server.go new file mode 100644 index 0000000000..6ceebde2e9 --- /dev/null +++ b/x/lazyledgerapp/keeper/msg_server.go @@ -0,0 +1,15 @@ +package keeper + +import "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" + +var _ types.MsgServer = msgServer{} + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the bank MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go new file mode 100644 index 0000000000..ccf63b4eab --- /dev/null +++ b/x/lazyledgerapp/types/payformessage.go @@ -0,0 +1,292 @@ +package types + +import ( + "crypto/sha256" + "errors" + fmt "fmt" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/lazyledger/lazyledger-core/crypto/merkle" + "github.com/lazyledger/nmt" +) + +const ( + TypeMsgPayforMessage = "payformessage" + TypeSignedTransactionDataPayForMessage = "signedtransactiondatapayformessage" + ShareSize = 256 +) + +/////////////////////////////////////// +// MsgWirePayForMessage +/////////////////////////////////////// + +var _ sdk.MsgRequest = &MsgWirePayForMessage{} + +func (msg *MsgWirePayForMessage) Route() string { return RouterKey } + +func (msg *MsgWirePayForMessage) Type() string { return TypeMsgPayforMessage } + +// ValidateBasic checks for valid namespace length, declared message size, share +// commitments, signatures for those share commitments, and fulfills the sdk.Msg +// interface +func (msg *MsgWirePayForMessage) ValidateBasic() error { + pubK := msg.PubKey() + _, err := sdk.AccAddressFromBech32(pubK.Address().String()) + if err != nil { + return sdkerrors.Wrapf( + sdkerrors.ErrInvalidAddress, + "Invalid sender address (%s)", + err, + ) + } + + // ensure that the namespace id is of length == 8 + if len(msg.GetMessageNameSpaceId()) != 8 { + return fmt.Errorf( + "invalid namespace length: got %d wanted 8", + len(msg.GetMessageNameSpaceId()), + ) + } + + // ensure that the included message is evenly divisble into shares + if uint64(len(msg.GetMessage()))%ShareSize != 0 { + return fmt.Errorf("Share message must be divisible by %d", ShareSize) + } + + // make sure that the message size matches the actual size of the message + if msg.MessageSize != uint64(len(msg.Message)) { + return fmt.Errorf( + "Declared Message size does not match actual Message size, %d vs %d", + msg.MessageSize, + len(msg.Message), + ) + } + + for _, commit := range msg.MessageShareCommitment { + // check that each commit is valid + calculatedCommit, err := CreateCommit(commit.K, msg.GetMessageNameSpaceId(), msg.Message) + if err != nil { + return err + } + + if string(calculatedCommit) != string(commit.ShareCommitment) { + return fmt.Errorf("invalid commit for square size %d", commit.K) + } + + // check that the signatures are valid + bytesToSign, err := msg.GetCommitSignBytes(commit.K) + if err != nil { + return err + } + + if !pubK.VerifySignature(bytesToSign, commit.Signature) { + return fmt.Errorf("invalid signature for share commitment to square size %d", commit.K) + } + } + + return nil +} + +// GetSignBytes returns messages bytes that need to be signed in order for the +// message to be valid todo(evan): follow the spec so that each share commitment +// is signed, instead of the entire message +func (msg *MsgWirePayForMessage) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +// GetSigners returns the addresses of the message signers +func (msg *MsgWirePayForMessage) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{sdk.AccAddress(msg.PubKey().Address())} +} + +// PubKey uses the string version of the public key to +func (msg *MsgWirePayForMessage) PubKey() *secp256k1.PubKey { + return &secp256k1.PubKey{Key: msg.PublicKey} +} + +// GetCommitSignBytes generates the bytes that each need to be signed per share commit +func (msg *MsgWirePayForMessage) GetCommitSignBytes(k uint64) ([]byte, error) { + sTxMsg, err := msg.SignedTransactionDataPayForMessage(k) + if err != nil { + return nil, err + } + return sTxMsg.GetSignBytes(), nil +} + +// SignedTransactionDataPayForMessage use the data in the MsgWirePayForMessage +// to create a new SignedTransactionDataPayForMessage +func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (*SignedTransactionDataPayForMessage, error) { + commit, err := CreateCommit(k, msg.MessageNameSpaceId, msg.Message) + if err != nil { + return nil, err + } + sTxMsg := SignedTransactionDataPayForMessage{ + Fee: &TransactionFee{ + BaseRateMax: msg.Fee.BaseRateMax, + TipRateMax: msg.Fee.TipRateMax, + }, + Nonce: msg.Nonce, + MessageNamespaceId: msg.MessageNameSpaceId, + MessageSize: msg.MessageSize, + MessageShareCommitment: commit, + } + return &sTxMsg, nil +} + +/////////////////////////////////////// +// SignedTransactionDataPayForMessage +/////////////////////////////////////// + +var _ sdk.Tx = &TxSignedTransactionDataPayForMessage{} + +// GetMsgs fullfills the sdk.Tx interface +func (tx *TxSignedTransactionDataPayForMessage) GetMsgs() []sdk.Msg { + return []sdk.Msg{tx.Message} +} + +// ValidateBasic fullfills the sdk.Tx interface by verifing the signature of the +// underlying signed transaction +func (tx *TxSignedTransactionDataPayForMessage) ValidateBasic() error { + pKey := secp256k1.PubKey{Key: tx.PublicKey} + + if !pKey.VerifySignature(tx.Message.GetSignBytes(), tx.Signature) { + return errors.New("failure to validte SignedTransactionDataPayForMessage") + } + return nil +} + +var _ sdk.Msg = &SignedTransactionDataPayForMessage{} + +// Route fullfills the sdk.Msg interface +func (msg *SignedTransactionDataPayForMessage) Route() string { return RouterKey } + +// Type fullfills the sdk.Msg interface +func (msg *SignedTransactionDataPayForMessage) Type() string { + return TypeSignedTransactionDataPayForMessage +} + +// ValidateBasic fullfills the sdk.Msg interface by performing stateless +// validity checks on the msg that also don't require having the actual message +func (msg *SignedTransactionDataPayForMessage) ValidateBasic() error { + // ensure that the namespace id is of length == 8 + if len(msg.GetMessageNamespaceId()) != 8 { + return fmt.Errorf( + "invalid namespace length: got %d wanted 8", + len(msg.GetMessageNamespaceId()), + ) + } + return nil +} + +// GetSignBytes fullfills the sdk.Msg interface by reterning a deterministic set +// of bytes to sign over +func (msg *SignedTransactionDataPayForMessage) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +// GetSigners fullfills the sdk.Msg interface but does not return anything, as +// SignTransactionDataPayForMessage doesn't have access the public key necessary +// in MsgWirePayForMessage +func (msg *SignedTransactionDataPayForMessage) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{} +} + +/////////////////////////////////////// +// Utilities +/////////////////////////////////////// + +// CreateCommit generates the commit bytes for a given message, namespace, and +// squaresize using a namespace merkle tree and the rules described at +// https://github.com/lazyledger/lazyledger-specs/blob/master/rationale/message_block_layout.md#non-interactive-default-rules +func CreateCommit(k uint64, namespace, message []byte) ([]byte, error) { + // break message into shares + shares := ChunkMessage(message) + + // organize shares for merkle mountain range + heights := PowerOf2MountainRange(uint64(len(shares)), k) + leafSets := make([][][]byte, len(heights)) + cursor := uint64(0) + for i, height := range heights { + leafSets[i] = shares[cursor : cursor+height] + cursor = cursor + height + } + + // create the commits by pushing each leaf set onto an nmt + subTreeRoots := make([][]byte, len(leafSets)) + for i, set := range leafSets { + // create the nmt + tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(8)) + for _, leaf := range set { + err := tree.Push(namespace, leaf) + if err != nil { + return nil, err + } + } + // add the root + subTreeRoots[i] = tree.Root().Bytes() + } + return merkle.HashFromByteSlices(subTreeRoots), nil +} + +// ChunkMessage breaks the message into 256 byte pieces +func ChunkMessage(message []byte) [][]byte { + var shares [][]byte + for i := 0; i < len(message); i += ShareSize { + end := i + ShareSize + if end > len(message) { + end = len(message) + } + shares = append(shares, message[i:end]) + } + return shares +} + +// PowerOf2MountainRange returns the heights of the subtrees for binary merkle +// mountian range +func PowerOf2MountainRange(l, k uint64) []uint64 { + var output []uint64 + + for l != 0 { + switch { + case l >= k: + output = append(output, k) + l = l - k + case l < k: + p := nextPowerOf2(l) + output = append(output, p) + l = l - p + } + } + + return output +} + +// nextPowerOf2 returns the next lowest power of 2 unless the input is a power +// of two, in which case it returns the input +func nextPowerOf2(v uint64) uint64 { + if v == 1 { + return 1 + } + // keep track of the input + i := v + + // find the next highest power using bit mashing + v-- + v |= v >> 1 + v |= v >> 2 + v |= v >> 4 + v |= v >> 8 + v |= v >> 16 + v |= v >> 32 + v++ + + // check if the input was the next highest power + if i == v { + return v + } + + // return the next lowest power + return v / 2 +} diff --git a/x/lazyledgerapp/types/payformessage_test.go b/x/lazyledgerapp/types/payformessage_test.go new file mode 100644 index 0000000000..086dda5326 --- /dev/null +++ b/x/lazyledgerapp/types/payformessage_test.go @@ -0,0 +1,120 @@ +package types + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMountainRange(t *testing.T) { + type test struct { + l, k uint64 + expected []uint64 + } + tests := []test{ + { + l: 11, + k: 4, + expected: []uint64{4, 4, 2, 1}, + }, + { + l: 2, + k: 64, + expected: []uint64{2}, + }, + { //should this test throw an error? we + l: 64, + k: 8, + expected: []uint64{8, 8, 8, 8, 8, 8, 8, 8}, + }, + } + for _, tt := range tests { + res := PowerOf2MountainRange(tt.l, tt.k) + assert.Equal(t, tt.expected, res) + } +} + +func TestNextPowerOf2(t *testing.T) { + type test struct { + input uint64 + expected uint64 + } + tests := []test{ + { + input: 2, + expected: 2, + }, + { + input: 11, + expected: 8, + }, + { + input: 511, + expected: 256, + }, + { + input: 1, + expected: 1, + }, + { + input: 0, + expected: 0, + }, + } + for _, tt := range tests { + res := nextPowerOf2(tt.input) + assert.Equal(t, tt.expected, res) + } +} + +// TestCreateCommit only shows if something changed, it doesn't actually show +// the commit is being created correctly todo(evan): fix me. +func TestCreateCommit(t *testing.T) { + type test struct { + k uint64 + namespace []byte + message []byte + expected []byte + } + tests := []test{ + { + k: 4, + namespace: bytes.Repeat([]byte{0xFF}, 8), + message: bytes.Repeat([]byte{0xFF}, 11*256), + expected: []byte{0x5d, 0x43, 0xd7, 0x40, 0xe5, 0xe6, 0x5e, 0x2a, 0xb9, 0x10, 0x5c, 0xf9, 0x26, 0xf9, 0xf0, 0x1c, 0x3a, 0x11, 0x49, 0x1c, 0x71, 0x21, 0xdf, 0x46, 0xdd, 0x21, 0x94, 0x3f, 0xba, 0xb1, 0xcf, 0xd4}, + }, + } + for _, tt := range tests { + res, err := CreateCommit(tt.k, tt.namespace, tt.message) + assert.NoError(t, err) + assert.Equal(t, tt.expected, res) + } +} + +func TestGetCommitSignBytes(t *testing.T) { + type test struct { + msg MsgWirePayForMessage + expected []byte + } + tests := []test{ + { + msg: MsgWirePayForMessage{ + MessageSize: 4, + Message: []byte{1, 2, 3, 4}, + MessageNameSpaceId: []byte{1, 2, 3, 4, 1, 2, 3, 4}, + Nonce: 1, + Fee: &TransactionFee{ + BaseRateMax: 10000, + TipRateMax: 1000, + }, + }, + expected: []byte(`{"fee":{"base_rate_max":"10000","tip_rate_max":"1000"},"message_namespace_id":"AQIDBAECAwQ=","message_share_commitment":"kLkMnfL0wruFOdgRJ4KnyjJBLJWlKxbEyks8SI0cfZs=","message_size":"4","nonce":"1","type":2}`), + }, + } + for _, tt := range tests { + res, err := tt.msg.GetCommitSignBytes(64) + assert.NoError(t, err) + assert.Equal(t, tt.expected, res) + } +} diff --git a/x/lazyledgerapp/types/tx.pb.go b/x/lazyledgerapp/types/tx.pb.go index 7ed455cb30..3067091063 100644 --- a/x/lazyledgerapp/types/tx.pb.go +++ b/x/lazyledgerapp/types/tx.pb.go @@ -29,66 +29,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// the different types of valid transactions in lazyledger -type TransactionType int32 - -const ( - // Unknown transaction type - TRANSACTION_TYPE_UNSPECIFIED TransactionType = 0 - // Transfer moves tokens from one address to another - TRANSACTION_TYPE_TRANSFER TransactionType = 1 - // PayForMessage removes funds from the account paying for the message - TRANSACTION_TYPE_PAY_FOR_MESSAGE TransactionType = 2 - // CreateValidator creates a new validator - TRANSACTION_TYPE_CREATE_VALIDATOR TransactionType = 3 - // BeginUnbondingValidator is meant to signal a validator's desire to unbond - TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR TransactionType = 4 - // UnbondValidator unbonds - TRANSACTION_TYPE_UNBOND_VALIDATOR TransactionType = 5 - // CreateDelegation begins the process of delegation to a bonded validator - TRANSACTION_TYPE_CREATE_DELEGATION TransactionType = 6 - // BeginUnbondingDelegation starts the process to stop delegating - TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION TransactionType = 7 - // UnbondDelegation finalizes stopping delegation - TRANSACTION_TYPE_UNBOND_DELEGATION TransactionType = 8 - // Burn burns tokens from one account - TRANSACTION_TYPE_BURN TransactionType = 9 -) - -var TransactionType_name = map[int32]string{ - 0: "TRANSACTION_TYPE_UNSPECIFIED", - 1: "TRANSACTION_TYPE_TRANSFER", - 2: "TRANSACTION_TYPE_PAY_FOR_MESSAGE", - 3: "TRANSACTION_TYPE_CREATE_VALIDATOR", - 4: "TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR", - 5: "TRANSACTION_TYPE_UNBOND_VALIDATOR", - 6: "TRANSACTION_TYPE_CREATE_DELEGATION", - 7: "TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION", - 8: "TRANSACTION_TYPE_UNBOND_DELEGATION", - 9: "TRANSACTION_TYPE_BURN", -} - -var TransactionType_value = map[string]int32{ - "TRANSACTION_TYPE_UNSPECIFIED": 0, - "TRANSACTION_TYPE_TRANSFER": 1, - "TRANSACTION_TYPE_PAY_FOR_MESSAGE": 2, - "TRANSACTION_TYPE_CREATE_VALIDATOR": 3, - "TRANSACTION_TYPE_BEGIN_UNBONDING_VALIDATOR": 4, - "TRANSACTION_TYPE_UNBOND_VALIDATOR": 5, - "TRANSACTION_TYPE_CREATE_DELEGATION": 6, - "TRANSACTION_TYPE_BEGIN_UNBONDING_DELEGATION": 7, - "TRANSACTION_TYPE_UNBOND_DELEGATION": 8, - "TRANSACTION_TYPE_BURN": 9, -} - -func (x TransactionType) String() string { - return proto.EnumName(TransactionType_name, int32(x)) -} - -func (TransactionType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_4a525bbab69d1e80, []int{0} -} - // WirePayForMessage describes the format of data that is sent over the wire for // each PayForMessage type MsgWirePayForMessage struct { @@ -98,7 +38,7 @@ type MsgWirePayForMessage struct { MessageSize uint64 `protobuf:"varint,4,opt,name=message_size,json=messageSize,proto3" json:"message_size,omitempty"` Message []byte `protobuf:"bytes,5,opt,name=message,proto3" json:"message,omitempty"` MessageShareCommitment []ShareCommitAndSignature `protobuf:"bytes,6,rep,name=message_share_commitment,json=messageShareCommitment,proto3" json:"message_share_commitment"` - From []byte `protobuf:"bytes,7,opt,name=from,proto3" json:"from,omitempty"` + PublicKey []byte `protobuf:"bytes,7,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` } func (m *MsgWirePayForMessage) Reset() { *m = MsgWirePayForMessage{} } @@ -176,17 +116,15 @@ func (m *MsgWirePayForMessage) GetMessageShareCommitment() []ShareCommitAndSigna return nil } -func (m *MsgWirePayForMessage) GetFrom() []byte { +func (m *MsgWirePayForMessage) GetPublicKey() []byte { if m != nil { - return m.From + return m.PublicKey } return nil } // WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage type MsgWirePayForMessageResponse struct { - Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` - Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"` } func (m *MsgWirePayForMessageResponse) Reset() { *m = MsgWirePayForMessageResponse{} } @@ -222,24 +160,11 @@ func (m *MsgWirePayForMessageResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWirePayForMessageResponse proto.InternalMessageInfo -func (m *MsgWirePayForMessageResponse) GetError() string { - if m != nil { - return m.Error - } - return "" -} - -func (m *MsgWirePayForMessageResponse) GetHash() []byte { - if m != nil { - return m.Hash - } - return nil -} - // ShareCommitAndSignature defines the type ShareCommitAndSignature struct { - ShareCommitment []byte `protobuf:"bytes,1,opt,name=share_commitment,json=shareCommitment,proto3" json:"share_commitment,omitempty"` - Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` + K uint64 `protobuf:"varint,1,opt,name=k,proto3" json:"k,omitempty"` + ShareCommitment []byte `protobuf:"bytes,2,opt,name=share_commitment,json=shareCommitment,proto3" json:"share_commitment,omitempty"` + Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` } func (m *ShareCommitAndSignature) Reset() { *m = ShareCommitAndSignature{} } @@ -275,6 +200,13 @@ func (m *ShareCommitAndSignature) XXX_DiscardUnknown() { var xxx_messageInfo_ShareCommitAndSignature proto.InternalMessageInfo +func (m *ShareCommitAndSignature) GetK() uint64 { + if m != nil { + return m.K + } + return 0 +} + func (m *ShareCommitAndSignature) GetShareCommitment() []byte { if m != nil { return m.ShareCommitment @@ -289,22 +221,83 @@ func (m *ShareCommitAndSignature) GetSignature() []byte { return nil } +// TxSignedTransactionDataPayForMessage is a wrapper around +// SignedTransactionDataPayForMessage that fullfills the sdk.Tx interface +type TxSignedTransactionDataPayForMessage struct { + Message *SignedTransactionDataPayForMessage `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` + PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` +} + +func (m *TxSignedTransactionDataPayForMessage) Reset() { *m = TxSignedTransactionDataPayForMessage{} } +func (m *TxSignedTransactionDataPayForMessage) String() string { return proto.CompactTextString(m) } +func (*TxSignedTransactionDataPayForMessage) ProtoMessage() {} +func (*TxSignedTransactionDataPayForMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{3} +} +func (m *TxSignedTransactionDataPayForMessage) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TxSignedTransactionDataPayForMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TxSignedTransactionDataPayForMessage.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TxSignedTransactionDataPayForMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_TxSignedTransactionDataPayForMessage.Merge(m, src) +} +func (m *TxSignedTransactionDataPayForMessage) XXX_Size() int { + return m.Size() +} +func (m *TxSignedTransactionDataPayForMessage) XXX_DiscardUnknown() { + xxx_messageInfo_TxSignedTransactionDataPayForMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_TxSignedTransactionDataPayForMessage proto.InternalMessageInfo + +func (m *TxSignedTransactionDataPayForMessage) GetMessage() *SignedTransactionDataPayForMessage { + if m != nil { + return m.Message + } + return nil +} + +func (m *TxSignedTransactionDataPayForMessage) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +func (m *TxSignedTransactionDataPayForMessage) GetPublicKey() []byte { + if m != nil { + return m.PublicKey + } + return nil +} + // SignedTransactionsDataPayForMessage is what gets signed by users when // creating ShareCommitSignatures. Multiple versions are signed and included. type SignedTransactionDataPayForMessage struct { - Type TransactionType `protobuf:"varint,1,opt,name=type,proto3,enum=lazyledgerapp.TransactionType" json:"type,omitempty"` - Fee *TransactionFee `protobuf:"bytes,2,opt,name=fee,proto3" json:"fee,omitempty"` - Nonce uint64 `protobuf:"varint,3,opt,name=nonce,proto3" json:"nonce,omitempty"` - MessageNamespaceId []byte `protobuf:"bytes,4,opt,name=message_namespace_id,json=messageNamespaceId,proto3" json:"message_namespace_id,omitempty"` - MessageSize uint64 `protobuf:"varint,5,opt,name=message_size,json=messageSize,proto3" json:"message_size,omitempty"` - MessageShareCommitment []byte `protobuf:"bytes,6,opt,name=message_share_commitment,json=messageShareCommitment,proto3" json:"message_share_commitment,omitempty"` + Fee *TransactionFee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee,omitempty"` + Nonce uint64 `protobuf:"varint,2,opt,name=nonce,proto3" json:"nonce,omitempty"` + MessageNamespaceId []byte `protobuf:"bytes,3,opt,name=message_namespace_id,json=messageNamespaceId,proto3" json:"message_namespace_id,omitempty"` + MessageSize uint64 `protobuf:"varint,4,opt,name=message_size,json=messageSize,proto3" json:"message_size,omitempty"` + MessageShareCommitment []byte `protobuf:"bytes,5,opt,name=message_share_commitment,json=messageShareCommitment,proto3" json:"message_share_commitment,omitempty"` } func (m *SignedTransactionDataPayForMessage) Reset() { *m = SignedTransactionDataPayForMessage{} } func (m *SignedTransactionDataPayForMessage) String() string { return proto.CompactTextString(m) } func (*SignedTransactionDataPayForMessage) ProtoMessage() {} func (*SignedTransactionDataPayForMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_4a525bbab69d1e80, []int{3} + return fileDescriptor_4a525bbab69d1e80, []int{4} } func (m *SignedTransactionDataPayForMessage) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -333,13 +326,6 @@ func (m *SignedTransactionDataPayForMessage) XXX_DiscardUnknown() { var xxx_messageInfo_SignedTransactionDataPayForMessage proto.InternalMessageInfo -func (m *SignedTransactionDataPayForMessage) GetType() TransactionType { - if m != nil { - return m.Type - } - return TRANSACTION_TYPE_UNSPECIFIED -} - func (m *SignedTransactionDataPayForMessage) GetFee() *TransactionFee { if m != nil { return m.Fee @@ -385,7 +371,7 @@ func (m *TransactionFee) Reset() { *m = TransactionFee{} } func (m *TransactionFee) String() string { return proto.CompactTextString(m) } func (*TransactionFee) ProtoMessage() {} func (*TransactionFee) Descriptor() ([]byte, []int) { - return fileDescriptor_4a525bbab69d1e80, []int{4} + return fileDescriptor_4a525bbab69d1e80, []int{5} } func (m *TransactionFee) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -429,10 +415,10 @@ func (m *TransactionFee) GetTipRateMax() uint64 { } func init() { - proto.RegisterEnum("lazyledgerapp.TransactionType", TransactionType_name, TransactionType_value) proto.RegisterType((*MsgWirePayForMessage)(nil), "lazyledgerapp.MsgWirePayForMessage") proto.RegisterType((*MsgWirePayForMessageResponse)(nil), "lazyledgerapp.MsgWirePayForMessageResponse") proto.RegisterType((*ShareCommitAndSignature)(nil), "lazyledgerapp.ShareCommitAndSignature") + proto.RegisterType((*TxSignedTransactionDataPayForMessage)(nil), "lazyledgerapp.TxSignedTransactionDataPayForMessage") proto.RegisterType((*SignedTransactionDataPayForMessage)(nil), "lazyledgerapp.SignedTransactionDataPayForMessage") proto.RegisterType((*TransactionFee)(nil), "lazyledgerapp.TransactionFee") } @@ -440,56 +426,45 @@ func init() { func init() { proto.RegisterFile("lazyledgerapp/tx.proto", fileDescriptor_4a525bbab69d1e80) } var fileDescriptor_4a525bbab69d1e80 = []byte{ - // 778 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x95, 0xcf, 0x8f, 0xda, 0x46, - 0x14, 0xc7, 0x31, 0x98, 0xdd, 0xec, 0xc0, 0x26, 0x68, 0x44, 0x52, 0x07, 0x11, 0x97, 0xb8, 0x6d, - 0x44, 0x37, 0x2a, 0x4e, 0xe9, 0xa5, 0xea, 0xcd, 0x80, 0xa1, 0x48, 0xc1, 0xa0, 0xb1, 0x37, 0x55, - 0x7a, 0xb1, 0x06, 0x18, 0x8c, 0x25, 0xec, 0xb1, 0x3c, 0x8e, 0x04, 0x7b, 0xec, 0xa9, 0xc7, 0x4a, - 0x7b, 0x6c, 0x6f, 0xed, 0xa1, 0xa7, 0xfe, 0x1d, 0xdb, 0xdb, 0x4a, 0xbd, 0xf4, 0x54, 0x55, 0xbb,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a0, 0x0c, 0x5e, 0xfe, 0x6b, 0xfb, 0x44, 0xc1, 0xf1, 0x5e, 0xe1, 0x75, 0xff, 0x04, 0xf7, 0x00, - 0x3e, 0x05, 0x8f, 0xd3, 0xc2, 0xe7, 0x48, 0x2b, 0x9d, 0x54, 0x1e, 0x7c, 0xfb, 0xa3, 0x98, 0xf9, - 0xf9, 0x27, 0x91, 0x6b, 0x7e, 0xcf, 0x81, 0xdc, 0x80, 0x59, 0xf0, 0x92, 0x03, 0xa7, 0xdb, 0x57, - 0xe3, 0x83, 0x1d, 0x67, 0xef, 0xbb, 0xfc, 0x95, 0x97, 0xff, 0x01, 0xda, 0x7c, 0x21, 0xa4, 0x57, - 0xdf, 0xfc, 0xf6, 0xd7, 0x65, 0xf6, 0x0c, 0xd6, 0xe5, 0x05, 0x5e, 0x6d, 0xaa, 0xe4, 0xed, 0xaf, - 0xbf, 0x87, 0x57, 0x33, 0xea, 0xaf, 0x3d, 0xda, 0x32, 0xae, 0x6e, 0x44, 0xee, 0xfa, 0x46, 0xe4, - 0xfe, 0xbc, 0x11, 0xb9, 0xef, 0x6e, 0xc5, 0xcc, 0xf5, 0xad, 0x98, 0xf9, 0xfd, 0x56, 0xcc, 0x7c, - 0xfd, 0x85, 0x65, 0x07, 0xf3, 0x77, 0xe3, 0xc6, 0x84, 0x3a, 0x09, 0x85, 0xc4, 0xf2, 0x93, 0x50, - 0x6d, 0xb9, 0xa3, 0x1e, 0xde, 0x5f, 0x36, 0x3e, 0x8a, 0x7e, 0x0e, 0x9f, 0xfd, 0x1d, 0x00, 0x00, - 0xff, 0xff, 0xaf, 0x90, 0xc0, 0x7f, 0x79, 0x06, 0x00, 0x00, + // 600 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xce, 0x26, 0x69, 0xab, 0x4e, 0xd2, 0xdf, 0x0f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0xd4, 0xf1, 0x71, 0xcc, 0x36, 0x2a, + 0xb0, 0xeb, 0x48, 0xa2, 0xea, 0xcd, 0x27, 0x7f, 0xdd, 0x93, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x61, 0x4c, 0x17, 0xa5, 0x48, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -594,10 +569,10 @@ func (m *MsgWirePayForMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.From) > 0 { - i -= len(m.From) - copy(dAtA[i:], m.From) - i = encodeVarintTx(dAtA, i, uint64(len(m.From))) + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PublicKey))) i-- dAtA[i] = 0x3a } @@ -674,20 +649,6 @@ func (m *MsgWirePayForMessageResponse) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l - if len(m.Hash) > 0 { - i -= len(m.Hash) - copy(dAtA[i:], m.Hash) - i = encodeVarintTx(dAtA, i, uint64(len(m.Hash))) - i-- - dAtA[i] = 0x12 - } - if len(m.Error) > 0 { - i -= len(m.Error) - copy(dAtA[i:], m.Error) - i = encodeVarintTx(dAtA, i, uint64(len(m.Error))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } @@ -716,13 +677,67 @@ func (m *ShareCommitAndSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) copy(dAtA[i:], m.Signature) i = encodeVarintTx(dAtA, i, uint64(len(m.Signature))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.ShareCommitment) > 0 { i -= len(m.ShareCommitment) copy(dAtA[i:], m.ShareCommitment) i = encodeVarintTx(dAtA, i, uint64(len(m.ShareCommitment))) i-- + dAtA[i] = 0x12 + } + if m.K != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.K)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *TxSignedTransactionDataPayForMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TxSignedTransactionDataPayForMessage) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TxSignedTransactionDataPayForMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0x1a + } + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x12 + } + if m.Message != nil { + { + size, err := m.Message.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -753,24 +768,24 @@ func (m *SignedTransactionDataPayForMessage) MarshalToSizedBuffer(dAtA []byte) ( copy(dAtA[i:], m.MessageShareCommitment) i = encodeVarintTx(dAtA, i, uint64(len(m.MessageShareCommitment))) i-- - dAtA[i] = 0x32 + dAtA[i] = 0x2a } if m.MessageSize != 0 { i = encodeVarintTx(dAtA, i, uint64(m.MessageSize)) i-- - dAtA[i] = 0x28 + dAtA[i] = 0x20 } if len(m.MessageNamespaceId) > 0 { i -= len(m.MessageNamespaceId) copy(dAtA[i:], m.MessageNamespaceId) i = encodeVarintTx(dAtA, i, uint64(len(m.MessageNamespaceId))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } if m.Nonce != 0 { i = encodeVarintTx(dAtA, i, uint64(m.Nonce)) i-- - dAtA[i] = 0x18 + dAtA[i] = 0x10 } if m.Fee != nil { { @@ -782,12 +797,7 @@ func (m *SignedTransactionDataPayForMessage) MarshalToSizedBuffer(dAtA []byte) ( i = encodeVarintTx(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 - } - if m.Type != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -866,7 +876,7 @@ func (m *MsgWirePayForMessage) Size() (n int) { n += 1 + l + sovTx(uint64(l)) } } - l = len(m.From) + l = len(m.PublicKey) if l > 0 { n += 1 + l + sovTx(uint64(l)) } @@ -879,31 +889,47 @@ func (m *MsgWirePayForMessageResponse) Size() (n int) { } var l int _ = l - l = len(m.Error) + return n +} + +func (m *ShareCommitAndSignature) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.K != 0 { + n += 1 + sovTx(uint64(m.K)) + } + l = len(m.ShareCommitment) if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Hash) + l = len(m.Signature) if l > 0 { n += 1 + l + sovTx(uint64(l)) } return n } -func (m *ShareCommitAndSignature) Size() (n int) { +func (m *TxSignedTransactionDataPayForMessage) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = len(m.ShareCommitment) - if l > 0 { + if m.Message != nil { + l = m.Message.Size() n += 1 + l + sovTx(uint64(l)) } l = len(m.Signature) if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -913,9 +939,6 @@ func (m *SignedTransactionDataPayForMessage) Size() (n int) { } var l int _ = l - if m.Type != 0 { - n += 1 + sovTx(uint64(m.Type)) - } if m.Fee != nil { l = m.Fee.Size() n += 1 + l + sovTx(uint64(l)) @@ -1165,7 +1188,7 @@ func (m *MsgWirePayForMessage) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 7: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field From", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1192,9 +1215,9 @@ func (m *MsgWirePayForMessage) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.From = append(m.From[:0], dAtA[iNdEx:postIndex]...) - if m.From == nil { - m.From = []byte{} + m.PublicKey = append(m.PublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.PublicKey == nil { + m.PublicKey = []byte{} } iNdEx = postIndex default: @@ -1250,11 +1273,83 @@ func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgWirePayForMessageResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ShareCommitAndSignature) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ShareCommitAndSignature: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ShareCommitAndSignature: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field K", wireType) + } + m.K = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.K |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ShareCommitment", wireType) } - var stringLen uint64 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1264,27 +1359,29 @@ func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if byteLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.Error = string(dAtA[iNdEx:postIndex]) + m.ShareCommitment = append(m.ShareCommitment[:0], dAtA[iNdEx:postIndex]...) + if m.ShareCommitment == nil { + m.ShareCommitment = []byte{} + } iNdEx = postIndex - case 2: + case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1311,9 +1408,9 @@ func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) - if m.Hash == nil { - m.Hash = []byte{} + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} } iNdEx = postIndex default: @@ -1340,7 +1437,7 @@ func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *ShareCommitAndSignature) Unmarshal(dAtA []byte) error { +func (m *TxSignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1363,17 +1460,17 @@ func (m *ShareCommitAndSignature) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ShareCommitAndSignature: wiretype end group for non-group") + return fmt.Errorf("proto: TxSignedTransactionDataPayForMessage: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ShareCommitAndSignature: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: TxSignedTransactionDataPayForMessage: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ShareCommitment", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) } - var byteLen int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -1383,24 +1480,26 @@ func (m *ShareCommitAndSignature) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + if msglen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + byteLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - m.ShareCommitment = append(m.ShareCommitment[:0], dAtA[iNdEx:postIndex]...) - if m.ShareCommitment == nil { - m.ShareCommitment = []byte{} + if m.Message == nil { + m.Message = &SignedTransactionDataPayForMessage{} + } + if err := m.Message.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex case 2: @@ -1437,6 +1536,40 @@ func (m *ShareCommitAndSignature) Unmarshal(dAtA []byte) error { m.Signature = []byte{} } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = append(m.PublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.PublicKey == nil { + m.PublicKey = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -1491,25 +1624,6 @@ func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= TransactionType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) } @@ -1545,7 +1659,7 @@ func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Nonce", wireType) } @@ -1564,7 +1678,7 @@ func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { break } } - case 4: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MessageNamespaceId", wireType) } @@ -1598,7 +1712,7 @@ func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { m.MessageNamespaceId = []byte{} } iNdEx = postIndex - case 5: + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field MessageSize", wireType) } @@ -1617,7 +1731,7 @@ func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { break } } - case 6: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MessageShareCommitment", wireType) } diff --git a/x/lazyledgerapp/types/tx.pb.gw.go b/x/lazyledgerapp/types/tx.pb.gw.go index dfadd14b4d..b3167be184 100644 --- a/x/lazyledgerapp/types/tx.pb.gw.go +++ b/x/lazyledgerapp/types/tx.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join var ( filter_Msg_PayForMessage_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} @@ -70,12 +72,14 @@ func local_request_Msg_PayForMessage_0(ctx context.Context, marshaler runtime.Ma // RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". // UnaryRPC :call MsgServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { mux.Handle("GET", pattern_Msg_PayForMessage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -83,6 +87,7 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } resp, md, err := local_request_Msg_PayForMessage_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) From 9afafdb1b5e136d3a46b81f1a6ffb026df565b2e Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Thu, 11 Feb 2021 18:50:46 -0600 Subject: [PATCH 03/10] integrate PayForMessage into PreprocessTxs delete unused utility func change the respone type name to appease the linter go mod tidy app: just save the encoding config instead of the only the tx encoder and decoders types: register PayForMessage types in the codec registry break up testing into two chunks. document process add a sanity check for signing and verifying signatures lazyledgerapp: sign the commit bytes instead of the message bytes add genesis accounts, and attempt to debug why the signature data is getting erased clean up tests a bit, and fix bug causing the inability to verify the signature app: add sorting by namespace ids for returned core.Messages clean up unused code slight reorg of tests unused code caught by linter only pass successfully processed txs update test fix accidental changes to go.mod mod.go: fixed the dep that was causing weird ci errors and failed proto generation init simapp flags when testing run make build --- app/abci.go | 141 +++++-- app/abci_test.go | 432 ++++++++++++++++---- app/app.go | 9 +- go.mod | 12 +- go.sum | 95 +++-- proto/lazyledgerapp/tx.proto | 4 +- x/lazyledgerapp/keeper/keeper.go | 4 +- x/lazyledgerapp/types/codec.go | 6 +- x/lazyledgerapp/types/payformessage.go | 18 +- x/lazyledgerapp/types/payformessage_test.go | 4 +- x/lazyledgerapp/types/tx.pb.go | 130 +++--- x/lazyledgerapp/types/tx.pb.gw.go | 7 +- 12 files changed, 615 insertions(+), 247 deletions(-) diff --git a/app/abci.go b/app/abci.go index 74b9223642..38d1fa8b2a 100644 --- a/app/abci.go +++ b/app/abci.go @@ -1,6 +1,12 @@ package app import ( + "bytes" + "errors" + "fmt" + "sort" + + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" abci "github.com/lazyledger/lazyledger-core/abci/types" core "github.com/lazyledger/lazyledger-core/proto/tendermint/types" @@ -13,75 +19,142 @@ import ( // share messages from transactions // todo(evan): refactor out a for loop. func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePreprocessTxs { + squareSize := app.SquareSize() + shareCounter := uint64(0) var shareMsgs []*core.Message + var processedTxs [][]byte for _, rawTx := range txs.Txs { // decode the Tx - tx, err := app.txDecoder(rawTx) + tx, err := app.txConfig.TxDecoder()(rawTx) if err != nil { continue } - // run basic validation on the transaction - err = tx.ValidateBasic() - if err != nil { + // don't do anything if the transaction doesn't contain a PayForMessage sdk.Msg + if !hasWirePayForMessage(tx) { + processedTxs = append(processedTxs, rawTx) continue } - // don't allow transactions with multiple messages to be ran + // only support transactions that contain a single sdk.Msg for now if len(tx.GetMsgs()) != 1 { continue } msg := tx.GetMsgs()[0] - // run basic validation on the msg - err = msg.ValidateBasic() + // run basic validation on the transaction + err = tx.ValidateBasic() if err != nil { continue } - // quickly check the stated type of the message - if msg.Type() != types.TypeMsgPayforMessage { + // process and validate the message + coreMsg, signedTx, err := app.processMsg(msg) + if err != nil { continue } - // double check the actual type of the message - wireMsg, ok := msg.(*types.MsgWirePayForMessage) - if !ok { + // execute the tx in runTxModeDeliver mode (3) + // execution includes all validation checks burning fees + // currently, no fees are burned + _, _, err = app.BaseApp.TxRunner()(3, rawTx) + if err != nil { + continue } - // todo(evan): this needs to turn the transaction into a SignedTransactionDataPayForMessage - // // discard the share commitments that won't be used - // var shareCommit types.ShareCommitAndSignature - // for _, commit := range wireMsg.MessageShareCommitment { - // if commit.K == app.SquareSize() { - // shareCommit = commit - // break - // } - // } + // increment the share counter by the number of shares taken by the message + sharesTaken := uint64(len(coreMsg.Data) / 256) + shareCounter += sharesTaken - // make sure to get rid of excess txs or do something with them + // if there are too many shares stop processing and return the transactions + // this is related to issues 67 and 77 of lazyledger-core + if shareCounter > squareSize { + break + } - // execute the tx in runTxModeDeliver mode (3) - // execution includes all validation checks burning fees - _, _, err = app.BaseApp.TxRunner()(3, rawTx) + // encode the processed tx + rawProcessedTx, err := app.appCodec.MarshalBinaryBare(signedTx) if err != nil { continue } - // the message is valid and paid for, include it in the response - shareMsgs = append( - shareMsgs, - &core.Message{ - NamespaceId: wireMsg.GetMessageNameSpaceId(), - Data: wireMsg.Message, - }, - ) + // add the message and tx to the output + shareMsgs = append(shareMsgs, &coreMsg) + processedTxs = append(processedTxs, rawProcessedTx) } + // sort messages lexographically + sort.Slice(shareMsgs, func(i, j int) bool { + return bytes.Compare(shareMsgs[i].NamespaceId, shareMsgs[j].NamespaceId) < 0 + }) + return abci.ResponsePreprocessTxs{ - Txs: txs.Txs, + Txs: processedTxs, Messages: &core.Messages{MessagesList: shareMsgs}, } } + +func hasWirePayForMessage(tx sdk.Tx) bool { + for _, msg := range tx.GetMsgs() { + if msg.Type() == types.TypeMsgPayforMessage { + return true + } + } + return false +} + +// processMsgs will perform the processing required by PreProcessTxs for a set +// of sdk.Msg's from a single sdk.Tx +func (app *App) processMsg(msg sdk.Msg) (core.Message, *types.TxSignedTransactionDataPayForMessage, error) { + squareSize := app.SquareSize() + // reject all msgs in tx if a single included msg is not correct type + wireMsg, ok := msg.(*types.MsgWirePayForMessage) + if !ok { + return core.Message{}, + nil, + errors.New("transaction contained a message type other than types.MsgWirePayForMessage") + } + + // make sure that a ShareCommitAndSignature of the correct size is + // included in the message + var shareCommit types.ShareCommitAndSignature + for _, commit := range wireMsg.MessageShareCommitment { + if commit.K == squareSize { + shareCommit = commit + } + } + // K == 0 means there was no share commit with the desired current square size + if shareCommit.K == 0 { + return core.Message{}, + nil, + fmt.Errorf("No share commit for correct square size. Current square size: %d", squareSize) + } + + // run basic validation on the msg + err := wireMsg.ValidateBasic() + if err != nil { + return core.Message{}, nil, err + } + + // add the message to the list of core message to be returned to ll-core + coreMsg := core.Message{ + NamespaceId: wireMsg.GetMessageNameSpaceId(), + Data: wireMsg.GetMessage(), + } + + // wrap the signed transaction data + sTxData, err := wireMsg.SignedTransactionDataPayForMessage(squareSize) + if err != nil { + return core.Message{}, nil, err + } + + signedData := &types.TxSignedTransactionDataPayForMessage{ + Message: sTxData, + Signature: shareCommit.Signature, + PublicKey: wireMsg.PublicKey, + } + + return coreMsg, signedData, nil +} diff --git a/app/abci_test.go b/app/abci_test.go index c857a0f116..3d3e891fea 100644 --- a/app/abci_test.go +++ b/app/abci_test.go @@ -1,62 +1,308 @@ package app import ( + "bytes" + "encoding/json" + "fmt" "os" "testing" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" + cliTx "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" abci "github.com/lazyledger/lazyledger-core/abci/types" "github.com/lazyledger/lazyledger-core/libs/log" + core "github.com/lazyledger/lazyledger-core/proto/tendermint/types" "github.com/spf13/cast" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" dbm "github.com/tendermint/tm-db" ) -// this test doesn't currently test anything, but it's a good starting template -func TestPreProcessTxs(t *testing.T) { - testApp := setupApp() - basicTx := &types.MsgWirePayForMessage{ - MessageSize: 4, - Message: []byte{1, 2, 3, 4}, - MessageNameSpaceId: []byte{1, 2, 3, 4}, - From: "cosmos1tg66f06v0jh42g5wxnht9a5fqqj0lu78n37ss5", +// TODO: +// - flesh tests with more cases +// - test for when the tx should fail + +// Get flags every time the simulator is run +func init() { + simapp.GetSimulatorFlags() +} + +func TestProcessMsg(t *testing.T) { + key := secp256k1.GenPrivKey() + + testApp := setupApp(t) + + for acc := range maccPerms { + require.Equal(t, !allowedReceivingModAcc[acc], testApp.BankKeeper.BlockedAddr(testApp.AccountKeeper.GetModuleAddress(acc)), + "ensure that blocked addresses are properly set in bank keeper") } - rawBasicTx, err := testApp.txEncoder(txTest{[]sdk.Msg{basicTx}}) + + genesisState := NewDefaultGenesisState() + + genesisState, err := addGenesisAccount(sdk.AccAddress(key.PubKey().Address().Bytes()), genesisState, testApp.appCodec) if err != nil { t.Error(err) } + + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + + // Initialize the chain + testApp.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + AppStateBytes: stateBytes, + }, + ) + + // create a tx + msg := generateWirePayForMessage(t, testApp.SquareSize(), key) + tests := []struct { name string - args abci.RequestPreprocessTxs - want abci.ResponsePreprocessTxs + args sdk.Msg + want core.Message }{ { name: "basic", - args: abci.RequestPreprocessTxs{ - Txs: [][]byte{rawBasicTx}, - }, + args: msg, + want: core.Message{NamespaceId: msg.MessageNameSpaceId, Data: msg.Message}, }, } for _, tt := range tests { - result := testApp.PreprocessTxs(tt.args) + result, _, err := testApp.processMsg(tt.args) + if err != nil { + t.Error(err) + } assert.Equal(t, tt.want, result, tt.name) } } -func generateTxs() [][]byte { - return [][]byte{} +// this belongs in the lazyledgerapp/simulation package +func TestRunTx(t *testing.T) { + key := secp256k1.GenPrivKey() + + testApp := setupApp(t) + + for acc := range maccPerms { + require.Equal(t, !allowedReceivingModAcc[acc], testApp.BankKeeper.BlockedAddr(testApp.AccountKeeper.GetModuleAddress(acc)), + "ensure that blocked addresses are properly set in bank keeper") + } + + genesisState := NewDefaultGenesisState() + + // give the key a bunch a coins for testing + genesisState, err := addGenesisAccount(sdk.AccAddress(key.PubKey().Address().Bytes()), genesisState, testApp.appCodec) + if err != nil { + t.Error(err) + } + + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + + // Initialize the chain + testApp.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + AppStateBytes: stateBytes, + ChainId: "test-chain", + }, + ) + + // create a msg + msg := generateWirePayForMessage(t, 64, key) + + // this is returning a tx.wrapper + builder := testApp.txConfig.NewTxBuilder() + err = builder.SetMsgs(msg) + if err != nil { + t.Error(err) + } + + coin := sdk.Coin{ + Denom: "token", + Amount: sdk.NewInt(1000), + } + + builder.SetFeeAmount(sdk.NewCoins(coin)) + builder.SetGasLimit(10000) + builder.SetTimeoutHeight(99) + + signingData := authsigning.SignerData{ + ChainID: "test-chain", + AccountNumber: 0, + Sequence: 0, + } + + // Important set the Signature to nil BEFORE actually signing + sigData := signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + } + + sig := signing.SignatureV2{ + PubKey: key.PubKey(), + Data: &sigData, + Sequence: 0, + } + + // set the empty signature + err = builder.SetSignatures(sig) + if err != nil { + if err != nil { + t.Error(err) + } + } + + // create the actual signature + sigV2, err := cliTx.SignWithPrivKey(signing.SignMode_SIGN_MODE_DIRECT, signingData, builder, key, testApp.txConfig, 0) + if err != nil { + t.Error(err) + } + + // set the actual signature + err = builder.SetSignatures(sigV2) + if err != nil { + if err != nil { + t.Error(err) + } + } + + // finish the tx + tx := builder.GetTx() + + // verify the signature before encoding + err = authsigning.VerifySignature(key.PubKey(), signingData, sigV2.Data, testApp.txConfig.SignModeHandler(), tx) + if err != nil { + t.Error(err) + } + + rawTx, err := testApp.txConfig.TxEncoder()(tx) + if err != nil { + t.Error(err) + } + + tests := []struct { + name string + input []byte + want core.Message + mode uint8 + }{ + { + name: "basic", + mode: 3, + input: rawTx, + want: core.Message{NamespaceId: msg.MessageNameSpaceId, Data: msg.Message}, + }, + } + + for _, tt := range tests { + _, _, err := testApp.TxRunner()(3, tt.input) + assert.NoError(t, err, "failure to validate and run tx") + } } -func setupApp() *App { +// this is more of a sanity check +func TestTxSignature(t *testing.T) { + key := secp256k1.GenPrivKey() + + encConf := MakeEncodingConfig() + txConf := encConf.TxConfig + + // create a msg + msg := generateWirePayForMessage(t, 64, key) + + // this is returning a tx.wrapper + builder := txConf.NewTxBuilder() + err := builder.SetMsgs(msg) + if err != nil { + t.Error(err) + } + + signingData := authsigning.SignerData{ + ChainID: "test-chain", + AccountNumber: 0, + Sequence: 0, + } + + sigData := signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + } + + sig := signing.SignatureV2{ + PubKey: key.PubKey(), + Data: &sigData, + Sequence: 0, + } + + // set the unsigned signature data (nil) first + // this is required for SignWithPriveKey to sign properly + err = builder.SetSignatures(sig) + if err != nil { + if err != nil { + t.Error(err) + } + } + + sigV2, err := cliTx.SignWithPrivKey(signing.SignMode_SIGN_MODE_DIRECT, signingData, builder, key, txConf, 0) + if err != nil { + t.Error(err) + } + + err = builder.SetSignatures(sigV2) + if err != nil { + if err != nil { + t.Error(err) + } + } + + tx := builder.GetTx() + + err = authsigning.VerifySignature(key.PubKey(), signingData, sigV2.Data, txConf.SignModeHandler(), tx) + if err != nil { + t.Error("failure to verify Signature") + } + + rawTx, err := txConf.TxEncoder()(tx) + if err != nil { + t.Error(err) + } + + stx, err := txConf.TxDecoder()(rawTx) + if err != nil { + t.Error(err) + } + + // verify the signature after decoding + err = authsigning.VerifySignature(key.PubKey(), signingData, sigV2.Data, txConf.SignModeHandler(), stx) + if err != nil { + t.Error(err) + } +} + +///////////////////////////// +// Setup App +///////////////////////////// + +func setupApp(t *testing.T) *App { // var cache sdk.MultiStorePersistentCache // EmptyAppOptions is a stub implementing AppOptions emptyOpts := emptyAppOptions{} + var anteOpt = func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(nil) } db := dbm.NewMemDB() - logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger := log.NewTMLogger(log.NewSyncWriter(os.Stderr)) skipUpgradeHeights := make(map[int64]bool) @@ -64,8 +310,9 @@ func setupApp() *App { "test-app", logger, db, nil, true, skipUpgradeHeights, cast.ToString(emptyOpts.Get(flags.FlagHome)), cast.ToUint(emptyOpts.Get(server.FlagInvCheckPeriod)), - MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd. + MakeEncodingConfig(), emptyOpts, + anteOpt, ) } @@ -76,63 +323,110 @@ func (ao emptyAppOptions) Get(o string) interface{} { return nil } +// addGenesisAccount mimics the cli addGenesisAccount command, providing an +// account with an allocation of to "token" and "stake" tokens in the genesis +// state +func addGenesisAccount(addr sdk.AccAddress, appState map[string]json.RawMessage, cdc codec.Marshaler) (map[string]json.RawMessage, error) { + // create concrete account type based on input parameters + var genAccount authtypes.GenesisAccount + + coins := sdk.Coins{ + sdk.NewCoin("token", sdk.NewInt(1000000)), + sdk.NewCoin("stake", sdk.NewInt(1000000)), + } + + balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()} + baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0) + + genAccount = baseAccount + + if err := genAccount.Validate(); err != nil { + return appState, fmt.Errorf("failed to validate new genesis account: %w", err) + } + + authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState) + + accs, err := authtypes.UnpackAccounts(authGenState.Accounts) + if err != nil { + return appState, fmt.Errorf("failed to get accounts from any: %w", err) + } + + if accs.Contains(addr) { + return appState, fmt.Errorf("cannot add account at existing address %s", addr) + } + + // Add the new account to the set of genesis accounts and sanitize the + // accounts afterwards. + accs = append(accs, genAccount) + accs = authtypes.SanitizeGenesisAccounts(accs) + + genAccs, err := authtypes.PackAccounts(accs) + if err != nil { + return appState, fmt.Errorf("failed to convert accounts into any's: %w", err) + } + authGenState.Accounts = genAccs + + authGenStateBz, err := cdc.MarshalJSON(&authGenState) + if err != nil { + return appState, fmt.Errorf("failed to marshal auth genesis state: %w", err) + } + + appState[authtypes.ModuleName] = authGenStateBz + + bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState) + bankGenState.Balances = append(bankGenState.Balances, balances) + bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances) + + bankGenStateBz, err := cdc.MarshalJSON(bankGenState) + if err != nil { + return appState, fmt.Errorf("failed to marshal bank genesis state: %w", err) + } + + appState[banktypes.ModuleName] = bankGenStateBz + return appState, nil +} + ///////////////////////////// // Generate Txs ///////////////////////////// -func generateRawTxs(t *testing.T, count int, txEncoder sdk.TxEncoder) [][]byte { - output := make([][]byte, count) - for i := 0; i < count; i++ { - // create the tx - tx := newTxCounter(int64(i), int64(i)) - // encode the tx - raw, err := txEncoder(tx) - if err != nil { - t.Error(err) - } - output[i] = raw - } - return output -} +func generateWirePayForMessage(t *testing.T, k uint64, key *secp256k1.PrivKey) *types.MsgWirePayForMessage { + pubKey := key.PubKey() -// Simple tx with a list of Msgs. -type txTest struct { - Msgs []sdk.Msg -} + message := bytes.Repeat([]byte{2}, 512) + nsp := []byte{1, 1, 1, 1, 1, 1, 1, 1} -// Implements Tx -func (tx txTest) GetMsgs() []sdk.Msg { return tx.Msgs } -func (tx txTest) ValidateBasic() error { return nil } + commit, err := types.CreateCommit(k, nsp, message) + if err != nil { + t.Error(err) + } -// ValidateBasic() fails on negative counters. -// Otherwise it's up to the handlers -type msgCounter struct { - Counter int64 - FailOnHandler bool -} + msg := &types.MsgWirePayForMessage{ + Fee: &types.TransactionFee{}, + Nonce: 0, + MessageNameSpaceId: nsp, + MessageSize: 512, + Message: message, + PublicKey: pubKey.Bytes(), + MessageShareCommitment: []types.ShareCommitAndSignature{ + { + K: k, + ShareCommitment: commit, + }, + }, + } -// dummy implementation of proto.Message -func (msg msgCounter) Reset() {} -func (msg msgCounter) String() string { return "TODO" } -func (msg msgCounter) ProtoMessage() {} - -// Implements Msg -func (msg msgCounter) Route() string { return "lazyledgerapp" } -func (msg msgCounter) Type() string { return types.TypeMsgPayforMessage } -func (msg msgCounter) GetSignBytes() []byte { return nil } -func (msg msgCounter) GetSigners() []sdk.AccAddress { return nil } -func (msg msgCounter) ValidateBasic() error { - if msg.Counter >= 0 { - return nil - } - return sdkerrors.Wrap(sdkerrors.ErrInvalidSequence, "counter should be a non-negative integer") -} + rawTxPFM, err := msg.GetCommitSignBytes(k) + if err != nil { + t.Error(err) + } -func newTxCounter(counter int64, msgCounters ...int64) *txTest { - msgs := make([]sdk.Msg, 0, len(msgCounters)) - for _, c := range msgCounters { - msgs = append(msgs, msgCounter{c, false}) + signedTxPFM, err := key.Sign(rawTxPFM) + if err != nil { + t.Error(err) } - return &txTest{msgs} + msg.MessageShareCommitment[0].Signature = signedTxPFM + + return msg } diff --git a/app/app.go b/app/app.go index 612ce6f3c0..827d6870f9 100644 --- a/app/app.go +++ b/app/app.go @@ -146,8 +146,7 @@ type App struct { cdc *codec.LegacyAmino appCodec codec.Marshaler - txDecoder sdk.TxDecoder - txEncoder sdk.TxEncoder + txConfig client.TxConfig interfaceRegistry types.InterfaceRegistry invCheckPeriod uint @@ -195,8 +194,7 @@ func New( appCodec := encodingConfig.Marshaler cdc := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry - txDecoder := encodingConfig.TxConfig.TxDecoder() - txEncoder := encodingConfig.TxConfig.TxEncoder() + txConfig := encodingConfig.TxConfig bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) @@ -221,8 +219,7 @@ func New( squareSize: 64, cdc: cdc, appCodec: appCodec, - txDecoder: txDecoder, - txEncoder: txEncoder, + txConfig: txConfig, interfaceRegistry: interfaceRegistry, invCheckPeriod: invCheckPeriod, keys: keys, diff --git a/go.mod b/go.mod index 5b16ad4435..1699579d11 100644 --- a/go.mod +++ b/go.mod @@ -4,30 +4,38 @@ go 1.15 require ( github.com/cosmos/cosmos-sdk v0.40.0-rc5 + github.com/gobuffalo/packr/v2 v2.8.1 // indirect github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.4.3 github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/karrick/godirwalk v1.16.1 // indirect github.com/lazyledger/lazyledger-core v0.0.0-20210122184344-b83e6766973c github.com/lazyledger/nmt v0.1.0 + github.com/magefile/mage v1.11.0 // indirect github.com/pelletier/go-toml v1.8.0 github.com/regen-network/cosmos-proto v0.3.1 + github.com/rogpeppe/go-internal v1.7.0 // indirect github.com/rs/zerolog v1.20.0 + github.com/sirupsen/logrus v1.7.1 // indirect github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.6.1 github.com/tendermint/tm-db v0.6.3 golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect - golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect + golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect + golang.org/x/sys v0.0.0-20210216224549-f992740a1bac // indirect golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect + golang.org/x/tools v0.1.0 // indirect google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea google.golang.org/grpc v1.33.2 ) replace ( - github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210210133003-f5820a7732ed + github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 + golang.org/x/sys => golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // updating this dep will mess up ci and proto generation ) diff --git a/go.sum b/go.sum index 514377d17c..3576ee5e2e 100644 --- a/go.sum +++ b/go.sum @@ -198,6 +198,13 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc= +github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM= +github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM= +github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI= +github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg= +github.com/gobuffalo/packr/v2 v2.8.1 h1:tkQpju6i3EtMXJ9uoF5GT6kB+LMTimDWD8Xvbz6zDVA= +github.com/gobuffalo/packr/v2 v2.8.1/go.mod h1:c/PLlOuTU+p3SybaJATW3H6lX/iK7xEz5OeMf+NnJpg= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0= @@ -353,6 +360,10 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/karrick/godirwalk v1.15.8 h1:7+rWAZPn9zuRxaIqqT8Ohs2Q2Ac0msBqwRdxNCr2VVs= +github.com/karrick/godirwalk v1.15.8/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= +github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw= +github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -360,6 +371,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -369,8 +381,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210210133003-f5820a7732ed h1:gkJ4Iu1ku7gfwx0Uh3GRzzH8wDqybAITbcl0INr3vu8= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210210133003-f5820a7732ed/go.mod h1:JVWmoRJFlFZthbwocA6GVFvS6cwoZgw02vGJr2qj6Cc= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546 h1:REPUOcb/gUIoC9tDibope+CxeuLOJFFH9ASouiXDDsk= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546/go.mod h1:xd7XFf9WnYPJiZp1XWQdITvlOtWxZClrlYHxvJeDeaU= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181 h1:mUeCGuCgjZVadW4CzA2dMBq7p2BqaoCfpnKjxMmSaSE= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181/go.mod h1:v1o1CRihQ9i7hizx23KK4aR79lxA6VDUIzUCfDva0XQ= github.com/lazyledger/lazyledger-core v0.0.0-20210115223437-eff282ad2592/go.mod h1:yNWM9NVGWzSqRS56TL5cVdD6fS0eoxZlCZNHRvxjneE= @@ -388,11 +400,21 @@ github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoR github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= +github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= +github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls= +github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= +github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= +github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= +github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= +github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -528,12 +550,15 @@ github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFB github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/regen-network/cosmos-proto v0.3.0 h1:24dVpPrPi0GDoPVLesf2Ug98iK5QgVscPl0ga4Eoub0= +github.com/regen-network/cosmos-proto v0.3.0/go.mod h1:zuP2jVPHab6+IIyOx3nXHFN+euFNeS3W8XQkcdd4s7A= github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg= github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM= github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= @@ -543,6 +568,10 @@ github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.5.2 h1:qLvObTrvO/XRCqmkKxUlOBc48bI3efyDuAZe25QiF0w= +github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.7.0 h1:3qqXGV8nn7GJT65debw77Dzrx9sfWYgP0DDo7xcMFRk= +github.com/rogpeppe/go-internal v1.7.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= @@ -560,6 +589,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/sirupsen/logrus v1.7.1 h1:rsizeFmZP+GYwyb4V6t6qpG7ZNWzA2bvgW/yC2xHCcg= +github.com/sirupsen/logrus v1.7.1/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= @@ -584,6 +615,7 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= @@ -644,6 +676,7 @@ github.com/vivint/infectious v0.0.0-20190108171102-2455b059135b h1:dLkqBELopfQNh github.com/vivint/infectious v0.0.0-20190108171102-2455b059135b/go.mod h1:5oyMAv4hrBEKqBwORFsiqIrCNCmL2qcZLQTdJLYeYIc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8 h1:gZfMjx7Jr6N8b7iJO4eUjDsn6xJqoyXg8D+ogdoAfKY= @@ -679,6 +712,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200109152110-61a87790db17/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -718,6 +752,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -739,6 +775,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= @@ -764,52 +801,9 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= -golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= @@ -850,9 +844,14 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 h1:9Di9iYgOt9ThCipBxChBVhgNipDoE5mxO84rQV7D0FE= +golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/proto/lazyledgerapp/tx.proto b/proto/lazyledgerapp/tx.proto index 1bf4a518ea..76aaaf374a 100644 --- a/proto/lazyledgerapp/tx.proto +++ b/proto/lazyledgerapp/tx.proto @@ -10,7 +10,7 @@ option go_package = "github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" // Msg defines the bank Msg service. service Msg { // PayForMessage allows the user to post data to made be available. - rpc PayForMessage(MsgWirePayForMessage) returns (MsgWirePayForMessageResponse) { + rpc PayForMessage(MsgWirePayForMessage) returns (MsgPayForMessageResponse) { option (google.api.http).get = "/layzyledger/lazyledgerapp/payformessage"; } } @@ -28,7 +28,7 @@ message MsgWirePayForMessage { } // WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage -message MsgWirePayForMessageResponse {} +message MsgPayForMessageResponse {} // ShareCommitAndSignature defines the message ShareCommitAndSignature { diff --git a/x/lazyledgerapp/keeper/keeper.go b/x/lazyledgerapp/keeper/keeper.go index d32676e0be..6ab1b0c99e 100644 --- a/x/lazyledgerapp/keeper/keeper.go +++ b/x/lazyledgerapp/keeper/keeper.go @@ -39,9 +39,9 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // PayForMessage moves a user's coins to the module address and burns them. -func (k Keeper) PayForMessage(goCtx context.Context, msg *types.MsgWirePayForMessage) (*types.MsgWirePayForMessageResponse, error) { +func (k Keeper) PayForMessage(goCtx context.Context, msg *types.MsgWirePayForMessage) (*types.MsgPayForMessageResponse, error) { // don't pay for fees for the first version - return &types.MsgWirePayForMessageResponse{}, nil + return &types.MsgPayForMessageResponse{}, nil } // BankKeeper restricts the funtionality of the bank keeper used in the lazyledgerapp keeper diff --git a/x/lazyledgerapp/types/codec.go b/x/lazyledgerapp/types/codec.go index 8fb9abf553..9eaf2e6154 100644 --- a/x/lazyledgerapp/types/codec.go +++ b/x/lazyledgerapp/types/codec.go @@ -3,15 +3,19 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" // this line is used by starport scaffolding # 1 ) func RegisterCodec(cdc *codec.LegacyAmino) { // this line is used by starport scaffolding # 2 + cdc.RegisterConcrete(&MsgWirePayForMessage{}, "lazyledgerapp/WirePayForMessage", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - // this line is used by starport scaffolding # 3 + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgWirePayForMessage{}, + ) } var ( diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go index ccf63b4eab..e6978c5017 100644 --- a/x/lazyledgerapp/types/payformessage.go +++ b/x/lazyledgerapp/types/payformessage.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/lazyledger/lazyledger-core/crypto/merkle" "github.com/lazyledger/nmt" ) @@ -33,14 +32,6 @@ func (msg *MsgWirePayForMessage) Type() string { return TypeMsgPayforMessage } // interface func (msg *MsgWirePayForMessage) ValidateBasic() error { pubK := msg.PubKey() - _, err := sdk.AccAddressFromBech32(pubK.Address().String()) - if err != nil { - return sdkerrors.Wrapf( - sdkerrors.ErrInvalidAddress, - "Invalid sender address (%s)", - err, - ) - } // ensure that the namespace id is of length == 8 if len(msg.GetMessageNameSpaceId()) != 8 { @@ -92,13 +83,18 @@ func (msg *MsgWirePayForMessage) ValidateBasic() error { // GetSignBytes returns messages bytes that need to be signed in order for the // message to be valid todo(evan): follow the spec so that each share commitment // is signed, instead of the entire message +// TODO(evan): remove panic and add possibility to vary square size func (msg *MsgWirePayForMessage) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + out, err := msg.GetCommitSignBytes(64) + if err != nil { + panic(err) + } + return out } // GetSigners returns the addresses of the message signers func (msg *MsgWirePayForMessage) GetSigners() []sdk.AccAddress { - return []sdk.AccAddress{sdk.AccAddress(msg.PubKey().Address())} + return []sdk.AccAddress{sdk.AccAddress(msg.PubKey().Address().Bytes())} } // PubKey uses the string version of the public key to diff --git a/x/lazyledgerapp/types/payformessage_test.go b/x/lazyledgerapp/types/payformessage_test.go index 086dda5326..163a720947 100644 --- a/x/lazyledgerapp/types/payformessage_test.go +++ b/x/lazyledgerapp/types/payformessage_test.go @@ -92,6 +92,8 @@ func TestCreateCommit(t *testing.T) { } } +// this test only tests for changes, it doesn't actually test that the result is valid. +// todo(evan): fixme func TestGetCommitSignBytes(t *testing.T) { type test struct { msg MsgWirePayForMessage @@ -109,7 +111,7 @@ func TestGetCommitSignBytes(t *testing.T) { TipRateMax: 1000, }, }, - expected: []byte(`{"fee":{"base_rate_max":"10000","tip_rate_max":"1000"},"message_namespace_id":"AQIDBAECAwQ=","message_share_commitment":"kLkMnfL0wruFOdgRJ4KnyjJBLJWlKxbEyks8SI0cfZs=","message_size":"4","nonce":"1","type":2}`), + expected: []byte(`{"fee":{"base_rate_max":"10000","tip_rate_max":"1000"},"message_namespace_id":"AQIDBAECAwQ=","message_share_commitment":"kLkMnfL0wruFOdgRJ4KnyjJBLJWlKxbEyks8SI0cfZs=","message_size":"4","nonce":"1"}`), }, } for _, tt := range tests { diff --git a/x/lazyledgerapp/types/tx.pb.go b/x/lazyledgerapp/types/tx.pb.go index 3067091063..8b7e3c74d5 100644 --- a/x/lazyledgerapp/types/tx.pb.go +++ b/x/lazyledgerapp/types/tx.pb.go @@ -124,21 +124,21 @@ func (m *MsgWirePayForMessage) GetPublicKey() []byte { } // WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage -type MsgWirePayForMessageResponse struct { +type MsgPayForMessageResponse struct { } -func (m *MsgWirePayForMessageResponse) Reset() { *m = MsgWirePayForMessageResponse{} } -func (m *MsgWirePayForMessageResponse) String() string { return proto.CompactTextString(m) } -func (*MsgWirePayForMessageResponse) ProtoMessage() {} -func (*MsgWirePayForMessageResponse) Descriptor() ([]byte, []int) { +func (m *MsgPayForMessageResponse) Reset() { *m = MsgPayForMessageResponse{} } +func (m *MsgPayForMessageResponse) String() string { return proto.CompactTextString(m) } +func (*MsgPayForMessageResponse) ProtoMessage() {} +func (*MsgPayForMessageResponse) Descriptor() ([]byte, []int) { return fileDescriptor_4a525bbab69d1e80, []int{1} } -func (m *MsgWirePayForMessageResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgPayForMessageResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgWirePayForMessageResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgPayForMessageResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgWirePayForMessageResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgPayForMessageResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -148,17 +148,17 @@ func (m *MsgWirePayForMessageResponse) XXX_Marshal(b []byte, deterministic bool) return b[:n], nil } } -func (m *MsgWirePayForMessageResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgWirePayForMessageResponse.Merge(m, src) +func (m *MsgPayForMessageResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPayForMessageResponse.Merge(m, src) } -func (m *MsgWirePayForMessageResponse) XXX_Size() int { +func (m *MsgPayForMessageResponse) XXX_Size() int { return m.Size() } -func (m *MsgWirePayForMessageResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgWirePayForMessageResponse.DiscardUnknown(m) +func (m *MsgPayForMessageResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPayForMessageResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgWirePayForMessageResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgPayForMessageResponse proto.InternalMessageInfo // ShareCommitAndSignature defines the type ShareCommitAndSignature struct { @@ -416,7 +416,7 @@ func (m *TransactionFee) GetTipRateMax() uint64 { func init() { proto.RegisterType((*MsgWirePayForMessage)(nil), "lazyledgerapp.MsgWirePayForMessage") - proto.RegisterType((*MsgWirePayForMessageResponse)(nil), "lazyledgerapp.MsgWirePayForMessageResponse") + proto.RegisterType((*MsgPayForMessageResponse)(nil), "lazyledgerapp.MsgPayForMessageResponse") proto.RegisterType((*ShareCommitAndSignature)(nil), "lazyledgerapp.ShareCommitAndSignature") proto.RegisterType((*TxSignedTransactionDataPayForMessage)(nil), "lazyledgerapp.TxSignedTransactionDataPayForMessage") proto.RegisterType((*SignedTransactionDataPayForMessage)(nil), "lazyledgerapp.SignedTransactionDataPayForMessage") @@ -426,45 +426,45 @@ func init() { func init() { proto.RegisterFile("lazyledgerapp/tx.proto", fileDescriptor_4a525bbab69d1e80) } var fileDescriptor_4a525bbab69d1e80 = []byte{ - // 600 bytes of a gzipped FileDescriptorProto + // 602 bytes of a gzipped FileDescriptorProto 0x1f, 0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be, 0xf6, 0xee, 0xcb, 0xcf, 0x8f, 0xe5, 0x07, 0xb4, 0x63, 0x8d, 0x58, 0x34, 0x79, 0x61, 0xe5, + 0x97, 0x98, 0x64, 0xd1, 0xae, 0x08, 0x33, 0x01, 0x36, 0x77, 0x8e, 0x4e, 0x5a, 0xe4, 0xf8, 0xa4, + 0x45, 0x7e, 0x9c, 0xb4, 0xc8, 0x87, 0xd3, 0x56, 0xe9, 0xf8, 0xb4, 0x55, 0xfa, 0x76, 0xda, 0x2a, + 0xbd, 0x7d, 0xe2, 0x71, 0xbd, 0x77, 0x30, 0xe8, 0xba, 0xc2, 0x9f, 0x61, 0x98, 0x39, 0x3e, 0x8c, + 0xd9, 0xc6, 0x05, 0x76, 0x1d, 0x49, 0x54, 0x83, 0xf9, 0x64, 0xc7, 0x3d, 0xfa, 0x1d, 0x00, 0x00, + 0xff, 0xff, 0xd7, 0x1a, 0x00, 0x37, 0x40, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -480,7 +480,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { // PayForMessage allows the user to post data to made be available. - PayForMessage(ctx context.Context, in *MsgWirePayForMessage, opts ...grpc.CallOption) (*MsgWirePayForMessageResponse, error) + PayForMessage(ctx context.Context, in *MsgWirePayForMessage, opts ...grpc.CallOption) (*MsgPayForMessageResponse, error) } type msgClient struct { @@ -491,8 +491,8 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) PayForMessage(ctx context.Context, in *MsgWirePayForMessage, opts ...grpc.CallOption) (*MsgWirePayForMessageResponse, error) { - out := new(MsgWirePayForMessageResponse) +func (c *msgClient) PayForMessage(ctx context.Context, in *MsgWirePayForMessage, opts ...grpc.CallOption) (*MsgPayForMessageResponse, error) { + out := new(MsgPayForMessageResponse) err := c.cc.Invoke(ctx, "/lazyledgerapp.Msg/PayForMessage", in, out, opts...) if err != nil { return nil, err @@ -503,14 +503,14 @@ func (c *msgClient) PayForMessage(ctx context.Context, in *MsgWirePayForMessage, // MsgServer is the server API for Msg service. type MsgServer interface { // PayForMessage allows the user to post data to made be available. - PayForMessage(context.Context, *MsgWirePayForMessage) (*MsgWirePayForMessageResponse, error) + PayForMessage(context.Context, *MsgWirePayForMessage) (*MsgPayForMessageResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) PayForMessage(ctx context.Context, req *MsgWirePayForMessage) (*MsgWirePayForMessageResponse, error) { +func (*UnimplementedMsgServer) PayForMessage(ctx context.Context, req *MsgWirePayForMessage) (*MsgPayForMessageResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method PayForMessage not implemented") } @@ -629,7 +629,7 @@ func (m *MsgWirePayForMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgWirePayForMessageResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgPayForMessageResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -639,12 +639,12 @@ func (m *MsgWirePayForMessageResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgWirePayForMessageResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgPayForMessageResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgWirePayForMessageResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgPayForMessageResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -883,7 +883,7 @@ func (m *MsgWirePayForMessage) Size() (n int) { return n } -func (m *MsgWirePayForMessageResponse) Size() (n int) { +func (m *MsgPayForMessageResponse) Size() (n int) { if m == nil { return 0 } @@ -1244,7 +1244,7 @@ func (m *MsgWirePayForMessage) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { +func (m *MsgPayForMessageResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1267,10 +1267,10 @@ func (m *MsgWirePayForMessageResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgWirePayForMessageResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgPayForMessageResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgWirePayForMessageResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgPayForMessageResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/x/lazyledgerapp/types/tx.pb.gw.go b/x/lazyledgerapp/types/tx.pb.gw.go index b3167be184..dfadd14b4d 100644 --- a/x/lazyledgerapp/types/tx.pb.gw.go +++ b/x/lazyledgerapp/types/tx.pb.gw.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -31,7 +30,6 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage -var _ = metadata.Join var ( filter_Msg_PayForMessage_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} @@ -72,14 +70,12 @@ func local_request_Msg_PayForMessage_0(ctx context.Context, marshaler runtime.Ma // RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". // UnaryRPC :call MsgServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { mux.Handle("GET", pattern_Msg_PayForMessage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -87,7 +83,6 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } resp, md, err := local_request_Msg_PayForMessage_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) From 04cbae10f9e217fdb2b542cbcc84481efc6f6396 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Wed, 17 Feb 2021 08:52:32 -0600 Subject: [PATCH 04/10] review feedback: add and use constants, better wording for some documentation, remove redundant ValidateBasicChecks payformessage: use constants and explanation of panic use namespace and share constants from ll-core app: added comments to constant copy and pasted from the sdk review feedback: switch to using constant for namespaceID size review feedback: change name of GetCommitSignBytes to GetCommitmentSignBytes review feedback: use the max square size from lazyledger-core instead of 64 fix doc typo Co-authored-by: John Adler review feedback: docs update for the public key method switch to using constants in the docs too Update x/lazyledgerapp/types/payformessage.go Co-authored-by: Ismail Khoffi switch to updated PR for cosmos-sdk change and update deps --- app/abci.go | 33 +++---- app/abci_test.go | 2 +- app/app.go | 2 +- go.mod | 15 +--- go.sum | 98 +++++++++++---------- x/lazyledgerapp/types/payformessage.go | 40 +++++---- x/lazyledgerapp/types/payformessage_test.go | 4 +- 7 files changed, 99 insertions(+), 95 deletions(-) diff --git a/app/abci.go b/app/abci.go index 38d1fa8b2a..948a81299b 100644 --- a/app/abci.go +++ b/app/abci.go @@ -12,7 +12,15 @@ import ( core "github.com/lazyledger/lazyledger-core/proto/tendermint/types" ) -// This file should contain all of the althered ABCI methods +const ( + // runTxModeDeliver determines if the tx being ran should only be checked, + // or if it should actually modify the state. + // copy and pasted from the sdk, as it is not exported + // https://github.com/lazyledger/cosmos-sdk/blob/3addd7f65d1c35f76716d67641ee629b01f5b9c7/baseapp/baseapp.go#L28 + runTxModeDeliver = 3 +) + +// This file should contain all of the altered ABCI methods // PreprocessTxs fullfills the lazyledger-core version of the ACBI interface, by // performing basic validation for the incoming txs, and by cleanly separating @@ -30,13 +38,14 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro continue } - // don't do anything if the transaction doesn't contain a PayForMessage sdk.Msg + // don't process the tx if the transaction doesn't contain a + // PayForMessage sdk.Msg if !hasWirePayForMessage(tx) { processedTxs = append(processedTxs, rawTx) continue } - // only support transactions that contain a single sdk.Msg for now + // only support transactions that contain a single sdk.Msg if len(tx.GetMsgs()) != 1 { continue } @@ -49,7 +58,7 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro continue } - // process and validate the message + // process the message coreMsg, signedTx, err := app.processMsg(msg) if err != nil { continue @@ -58,19 +67,17 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro // execute the tx in runTxModeDeliver mode (3) // execution includes all validation checks burning fees // currently, no fees are burned - _, _, err = app.BaseApp.TxRunner()(3, rawTx) + _, _, err = app.BaseApp.TxRunner()(runTxModeDeliver, rawTx) if err != nil { - continue } // increment the share counter by the number of shares taken by the message - sharesTaken := uint64(len(coreMsg.Data) / 256) + sharesTaken := uint64(len(coreMsg.Data) / types.ShareSize) shareCounter += sharesTaken // if there are too many shares stop processing and return the transactions - // this is related to issues 67 and 77 of lazyledger-core - if shareCounter > squareSize { + if shareCounter > squareSize*squareSize { break } @@ -85,7 +92,7 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro processedTxs = append(processedTxs, rawProcessedTx) } - // sort messages lexographically + // sort messages lexigraphically sort.Slice(shareMsgs, func(i, j int) bool { return bytes.Compare(shareMsgs[i].NamespaceId, shareMsgs[j].NamespaceId) < 0 }) @@ -132,12 +139,6 @@ func (app *App) processMsg(msg sdk.Msg) (core.Message, *types.TxSignedTransactio fmt.Errorf("No share commit for correct square size. Current square size: %d", squareSize) } - // run basic validation on the msg - err := wireMsg.ValidateBasic() - if err != nil { - return core.Message{}, nil, err - } - // add the message to the list of core message to be returned to ll-core coreMsg := core.Message{ NamespaceId: wireMsg.GetMessageNameSpaceId(), diff --git a/app/abci_test.go b/app/abci_test.go index 3d3e891fea..31101bc94d 100644 --- a/app/abci_test.go +++ b/app/abci_test.go @@ -416,7 +416,7 @@ func generateWirePayForMessage(t *testing.T, k uint64, key *secp256k1.PrivKey) * }, } - rawTxPFM, err := msg.GetCommitSignBytes(k) + rawTxPFM, err := msg.GetCommitmentSignBytes(k) if err != nil { t.Error(err) } diff --git a/app/app.go b/app/app.go index 827d6870f9..088d6b91ee 100644 --- a/app/app.go +++ b/app/app.go @@ -216,7 +216,7 @@ func New( BaseApp: bApp, appName: appName, // todo(evan): don't hardcode square size - squareSize: 64, + squareSize: lazyledgerapptypes.SquareSize, cdc: cdc, appCodec: appCodec, txConfig: txConfig, diff --git a/go.mod b/go.mod index 1699579d11..0d1e0e64d6 100644 --- a/go.mod +++ b/go.mod @@ -4,38 +4,31 @@ go 1.15 require ( github.com/cosmos/cosmos-sdk v0.40.0-rc5 - github.com/gobuffalo/packr/v2 v2.8.1 // indirect github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.4.3 github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/karrick/godirwalk v1.16.1 // indirect github.com/lazyledger/lazyledger-core v0.0.0-20210122184344-b83e6766973c github.com/lazyledger/nmt v0.1.0 - github.com/magefile/mage v1.11.0 // indirect github.com/pelletier/go-toml v1.8.0 github.com/regen-network/cosmos-proto v0.3.1 - github.com/rogpeppe/go-internal v1.7.0 // indirect github.com/rs/zerolog v1.20.0 - github.com/sirupsen/logrus v1.7.1 // indirect github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.6.1 github.com/tendermint/tm-db v0.6.3 + golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect - golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect - golang.org/x/sys v0.0.0-20210216224549-f992740a1bac // indirect - golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect - golang.org/x/tools v0.1.0 // indirect + golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect + golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea google.golang.org/grpc v1.33.2 ) replace ( - github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546 + github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 - golang.org/x/sys => golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // updating this dep will mess up ci and proto generation ) diff --git a/go.sum b/go.sum index 3576ee5e2e..bb66208da1 100644 --- a/go.sum +++ b/go.sum @@ -198,13 +198,6 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc= -github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM= -github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM= -github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI= -github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg= -github.com/gobuffalo/packr/v2 v2.8.1 h1:tkQpju6i3EtMXJ9uoF5GT6kB+LMTimDWD8Xvbz6zDVA= -github.com/gobuffalo/packr/v2 v2.8.1/go.mod h1:c/PLlOuTU+p3SybaJATW3H6lX/iK7xEz5OeMf+NnJpg= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0= @@ -360,10 +353,6 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= -github.com/karrick/godirwalk v1.15.8 h1:7+rWAZPn9zuRxaIqqT8Ohs2Q2Ac0msBqwRdxNCr2VVs= -github.com/karrick/godirwalk v1.15.8/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= -github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw= -github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -371,7 +360,6 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -381,8 +369,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546 h1:REPUOcb/gUIoC9tDibope+CxeuLOJFFH9ASouiXDDsk= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210217005603-b260792f5546/go.mod h1:xd7XFf9WnYPJiZp1XWQdITvlOtWxZClrlYHxvJeDeaU= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14 h1:dK4IDXe4hDeblk4IACHBjY4sIvAeu0NKMilRH+OGyD4= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14/go.mod h1:pPx3/tAjdExEctV+nKzvNeedZcvuys5fUD0A3r5XX20= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181 h1:mUeCGuCgjZVadW4CzA2dMBq7p2BqaoCfpnKjxMmSaSE= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181/go.mod h1:v1o1CRihQ9i7hizx23KK4aR79lxA6VDUIzUCfDva0XQ= github.com/lazyledger/lazyledger-core v0.0.0-20210115223437-eff282ad2592/go.mod h1:yNWM9NVGWzSqRS56TL5cVdD6fS0eoxZlCZNHRvxjneE= @@ -400,21 +388,11 @@ github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoR github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= -github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= -github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls= -github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= -github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= -github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= -github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= -github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI= -github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -568,10 +546,6 @@ github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.5.2 h1:qLvObTrvO/XRCqmkKxUlOBc48bI3efyDuAZe25QiF0w= -github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.7.0 h1:3qqXGV8nn7GJT65debw77Dzrx9sfWYgP0DDo7xcMFRk= -github.com/rogpeppe/go-internal v1.7.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= @@ -589,8 +563,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sirupsen/logrus v1.7.1 h1:rsizeFmZP+GYwyb4V6t6qpG7ZNWzA2bvgW/yC2xHCcg= -github.com/sirupsen/logrus v1.7.1/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= @@ -615,7 +587,6 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= @@ -676,7 +647,6 @@ github.com/vivint/infectious v0.0.0-20190108171102-2455b059135b h1:dLkqBELopfQNh github.com/vivint/infectious v0.0.0-20190108171102-2455b059135b/go.mod h1:5oyMAv4hrBEKqBwORFsiqIrCNCmL2qcZLQTdJLYeYIc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8 h1:gZfMjx7Jr6N8b7iJO4eUjDsn6xJqoyXg8D+ogdoAfKY= @@ -712,7 +682,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200109152110-61a87790db17/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -726,6 +695,8 @@ golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= +golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -752,8 +723,6 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -775,7 +744,6 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= @@ -801,15 +769,53 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 h1:SgQ6LNaYJU0JIuEHv9+s6EbhSCwYeAf5Yvj6lpYlqAE= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -844,14 +850,9 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 h1:9Di9iYgOt9ThCipBxChBVhgNipDoE5mxO84rQV7D0FE= -golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -897,6 +898,7 @@ google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4 h1:Rt0FRalMgdSlXAVJvX4pr65KfqaxHXSLkSJRD9pw6g0= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea h1:N98SvVh7Hdle2lgUVFuIkf0B3u29CUakMUQa7Hwz8Wc= google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go index e6978c5017..0f8128e4ed 100644 --- a/x/lazyledgerapp/types/payformessage.go +++ b/x/lazyledgerapp/types/payformessage.go @@ -8,13 +8,16 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/lazyledger/lazyledger-core/crypto/merkle" + core "github.com/lazyledger/lazyledger-core/types" "github.com/lazyledger/nmt" ) const ( TypeMsgPayforMessage = "payformessage" TypeSignedTransactionDataPayForMessage = "signedtransactiondatapayformessage" - ShareSize = 256 + ShareSize = core.ShareSize + SquareSize = core.MaxSquareSize + NamespaceIDSize = core.NamespaceSize ) /////////////////////////////////////// @@ -33,11 +36,12 @@ func (msg *MsgWirePayForMessage) Type() string { return TypeMsgPayforMessage } func (msg *MsgWirePayForMessage) ValidateBasic() error { pubK := msg.PubKey() - // ensure that the namespace id is of length == 8 - if len(msg.GetMessageNameSpaceId()) != 8 { + // ensure that the namespace id is of length == NamespaceIDSize + if len(msg.GetMessageNameSpaceId()) != NamespaceIDSize { return fmt.Errorf( - "invalid namespace length: got %d wanted 8", + "invalid namespace length: got %d wanted %d", len(msg.GetMessageNameSpaceId()), + NamespaceIDSize, ) } @@ -67,7 +71,7 @@ func (msg *MsgWirePayForMessage) ValidateBasic() error { } // check that the signatures are valid - bytesToSign, err := msg.GetCommitSignBytes(commit.K) + bytesToSign, err := msg.GetCommitmentSignBytes(commit.K) if err != nil { return err } @@ -81,12 +85,15 @@ func (msg *MsgWirePayForMessage) ValidateBasic() error { } // GetSignBytes returns messages bytes that need to be signed in order for the -// message to be valid todo(evan): follow the spec so that each share commitment -// is signed, instead of the entire message -// TODO(evan): remove panic and add possibility to vary square size +// message to be valid func (msg *MsgWirePayForMessage) GetSignBytes() []byte { - out, err := msg.GetCommitSignBytes(64) + out, err := msg.GetCommitmentSignBytes(SquareSize) if err != nil { + // this panic can only be reached if the nmt cannot push bytes onto the + // tree while creating the commit. This should never happen, as an error + // only occurs when out of order or varying sized namespaces are used, + // and we are using an identical namespace when pushing to the nmt + // https://github.com/lazyledger/nmt/blob/b22170d6f23796a186c07e87e4ef9856282ffd1a/nmt.go#L250 panic(err) } return out @@ -97,13 +104,13 @@ func (msg *MsgWirePayForMessage) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{sdk.AccAddress(msg.PubKey().Address().Bytes())} } -// PubKey uses the string version of the public key to +// PubKey returns the public key of the creator of MsgWirePayForMessage func (msg *MsgWirePayForMessage) PubKey() *secp256k1.PubKey { return &secp256k1.PubKey{Key: msg.PublicKey} } -// GetCommitSignBytes generates the bytes that each need to be signed per share commit -func (msg *MsgWirePayForMessage) GetCommitSignBytes(k uint64) ([]byte, error) { +// GetCommitmentSignBytes generates the bytes that each need to be signed per share commit +func (msg *MsgWirePayForMessage) GetCommitmentSignBytes(k uint64) ([]byte, error) { sTxMsg, err := msg.SignedTransactionDataPayForMessage(k) if err != nil { return nil, err @@ -166,11 +173,12 @@ func (msg *SignedTransactionDataPayForMessage) Type() string { // ValidateBasic fullfills the sdk.Msg interface by performing stateless // validity checks on the msg that also don't require having the actual message func (msg *SignedTransactionDataPayForMessage) ValidateBasic() error { - // ensure that the namespace id is of length == 8 - if len(msg.GetMessageNamespaceId()) != 8 { + // ensure that the namespace id is of length == NamespaceIDSize + if len(msg.GetMessageNamespaceId()) != NamespaceIDSize { return fmt.Errorf( - "invalid namespace length: got %d wanted 8", + "invalid namespace length: got %d wanted %d", len(msg.GetMessageNamespaceId()), + NamespaceIDSize, ) } return nil @@ -213,7 +221,7 @@ func CreateCommit(k uint64, namespace, message []byte) ([]byte, error) { subTreeRoots := make([][]byte, len(leafSets)) for i, set := range leafSets { // create the nmt - tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(8)) + tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(NamespaceIDSize)) for _, leaf := range set { err := tree.Push(namespace, leaf) if err != nil { diff --git a/x/lazyledgerapp/types/payformessage_test.go b/x/lazyledgerapp/types/payformessage_test.go index 163a720947..dfa78c571f 100644 --- a/x/lazyledgerapp/types/payformessage_test.go +++ b/x/lazyledgerapp/types/payformessage_test.go @@ -94,7 +94,7 @@ func TestCreateCommit(t *testing.T) { // this test only tests for changes, it doesn't actually test that the result is valid. // todo(evan): fixme -func TestGetCommitSignBytes(t *testing.T) { +func TestGetCommitmentSignBytes(t *testing.T) { type test struct { msg MsgWirePayForMessage expected []byte @@ -115,7 +115,7 @@ func TestGetCommitSignBytes(t *testing.T) { }, } for _, tt := range tests { - res, err := tt.msg.GetCommitSignBytes(64) + res, err := tt.msg.GetCommitmentSignBytes(64) assert.NoError(t, err) assert.Equal(t, tt.expected, res) } From a41e189f754ae31c95dbcf6edee6a2626f321563 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Fri, 19 Feb 2021 10:13:17 -0600 Subject: [PATCH 05/10] review feedback: follow the spec and pad shares when generating the share commitment instead of not allowing chains update failing test to new expected result now that the square size is 128 instead of 64 --- x/lazyledgerapp/types/payformessage.go | 25 +++++++++++++++-- x/lazyledgerapp/types/payformessage_test.go | 31 +++++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go index 0f8128e4ed..b5337f2887 100644 --- a/x/lazyledgerapp/types/payformessage.go +++ b/x/lazyledgerapp/types/payformessage.go @@ -206,7 +206,10 @@ func (msg *SignedTransactionDataPayForMessage) GetSigners() []sdk.AccAddress { // https://github.com/lazyledger/lazyledger-specs/blob/master/rationale/message_block_layout.md#non-interactive-default-rules func CreateCommit(k uint64, namespace, message []byte) ([]byte, error) { // break message into shares - shares := ChunkMessage(message) + shares := chunkMessage(message) + + // add padding if necessary + shares = addSharePadding(shares) // organize shares for merkle mountain range heights := PowerOf2MountainRange(uint64(len(shares)), k) @@ -234,8 +237,8 @@ func CreateCommit(k uint64, namespace, message []byte) ([]byte, error) { return merkle.HashFromByteSlices(subTreeRoots), nil } -// ChunkMessage breaks the message into 256 byte pieces -func ChunkMessage(message []byte) [][]byte { +// chunkMessage breaks the message into 256 byte pieces +func chunkMessage(message []byte) [][]byte { var shares [][]byte for i := 0; i < len(message); i += ShareSize { end := i + ShareSize @@ -247,6 +250,22 @@ func ChunkMessage(message []byte) [][]byte { return shares } +// addSharePadding will add padding to the last share if necessary +func addSharePadding(shares [][]byte) [][]byte { + if len(shares) == 0 { + return shares + } + + // add padding to the last share if necessary + if len(shares[len(shares)-1]) != ShareSize { + padded := make([]byte, ShareSize) + copy(padded, shares[len(shares)-1]) + shares[len(shares)-1] = padded + } + + return shares +} + // PowerOf2MountainRange returns the heights of the subtrees for binary merkle // mountian range func PowerOf2MountainRange(l, k uint64) []uint64 { diff --git a/x/lazyledgerapp/types/payformessage_test.go b/x/lazyledgerapp/types/payformessage_test.go index dfa78c571f..8700bf54cb 100644 --- a/x/lazyledgerapp/types/payformessage_test.go +++ b/x/lazyledgerapp/types/payformessage_test.go @@ -111,12 +111,39 @@ func TestGetCommitmentSignBytes(t *testing.T) { TipRateMax: 1000, }, }, - expected: []byte(`{"fee":{"base_rate_max":"10000","tip_rate_max":"1000"},"message_namespace_id":"AQIDBAECAwQ=","message_share_commitment":"kLkMnfL0wruFOdgRJ4KnyjJBLJWlKxbEyks8SI0cfZs=","message_size":"4","nonce":"1"}`), + expected: []byte(`{"fee":{"base_rate_max":"10000","tip_rate_max":"1000"},"message_namespace_id":"AQIDBAECAwQ=","message_share_commitment":"byozRVIrw5NF/rU1PPyq6BAo3g2ny3uLTiOFedtgSwo=","message_size":"4","nonce":"1"}`), }, } for _, tt := range tests { - res, err := tt.msg.GetCommitmentSignBytes(64) + res, err := tt.msg.GetCommitmentSignBytes(SquareSize) assert.NoError(t, err) assert.Equal(t, tt.expected, res) } } + +func TestShareChunkingAndPadding(t *testing.T) { + type test struct { + input []byte + expect [][]byte + } + tests := []test{ + { + input: []byte{1}, + expect: [][]byte{append([]byte{1}, bytes.Repeat([]byte{0}, ShareSize-1)...)}, + }, + { + input: bytes.Repeat([]byte{1}, ShareSize), + expect: [][]byte{bytes.Repeat([]byte{1}, ShareSize)}, + }, + } + for _, tt := range tests { + shares := chunkMessage(tt.input) + shares = addSharePadding(shares) + for _, share := range shares { + if len(share) != ShareSize { + t.Errorf("invalid share length: got %d wanted core.ShareSize (%d)", len(share), ShareSize) + } + } + assert.Equal(t, tt.expect, shares) + } +} From 1203b1819c6f6e6cd0b8fcae5439b7ee7ce666b8 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Mon, 22 Feb 2021 14:34:32 -0600 Subject: [PATCH 06/10] add a handler for SignedTransactionDataPayForMessage --- proto/lazyledgerapp/tx.proto | 5 +- x/lazyledgerapp/handler.go | 3 + x/lazyledgerapp/keeper/keeper.go | 7 ++ x/lazyledgerapp/types/tx.pb.go | 206 +++++++++++++++++++++++++------ 4 files changed, 182 insertions(+), 39 deletions(-) diff --git a/proto/lazyledgerapp/tx.proto b/proto/lazyledgerapp/tx.proto index 76aaaf374a..0439e60317 100644 --- a/proto/lazyledgerapp/tx.proto +++ b/proto/lazyledgerapp/tx.proto @@ -27,7 +27,7 @@ message MsgWirePayForMessage { bytes public_key = 7; } -// WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage +// MsgPayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage message MsgPayForMessageResponse {} // ShareCommitAndSignature defines the @@ -55,6 +55,9 @@ message SignedTransactionDataPayForMessage { bytes message_share_commitment = 5; } +// SignedTransactionDataPayForMessageResponse describes the response returned after the submission of a SignedTransactionDataPayForMessage +message SignedTransactionDataPayForMessageResponse {} + // TransactionFee contains the base and tip rates. message TransactionFee { uint64 base_rate_max = 1; diff --git a/x/lazyledgerapp/handler.go b/x/lazyledgerapp/handler.go index 101e04b2c1..aca3c35672 100644 --- a/x/lazyledgerapp/handler.go +++ b/x/lazyledgerapp/handler.go @@ -20,6 +20,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgWirePayForMessage: res, err := msgServer.PayForMessage(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.SignedTransactionDataPayForMessage: + res, err := msgServer.SignedTransactionDataPayForMessage(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) diff --git a/x/lazyledgerapp/keeper/keeper.go b/x/lazyledgerapp/keeper/keeper.go index 6ab1b0c99e..ed47506f6f 100644 --- a/x/lazyledgerapp/keeper/keeper.go +++ b/x/lazyledgerapp/keeper/keeper.go @@ -16,6 +16,7 @@ const ( TokenDenomination = "token" ) +// Keeper handles all the state changes for the lazyledger-app module. type Keeper struct { cdc codec.Marshaler storeKey sdk.StoreKey @@ -44,6 +45,12 @@ func (k Keeper) PayForMessage(goCtx context.Context, msg *types.MsgWirePayForMes return &types.MsgPayForMessageResponse{}, nil } +// SignedTransactionDataPayForMessage moves a user's coins to the module address and burns them. +func (k Keeper) SignedTransactionDataPayForMessage(goCtx context.Context, msg *types.SignedTransactionDataPayForMessage) (*types.SignedTransactionDataPayForMessageResponse, error) { + // don't pay for fees for the first version + return &types.SignedTransactionDataPayForMessageResponse{}, nil +} + // BankKeeper restricts the funtionality of the bank keeper used in the lazyledgerapp keeper type BankKeeper interface { SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error diff --git a/x/lazyledgerapp/types/tx.pb.go b/x/lazyledgerapp/types/tx.pb.go index 8b7e3c74d5..8b7b4dfb65 100644 --- a/x/lazyledgerapp/types/tx.pb.go +++ b/x/lazyledgerapp/types/tx.pb.go @@ -123,7 +123,7 @@ func (m *MsgWirePayForMessage) GetPublicKey() []byte { return nil } -// WirePayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage +// MsgPayForMessageResponse describes the response returned after the submission of a MsgWirePayForMessage type MsgPayForMessageResponse struct { } @@ -361,6 +361,47 @@ func (m *SignedTransactionDataPayForMessage) GetMessageShareCommitment() []byte return nil } +// SignedTransactionDataPayForMessageResponse describes the response returned after the submission of a SignedTransactionDataPayForMessage +type SignedTransactionDataPayForMessageResponse struct { +} + +func (m *SignedTransactionDataPayForMessageResponse) Reset() { + *m = SignedTransactionDataPayForMessageResponse{} +} +func (m *SignedTransactionDataPayForMessageResponse) String() string { + return proto.CompactTextString(m) +} +func (*SignedTransactionDataPayForMessageResponse) ProtoMessage() {} +func (*SignedTransactionDataPayForMessageResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4a525bbab69d1e80, []int{5} +} +func (m *SignedTransactionDataPayForMessageResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SignedTransactionDataPayForMessageResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SignedTransactionDataPayForMessageResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SignedTransactionDataPayForMessageResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SignedTransactionDataPayForMessageResponse.Merge(m, src) +} +func (m *SignedTransactionDataPayForMessageResponse) XXX_Size() int { + return m.Size() +} +func (m *SignedTransactionDataPayForMessageResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SignedTransactionDataPayForMessageResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SignedTransactionDataPayForMessageResponse proto.InternalMessageInfo + // TransactionFee contains the base and tip rates. type TransactionFee struct { BaseRateMax uint64 `protobuf:"varint,1,opt,name=base_rate_max,json=baseRateMax,proto3" json:"base_rate_max,omitempty"` @@ -371,7 +412,7 @@ func (m *TransactionFee) Reset() { *m = TransactionFee{} } func (m *TransactionFee) String() string { return proto.CompactTextString(m) } func (*TransactionFee) ProtoMessage() {} func (*TransactionFee) Descriptor() ([]byte, []int) { - return fileDescriptor_4a525bbab69d1e80, []int{5} + return fileDescriptor_4a525bbab69d1e80, []int{6} } func (m *TransactionFee) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -420,51 +461,53 @@ func init() { proto.RegisterType((*ShareCommitAndSignature)(nil), "lazyledgerapp.ShareCommitAndSignature") proto.RegisterType((*TxSignedTransactionDataPayForMessage)(nil), "lazyledgerapp.TxSignedTransactionDataPayForMessage") proto.RegisterType((*SignedTransactionDataPayForMessage)(nil), "lazyledgerapp.SignedTransactionDataPayForMessage") + proto.RegisterType((*SignedTransactionDataPayForMessageResponse)(nil), "lazyledgerapp.SignedTransactionDataPayForMessageResponse") proto.RegisterType((*TransactionFee)(nil), "lazyledgerapp.TransactionFee") } func init() { proto.RegisterFile("lazyledgerapp/tx.proto", fileDescriptor_4a525bbab69d1e80) } var fileDescriptor_4a525bbab69d1e80 = []byte{ - // 602 bytes of a gzipped FileDescriptorProto + // 610 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, 0x10, 0xce, 0x26, 0x69, 0xab, 0x4e, 0xd2, 0xdf, 0x0f, 0xad, 0x42, 0xb1, 0xa2, 0x36, 0x04, 0x83, - 0x20, 0x20, 0x11, 0xb7, 0xe5, 0x82, 0xb8, 0x51, 0x50, 0x25, 0x54, 0x05, 0x21, 0xa7, 0x02, 0x89, - 0x8b, 0xb5, 0x71, 0xa6, 0xee, 0xaa, 0xb1, 0x77, 0xe5, 0xdd, 0x4a, 0x71, 0x8f, 0xbc, 0x00, 0x48, + 0x20, 0x54, 0x10, 0xb7, 0xe5, 0x82, 0xb8, 0x51, 0x50, 0x25, 0x54, 0x05, 0x21, 0xa7, 0x02, 0x89, + 0x8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3, 0x9b, 0xf4, 0xf1, 0x15, 0x56, 0x4c, 0x5c, 0x7b, 0x89, 0xb9, + 0xcc, 0x07, 0xb0, 0x36, 0x83, 0xd0, 0x63, 0x3f, 0xbd, 0x86, 0xff, 0xb2, 0x3f, 0xa5, 0x26, 0x2c, + 0xf5, 0x98, 0x42, 0x27, 0x60, 0x1a, 0x1d, 0x8f, 0x8d, 0x52, 0x4b, 0x55, 0xa2, 0xa0, 0xcd, 0x34, + 0x76, 0xd8, 0x88, 0x36, 0xa1, 0xaa, 0xb9, 0x9c, 0x40, 0x12, 0x3d, 0x40, 0x73, 0x99, 0x22, 0x36, + 0x3f, 0x11, 0x28, 0x75, 0x94, 0x4b, 0xdf, 0x13, 0x58, 0xca, 0xaa, 0x7e, 0x3b, 0x27, 0xf4, 0x45, + 0x0b, 0xa4, 0x7e, 0xef, 0x3c, 0xe8, 0xe2, 0xfe, 0xd7, 0xdf, 0x7d, 0xf9, 0xf9, 0xb1, 0xb8, 0x46, + 0x5b, 0xd6, 0x90, 0x85, 0xe3, 0x17, 0x56, 0x76, 0xe5, 0x49, 0x16, 0xee, 0x89, 0x20, 0x95, 0x6b, + 0x6b, 0xf7, 0xf8, 0xb4, 0x41, 0x4e, 0x4e, 0x1b, 0xe4, 0xc7, 0x69, 0x83, 0x7c, 0x38, 0x6b, 0x14, + 0x4e, 0xce, 0x1a, 0x85, 0x6f, 0x67, 0x8d, 0xc2, 0xdb, 0x27, 0x2e, 0xd7, 0xfb, 0x87, 0xbd, 0x76, + 0x5f, 0x78, 0x53, 0x0c, 0x53, 0xc7, 0x87, 0x11, 0xdb, 0x28, 0xc7, 0xae, 0x43, 0x89, 0xaa, 0x37, + 0x1f, 0x6f, 0xc4, 0x47, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x1d, 0x9d, 0xb8, 0x67, 0x6e, 0x05, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -504,6 +547,8 @@ func (c *msgClient) PayForMessage(ctx context.Context, in *MsgWirePayForMessage, type MsgServer interface { // PayForMessage allows the user to post data to made be available. PayForMessage(context.Context, *MsgWirePayForMessage) (*MsgPayForMessageResponse, error) + // PayForMessage allows the user to post data to made be available. + SignedTransactionDataPayForMessage(context.Context, *SignedTransactionDataPayForMessage) (*SignedTransactionDataPayForMessageResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -802,6 +847,29 @@ func (m *SignedTransactionDataPayForMessage) MarshalToSizedBuffer(dAtA []byte) ( return len(dAtA) - i, nil } +func (m *SignedTransactionDataPayForMessageResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SignedTransactionDataPayForMessageResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SignedTransactionDataPayForMessageResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *TransactionFee) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -960,6 +1028,15 @@ func (m *SignedTransactionDataPayForMessage) Size() (n int) { return n } +func (m *SignedTransactionDataPayForMessageResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *TransactionFee) Size() (n int) { if m == nil { return 0 @@ -1789,6 +1866,59 @@ func (m *SignedTransactionDataPayForMessage) Unmarshal(dAtA []byte) error { } return nil } +func (m *SignedTransactionDataPayForMessageResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SignedTransactionDataPayForMessageResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SignedTransactionDataPayForMessageResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *TransactionFee) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From e0e7a86e23b5b4af31172488440e902650985e61 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Mon, 22 Feb 2021 14:41:51 -0600 Subject: [PATCH 07/10] change PreprocessTxs so that it does not run the transaction use the latest version the lazyledger/cosmos-sdk instead of the modified version --- app/abci.go | 17 ----------------- go.mod | 2 +- go.sum | 6 +++--- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/app/abci.go b/app/abci.go index 948a81299b..3cc70d831a 100644 --- a/app/abci.go +++ b/app/abci.go @@ -12,20 +12,11 @@ import ( core "github.com/lazyledger/lazyledger-core/proto/tendermint/types" ) -const ( - // runTxModeDeliver determines if the tx being ran should only be checked, - // or if it should actually modify the state. - // copy and pasted from the sdk, as it is not exported - // https://github.com/lazyledger/cosmos-sdk/blob/3addd7f65d1c35f76716d67641ee629b01f5b9c7/baseapp/baseapp.go#L28 - runTxModeDeliver = 3 -) - // This file should contain all of the altered ABCI methods // PreprocessTxs fullfills the lazyledger-core version of the ACBI interface, by // performing basic validation for the incoming txs, and by cleanly separating // share messages from transactions -// todo(evan): refactor out a for loop. func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePreprocessTxs { squareSize := app.SquareSize() shareCounter := uint64(0) @@ -64,14 +55,6 @@ func (app *App) PreprocessTxs(txs abci.RequestPreprocessTxs) abci.ResponsePrepro continue } - // execute the tx in runTxModeDeliver mode (3) - // execution includes all validation checks burning fees - // currently, no fees are burned - _, _, err = app.BaseApp.TxRunner()(runTxModeDeliver, rawTx) - if err != nil { - continue - } - // increment the share counter by the number of shares taken by the message sharesTaken := uint64(len(coreMsg.Data) / types.ShareSize) shareCounter += sharesTaken diff --git a/go.mod b/go.mod index 0d1e0e64d6..1405677af2 100644 --- a/go.mod +++ b/go.mod @@ -29,6 +29,6 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14 + github.com/cosmos/cosmos-sdk v0.40.0-rc5 => github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210121152417-3addd7f65d1c github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 ) diff --git a/go.sum b/go.sum index bb66208da1..bcbba24b42 100644 --- a/go.sum +++ b/go.sum @@ -118,6 +118,7 @@ github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXy github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE= +github.com/cosmos/iavl v0.15.0-rc5 h1:AMKgaAjXwGANWv56NL4q4hV+a0puSkLYD6cCQAv3i44= github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7uMjgxke/I= github.com/cosmos/iavl v0.15.3 h1:xE9r6HW8GeKeoYJN4zefpljZ1oukVScP/7M8oj6SUts= github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4= @@ -369,8 +370,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14 h1:dK4IDXe4hDeblk4IACHBjY4sIvAeu0NKMilRH+OGyD4= -github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210221170254-8943f1496a14/go.mod h1:pPx3/tAjdExEctV+nKzvNeedZcvuys5fUD0A3r5XX20= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210121152417-3addd7f65d1c h1:OFw8rVLTYvM2QDz8OMcnJEXm/+dCUTkBOyAPVccsLiU= +github.com/lazyledger/cosmos-sdk v0.40.0-rc5.0.20210121152417-3addd7f65d1c/go.mod h1:pPx3/tAjdExEctV+nKzvNeedZcvuys5fUD0A3r5XX20= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181 h1:mUeCGuCgjZVadW4CzA2dMBq7p2BqaoCfpnKjxMmSaSE= github.com/lazyledger/go-leopard v0.0.0-20200604113236-298f93361181/go.mod h1:v1o1CRihQ9i7hizx23KK4aR79lxA6VDUIzUCfDva0XQ= github.com/lazyledger/lazyledger-core v0.0.0-20210115223437-eff282ad2592/go.mod h1:yNWM9NVGWzSqRS56TL5cVdD6fS0eoxZlCZNHRvxjneE= @@ -693,7 +694,6 @@ golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= From 6abdee4f6f3e6e9a42cfb67db36695f378ab2fb1 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Mon, 22 Feb 2021 16:27:51 -0600 Subject: [PATCH 08/10] add a test for Preprocessing and remove the old test for runTx fix SignedTransactionDataPayForMessage generation so that padding is added to the message if necessary change name of CreateCommit to CreateCommitment --- app/abci_test.go | 299 ++++++++++---------- x/lazyledgerapp/types/payformessage.go | 26 +- x/lazyledgerapp/types/payformessage_test.go | 4 +- 3 files changed, 174 insertions(+), 155 deletions(-) diff --git a/app/abci_test.go b/app/abci_test.go index 31101bc94d..b02922d39a 100644 --- a/app/abci_test.go +++ b/app/abci_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" cliTx "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" @@ -29,45 +30,19 @@ import ( dbm "github.com/tendermint/tm-db" ) -// TODO: -// - flesh tests with more cases -// - test for when the tx should fail - // Get flags every time the simulator is run func init() { simapp.GetSimulatorFlags() } func TestProcessMsg(t *testing.T) { - key := secp256k1.GenPrivKey() - - testApp := setupApp(t) - - for acc := range maccPerms { - require.Equal(t, !allowedReceivingModAcc[acc], testApp.BankKeeper.BlockedAddr(testApp.AccountKeeper.GetModuleAddress(acc)), - "ensure that blocked addresses are properly set in bank keeper") - } - - genesisState := NewDefaultGenesisState() - - genesisState, err := addGenesisAccount(sdk.AccAddress(key.PubKey().Address().Bytes()), genesisState, testApp.appCodec) - if err != nil { - t.Error(err) - } + testApp, key := setupApp(t) - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) - - // Initialize the chain - testApp.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - AppStateBytes: stateBytes, - }, - ) + ns := []byte{1, 1, 1, 1, 1, 1, 1, 1} + message := bytes.Repeat([]byte{1}, 256) // create a tx - msg := generateWirePayForMessage(t, testApp.SquareSize(), key) + msg := generateWirePayForMessage(t, testApp.SquareSize(), key, ns, message) tests := []struct { name string @@ -89,127 +64,54 @@ func TestProcessMsg(t *testing.T) { } } -// this belongs in the lazyledgerapp/simulation package -func TestRunTx(t *testing.T) { - key := secp256k1.GenPrivKey() - - testApp := setupApp(t) - - for acc := range maccPerms { - require.Equal(t, !allowedReceivingModAcc[acc], testApp.BankKeeper.BlockedAddr(testApp.AccountKeeper.GetModuleAddress(acc)), - "ensure that blocked addresses are properly set in bank keeper") - } - - genesisState := NewDefaultGenesisState() - - // give the key a bunch a coins for testing - genesisState, err := addGenesisAccount(sdk.AccAddress(key.PubKey().Address().Bytes()), genesisState, testApp.appCodec) - if err != nil { - t.Error(err) - } - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) - - // Initialize the chain - testApp.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - AppStateBytes: stateBytes, - ChainId: "test-chain", - }, - ) - - // create a msg - msg := generateWirePayForMessage(t, 64, key) - - // this is returning a tx.wrapper - builder := testApp.txConfig.NewTxBuilder() - err = builder.SetMsgs(msg) - if err != nil { - t.Error(err) - } - - coin := sdk.Coin{ - Denom: "token", - Amount: sdk.NewInt(1000), - } - - builder.SetFeeAmount(sdk.NewCoins(coin)) - builder.SetGasLimit(10000) - builder.SetTimeoutHeight(99) - - signingData := authsigning.SignerData{ - ChainID: "test-chain", - AccountNumber: 0, - Sequence: 0, - } - - // Important set the Signature to nil BEFORE actually signing - sigData := signing.SingleSignatureData{ - SignMode: signing.SignMode_SIGN_MODE_DIRECT, - Signature: nil, - } - - sig := signing.SignatureV2{ - PubKey: key.PubKey(), - Data: &sigData, - Sequence: 0, - } - - // set the empty signature - err = builder.SetSignatures(sig) - if err != nil { - if err != nil { - t.Error(err) - } - } - - // create the actual signature - sigV2, err := cliTx.SignWithPrivKey(signing.SignMode_SIGN_MODE_DIRECT, signingData, builder, key, testApp.txConfig, 0) - if err != nil { - t.Error(err) - } +func TestPreprocessTxs(t *testing.T) { + testApp, key := setupApp(t) - // set the actual signature - err = builder.SetSignatures(sigV2) - if err != nil { - if err != nil { - t.Error(err) - } + type test struct { + input abci.RequestPreprocessTxs + expectedMessages []*core.Message + expectedTxs int } - // finish the tx - tx := builder.GetTx() + firstNS := []byte{2, 2, 2, 2, 2, 2, 2, 2} + firstMessage := bytes.Repeat([]byte{2}, 512) + firstRawTx := generateRawTx(t, key, testApp.txConfig, firstNS, firstMessage) - // verify the signature before encoding - err = authsigning.VerifySignature(key.PubKey(), signingData, sigV2.Data, testApp.txConfig.SignModeHandler(), tx) - if err != nil { - t.Error(err) - } + secondNS := []byte{1, 1, 1, 1, 1, 1, 1, 1} + secondMessage := []byte{2} + secondRawTx := generateRawTx(t, key, testApp.txConfig, secondNS, secondMessage) - rawTx, err := testApp.txConfig.TxEncoder()(tx) - if err != nil { - t.Error(err) - } + thirdNS := []byte{3, 3, 3, 3, 3, 3, 3, 3} + thirdMessage := []byte{} + thirdRawTx := generateRawTx(t, key, testApp.txConfig, thirdNS, thirdMessage) - tests := []struct { - name string - input []byte - want core.Message - mode uint8 - }{ + tests := []test{ { - name: "basic", - mode: 3, - input: rawTx, - want: core.Message{NamespaceId: msg.MessageNameSpaceId, Data: msg.Message}, + input: abci.RequestPreprocessTxs{ + Txs: [][]byte{firstRawTx, secondRawTx, thirdRawTx}, + }, + expectedMessages: []*core.Message{ + { + NamespaceId: secondNS, // the second message should be first + Data: append([]byte{2}, bytes.Repeat([]byte{0}, 255)...), // check that the message is padded + }, + { + NamespaceId: firstNS, + Data: firstMessage, + }, + { + NamespaceId: thirdNS, + Data: nil, + }, + }, + expectedTxs: 3, }, } for _, tt := range tests { - _, _, err := testApp.TxRunner()(3, tt.input) - assert.NoError(t, err, "failure to validate and run tx") + res := testApp.PreprocessTxs(tt.input) + assert.Equal(t, tt.expectedMessages, res.Messages.MessagesList) + assert.Equal(t, tt.expectedTxs, len(res.Txs)) } } @@ -220,8 +122,11 @@ func TestTxSignature(t *testing.T) { encConf := MakeEncodingConfig() txConf := encConf.TxConfig + ns := []byte{1, 1, 1, 1, 1, 1, 1, 1} + message := bytes.Repeat([]byte{1}, 256) + // create a msg - msg := generateWirePayForMessage(t, 64, key) + msg := generateWirePayForMessage(t, 64, key, ns, message) // this is returning a tx.wrapper builder := txConf.NewTxBuilder() @@ -296,7 +201,7 @@ func TestTxSignature(t *testing.T) { // Setup App ///////////////////////////// -func setupApp(t *testing.T) *App { +func setupApp(t *testing.T) (*App, *secp256k1.PrivKey) { // var cache sdk.MultiStorePersistentCache // EmptyAppOptions is a stub implementing AppOptions emptyOpts := emptyAppOptions{} @@ -306,7 +211,7 @@ func setupApp(t *testing.T) *App { skipUpgradeHeights := make(map[int64]bool) - return New( + testApp := New( "test-app", logger, db, nil, true, skipUpgradeHeights, cast.ToString(emptyOpts.Get(flags.FlagHome)), cast.ToUint(emptyOpts.Get(server.FlagInvCheckPeriod)), @@ -314,6 +219,33 @@ func setupApp(t *testing.T) *App { emptyOpts, anteOpt, ) + + key := secp256k1.GenPrivKey() + + for acc := range maccPerms { + require.Equal(t, !allowedReceivingModAcc[acc], testApp.BankKeeper.BlockedAddr(testApp.AccountKeeper.GetModuleAddress(acc)), + "ensure that blocked addresses are properly set in bank keeper") + } + + genesisState := NewDefaultGenesisState() + + genesisState, err := addGenesisAccount(sdk.AccAddress(key.PubKey().Address().Bytes()), genesisState, testApp.appCodec) + if err != nil { + t.Error(err) + } + + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + + // Initialize the chain + testApp.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + AppStateBytes: stateBytes, + }, + ) + + return testApp, key } type emptyAppOptions struct{} @@ -390,13 +322,82 @@ func addGenesisAccount(addr sdk.AccAddress, appState map[string]json.RawMessage, // Generate Txs ///////////////////////////// -func generateWirePayForMessage(t *testing.T, k uint64, key *secp256k1.PrivKey) *types.MsgWirePayForMessage { - pubKey := key.PubKey() +func generateRawTx(t *testing.T, key *secp256k1.PrivKey, txConfig client.TxConfig, ns, message []byte) (rawTx []byte) { + // create a msg + msg := generateWirePayForMessage(t, types.SquareSize, key, ns, message) + + // this is returning a tx.wrapper + builder := txConfig.NewTxBuilder() + err := builder.SetMsgs(msg) + if err != nil { + t.Error(err) + } + + coin := sdk.Coin{ + Denom: "token", + Amount: sdk.NewInt(1000), + } + + builder.SetFeeAmount(sdk.NewCoins(coin)) + builder.SetGasLimit(10000) + builder.SetTimeoutHeight(99) + + signingData := authsigning.SignerData{ + ChainID: "test-chain", + AccountNumber: 0, + Sequence: 0, + } + + // Important set the Signature to nil BEFORE actually signing + sigData := signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + } + + sig := signing.SignatureV2{ + PubKey: key.PubKey(), + Data: &sigData, + Sequence: 0, + } + + // set the empty signature + err = builder.SetSignatures(sig) + if err != nil { + if err != nil { + t.Error(err) + } + } + + // create the actual signature + sigV2, err := cliTx.SignWithPrivKey(signing.SignMode_SIGN_MODE_DIRECT, signingData, builder, key, txConfig, 0) + if err != nil { + t.Error(err) + } + + // set the actual signature + err = builder.SetSignatures(sigV2) + if err != nil { + if err != nil { + t.Error(err) + } + } - message := bytes.Repeat([]byte{2}, 512) - nsp := []byte{1, 1, 1, 1, 1, 1, 1, 1} + // finish the tx + tx := builder.GetTx() + + // encode the tx + rawTx, err = txConfig.TxEncoder()(tx) + if err != nil { + t.Error(err) + } + + return rawTx +} + +func generateWirePayForMessage(t *testing.T, k uint64, key *secp256k1.PrivKey, ns, message []byte) *types.MsgWirePayForMessage { + pubKey := key.PubKey() - commit, err := types.CreateCommit(k, nsp, message) + commit, err := types.CreateCommitment(k, ns, message) if err != nil { t.Error(err) } @@ -404,7 +405,7 @@ func generateWirePayForMessage(t *testing.T, k uint64, key *secp256k1.PrivKey) * msg := &types.MsgWirePayForMessage{ Fee: &types.TransactionFee{}, Nonce: 0, - MessageNameSpaceId: nsp, + MessageNameSpaceId: ns, MessageSize: 512, Message: message, PublicKey: pubKey.Bytes(), diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go index b5337f2887..1661c52f78 100644 --- a/x/lazyledgerapp/types/payformessage.go +++ b/x/lazyledgerapp/types/payformessage.go @@ -1,6 +1,7 @@ package types import ( + "bytes" "crypto/sha256" "errors" fmt "fmt" @@ -61,7 +62,7 @@ func (msg *MsgWirePayForMessage) ValidateBasic() error { for _, commit := range msg.MessageShareCommitment { // check that each commit is valid - calculatedCommit, err := CreateCommit(commit.K, msg.GetMessageNameSpaceId(), msg.Message) + calculatedCommit, err := CreateCommitment(commit.K, msg.GetMessageNameSpaceId(), msg.Message) if err != nil { return err } @@ -121,7 +122,9 @@ func (msg *MsgWirePayForMessage) GetCommitmentSignBytes(k uint64) ([]byte, error // SignedTransactionDataPayForMessage use the data in the MsgWirePayForMessage // to create a new SignedTransactionDataPayForMessage func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (*SignedTransactionDataPayForMessage, error) { - commit, err := CreateCommit(k, msg.MessageNameSpaceId, msg.Message) + // add padding to message if necessary + msg.parseMessage() + commit, err := CreateCommitment(k, msg.MessageNameSpaceId, msg.Message) if err != nil { return nil, err } @@ -138,6 +141,21 @@ func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (* return &sTxMsg, nil } +// parseMessage breaks the message into chunks and adds padding to msg.Message +// if necessary +func (msg *MsgWirePayForMessage) parseMessage() [][]byte { + // break message into shares + shares := chunkMessage(msg.Message) + + // add padding if necessary + shares = addSharePadding(shares) + + // modify the message to reflect padding + msg.Message = bytes.Join(shares, []byte{}) + + return shares +} + /////////////////////////////////////// // SignedTransactionDataPayForMessage /////////////////////////////////////// @@ -201,10 +219,10 @@ func (msg *SignedTransactionDataPayForMessage) GetSigners() []sdk.AccAddress { // Utilities /////////////////////////////////////// -// CreateCommit generates the commit bytes for a given message, namespace, and +// CreateCommitment generates the commit bytes for a given message, namespace, and // squaresize using a namespace merkle tree and the rules described at // https://github.com/lazyledger/lazyledger-specs/blob/master/rationale/message_block_layout.md#non-interactive-default-rules -func CreateCommit(k uint64, namespace, message []byte) ([]byte, error) { +func CreateCommitment(k uint64, namespace, message []byte) ([]byte, error) { // break message into shares shares := chunkMessage(message) diff --git a/x/lazyledgerapp/types/payformessage_test.go b/x/lazyledgerapp/types/payformessage_test.go index 8700bf54cb..664478e3b5 100644 --- a/x/lazyledgerapp/types/payformessage_test.go +++ b/x/lazyledgerapp/types/payformessage_test.go @@ -70,7 +70,7 @@ func TestNextPowerOf2(t *testing.T) { // TestCreateCommit only shows if something changed, it doesn't actually show // the commit is being created correctly todo(evan): fix me. -func TestCreateCommit(t *testing.T) { +func TestCreateCommitment(t *testing.T) { type test struct { k uint64 namespace []byte @@ -86,7 +86,7 @@ func TestCreateCommit(t *testing.T) { }, } for _, tt := range tests { - res, err := CreateCommit(tt.k, tt.namespace, tt.message) + res, err := CreateCommitment(tt.k, tt.namespace, tt.message) assert.NoError(t, err) assert.Equal(t, tt.expected, res) } From 7295885a213b3e3316e99dce6d740b8232d07288 Mon Sep 17 00:00:00 2001 From: evan-forbes Date: Mon, 22 Feb 2021 18:07:13 -0600 Subject: [PATCH 09/10] refactor message padding remove extra redundant check --- x/lazyledgerapp/types/payformessage.go | 51 ++++++++------------- x/lazyledgerapp/types/payformessage_test.go | 32 +++++++------ 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go index 1661c52f78..5b48dfb1e9 100644 --- a/x/lazyledgerapp/types/payformessage.go +++ b/x/lazyledgerapp/types/payformessage.go @@ -1,7 +1,6 @@ package types import ( - "bytes" "crypto/sha256" "errors" fmt "fmt" @@ -123,11 +122,15 @@ func (msg *MsgWirePayForMessage) GetCommitmentSignBytes(k uint64) ([]byte, error // to create a new SignedTransactionDataPayForMessage func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (*SignedTransactionDataPayForMessage, error) { // add padding to message if necessary - msg.parseMessage() + msg.Message = PadMessage(msg.Message) + + // create the commitment using the padded message commit, err := CreateCommitment(k, msg.MessageNameSpaceId, msg.Message) if err != nil { return nil, err } + + // sTxMsg := SignedTransactionDataPayForMessage{ Fee: &TransactionFee{ BaseRateMax: msg.Fee.BaseRateMax, @@ -141,21 +144,6 @@ func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (* return &sTxMsg, nil } -// parseMessage breaks the message into chunks and adds padding to msg.Message -// if necessary -func (msg *MsgWirePayForMessage) parseMessage() [][]byte { - // break message into shares - shares := chunkMessage(msg.Message) - - // add padding if necessary - shares = addSharePadding(shares) - - // modify the message to reflect padding - msg.Message = bytes.Join(shares, []byte{}) - - return shares -} - /////////////////////////////////////// // SignedTransactionDataPayForMessage /////////////////////////////////////// @@ -223,12 +211,12 @@ func (msg *SignedTransactionDataPayForMessage) GetSigners() []sdk.AccAddress { // squaresize using a namespace merkle tree and the rules described at // https://github.com/lazyledger/lazyledger-specs/blob/master/rationale/message_block_layout.md#non-interactive-default-rules func CreateCommitment(k uint64, namespace, message []byte) ([]byte, error) { + // add padding to the message if necessary + message = PadMessage(message) + // break message into shares shares := chunkMessage(message) - // add padding if necessary - shares = addSharePadding(shares) - // organize shares for merkle mountain range heights := PowerOf2MountainRange(uint64(len(shares)), k) leafSets := make([][][]byte, len(heights)) @@ -255,7 +243,7 @@ func CreateCommitment(k uint64, namespace, message []byte) ([]byte, error) { return merkle.HashFromByteSlices(subTreeRoots), nil } -// chunkMessage breaks the message into 256 byte pieces +// chunkMessage breaks the message into ShareSize pieces func chunkMessage(message []byte) [][]byte { var shares [][]byte for i := 0; i < len(message); i += ShareSize { @@ -268,20 +256,19 @@ func chunkMessage(message []byte) [][]byte { return shares } -// addSharePadding will add padding to the last share if necessary -func addSharePadding(shares [][]byte) [][]byte { - if len(shares) == 0 { - return shares +// PadMessage adds padding to the msg if the length of the msg is not divisible +// by the share size specified in lazyledger-core +func PadMessage(msg []byte) []byte { + // check if the message needs padding + if uint64(len(msg))%ShareSize == 0 { + return msg } - // add padding to the last share if necessary - if len(shares[len(shares)-1]) != ShareSize { - padded := make([]byte, ShareSize) - copy(padded, shares[len(shares)-1]) - shares[len(shares)-1] = padded - } + shareCount := (len(msg) / ShareSize) + 1 - return shares + padded := make([]byte, shareCount*ShareSize) + copy(padded, msg) + return padded } // PowerOf2MountainRange returns the heights of the subtrees for binary merkle diff --git a/x/lazyledgerapp/types/payformessage_test.go b/x/lazyledgerapp/types/payformessage_test.go index 664478e3b5..0e76e348a2 100644 --- a/x/lazyledgerapp/types/payformessage_test.go +++ b/x/lazyledgerapp/types/payformessage_test.go @@ -121,29 +121,31 @@ func TestGetCommitmentSignBytes(t *testing.T) { } } -func TestShareChunkingAndPadding(t *testing.T) { +func TestPadMessage(t *testing.T) { type test struct { - input []byte - expect [][]byte + input []byte + expected []byte } tests := []test{ { - input: []byte{1}, - expect: [][]byte{append([]byte{1}, bytes.Repeat([]byte{0}, ShareSize-1)...)}, + input: []byte{1}, + expected: append([]byte{1}, bytes.Repeat([]byte{0}, ShareSize-1)...), + }, + { + input: []byte{}, + expected: []byte{}, }, { - input: bytes.Repeat([]byte{1}, ShareSize), - expect: [][]byte{bytes.Repeat([]byte{1}, ShareSize)}, + input: bytes.Repeat([]byte{1}, ShareSize), + expected: bytes.Repeat([]byte{1}, ShareSize), + }, + { + input: bytes.Repeat([]byte{1}, (3*ShareSize)-10), + expected: append(bytes.Repeat([]byte{1}, (3*ShareSize)-10), bytes.Repeat([]byte{0}, 10)...), }, } for _, tt := range tests { - shares := chunkMessage(tt.input) - shares = addSharePadding(shares) - for _, share := range shares { - if len(share) != ShareSize { - t.Errorf("invalid share length: got %d wanted core.ShareSize (%d)", len(share), ShareSize) - } - } - assert.Equal(t, tt.expect, shares) + res := PadMessage(tt.input) + assert.Equal(t, tt.expected, res) } } From 3578791181b0be1a7c66c4320bf869369177adac Mon Sep 17 00:00:00 2001 From: Evan Forbes <42654277+evan-forbes@users.noreply.github.com> Date: Tue, 23 Feb 2021 06:56:37 -0600 Subject: [PATCH 10/10] remove unused comment Co-authored-by: Ismail Khoffi --- x/lazyledgerapp/types/payformessage.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/lazyledgerapp/types/payformessage.go b/x/lazyledgerapp/types/payformessage.go index 5b48dfb1e9..1f2ffec5cf 100644 --- a/x/lazyledgerapp/types/payformessage.go +++ b/x/lazyledgerapp/types/payformessage.go @@ -130,7 +130,6 @@ func (msg *MsgWirePayForMessage) SignedTransactionDataPayForMessage(k uint64) (* return nil, err } - // sTxMsg := SignedTransactionDataPayForMessage{ Fee: &TransactionFee{ BaseRateMax: msg.Fee.BaseRateMax,