From 71f51129c275dcce267999c88027fbb07a6b39f9 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 29 Jan 2025 15:17:47 +0100 Subject: [PATCH 01/12] refactor: fixture generator testutil --- cmd/poktrolld/cmd/migrate/migrate_test.go | 101 +------------------ testutil/testmigration/fixtures.go | 116 ++++++++++++++++++++++ 2 files changed, 120 insertions(+), 97 deletions(-) create mode 100644 testutil/testmigration/fixtures.go diff --git a/cmd/poktrolld/cmd/migrate/migrate_test.go b/cmd/poktrolld/cmd/migrate/migrate_test.go index dee73474d..4216d363c 100644 --- a/cmd/poktrolld/cmd/migrate/migrate_test.go +++ b/cmd/poktrolld/cmd/migrate/migrate_test.go @@ -1,22 +1,17 @@ package migrate import ( - "encoding/binary" "fmt" "math" - "math/rand" "os" "path/filepath" "strings" "testing" - cometcrypto "github.com/cometbft/cometbft/crypto/ed25519" cmtjson "github.com/cometbft/cometbft/libs/json" - cosmostypes "github.com/cosmos/cosmos-sdk/types" - "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/app/volatile" + "github.com/pokt-network/poktroll/testutil/testmigration" migrationtypes "github.com/pokt-network/poktroll/x/migration/types" ) @@ -26,7 +21,7 @@ func TestCollectMorseAccounts(t *testing.T) { inputFile, err := os.CreateTemp(tmpDir, "morse-state-input.json") require.NoError(t, err) - morseStateExportBz, morseAccountStateBz := newMorseStateExportAndAccountState(t, 10) + morseStateExportBz, morseAccountStateBz := testmigration.NewMorseStateExportAndAccountStateBytes(t, 10) _, err = inputFile.Write(morseStateExportBz) require.NoError(t, err) @@ -55,7 +50,7 @@ func TestNewTestMorseStateExport(t *testing.T) { for i := 1; i < 10; i++ { t.Run(fmt.Sprintf("num_accounts=%d", i), func(t *testing.T) { morseStateExport := new(migrationtypes.MorseStateExport) - stateExportBz, _ := newMorseStateExportAndAccountState(t, i) + stateExportBz, _ := testmigration.NewMorseStateExportAndAccountStateBytes(t, i) err := cmtjson.Unmarshal(stateExportBz, morseStateExport) require.NoError(t, err) @@ -79,7 +74,7 @@ func BenchmarkTransformMorseState(b *testing.B) { for i := 0; i < 5; i++ { numAccounts := int(math.Pow10(i + 1)) morseStateExport := new(migrationtypes.MorseStateExport) - morseStateExportBz, _ := newMorseStateExportAndAccountState(b, numAccounts) + morseStateExportBz, _ := testmigration.NewMorseStateExportAndAccountStateBytes(b, numAccounts) err := cmtjson.Unmarshal(morseStateExportBz, morseStateExport) require.NoError(b, err) @@ -94,91 +89,3 @@ func BenchmarkTransformMorseState(b *testing.B) { }) } } - -// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture. -func newMorseStateExportAndAccountState( - t gocuke.TestingT, - numAccounts int, -) (morseStateExportBz []byte, morseAccountStateBz []byte) { - morseStateExport := &migrationtypes.MorseStateExport{ - AppHash: "", - AppState: &migrationtypes.MorseAppState{ - Application: &migrationtypes.MorseApplications{}, - Auth: &migrationtypes.MorseAuth{}, - Pos: &migrationtypes.MorsePos{}, - }, - } - - morseAccountState := &migrationtypes.MorseAccountState{ - Accounts: make([]*migrationtypes.MorseAccount, numAccounts), - } - - for i := 1; i < numAccounts+1; i++ { - seedUint := rand.Uint64() - seedBz := make([]byte, 8) - binary.LittleEndian.PutUint64(seedBz, seedUint) - privKey := cometcrypto.GenPrivKeyFromSecret(seedBz) - pubKey := privKey.PubKey() - balanceAmount := int64(1e6*i + i) // i_000_00i - appStakeAmount := int64(1e5*i + (i * 10)) // i00_0i0 - supplierStakeAmount := int64(1e4*i + (i * 100)) // i0_i00 - sumAmount := balanceAmount + appStakeAmount + supplierStakeAmount // i_ii0_iii - - // Add an account. - morseStateExport.AppState.Auth.Accounts = append( - morseStateExport.AppState.Auth.Accounts, - &migrationtypes.MorseAuthAccount{ - Type: "posmint/Account", - Value: &migrationtypes.MorseAccount{ - Address: pubKey.Address(), - Coins: cosmostypes.NewCoins(cosmostypes.NewInt64Coin(volatile.DenomuPOKT, balanceAmount)), - PubKey: &migrationtypes.MorsePublicKey{ - Value: pubKey.Bytes(), - }, - }, - }, - ) - - // Add an application. - morseStateExport.AppState.Application.Applications = append( - morseStateExport.AppState.Application.Applications, - &migrationtypes.MorseApplication{ - Address: pubKey.Address(), - PublicKey: pubKey.Bytes(), - Jailed: false, - Status: 2, - StakedTokens: fmt.Sprintf("%d", appStakeAmount), - }, - ) - - // Add a supplier. - morseStateExport.AppState.Pos.Validators = append( - morseStateExport.AppState.Pos.Validators, - &migrationtypes.MorseValidator{ - Address: pubKey.Address(), - PublicKey: pubKey.Bytes(), - Jailed: false, - Status: 2, - StakedTokens: fmt.Sprintf("%d", supplierStakeAmount), - }, - ) - - // Add the account to the morseAccountState. - morseAccountState.Accounts[i-1] = &migrationtypes.MorseAccount{ - Address: pubKey.Address(), - Coins: cosmostypes.NewCoins(cosmostypes.NewInt64Coin(volatile.DenomuPOKT, sumAmount)), - PubKey: &migrationtypes.MorsePublicKey{ - Value: pubKey.Bytes(), - }, - } - } - - var err error - morseStateExportBz, err = cmtjson.Marshal(morseStateExport) - require.NoError(t, err) - - morseAccountStateBz, err = cmtjson.Marshal(morseAccountState) - require.NoError(t, err) - - return morseStateExportBz, morseAccountStateBz -} diff --git a/testutil/testmigration/fixtures.go b/testutil/testmigration/fixtures.go new file mode 100644 index 000000000..e360f593d --- /dev/null +++ b/testutil/testmigration/fixtures.go @@ -0,0 +1,116 @@ +package testmigration + +import ( + "encoding/binary" + "fmt" + "math/rand" + + cometcrypto "github.com/cometbft/cometbft/crypto/ed25519" + cmtjson "github.com/cometbft/cometbft/libs/json" + cosmostypes "github.com/cosmos/cosmos-sdk/types" + "github.com/regen-network/gocuke" + "github.com/stretchr/testify/require" + + "github.com/pokt-network/poktroll/app/volatile" + migrationtypes "github.com/pokt-network/poktroll/x/migration/types" +) + +// TODO_IN_THIS_COMMIT: godoc... +// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture. +func NewMorseStateExportAndAccountStateBytes( + t gocuke.TestingT, + numAccounts int, +) (morseStateExportBz []byte, morseAccountStateBz []byte) { + morseStateExport, morseAccountState := NewMorseStateExportAndAccountState(t, numAccounts) + + var err error + morseStateExportBz, err = cmtjson.Marshal(morseStateExport) + require.NoError(t, err) + + morseAccountStateBz, err = cmtjson.Marshal(morseAccountState) + require.NoError(t, err) + + return morseStateExportBz, morseAccountStateBz +} + +// TODO_IN_THIS_COMMIT: godoc... +func NewMorseStateExportAndAccountState( + t gocuke.TestingT, numAccounts int, +) (export *migrationtypes.MorseStateExport, state *migrationtypes.MorseAccountState) { + t.Helper() + + morseStateExport := &migrationtypes.MorseStateExport{ + AppHash: "", + AppState: &migrationtypes.MorseAppState{ + Application: &migrationtypes.MorseApplications{}, + Auth: &migrationtypes.MorseAuth{}, + Pos: &migrationtypes.MorsePos{}, + }, + } + + morseAccountState := &migrationtypes.MorseAccountState{ + Accounts: make([]*migrationtypes.MorseAccount, numAccounts), + } + + for i := 1; i < numAccounts+1; i++ { + seedUint := rand.Uint64() + seedBz := make([]byte, 8) + binary.LittleEndian.PutUint64(seedBz, seedUint) + privKey := cometcrypto.GenPrivKeyFromSecret(seedBz) + pubKey := privKey.PubKey() + balanceAmount := int64(1e6*i + i) // i_000_00i + appStakeAmount := int64(1e5*i + (i * 10)) // i00_0i0 + supplierStakeAmount := int64(1e4*i + (i * 100)) // i0_i00 + sumAmount := balanceAmount + appStakeAmount + supplierStakeAmount // i_ii0_iii + + // Add an account. + morseStateExport.AppState.Auth.Accounts = append( + morseStateExport.AppState.Auth.Accounts, + &migrationtypes.MorseAuthAccount{ + Type: "posmint/Account", + Value: &migrationtypes.MorseAccount{ + Address: pubKey.Address(), + Coins: cosmostypes.NewCoins(cosmostypes.NewInt64Coin(volatile.DenomuPOKT, balanceAmount)), + PubKey: &migrationtypes.MorsePublicKey{ + Value: pubKey.Bytes(), + }, + }, + }, + ) + + // Add an application. + morseStateExport.AppState.Application.Applications = append( + morseStateExport.AppState.Application.Applications, + &migrationtypes.MorseApplication{ + Address: pubKey.Address(), + PublicKey: pubKey.Bytes(), + Jailed: false, + Status: 2, + StakedTokens: fmt.Sprintf("%d", appStakeAmount), + }, + ) + + // Add a supplier. + morseStateExport.AppState.Pos.Validators = append( + morseStateExport.AppState.Pos.Validators, + &migrationtypes.MorseValidator{ + Address: pubKey.Address(), + PublicKey: pubKey.Bytes(), + Jailed: false, + Status: 2, + StakedTokens: fmt.Sprintf("%d", supplierStakeAmount), + }, + ) + + // Add the account to the morseAccountState. + morseAccountState.Accounts[i-1] = &migrationtypes.MorseAccount{ + Address: pubKey.Address(), + Coins: cosmostypes.NewCoins(cosmostypes.NewInt64Coin(volatile.DenomuPOKT, sumAmount)), + PubKey: &migrationtypes.MorsePublicKey{ + Value: pubKey.Bytes(), + }, + } + } + + return morseStateExport, morseAccountState +} From 0180b2f48023e35f8ad5e5af8966a8806d784549 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 29 Jan 2025 15:18:30 +0100 Subject: [PATCH 02/12] feat: implement Morse account state upload --- api/poktroll/migration/event.pulsar.go | 646 ++++++++++++++++++ proto/poktroll/migration/event.proto | 18 + .../keeper/msg_server_morse_account_state.go | 40 +- .../msg_server_morse_account_state_test.go | 85 ++- x/migration/types/event.pb.go | 361 ++++++++++ x/migration/types/morse_account_state.go | 17 + 6 files changed, 1153 insertions(+), 14 deletions(-) create mode 100644 api/poktroll/migration/event.pulsar.go create mode 100644 proto/poktroll/migration/event.proto create mode 100644 x/migration/types/event.pb.go create mode 100644 x/migration/types/morse_account_state.go diff --git a/api/poktroll/migration/event.pulsar.go b/api/poktroll/migration/event.pulsar.go new file mode 100644 index 000000000..07c371df5 --- /dev/null +++ b/api/poktroll/migration/event.pulsar.go @@ -0,0 +1,646 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package migration + +import ( + _ "cosmossdk.io/api/cosmos/base/v1beta1" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + runtime "github.com/cosmos/cosmos-proto/runtime" + _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/pokt-network/poktroll/api/poktroll/shared" + prot + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_EventCreateMorseAccountState protoreflect.MessageDescriptor + fd_EventCreateMorseAccountState_height protoreflect.FieldDescriptor + fd_EventCreateMorseAccountState_state_hash protoreflect.FieldDescriptor +) + +func init() { + file_poktroll_migration_event_proto_init() + md_EventCreateMorseAccountState = File_poktroll_migration_event_proto.Messages().ByName("EventCreateMorseAccountState") + fd_EventCreateMorseAccountState_height = md_EventCreateMorseAccountState.Fields().ByName("height") + fd_EventCreateMorseAccountState_state_hash = md_EventCreateMorseAccountState.Fields().ByName("state_hash") +} + +var _ protoreflect.Message = (*fastReflection_EventCreateMorseAccountState)(nil) + +type fastReflection_EventCreateMorseAccountState EventCreateMorseAccountState + +func (x *EventCreateMorseAccountState) ProtoReflect() protoreflect.Message { + return (*fastReflection_EventCreateMorseAccountState)(x) +} + +func (x *EventCreateMorseAccountState) slowProtoReflect() protoreflect.Message { + mi := &file_poktroll_migration_event_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_EventCreateMorseAccountState_messageType fastReflection_EventCreateMorseAccountState_messageType +var _ protoreflect.MessageType = fastReflection_EventCreateMorseAccountState_messageType{} + +type fastReflection_EventCreateMorseAccountState_messageType struct{} + +func (x fastReflection_EventCreateMorseAccountState_messageType) Zero() protoreflect.Message { + return (*fastReflection_EventCreateMorseAccountState)(nil) +} +func (x fastReflection_EventCreateMorseAccountState_messageType) New() protoreflect.Message { + return new(fastReflection_EventCreateMorseAccountState) +} +func (x fastReflection_EventCreateMorseAccountState_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_EventCreateMorseAccountState +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_EventCreateMorseAccountState) Descriptor() protoreflect.MessageDescriptor { + return md_EventCreateMorseAccountState +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_EventCreateMorseAccountState) Type() protoreflect.MessageType { + return _fastReflection_EventCreateMorseAccountState_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_EventCreateMorseAccountState) New() protoreflect.Message { + return new(fastReflection_EventCreateMorseAccountState) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_EventCreateMorseAccountState) Interface() protoreflect.ProtoMessage { + return (*EventCreateMorseAccountState)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_EventCreateMorseAccountState) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Height != int64(0) { + value := protoreflect.ValueOfInt64(x.Height) + if !f(fd_EventCreateMorseAccountState_height, value) { + return + } + } + if len(x.StateHash) != 0 { + value := protoreflect.ValueOfBytes(x.StateHash) + if !f(fd_EventCreateMorseAccountState_state_hash, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_EventCreateMorseAccountState) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "poktroll.migration.EventCreateMorseAccountState.height": + return x.Height != int64(0) + case "poktroll.migration.EventCreateMorseAccountState.state_hash": + return len(x.StateHash) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) + } + panic(fmt.Errorf("message poktroll.migration.EventCreateMorseAccountState does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EventCreateMorseAccountState) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "poktroll.migration.EventCreateMorseAccountState.height": + x.Height = int64(0) + case "poktroll.migration.EventCreateMorseAccountState.state_hash": + x.StateHash = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) + } + panic(fmt.Errorf("message poktroll.migration.EventCreateMorseAccountState does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_EventCreateMorseAccountState) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "poktroll.migration.EventCreateMorseAccountState.height": + value := x.Height + return protoreflect.ValueOfInt64(value) + case "poktroll.migration.EventCreateMorseAccountState.state_hash": + value := x.StateHash + return protoreflect.ValueOfBytes(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) + } + panic(fmt.Errorf("message poktroll.migration.EventCreateMorseAccountState does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EventCreateMorseAccountState) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "poktroll.migration.EventCreateMorseAccountState.height": + x.Height = value.Int() + case "poktroll.migration.EventCreateMorseAccountState.state_hash": + x.StateHash = value.Bytes() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) + } + panic(fmt.Errorf("message poktroll.migration.EventCreateMorseAccountState does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EventCreateMorseAccountState) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "poktroll.migration.EventCreateMorseAccountState.height": + panic(fmt.Errorf("field height of message poktroll.migration.EventCreateMorseAccountState is not mutable")) + case "poktroll.migration.EventCreateMorseAccountState.state_hash": + panic(fmt.Errorf("field state_hash of message poktroll.migration.EventCreateMorseAccountState is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) + } + panic(fmt.Errorf("message poktroll.migration.EventCreateMorseAccountState does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_EventCreateMorseAccountState) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "poktroll.migration.EventCreateMorseAccountState.height": + return protoreflect.ValueOfInt64(int64(0)) + case "poktroll.migration.EventCreateMorseAccountState.state_hash": + return protoreflect.ValueOfBytes(nil) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) + } + panic(fmt.Errorf("message poktroll.migration.EventCreateMorseAccountState does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_EventCreateMorseAccountState) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in poktroll.migration.EventCreateMorseAccountState", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_EventCreateMorseAccountState) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EventCreateMorseAccountState) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_EventCreateMorseAccountState) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*EventCreateMorseAccountState) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.Height != 0 { + n += 1 + runtime.Sov(uint64(x.Height)) + } + l = len(x.StateHash) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*EventCreateMorseAccountState) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.StateHash) > 0 { + i -= len(x.StateHash) + copy(dAtA[i:], x.StateHash) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.StateHash))) + i-- + dAtA[i] = 0x1a + } + if x.Height != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Height)) + i-- + dAtA[i] = 0x8 + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*EventCreateMorseAccountState) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, 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 protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EventCreateMorseAccountState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EventCreateMorseAccountState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + x.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field StateHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.StateHash = append(x.StateHash[:0], dAtA[iNdEx:postIndex]...) + if x.StateHash == nil { + x.StateHash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: poktroll/migration/event.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// EventUploadMorseState is emitted when a new state hash is uploaded. +type EventCreateMorseAccountState struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + StateHash []byte `protobuf:"bytes,3,opt,name=state_hash,json=stateHash,proto3" json:"state_hash,omitempty"` +} + +func (x *EventCreateMorseAccountState) Reset() { + *x = EventCreateMorseAccountState{} + if protoimpl.UnsafeEnabled { + mi := &file_poktroll_migration_event_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EventCreateMorseAccountState) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EventCreateMorseAccountState) ProtoMessage() {} + +// Deprecated: Use EventCreateMorseAccountState.ProtoReflect.Descriptor instead. +func (*EventCreateMorseAccountState) Descriptor() ([]byte, []int) { + return file_poktroll_migration_event_proto_rawDescGZIP(), []int{0} +} + +func (x *EventCreateMorseAccountState) GetHeight() int64 { + if x != nil { + return x.Height + } + return 0 +} + +func (x *EventCreateMorseAccountState) GetStateHash() []byte { + if x != nil { + return x.StateHash + } + return nil +} + +var File_poktroll_migration_event_proto protoreflect.FileDescriptor + +var file_poktroll_migration_event_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x12, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, + 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, + 0x73, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x71, 0x0a, 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x72, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x12, 0x22, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x42, 0x0a, 0xea, 0xde, 0x1f, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, + 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x2d, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, + 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x0e, 0xea, 0xde, + 0x1f, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x52, 0x09, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x42, 0xb6, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x16, + 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, + 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x23, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, + 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, + 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x4d, 0x58, 0xaa, + 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x4d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, + 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x1e, 0x50, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x50, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_poktroll_migration_event_proto_rawDescOnce sync.Once + file_poktroll_migration_event_proto_rawDescData = file_poktroll_migration_event_proto_rawDesc +) + +func file_poktroll_migration_event_proto_rawDescGZIP() []byte { + file_poktroll_migration_event_proto_rawDescOnce.Do(func() { + file_poktroll_migration_event_proto_rawDescData = protoimpl.X.CompressGZIP(file_poktroll_migration_event_proto_rawDescData) + }) + return file_poktroll_migration_event_proto_rawDescData +} + +var file_poktroll_migration_event_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_poktroll_migration_event_proto_goTypes = []interface{}{ + (*EventCreateMorseAccountState)(nil), // 0: poktroll.migration.EventCreateMorseAccountState +} +var file_poktroll_migration_event_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_poktroll_migration_event_proto_init() } +func file_poktroll_migration_event_proto_init() { + if File_poktroll_migration_event_proto != nil { + return + } + file_poktroll_migration_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_poktroll_migration_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EventCreateMorseAccountState); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_poktroll_migration_event_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_poktroll_migration_event_proto_goTypes, + DependencyIndexes: file_poktroll_migration_event_proto_depIdxs, + MessageInfos: file_poktroll_migration_event_proto_msgTypes, + }.Build() + File_poktroll_migration_event_proto = out.File + file_poktroll_migration_event_proto_rawDesc = nil + file_poktroll_migration_event_proto_goTypes = nil + file_poktroll_migration_event_proto_depIdxs = nil +} diff --git a/proto/poktroll/migration/event.proto b/proto/poktroll/migration/event.proto new file mode 100644 index 000000000..d1b9cc900 --- /dev/null +++ b/proto/poktroll/migration/event.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package poktroll.migration; + +option go_package = "github.com/pokt-network/poktroll/x/migration/types"; +option (gogoproto.stable_marshaler_all) = true; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +import "poktroll/shared/service.proto"; +import "poktroll/migration/types.proto"; + +// EventUploadMorseState is emitted when a new state hash is uploaded. +message EventCreateMorseAccountState { + int64 height = 1 [(gogoproto.jsontag) = "height"]; + bytes state_hash = 3 [(gogoproto.jsontag) = "state_hash"]; +} diff --git a/x/migration/keeper/msg_server_morse_account_state.go b/x/migration/keeper/msg_server_morse_account_state.go index 9ae9b6139..75ecfa7a6 100644 --- a/x/migration/keeper/msg_server_morse_account_state.go +++ b/x/migration/keeper/msg_server_morse_account_state.go @@ -3,25 +3,51 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/x/migration/types" ) -func (k msgServer) CreateMorseAccountState(goCtx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) +func (k msgServer) CreateMorseAccountState(ctx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + if err := msg.ValidateBasic(); err != nil { + return nil, err + } // Check if the value already exists - _, isFound := k.GetMorseAccountState(ctx) + _, isFound := k.GetMorseAccountState(sdkCtx) if isFound { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "already set") + return nil, status.Error( + codes.FailedPrecondition, + sdkerrors.ErrInvalidRequest.Wrap("already set").Error(), + ) } k.SetMorseAccountState( - ctx, + sdkCtx, msg.MorseAccountState, ) - return &types.MsgCreateMorseAccountStateResponse{}, nil + + stateHash, err := msg.MorseAccountState.GetHash() + if err != nil { + return nil, err + } + + if err = sdkCtx.EventManager().EmitTypedEvent( + &types.EventCreateMorseAccountState{ + Height: sdkCtx.BlockHeight(), + StateHash: stateHash, + }, + ); err != nil { + return nil, err + } + + return &types.MsgCreateMorseAccountStateResponse{ + StateHash: stateHash, + NumAccounts: uint64(len(msg.MorseAccountState.Accounts)), + }, nil } diff --git a/x/migration/keeper/msg_server_morse_account_state_test.go b/x/migration/keeper/msg_server_morse_account_state_test.go index c12fd49bc..a4f811b48 100644 --- a/x/migration/keeper/msg_server_morse_account_state_test.go +++ b/x/migration/keeper/msg_server_morse_account_state_test.go @@ -3,20 +3,91 @@ package keeper_test import ( "testing" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pokt-network/poktroll/testutil/events" keepertest "github.com/pokt-network/poktroll/testutil/keeper" + "github.com/pokt-network/poktroll/testutil/testmigration" "github.com/pokt-network/poktroll/x/migration/keeper" - "github.com/pokt-network/poktroll/x/migration/types" + migrationtypes "github.com/pokt-network/poktroll/x/migration/types" ) -func TestMorseAccountStateMsgServerCreate(t *testing.T) { +func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { k, ctx := keepertest.MigrationKeeper(t) srv := keeper.NewMsgServerImpl(k) - authority := "A" - expected := &types.MsgCreateMorseAccountState{Authority: authority} - _, err := srv.CreateMorseAccountState(ctx, expected) + + numAccounts := 10 + _, accountState := testmigration.NewMorseStateExportAndAccountState(t, numAccounts) + + // Assert that the MorseAccountState is not set initially. + _, isFound := k.GetMorseAccountState(ctx) + require.False(t, isFound) + + res, err := srv.CreateMorseAccountState(ctx, &migrationtypes.MsgCreateMorseAccountState{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + MorseAccountState: *accountState, + }) + require.NoError(t, err) + + expectedUploadMsg := &migrationtypes.MsgCreateMorseAccountState{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + MorseAccountState: *accountState, + } + expectedStateHash, err := expectedUploadMsg.MorseAccountState.GetHash() + require.NoError(t, err) + require.NotEmpty(t, expectedStateHash) + require.Len(t, expectedStateHash, 32) + + expectedRes := &migrationtypes.MsgCreateMorseAccountStateResponse{ + StateHash: expectedStateHash, + NumAccounts: uint64(numAccounts), + } + require.Equal(t, expectedRes, res) + + MorseAccountState, isFound := k.GetMorseAccountState(ctx) + require.True(t, isFound) + require.NoError(t, err) + + actualStateHash, err := MorseAccountState.GetHash() require.NoError(t, err) - _, found := k.GetMorseAccountState(ctx) - require.True(t, found) + require.Equal(t, expectedRes.StateHash, actualStateHash) + require.Equal(t, int(expectedRes.NumAccounts), len(MorseAccountState.GetAccounts())) + + evts := ctx.EventManager().Events() + filteredEvts := events.FilterEvents[*migrationtypes.EventCreateMorseAccountState](t, evts) + require.Equal(t, 1, len(filteredEvts)) + + expectedEvent := &migrationtypes.EventCreateMorseAccountState{ + Height: ctx.BlockHeight(), + StateHash: expectedStateHash, + } + require.Equal(t, expectedEvent, filteredEvts[0]) +} + +func TestMorseAccountStateMsgServerCreate_Error(t *testing.T) { + k, ctx := keepertest.MigrationKeeper(t) + srv := keeper.NewMsgServerImpl(k) + + numAccounts := 10 + _, accountState := testmigration.NewMorseStateExportAndAccountState(t, numAccounts) + k.SetMorseAccountState(ctx, *accountState) + + // Assert that the MorseAccountState is set initially. + _, isFound := k.GetMorseAccountState(ctx) + require.True(t, isFound) + + // Assert that the MorseAccountState can ONLY be set once. + _, err := srv.CreateMorseAccountState(ctx, &migrationtypes.MsgCreateMorseAccountState{ + Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), + MorseAccountState: *accountState, + }) + t.Log(err) + + stat := status.Convert(err) + require.Equal(t, codes.FailedPrecondition, stat.Code()) + require.ErrorContains(t, err, "already set") } diff --git a/x/migration/types/event.pb.go b/x/migration/types/event.pb.go new file mode 100644 index 000000000..4960740bc --- /dev/null +++ b/x/migration/types/event.pb.go @@ -0,0 +1,361 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: poktroll/migration/event.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "github.com/pokt-network/poktroll/x/shared/types" + 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 + +// EventUploadMorseState is emitted when a new state hash is uploaded. +type EventCreateMorseAccountState struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height"` + StateHash []byte `protobuf:"bytes,3,opt,name=state_hash,json=stateHash,proto3" json:"state_hash"` +} + +func (m *EventCreateMorseAccountState) Reset() { *m = EventCreateMorseAccountState{} } +func (m *EventCreateMorseAccountState) String() string { return proto.CompactTextString(m) } +func (*EventCreateMorseAccountState) ProtoMessage() {} +func (*EventCreateMorseAccountState) Descriptor() ([]byte, []int) { + return fileDescriptor_d5b0bc9ed37905e1, []int{0} +} +func (m *EventCreateMorseAccountState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventCreateMorseAccountState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *EventCreateMorseAccountState) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventCreateMorseAccountState.Merge(m, src) +} +func (m *EventCreateMorseAccountState) XXX_Size() int { + return m.Size() +} +func (m *EventCreateMorseAccountState) XXX_DiscardUnknown() { + xxx_messageInfo_EventCreateMorseAccountState.DiscardUnknown(m) +} + +var xxx_messageInfo_EventCreateMorseAccountState proto.InternalMessageInfo + +func (m *EventCreateMorseAccountState) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *EventCreateMorseAccountState) GetStateHash() []byte { + if m != nil { + return m.StateHash + } + return nil +} + +func init() { + proto.RegisterType((*EventCreateMorseAccountState)(nil), "poktroll.migration.EventCreateMorseAccountState") +} + +func init() { proto.RegisterFile("poktroll/migration/event.proto", fileDescriptor_d5b0bc9ed37905e1) } + +var fileDescriptor_d5b0bc9ed37905e1 = []byte{ + // 290 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x8f, 0xcf, 0x4a, 0x33, 0x31, + 0x14, 0xc5, 0x1b, 0x0a, 0x85, 0x2f, 0x7c, 0xb8, 0x18, 0x5c, 0xd4, 0xa2, 0x69, 0xe9, 0xaa, 0x9b, + 0x36, 0x54, 0x9f, 0xc0, 0x8a, 0xe0, 0x46, 0x90, 0xba, 0x73, 0x53, 0x32, 0xf1, 0x32, 0x09, 0x6d, + 0xe7, 0x8e, 0xc9, 0xed, 0xa8, 0x6f, 0xe1, 0x63, 0xb9, 0xec, 0xb2, 0xab, 0x22, 0x33, 0xbb, 0x3e, + 0x85, 0xcc, 0x9f, 0x0e, 0x22, 0xae, 0x72, 0x72, 0xce, 0x09, 0xf9, 0x1d, 0x2e, 0x12, 0x5c, 0x92, + 0xc3, 0xd5, 0x4a, 0xae, 0x6d, 0xe4, 0x14, 0x59, 0x8c, 0x25, 0xa4, 0x10, 0xd3, 0x24, 0x71, 0x48, + 0x18, 0x04, 0xc7, 0x7c, 0xd2, 0xe4, 0xbd, 0x33, 0x8d, 0x7e, 0x8d, 0x7e, 0x51, 0x36, 0x64, 0x75, + 0xa9, 0xea, 0xbd, 0xd3, 0x08, 0x23, 0xac, 0xfc, 0x42, 0xd5, 0xae, 0xa8, 0x3a, 0x32, 0x54, 0x1e, + 0x64, 0x3a, 0x0d, 0x81, 0xd4, 0x54, 0x6a, 0xb4, 0x71, 0x9d, 0x5f, 0x34, 0x10, 0xde, 0x28, 0x07, + 0xcf, 0xd2, 0x83, 0x4b, 0xad, 0x86, 0xe3, 0xf3, 0x3f, 0x18, 0xe9, 0x3d, 0x81, 0xfa, 0xd3, 0xe1, + 0x0b, 0x3f, 0xbf, 0x2d, 0x90, 0x6f, 0x1c, 0x28, 0x82, 0x7b, 0x74, 0x1e, 0xae, 0xb5, 0xc6, 0x4d, + 0x4c, 0x8f, 0xa4, 0x08, 0x82, 0x21, 0xef, 0x18, 0xb0, 0x91, 0xa1, 0x2e, 0x1b, 0xb0, 0x51, 0x7b, + 0xc6, 0x0f, 0xfb, 0x7e, 0xed, 0xcc, 0xeb, 0x33, 0x18, 0x73, 0xee, 0x8b, 0xf2, 0xc2, 0x28, 0x6f, + 0xba, 0xed, 0x01, 0x1b, 0xfd, 0x9f, 0x9d, 0x1c, 0xf6, 0xfd, 0x1f, 0xee, 0xfc, 0x5f, 0xa9, 0xef, + 0x94, 0x37, 0xb3, 0x87, 0xcf, 0x4c, 0xb0, 0x6d, 0x26, 0xd8, 0x2e, 0x13, 0xec, 0x2b, 0x13, 0xec, + 0x23, 0x17, 0xad, 0x6d, 0x2e, 0x5a, 0xbb, 0x5c, 0xb4, 0x9e, 0x2e, 0x23, 0x4b, 0x66, 0x13, 0x4e, + 0x34, 0xae, 0x65, 0xc1, 0x3e, 0x8e, 0x81, 0x5e, 0xd1, 0x2d, 0x65, 0x33, 0xe4, 0xed, 0xf7, 0x94, + 0xb0, 0x53, 0x6e, 0xb9, 0xfa, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x52, 0xd7, 0x04, 0x91, 0x01, + 0x00, 0x00, +} + +func (m *EventCreateMorseAccountState) 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 *EventCreateMorseAccountState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventCreateMorseAccountState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StateHash) > 0 { + i -= len(m.StateHash) + copy(dAtA[i:], m.StateHash) + i = encodeVarintEvent(dAtA, i, uint64(len(m.StateHash))) + i-- + dAtA[i] = 0x1a + } + if m.Height != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { + offset -= sovEvent(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *EventCreateMorseAccountState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovEvent(uint64(m.Height)) + } + l = len(m.StateHash) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + return n +} + +func sovEvent(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvent(x uint64) (n int) { + return sovEvent(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *EventCreateMorseAccountState) 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 ErrIntOverflowEvent + } + 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: EventCreateMorseAccountState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventCreateMorseAccountState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StateHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEvent + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StateHash = append(m.StateHash[:0], dAtA[iNdEx:postIndex]...) + if m.StateHash == nil { + m.StateHash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvent(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, ErrIntOverflowEvent + } + 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, ErrIntOverflowEvent + } + 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, ErrIntOverflowEvent + } + 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, ErrInvalidLengthEvent + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvent + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvent + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvent = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvent = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvent = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/migration/types/morse_account_state.go b/x/migration/types/morse_account_state.go new file mode 100644 index 000000000..d1a9763fa --- /dev/null +++ b/x/migration/types/morse_account_state.go @@ -0,0 +1,17 @@ +package types + +import ( + "crypto/sha256" + + "github.com/cosmos/gogoproto/proto" +) + +func (m MorseAccountState) GetHash() ([]byte, error) { + accountStateBz, err := proto.Marshal(&m) + if err != nil { + return nil, err + } + + hash := sha256.Sum256(accountStateBz) + return hash[:], nil +} From 7c42e218e0a10b032f54792edd6de8a90b3edeee Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 29 Jan 2025 15:46:38 +0100 Subject: [PATCH 03/12] fix: typo --- api/poktroll/migration/event.pulsar.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/poktroll/migration/event.pulsar.go b/api/poktroll/migration/event.pulsar.go index 07c371df5..c9cfc5543 100644 --- a/api/poktroll/migration/event.pulsar.go +++ b/api/poktroll/migration/event.pulsar.go @@ -3,12 +3,11 @@ package migration import ( _ "cosmossdk.io/api/cosmos/base/v1beta1" + _ "github.com/pokt-network/poktroll/api/poktroll/shared" fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" - _ "github.com/pokt-network/poktroll/api/poktroll/shared" - prot protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" From 1add213d65ce2d12aa3842ceb2a37f9c8d3db9f3 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 29 Jan 2025 16:41:20 +0100 Subject: [PATCH 04/12] chore: comments --- testutil/testmigration/fixtures.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/testutil/testmigration/fixtures.go b/testutil/testmigration/fixtures.go index e360f593d..fb36d92ba 100644 --- a/testutil/testmigration/fixtures.go +++ b/testutil/testmigration/fixtures.go @@ -15,7 +15,10 @@ import ( migrationtypes "github.com/pokt-network/poktroll/x/migration/types" ) -// TODO_IN_THIS_COMMIT: godoc... +// NewMorseStateExportAndAccountStateBytes returns a serialized `MorseStateExport` +// and its corresponding `MorseAccountState`, populated dynamically with randomized +// account addresses, and monotonically increasing balances/stakes. For each account, +// one application and supplier are also added to the states. // TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture. func NewMorseStateExportAndAccountStateBytes( t gocuke.TestingT, @@ -33,7 +36,10 @@ func NewMorseStateExportAndAccountStateBytes( return morseStateExportBz, morseAccountStateBz } -// TODO_IN_THIS_COMMIT: godoc... +// NewMorseStateExportAndAccountState returns a `MorseStateExport` and its +// corresponding `MorseAccountState`, populated dynamically with randomized +// account addresses, and monotonically increasing balances/stakes. For each account, +// one application and supplier are also added to the states. func NewMorseStateExportAndAccountState( t gocuke.TestingT, numAccounts int, ) (export *migrationtypes.MorseStateExport, state *migrationtypes.MorseAccountState) { From dad4fe4ecd75fcf1ff854d1d21f429afbeeb5d07 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 3 Feb 2025 16:56:03 +0100 Subject: [PATCH 05/12] chore: improvements --- .../keeper/msg_server_morse_account_state.go | 5 ++- .../msg_server_morse_account_state_test.go | 22 +++++++----- x/migration/types/errors.go | 4 +-- .../types/messages_morse_account_state.go | 34 +++++++++++++------ .../messages_morse_account_state_test.go | 7 ++-- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/x/migration/keeper/msg_server_morse_account_state.go b/x/migration/keeper/msg_server_morse_account_state.go index 408e382ce..c95f05946 100644 --- a/x/migration/keeper/msg_server_morse_account_state.go +++ b/x/migration/keeper/msg_server_morse_account_state.go @@ -34,7 +34,10 @@ func (k msgServer) CreateMorseAccountState(ctx context.Context, msg *types.MsgCr stateHash, err := msg.MorseAccountState.GetHash() if err != nil { - return nil, err + return nil, status.Error( + codes.Internal, + err.Error(), + ) } if err = sdkCtx.EventManager().EmitTypedEvent( diff --git a/x/migration/keeper/msg_server_morse_account_state_test.go b/x/migration/keeper/msg_server_morse_account_state_test.go index a4f811b48..ae4f17fdf 100644 --- a/x/migration/keeper/msg_server_morse_account_state_test.go +++ b/x/migration/keeper/msg_server_morse_account_state_test.go @@ -27,10 +27,13 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { _, isFound := k.GetMorseAccountState(ctx) require.False(t, isFound) - res, err := srv.CreateMorseAccountState(ctx, &migrationtypes.MsgCreateMorseAccountState{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - MorseAccountState: *accountState, - }) + msgCreateMorseAccountState, err := migrationtypes.NewMsgCreateMorseAccountState( + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + *accountState, + ) + require.NoError(t, err) + + res, err := srv.CreateMorseAccountState(ctx, msgCreateMorseAccountState) require.NoError(t, err) expectedUploadMsg := &migrationtypes.MsgCreateMorseAccountState{ @@ -81,12 +84,13 @@ func TestMorseAccountStateMsgServerCreate_Error(t *testing.T) { require.True(t, isFound) // Assert that the MorseAccountState can ONLY be set once. - _, err := srv.CreateMorseAccountState(ctx, &migrationtypes.MsgCreateMorseAccountState{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - MorseAccountState: *accountState, - }) - t.Log(err) + msgCreateMorseAccountState, err := migrationtypes.NewMsgCreateMorseAccountState( + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + *accountState, + ) + require.NoError(t, err) + _, err = srv.CreateMorseAccountState(ctx, msgCreateMorseAccountState) stat := status.Convert(err) require.Equal(t, codes.FailedPrecondition, stat.Code()) require.ErrorContains(t, err, "already set") diff --git a/x/migration/types/errors.go b/x/migration/types/errors.go index ca50b521e..e7889ff78 100644 --- a/x/migration/types/errors.go +++ b/x/migration/types/errors.go @@ -8,6 +8,6 @@ import ( // x/migration module sentinel errors var ( - ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") - ErrSample = sdkerrors.Register(ModuleName, 1101, "sample error") + ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") + ErrMorseAccountState = sdkerrors.Register(ModuleName, 1101, "morse account state is invalid") ) diff --git a/x/migration/types/messages_morse_account_state.go b/x/migration/types/messages_morse_account_state.go index 75cce1c4a..fe8b1fd36 100644 --- a/x/migration/types/messages_morse_account_state.go +++ b/x/migration/types/messages_morse_account_state.go @@ -3,18 +3,26 @@ package types import ( "bytes" - "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) var _ sdk.Msg = &MsgCreateMorseAccountState{} -func NewMsgCreateMorseAccountState(authority string, morseAccountState MorseAccountState) *MsgCreateMorseAccountState { - return &MsgCreateMorseAccountState{ - Authority: authority, - MorseAccountState: morseAccountState, +func NewMsgCreateMorseAccountState( + authority string, + morseAccountState MorseAccountState, +) (*MsgCreateMorseAccountState, error) { + morseAccountStateHash, err := morseAccountState.GetHash() + if err != nil { + return nil, err } + + return &MsgCreateMorseAccountState{ + Authority: authority, + MorseAccountState: morseAccountState, + MorseAccountStateHash: morseAccountStateHash, + }, nil } func (msg *MsgCreateMorseAccountState) ValidateBasic() error { @@ -28,12 +36,16 @@ func (msg *MsgCreateMorseAccountState) ValidateBasic() error { } expectedHash := msg.GetMorseAccountStateHash() - if bytes.Equal(actualHash, expectedHash) { - return nil + if len(expectedHash) == 0 { + return ErrMorseAccountState.Wrapf("expected hash is empty") + } + + if !bytes.Equal(actualHash, expectedHash) { + return ErrMorseAccountState.Wrapf( + "Morse account state hash (%x) doesn't match expected: (%x)", + actualHash, expectedHash, + ) } - return types.ErrInvalidRequest.Wrapf( - "Morse account state hash (%s) doesn't match expected: (%s)", - actualHash, expectedHash, - ) + return nil } diff --git a/x/migration/types/messages_morse_account_state_test.go b/x/migration/types/messages_morse_account_state_test.go index f877b22a5..db13b0e62 100644 --- a/x/migration/types/messages_morse_account_state_test.go +++ b/x/migration/types/messages_morse_account_state_test.go @@ -10,6 +10,9 @@ import ( ) func TestMsgCreateMorseAccountState_ValidateBasic(t *testing.T) { + validMsg, err := NewMsgCreateMorseAccountState(sample.AccAddress(), MorseAccountState{}) + require.NoError(t, err) + tests := []struct { name string msg MsgCreateMorseAccountState @@ -23,9 +26,7 @@ func TestMsgCreateMorseAccountState_ValidateBasic(t *testing.T) { err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", - msg: MsgCreateMorseAccountState{ - Authority: sample.AccAddress(), - }, + msg: *validMsg, }, } for _, tt := range tests { From e0a6d4be37d158d942a163e18ead9b16c5546b27 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 3 Feb 2025 17:00:37 +0100 Subject: [PATCH 06/12] chore: review feedback improvements Co-authored-by: Daniel Olshansky --- testutil/testmigration/fixtures.go | 27 +++++++++++++------ .../keeper/msg_server_morse_account_state.go | 5 +++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/testutil/testmigration/fixtures.go b/testutil/testmigration/fixtures.go index fb36d92ba..f116816e7 100644 --- a/testutil/testmigration/fixtures.go +++ b/testutil/testmigration/fixtures.go @@ -15,10 +15,16 @@ import ( migrationtypes "github.com/pokt-network/poktroll/x/migration/types" ) -// NewMorseStateExportAndAccountStateBytes returns a serialized `MorseStateExport` -// and its corresponding `MorseAccountState`, populated dynamically with randomized -// account addresses, and monotonically increasing balances/stakes. For each account, -// one application and supplier are also added to the states. +// NewMorseStateExportAndAccountStateBytes returns: +// - A serialized MorseStateExport +// - Its corresponding MorseAccountState +// +// The states are populated with: +// - Random account addresses +// - Monotonically increasing balances/stakes +// - One application per account +// - One supplier per account +// // TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture. func NewMorseStateExportAndAccountStateBytes( t gocuke.TestingT, @@ -36,10 +42,15 @@ func NewMorseStateExportAndAccountStateBytes( return morseStateExportBz, morseAccountStateBz } -// NewMorseStateExportAndAccountState returns a `MorseStateExport` and its -// corresponding `MorseAccountState`, populated dynamically with randomized -// account addresses, and monotonically increasing balances/stakes. For each account, -// one application and supplier are also added to the states. +// NewMorseStateExportAndAccountState returns MorseStateExport and MorseAccountState +// structs populated with: +// - Random account addresses +// - Monotonically increasing balances/stakes +// - One application per account +// - One supplier per account +func NewMorseStateExportAndAccountState( + t gocuke.TestingT, numAccounts int, +) (*types.MorseStateExport, *types.MorseAccountState) func NewMorseStateExportAndAccountState( t gocuke.TestingT, numAccounts int, ) (export *migrationtypes.MorseStateExport, state *migrationtypes.MorseAccountState) { diff --git a/x/migration/keeper/msg_server_morse_account_state.go b/x/migration/keeper/msg_server_morse_account_state.go index c95f05946..849919b62 100644 --- a/x/migration/keeper/msg_server_morse_account_state.go +++ b/x/migration/keeper/msg_server_morse_account_state.go @@ -12,7 +12,10 @@ import ( ) // CreateMorseAccountState creates the on-chain MorseAccountState ONLY ONCE (per network / re-genesis). -func (k msgServer) CreateMorseAccountState(ctx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) { +func (k msgServer) CreateMorseAccountState( + ctx context.Context, + msg *types.MsgCreateMorseAccountState +) (*types.MsgCreateMorseAccountStateResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) if err := msg.ValidateBasic(); err != nil { From 923373b28e0048b77736ac2756575a829fa56658 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 3 Feb 2025 17:37:13 +0100 Subject: [PATCH 07/12] chore: review improvements --- api/poktroll/migration/event.pulsar.go | 165 +++++++++--------- proto/poktroll/migration/event.proto | 8 +- testutil/testmigration/fixtures.go | 7 +- .../keeper/msg_server_morse_account_state.go | 6 +- .../msg_server_morse_account_state_test.go | 4 +- x/migration/types/event.pb.go | 93 +++++----- 6 files changed, 146 insertions(+), 137 deletions(-) diff --git a/api/poktroll/migration/event.pulsar.go b/api/poktroll/migration/event.pulsar.go index c9cfc5543..29f39b31e 100644 --- a/api/poktroll/migration/event.pulsar.go +++ b/api/poktroll/migration/event.pulsar.go @@ -3,11 +3,12 @@ package migration import ( _ "cosmossdk.io/api/cosmos/base/v1beta1" - _ "github.com/pokt-network/poktroll/api/poktroll/shared" fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" + _ "github.com/pokt-network/poktroll/api/poktroll/shared" + prot protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -17,16 +18,16 @@ import ( ) var ( - md_EventCreateMorseAccountState protoreflect.MessageDescriptor - fd_EventCreateMorseAccountState_height protoreflect.FieldDescriptor - fd_EventCreateMorseAccountState_state_hash protoreflect.FieldDescriptor + md_EventCreateMorseAccountState protoreflect.MessageDescriptor + fd_EventCreateMorseAccountState_created_at_height protoreflect.FieldDescriptor + fd_EventCreateMorseAccountState_morse_account_state_hash protoreflect.FieldDescriptor ) func init() { file_poktroll_migration_event_proto_init() md_EventCreateMorseAccountState = File_poktroll_migration_event_proto.Messages().ByName("EventCreateMorseAccountState") - fd_EventCreateMorseAccountState_height = md_EventCreateMorseAccountState.Fields().ByName("height") - fd_EventCreateMorseAccountState_state_hash = md_EventCreateMorseAccountState.Fields().ByName("state_hash") + fd_EventCreateMorseAccountState_created_at_height = md_EventCreateMorseAccountState.Fields().ByName("created_at_height") + fd_EventCreateMorseAccountState_morse_account_state_hash = md_EventCreateMorseAccountState.Fields().ByName("morse_account_state_hash") } var _ protoreflect.Message = (*fastReflection_EventCreateMorseAccountState)(nil) @@ -94,15 +95,15 @@ func (x *fastReflection_EventCreateMorseAccountState) Interface() protoreflect.P // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_EventCreateMorseAccountState) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Height != int64(0) { - value := protoreflect.ValueOfInt64(x.Height) - if !f(fd_EventCreateMorseAccountState_height, value) { + if x.CreatedAtHeight != int64(0) { + value := protoreflect.ValueOfInt64(x.CreatedAtHeight) + if !f(fd_EventCreateMorseAccountState_created_at_height, value) { return } } - if len(x.StateHash) != 0 { - value := protoreflect.ValueOfBytes(x.StateHash) - if !f(fd_EventCreateMorseAccountState_state_hash, value) { + if len(x.MorseAccountStateHash) != 0 { + value := protoreflect.ValueOfBytes(x.MorseAccountStateHash) + if !f(fd_EventCreateMorseAccountState_morse_account_state_hash, value) { return } } @@ -121,10 +122,10 @@ func (x *fastReflection_EventCreateMorseAccountState) Range(f func(protoreflect. // a repeated field is populated if it is non-empty. func (x *fastReflection_EventCreateMorseAccountState) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { - case "poktroll.migration.EventCreateMorseAccountState.height": - return x.Height != int64(0) - case "poktroll.migration.EventCreateMorseAccountState.state_hash": - return len(x.StateHash) != 0 + case "poktroll.migration.EventCreateMorseAccountState.created_at_height": + return x.CreatedAtHeight != int64(0) + case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": + return len(x.MorseAccountStateHash) != 0 default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -141,10 +142,10 @@ func (x *fastReflection_EventCreateMorseAccountState) Has(fd protoreflect.FieldD // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_EventCreateMorseAccountState) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { - case "poktroll.migration.EventCreateMorseAccountState.height": - x.Height = int64(0) - case "poktroll.migration.EventCreateMorseAccountState.state_hash": - x.StateHash = nil + case "poktroll.migration.EventCreateMorseAccountState.created_at_height": + x.CreatedAtHeight = int64(0) + case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": + x.MorseAccountStateHash = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -161,11 +162,11 @@ func (x *fastReflection_EventCreateMorseAccountState) Clear(fd protoreflect.Fiel // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_EventCreateMorseAccountState) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { - case "poktroll.migration.EventCreateMorseAccountState.height": - value := x.Height + case "poktroll.migration.EventCreateMorseAccountState.created_at_height": + value := x.CreatedAtHeight return protoreflect.ValueOfInt64(value) - case "poktroll.migration.EventCreateMorseAccountState.state_hash": - value := x.StateHash + case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": + value := x.MorseAccountStateHash return protoreflect.ValueOfBytes(value) default: if descriptor.IsExtension() { @@ -187,10 +188,10 @@ func (x *fastReflection_EventCreateMorseAccountState) Get(descriptor protoreflec // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_EventCreateMorseAccountState) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { - case "poktroll.migration.EventCreateMorseAccountState.height": - x.Height = value.Int() - case "poktroll.migration.EventCreateMorseAccountState.state_hash": - x.StateHash = value.Bytes() + case "poktroll.migration.EventCreateMorseAccountState.created_at_height": + x.CreatedAtHeight = value.Int() + case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": + x.MorseAccountStateHash = value.Bytes() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -211,10 +212,10 @@ func (x *fastReflection_EventCreateMorseAccountState) Set(fd protoreflect.FieldD // Mutable is a mutating operation and unsafe for concurrent use. func (x *fastReflection_EventCreateMorseAccountState) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "poktroll.migration.EventCreateMorseAccountState.height": - panic(fmt.Errorf("field height of message poktroll.migration.EventCreateMorseAccountState is not mutable")) - case "poktroll.migration.EventCreateMorseAccountState.state_hash": - panic(fmt.Errorf("field state_hash of message poktroll.migration.EventCreateMorseAccountState is not mutable")) + case "poktroll.migration.EventCreateMorseAccountState.created_at_height": + panic(fmt.Errorf("field created_at_height of message poktroll.migration.EventCreateMorseAccountState is not mutable")) + case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": + panic(fmt.Errorf("field morse_account_state_hash of message poktroll.migration.EventCreateMorseAccountState is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -228,9 +229,9 @@ func (x *fastReflection_EventCreateMorseAccountState) Mutable(fd protoreflect.Fi // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_EventCreateMorseAccountState) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "poktroll.migration.EventCreateMorseAccountState.height": + case "poktroll.migration.EventCreateMorseAccountState.created_at_height": return protoreflect.ValueOfInt64(int64(0)) - case "poktroll.migration.EventCreateMorseAccountState.state_hash": + case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": return protoreflect.ValueOfBytes(nil) default: if fd.IsExtension() { @@ -301,10 +302,10 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface var n int var l int _ = l - if x.Height != 0 { - n += 1 + runtime.Sov(uint64(x.Height)) + if x.CreatedAtHeight != 0 { + n += 1 + runtime.Sov(uint64(x.CreatedAtHeight)) } - l = len(x.StateHash) + l = len(x.MorseAccountStateHash) if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } @@ -337,15 +338,15 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if len(x.StateHash) > 0 { - i -= len(x.StateHash) - copy(dAtA[i:], x.StateHash) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.StateHash))) + if len(x.MorseAccountStateHash) > 0 { + i -= len(x.MorseAccountStateHash) + copy(dAtA[i:], x.MorseAccountStateHash) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.MorseAccountStateHash))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } - if x.Height != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.Height)) + if x.CreatedAtHeight != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.CreatedAtHeight)) i-- dAtA[i] = 0x8 } @@ -400,9 +401,9 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface switch fieldNum { case 1: if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) } - x.Height = 0 + x.CreatedAtHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow @@ -412,14 +413,14 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface } b := dAtA[iNdEx] iNdEx++ - x.Height |= int64(b&0x7F) << shift + x.CreatedAtHeight |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 3: + case 2: if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field StateHash", wireType) + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MorseAccountStateHash", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -446,9 +447,9 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface if postIndex > l { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } - x.StateHash = append(x.StateHash[:0], dAtA[iNdEx:postIndex]...) - if x.StateHash == nil { - x.StateHash = []byte{} + x.MorseAccountStateHash = append(x.MorseAccountStateHash[:0], dAtA[iNdEx:postIndex]...) + if x.MorseAccountStateHash == nil { + x.MorseAccountStateHash = []byte{} } iNdEx = postIndex default: @@ -499,14 +500,16 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// EventUploadMorseState is emitted when a new state hash is uploaded. +// EventUploadMorseState is emitted when the MorseAccountState is created on-chain. type EventCreateMorseAccountState struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` - StateHash []byte `protobuf:"bytes,3,opt,name=state_hash,json=stateHash,proto3" json:"state_hash,omitempty"` + // The height (on Shannon) at which the MorseAccountState was created on-chain. + CreatedAtHeight int64 `protobuf:"varint,1,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` + // The sha256 has of the MorseAccountState. + MorseAccountStateHash []byte `protobuf:"bytes,2,opt,name=morse_account_state_hash,json=morseAccountStateHash,proto3" json:"morse_account_state_hash,omitempty"` } func (x *EventCreateMorseAccountState) Reset() { @@ -529,16 +532,16 @@ func (*EventCreateMorseAccountState) Descriptor() ([]byte, []int) { return file_poktroll_migration_event_proto_rawDescGZIP(), []int{0} } -func (x *EventCreateMorseAccountState) GetHeight() int64 { +func (x *EventCreateMorseAccountState) GetCreatedAtHeight() int64 { if x != nil { - return x.Height + return x.CreatedAtHeight } return 0 } -func (x *EventCreateMorseAccountState) GetStateHash() []byte { +func (x *EventCreateMorseAccountState) GetMorseAccountStateHash() []byte { if x != nil { - return x.StateHash + return x.MorseAccountStateHash } return nil } @@ -558,26 +561,30 @@ var file_poktroll_migration_event_proto_rawDesc = []byte{ 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x71, 0x0a, 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x72, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x12, 0x22, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x03, 0x42, 0x0a, 0xea, 0xde, 0x1f, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, - 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x2d, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, - 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x0e, 0xea, 0xde, - 0x1f, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x52, 0x09, 0x73, 0x74, - 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x42, 0xb6, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x16, - 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x23, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, - 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, - 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x4d, 0x58, 0xaa, - 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x4d, 0x69, 0x67, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, - 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x1e, 0x50, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, - 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x50, 0x6f, 0x6b, - 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb8, 0x01, 0x0a, 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x72, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x41, 0x0a, 0x11, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x42, 0x15, 0xea, 0xde, 0x1f, 0x11, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, + 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x0f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x41, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x55, 0x0a, 0x18, 0x6d, 0x6f, 0x72, 0x73, + 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, + 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x1c, 0xea, 0xde, 0x1f, 0x18, + 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x52, 0x15, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x42, + 0xb6, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x23, 0x63, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x4d, 0x58, 0xaa, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x2e, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x12, 0x50, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0xe2, 0x02, 0x1e, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0xea, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/poktroll/migration/event.proto b/proto/poktroll/migration/event.proto index d1b9cc900..3bb863db7 100644 --- a/proto/poktroll/migration/event.proto +++ b/proto/poktroll/migration/event.proto @@ -11,8 +11,10 @@ import "cosmos/base/v1beta1/coin.proto"; import "poktroll/shared/service.proto"; import "poktroll/migration/types.proto"; -// EventUploadMorseState is emitted when a new state hash is uploaded. +// EventUploadMorseState is emitted when the MorseAccountState is created on-chain. message EventCreateMorseAccountState { - int64 height = 1 [(gogoproto.jsontag) = "height"]; - bytes state_hash = 3 [(gogoproto.jsontag) = "state_hash"]; + // The height (on Shannon) at which the MorseAccountState was created on-chain. + int64 created_at_height = 1 [(gogoproto.jsontag) = "created_at_height"]; + // The sha256 has of the MorseAccountState. + bytes morse_account_state_hash = 2 [(gogoproto.jsontag) = "morse_account_state_hash"]; } diff --git a/testutil/testmigration/fixtures.go b/testutil/testmigration/fixtures.go index f116816e7..363330be9 100644 --- a/testutil/testmigration/fixtures.go +++ b/testutil/testmigration/fixtures.go @@ -16,7 +16,7 @@ import ( ) // NewMorseStateExportAndAccountStateBytes returns: -// - A serialized MorseStateExport +// - A serialized MorseStateExport // - Its corresponding MorseAccountState // // The states are populated with: @@ -44,13 +44,10 @@ func NewMorseStateExportAndAccountStateBytes( // NewMorseStateExportAndAccountState returns MorseStateExport and MorseAccountState // structs populated with: -// - Random account addresses +// - Random account addresses // - Monotonically increasing balances/stakes // - One application per account // - One supplier per account -func NewMorseStateExportAndAccountState( - t gocuke.TestingT, numAccounts int, -) (*types.MorseStateExport, *types.MorseAccountState) func NewMorseStateExportAndAccountState( t gocuke.TestingT, numAccounts int, ) (export *migrationtypes.MorseStateExport, state *migrationtypes.MorseAccountState) { diff --git a/x/migration/keeper/msg_server_morse_account_state.go b/x/migration/keeper/msg_server_morse_account_state.go index 849919b62..1a1272a4f 100644 --- a/x/migration/keeper/msg_server_morse_account_state.go +++ b/x/migration/keeper/msg_server_morse_account_state.go @@ -14,7 +14,7 @@ import ( // CreateMorseAccountState creates the on-chain MorseAccountState ONLY ONCE (per network / re-genesis). func (k msgServer) CreateMorseAccountState( ctx context.Context, - msg *types.MsgCreateMorseAccountState + msg *types.MsgCreateMorseAccountState, ) (*types.MsgCreateMorseAccountStateResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) @@ -45,8 +45,8 @@ func (k msgServer) CreateMorseAccountState( if err = sdkCtx.EventManager().EmitTypedEvent( &types.EventCreateMorseAccountState{ - Height: sdkCtx.BlockHeight(), - StateHash: stateHash, + CreatedAtHeight: sdkCtx.BlockHeight(), + MorseAccountStateHash: stateHash, }, ); err != nil { return nil, err diff --git a/x/migration/keeper/msg_server_morse_account_state_test.go b/x/migration/keeper/msg_server_morse_account_state_test.go index ae4f17fdf..0b9152543 100644 --- a/x/migration/keeper/msg_server_morse_account_state_test.go +++ b/x/migration/keeper/msg_server_morse_account_state_test.go @@ -65,8 +65,8 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { require.Equal(t, 1, len(filteredEvts)) expectedEvent := &migrationtypes.EventCreateMorseAccountState{ - Height: ctx.BlockHeight(), - StateHash: expectedStateHash, + CreatedAtHeight: ctx.BlockHeight(), + MorseAccountStateHash: expectedStateHash, } require.Equal(t, expectedEvent, filteredEvts[0]) } diff --git a/x/migration/types/event.pb.go b/x/migration/types/event.pb.go index 4960740bc..d71342645 100644 --- a/x/migration/types/event.pb.go +++ b/x/migration/types/event.pb.go @@ -26,10 +26,12 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// EventUploadMorseState is emitted when a new state hash is uploaded. +// EventUploadMorseState is emitted when the MorseAccountState is created on-chain. type EventCreateMorseAccountState struct { - Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height"` - StateHash []byte `protobuf:"bytes,3,opt,name=state_hash,json=stateHash,proto3" json:"state_hash"` + // The height (on Shannon) at which the MorseAccountState was created on-chain. + CreatedAtHeight int64 `protobuf:"varint,1,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height"` + // The sha256 has of the MorseAccountState. + MorseAccountStateHash []byte `protobuf:"bytes,2,opt,name=morse_account_state_hash,json=morseAccountStateHash,proto3" json:"morse_account_state_hash"` } func (m *EventCreateMorseAccountState) Reset() { *m = EventCreateMorseAccountState{} } @@ -61,16 +63,16 @@ func (m *EventCreateMorseAccountState) XXX_DiscardUnknown() { var xxx_messageInfo_EventCreateMorseAccountState proto.InternalMessageInfo -func (m *EventCreateMorseAccountState) GetHeight() int64 { +func (m *EventCreateMorseAccountState) GetCreatedAtHeight() int64 { if m != nil { - return m.Height + return m.CreatedAtHeight } return 0 } -func (m *EventCreateMorseAccountState) GetStateHash() []byte { +func (m *EventCreateMorseAccountState) GetMorseAccountStateHash() []byte { if m != nil { - return m.StateHash + return m.MorseAccountStateHash } return nil } @@ -82,26 +84,27 @@ func init() { func init() { proto.RegisterFile("poktroll/migration/event.proto", fileDescriptor_d5b0bc9ed37905e1) } var fileDescriptor_d5b0bc9ed37905e1 = []byte{ - // 290 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x8f, 0xcf, 0x4a, 0x33, 0x31, - 0x14, 0xc5, 0x1b, 0x0a, 0x85, 0x2f, 0x7c, 0xb8, 0x18, 0x5c, 0xd4, 0xa2, 0x69, 0xe9, 0xaa, 0x9b, - 0x36, 0x54, 0x9f, 0xc0, 0x8a, 0xe0, 0x46, 0x90, 0xba, 0x73, 0x53, 0x32, 0xf1, 0x32, 0x09, 0x6d, - 0xe7, 0x8e, 0xc9, 0xed, 0xa8, 0x6f, 0xe1, 0x63, 0xb9, 0xec, 0xb2, 0xab, 0x22, 0x33, 0xbb, 0x3e, - 0x85, 0xcc, 0x9f, 0x0e, 0x22, 0xae, 0x72, 0x72, 0xce, 0x09, 0xf9, 0x1d, 0x2e, 0x12, 0x5c, 0x92, - 0xc3, 0xd5, 0x4a, 0xae, 0x6d, 0xe4, 0x14, 0x59, 0x8c, 0x25, 0xa4, 0x10, 0xd3, 0x24, 0x71, 0x48, - 0x18, 0x04, 0xc7, 0x7c, 0xd2, 0xe4, 0xbd, 0x33, 0x8d, 0x7e, 0x8d, 0x7e, 0x51, 0x36, 0x64, 0x75, - 0xa9, 0xea, 0xbd, 0xd3, 0x08, 0x23, 0xac, 0xfc, 0x42, 0xd5, 0xae, 0xa8, 0x3a, 0x32, 0x54, 0x1e, - 0x64, 0x3a, 0x0d, 0x81, 0xd4, 0x54, 0x6a, 0xb4, 0x71, 0x9d, 0x5f, 0x34, 0x10, 0xde, 0x28, 0x07, - 0xcf, 0xd2, 0x83, 0x4b, 0xad, 0x86, 0xe3, 0xf3, 0x3f, 0x18, 0xe9, 0x3d, 0x81, 0xfa, 0xd3, 0xe1, - 0x0b, 0x3f, 0xbf, 0x2d, 0x90, 0x6f, 0x1c, 0x28, 0x82, 0x7b, 0x74, 0x1e, 0xae, 0xb5, 0xc6, 0x4d, - 0x4c, 0x8f, 0xa4, 0x08, 0x82, 0x21, 0xef, 0x18, 0xb0, 0x91, 0xa1, 0x2e, 0x1b, 0xb0, 0x51, 0x7b, - 0xc6, 0x0f, 0xfb, 0x7e, 0xed, 0xcc, 0xeb, 0x33, 0x18, 0x73, 0xee, 0x8b, 0xf2, 0xc2, 0x28, 0x6f, - 0xba, 0xed, 0x01, 0x1b, 0xfd, 0x9f, 0x9d, 0x1c, 0xf6, 0xfd, 0x1f, 0xee, 0xfc, 0x5f, 0xa9, 0xef, - 0x94, 0x37, 0xb3, 0x87, 0xcf, 0x4c, 0xb0, 0x6d, 0x26, 0xd8, 0x2e, 0x13, 0xec, 0x2b, 0x13, 0xec, - 0x23, 0x17, 0xad, 0x6d, 0x2e, 0x5a, 0xbb, 0x5c, 0xb4, 0x9e, 0x2e, 0x23, 0x4b, 0x66, 0x13, 0x4e, - 0x34, 0xae, 0x65, 0xc1, 0x3e, 0x8e, 0x81, 0x5e, 0xd1, 0x2d, 0x65, 0x33, 0xe4, 0xed, 0xf7, 0x94, - 0xb0, 0x53, 0x6e, 0xb9, 0xfa, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x52, 0xd7, 0x04, 0x91, 0x01, - 0x00, 0x00, + // 315 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xcf, 0x4e, 0x32, 0x31, + 0x14, 0xc5, 0xe9, 0xf7, 0x25, 0x2e, 0x26, 0x26, 0xc6, 0x89, 0x24, 0x48, 0xb0, 0x10, 0x57, 0x6c, + 0xa4, 0x41, 0x9f, 0x00, 0x8c, 0x09, 0x1b, 0x13, 0x83, 0x71, 0xe3, 0x66, 0xd2, 0x29, 0x37, 0xd3, + 0x06, 0x66, 0x2e, 0x69, 0x2f, 0xa8, 0x6f, 0xe1, 0xe3, 0xf8, 0x08, 0x2e, 0x59, 0xb2, 0x22, 0x66, + 0xd8, 0xf1, 0x14, 0x66, 0xfe, 0x30, 0x0b, 0xd4, 0x5d, 0x7b, 0x7e, 0xa7, 0xa7, 0x27, 0xc7, 0xe3, + 0x73, 0x9c, 0x92, 0xc5, 0xd9, 0x4c, 0xc4, 0x26, 0xb2, 0x92, 0x0c, 0x26, 0x02, 0x96, 0x90, 0x50, + 0x6f, 0x6e, 0x91, 0xd0, 0xf7, 0xf7, 0xbc, 0x57, 0xf1, 0xe6, 0xb9, 0x42, 0x17, 0xa3, 0x0b, 0x72, + 0x87, 0x28, 0x2e, 0x85, 0xbd, 0x79, 0x16, 0x61, 0x84, 0x85, 0x9e, 0x9d, 0x4a, 0x95, 0x17, 0x1e, + 0x11, 0x4a, 0x07, 0x62, 0xd9, 0x0f, 0x81, 0x64, 0x5f, 0x28, 0x34, 0x49, 0xc9, 0x2f, 0xaa, 0x12, + 0x4e, 0x4b, 0x0b, 0x13, 0xe1, 0xc0, 0x2e, 0x8d, 0x82, 0xfd, 0xf3, 0x5f, 0x3a, 0xd2, 0xdb, 0x1c, + 0xca, 0x4f, 0x2f, 0x3f, 0x98, 0xd7, 0xba, 0xcb, 0x3a, 0xdf, 0x5a, 0x90, 0x04, 0xf7, 0x68, 0x1d, + 0x0c, 0x94, 0xc2, 0x45, 0x42, 0x8f, 0x24, 0x09, 0xfc, 0x81, 0x77, 0xaa, 0x72, 0x34, 0x09, 0x24, + 0x05, 0x1a, 0x4c, 0xa4, 0xa9, 0xc1, 0x3a, 0xac, 0xfb, 0x7f, 0x58, 0xdf, 0x6d, 0xda, 0x3f, 0xe1, + 0xf8, 0xa4, 0x94, 0x06, 0x34, 0xca, 0x05, 0xff, 0xc9, 0x6b, 0xc4, 0x59, 0x6e, 0x20, 0x8b, 0xe0, + 0xc0, 0x65, 0xc9, 0x81, 0x96, 0x4e, 0x37, 0xfe, 0x75, 0x58, 0xf7, 0x78, 0xd8, 0xda, 0x6d, 0xda, + 0x7f, 0x7a, 0xc6, 0xf5, 0xf8, 0xb0, 0xd5, 0x48, 0x3a, 0x3d, 0x7c, 0xf8, 0x4c, 0x39, 0x5b, 0xa5, + 0x9c, 0xad, 0x53, 0xce, 0xbe, 0x52, 0xce, 0xde, 0xb7, 0xbc, 0xb6, 0xda, 0xf2, 0xda, 0x7a, 0xcb, + 0x6b, 0xcf, 0xd7, 0x91, 0x21, 0xbd, 0x08, 0x7b, 0x0a, 0x63, 0x91, 0x6d, 0x70, 0x95, 0x00, 0xbd, + 0xa0, 0x9d, 0x8a, 0x6a, 0x90, 0xd7, 0xc3, 0x49, 0xc2, 0xa3, 0x7c, 0x93, 0x9b, 0xef, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xdb, 0x2d, 0xda, 0x9f, 0xd9, 0x01, 0x00, 0x00, } func (m *EventCreateMorseAccountState) Marshal() (dAtA []byte, err error) { @@ -124,15 +127,15 @@ func (m *EventCreateMorseAccountState) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l - if len(m.StateHash) > 0 { - i -= len(m.StateHash) - copy(dAtA[i:], m.StateHash) - i = encodeVarintEvent(dAtA, i, uint64(len(m.StateHash))) + if len(m.MorseAccountStateHash) > 0 { + i -= len(m.MorseAccountStateHash) + copy(dAtA[i:], m.MorseAccountStateHash) + i = encodeVarintEvent(dAtA, i, uint64(len(m.MorseAccountStateHash))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } - if m.Height != 0 { - i = encodeVarintEvent(dAtA, i, uint64(m.Height)) + if m.CreatedAtHeight != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.CreatedAtHeight)) i-- dAtA[i] = 0x8 } @@ -156,10 +159,10 @@ func (m *EventCreateMorseAccountState) Size() (n int) { } var l int _ = l - if m.Height != 0 { - n += 1 + sovEvent(uint64(m.Height)) + if m.CreatedAtHeight != 0 { + n += 1 + sovEvent(uint64(m.CreatedAtHeight)) } - l = len(m.StateHash) + l = len(m.MorseAccountStateHash) if l > 0 { n += 1 + l + sovEvent(uint64(l)) } @@ -203,9 +206,9 @@ func (m *EventCreateMorseAccountState) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CreatedAtHeight", wireType) } - m.Height = 0 + m.CreatedAtHeight = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -215,14 +218,14 @@ func (m *EventCreateMorseAccountState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Height |= int64(b&0x7F) << shift + m.CreatedAtHeight |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 3: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StateHash", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MorseAccountStateHash", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -249,9 +252,9 @@ func (m *EventCreateMorseAccountState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.StateHash = append(m.StateHash[:0], dAtA[iNdEx:postIndex]...) - if m.StateHash == nil { - m.StateHash = []byte{} + m.MorseAccountStateHash = append(m.MorseAccountStateHash[:0], dAtA[iNdEx:postIndex]...) + if m.MorseAccountStateHash == nil { + m.MorseAccountStateHash = []byte{} } iNdEx = postIndex default: From 1a314f1bfde58f07c7ddcf5360e349818f75e840 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 4 Feb 2025 12:56:02 +0100 Subject: [PATCH 08/12] chore: review improvements --- api/poktroll/migration/event.pulsar.go | 91 ++++++++++++++++--- proto/poktroll/migration/event.proto | 3 + .../keeper/msg_server_morse_account_state.go | 34 +++---- x/migration/types/event.pb.go | 81 ++++++++++++----- 4 files changed, 154 insertions(+), 55 deletions(-) diff --git a/api/poktroll/migration/event.pulsar.go b/api/poktroll/migration/event.pulsar.go index 29f39b31e..c8b4932a1 100644 --- a/api/poktroll/migration/event.pulsar.go +++ b/api/poktroll/migration/event.pulsar.go @@ -8,7 +8,6 @@ import ( runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" _ "github.com/pokt-network/poktroll/api/poktroll/shared" - prot protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -21,6 +20,7 @@ var ( md_EventCreateMorseAccountState protoreflect.MessageDescriptor fd_EventCreateMorseAccountState_created_at_height protoreflect.FieldDescriptor fd_EventCreateMorseAccountState_morse_account_state_hash protoreflect.FieldDescriptor + fd_EventCreateMorseAccountState_num_accounts protoreflect.FieldDescriptor ) func init() { @@ -28,6 +28,7 @@ func init() { md_EventCreateMorseAccountState = File_poktroll_migration_event_proto.Messages().ByName("EventCreateMorseAccountState") fd_EventCreateMorseAccountState_created_at_height = md_EventCreateMorseAccountState.Fields().ByName("created_at_height") fd_EventCreateMorseAccountState_morse_account_state_hash = md_EventCreateMorseAccountState.Fields().ByName("morse_account_state_hash") + fd_EventCreateMorseAccountState_num_accounts = md_EventCreateMorseAccountState.Fields().ByName("num_accounts") } var _ protoreflect.Message = (*fastReflection_EventCreateMorseAccountState)(nil) @@ -107,6 +108,12 @@ func (x *fastReflection_EventCreateMorseAccountState) Range(f func(protoreflect. return } } + if x.NumAccounts != uint64(0) { + value := protoreflect.ValueOfUint64(x.NumAccounts) + if !f(fd_EventCreateMorseAccountState_num_accounts, value) { + return + } + } } // Has reports whether a field is populated. @@ -126,6 +133,8 @@ func (x *fastReflection_EventCreateMorseAccountState) Has(fd protoreflect.FieldD return x.CreatedAtHeight != int64(0) case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": return len(x.MorseAccountStateHash) != 0 + case "poktroll.migration.EventCreateMorseAccountState.num_accounts": + return x.NumAccounts != uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -146,6 +155,8 @@ func (x *fastReflection_EventCreateMorseAccountState) Clear(fd protoreflect.Fiel x.CreatedAtHeight = int64(0) case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": x.MorseAccountStateHash = nil + case "poktroll.migration.EventCreateMorseAccountState.num_accounts": + x.NumAccounts = uint64(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -168,6 +179,9 @@ func (x *fastReflection_EventCreateMorseAccountState) Get(descriptor protoreflec case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": value := x.MorseAccountStateHash return protoreflect.ValueOfBytes(value) + case "poktroll.migration.EventCreateMorseAccountState.num_accounts": + value := x.NumAccounts + return protoreflect.ValueOfUint64(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -192,6 +206,8 @@ func (x *fastReflection_EventCreateMorseAccountState) Set(fd protoreflect.FieldD x.CreatedAtHeight = value.Int() case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": x.MorseAccountStateHash = value.Bytes() + case "poktroll.migration.EventCreateMorseAccountState.num_accounts": + x.NumAccounts = value.Uint() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -216,6 +232,8 @@ func (x *fastReflection_EventCreateMorseAccountState) Mutable(fd protoreflect.Fi panic(fmt.Errorf("field created_at_height of message poktroll.migration.EventCreateMorseAccountState is not mutable")) case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": panic(fmt.Errorf("field morse_account_state_hash of message poktroll.migration.EventCreateMorseAccountState is not mutable")) + case "poktroll.migration.EventCreateMorseAccountState.num_accounts": + panic(fmt.Errorf("field num_accounts of message poktroll.migration.EventCreateMorseAccountState is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -233,6 +251,8 @@ func (x *fastReflection_EventCreateMorseAccountState) NewField(fd protoreflect.F return protoreflect.ValueOfInt64(int64(0)) case "poktroll.migration.EventCreateMorseAccountState.morse_account_state_hash": return protoreflect.ValueOfBytes(nil) + case "poktroll.migration.EventCreateMorseAccountState.num_accounts": + return protoreflect.ValueOfUint64(uint64(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.migration.EventCreateMorseAccountState")) @@ -309,6 +329,9 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } + if x.NumAccounts != 0 { + n += 1 + runtime.Sov(uint64(x.NumAccounts)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -338,6 +361,11 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.NumAccounts != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.NumAccounts)) + i-- + dAtA[i] = 0x18 + } if len(x.MorseAccountStateHash) > 0 { i -= len(x.MorseAccountStateHash) copy(dAtA[i:], x.MorseAccountStateHash) @@ -452,6 +480,25 @@ func (x *fastReflection_EventCreateMorseAccountState) ProtoMethods() *protoiface x.MorseAccountStateHash = []byte{} } iNdEx = postIndex + case 3: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NumAccounts", wireType) + } + x.NumAccounts = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.NumAccounts |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -510,6 +557,9 @@ type EventCreateMorseAccountState struct { CreatedAtHeight int64 `protobuf:"varint,1,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height,omitempty"` // The sha256 has of the MorseAccountState. MorseAccountStateHash []byte `protobuf:"bytes,2,opt,name=morse_account_state_hash,json=morseAccountStateHash,proto3" json:"morse_account_state_hash,omitempty"` + // The number of accounts (EOAs) which were collected from the Morse state export, which may be claimed. + // NOTE: Application and supplier actor stakes are consolidated into their corresponding account balances. + NumAccounts uint64 `protobuf:"varint,3,opt,name=num_accounts,json=numAccounts,proto3" json:"num_accounts,omitempty"` } func (x *EventCreateMorseAccountState) Reset() { @@ -546,6 +596,13 @@ func (x *EventCreateMorseAccountState) GetMorseAccountStateHash() []byte { return nil } +func (x *EventCreateMorseAccountState) GetNumAccounts() uint64 { + if x != nil { + return x.NumAccounts + } + return 0 +} + var File_poktroll_migration_event_proto protoreflect.FileDescriptor var file_poktroll_migration_event_proto_rawDesc = []byte{ @@ -561,7 +618,7 @@ var file_poktroll_migration_event_proto_rawDesc = []byte{ 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb8, 0x01, 0x0a, 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xed, 0x01, 0x0a, 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x72, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x41, 0x0a, 0x11, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, @@ -572,19 +629,23 @@ var file_poktroll_migration_event_proto_rawDesc = []byte{ 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x1c, 0xea, 0xde, 0x1f, 0x18, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x52, 0x15, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x42, - 0xb6, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x23, 0x63, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x4d, 0x58, 0xaa, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, - 0x6c, 0x6c, 0x2e, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x12, 0x50, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0xe2, 0x02, 0x1e, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, - 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, + 0x33, 0x0a, 0x0c, 0x6e, 0x75, 0x6d, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x04, 0x42, 0x10, 0xea, 0xde, 0x1f, 0x0c, 0x6e, 0x75, 0x6d, 0x5f, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x0b, 0x6e, 0x75, 0x6d, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x73, 0x42, 0xb6, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, + 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x23, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x4d, 0x58, 0xaa, 0x02, 0x12, 0x50, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0xca, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x1e, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, + 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/poktroll/migration/event.proto b/proto/poktroll/migration/event.proto index 3bb863db7..dd701e6bc 100644 --- a/proto/poktroll/migration/event.proto +++ b/proto/poktroll/migration/event.proto @@ -17,4 +17,7 @@ message EventCreateMorseAccountState { int64 created_at_height = 1 [(gogoproto.jsontag) = "created_at_height"]; // The sha256 has of the MorseAccountState. bytes morse_account_state_hash = 2 [(gogoproto.jsontag) = "morse_account_state_hash"]; + // The number of accounts (EOAs) which were collected from the Morse state export, which may be claimed. + // NOTE: Application and supplier actor stakes are consolidated into their corresponding account balances. + uint64 num_accounts = 3 [(gogoproto.jsontag) = "num_accounts"]; } diff --git a/x/migration/keeper/msg_server_morse_account_state.go b/x/migration/keeper/msg_server_morse_account_state.go index 1a1272a4f..185ebc326 100644 --- a/x/migration/keeper/msg_server_morse_account_state.go +++ b/x/migration/keeper/msg_server_morse_account_state.go @@ -4,55 +4,51 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/pokt-network/poktroll/x/migration/types" + migrationtypes "github.com/pokt-network/poktroll/x/migration/types" ) // CreateMorseAccountState creates the on-chain MorseAccountState ONLY ONCE (per network / re-genesis). func (k msgServer) CreateMorseAccountState( ctx context.Context, - msg *types.MsgCreateMorseAccountState, -) (*types.MsgCreateMorseAccountStateResponse, error) { + msg *migrationtypes.MsgCreateMorseAccountState, +) (*migrationtypes.MsgCreateMorseAccountStateResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) + logger := sdkCtx.Logger().With("method", "CreateMorseAccountState") if err := msg.ValidateBasic(); err != nil { - return nil, err + logger.Info(err.Error()) + return nil, status.Error(codes.InvalidArgument, err.Error()) } // Check if the value already exists if _, isFound := k.GetMorseAccountState(sdkCtx); isFound { - return nil, status.Error( - codes.FailedPrecondition, - sdkerrors.ErrInvalidRequest.Wrap("already set").Error(), - ) + err := migrationtypes.ErrMorseAccountState.Wrap("already set") + logger.Info(err.Error()) + return nil, status.Error(codes.FailedPrecondition, err.Error()) } - k.SetMorseAccountState( - sdkCtx, - msg.MorseAccountState, - ) + k.SetMorseAccountState(sdkCtx, msg.MorseAccountState) stateHash, err := msg.MorseAccountState.GetHash() if err != nil { - return nil, status.Error( - codes.Internal, - err.Error(), - ) + logger.Info(err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } if err = sdkCtx.EventManager().EmitTypedEvent( - &types.EventCreateMorseAccountState{ + &migrationtypes.EventCreateMorseAccountState{ CreatedAtHeight: sdkCtx.BlockHeight(), MorseAccountStateHash: stateHash, }, ); err != nil { + logger.Info(err.Error()) return nil, err } - return &types.MsgCreateMorseAccountStateResponse{ + return &migrationtypes.MsgCreateMorseAccountStateResponse{ StateHash: stateHash, NumAccounts: uint64(len(msg.MorseAccountState.Accounts)), }, nil diff --git a/x/migration/types/event.pb.go b/x/migration/types/event.pb.go index d71342645..a71844632 100644 --- a/x/migration/types/event.pb.go +++ b/x/migration/types/event.pb.go @@ -32,6 +32,9 @@ type EventCreateMorseAccountState struct { CreatedAtHeight int64 `protobuf:"varint,1,opt,name=created_at_height,json=createdAtHeight,proto3" json:"created_at_height"` // The sha256 has of the MorseAccountState. MorseAccountStateHash []byte `protobuf:"bytes,2,opt,name=morse_account_state_hash,json=morseAccountStateHash,proto3" json:"morse_account_state_hash"` + // The number of accounts (EOAs) which were collected from the Morse state export, which may be claimed. + // NOTE: Application and supplier actor stakes are consolidated into their corresponding account balances. + NumAccounts uint64 `protobuf:"varint,3,opt,name=num_accounts,json=numAccounts,proto3" json:"num_accounts"` } func (m *EventCreateMorseAccountState) Reset() { *m = EventCreateMorseAccountState{} } @@ -77,6 +80,13 @@ func (m *EventCreateMorseAccountState) GetMorseAccountStateHash() []byte { return nil } +func (m *EventCreateMorseAccountState) GetNumAccounts() uint64 { + if m != nil { + return m.NumAccounts + } + return 0 +} + func init() { proto.RegisterType((*EventCreateMorseAccountState)(nil), "poktroll.migration.EventCreateMorseAccountState") } @@ -84,27 +94,29 @@ func init() { func init() { proto.RegisterFile("poktroll/migration/event.proto", fileDescriptor_d5b0bc9ed37905e1) } var fileDescriptor_d5b0bc9ed37905e1 = []byte{ - // 315 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xcf, 0x4e, 0x32, 0x31, - 0x14, 0xc5, 0xe9, 0xf7, 0x25, 0x2e, 0x26, 0x26, 0xc6, 0x89, 0x24, 0x48, 0xb0, 0x10, 0x57, 0x6c, - 0xa4, 0x41, 0x9f, 0x00, 0x8c, 0x09, 0x1b, 0x13, 0x83, 0x71, 0xe3, 0x66, 0xd2, 0x29, 0x37, 0xd3, - 0x06, 0x66, 0x2e, 0x69, 0x2f, 0xa8, 0x6f, 0xe1, 0xe3, 0xf8, 0x08, 0x2e, 0x59, 0xb2, 0x22, 0x66, - 0xd8, 0xf1, 0x14, 0x66, 0xfe, 0x30, 0x0b, 0xd4, 0x5d, 0x7b, 0x7e, 0xa7, 0xa7, 0x27, 0xc7, 0xe3, - 0x73, 0x9c, 0x92, 0xc5, 0xd9, 0x4c, 0xc4, 0x26, 0xb2, 0x92, 0x0c, 0x26, 0x02, 0x96, 0x90, 0x50, - 0x6f, 0x6e, 0x91, 0xd0, 0xf7, 0xf7, 0xbc, 0x57, 0xf1, 0xe6, 0xb9, 0x42, 0x17, 0xa3, 0x0b, 0x72, - 0x87, 0x28, 0x2e, 0x85, 0xbd, 0x79, 0x16, 0x61, 0x84, 0x85, 0x9e, 0x9d, 0x4a, 0x95, 0x17, 0x1e, - 0x11, 0x4a, 0x07, 0x62, 0xd9, 0x0f, 0x81, 0x64, 0x5f, 0x28, 0x34, 0x49, 0xc9, 0x2f, 0xaa, 0x12, - 0x4e, 0x4b, 0x0b, 0x13, 0xe1, 0xc0, 0x2e, 0x8d, 0x82, 0xfd, 0xf3, 0x5f, 0x3a, 0xd2, 0xdb, 0x1c, - 0xca, 0x4f, 0x2f, 0x3f, 0x98, 0xd7, 0xba, 0xcb, 0x3a, 0xdf, 0x5a, 0x90, 0x04, 0xf7, 0x68, 0x1d, - 0x0c, 0x94, 0xc2, 0x45, 0x42, 0x8f, 0x24, 0x09, 0xfc, 0x81, 0x77, 0xaa, 0x72, 0x34, 0x09, 0x24, - 0x05, 0x1a, 0x4c, 0xa4, 0xa9, 0xc1, 0x3a, 0xac, 0xfb, 0x7f, 0x58, 0xdf, 0x6d, 0xda, 0x3f, 0xe1, - 0xf8, 0xa4, 0x94, 0x06, 0x34, 0xca, 0x05, 0xff, 0xc9, 0x6b, 0xc4, 0x59, 0x6e, 0x20, 0x8b, 0xe0, - 0xc0, 0x65, 0xc9, 0x81, 0x96, 0x4e, 0x37, 0xfe, 0x75, 0x58, 0xf7, 0x78, 0xd8, 0xda, 0x6d, 0xda, - 0x7f, 0x7a, 0xc6, 0xf5, 0xf8, 0xb0, 0xd5, 0x48, 0x3a, 0x3d, 0x7c, 0xf8, 0x4c, 0x39, 0x5b, 0xa5, - 0x9c, 0xad, 0x53, 0xce, 0xbe, 0x52, 0xce, 0xde, 0xb7, 0xbc, 0xb6, 0xda, 0xf2, 0xda, 0x7a, 0xcb, - 0x6b, 0xcf, 0xd7, 0x91, 0x21, 0xbd, 0x08, 0x7b, 0x0a, 0x63, 0x91, 0x6d, 0x70, 0x95, 0x00, 0xbd, - 0xa0, 0x9d, 0x8a, 0x6a, 0x90, 0xd7, 0xc3, 0x49, 0xc2, 0xa3, 0x7c, 0x93, 0x9b, 0xef, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xdb, 0x2d, 0xda, 0x9f, 0xd9, 0x01, 0x00, 0x00, + // 337 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x50, 0x4d, 0x4b, 0x02, 0x41, + 0x18, 0x76, 0x32, 0x3a, 0x6c, 0x42, 0xb5, 0x24, 0x6c, 0x62, 0xa3, 0x74, 0xf2, 0x92, 0x83, 0xf9, + 0x0b, 0xdc, 0x08, 0xbc, 0x04, 0x61, 0x74, 0xe9, 0xb2, 0xcc, 0xae, 0x2f, 0xbb, 0x8b, 0xee, 0xbe, + 0x32, 0xf3, 0xae, 0xd5, 0xbf, 0xe8, 0x67, 0x75, 0xf4, 0xe8, 0x49, 0x62, 0xbd, 0x09, 0xfd, 0x87, + 0xd8, 0x0f, 0x85, 0xac, 0x6e, 0x33, 0xcf, 0xd7, 0xfb, 0xf0, 0x18, 0x7c, 0x86, 0x13, 0x52, 0x38, + 0x9d, 0x8a, 0x28, 0xf4, 0x95, 0xa4, 0x10, 0x63, 0x01, 0x73, 0x88, 0xa9, 0x3b, 0x53, 0x48, 0x68, + 0x9a, 0x5b, 0xbe, 0xbb, 0xe3, 0x1b, 0x17, 0x1e, 0xea, 0x08, 0xb5, 0x93, 0x2b, 0x44, 0xf1, 0x29, + 0xe4, 0x8d, 0x73, 0x1f, 0x7d, 0x2c, 0xf0, 0xec, 0x55, 0xa2, 0xbc, 0xd0, 0x08, 0x57, 0x6a, 0x10, + 0xf3, 0x9e, 0x0b, 0x24, 0x7b, 0xc2, 0xc3, 0x30, 0x2e, 0xf9, 0xcb, 0x5d, 0x09, 0x1d, 0x48, 0x05, + 0x63, 0xa1, 0x41, 0xcd, 0x43, 0x0f, 0xb6, 0xf6, 0x3f, 0x3a, 0xd2, 0xdb, 0x0c, 0xca, 0xa3, 0x57, + 0x5f, 0xcc, 0x68, 0xde, 0x65, 0x9d, 0x6f, 0x15, 0x48, 0x82, 0x7b, 0x54, 0x1a, 0x06, 0x9e, 0x87, + 0x49, 0x4c, 0x8f, 0x24, 0x09, 0xcc, 0x81, 0x71, 0xe6, 0xe5, 0xd4, 0xd8, 0x91, 0xe4, 0x04, 0x10, + 0xfa, 0x01, 0x59, 0xac, 0xcd, 0x3a, 0x55, 0xbb, 0xbe, 0x59, 0xb5, 0x7e, 0x93, 0xa3, 0x93, 0x12, + 0x1a, 0xd0, 0x30, 0x07, 0xcc, 0x27, 0xc3, 0x8a, 0xb2, 0x5c, 0x47, 0x16, 0xc1, 0x8e, 0xce, 0x92, + 0x9d, 0x40, 0xea, 0xc0, 0x3a, 0x68, 0xb3, 0x4e, 0xcd, 0x6e, 0x6e, 0x56, 0xad, 0x7f, 0x35, 0xa3, + 0x7a, 0xb4, 0xdf, 0x6a, 0x28, 0x75, 0x60, 0xf6, 0x8d, 0x5a, 0x9c, 0x44, 0x5b, 0x83, 0xb6, 0xaa, + 0x6d, 0xd6, 0x39, 0xb4, 0x4f, 0x37, 0xab, 0xd6, 0x0f, 0x7c, 0x74, 0x1c, 0x27, 0x51, 0x69, 0xd6, + 0xf6, 0xc3, 0x47, 0xca, 0xd9, 0x22, 0xe5, 0x6c, 0x99, 0x72, 0xf6, 0x99, 0x72, 0xf6, 0xbe, 0xe6, + 0x95, 0xc5, 0x9a, 0x57, 0x96, 0x6b, 0x5e, 0x79, 0xbe, 0xf1, 0x43, 0x0a, 0x12, 0xb7, 0xeb, 0x61, + 0x24, 0xb2, 0xe1, 0xae, 0x63, 0xa0, 0x17, 0x54, 0x13, 0xb1, 0x5b, 0xf1, 0x75, 0x7f, 0x47, 0xf7, + 0x28, 0x1f, 0xb2, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x60, 0x3c, 0xa1, 0x67, 0x0e, 0x02, 0x00, + 0x00, } func (m *EventCreateMorseAccountState) Marshal() (dAtA []byte, err error) { @@ -127,6 +139,11 @@ func (m *EventCreateMorseAccountState) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if m.NumAccounts != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.NumAccounts)) + i-- + dAtA[i] = 0x18 + } if len(m.MorseAccountStateHash) > 0 { i -= len(m.MorseAccountStateHash) copy(dAtA[i:], m.MorseAccountStateHash) @@ -166,6 +183,9 @@ func (m *EventCreateMorseAccountState) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } + if m.NumAccounts != 0 { + n += 1 + sovEvent(uint64(m.NumAccounts)) + } return n } @@ -257,6 +277,25 @@ func (m *EventCreateMorseAccountState) Unmarshal(dAtA []byte) error { m.MorseAccountStateHash = []byte{} } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NumAccounts", wireType) + } + m.NumAccounts = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NumAccounts |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipEvent(dAtA[iNdEx:]) From 3009a857d9fc75f5477703157cbe24063eae58a0 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 4 Feb 2025 14:19:37 +0100 Subject: [PATCH 09/12] fix: delete unused --- cmd/poktrolld/cmd/migrate/migrate_test.go | 88 ----------------------- 1 file changed, 88 deletions(-) diff --git a/cmd/poktrolld/cmd/migrate/migrate_test.go b/cmd/poktrolld/cmd/migrate/migrate_test.go index 3e26c507e..f6370a066 100644 --- a/cmd/poktrolld/cmd/migrate/migrate_test.go +++ b/cmd/poktrolld/cmd/migrate/migrate_test.go @@ -94,91 +94,3 @@ func BenchmarkTransformMorseState(b *testing.B) { }) } } - -// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture. -func newMorseStateExportAndAccountState( - t gocuke.TestingT, - numAccounts int, -) (morseStateExportBz []byte, morseAccountStateBz []byte) { - morseStateExport := &migrationtypes.MorseStateExport{ - AppHash: "", - AppState: &migrationtypes.MorseAppState{ - Application: &migrationtypes.MorseApplications{}, - Auth: &migrationtypes.MorseAuth{}, - Pos: &migrationtypes.MorsePos{}, - }, - } - - morseAccountState := &migrationtypes.MorseAccountState{ - Accounts: make([]*migrationtypes.MorseAccount, numAccounts), - } - - for i := 1; i < numAccounts+1; i++ { - seedUint := rand.Uint64() - seedBz := make([]byte, 8) - binary.LittleEndian.PutUint64(seedBz, seedUint) - privKey := cometcrypto.GenPrivKeyFromSecret(seedBz) - pubKey := privKey.PubKey() - balanceAmount := int64(1e6*i + i) // i_000_00i - appStakeAmount := int64(1e5*i + (i * 10)) // i00_0i0 - supplierStakeAmount := int64(1e4*i + (i * 100)) // i0_i00 - sumAmount := balanceAmount + appStakeAmount + supplierStakeAmount // i_ii0_iii - - // Add an account. - morseStateExport.AppState.Auth.Accounts = append( - morseStateExport.AppState.Auth.Accounts, - &migrationtypes.MorseAuthAccount{ - Type: "posmint/Account", - Value: &migrationtypes.MorseAccount{ - Address: pubKey.Address(), - Coins: cosmostypes.NewCoins(cosmostypes.NewInt64Coin(volatile.DenomuPOKT, balanceAmount)), - PubKey: &migrationtypes.MorsePublicKey{ - Value: pubKey.Bytes(), - }, - }, - }, - ) - - // Add an application. - morseStateExport.AppState.Application.Applications = append( - morseStateExport.AppState.Application.Applications, - &migrationtypes.MorseApplication{ - Address: pubKey.Address(), - PublicKey: pubKey.Bytes(), - Jailed: false, - Status: 2, - StakedTokens: fmt.Sprintf("%d", appStakeAmount), - }, - ) - - // Add a supplier. - morseStateExport.AppState.Pos.Validators = append( - morseStateExport.AppState.Pos.Validators, - &migrationtypes.MorseValidator{ - Address: pubKey.Address(), - PublicKey: pubKey.Bytes(), - Jailed: false, - Status: 2, - StakedTokens: fmt.Sprintf("%d", supplierStakeAmount), - }, - ) - - // Add the account to the morseAccountState. - morseAccountState.Accounts[i-1] = &migrationtypes.MorseAccount{ - Address: pubKey.Address(), - Coins: cosmostypes.NewCoins(cosmostypes.NewInt64Coin(volatile.DenomuPOKT, sumAmount)), - PubKey: &migrationtypes.MorsePublicKey{ - Value: pubKey.Bytes(), - }, - } - } - - var err error - morseStateExportBz, err = cmtjson.Marshal(morseStateExport) - require.NoError(t, err) - - morseAccountStateBz, err = cmtjson.Marshal(morseAccountState) - require.NoError(t, err) - - return morseStateExportBz, morseAccountStateBz -} From f7fc70a43dbde2b437ef48749203afaa0be6238b Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 4 Feb 2025 14:37:35 +0100 Subject: [PATCH 10/12] chore: review improvements --- x/migration/keeper/msg_server_morse_account_state.go | 1 + x/migration/keeper/msg_server_morse_account_state_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/x/migration/keeper/msg_server_morse_account_state.go b/x/migration/keeper/msg_server_morse_account_state.go index 185ebc326..e562138a7 100644 --- a/x/migration/keeper/msg_server_morse_account_state.go +++ b/x/migration/keeper/msg_server_morse_account_state.go @@ -42,6 +42,7 @@ func (k msgServer) CreateMorseAccountState( &migrationtypes.EventCreateMorseAccountState{ CreatedAtHeight: sdkCtx.BlockHeight(), MorseAccountStateHash: stateHash, + NumAccounts: uint64(len(msg.MorseAccountState.Accounts)), }, ); err != nil { logger.Info(err.Error()) diff --git a/x/migration/keeper/msg_server_morse_account_state_test.go b/x/migration/keeper/msg_server_morse_account_state_test.go index 0b9152543..65e7562c2 100644 --- a/x/migration/keeper/msg_server_morse_account_state_test.go +++ b/x/migration/keeper/msg_server_morse_account_state_test.go @@ -67,6 +67,7 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { expectedEvent := &migrationtypes.EventCreateMorseAccountState{ CreatedAtHeight: ctx.BlockHeight(), MorseAccountStateHash: expectedStateHash, + NumAccounts: uint64(numAccounts), } require.Equal(t, expectedEvent, filteredEvts[0]) } From e38baee5eee35466c663ebeb2f0eed33c3ddbc88 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Thu, 6 Feb 2025 14:50:17 +0100 Subject: [PATCH 11/12] fix: autocli --- x/migration/module/autocli.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/migration/module/autocli.go b/x/migration/module/autocli.go index ce8e01995..7bfa46165 100644 --- a/x/migration/module/autocli.go +++ b/x/migration/module/autocli.go @@ -23,9 +23,8 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { }, { RpcMethod: "MorseAccountState", - Use: "show-morse-account-state", + Use: "morse-account-state", Short: "show morse_account_state", - Skip: true, }, // this line is used by ignite scaffolding # autocli/query }, From 59cada21373cc86c6e8e2a93fbdb923777796045 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 10 Feb 2025 15:17:04 +0100 Subject: [PATCH 12/12] chore: review feedback improvements Co-authored-by: Daniel Olshansky --- api/poktroll/migration/event.pulsar.go | 62 +++++++++---------- proto/poktroll/migration/event.proto | 4 +- testutil/testmigration/fixtures.go | 12 ++-- .../msg_server_morse_account_state_test.go | 12 ++-- x/migration/types/event.pb.go | 46 +++++++------- .../types/messages_morse_account_state.go | 2 - 6 files changed, 72 insertions(+), 66 deletions(-) diff --git a/api/poktroll/migration/event.pulsar.go b/api/poktroll/migration/event.pulsar.go index c8b4932a1..5e22ebcfe 100644 --- a/api/poktroll/migration/event.pulsar.go +++ b/api/poktroll/migration/event.pulsar.go @@ -616,36 +616,36 @@ var file_poktroll_migration_event_proto_rawDesc = []byte{ 0x73, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, - 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xed, 0x01, 0x0a, 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x72, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x41, 0x0a, 0x11, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x5f, 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, - 0x42, 0x15, 0xea, 0xde, 0x1f, 0x11, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, - 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x0f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x41, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x55, 0x0a, 0x18, 0x6d, 0x6f, 0x72, 0x73, - 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, - 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x1c, 0xea, 0xde, 0x1f, 0x18, - 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x73, 0x74, - 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x52, 0x15, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, - 0x33, 0x0a, 0x0c, 0x6e, 0x75, 0x6d, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x04, 0x42, 0x10, 0xea, 0xde, 0x1f, 0x0c, 0x6e, 0x75, 0x6d, 0x5f, 0x61, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x0b, 0x6e, 0x75, 0x6d, 0x41, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x73, 0x42, 0xb6, 0x01, 0xd8, 0xe2, 0x1e, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, - 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, - 0x01, 0x5a, 0x23, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x4d, 0x58, 0xaa, 0x02, 0x12, 0x50, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0xca, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x1e, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, - 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, - 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x26, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x5f, 0x6f, + 0x6e, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xed, 0x01, 0x0a, + 0x1c, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x72, 0x73, + 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x41, 0x0a, + 0x11, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x15, 0xea, 0xde, 0x1f, 0x11, 0x63, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, + 0x0f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, + 0x12, 0x55, 0x0a, 0x18, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0c, 0x42, 0x1c, 0xea, 0xde, 0x1f, 0x18, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x5f, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, + 0x52, 0x15, 0x6d, 0x6f, 0x72, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, 0x33, 0x0a, 0x0c, 0x6e, 0x75, 0x6d, 0x5f, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x42, 0x10, 0xea, + 0xde, 0x1f, 0x0c, 0x6e, 0x75, 0x6d, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, + 0x0b, 0x6e, 0x75, 0x6d, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0xb6, 0x01, 0xd8, + 0xe2, 0x1e, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x2e, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x23, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, + 0x03, 0x50, 0x4d, 0x58, 0xaa, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, + 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x12, 0x50, 0x6f, 0x6b, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, + 0x1e, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, + 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x4d, 0x69, 0x67, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -677,7 +677,7 @@ func file_poktroll_migration_event_proto_init() { if File_poktroll_migration_event_proto != nil { return } - file_poktroll_migration_types_proto_init() + file_poktroll_migration_morse_onchain_proto_init() if !protoimpl.UnsafeEnabled { file_poktroll_migration_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*EventCreateMorseAccountState); i { diff --git a/proto/poktroll/migration/event.proto b/proto/poktroll/migration/event.proto index dd701e6bc..142abf6fc 100644 --- a/proto/poktroll/migration/event.proto +++ b/proto/poktroll/migration/event.proto @@ -9,14 +9,16 @@ import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; import "poktroll/shared/service.proto"; -import "poktroll/migration/types.proto"; +import "poktroll/migration/morse_onchain.proto"; // EventUploadMorseState is emitted when the MorseAccountState is created on-chain. message EventCreateMorseAccountState { // The height (on Shannon) at which the MorseAccountState was created on-chain. int64 created_at_height = 1 [(gogoproto.jsontag) = "created_at_height"]; + // The sha256 has of the MorseAccountState. bytes morse_account_state_hash = 2 [(gogoproto.jsontag) = "morse_account_state_hash"]; + // The number of accounts (EOAs) which were collected from the Morse state export, which may be claimed. // NOTE: Application and supplier actor stakes are consolidated into their corresponding account balances. uint64 num_accounts = 3 [(gogoproto.jsontag) = "num_accounts"]; diff --git a/testutil/testmigration/fixtures.go b/testutil/testmigration/fixtures.go index 363330be9..a9ee7f96a 100644 --- a/testutil/testmigration/fixtures.go +++ b/testutil/testmigration/fixtures.go @@ -16,16 +16,18 @@ import ( ) // NewMorseStateExportAndAccountStateBytes returns: -// - A serialized MorseStateExport -// - Its corresponding MorseAccountState +// - A serialized MorseStateExport. +// This is the JSON output of `pocket util export-genesis-for-reset`. +// It is used to generate the MorseAccountState. +// - Its corresponding MorseAccountState. +// This is the JSON output of `poktrolld migrate collect-morse-accounts`. +// It is used to persist the canonical Morse migration state from on Shannon. // // The states are populated with: // - Random account addresses // - Monotonically increasing balances/stakes // - One application per account // - One supplier per account -// -// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture. func NewMorseStateExportAndAccountStateBytes( t gocuke.TestingT, numAccounts int, @@ -55,7 +57,7 @@ func NewMorseStateExportAndAccountState( morseStateExport := &migrationtypes.MorseStateExport{ AppHash: "", - AppState: &migrationtypes.MorseAppState{ + AppState: &migrationtypes.MorseTendermintAppState{ Application: &migrationtypes.MorseApplications{}, Auth: &migrationtypes.MorseAuth{}, Pos: &migrationtypes.MorsePos{}, diff --git a/x/migration/keeper/msg_server_morse_account_state_test.go b/x/migration/keeper/msg_server_morse_account_state_test.go index 65e7562c2..5c45c28fa 100644 --- a/x/migration/keeper/msg_server_morse_account_state_test.go +++ b/x/migration/keeper/msg_server_morse_account_state_test.go @@ -27,6 +27,7 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { _, isFound := k.GetMorseAccountState(ctx) require.False(t, isFound) + // Create the on-chain MorseAccountState. msgCreateMorseAccountState, err := migrationtypes.NewMsgCreateMorseAccountState( authtypes.NewModuleAddress(govtypes.ModuleName).String(), *accountState, @@ -36,6 +37,7 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { res, err := srv.CreateMorseAccountState(ctx, msgCreateMorseAccountState) require.NoError(t, err) + // Assert that the response matches expectations. expectedUploadMsg := &migrationtypes.MsgCreateMorseAccountState{ Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), MorseAccountState: *accountState, @@ -51,15 +53,17 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { } require.Equal(t, expectedRes, res) - MorseAccountState, isFound := k.GetMorseAccountState(ctx) + // Assert that the MorseAccountState was created and matches expectations. + morseAccountState, isFound := k.GetMorseAccountState(ctx) require.True(t, isFound) require.NoError(t, err) - actualStateHash, err := MorseAccountState.GetHash() + actualStateHash, err := morseAccountState.GetHash() require.NoError(t, err) require.Equal(t, expectedRes.StateHash, actualStateHash) - require.Equal(t, int(expectedRes.NumAccounts), len(MorseAccountState.GetAccounts())) + require.Equal(t, int(expectedRes.NumAccounts), len(morseAccountState.GetAccounts())) + // Assert that the EventCreateMorseAccountState event was emitted. evts := ctx.EventManager().Events() filteredEvts := events.FilterEvents[*migrationtypes.EventCreateMorseAccountState](t, evts) require.Equal(t, 1, len(filteredEvts)) @@ -72,7 +76,7 @@ func TestMorseAccountStateMsgServerCreate_Success(t *testing.T) { require.Equal(t, expectedEvent, filteredEvts[0]) } -func TestMorseAccountStateMsgServerCreate_Error(t *testing.T) { +func TestMorseAccountStateMsgServerCreate_ErrorAlreadySet(t *testing.T) { k, ctx := keepertest.MigrationKeeper(t) srv := keeper.NewMsgServerImpl(k) diff --git a/x/migration/types/event.pb.go b/x/migration/types/event.pb.go index a71844632..7b37e6b2c 100644 --- a/x/migration/types/event.pb.go +++ b/x/migration/types/event.pb.go @@ -94,29 +94,29 @@ func init() { func init() { proto.RegisterFile("poktroll/migration/event.proto", fileDescriptor_d5b0bc9ed37905e1) } var fileDescriptor_d5b0bc9ed37905e1 = []byte{ - // 337 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x50, 0x4d, 0x4b, 0x02, 0x41, - 0x18, 0x76, 0x32, 0x3a, 0x6c, 0x42, 0xb5, 0x24, 0x6c, 0x62, 0xa3, 0x74, 0xf2, 0x92, 0x83, 0xf9, - 0x0b, 0xdc, 0x08, 0xbc, 0x04, 0x61, 0x74, 0xe9, 0xb2, 0xcc, 0xae, 0x2f, 0xbb, 0x8b, 0xee, 0xbe, - 0x32, 0xf3, 0xae, 0xd5, 0xbf, 0xe8, 0x67, 0x75, 0xf4, 0xe8, 0x49, 0x62, 0xbd, 0x09, 0xfd, 0x87, - 0xd8, 0x0f, 0x85, 0xac, 0x6e, 0x33, 0xcf, 0xd7, 0xfb, 0xf0, 0x18, 0x7c, 0x86, 0x13, 0x52, 0x38, - 0x9d, 0x8a, 0x28, 0xf4, 0x95, 0xa4, 0x10, 0x63, 0x01, 0x73, 0x88, 0xa9, 0x3b, 0x53, 0x48, 0x68, - 0x9a, 0x5b, 0xbe, 0xbb, 0xe3, 0x1b, 0x17, 0x1e, 0xea, 0x08, 0xb5, 0x93, 0x2b, 0x44, 0xf1, 0x29, - 0xe4, 0x8d, 0x73, 0x1f, 0x7d, 0x2c, 0xf0, 0xec, 0x55, 0xa2, 0xbc, 0xd0, 0x08, 0x57, 0x6a, 0x10, - 0xf3, 0x9e, 0x0b, 0x24, 0x7b, 0xc2, 0xc3, 0x30, 0x2e, 0xf9, 0xcb, 0x5d, 0x09, 0x1d, 0x48, 0x05, - 0x63, 0xa1, 0x41, 0xcd, 0x43, 0x0f, 0xb6, 0xf6, 0x3f, 0x3a, 0xd2, 0xdb, 0x0c, 0xca, 0xa3, 0x57, - 0x5f, 0xcc, 0x68, 0xde, 0x65, 0x9d, 0x6f, 0x15, 0x48, 0x82, 0x7b, 0x54, 0x1a, 0x06, 0x9e, 0x87, - 0x49, 0x4c, 0x8f, 0x24, 0x09, 0xcc, 0x81, 0x71, 0xe6, 0xe5, 0xd4, 0xd8, 0x91, 0xe4, 0x04, 0x10, - 0xfa, 0x01, 0x59, 0xac, 0xcd, 0x3a, 0x55, 0xbb, 0xbe, 0x59, 0xb5, 0x7e, 0x93, 0xa3, 0x93, 0x12, - 0x1a, 0xd0, 0x30, 0x07, 0xcc, 0x27, 0xc3, 0x8a, 0xb2, 0x5c, 0x47, 0x16, 0xc1, 0x8e, 0xce, 0x92, - 0x9d, 0x40, 0xea, 0xc0, 0x3a, 0x68, 0xb3, 0x4e, 0xcd, 0x6e, 0x6e, 0x56, 0xad, 0x7f, 0x35, 0xa3, - 0x7a, 0xb4, 0xdf, 0x6a, 0x28, 0x75, 0x60, 0xf6, 0x8d, 0x5a, 0x9c, 0x44, 0x5b, 0x83, 0xb6, 0xaa, - 0x6d, 0xd6, 0x39, 0xb4, 0x4f, 0x37, 0xab, 0xd6, 0x0f, 0x7c, 0x74, 0x1c, 0x27, 0x51, 0x69, 0xd6, - 0xf6, 0xc3, 0x47, 0xca, 0xd9, 0x22, 0xe5, 0x6c, 0x99, 0x72, 0xf6, 0x99, 0x72, 0xf6, 0xbe, 0xe6, - 0x95, 0xc5, 0x9a, 0x57, 0x96, 0x6b, 0x5e, 0x79, 0xbe, 0xf1, 0x43, 0x0a, 0x12, 0xb7, 0xeb, 0x61, - 0x24, 0xb2, 0xe1, 0xae, 0x63, 0xa0, 0x17, 0x54, 0x13, 0xb1, 0x5b, 0xf1, 0x75, 0x7f, 0x47, 0xf7, - 0x28, 0x1f, 0xb2, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x60, 0x3c, 0xa1, 0x67, 0x0e, 0x02, 0x00, - 0x00, + // 350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0xcd, 0x6a, 0x22, 0x41, + 0x14, 0x85, 0xad, 0x71, 0x98, 0x45, 0x8f, 0x30, 0x33, 0xcd, 0x08, 0x3d, 0xe2, 0x94, 0x92, 0x45, + 0x70, 0x13, 0x0b, 0xe3, 0x13, 0xd8, 0x21, 0xe0, 0x26, 0x10, 0x0c, 0xd9, 0x64, 0xd3, 0x54, 0x97, + 0x45, 0x57, 0xa3, 0x5d, 0x57, 0xaa, 0x6e, 0x9b, 0xe4, 0x2d, 0xf2, 0x58, 0x59, 0xba, 0x74, 0x25, + 0xa1, 0xdd, 0x09, 0x79, 0x87, 0xd0, 0x3f, 0x4a, 0x7e, 0x77, 0xdd, 0xe7, 0x3b, 0xf7, 0xd4, 0xe1, + 0x38, 0x74, 0x01, 0x33, 0x34, 0x30, 0x9f, 0xb3, 0x24, 0x8e, 0x0c, 0xc7, 0x18, 0x34, 0x93, 0x4b, + 0xa9, 0xb1, 0xbf, 0x30, 0x80, 0xe0, 0xba, 0x7b, 0xde, 0x3f, 0xf0, 0xd6, 0x3f, 0x01, 0x36, 0x01, + 0x1b, 0x14, 0x0e, 0x56, 0xfe, 0x94, 0xf6, 0xd6, 0xdf, 0x08, 0x22, 0x28, 0xf5, 0xfc, 0xab, 0x52, + 0x69, 0xe9, 0x61, 0x21, 0xb7, 0x92, 0x2d, 0x07, 0xa1, 0x44, 0x3e, 0x60, 0x02, 0x62, 0x5d, 0xf1, + 0xff, 0x87, 0x12, 0x56, 0x71, 0x23, 0xa7, 0xcc, 0x4a, 0xb3, 0x8c, 0x85, 0xac, 0xf0, 0xf1, 0x27, + 0x1d, 0x13, 0x30, 0x56, 0x06, 0xa0, 0x85, 0xe2, 0xfb, 0x98, 0xa3, 0x67, 0xe2, 0xb4, 0xcf, 0xf3, + 0xee, 0x67, 0x46, 0x72, 0x94, 0x17, 0xb9, 0x65, 0x24, 0x04, 0xa4, 0x1a, 0xaf, 0x90, 0xa3, 0x74, + 0x47, 0xce, 0x1f, 0x51, 0xa0, 0x69, 0xc0, 0x31, 0x50, 0x32, 0x8e, 0x14, 0x7a, 0xa4, 0x4b, 0x7a, + 0x75, 0xbf, 0xb9, 0xdb, 0x74, 0x3e, 0xc2, 0xc9, 0xaf, 0x4a, 0x1a, 0xe1, 0xb8, 0x10, 0xdc, 0x6b, + 0xc7, 0x2b, 0x9f, 0xe6, 0x65, 0x70, 0x60, 0xf3, 0xe4, 0x40, 0x71, 0xab, 0xbc, 0x6f, 0x5d, 0xd2, + 0x6b, 0xf8, 0xed, 0xdd, 0xa6, 0xf3, 0xa5, 0x67, 0xd2, 0x4c, 0xde, 0xb7, 0x1a, 0x73, 0xab, 0xdc, + 0xa1, 0xd3, 0xd0, 0x69, 0xb2, 0x3f, 0xb0, 0x5e, 0xbd, 0x4b, 0x7a, 0xdf, 0xfd, 0xdf, 0xbb, 0x4d, + 0xe7, 0x8d, 0x3e, 0xf9, 0xa9, 0xd3, 0xa4, 0x3a, 0xb6, 0xfe, 0xe5, 0x63, 0x46, 0xc9, 0x2a, 0xa3, + 0x64, 0x9d, 0x51, 0xf2, 0x94, 0x51, 0xf2, 0xb0, 0xa5, 0xb5, 0xd5, 0x96, 0xd6, 0xd6, 0x5b, 0x5a, + 0xbb, 0x39, 0x8d, 0x62, 0x54, 0x69, 0xd8, 0x17, 0x90, 0xb0, 0x7c, 0xc0, 0x13, 0x2d, 0xf1, 0x16, + 0xcc, 0x8c, 0x1d, 0xd6, 0xbc, 0x7b, 0xb5, 0x27, 0xde, 0x2f, 0xa4, 0x0d, 0x7f, 0x14, 0x43, 0x0e, + 0x5f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xca, 0xdd, 0x3d, 0xd8, 0x16, 0x02, 0x00, 0x00, } func (m *EventCreateMorseAccountState) Marshal() (dAtA []byte, err error) { diff --git a/x/migration/types/messages_morse_account_state.go b/x/migration/types/messages_morse_account_state.go index 2edd6b63e..fe8b1fd36 100644 --- a/x/migration/types/messages_morse_account_state.go +++ b/x/migration/types/messages_morse_account_state.go @@ -30,8 +30,6 @@ func (msg *MsgCreateMorseAccountState) ValidateBasic() error { return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address (%s)", err) } - // TODO_UPNEXT(@bryanchriswhite): add validation. - actualHash, err := msg.MorseAccountState.GetHash() if err != nil { return err