diff --git a/Makefile b/Makefile index a467c6b63..fa37c4515 100644 --- a/Makefile +++ b/Makefile @@ -186,11 +186,15 @@ warn_destructive: ## Print WARNING to the user proto_ignite_gen: ## Generate protobuf artifacts using ignite ignite generate proto-go --yes -.PHONY: proto_fix_self_import proto_fix_self_import: ## TODO_TECHDEBT(@bryanchriswhite): Add a proper explanation for this make target explaining why it's necessary + @echo "Updating all instances of cosmossdk.io/api/poktroll to github.com/pokt-network/poktroll/api/poktroll..." + @find ./api/poktroll/ -type f | while read -r file; do \ + echo "Processing file: $$file"; \ + $(SED) -i 's,cosmossdk.io/api/poktroll,github.com/pokt-network/poktroll/api/poktroll,g' "$$file"; \ + done @for dir in $(wildcard ./api/poktroll/*/); do \ module=$$(basename $$dir); \ - echo "Processing module $$module"; \ + echo "Further processing module $$module"; \ $(GREP) -lRP '\s+'$$module' "github.com/pokt-network/poktroll/api/poktroll/'$$module'"' ./api/poktroll/$$module | while read -r file; do \ echo "Modifying file: $$file"; \ $(SED) -i -E 's,^[[:space:]]+'$$module'[[:space:]]+"github.com/pokt-network/poktroll/api/poktroll/'$$module'",,' "$$file"; \ @@ -198,6 +202,7 @@ proto_fix_self_import: ## TODO_TECHDEBT(@bryanchriswhite): Add a proper explanat done; \ done + .PHONY: proto_clean proto_clean: ## Delete existing .pb.go or .pb.gw.go files find . \( -name "*.pb.go" -o -name "*.pb.gw.go" \) | xargs --no-run-if-empty rm @@ -337,7 +342,7 @@ load_test_simple: ## Runs the simplest load test through the whole stack (appgat # e.g. TODO_HACK: This is a hack, we need to fix it later # 2. If there's a specific issue, or specific person, add that in paranthesiss # e.g. TODO(@Olshansk): Automatically link to the Github user https://github.com/olshansk -# e.g. TODO_INVESTIGATE(#420): Automatically link this to github issue https://github.com/pokt-network/pocket/issues/420 +# e.g. TODO_INVESTIGATE(#420): Automatically link this to github issue https://github.com/pokt-network/poktroll/issues/420 # e.g. TODO_DISCUSS(@Olshansk, #420): Specific individual should tend to the action item in the specific ticket # e.g. TODO_CLEANUP(core): This is not tied to an issue, or a person, but should only be done by the core team. # e.g. TODO_CLEANUP: This is not tied to an issue, or a person, and can be done by the core team or external contributors. diff --git a/api/poktroll/application/event.pulsar.go b/api/poktroll/application/event.pulsar.go index 755da9625..6f5701306 100644 --- a/api/poktroll/application/event.pulsar.go +++ b/api/poktroll/application/event.pulsar.go @@ -5,7 +5,6 @@ import ( fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" - _ "github.com/cosmos/gogoproto/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -519,7 +518,6 @@ type EventRedelegation struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // TODO: Check if this tag is relevant for events: (gogoproto.jsontag) = "app_address" AppAddress string `protobuf:"bytes,1,opt,name=app_address,json=appAddress,proto3" json:"app_address,omitempty"` // The Bech32 address of the application, using cosmos' ScalarDescriptor to ensure deterministic encoding GatewayAddress string `protobuf:"bytes,2,opt,name=gateway_address,json=gatewayAddress,proto3" json:"gateway_address,omitempty"` // The Bech32 address of the gateway the application has changed their delegation of, using cosmos' ScalarDescriptor to ensure deterministic encoding } @@ -566,30 +564,28 @@ var file_poktroll_application_event_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x14, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 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, 0x22, 0x91, 0x01, 0x0a, 0x11, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x52, 0x65, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x39, 0x0a, 0x0b, 0x61, 0x70, 0x70, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x0a, - 0x61, 0x70, 0x70, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x67, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, - 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x0e, 0x67, - 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0xbe, 0x01, - 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, - 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x25, 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, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, - 0x02, 0x03, 0x50, 0x41, 0x58, 0xaa, 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, - 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x14, 0x50, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x20, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x41, - 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, - 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x15, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, - 0x6c, 0x3a, 0x3a, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x74, 0x6f, 0x22, 0x91, 0x01, 0x0a, 0x11, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x64, + 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x39, 0x0a, 0x0b, 0x61, 0x70, 0x70, + 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, + 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x0a, 0x61, 0x70, 0x70, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, + 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, + 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, + 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x0e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, + 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0xbe, 0x01, 0x0a, 0x18, 0x63, 0x6f, 0x6d, 0x2e, + 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x25, 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, 0x61, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x41, 0x58, 0xaa, + 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xca, 0x02, 0x14, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0xe2, 0x02, 0x20, + 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0xea, 0x02, 0x15, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/poktroll/service/service.pulsar.go b/api/poktroll/service/service.pulsar.go deleted file mode 100644 index e47fdeda9..000000000 --- a/api/poktroll/service/service.pulsar.go +++ /dev/null @@ -1,639 +0,0 @@ -// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. -package service - -import ( - fmt "fmt" - runtime "github.com/cosmos/cosmos-proto/runtime" - 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_Service protoreflect.MessageDescriptor - fd_Service_index protoreflect.FieldDescriptor - fd_Service_name protoreflect.FieldDescriptor -) - -func init() { - file_poktroll_service_service_proto_init() - md_Service = File_poktroll_service_service_proto.Messages().ByName("Service") - fd_Service_index = md_Service.Fields().ByName("index") - fd_Service_name = md_Service.Fields().ByName("name") -} - -var _ protoreflect.Message = (*fastReflection_Service)(nil) - -type fastReflection_Service Service - -func (x *Service) ProtoReflect() protoreflect.Message { - return (*fastReflection_Service)(x) -} - -func (x *Service) slowProtoReflect() protoreflect.Message { - mi := &file_poktroll_service_service_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_Service_messageType fastReflection_Service_messageType -var _ protoreflect.MessageType = fastReflection_Service_messageType{} - -type fastReflection_Service_messageType struct{} - -func (x fastReflection_Service_messageType) Zero() protoreflect.Message { - return (*fastReflection_Service)(nil) -} -func (x fastReflection_Service_messageType) New() protoreflect.Message { - return new(fastReflection_Service) -} -func (x fastReflection_Service_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_Service -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_Service) Descriptor() protoreflect.MessageDescriptor { - return md_Service -} - -// 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_Service) Type() protoreflect.MessageType { - return _fastReflection_Service_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_Service) New() protoreflect.Message { - return new(fastReflection_Service) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_Service) Interface() protoreflect.ProtoMessage { - return (*Service)(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_Service) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Index != "" { - value := protoreflect.ValueOfString(x.Index) - if !f(fd_Service_index, value) { - return - } - } - if x.Name != "" { - value := protoreflect.ValueOfString(x.Name) - if !f(fd_Service_name, 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_Service) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "poktroll.service.Service.index": - return x.Index != "" - case "poktroll.service.Service.name": - return x.Name != "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.service.Service")) - } - panic(fmt.Errorf("message poktroll.service.Service 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_Service) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "poktroll.service.Service.index": - x.Index = "" - case "poktroll.service.Service.name": - x.Name = "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.service.Service")) - } - panic(fmt.Errorf("message poktroll.service.Service 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_Service) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "poktroll.service.Service.index": - value := x.Index - return protoreflect.ValueOfString(value) - case "poktroll.service.Service.name": - value := x.Name - return protoreflect.ValueOfString(value) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.service.Service")) - } - panic(fmt.Errorf("message poktroll.service.Service 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_Service) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "poktroll.service.Service.index": - x.Index = value.Interface().(string) - case "poktroll.service.Service.name": - x.Name = value.Interface().(string) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.service.Service")) - } - panic(fmt.Errorf("message poktroll.service.Service 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_Service) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "poktroll.service.Service.index": - panic(fmt.Errorf("field index of message poktroll.service.Service is not mutable")) - case "poktroll.service.Service.name": - panic(fmt.Errorf("field name of message poktroll.service.Service is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.service.Service")) - } - panic(fmt.Errorf("message poktroll.service.Service 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_Service) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "poktroll.service.Service.index": - return protoreflect.ValueOfString("") - case "poktroll.service.Service.name": - return protoreflect.ValueOfString("") - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.service.Service")) - } - panic(fmt.Errorf("message poktroll.service.Service 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_Service) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in poktroll.service.Service", 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_Service) 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_Service) 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_Service) 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_Service) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*Service) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - l = len(x.Index) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - l = len(x.Name) - 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().(*Service) - 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.Name) > 0 { - i -= len(x.Name) - copy(dAtA[i:], x.Name) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Name))) - i-- - dAtA[i] = 0x12 - } - if len(x.Index) > 0 { - i -= len(x.Index) - copy(dAtA[i:], x.Index) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Index))) - i-- - dAtA[i] = 0xa - } - 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().(*Service) - 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: Service: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Service: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - var stringLen 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++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - 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.Index = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen 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++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - 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.Name = string(dAtA[iNdEx:postIndex]) - 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/service/service.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) -) - -type Service struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` -} - -func (x *Service) Reset() { - *x = Service{} - if protoimpl.UnsafeEnabled { - mi := &file_poktroll_service_service_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Service) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Service) ProtoMessage() {} - -// Deprecated: Use Service.ProtoReflect.Descriptor instead. -func (*Service) Descriptor() ([]byte, []int) { - return file_poktroll_service_service_proto_rawDescGZIP(), []int{0} -} - -func (x *Service) GetIndex() string { - if x != nil { - return x.Index - } - return "" -} - -func (x *Service) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -var File_poktroll_service_service_proto protoreflect.FileDescriptor - -var file_poktroll_service_service_proto_rawDesc = []byte{ - 0x0a, 0x1e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x10, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x22, 0x33, 0x0a, 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x14, 0x0a, - 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6e, - 0x64, 0x65, 0x78, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0xa8, 0x01, 0x0a, 0x14, 0x63, 0x6f, 0x6d, 0x2e, - 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x42, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, - 0x5a, 0x21, 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, 0x73, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0xa2, 0x02, 0x03, 0x50, 0x53, 0x58, 0xaa, 0x02, 0x10, 0x50, 0x6f, 0x6b, 0x74, - 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0xca, 0x02, 0x10, 0x50, - 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0xe2, - 0x02, 0x1c, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, - 0x11, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_poktroll_service_service_proto_rawDescOnce sync.Once - file_poktroll_service_service_proto_rawDescData = file_poktroll_service_service_proto_rawDesc -) - -func file_poktroll_service_service_proto_rawDescGZIP() []byte { - file_poktroll_service_service_proto_rawDescOnce.Do(func() { - file_poktroll_service_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_poktroll_service_service_proto_rawDescData) - }) - return file_poktroll_service_service_proto_rawDescData -} - -var file_poktroll_service_service_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_poktroll_service_service_proto_goTypes = []interface{}{ - (*Service)(nil), // 0: poktroll.service.Service -} -var file_poktroll_service_service_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_service_service_proto_init() } -func file_poktroll_service_service_proto_init() { - if File_poktroll_service_service_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_poktroll_service_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Service); 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_service_service_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_poktroll_service_service_proto_goTypes, - DependencyIndexes: file_poktroll_service_service_proto_depIdxs, - MessageInfos: file_poktroll_service_service_proto_msgTypes, - }.Build() - File_poktroll_service_service_proto = out.File - file_poktroll_service_service_proto_rawDesc = nil - file_poktroll_service_service_proto_goTypes = nil - file_poktroll_service_service_proto_depIdxs = nil -} diff --git a/api/poktroll/session/session.pulsar.go b/api/poktroll/session/session.pulsar.go index c0a424878..0baf919c8 100644 --- a/api/poktroll/session/session.pulsar.go +++ b/api/poktroll/session/session.pulsar.go @@ -19,8 +19,8 @@ var ( md_SessionHeader protoreflect.MessageDescriptor fd_SessionHeader_application_address protoreflect.FieldDescriptor fd_SessionHeader_service protoreflect.FieldDescriptor - fd_SessionHeader_session_start_block_height protoreflect.FieldDescriptor fd_SessionHeader_session_id protoreflect.FieldDescriptor + fd_SessionHeader_session_start_block_height protoreflect.FieldDescriptor fd_SessionHeader_session_end_block_height protoreflect.FieldDescriptor ) @@ -29,8 +29,8 @@ func init() { md_SessionHeader = File_poktroll_session_session_proto.Messages().ByName("SessionHeader") fd_SessionHeader_application_address = md_SessionHeader.Fields().ByName("application_address") fd_SessionHeader_service = md_SessionHeader.Fields().ByName("service") - fd_SessionHeader_session_start_block_height = md_SessionHeader.Fields().ByName("session_start_block_height") fd_SessionHeader_session_id = md_SessionHeader.Fields().ByName("session_id") + fd_SessionHeader_session_start_block_height = md_SessionHeader.Fields().ByName("session_start_block_height") fd_SessionHeader_session_end_block_height = md_SessionHeader.Fields().ByName("session_end_block_height") } @@ -111,18 +111,18 @@ func (x *fastReflection_SessionHeader) Range(f func(protoreflect.FieldDescriptor return } } - if x.SessionStartBlockHeight != int64(0) { - value := protoreflect.ValueOfInt64(x.SessionStartBlockHeight) - if !f(fd_SessionHeader_session_start_block_height, value) { - return - } - } if x.SessionId != "" { value := protoreflect.ValueOfString(x.SessionId) if !f(fd_SessionHeader_session_id, value) { return } } + if x.SessionStartBlockHeight != int64(0) { + value := protoreflect.ValueOfInt64(x.SessionStartBlockHeight) + if !f(fd_SessionHeader_session_start_block_height, value) { + return + } + } if x.SessionEndBlockHeight != int64(0) { value := protoreflect.ValueOfInt64(x.SessionEndBlockHeight) if !f(fd_SessionHeader_session_end_block_height, value) { @@ -148,10 +148,10 @@ func (x *fastReflection_SessionHeader) Has(fd protoreflect.FieldDescriptor) bool return x.ApplicationAddress != "" case "poktroll.session.SessionHeader.service": return x.Service != nil - case "poktroll.session.SessionHeader.session_start_block_height": - return x.SessionStartBlockHeight != int64(0) case "poktroll.session.SessionHeader.session_id": return x.SessionId != "" + case "poktroll.session.SessionHeader.session_start_block_height": + return x.SessionStartBlockHeight != int64(0) case "poktroll.session.SessionHeader.session_end_block_height": return x.SessionEndBlockHeight != int64(0) default: @@ -174,10 +174,10 @@ func (x *fastReflection_SessionHeader) Clear(fd protoreflect.FieldDescriptor) { x.ApplicationAddress = "" case "poktroll.session.SessionHeader.service": x.Service = nil - case "poktroll.session.SessionHeader.session_start_block_height": - x.SessionStartBlockHeight = int64(0) case "poktroll.session.SessionHeader.session_id": x.SessionId = "" + case "poktroll.session.SessionHeader.session_start_block_height": + x.SessionStartBlockHeight = int64(0) case "poktroll.session.SessionHeader.session_end_block_height": x.SessionEndBlockHeight = int64(0) default: @@ -202,12 +202,12 @@ func (x *fastReflection_SessionHeader) Get(descriptor protoreflect.FieldDescript case "poktroll.session.SessionHeader.service": value := x.Service return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "poktroll.session.SessionHeader.session_start_block_height": - value := x.SessionStartBlockHeight - return protoreflect.ValueOfInt64(value) case "poktroll.session.SessionHeader.session_id": value := x.SessionId return protoreflect.ValueOfString(value) + case "poktroll.session.SessionHeader.session_start_block_height": + value := x.SessionStartBlockHeight + return protoreflect.ValueOfInt64(value) case "poktroll.session.SessionHeader.session_end_block_height": value := x.SessionEndBlockHeight return protoreflect.ValueOfInt64(value) @@ -235,10 +235,10 @@ func (x *fastReflection_SessionHeader) Set(fd protoreflect.FieldDescriptor, valu x.ApplicationAddress = value.Interface().(string) case "poktroll.session.SessionHeader.service": x.Service = value.Message().Interface().(*shared.Service) - case "poktroll.session.SessionHeader.session_start_block_height": - x.SessionStartBlockHeight = value.Int() case "poktroll.session.SessionHeader.session_id": x.SessionId = value.Interface().(string) + case "poktroll.session.SessionHeader.session_start_block_height": + x.SessionStartBlockHeight = value.Int() case "poktroll.session.SessionHeader.session_end_block_height": x.SessionEndBlockHeight = value.Int() default: @@ -268,10 +268,10 @@ func (x *fastReflection_SessionHeader) Mutable(fd protoreflect.FieldDescriptor) return protoreflect.ValueOfMessage(x.Service.ProtoReflect()) case "poktroll.session.SessionHeader.application_address": panic(fmt.Errorf("field application_address of message poktroll.session.SessionHeader is not mutable")) - case "poktroll.session.SessionHeader.session_start_block_height": - panic(fmt.Errorf("field session_start_block_height of message poktroll.session.SessionHeader is not mutable")) case "poktroll.session.SessionHeader.session_id": panic(fmt.Errorf("field session_id of message poktroll.session.SessionHeader is not mutable")) + case "poktroll.session.SessionHeader.session_start_block_height": + panic(fmt.Errorf("field session_start_block_height of message poktroll.session.SessionHeader is not mutable")) case "poktroll.session.SessionHeader.session_end_block_height": panic(fmt.Errorf("field session_end_block_height of message poktroll.session.SessionHeader is not mutable")) default: @@ -292,10 +292,10 @@ func (x *fastReflection_SessionHeader) NewField(fd protoreflect.FieldDescriptor) case "poktroll.session.SessionHeader.service": m := new(shared.Service) return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "poktroll.session.SessionHeader.session_start_block_height": - return protoreflect.ValueOfInt64(int64(0)) case "poktroll.session.SessionHeader.session_id": return protoreflect.ValueOfString("") + case "poktroll.session.SessionHeader.session_start_block_height": + return protoreflect.ValueOfInt64(int64(0)) case "poktroll.session.SessionHeader.session_end_block_height": return protoreflect.ValueOfInt64(int64(0)) default: @@ -375,13 +375,13 @@ func (x *fastReflection_SessionHeader) ProtoMethods() *protoiface.Methods { l = options.Size(x.Service) n += 1 + l + runtime.Sov(uint64(l)) } - if x.SessionStartBlockHeight != 0 { - n += 1 + runtime.Sov(uint64(x.SessionStartBlockHeight)) - } l = len(x.SessionId) if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } + if x.SessionStartBlockHeight != 0 { + n += 1 + runtime.Sov(uint64(x.SessionStartBlockHeight)) + } if x.SessionEndBlockHeight != 0 { n += 1 + runtime.Sov(uint64(x.SessionEndBlockHeight)) } @@ -419,17 +419,17 @@ func (x *fastReflection_SessionHeader) ProtoMethods() *protoiface.Methods { i-- dAtA[i] = 0x28 } + if x.SessionStartBlockHeight != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.SessionStartBlockHeight)) + i-- + dAtA[i] = 0x20 + } if len(x.SessionId) > 0 { i -= len(x.SessionId) copy(dAtA[i:], x.SessionId) i = runtime.EncodeVarint(dAtA, i, uint64(len(x.SessionId))) i-- - dAtA[i] = 0x22 - } - if x.SessionStartBlockHeight != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.SessionStartBlockHeight)) - i-- - dAtA[i] = 0x18 + dAtA[i] = 0x1a } if x.Service != nil { encoded, err := options.Marshal(x.Service) @@ -570,25 +570,6 @@ func (x *fastReflection_SessionHeader) ProtoMethods() *protoiface.Methods { } iNdEx = postIndex case 3: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SessionStartBlockHeight", wireType) - } - x.SessionStartBlockHeight = 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.SessionStartBlockHeight |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SessionId", wireType) } @@ -620,6 +601,25 @@ func (x *fastReflection_SessionHeader) ProtoMethods() *protoiface.Methods { } x.SessionId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SessionStartBlockHeight", wireType) + } + x.SessionStartBlockHeight = 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.SessionStartBlockHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } case 5: if wireType != 0 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SessionEndBlockHeight", wireType) @@ -1506,12 +1506,15 @@ type SessionHeader struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ApplicationAddress string `protobuf:"bytes,1,opt,name=application_address,json=applicationAddress,proto3" json:"application_address,omitempty"` // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding - Service *shared.Service `protobuf:"bytes,2,opt,name=service,proto3" json:"service,omitempty"` // The service this session is for - SessionStartBlockHeight int64 `protobuf:"varint,3,opt,name=session_start_block_height,json=sessionStartBlockHeight,proto3" json:"session_start_block_height,omitempty"` // The height at which this session started + ApplicationAddress string `protobuf:"bytes,1,opt,name=application_address,json=applicationAddress,proto3" json:"application_address,omitempty"` // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding + Service *shared.Service `protobuf:"bytes,2,opt,name=service,proto3" json:"service,omitempty"` // The service this session is for // NOTE: session_id can be derived from the above values using on-chain but is included in the header for convenience - SessionId string `protobuf:"bytes,4,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` // A unique pseudoranom ID for this session - SessionEndBlockHeight int64 `protobuf:"varint,5,opt,name=session_end_block_height,json=sessionEndBlockHeight,proto3" json:"session_end_block_height,omitempty"` // The height at which this session ended, this is the last block of the session + SessionId string `protobuf:"bytes,3,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` // A unique pseudoranom ID for this session + SessionStartBlockHeight int64 `protobuf:"varint,4,opt,name=session_start_block_height,json=sessionStartBlockHeight,proto3" json:"session_start_block_height,omitempty"` // The height at which this session started + // TODO_BLOCKER: `session_end_block_height` is not required for the header because + // it is a derivative of `start` + `num_blocks_per_session` as goverened by on-chain + // params at the time of the session start. Could/should we remove it? + SessionEndBlockHeight int64 `protobuf:"varint,5,opt,name=session_end_block_height,json=sessionEndBlockHeight,proto3" json:"session_end_block_height,omitempty"` // The height at which this session ended, this is the last block of the session } func (x *SessionHeader) Reset() { @@ -1548,18 +1551,18 @@ func (x *SessionHeader) GetService() *shared.Service { return nil } -func (x *SessionHeader) GetSessionStartBlockHeight() int64 { +func (x *SessionHeader) GetSessionId() string { if x != nil { - return x.SessionStartBlockHeight + return x.SessionId } - return 0 + return "" } -func (x *SessionHeader) GetSessionId() string { +func (x *SessionHeader) GetSessionStartBlockHeight() int64 { if x != nil { - return x.SessionId + return x.SessionStartBlockHeight } - return "" + return 0 } func (x *SessionHeader) GetSessionEndBlockHeight() int64 { @@ -1669,13 +1672,13 @@ var file_poktroll_session_session_proto_rawDesc = []byte{ 0x73, 0x12, 0x32, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x07, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x1a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, - 0x67, 0x68, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x17, 0x73, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, - 0x68, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, - 0x64, 0x12, 0x37, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x65, 0x6e, 0x64, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x3b, 0x0a, 0x1a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, + 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x17, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, + 0x74, 0x12, 0x37, 0x0a, 0x18, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0xbb, 0x02, 0x0a, 0x07, 0x53, diff --git a/api/poktroll/tokenomics/event.pulsar.go b/api/poktroll/tokenomics/event.pulsar.go new file mode 100644 index 000000000..6873f6c95 --- /dev/null +++ b/api/poktroll/tokenomics/event.pulsar.go @@ -0,0 +1,1263 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package tokenomics + +import ( + proof "github.com/pokt-network/poktroll/api/poktroll/proof" + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + 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_EventClaimExpired protoreflect.MessageDescriptor + fd_EventClaimExpired_claim protoreflect.FieldDescriptor + fd_EventClaimExpired_compute_units protoreflect.FieldDescriptor +) + +func init() { + file_poktroll_tokenomics_event_proto_init() + md_EventClaimExpired = File_poktroll_tokenomics_event_proto.Messages().ByName("EventClaimExpired") + fd_EventClaimExpired_claim = md_EventClaimExpired.Fields().ByName("claim") + fd_EventClaimExpired_compute_units = md_EventClaimExpired.Fields().ByName("compute_units") +} + +var _ protoreflect.Message = (*fastReflection_EventClaimExpired)(nil) + +type fastReflection_EventClaimExpired EventClaimExpired + +func (x *EventClaimExpired) ProtoReflect() protoreflect.Message { + return (*fastReflection_EventClaimExpired)(x) +} + +func (x *EventClaimExpired) slowProtoReflect() protoreflect.Message { + mi := &file_poktroll_tokenomics_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_EventClaimExpired_messageType fastReflection_EventClaimExpired_messageType +var _ protoreflect.MessageType = fastReflection_EventClaimExpired_messageType{} + +type fastReflection_EventClaimExpired_messageType struct{} + +func (x fastReflection_EventClaimExpired_messageType) Zero() protoreflect.Message { + return (*fastReflection_EventClaimExpired)(nil) +} +func (x fastReflection_EventClaimExpired_messageType) New() protoreflect.Message { + return new(fastReflection_EventClaimExpired) +} +func (x fastReflection_EventClaimExpired_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_EventClaimExpired +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_EventClaimExpired) Descriptor() protoreflect.MessageDescriptor { + return md_EventClaimExpired +} + +// 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_EventClaimExpired) Type() protoreflect.MessageType { + return _fastReflection_EventClaimExpired_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_EventClaimExpired) New() protoreflect.Message { + return new(fastReflection_EventClaimExpired) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_EventClaimExpired) Interface() protoreflect.ProtoMessage { + return (*EventClaimExpired)(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_EventClaimExpired) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Claim != nil { + value := protoreflect.ValueOfMessage(x.Claim.ProtoReflect()) + if !f(fd_EventClaimExpired_claim, value) { + return + } + } + if x.ComputeUnits != uint64(0) { + value := protoreflect.ValueOfUint64(x.ComputeUnits) + if !f(fd_EventClaimExpired_compute_units, 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_EventClaimExpired) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimExpired.claim": + return x.Claim != nil + case "poktroll.tokenomics.EventClaimExpired.compute_units": + return x.ComputeUnits != uint64(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimExpired")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimExpired 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_EventClaimExpired) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimExpired.claim": + x.Claim = nil + case "poktroll.tokenomics.EventClaimExpired.compute_units": + x.ComputeUnits = uint64(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimExpired")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimExpired 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_EventClaimExpired) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "poktroll.tokenomics.EventClaimExpired.claim": + value := x.Claim + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "poktroll.tokenomics.EventClaimExpired.compute_units": + value := x.ComputeUnits + return protoreflect.ValueOfUint64(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimExpired")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimExpired 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_EventClaimExpired) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimExpired.claim": + x.Claim = value.Message().Interface().(*proof.Claim) + case "poktroll.tokenomics.EventClaimExpired.compute_units": + x.ComputeUnits = value.Uint() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimExpired")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimExpired 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_EventClaimExpired) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimExpired.claim": + if x.Claim == nil { + x.Claim = new(proof.Claim) + } + return protoreflect.ValueOfMessage(x.Claim.ProtoReflect()) + case "poktroll.tokenomics.EventClaimExpired.compute_units": + panic(fmt.Errorf("field compute_units of message poktroll.tokenomics.EventClaimExpired is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimExpired")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimExpired 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_EventClaimExpired) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimExpired.claim": + m := new(proof.Claim) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "poktroll.tokenomics.EventClaimExpired.compute_units": + return protoreflect.ValueOfUint64(uint64(0)) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimExpired")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimExpired 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_EventClaimExpired) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in poktroll.tokenomics.EventClaimExpired", 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_EventClaimExpired) 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_EventClaimExpired) 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_EventClaimExpired) 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_EventClaimExpired) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*EventClaimExpired) + 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.Claim != nil { + l = options.Size(x.Claim) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.ComputeUnits != 0 { + n += 1 + runtime.Sov(uint64(x.ComputeUnits)) + } + 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().(*EventClaimExpired) + 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 x.ComputeUnits != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.ComputeUnits)) + i-- + dAtA[i] = 0x10 + } + if x.Claim != nil { + encoded, err := options.Marshal(x.Claim) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0xa + } + 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().(*EventClaimExpired) + 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: EventClaimExpired: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EventClaimExpired: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Claim", wireType) + } + var msglen 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++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + 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 + } + if x.Claim == nil { + x.Claim = &proof.Claim{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Claim); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ComputeUnits", wireType) + } + x.ComputeUnits = 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.ComputeUnits |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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, + } +} + +var ( + md_EventClaimSettled protoreflect.MessageDescriptor + fd_EventClaimSettled_claim protoreflect.FieldDescriptor + fd_EventClaimSettled_compute_units protoreflect.FieldDescriptor + fd_EventClaimSettled_proof_required protoreflect.FieldDescriptor +) + +func init() { + file_poktroll_tokenomics_event_proto_init() + md_EventClaimSettled = File_poktroll_tokenomics_event_proto.Messages().ByName("EventClaimSettled") + fd_EventClaimSettled_claim = md_EventClaimSettled.Fields().ByName("claim") + fd_EventClaimSettled_compute_units = md_EventClaimSettled.Fields().ByName("compute_units") + fd_EventClaimSettled_proof_required = md_EventClaimSettled.Fields().ByName("proof_required") +} + +var _ protoreflect.Message = (*fastReflection_EventClaimSettled)(nil) + +type fastReflection_EventClaimSettled EventClaimSettled + +func (x *EventClaimSettled) ProtoReflect() protoreflect.Message { + return (*fastReflection_EventClaimSettled)(x) +} + +func (x *EventClaimSettled) slowProtoReflect() protoreflect.Message { + mi := &file_poktroll_tokenomics_event_proto_msgTypes[1] + 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_EventClaimSettled_messageType fastReflection_EventClaimSettled_messageType +var _ protoreflect.MessageType = fastReflection_EventClaimSettled_messageType{} + +type fastReflection_EventClaimSettled_messageType struct{} + +func (x fastReflection_EventClaimSettled_messageType) Zero() protoreflect.Message { + return (*fastReflection_EventClaimSettled)(nil) +} +func (x fastReflection_EventClaimSettled_messageType) New() protoreflect.Message { + return new(fastReflection_EventClaimSettled) +} +func (x fastReflection_EventClaimSettled_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_EventClaimSettled +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_EventClaimSettled) Descriptor() protoreflect.MessageDescriptor { + return md_EventClaimSettled +} + +// 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_EventClaimSettled) Type() protoreflect.MessageType { + return _fastReflection_EventClaimSettled_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_EventClaimSettled) New() protoreflect.Message { + return new(fastReflection_EventClaimSettled) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_EventClaimSettled) Interface() protoreflect.ProtoMessage { + return (*EventClaimSettled)(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_EventClaimSettled) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Claim != nil { + value := protoreflect.ValueOfMessage(x.Claim.ProtoReflect()) + if !f(fd_EventClaimSettled_claim, value) { + return + } + } + if x.ComputeUnits != uint64(0) { + value := protoreflect.ValueOfUint64(x.ComputeUnits) + if !f(fd_EventClaimSettled_compute_units, value) { + return + } + } + if x.ProofRequired != false { + value := protoreflect.ValueOfBool(x.ProofRequired) + if !f(fd_EventClaimSettled_proof_required, 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_EventClaimSettled) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimSettled.claim": + return x.Claim != nil + case "poktroll.tokenomics.EventClaimSettled.compute_units": + return x.ComputeUnits != uint64(0) + case "poktroll.tokenomics.EventClaimSettled.proof_required": + return x.ProofRequired != false + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimSettled")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimSettled 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_EventClaimSettled) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimSettled.claim": + x.Claim = nil + case "poktroll.tokenomics.EventClaimSettled.compute_units": + x.ComputeUnits = uint64(0) + case "poktroll.tokenomics.EventClaimSettled.proof_required": + x.ProofRequired = false + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimSettled")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimSettled 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_EventClaimSettled) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "poktroll.tokenomics.EventClaimSettled.claim": + value := x.Claim + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "poktroll.tokenomics.EventClaimSettled.compute_units": + value := x.ComputeUnits + return protoreflect.ValueOfUint64(value) + case "poktroll.tokenomics.EventClaimSettled.proof_required": + value := x.ProofRequired + return protoreflect.ValueOfBool(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimSettled")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimSettled 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_EventClaimSettled) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimSettled.claim": + x.Claim = value.Message().Interface().(*proof.Claim) + case "poktroll.tokenomics.EventClaimSettled.compute_units": + x.ComputeUnits = value.Uint() + case "poktroll.tokenomics.EventClaimSettled.proof_required": + x.ProofRequired = value.Bool() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimSettled")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimSettled 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_EventClaimSettled) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimSettled.claim": + if x.Claim == nil { + x.Claim = new(proof.Claim) + } + return protoreflect.ValueOfMessage(x.Claim.ProtoReflect()) + case "poktroll.tokenomics.EventClaimSettled.compute_units": + panic(fmt.Errorf("field compute_units of message poktroll.tokenomics.EventClaimSettled is not mutable")) + case "poktroll.tokenomics.EventClaimSettled.proof_required": + panic(fmt.Errorf("field proof_required of message poktroll.tokenomics.EventClaimSettled is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimSettled")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimSettled 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_EventClaimSettled) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "poktroll.tokenomics.EventClaimSettled.claim": + m := new(proof.Claim) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "poktroll.tokenomics.EventClaimSettled.compute_units": + return protoreflect.ValueOfUint64(uint64(0)) + case "poktroll.tokenomics.EventClaimSettled.proof_required": + return protoreflect.ValueOfBool(false) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: poktroll.tokenomics.EventClaimSettled")) + } + panic(fmt.Errorf("message poktroll.tokenomics.EventClaimSettled 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_EventClaimSettled) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in poktroll.tokenomics.EventClaimSettled", 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_EventClaimSettled) 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_EventClaimSettled) 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_EventClaimSettled) 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_EventClaimSettled) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*EventClaimSettled) + 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.Claim != nil { + l = options.Size(x.Claim) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.ComputeUnits != 0 { + n += 1 + runtime.Sov(uint64(x.ComputeUnits)) + } + if x.ProofRequired { + n += 2 + } + 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().(*EventClaimSettled) + 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 x.ProofRequired { + i-- + if x.ProofRequired { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if x.ComputeUnits != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.ComputeUnits)) + i-- + dAtA[i] = 0x10 + } + if x.Claim != nil { + encoded, err := options.Marshal(x.Claim) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0xa + } + 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().(*EventClaimSettled) + 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: EventClaimSettled: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EventClaimSettled: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Claim", wireType) + } + var msglen 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++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + 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 + } + if x.Claim == nil { + x.Claim = &proof.Claim{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Claim); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ComputeUnits", wireType) + } + x.ComputeUnits = 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.ComputeUnits |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ProofRequired", wireType) + } + var v 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++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.ProofRequired = bool(v != 0) + 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/tokenomics/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) +) + +// EventClaimExpired is an event emitted whenever a claim requiring an on-chain +// proof doesn't have one. The claim cannot be settled, leading to that work +// never being rewarded. +type EventClaimExpired struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Claim *proof.Claim `protobuf:"bytes,1,opt,name=claim,proto3" json:"claim,omitempty"` + ComputeUnits uint64 `protobuf:"varint,2,opt,name=compute_units,json=computeUnits,proto3" json:"compute_units,omitempty"` +} + +func (x *EventClaimExpired) Reset() { + *x = EventClaimExpired{} + if protoimpl.UnsafeEnabled { + mi := &file_poktroll_tokenomics_event_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EventClaimExpired) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EventClaimExpired) ProtoMessage() {} + +// Deprecated: Use EventClaimExpired.ProtoReflect.Descriptor instead. +func (*EventClaimExpired) Descriptor() ([]byte, []int) { + return file_poktroll_tokenomics_event_proto_rawDescGZIP(), []int{0} +} + +func (x *EventClaimExpired) GetClaim() *proof.Claim { + if x != nil { + return x.Claim + } + return nil +} + +func (x *EventClaimExpired) GetComputeUnits() uint64 { + if x != nil { + return x.ComputeUnits + } + return 0 +} + +// EventClaimSettled is an event emitted whenever a claim is settled. +// The booleans determine +type EventClaimSettled struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Claim *proof.Claim `protobuf:"bytes,1,opt,name=claim,proto3" json:"claim,omitempty"` + ComputeUnits uint64 `protobuf:"varint,2,opt,name=compute_units,json=computeUnits,proto3" json:"compute_units,omitempty"` + ProofRequired bool `protobuf:"varint,3,opt,name=proof_required,json=proofRequired,proto3" json:"proof_required,omitempty"` +} + +func (x *EventClaimSettled) Reset() { + *x = EventClaimSettled{} + if protoimpl.UnsafeEnabled { + mi := &file_poktroll_tokenomics_event_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EventClaimSettled) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EventClaimSettled) ProtoMessage() {} + +// Deprecated: Use EventClaimSettled.ProtoReflect.Descriptor instead. +func (*EventClaimSettled) Descriptor() ([]byte, []int) { + return file_poktroll_tokenomics_event_proto_rawDescGZIP(), []int{1} +} + +func (x *EventClaimSettled) GetClaim() *proof.Claim { + if x != nil { + return x.Claim + } + return nil +} + +func (x *EventClaimSettled) GetComputeUnits() uint64 { + if x != nil { + return x.ComputeUnits + } + return 0 +} + +func (x *EventClaimSettled) GetProofRequired() bool { + if x != nil { + return x.ProofRequired + } + return false +} + +var File_poktroll_tokenomics_event_proto protoreflect.FileDescriptor + +var file_poktroll_tokenomics_event_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x13, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0x1a, 0x1a, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, + 0x2f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x2f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x65, 0x0a, 0x11, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x61, 0x69, 0x6d, + 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x64, 0x12, 0x2b, 0x0a, 0x05, 0x63, 0x6c, 0x61, 0x69, 0x6d, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, + 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x2e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x05, 0x63, + 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x5f, + 0x75, 0x6e, 0x69, 0x74, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x63, 0x6f, 0x6d, + 0x70, 0x75, 0x74, 0x65, 0x55, 0x6e, 0x69, 0x74, 0x73, 0x22, 0x8c, 0x01, 0x0a, 0x11, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x64, 0x12, + 0x2b, 0x0a, 0x05, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, + 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x2e, + 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x05, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x23, 0x0a, 0x0d, + 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x0c, 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x55, 0x6e, 0x69, 0x74, + 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x5f, 0x72, 0x65, 0x71, 0x75, 0x69, + 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x6f, 0x66, + 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x42, 0xb8, 0x01, 0x0a, 0x17, 0x63, 0x6f, 0x6d, + 0x2e, 0x70, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, + 0x6d, 0x69, 0x63, 0x73, 0x42, 0x0a, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x24, 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, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0xa2, 0x02, 0x03, 0x50, 0x54, 0x58, 0xaa, 0x02, + 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, + 0x6d, 0x69, 0x63, 0x73, 0xca, 0x02, 0x13, 0x50, 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, + 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, 0xe2, 0x02, 0x1f, 0x50, 0x6f, 0x6b, + 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x5c, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, 0x69, 0x63, 0x73, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x50, + 0x6f, 0x6b, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x3a, 0x3a, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x6f, 0x6d, + 0x69, 0x63, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_poktroll_tokenomics_event_proto_rawDescOnce sync.Once + file_poktroll_tokenomics_event_proto_rawDescData = file_poktroll_tokenomics_event_proto_rawDesc +) + +func file_poktroll_tokenomics_event_proto_rawDescGZIP() []byte { + file_poktroll_tokenomics_event_proto_rawDescOnce.Do(func() { + file_poktroll_tokenomics_event_proto_rawDescData = protoimpl.X.CompressGZIP(file_poktroll_tokenomics_event_proto_rawDescData) + }) + return file_poktroll_tokenomics_event_proto_rawDescData +} + +var file_poktroll_tokenomics_event_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_poktroll_tokenomics_event_proto_goTypes = []interface{}{ + (*EventClaimExpired)(nil), // 0: poktroll.tokenomics.EventClaimExpired + (*EventClaimSettled)(nil), // 1: poktroll.tokenomics.EventClaimSettled + (*proof.Claim)(nil), // 2: poktroll.proof.Claim +} +var file_poktroll_tokenomics_event_proto_depIdxs = []int32{ + 2, // 0: poktroll.tokenomics.EventClaimExpired.claim:type_name -> poktroll.proof.Claim + 2, // 1: poktroll.tokenomics.EventClaimSettled.claim:type_name -> poktroll.proof.Claim + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_poktroll_tokenomics_event_proto_init() } +func file_poktroll_tokenomics_event_proto_init() { + if File_poktroll_tokenomics_event_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_poktroll_tokenomics_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EventClaimExpired); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_poktroll_tokenomics_event_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EventClaimSettled); 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_tokenomics_event_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_poktroll_tokenomics_event_proto_goTypes, + DependencyIndexes: file_poktroll_tokenomics_event_proto_depIdxs, + MessageInfos: file_poktroll_tokenomics_event_proto_msgTypes, + }.Build() + File_poktroll_tokenomics_event_proto = out.File + file_poktroll_tokenomics_event_proto_rawDesc = nil + file_poktroll_tokenomics_event_proto_goTypes = nil + file_poktroll_tokenomics_event_proto_depIdxs = nil +} diff --git a/app/app.go b/app/app.go index 66fe5ec05..a5d656049 100644 --- a/app/app.go +++ b/app/app.go @@ -4,6 +4,7 @@ import ( "io" "os" "path/filepath" + // this line is used by starport scaffolding # stargate/app/moduleImport "cosmossdk.io/depinject" "cosmossdk.io/log" @@ -53,6 +54,7 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + "github.com/pokt-network/poktroll/docs" applicationmodulekeeper "github.com/pokt-network/poktroll/x/application/keeper" gatewaymodulekeeper "github.com/pokt-network/poktroll/x/gateway/keeper" proofmodulekeeper "github.com/pokt-network/poktroll/x/proof/keeper" @@ -60,10 +62,6 @@ import ( sessionmodulekeeper "github.com/pokt-network/poktroll/x/session/keeper" suppliermodulekeeper "github.com/pokt-network/poktroll/x/supplier/keeper" tokenomicsmodulekeeper "github.com/pokt-network/poktroll/x/tokenomics/keeper" - - // this line is used by starport scaffolding # stargate/app/moduleImport - - "github.com/pokt-network/poktroll/docs" ) const ( diff --git a/app/app_config.go b/app/app_config.go index fb5e1e833..a35c72da9 100644 --- a/app/app_config.go +++ b/app/app_config.go @@ -69,6 +69,8 @@ import ( ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + "google.golang.org/protobuf/types/known/durationpb" + applicationmodulev1 "github.com/pokt-network/poktroll/api/poktroll/application/module" gatewaymodulev1 "github.com/pokt-network/poktroll/api/poktroll/gateway/module" proofmodulev1 "github.com/pokt-network/poktroll/api/poktroll/proof/module" @@ -90,8 +92,6 @@ import ( suppliermoduletypes "github.com/pokt-network/poktroll/x/supplier/types" _ "github.com/pokt-network/poktroll/x/tokenomics/module" // import for side-effects tokenomicsmoduletypes "github.com/pokt-network/poktroll/x/tokenomics/types" - "google.golang.org/protobuf/types/known/durationpb" - // this line is used by starport scaffolding # stargate/app/moduleImport ) var ( diff --git a/docusaurus/docs/developer_guide/quickstart.md b/docusaurus/docs/developer_guide/quickstart.md index 3fc30263c..a34d7902c 100644 --- a/docusaurus/docs/developer_guide/quickstart.md +++ b/docusaurus/docs/developer_guide/quickstart.md @@ -28,7 +28,7 @@ The goal of this document is to get you up and running with a LocalNet and end-to-end relay. **If you encounter any problems**, the best way to get support -from the team is by creating a new [GitHub Issue here](https://github.com/pokt-network/pocket/issues/new/choose). +from the team is by creating a new [GitHub Issue here](https://github.com/pokt-network/poktroll/issues/new/choose). ::: ## Install Dependencies diff --git a/docusaurus/docs/infrastructure/localnet.md b/docusaurus/docs/infrastructure/localnet.md index 3ddfb4cdb..3a20c6480 100644 --- a/docusaurus/docs/infrastructure/localnet.md +++ b/docusaurus/docs/infrastructure/localnet.md @@ -31,7 +31,7 @@ needed to send an end-to-end relay. ### Report issues -If you encounter any problems, please create a new [GitHub Issue here](https://github.com/pokt-network/pocket/issues/new/choose). +If you encounter any problems, please create a new [GitHub Issue here](https://github.com/pokt-network/poktroll/issues/new/choose). ### TL;DR diff --git a/docusaurus/docs/roadmap/roadmap_changelog.md b/docusaurus/docs/roadmap/roadmap_changelog.md index 32c590a1c..c8c2bdf61 100644 --- a/docusaurus/docs/roadmap/roadmap_changelog.md +++ b/docusaurus/docs/roadmap/roadmap_changelog.md @@ -56,7 +56,7 @@ A few changes were made, but the important pieces are the focus of each of the n ### After Change #2 -![Screenshot 2023-11-13 at 12 42 02 PM](https://github.com/pokt-network/poktroll/assets/1892194/d1bc7be8-47c3-4358-be77-626533c7f98e) +![Screenshot 2023-11-13 at 12 42 02 PM](https://github.com/pokt-network/pocket/assets/1892194/d1bc7be8-47c3-4358-be77-626533c7f98e) ### Before Change #2 diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index f1bcb422d..c86670573 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "log" + "math" "os" "regexp" "strconv" @@ -16,7 +17,7 @@ import ( "cosmossdk.io/depinject" sdklog "cosmossdk.io/log" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/codec" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" @@ -112,13 +113,13 @@ func (s *suite) TheUserRunsTheCommand(cmd string) { res, err := s.pocketd.RunCommand(cmds...) s.pocketd.result = res if err != nil { - s.Fatalf("error running command %s: %s", cmd, err) + s.Fatalf("ERROR: error running command %s: %s", cmd, err) } } func (s *suite) TheUserShouldBeAbleToSeeStandardOutputContaining(arg1 string) { if !strings.Contains(s.pocketd.result.Stdout, arg1) { - s.Fatalf("stdout must contain %s", arg1) + s.Fatalf("ERROR: stdout must contain '%s' but instead contains: '%s'", arg1, s.pocketd.result.Stdout) } } @@ -136,43 +137,61 @@ func (s *suite) TheUserSendsUpoktFromAccountToAccount(amount int64, accName1, ac } res, err := s.pocketd.RunCommandOnHost("", args...) if err != nil { - s.Fatalf("error sending upokt: %s", err) + s.Fatalf("ERROR: error sending upokt: %s", err) } s.pocketd.result = res } func (s *suite) TheAccountHasABalanceGreaterThanUpokt(accName string, amount int64) { bal := s.getAccBalance(accName) - if int64(bal) < amount { - s.Fatalf("account %s does not have enough upokt: %d < %d", accName, bal, amount) + if bal < amount { + s.Fatalf("ERROR: account %s does not have enough upokt: %d < %d", accName, bal, amount) } - s.scenarioState[accName] = bal // save the balance for later + s.scenarioState[accBalanceKey(accName)] = bal // save the balance for later } func (s *suite) AnAccountExistsFor(accName string) { bal := s.getAccBalance(accName) - s.scenarioState[accName] = bal // save the balance for later + s.scenarioState[accBalanceKey(accName)] = bal // save the balance for later } -func (s *suite) TheAccountBalanceOfShouldBeUpoktThanBefore(accName string, amount int64, condition string) { - prev, ok := s.scenarioState[accName] +func (s *suite) TheStakeOfShouldBeUpoktThanBefore(actorType string, accName string, expectedStakeChange int64, condition string) { + // Get previous stake + prevStakeStr, ok := s.scenarioState[accStakeKey(actorType, accName)] if !ok { - s.Fatalf("no previous balance found for %s", accName) + s.Fatalf("ERROR: no previous stake found for %s", accName) + } + prevStake, ok := prevStakeStr.(int64) + if !ok { + s.Fatalf("ERROR: previous stake for %s is not an int", accName) } - bal := s.getAccBalance(accName) - switch condition { - case "more": - if bal <= prev.(int) { - s.Fatalf("account %s expected to have more upokt but: %d <= %d", accName, bal, prev) - } - case "less": - if bal >= prev.(int) { - s.Fatalf("account %s expected to have less upokt but: %d >= %d", accName, bal, prev) - } - default: - s.Fatalf("unknown condition %s", condition) + // Get current stake + ok, currStake := s.getStakedAmount(actorType, accName) + if !ok { + s.Fatalf("ERROR: no current stake found for %s", accName) } + + // Validate the change in stake + s.validateAmountChange(prevStake, int64(currStake), expectedStakeChange, accName, condition) +} + +func (s *suite) TheAccountBalanceOfShouldBeUpoktThanBefore(accName string, expectedStakeChange int64, condition string) { + // Get previous balance + prevBalanceStr, ok := s.scenarioState[accBalanceKey(accName)] + if !ok { + s.Fatalf("ERROR: no previous balance found for %s", accName) + } + prevBalance, ok := prevBalanceStr.(int64) + if !ok { + s.Fatalf("ERROR: previous balance for %s is not an int", accName) + } + + // Get current balance + currBalance := s.getAccBalance(accName) + + // Validate the change in stake + s.validateAmountChange(prevBalance, int64(currBalance), expectedStakeChange, accName, condition) } func (s *suite) TheUserShouldWaitForSeconds(dur int64) { @@ -185,10 +204,10 @@ func (s *suite) TheUserStakesAWithUpoktFromTheAccount(actorType string, amount i configContent := fmt.Sprintf(`stake_amount: %d upokt`, amount) configFile, err := ioutil.TempFile("", configPathPattern) if err != nil { - s.Fatalf("error creating config file: %q", err) + s.Fatalf("ERROR: error creating config file: %q", err) } if _, err = configFile.Write([]byte(configContent)); err != nil { - s.Fatalf("error writing config file: %q", err) + s.Fatalf("ERROR: error writing config file: %q", err) } args := []string{ @@ -208,11 +227,11 @@ func (s *suite) TheUserStakesAWithUpoktFromTheAccount(actorType string, amount i // Remove the temporary config file err = os.Remove(configFile.Name()) if err != nil { - s.Fatalf("error removing config file: %q", err) + s.Fatalf("ERROR: error removing config file: %q", err) } if err != nil { - s.Fatalf("error staking %s: %s", actorType, err) + s.Fatalf("ERROR: error staking %s: %s", actorType, err) } s.pocketd.result = res } @@ -230,26 +249,36 @@ func (s *suite) TheUserUnstakesAFromTheAccount(actorType string, accName string) } res, err := s.pocketd.RunCommandOnHost("", args...) if err != nil { - s.Fatalf("error unstaking %s: %s", actorType, err) + s.Fatalf("ERROR: error unstaking %s: %s", actorType, err) } s.pocketd.result = res } +func (s *suite) TheAccountForIsStaked(actorType, accName string) { + found, stakeAmount := s.getStakedAmount(actorType, accName) + if !found { + s.Fatalf("ERROR: account %s should be staked", accName) + } + s.scenarioState[accStakeKey(actorType, accName)] = stakeAmount // save the stakeAmount for later +} + func (s *suite) TheForAccountIsNotStaked(actorType, accName string) { - found, _ := s.getStakedAmount(actorType, accName) + found, stakeAmount := s.getStakedAmount(actorType, accName) if found { - s.Fatalf("account %s should not be staked", accName) + s.Fatalf("ERROR: account %s should not be staked", accName) } + s.scenarioState[accStakeKey(actorType, accName)] = stakeAmount // save the stakeAmount for later } func (s *suite) TheForAccountIsStakedWithUpokt(actorType, accName string, amount int64) { found, stakeAmount := s.getStakedAmount(actorType, accName) if !found { - s.Fatalf("account %s should be staked", accName) + s.Fatalf("ERROR: account %s should be staked", accName) } if int64(stakeAmount) != amount { - s.Fatalf("account %s stake amount is not %d", accName, amount) + s.Fatalf("ERROR: account %s stake amount is not %d", accName, amount) } + s.scenarioState[accStakeKey(actorType, accName)] = stakeAmount // save the stakeAmount for later } func (s *suite) TheApplicationIsStakedForService(appName string, serviceId string) { @@ -258,7 +287,7 @@ func (s *suite) TheApplicationIsStakedForService(appName string, serviceId strin return } } - s.Fatalf("application %s is not staked for service %s", appName, serviceId) + s.Fatalf("ERROR: application %s is not staked for service %s", appName, serviceId) } func (s *suite) TheSupplierIsStakedForService(supplierName string, serviceId string) { @@ -267,17 +296,17 @@ func (s *suite) TheSupplierIsStakedForService(supplierName string, serviceId str return } } - s.Fatalf("supplier %s is not staked for service %s", supplierName, serviceId) + s.Fatalf("ERROR: supplier %s is not staked for service %s", supplierName, serviceId) } func (s *suite) TheSessionForApplicationAndServiceContainsTheSupplier(appName string, serviceId string, supplierName string) { app, found := accNameToAppMap[appName] if !found { - s.Fatalf("application %s not found", appName) + s.Fatalf("ERROR: application %s not found", appName) } expectedSupplier, found := accNameToSupplierMap[supplierName] if !found { - s.Fatalf("supplier %s not found", supplierName) + s.Fatalf("ERROR: supplier %s not found", supplierName) } argsAndFlags := []string{ "query", @@ -285,11 +314,11 @@ func (s *suite) TheSessionForApplicationAndServiceContainsTheSupplier(appName st "get-session", app.Address, serviceId, - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } res, err := s.pocketd.RunCommandOnHost("", argsAndFlags...) if err != nil { - s.Fatalf("error getting session for app %s and service %s: %s", appName, serviceId, err) + s.Fatalf("ERROR: error getting session for app %s and service %s: %s", appName, serviceId, err) } var resp sessiontypes.QueryGetSessionResponse responseBz := []byte(strings.TrimSpace(res.Stdout)) @@ -299,13 +328,13 @@ func (s *suite) TheSessionForApplicationAndServiceContainsTheSupplier(appName st return } } - s.Fatalf("session for app %s and service %s does not contain supplier %s", appName, serviceId, supplierName) + s.Fatalf("ERROR: session for app %s and service %s does not contain supplier %s", appName, serviceId, supplierName) } func (s *suite) TheApplicationSendsTheSupplierARequestForServiceWithData(appName, supplierName, serviceId, requestData string) { res, err := s.pocketd.RunCurl(appGateServerUrl, serviceId, requestData) if err != nil { - s.Fatalf("error sending relay request from app %s to supplier %s for service %s: %v", appName, supplierName, serviceId, err) + s.Fatalf("ERROR: error sending relay request from app %s to supplier %s for service %s: %v", appName, supplierName, serviceId, err) } relayKey := relayReferenceKey(appName, supplierName) @@ -329,7 +358,7 @@ func (s *suite) getStakedAmount(actorType, accName string) (bool, int) { } res, err := s.pocketd.RunCommandOnHost("", args...) if err != nil { - s.Fatalf("error getting %s: %s", actorType, err) + s.Fatalf("ERROR: error getting %s: %s", actorType, err) } s.pocketd.result = res found := strings.Contains(res.Stdout, accNameToAddrMap[accName]) @@ -339,7 +368,7 @@ func (s *suite) getStakedAmount(actorType, accName string) (bool, int) { stakedAmountRe := regexp.MustCompile(`address: ` + escapedAddress + `\s+stake:\s+amount: "(\d+)"`) matches := stakedAmountRe.FindStringSubmatch(res.Stdout) if len(matches) < 2 { - s.Fatalf("no stake amount found for %s", accName) + s.Fatalf("ERROR: no stake amount found for %s", accName) } amount, err = strconv.Atoi(matches[1]) require.NoError(s, err) @@ -353,7 +382,7 @@ func (s *suite) buildAddrMap() { "keys", "list", keyRingFlag, ) if err != nil { - s.Fatalf("error getting keys: %s", err) + s.Fatalf("ERROR: error getting keys: %s", err) } s.pocketd.result = res matches := addrRe.FindAllStringSubmatch(res.Stdout, -1) @@ -371,11 +400,11 @@ func (s *suite) buildAppMap() { "query", "application", "list-application", - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } res, err := s.pocketd.RunCommandOnHost("", argsAndFlags...) if err != nil { - s.Fatalf("error getting application list: %s", err) + s.Fatalf("ERROR: error getting application list: %s", err) } s.pocketd.result = res var resp apptypes.QueryAllApplicationsResponse @@ -392,11 +421,11 @@ func (s *suite) buildSupplierMap() { "query", "supplier", "list-supplier", - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } res, err := s.pocketd.RunCommandOnHost("", argsAndFlags...) if err != nil { - s.Fatalf("error getting supplier list: %s", err) + s.Fatalf("ERROR: error getting supplier list: %s", err) } s.pocketd.result = res var resp suppliertypes.QueryAllSuppliersResponse @@ -407,7 +436,7 @@ func (s *suite) buildSupplierMap() { } } -func (s *suite) getAccBalance(accName string) int { +func (s *suite) getAccBalance(accName string) int64 { s.Helper() args := []string{ "query", @@ -417,16 +446,41 @@ func (s *suite) getAccBalance(accName string) int { } res, err := s.pocketd.RunCommandOnHost("", args...) if err != nil { - s.Fatalf("error getting balance: %s", err) + s.Fatalf("ERROR: error getting balance: %s", err) } s.pocketd.result = res match := amountRe.FindStringSubmatch(res.Stdout) if len(match) < 2 { - s.Fatalf("no balance found for %s", accName) + s.Fatalf("ERROR: no balance found for %s", accName) } found, err := strconv.Atoi(match[1]) require.NoError(s, err) - return found + return int64(found) +} + +// validateAmountChange validates if the balance of an account has increased or decreased by the expected amount +func (s *suite) validateAmountChange(prevAmount, currAmount, expectedAmountChange int64, accName, condition string) { + deltaAmount := int64(math.Abs(float64(currAmount - prevAmount))) + // Verify if balance is more or less than before + switch condition { + case "more": + if currAmount <= prevAmount { + s.Fatalf("ERROR: account %s expected to have more upokt but: %d <= %d", accName, currAmount, prevAmount) + } + if deltaAmount != expectedAmountChange { + s.Fatalf("ERROR: account %s balance expected to increase by %d, but actually increased by %d", accName, expectedAmountChange, deltaAmount) + } + case "less": + if currAmount >= prevAmount { + s.Fatalf("ERROR: account %s expected to have less upokt but: %d >= %d", accName, currAmount, prevAmount) + } + if deltaAmount != expectedAmountChange { + s.Fatalf("ERROR: account %s balance expected to decrease by %d, but actually decreased by %d", accName, expectedAmountChange, deltaAmount) + } + default: + s.Fatalf("ERROR: unknown condition %s", condition) + } + } // TODO_IMPROVE: use `sessionId` and `supplierName` since those are the two values @@ -434,3 +488,15 @@ func (s *suite) getAccBalance(accName string) int { func relayReferenceKey(appName, supplierName string) string { return fmt.Sprintf("%s/%s", appName, supplierName) } + +// accBalanceKey is a helper function to create a key to store the balance +// for accName in the context of a scenario state. +func accBalanceKey(accName string) string { + return fmt.Sprintf("balance/%s", accName) +} + +// accStakeKey is a helper function to create a key to store the stake +// for accName of type actorType in the context of a scenario state. +func accStakeKey(actorType, accName string) string { + return fmt.Sprintf("stake/%s/%s", actorType, accName) +} diff --git a/e2e/tests/stake.feature b/e2e/tests/stake.feature index 1171ef3d6..10e4f1f40 100644 --- a/e2e/tests/stake.feature +++ b/e2e/tests/stake.feature @@ -8,6 +8,7 @@ Feature: Stake Namespaces Then the user should be able to see standard output containing "txhash:" And the user should be able to see standard output containing "code: 0" And the pocketd binary should exit without error + # TODO_TECHDEBT(@Olshansk, @red-0ne): Can we eliminate waits in these tests? And the user should wait for "5" seconds And the "gateway" for account "gateway1" is staked with "1000" uPOKT And the account balance of "gateway1" should be "1000" uPOKT "less" than before diff --git a/e2e/tests/tokenomics.feature b/e2e/tests/tokenomics.feature index 09e6cd83b..3b764eb0c 100644 --- a/e2e/tests/tokenomics.feature +++ b/e2e/tests/tokenomics.feature @@ -1,13 +1,13 @@ Feature: Tokenomics Namespaces - # This test + # TODO_IN_THIS_PR(@Olshansk): Finish this uni-test. Scenario: Basic tokenomics validation that Supplier mint equals Application burn Given the user has the pocketd binary installed And an account exists for "supplier1" And an account exists for "app1" When the supplier "supplier1" has serviced a session with "20" relays for service "svc1" for application "app1" - # And the user should wait for "5" seconds - # TODO_UPNEXT(@Olshansk, #359): Expand on the two expectations below after integrating the tokenomics module - # into the supplier module. + And the user should wait for the "proof" "CreateClaim" Message to be submited + And the user should wait for the "proof" "SubmitProof" Message to be submited + # Then the account balance of "supplier1" should be "1000" uPOKT "more" than before - # And the account balance of "app1" should be "1000" uPOKT "less" than before + # And the "application" stake of "app1" should be "1000" uPOKT "less" than before diff --git a/pkg/client/interface.go b/pkg/client/interface.go index 52b50e052..ec92dc562 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -111,7 +111,7 @@ type Block interface { // Redelegation is an interface which wraps the EventRedelegation event // emitted by the application module. -// See: proto/pocket/application/types/event.proto#EventRedelegation +// See: proto/poktroll/application/types/event.proto#EventRedelegation type Redelegation interface { GetAppAddress() string GetGatewayAddress() string diff --git a/pkg/client/supplier/client_integration_test.go b/pkg/client/supplier/client_integration_test.go index f7ea11f56..02a8e0796 100644 --- a/pkg/client/supplier/client_integration_test.go +++ b/pkg/client/supplier/client_integration_test.go @@ -26,7 +26,7 @@ func TestNewSupplierClient_Localnet(t *testing.T) { var rootHash []byte sessionHeader := sessiontypes.SessionHeader{ ApplicationAddress: "", - SessionStartBlockHeight: 0, + SessionStartBlockHeight: 1, SessionId: "", } err := supplierClient.CreateClaim(ctx, sessionHeader, rootHash) diff --git a/pkg/client/supplier/client_test.go b/pkg/client/supplier/client_test.go index 7a21bcaf2..f9e907b82 100644 --- a/pkg/client/supplier/client_test.go +++ b/pkg/client/supplier/client_test.go @@ -104,7 +104,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) { var rootHash []byte sessionHeader := sessiontypes.SessionHeader{ ApplicationAddress: testAppAddr.String(), - SessionStartBlockHeight: 0, + SessionStartBlockHeight: 1, SessionId: "", Service: &sharedtypes.Service{ Id: testService, @@ -162,7 +162,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) { sessionHeader := sessiontypes.SessionHeader{ ApplicationAddress: testAppAddr.String(), - SessionStartBlockHeight: 0, + SessionStartBlockHeight: 1, SessionId: "", Service: &sharedtypes.Service{ Id: testService, @@ -174,7 +174,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) { // Generating an ephemeral tree & spec just so we can submit // a proof of the right size. - // TODO_TECHDEBT: Centralize the configuration for the SMT spec. + // TODO_TECHDEBT(#446): Centralize the configuration for the SMT spec. tree := smt.NewSparseMerkleSumTrie(kvStore, sha256.New()) emptyPath := make([]byte, tree.PathHasherSize()) proof, err := tree.ProveClosest(emptyPath) diff --git a/pkg/client/tx/client_test.go b/pkg/client/tx/client_test.go index 827929dd7..71c4a573d 100644 --- a/pkg/client/tx/client_test.go +++ b/pkg/client/tx/client_test.go @@ -42,6 +42,7 @@ const ( // TODO_TECHDEBT: add coverage for the transactions client handling an events bytes error either. func TestTxClient_SignAndBroadcast_Succeeds(t *testing.T) { + t.Skip("TODO_BLOCKER(#425): Revisit Observable test tooling & fix flaky test") var ( // expectedTx is the expected transactions bytes that will be signed and broadcast // by the transaction client. It is computed and assigned in the @@ -403,7 +404,7 @@ func TestTxClient_SignAndBroadcast_Timeout(t *testing.T) { err, errCh := eitherErr.SyncOrAsyncError() require.NoError(t, err) - // TODO_TECHDEBT: Centralize the configuration for the SMT spec. + // TODO_TECHDEBT(#446): Centralize the configuration for the SMT spec. spec := smt.NoPrehashSpec(sha256.New(), true) emptyBlockHash := make([]byte, spec.PathHasherSize()) diff --git a/pkg/polylog/polyzero/test_logger.go b/pkg/polylog/polyzero/test_logger.go index f0c35c89c..610f23990 100644 --- a/pkg/polylog/polyzero/test_logger.go +++ b/pkg/polylog/polyzero/test_logger.go @@ -1,5 +1,3 @@ -//go:build test - package polyzero import ( diff --git a/pkg/relayer/miner/miner.go b/pkg/relayer/miner/miner.go index 591b31875..72b39b2ab 100644 --- a/pkg/relayer/miner/miner.go +++ b/pkg/relayer/miner/miner.go @@ -17,8 +17,8 @@ import ( var ( _ relayer.Miner = (*miner)(nil) - // TODO_BLOCKER(@Olshansk): Retrieve the relay hasher mechanism from the `smt` repo. - // TODO_TECHDEBT: Centralize the configuration for the SMT spec. Look at + // TODO_BLOCKER(#446): Retrieve the relay hasher mechanism from the `smt` repo. + // TODO_TECHDEBT(#446): Centralize the configuration for the SMT spec. Look at // `GetHashFromBytes` in `miner.go`. DefaultRelayHasher = sha256.New // TODO_BLOCKER: query on-chain governance params once available. @@ -116,7 +116,7 @@ func (mnr *miner) mapMineRelay( // // TODO_IMPROVE: We need to hash the key; it would be nice if smst.Update() could do it // since smst has a reference to the hasherConstructor - // TODO_TECHDEBT: Why is this not `relay.GetHash()`? + // TODO_IN_THIS_PR(@red-0ne, @Olshansk): Why is this not `relay.GetHash()`? relayHash := mnr.hash(relayBz) // The relay IS NOT volume / reward applicable diff --git a/pkg/relayer/protocol/block_heights.go b/pkg/relayer/protocol/block_heights.go index bb0676737..2785ba1f3 100644 --- a/pkg/relayer/protocol/block_heights.go +++ b/pkg/relayer/protocol/block_heights.go @@ -31,7 +31,7 @@ func GetEarliestCreateClaimHeight(ctx context.Context, createClaimWindowStartBlo rngSeed, _ := binary.Varint(createClaimWindowStartBlockHash) randomNumber := rand.NewSource(rngSeed).Int63() - // TODO_TECHDEBT: query the on-chain governance parameter once available. + // TODO_BLOCKER: query the on-chain governance parameter once available. // randCreateClaimHeightOffset := randomNumber % (claimproofparams.GovCreateClaimIntervalBlocks - claimproofparams.GovCreateClaimWindowBlocks - 1) _ = randomNumber randCreateClaimHeightOffset := int64(0) @@ -59,7 +59,7 @@ func GetEarliestSubmitProofHeight(ctx context.Context, submitProofWindowStartBlo rngSeed, _ := binary.Varint(earliestSubmitProofBlockHash) randomNumber := rand.NewSource(rngSeed).Int63() - // TODO_TECHDEBT: query the on-chain governance parameter once available. + // TODO_BLOCKER: query the on-chain governance parameter once available. // randSubmitProofHeightOffset := randomNumber % (claimproofparams.GovSubmitProofIntervalBlocks - claimproofparams.GovSubmitProofWindowBlocks - 1) _ = randomNumber randSubmitProofHeightOffset := int64(0) diff --git a/pkg/relayer/session/claim.go b/pkg/relayer/session/claim.go index 0894d5ff7..9ac33b485 100644 --- a/pkg/relayer/session/claim.go +++ b/pkg/relayer/session/claim.go @@ -77,7 +77,7 @@ func (rs *relayerSessionsManager) waitForEarliestCreateClaimHeight( // into account the heights, windows and grace periods into helper functions. createClaimWindowStartHeight := sessionEndHeight + sessionkeeper.GetSessionGracePeriodBlockCount() - // TODO_TECHDEBT: query the on-chain governance parameter once available. + // TODO_BLOCKER: query the on-chain governance parameter once available. // + claimproofparams.GovCreateClaimWindowStartHeightOffset // we wait for createClaimWindowStartHeight to be received before proceeding since we need its hash diff --git a/pkg/relayer/session/proof.go b/pkg/relayer/session/proof.go index 9d155acd1..5a237af40 100644 --- a/pkg/relayer/session/proof.go +++ b/pkg/relayer/session/proof.go @@ -72,7 +72,7 @@ func (rs *relayerSessionsManager) waitForEarliestSubmitProofHeight( // TODO_TECHDEBT(@red-0ne): Centralize the business logic that involves taking // into account the heights, windows and grace periods into helper functions. submitProofWindowStartHeight := createClaimHeight + sessionkeeper.GetSessionGracePeriodBlockCount() - // TODO_TECHDEBT: query the on-chain governance parameter once available. + // TODO_BLOCKER: query the on-chain governance parameter once available. // + claimproofparams.GovSubmitProofWindowStartHeightOffset // we wait for submitProofWindowStartHeight to be received before proceeding since we need its hash diff --git a/pkg/relayer/session/session_test.go b/pkg/relayer/session/session_test.go index 6ed5a4a6a..519c86acb 100644 --- a/pkg/relayer/session/session_test.go +++ b/pkg/relayer/session/session_test.go @@ -28,7 +28,7 @@ func TestRelayerSessionsManager_Start(t *testing.T) { sessionEndHeight = 2 ) - // TODO_TECHDEBT: Centralize the configuration for the SMT spec. + // TODO_TECHDEBT(#446): Centralize the configuration for the SMT spec. var ( _, ctx = testpolylog.NewLoggerWithCtx(context.Background(), polyzero.DebugLevel) spec = smt.NoPrehashSpec(sha256.New(), true) diff --git a/proto/poktroll/application/event.proto b/proto/poktroll/application/event.proto index 8602c195e..16d70a795 100644 --- a/proto/poktroll/application/event.proto +++ b/proto/poktroll/application/event.proto @@ -4,13 +4,11 @@ package poktroll.application; option go_package = "github.com/pokt-network/poktroll/x/application/types"; import "cosmos_proto/cosmos.proto"; -import "gogoproto/gogo.proto"; // EventRedelegation is an event emitted whenever an application changes its // delegatee gateways on chain. This is in response to both a DelegateToGateway // and UndelegateFromGateway message. message EventRedelegation { - // TODO: Check if this tag is relevant for events: (gogoproto.jsontag) = "app_address" string app_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application, using cosmos' ScalarDescriptor to ensure deterministic encoding string gateway_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the gateway the application has changed their delegation of, using cosmos' ScalarDescriptor to ensure deterministic encoding } \ No newline at end of file diff --git a/proto/poktroll/session/session.proto b/proto/poktroll/session/session.proto index 071fbb6e2..64264fb61 100644 --- a/proto/poktroll/session/session.proto +++ b/proto/poktroll/session/session.proto @@ -16,9 +16,12 @@ import "poktroll/shared/supplier.proto"; message SessionHeader { string application_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application using cosmos' ScalarDescriptor to ensure deterministic encoding poktroll.shared.Service service = 2; // The service this session is for - int64 session_start_block_height = 3; // The height at which this session started // NOTE: session_id can be derived from the above values using on-chain but is included in the header for convenience - string session_id = 4; // A unique pseudoranom ID for this session + string session_id = 3; // A unique pseudoranom ID for this session + int64 session_start_block_height = 4; // The height at which this session started + // TODO_BLOCKER: `session_end_block_height` is not required for the header because + // it is a derivative of `start` + `num_blocks_per_session` as goverened by on-chain + // params at the time of the session start. Could/should we remove it? int64 session_end_block_height = 5; // The height at which this session ended, this is the last block of the session } diff --git a/proto/poktroll/tokenomics/event.proto b/proto/poktroll/tokenomics/event.proto new file mode 100644 index 000000000..7c5204ca5 --- /dev/null +++ b/proto/poktroll/tokenomics/event.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package poktroll.tokenomics; + +option go_package = "github.com/pokt-network/poktroll/x/tokenomics/types"; + +// TODO_IN_THIS_PR: Figure how why this is so difficult to import in pulsar. +import "poktroll/proof/claim.proto"; + +// EventClaimExpired is an event emitted whenever a claim requiring an on-chain +// proof doesn't have one. The claim cannot be settled, leading to that work +// never being rewarded. +message EventClaimExpired { + poktroll.proof.Claim claim = 1; + uint64 compute_units = 2; +} + +// EventClaimSettled is an event emitted whenever a claim is settled. +// The booleans determine +message EventClaimSettled { + poktroll.proof.Claim claim = 1; + uint64 compute_units = 2; + bool proof_required = 3; +} diff --git a/testutil/keeper/tokenomics.go b/testutil/keeper/tokenomics.go index db7e0d517..999455c93 100644 --- a/testutil/keeper/tokenomics.go +++ b/testutil/keeper/tokenomics.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "testing" "cosmossdk.io/log" @@ -12,34 +13,67 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/app" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/testutil/tokenomics/mocks" + appkeeper "github.com/pokt-network/poktroll/x/application/keeper" apptypes "github.com/pokt-network/poktroll/x/application/types" + gatewaykeeper "github.com/pokt-network/poktroll/x/gateway/keeper" + gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types" + proofkeeper "github.com/pokt-network/poktroll/x/proof/keeper" + prooftypes "github.com/pokt-network/poktroll/x/proof/types" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + supplierkeeper "github.com/pokt-network/poktroll/x/supplier/keeper" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" - "github.com/pokt-network/poktroll/x/tokenomics/keeper" - "github.com/pokt-network/poktroll/x/tokenomics/types" + tokenomicskeeper "github.com/pokt-network/poktroll/x/tokenomics/keeper" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) -// TODO_TECHDEBT: Replace `AnyTimes` w/ `Times/MinTimes/MaxTimes` as the tests -// mature to be explicit about the number of expected tests. +// TokenomicsModuleKeepers is an aggregation of the tokenomics keeper and all its dependency +// keepers, and the codec that they share. Each keeper is embedded such that the +// TokenomicsModuleKeepers implements all the interfaces of the keepers. +// To call a method which is common to multiple keepers (e.g. `#SetParams()`), +// the field corresponding to the desired keeper on which to call the method +// MUST be specified (e.g. `keepers.AccountKeeper#SetParams()`). +type TokenomicsModuleKeepers struct { + *tokenomicskeeper.Keeper + tokenomicstypes.AccountKeeper + tokenomicstypes.BankKeeper + tokenomicstypes.ApplicationKeeper + tokenomicstypes.ProofKeeper + + Codec *codec.ProtoCodec +} + +// TokenomicsKeepersOpt is a function which receives and potentailly modifies the context +// and tokenomics keepers during construction of the aggregation. +type TokenomicsKeepersOpt func(context.Context, *TokenomicsModuleKeepers) context.Context func TokenomicsKeeper(t testing.TB) ( - k keeper.Keeper, + tokenomicsKeeper tokenomicskeeper.Keeper, ttx context.Context, appAddr string, supplierAddr string, ) { t.Helper() - storeKey := storetypes.NewKVStoreKey(types.StoreKey) + storeKey := storetypes.NewKVStoreKey(tokenomicstypes.StoreKey) // Initialize the in-memory database. db := dbm.NewMemDB() @@ -88,13 +122,6 @@ func TokenomicsKeeper(t testing.TB) ( SetApplication(gomock.Any(), gomock.Any()). AnyTimes() - // Get test supplier if the address matches. - mockSupplierKeeper := mocks.NewMockSupplierKeeper(ctrl) - mockSupplierKeeper.EXPECT(). - GetSupplier(gomock.Any(), supplier.Address). - Return(supplier, true). - AnyTimes() - // Mock the bank keeper. mockBankKeeper := mocks.NewMockBankKeeper(ctrl) mockBankKeeper.EXPECT(). @@ -117,7 +144,11 @@ func TokenomicsKeeper(t testing.TB) ( mockAccountKeeper := mocks.NewMockAccountKeeper(ctrl) mockAccountKeeper.EXPECT().GetAccount(gomock.Any(), gomock.Any()).AnyTimes() - tokenomicsKeeper := keeper.NewKeeper( + // Mock the proof keeper + mockProofKeeper := mocks.NewMockProofKeeper(ctrl) + mockProofKeeper.EXPECT().GetAllClaims(gomock.Any()).AnyTimes() + + k := tokenomicskeeper.NewKeeper( cdc, runtime.NewKVStoreService(storeKey), log.NewNopLogger(), @@ -125,13 +156,162 @@ func TokenomicsKeeper(t testing.TB) ( mockBankKeeper, mockAccountKeeper, mockApplicationKeeper, - mockSupplierKeeper, + mockProofKeeper, ) ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger()) // Initialize params - require.NoError(t, tokenomicsKeeper.SetParams(ctx, types.DefaultParams())) + require.NoError(t, k.SetParams(ctx, tokenomicstypes.DefaultParams())) + + return k, ctx, application.Address, supplier.Address +} + +// NewTokenomicsModuleKeepers is a helper function to create a tokenomics keeper and a context. It uses +// real dependencies for all keepers except the bank keeper, which is mocked as it's not used +// directly by the tokenomics keeper or its dependencies. +func NewTokenomicsModuleKeepers(t testing.TB, opts ...TokenomicsKeepersOpt) (_ TokenomicsModuleKeepers, ctx context.Context) { + t.Helper() + + // Collect store keys for all keepers which be constructed & interact with the state store. + keys := storetypes.NewKVStoreKeys( + tokenomicstypes.StoreKey, + banktypes.StoreKey, + gatewaytypes.StoreKey, + authtypes.StoreKey, + sessiontypes.StoreKey, + apptypes.StoreKey, + suppliertypes.StoreKey, + prooftypes.StoreKey, + ) + + // Construct a multistore & mount store keys for each keeper that will interact with the state store. + stateStore := integration.CreateMultiStore(keys, log.NewNopLogger()) + + // Prepare the context + logger := log.NewTestLogger(t) + ctx = sdk.NewContext(stateStore, cmtproto.Header{}, false, logger) + + // ctx.SetAccount + // Prepare the account keeper. + registry := codectypes.NewInterfaceRegistry() + authtypes.RegisterInterfaces(registry) + cryptocodec.RegisterInterfaces(registry) + + // Prepare the chain's authority + cdc := codec.NewProtoCodec(registry) + authority := authtypes.NewModuleAddress(govtypes.ModuleName) + + addrCodec := addresscodec.NewBech32Codec(app.AccountAddressPrefix) + + // Construct a real account keeper so that public keys can be queried. + accountKeeper := authkeeper.NewAccountKeeper( + cdc, + runtime.NewKVStoreService(keys[authtypes.StoreKey]), + authtypes.ProtoBaseAccount, + map[string][]string{minttypes.ModuleName: {authtypes.Minter}}, + addrCodec, + app.AccountAddressPrefix, + authority.String(), + ) + + fmt.Println("authority.String()", authority.String()) + + // Construct a real bank keeper so that the balances can be updated & verified + bankKeeper := bankkeeper.NewBaseKeeper( + cdc, + runtime.NewKVStoreService(keys[banktypes.StoreKey]), + accountKeeper, + make(map[string]bool), + authority.String(), + logger, + ) + require.NoError(t, bankKeeper.SetParams(ctx, banktypes.DefaultParams())) + + // Construct gateway keeper with a mocked bank keeper. + gatewayKeeper := gatewaykeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keys[gatewaytypes.StoreKey]), + logger, + authority.String(), + bankKeeper, + ) + require.NoError(t, gatewayKeeper.SetParams(ctx, gatewaytypes.DefaultParams())) + + // Construct an application keeper to add apps to sessions. + appKeeper := appkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keys[apptypes.StoreKey]), + logger, + authority.String(), + bankKeeper, + accountKeeper, + gatewayKeeper, + ) + require.NoError(t, appKeeper.SetParams(ctx, apptypes.DefaultParams())) + + // Construct a real supplier keeper to add suppliers to sessions. + supplierKeeper := supplierkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keys[suppliertypes.StoreKey]), + log.NewNopLogger(), + authority.String(), + bankKeeper, + ) + require.NoError(t, supplierKeeper.SetParams(ctx, suppliertypes.DefaultParams())) + + // Construct a real session keeper so that sessions can be queried. + sessionKeeper := sessionkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keys[sessiontypes.StoreKey]), + logger, + authority.String(), + accountKeeper, + bankKeeper, + appKeeper, + supplierKeeper, + ) + require.NoError(t, sessionKeeper.SetParams(ctx, sessiontypes.DefaultParams())) + + // Construct a real proof keeper so that claims & proofs can be created. + proofKeeper := proofkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keys[prooftypes.StoreKey]), + logger, + authority.String(), + sessionKeeper, + appKeeper, + accountKeeper, + ) + + // Construct a real tokenomics keeper so that claims & tokenomics can be created. + tokenomicsKeeper := tokenomicskeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keys[tokenomicstypes.StoreKey]), + logger, + authority.String(), + bankKeeper, + accountKeeper, + appKeeper, + proofKeeper, + ) + + require.NoError(t, tokenomicsKeeper.SetParams(ctx, tokenomicstypes.DefaultParams())) + + keepers := TokenomicsModuleKeepers{ + Keeper: &tokenomicsKeeper, + AccountKeeper: &accountKeeper, + BankKeeper: &bankKeeper, + ApplicationKeeper: &appKeeper, + ProofKeeper: &proofKeeper, + + Codec: cdc, + } + + // Apply any options to update the keepers or context prior to returning them. + for _, opt := range opts { + ctx = opt(ctx, &keepers) + } - return tokenomicsKeeper, ctx, application.Address, supplier.Address + return keepers, ctx } diff --git a/testutil/testrelayer/hash.go b/testutil/testrelayer/hash.go index d8c78e64e..d1fc3953c 100644 --- a/testutil/testrelayer/hash.go +++ b/testutil/testrelayer/hash.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -// TODO_TECHDEBT(@h5law): Retrieve the relay hasher mechanism from the `smt` repo. +// TODO_TECHDEBT(#446): Retrieve the relay hasher mechanism from the `smt` repo. func HashBytes(t *testing.T, newHasher func() hash.Hash, relayBz []byte) []byte { hasher := newHasher() _, err := hasher.Write(relayBz) diff --git a/x/application/module/query_application_test.go b/x/application/module/query_application_test.go index b97fcf71b..0a9c96efc 100644 --- a/x/application/module/query_application_test.go +++ b/x/application/module/query_application_test.go @@ -5,7 +5,7 @@ import ( "strconv" "testing" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/stretchr/testify/require" @@ -22,7 +22,7 @@ func TestShowApplication(t *testing.T) { ctx := net.Validators[0].ClientCtx common := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } tests := []struct { desc string @@ -78,7 +78,7 @@ func TestListApplication(t *testing.T) { ctx := net.Validators[0].ClientCtx request := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } if next == nil { args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) diff --git a/x/gateway/module/query_gateway_test.go b/x/gateway/module/query_gateway_test.go index e9b4d07b8..be80d4178 100644 --- a/x/gateway/module/query_gateway_test.go +++ b/x/gateway/module/query_gateway_test.go @@ -5,7 +5,7 @@ import ( "strconv" "testing" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/stretchr/testify/require" @@ -25,7 +25,7 @@ func TestShowGateway(t *testing.T) { ctx := net.Validators[0].ClientCtx common := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } tests := []struct { desc string @@ -81,7 +81,7 @@ func TestListGateway(t *testing.T) { ctx := net.Validators[0].ClientCtx request := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } if next == nil { args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) diff --git a/x/proof/keeper/msg_server_create_claim.go b/x/proof/keeper/msg_server_create_claim.go index 15e7b47e9..136278654 100644 --- a/x/proof/keeper/msg_server_create_claim.go +++ b/x/proof/keeper/msg_server_create_claim.go @@ -20,22 +20,22 @@ func (k msgServer) CreateClaim(ctx context.Context, msg *types.MsgCreateClaim) ( return nil, err } + sessionHeader := msg.GetSessionHeader() session, err := k.queryAndValidateSessionHeader( ctx, - msg.GetSessionHeader(), + sessionHeader, msg.GetSupplierAddress(), ) if err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } - logger. + logger = logger. With( "session_id", session.GetSessionId(), - "session_end_height", msg.GetSessionHeader().GetSessionEndBlockHeight(), + "session_end_height", sessionHeader.GetSessionEndBlockHeight(), "supplier", msg.GetSupplierAddress(), - ). - Debug("validated claim") + ) /* TODO_INCOMPLETE: @@ -49,10 +49,12 @@ func (k msgServer) CreateClaim(ctx context.Context, msg *types.MsgCreateClaim) ( 2. [ ] msg distribution validation */ + logger.Debug("validated claim") + // Construct and upsert claim after all validation. claim := types.Claim{ SupplierAddress: msg.GetSupplierAddress(), - SessionHeader: msg.GetSessionHeader(), + SessionHeader: sessionHeader, RootHash: msg.GetRootHash(), } @@ -60,13 +62,7 @@ func (k msgServer) CreateClaim(ctx context.Context, msg *types.MsgCreateClaim) ( // in any case where the supplier should no longer be able to update the given proof. k.Keeper.UpsertClaim(ctx, claim) - logger. - With( - "session_id", claim.GetSessionHeader().GetSessionId(), - "session_end_height", claim.GetSessionHeader().GetSessionEndBlockHeight(), - "supplier", claim.GetSupplierAddress(), - ). - Debug("created claim") + logger.Debug("created new claim") // TODO: return the claim in the response. return &types.MsgCreateClaimResponse{}, nil diff --git a/x/proof/keeper/msg_server_create_claim_test.go b/x/proof/keeper/msg_server_create_claim_test.go index 6aef6b5a3..cfa73d102 100644 --- a/x/proof/keeper/msg_server_create_claim_test.go +++ b/x/proof/keeper/msg_server_create_claim_test.go @@ -13,6 +13,7 @@ import ( apptypes "github.com/pokt-network/poktroll/x/application/types" "github.com/pokt-network/poktroll/x/proof/keeper" "github.com/pokt-network/poktroll/x/proof/types" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -284,10 +285,10 @@ func newTestClaimMsg( supplierAddr, &sessiontypes.SessionHeader{ ApplicationAddress: appAddr, - SessionId: sessionId, Service: service, + SessionId: sessionId, SessionStartBlockHeight: 1, - SessionEndBlockHeight: 4, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, merkleRoot, ) diff --git a/x/proof/keeper/msg_server_submit_proof.go b/x/proof/keeper/msg_server_submit_proof.go index 5a49f7cf8..5dfaf1aea 100644 --- a/x/proof/keeper/msg_server_submit_proof.go +++ b/x/proof/keeper/msg_server_submit_proof.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/sha256" + "fmt" "hash" "github.com/pokt-network/smt" @@ -35,9 +36,15 @@ func init() { // A proof that's stored on-chain is what leads to rewards (i.e. inflation) // downstream, making the series of checks a critical part of the protocol. // TODO_BLOCKER: Prevent proof upserts after the tokenomics module has processes the respective session. +// TODO_IN_THIS_PR_DISCUSS: Do we need to validate if the signature on the Proof message corresponds to the supplier before upserting? func (k msgServer) SubmitProof(ctx context.Context, msg *types.MsgSubmitProof) (*types.MsgSubmitProofResponse, error) { + // TODO_IN_THIS_PR_DISCUSS: A potential issue with doing proof validation inside + // `SubmitProof` is that we will not be storing false proofs on-chain (e.g. for slashing purposes). + // This could be considered a feature (e.g. less state bloat against sybil attacks) + // or a bug (i.e. no mechanisms for slashing suppliers who submit false proofs). + // Revisit this prior to mainnet launch as to whether the business logic for settling sessions should be in EndBlocker or here. logger := k.Logger().With("method", "SubmitProof") - logger.Debug("about to start submitting proof") + logger.Info("About to start submitting proof") /* TODO_DOCUMENT(@bryanchriswhite): Document these steps in proof @@ -64,17 +71,28 @@ func (k msgServer) SubmitProof(ctx context.Context, msg *types.MsgSubmitProof) ( ## Relay Mining validation 1. verify(proof.path) is the expected path; pseudo-random variation using on-chain data - 2. verify(proof.ValueHash, expectedDiffictulty); governance based + 2. verify(proof.ValueHash, expectedDifficulty); governance based 3. verify(claim.Root, proof.ClosestProof); verify the closest proof is correct */ + // Decomposing a few variables for easier access + sessionHeader := msg.GetSessionHeader() + supplierAddr := msg.GetSupplierAddress() + + // Helpers for logging the same metadata throughout this function calls + logger = logger.With( + "session_id", sessionHeader.GetSessionId(), + "session_end_height", sessionHeader.GetSessionEndBlockHeight(), + "supplier", supplierAddr) + + logger.Info("validated the submitProof message ") + // Basic validation of the SubmitProof message. if err := msg.ValidateBasic(); err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } // Retrieve the supplier's public key. - supplierAddr := msg.GetSupplierAddress() supplierPubKey, err := k.accountQuerier.GetPubKeyFromAddress(ctx, supplierAddr) if err != nil { return nil, status.Error(codes.FailedPrecondition, err.Error()) @@ -83,11 +101,12 @@ func (k msgServer) SubmitProof(ctx context.Context, msg *types.MsgSubmitProof) ( // Validate the session header. if _, err := k.queryAndValidateSessionHeader( ctx, - msg.GetSessionHeader(), + sessionHeader, supplierAddr, ); err != nil { return nil, status.Error(codes.InvalidArgument, err.Error()) } + logger.Info("queried and validated the session header") // Unmarshal the closest merkle proof from the message. sparseMerkleClosestProof := &smt.SparseMerkleClosestProof{} @@ -113,13 +132,6 @@ func (k msgServer) SubmitProof(ctx context.Context, msg *types.MsgSubmitProof) ( ) } - logger = logger. - With( - "session_id", msg.GetSessionHeader().GetSessionId(), - "session_end_height", msg.GetSessionHeader().GetSessionEndBlockHeight(), - "supplier", supplierAddr, - ) - // Basic validation of the relay request. relayReq := relay.GetReq() if err := relayReq.ValidateBasic(); err != nil { @@ -200,14 +212,12 @@ func (k msgServer) SubmitProof(ctx context.Context, msg *types.MsgSubmitProof) ( SessionHeader: msg.GetSessionHeader(), ClosestMerkleProof: msg.GetProof(), } + logger.Info(fmt.Sprintf("queried and validated the claim for session ID %s", sessionHeader.SessionId)) // TODO_BLOCKER: check if this proof already exists and return an appropriate error // in any case where the supplier should no longer be able to update the given proof. - k.Keeper.UpsertProof(ctx, proof) - - // TODO_UPNEXT(@Olshansk, #359): Call `tokenomics.SettleSessionAccounting()` here - - logger.Debug("successfully submitted proof") + k.UpsertProof(ctx, proof) + logger.Debug("successfully upserted the proof") return &types.MsgSubmitProofResponse{}, nil } diff --git a/x/proof/module/helpers_test.go b/x/proof/module/helpers_test.go index e613322a7..49dbafe05 100644 --- a/x/proof/module/helpers_test.go +++ b/x/proof/module/helpers_test.go @@ -23,15 +23,14 @@ import ( apptypes "github.com/pokt-network/poktroll/x/application/types" proof "github.com/pokt-network/poktroll/x/proof/module" "github.com/pokt-network/poktroll/x/proof/types" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) -// TODO_TECHDEBT: This should not be hardcoded once the num blocks per session is configurable. const ( - numBlocksPerSession = 4 - testServiceId = "svc1" + testServiceId = "svc1" ) // Dummy variable to avoid unused import error. @@ -56,7 +55,7 @@ func networkWithClaimObjects( // Construct an in-memory keyring so that it can be populated and used prior // to network start. kr := keyring.NewInMemory(cfg.Codec) - // Populate the in-memmory keyring with as many pre-generated accounts as + // Populate the in-memory keyring with as many pre-generated accounts as // we expect to need for the test (i.e. numApps + numSuppliers). testkeyring.CreatePreGeneratedKeyringAccounts(t, kr, numSuppliers+numApps) @@ -123,7 +122,7 @@ func networkWithClaimObjects( // Create numSessions * numClaimsPerSession claims for the supplier sessionEndHeight := int64(1) for sessionIdx := 0; sessionIdx < numSessions; sessionIdx++ { - sessionEndHeight += numBlocksPerSession + sessionEndHeight += sessionkeeper.NumBlocksPerSession for _, appAcct := range appAccts { for _, supplierAcct := range supplierAccts { claim := createClaim( @@ -138,7 +137,6 @@ func networkWithClaimObjects( } } } - return net, claims } @@ -154,10 +152,10 @@ func encodeSessionHeader( sessionHeader := &sessiontypes.SessionHeader{ ApplicationAddress: appAddr, - SessionStartBlockHeight: sessionStartHeight, - SessionId: sessionId, - SessionEndBlockHeight: sessionStartHeight + numBlocksPerSession, Service: &sharedtypes.Service{Id: testServiceId}, + SessionId: sessionId, + SessionStartBlockHeight: sessionStartHeight, + SessionEndBlockHeight: sessionStartHeight + sessionkeeper.NumBlocksPerSession, } cdc := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) sessionHeaderBz := cdc.MustMarshalJSON(sessionHeader) @@ -176,7 +174,7 @@ func createClaim( t.Helper() rootHash := []byte("root_hash") - sessionStartHeight := sessionEndHeight - numBlocksPerSession + sessionStartHeight := sessionEndHeight - sessionkeeper.NumBlocksPerSession sessionId := getSessionId(t, net, appAddr, supplierAddr, sessionStartHeight) sessionHeaderEncoded := encodeSessionHeader(t, appAddr, sessionId, sessionStartHeight) rootHashEncoded := base64.StdEncoding.EncodeToString(rootHash) diff --git a/x/proof/module/module.go b/x/proof/module/module.go index 07ba82954..5ad20da8b 100644 --- a/x/proof/module/module.go +++ b/x/proof/module/module.go @@ -18,8 +18,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/grpc-ecosystem/grpc-gateway/runtime" - // this line is used by starport scaffolding # 1 - modulev1 "github.com/pokt-network/poktroll/api/poktroll/proof/module" "github.com/pokt-network/poktroll/x/proof/keeper" "github.com/pokt-network/poktroll/x/proof/types" diff --git a/x/proof/module/query_claim_test.go b/x/proof/module/query_claim_test.go index a1f4513b9..76fac0069 100644 --- a/x/proof/module/query_claim_test.go +++ b/x/proof/module/query_claim_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/stretchr/testify/require" @@ -27,7 +27,7 @@ func TestClaim_Show(t *testing.T) { ctx := net.Validators[0].ClientCtx commonArgs := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } var wrongSupplierAddr = sample.AccAddress() @@ -128,7 +128,7 @@ func TestClaim_List(t *testing.T) { ctx := net.Validators[0].ClientCtx prepareArgs := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } if next == nil { args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) @@ -198,11 +198,11 @@ func TestClaim_List(t *testing.T) { var resp types.QueryAllClaimsResponse require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.Equal(t, sessionCount*numApps, int(resp.Pagination.Total)) require.ElementsMatch(t, nullify.Fill(expectedClaims), nullify.Fill(resp.Claims), ) - require.Equal(t, sessionCount*numApps, int(resp.Pagination.Total)) }) t.Run("BySession", func(t *testing.T) { @@ -223,11 +223,11 @@ func TestClaim_List(t *testing.T) { var resp types.QueryAllClaimsResponse require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.Equal(t, numSuppliers, int(resp.Pagination.Total)) require.ElementsMatch(t, nullify.Fill(expectedClaims), nullify.Fill(resp.Claims), ) - require.Equal(t, numSuppliers, int(resp.Pagination.Total)) }) t.Run("ByHeight", func(t *testing.T) { diff --git a/x/proof/types/errors.go b/x/proof/types/errors.go index 414bf467a..dc4f4116c 100644 --- a/x/proof/types/errors.go +++ b/x/proof/types/errors.go @@ -2,26 +2,29 @@ package types // DONTCOVER -import sdkerrors "cosmossdk.io/errors" +import ( + sdkerrors "cosmossdk.io/errors" +) // x/proof module sentinel errors var ( ErrProofInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message") ErrProofInvalidAddress = sdkerrors.Register(ModuleName, 1101, "invalid address") ErrProofNotFound = sdkerrors.Register(ModuleName, 1102, "supplier not found") - ErrProofInvalidSessionStartHeight = sdkerrors.Register(ModuleName, 1103, "invalid session start height") - ErrProofInvalidSessionId = sdkerrors.Register(ModuleName, 1104, "invalid session ID") - ErrProofInvalidService = sdkerrors.Register(ModuleName, 1105, "invalid service in supplier") - ErrProofInvalidClaimRootHash = sdkerrors.Register(ModuleName, 1106, "invalid root hash") - ErrProofInvalidSessionEndHeight = sdkerrors.Register(ModuleName, 1107, "invalid session ending height") - ErrProofInvalidQueryRequest = sdkerrors.Register(ModuleName, 1108, "invalid query request") - ErrProofClaimNotFound = sdkerrors.Register(ModuleName, 1109, "claim not found") - ErrProofProofNotFound = sdkerrors.Register(ModuleName, 1110, "proof not found") - ErrProofInvalidProof = sdkerrors.Register(ModuleName, 1111, "invalid proof") - ErrProofInvalidRelay = sdkerrors.Register(ModuleName, 1112, "invalid relay") - ErrProofInvalidRelayRequest = sdkerrors.Register(ModuleName, 1113, "invalid relay request") - ErrProofInvalidRelayResponse = sdkerrors.Register(ModuleName, 1114, "invalid relay response") - ErrProofNotSecp256k1Curve = sdkerrors.Register(ModuleName, 1115, "not secp256k1 curve") - ErrProofApplicationNotFound = sdkerrors.Register(ModuleName, 1116, "application not found") - ErrProofPubKeyNotFound = sdkerrors.Register(ModuleName, 1117, "public key not found") + ErrProofInvalidService = sdkerrors.Register(ModuleName, 1103, "invalid service in supplier") + ErrProofInvalidClaimRootHash = sdkerrors.Register(ModuleName, 1104, "invalid root hash") + ErrProofInvalidQueryRequest = sdkerrors.Register(ModuleName, 1105, "invalid query request") + ErrProofClaimNotFound = sdkerrors.Register(ModuleName, 1106, "claim not found") + ErrProofProofNotFound = sdkerrors.Register(ModuleName, 1107, "proof not found") + ErrProofInvalidProof = sdkerrors.Register(ModuleName, 1108, "invalid proof") + ErrProofInvalidRelay = sdkerrors.Register(ModuleName, 1109, "invalid relay") + ErrProofInvalidRelayRequest = sdkerrors.Register(ModuleName, 1110, "invalid relay request") + ErrProofInvalidRelayResponse = sdkerrors.Register(ModuleName, 1111, "invalid relay response") + ErrProofNotSecp256k1Curve = sdkerrors.Register(ModuleName, 1112, "not secp256k1 curve") + ErrProofApplicationNotFound = sdkerrors.Register(ModuleName, 1113, "application not found") + ErrProofPubKeyNotFound = sdkerrors.Register(ModuleName, 1114, "public key not found") + ErrProofInvalidSessionHeader = sdkerrors.Register(ModuleName, 1115, "invalid session header") + ErrProofInvalidSessionId = sdkerrors.Register(ModuleName, 1116, "invalid session ID") + ErrProofInvalidSessionEndHeight = sdkerrors.Register(ModuleName, 1117, "invalid session end height") + ErrProofInvalidSessionStartHeight = sdkerrors.Register(ModuleName, 1118, "invalid session start height") ) diff --git a/x/proof/types/message_create_claim.go b/x/proof/types/message_create_claim.go index a7bf0f61f..50e094d5b 100644 --- a/x/proof/types/message_create_claim.go +++ b/x/proof/types/message_create_claim.go @@ -4,7 +4,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - sharedhelpers "github.com/pokt-network/poktroll/x/shared/helpers" ) const TypeMsgCreateClaim = "create_claim" @@ -25,21 +24,17 @@ func NewMsgCreateClaim( func (msg *MsgCreateClaim) ValidateBasic() error { // Validate the supplier address - _, err := sdk.AccAddressFromBech32(msg.GetSupplierAddress()) - if err != nil { + if _, err := sdk.AccAddressFromBech32(msg.GetSupplierAddress()); err != nil { return ErrProofInvalidAddress.Wrapf("%s", msg.GetSupplierAddress()) } - // Validate the session header + // Retrieve & validate the session header sessionHeader := msg.SessionHeader - if sessionHeader.SessionStartBlockHeight < 0 { - return ErrProofInvalidSessionStartHeight.Wrapf("%d", sessionHeader.SessionStartBlockHeight) + if sessionHeader == nil { + return ErrProofInvalidSessionHeader.Wrapf("session header is nil") } - if len(sessionHeader.SessionId) == 0 { - return ErrProofInvalidSessionId.Wrapf("%s", sessionHeader.SessionId) - } - if !sharedhelpers.IsValidService(sessionHeader.Service) { - return ErrProofInvalidService.Wrapf("%v", sessionHeader.Service) + if err := sessionHeader.ValidateBasic(); err != nil { + return ErrProofInvalidSessionHeader.Wrapf("invalid session header: %v", err) } // Validate the root hash diff --git a/x/proof/types/message_create_claim_test.go b/x/proof/types/message_create_claim_test.go index 5c1572866..68befb3ce 100644 --- a/x/proof/types/message_create_claim_test.go +++ b/x/proof/types/message_create_claim_test.go @@ -3,11 +3,11 @@ package types import ( "testing" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/testutil/sample" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" - - "github.com/stretchr/testify/require" ) func TestMsgCreateClaim_ValidateBasic(t *testing.T) { @@ -18,35 +18,49 @@ func TestMsgCreateClaim_ValidateBasic(t *testing.T) { expectedErr error }{ { - desc: "invalid address", + desc: "invalid supplier address", msg: MsgCreateClaim{ SupplierAddress: "invalid_address", + SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: "svcId"}, + SessionStartBlockHeight: 100, + SessionEndBlockHeight: 101, + SessionId: "valid_session_id", + }, }, expectedErr: ErrProofInvalidAddress, }, { - desc: "valid address but invalid session start height", + desc: "valid supplier address but invalid session start height", msg: MsgCreateClaim{ SupplierAddress: sample.AccAddress(), SessionHeader: &sessiontypes.SessionHeader{ - SessionStartBlockHeight: -1, // Invalid start height + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: "svcId"}, + SessionStartBlockHeight: -1, + SessionEndBlockHeight: 101, + SessionId: "valid_session_id", }, }, - expectedErr: ErrProofInvalidSessionStartHeight, + expectedErr: ErrProofInvalidSessionHeader, }, { - desc: "valid address and session start height but invalid session ID", + desc: "valid supplier address and session start height but invalid session ID", msg: MsgCreateClaim{ SupplierAddress: sample.AccAddress(), SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: "svcId"}, SessionStartBlockHeight: 100, - SessionId: "", // Invalid session ID + SessionEndBlockHeight: 101, + SessionId: "", }, }, - expectedErr: ErrProofInvalidSessionId, + expectedErr: ErrProofInvalidSessionHeader, }, { desc: "valid address, session start height, session ID but invalid service", @@ -54,14 +68,14 @@ func TestMsgCreateClaim_ValidateBasic(t *testing.T) { msg: MsgCreateClaim{ SupplierAddress: sample.AccAddress(), SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: "invalid service id"}, SessionStartBlockHeight: 100, + SessionEndBlockHeight: 101, SessionId: "valid_session_id", - Service: &sharedtypes.Service{ - Id: "invalid_service_id", // Assuming this ID is invalid - }, // Should trigger error }, }, - expectedErr: ErrProofInvalidService, + expectedErr: ErrProofInvalidSessionHeader, }, { desc: "valid address, session start height, session ID, service but invalid root hash", @@ -69,11 +83,11 @@ func TestMsgCreateClaim_ValidateBasic(t *testing.T) { msg: MsgCreateClaim{ SupplierAddress: sample.AccAddress(), SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: "svcId"}, SessionStartBlockHeight: 100, + SessionEndBlockHeight: 101, SessionId: "valid_session_id", - Service: &sharedtypes.Service{ - Id: "svcId", // Assuming this ID is valid - }, }, RootHash: []byte(""), // Invalid root hash }, @@ -85,11 +99,11 @@ func TestMsgCreateClaim_ValidateBasic(t *testing.T) { msg: MsgCreateClaim{ SupplierAddress: sample.AccAddress(), SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + Service: &sharedtypes.Service{Id: "svcId"}, SessionStartBlockHeight: 100, + SessionEndBlockHeight: 101, SessionId: "valid_session_id", - Service: &sharedtypes.Service{ - Id: "svcId", // Assuming this ID is valid - }, }, RootHash: []byte("valid_root_hash"), // Assuming this is valid }, diff --git a/x/proof/types/message_submit_proof_test.go b/x/proof/types/message_submit_proof_test.go index 9ad93c91b..a1ea571d1 100644 --- a/x/proof/types/message_submit_proof_test.go +++ b/x/proof/types/message_submit_proof_test.go @@ -4,12 +4,12 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/sample" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" - - "github.com/stretchr/testify/require" ) func TestMsgSubmitProof_ValidateBasic(t *testing.T) { @@ -28,9 +28,9 @@ func TestMsgSubmitProof_ValidateBasic(t *testing.T) { SessionHeader: &sessiontypes.SessionHeader{ ApplicationAddress: "not_a_bech32_address", Service: testService, - SessionStartBlockHeight: 0, SessionId: "mock_session_id", - SessionEndBlockHeight: 5, + SessionStartBlockHeight: 1, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, Proof: testClosestMerkleProof, }, @@ -47,9 +47,9 @@ func TestMsgSubmitProof_ValidateBasic(t *testing.T) { SessionHeader: &sessiontypes.SessionHeader{ ApplicationAddress: sample.AccAddress(), Service: testService, - SessionStartBlockHeight: 0, SessionId: "mock_session_id", - SessionEndBlockHeight: 5, + SessionStartBlockHeight: 1, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, Proof: testClosestMerkleProof, }, @@ -66,9 +66,9 @@ func TestMsgSubmitProof_ValidateBasic(t *testing.T) { SessionHeader: &sessiontypes.SessionHeader{ ApplicationAddress: sample.AccAddress(), Service: &sharedtypes.Service{Id: ""}, - SessionStartBlockHeight: 0, SessionId: "mock_session_id", - SessionEndBlockHeight: 5, + SessionStartBlockHeight: 1, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, Proof: testClosestMerkleProof, }, @@ -82,8 +82,8 @@ func TestMsgSubmitProof_ValidateBasic(t *testing.T) { ApplicationAddress: sample.AccAddress(), Service: testService, SessionId: "mock_session_id", - SessionStartBlockHeight: 0, - SessionEndBlockHeight: 5, + SessionStartBlockHeight: 1, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, Proof: testClosestMerkleProof, }, diff --git a/x/session/keeper/query_get_session.go b/x/session/keeper/query_get_session.go index 02d515b9b..9c6e30579 100644 --- a/x/session/keeper/query_get_session.go +++ b/x/session/keeper/query_get_session.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -26,7 +27,7 @@ func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionReques // while the `Msg` server handles the code flow of the validator when a new block is being proposed. blockHeight := req.BlockHeight - k.Logger().Info("Getting session for height: %d", blockHeight) + k.Logger().Debug(fmt.Sprintf("Getting session for height: %d", blockHeight)) sessionHydrator := NewSessionHydrator(req.ApplicationAddress, req.Service.Id, blockHeight) session, err := k.HydrateSession(ctx, sessionHydrator) diff --git a/x/session/keeper/session_hydrator.go b/x/session/keeper/session_hydrator.go index 37a1376cf..73a4c3dcc 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -73,7 +73,7 @@ func (k Keeper) HydrateSession(ctx context.Context, sh *sessionHydrator) (*types if err := k.hydrateSessionID(ctx, sh); err != nil { return nil, err } - logger.Info(fmt.Sprintf("Finished hydrating session ID: %s", sh.sessionHeader.SessionId)) + logger.Debug(fmt.Sprintf("Finished hydrating session ID: %s", sh.sessionHeader.SessionId)) if err := k.hydrateSessionApplication(ctx, sh); err != nil { return nil, err diff --git a/x/session/module/module.go b/x/session/module/module.go index a8c55809b..e4bf737be 100644 --- a/x/session/module/module.go +++ b/x/session/module/module.go @@ -18,8 +18,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/grpc-ecosystem/grpc-gateway/runtime" - // this line is used by starport scaffolding # 1 - modulev1 "github.com/pokt-network/poktroll/api/poktroll/session/module" "github.com/pokt-network/poktroll/x/session/keeper" "github.com/pokt-network/poktroll/x/session/types" @@ -151,12 +149,18 @@ func (am AppModule) BeginBlock(_ context.Context) error { // EndBlock contains the logic that is automatically triggered at the end of each block. // The end block implementation is optional. -func (am AppModule) EndBlock(ctx context.Context) error { - // Store the block hash at the end of every block, so we can query the block hash - // to construct the SessionID. +// TODO_TECHDEBT( @red-0ne): Add unit/integration tests for this. +func (am AppModule) EndBlock(goCtx context.Context) error { + logger := am.keeper.Logger().With("EndBlock", "SessionModuleEndBlock") + ctx := sdk.UnwrapSDKContext(goCtx) + blockHeight := ctx.BlockHeight() + + // Store the block hash at the end of every block. + // This is necessary to correctly and pseudo-randomly construct a SessionID. // EndBlock is preferred over BeginBlock to avoid wasting resources if the block // does not get committed. am.keeper.StoreBlockHash(ctx) + logger.Info(fmt.Sprintf("Stored block hash at height %d", blockHeight)) return nil } diff --git a/x/session/module/query_get_session_test.go b/x/session/module/query_get_session_test.go index f2b230d1e..8c695432c 100644 --- a/x/session/module/query_get_session_test.go +++ b/x/session/module/query_get_session_test.go @@ -6,7 +6,7 @@ import ( "time" sdkerrors "cosmossdk.io/errors" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/gogo/status" "github.com/stretchr/testify/require" @@ -157,7 +157,7 @@ func TestCLI_GetSession(t *testing.T) { // We want to use the `--output=json` flag for all tests so it's easy to unmarshal below common := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } // Run the tests diff --git a/x/session/types/session_header.go b/x/session/types/session_header.go index 6e3daa1d0..a871bcfd8 100644 --- a/x/session/types/session_header.go +++ b/x/session/types/session_header.go @@ -1,6 +1,10 @@ package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + sharedhelpers "github.com/pokt-network/poktroll/x/shared/helpers" +) // TODO_TECHDEBT: Make sure this is used everywhere we validate components // of the session header. @@ -11,17 +15,20 @@ func (sh *SessionHeader) ValidateBasic() error { } // Validate the session ID - // TODO_TECHDEBT: Introduce a `SessionId#ValidateBasic` method. - if sh.SessionId == "" { + if len(sh.SessionId) == 0 { return ErrSessionInvalidSessionId.Wrapf("invalid session ID: %s", sh.SessionId) } // Validate the service - // TODO_TECHDEBT: Introduce a `Service#ValidateBasic` method. - if sh.Service == nil { + if sh.Service == nil || !sharedhelpers.IsValidService(sh.Service) { return ErrSessionInvalidService.Wrapf("invalid service: %s", sh.Service) } + // Sessions can only start at height 1 + if sh.SessionStartBlockHeight <= 0 { + return ErrSessionInvalidBlockHeight.Wrapf("sessions can only start at height 1 or greater") + } + // Check if session end height is greater than session start height if sh.SessionEndBlockHeight <= sh.SessionStartBlockHeight { return ErrSessionInvalidBlockHeight.Wrapf("session end block height cannot be less than or equal to session start block height") diff --git a/x/session/types/session_header_test.go b/x/session/types/session_header_test.go index 5d952be42..02b99f882 100644 --- a/x/session/types/session_header_test.go +++ b/x/session/types/session_header_test.go @@ -11,6 +11,11 @@ import ( ) func TestSessionHeader_ValidateBasic(t *testing.T) { + svc := sharedtypes.Service{ + Id: "svc_id", + Name: "svc_name", + } + tests := []struct { desc string sessionHeader types.SessionHeader @@ -21,7 +26,7 @@ func TestSessionHeader_ValidateBasic(t *testing.T) { sessionHeader: types.SessionHeader{ ApplicationAddress: "invalid_address", SessionId: "valid_session_id", - Service: &sharedtypes.Service{}, + Service: &svc, SessionStartBlockHeight: 100, SessionEndBlockHeight: 101, }, @@ -32,7 +37,7 @@ func TestSessionHeader_ValidateBasic(t *testing.T) { sessionHeader: types.SessionHeader{ ApplicationAddress: sample.AccAddress(), SessionId: "", - Service: &sharedtypes.Service{}, + Service: &svc, SessionStartBlockHeight: 100, SessionEndBlockHeight: 101, }, @@ -49,12 +54,23 @@ func TestSessionHeader_ValidateBasic(t *testing.T) { }, expectedErr: types.ErrSessionInvalidService, }, + { + desc: "invalid - start block height is 0", + sessionHeader: types.SessionHeader{ + ApplicationAddress: sample.AccAddress(), + SessionId: "valid_session_id", + Service: &svc, + SessionStartBlockHeight: 0, + SessionEndBlockHeight: 42, + }, + expectedErr: types.ErrSessionInvalidBlockHeight, + }, { desc: "invalid - start block height greater than end block height", sessionHeader: types.SessionHeader{ ApplicationAddress: sample.AccAddress(), SessionId: "valid_session_id", - Service: &sharedtypes.Service{}, + Service: &svc, SessionStartBlockHeight: 100, SessionEndBlockHeight: 99, }, @@ -65,7 +81,7 @@ func TestSessionHeader_ValidateBasic(t *testing.T) { sessionHeader: types.SessionHeader{ ApplicationAddress: sample.AccAddress(), SessionId: "valid_session_id", - Service: &sharedtypes.Service{}, + Service: &svc, SessionStartBlockHeight: 100, SessionEndBlockHeight: 101, }, diff --git a/x/shared/helpers/service.go b/x/shared/helpers/service.go index 2632769e6..9c1071871 100644 --- a/x/shared/helpers/service.go +++ b/x/shared/helpers/service.go @@ -28,6 +28,7 @@ func init() { } // IsValidService checks if the provided ServiceId struct has valid fields +// TODO_TECHDEBT: Refactor to a `Service#ValidateBasic` method. func IsValidService(service *sharedtypes.Service) bool { // Check if service Id and Name are valid using the provided helper functions return service != nil && @@ -36,6 +37,7 @@ func IsValidService(service *sharedtypes.Service) bool { } // IsValidServiceId checks if the input string is a valid serviceId +// TODO_TECHDEBT: Refactor to a `ServiceId#ValidateBasic` method. func IsValidServiceId(serviceId string) bool { // ServiceId CANNOT be empty if len(serviceId) == 0 { diff --git a/x/supplier/module/query_supplier_test.go b/x/supplier/module/query_supplier_test.go index 6cb48bf5d..d741481f2 100644 --- a/x/supplier/module/query_supplier_test.go +++ b/x/supplier/module/query_supplier_test.go @@ -5,7 +5,7 @@ import ( "strconv" "testing" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/stretchr/testify/require" @@ -23,7 +23,7 @@ func TestShowSupplier(t *testing.T) { ctx := net.Validators[0].ClientCtx common := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } tests := []struct { desc string @@ -79,7 +79,7 @@ func TestListSuppliers(t *testing.T) { ctx := net.Validators[0].ClientCtx request := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), } if next == nil { args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) diff --git a/x/tokenomics/keeper/keeper.go b/x/tokenomics/keeper/keeper.go index 03bc1c80a..f1e254164 100644 --- a/x/tokenomics/keeper/keeper.go +++ b/x/tokenomics/keeper/keeper.go @@ -11,31 +11,21 @@ import ( "github.com/pokt-network/poktroll/x/tokenomics/types" ) -// Keeper is the structure that implements the `KeeperI` interface. +type Keeper struct { + cdc codec.BinaryCodec + storeService store.KVStoreService + logger log.Logger -// TODO_TECHDEBT(#240): See `x/nft/keeper.keeper.go` in the Cosmos SDK on how -// we should refactor all our keepers. This keeper has started following a small -// subset of those patterns. -type ( - Keeper struct { - cdc codec.BinaryCodec - storeService store.KVStoreService - logger log.Logger + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string - // the address capable of executing a MsgUpdateParams message. Typically, this - // should be the x/gov module account. - authority string - - bankKeeper types.BankKeeper - accountKeeper types.AccountKeeper - applicationKeeper types.ApplicationKeeper - - // TODO_DISCUSS: The supplier keeper is not used in the tokenomics module, - // the bank keeper is the one that is used to handle the supplier rewards. - // Make sure to remove it from the expected keepers if removed from here. - supplierKeeper types.SupplierKeeper - } -) + // keepers + bankKeeper types.BankKeeper + accountKeeper types.AccountKeeper + applicationKeeper types.ApplicationKeeper + proofKeeper types.ProofKeeper +} func NewKeeper( cdc codec.BinaryCodec, @@ -46,7 +36,7 @@ func NewKeeper( bankKeeper types.BankKeeper, accountKeeper types.AccountKeeper, applicationKeeper types.ApplicationKeeper, - supplierKeeper types.SupplierKeeper, + proofKeeper types.ProofKeeper, ) Keeper { if _, err := sdk.AccAddressFromBech32(authority); err != nil { panic(fmt.Sprintf("invalid authority address: %s", authority)) @@ -61,7 +51,7 @@ func NewKeeper( bankKeeper: bankKeeper, accountKeeper: accountKeeper, applicationKeeper: applicationKeeper, - supplierKeeper: supplierKeeper, + proofKeeper: proofKeeper, } } diff --git a/x/tokenomics/keeper/keeper_test.go b/x/tokenomics/keeper/keeper_test.go new file mode 100644 index 000000000..4ad0abd34 --- /dev/null +++ b/x/tokenomics/keeper/keeper_test.go @@ -0,0 +1,124 @@ +package keeper_test + +import ( + "context" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/pokt-network/poktroll/cmd/poktrolld/cmd" + keepertest "github.com/pokt-network/poktroll/testutil/keeper" + "github.com/pokt-network/poktroll/testutil/sample" + prooftypes "github.com/pokt-network/poktroll/x/proof/types" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" + sessiontypes "github.com/pokt-network/poktroll/x/session/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" +) + +const ( + testServiceId = "svc1" + testSessionId = "mock_session_id" +) +const minExecutionPeriod = 5 * time.Second + +func init() { + cmd.InitSDKConfig() +} + +type TestSuite struct { + suite.Suite + + sdkCtx sdk.Context + ctx context.Context + keepers keepertest.TokenomicsModuleKeepers + claim prooftypes.Claim +} + +func (s *TestSuite) SetupTest() { + supplierAddr := sample.AccAddress() + appAddr := sample.AccAddress() + + // Prepare and insert the claim + s.claim = prooftypes.Claim{ + SupplierAddress: supplierAddr, + SessionHeader: &sessiontypes.SessionHeader{ + ApplicationAddress: appAddr, + Service: &sharedtypes.Service{Id: testServiceId}, + SessionId: "session_id", + SessionStartBlockHeight: 1, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, + }, + RootHash: []byte("default_roo_hash"), + } + + s.keepers, s.ctx = keepertest.NewTokenomicsModuleKeepers(s.T()) + s.sdkCtx = sdk.UnwrapSDKContext(s.ctx) +} + +func TestSettleExpiringSuite(t *testing.T) { + suite.Run(t, new(TestSuite)) +} + +// TODO_IN_THIS_PR(@Olshansk): Things to test +// 1. Balance changes (up and down) +// 2. Claim that requires a proof but doesn't have one expires +// 3. Claim that requires a proof and has one settles +// 4. Claim that doesn't require a proof settles +// 5. Expand on other test cases to add in the future +// 6. Validate the emitted events + +func (s *TestSuite) TestClaimSettlesAfterProofWindowCloses() { + // Retrieve default values + t := s.T() + ctx := s.ctx + sdkCtx := sdk.UnwrapSDKContext(ctx) + claim := s.claim + + // Add the claim & verify it exists + s.keepers.UpsertClaim(ctx, claim) + claims := s.keepers.GetAllClaims(ctx) + s.Require().Len(claims, 1) + + // Settle expiring claims at height 2 (while the session is still active). + // Expectations: No claims should be settled because the session is still ongoing + sdkCtx = sdkCtx.WithBlockHeight(claim.SessionHeader.SessionEndBlockHeight - 2) + numClaimsSettled, numClaimsExpired, err := s.keepers.SettlePendingClaims(sdkCtx) + // Check that no claims were settled + require.NoError(t, err) + require.Equal(t, uint64(0), numClaimsSettled) + require.Equal(t, uint64(0), numClaimsExpired) + // Validate that the claim still exists + claims = s.keepers.GetAllClaims(ctx) + require.Len(t, claims, 1) + + // Try to settle expiring claim a little after it ended. + // Goal: Claims should not be settled because the proof window hasn't closed yet. + sdkCtx = sdkCtx.WithBlockHeight(claim.SessionHeader.SessionEndBlockHeight + 2) + numClaimsSettled, numClaimsExpired, err = s.keepers.SettlePendingClaims(sdkCtx) + // Check that no claims were settled + require.NoError(t, err) + require.Equal(t, uint64(0), numClaimsSettled) + require.Equal(t, uint64(0), numClaimsExpired) + // Validate that the claim still exists + claims = s.keepers.GetAllClaims(ctx) + require.Len(t, claims, 1) + + // Try to settle expiring claims a long time after it ended + // Expectation: All (1) claims should be settled. + sdkCtx = sdkCtx.WithBlockHeight(claim.SessionHeader.SessionEndBlockHeight * 10) + numClaimsSettled, numClaimsExpired, err = s.keepers.SettlePendingClaims(sdkCtx) + // Check that no claims were settled + require.NoError(t, err) + require.Equal(t, uint64(0), numClaimsSettled) + require.Equal(t, uint64(0), numClaimsExpired) + // Validate that the claims expired + claims = s.keepers.GetAllClaims(ctx) + require.Len(t, claims, 0) + + // Confirm an expiration event was emitted + events := sdkCtx.EventManager().Events() + require.Len(t, events, 1) +} diff --git a/x/tokenomics/keeper/settle_pending_claims.go b/x/tokenomics/keeper/settle_pending_claims.go new file mode 100644 index 000000000..9f3ed5c34 --- /dev/null +++ b/x/tokenomics/keeper/settle_pending_claims.go @@ -0,0 +1,145 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/smt" + + prooftypes "github.com/pokt-network/poktroll/x/proof/types" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" + "github.com/pokt-network/poktroll/x/tokenomics/types" +) + +const ( + // TODO_BLOCKER/TODO_UPNEXT(@Olshansk): Implement this properly. Using a constant + // for "probabilistic proofs" is just a simple placeholder mechanism to get + // #359 over the finish line. + ProofRequiredComputeUnits = 100 +) + +// SettlePendingClaims settles all pending (i.e. expiring) claims. +// If a claim is expired and requires a proof and a proof IS available -> it's settled. +// If a claim is expired and requires a proof and a proof IS NOT available -> it's deleted. +// If a claim is expired and does NOT require a proof -> it's settled. +// Events are emitted for each claim that is settled or removed. +// On-chain Claims & Proofs are deleted after they're settled or expired to free up space. +func (k Keeper) SettlePendingClaims(ctx sdk.Context) (numClaimsSettled, numClaimsExpired uint64, err error) { + logger := k.Logger().With("method", "SettlePendingClaims") + + // TODO_BLOCKER(@Olshansk): Optimize this by indexing expiringClaims appropriately + // and only retrieving the expiringClaims that need to be settled rather than all + // of them and iterating through them one by one. + expiringClaims, err := k.getExpiringClaims(ctx) + if err != nil { + logger.Error(fmt.Sprintf("error getting expiring claims: %v", err)) + return 0, 0, err + } + + blockHeight := ctx.BlockHeight() + + for _, claim := range expiringClaims { + // Retrieve the number of compute units in the claim for the events emitted + root := (smt.MerkleRoot)(claim.GetRootHash()) + claimComputeUnits := root.Sum() + + sessionId := claim.SessionHeader.SessionId + + // Using the probabilistic proofs approach, determine if this expiring + // claim required an on-chain proof + isProofRequiredForClaim, err := k.isProofRequiredForClaim(ctx, &claim) + if err != nil { + logger.Error(fmt.Sprintf("error checking if proof is required for claim %s: %v", sessionId, err)) + return 0, 0, err + } + if isProofRequiredForClaim { + _, isProofFound := k.proofKeeper.GetProof(ctx, sessionId, claim.SupplierAddress) + // If a proof is not found, the claim will expire and never be settled. + if !isProofFound { + // Emit an event that a claim has expired and being removed without being settled. + claimExpiredEvent := types.EventClaimExpired{ + Claim: &claim, + ComputeUnits: claimComputeUnits, + } + if err := ctx.EventManager().EmitTypedEvent(&claimExpiredEvent); err != nil { + return 0, 0, err + } + // The claim & proof are no longer necessary, so there's no need for them + // to take up on-chain space. + k.proofKeeper.RemoveClaim(ctx, sessionId, claim.SupplierAddress) + continue + } + // NB: If a proof is found, it is valid because verification is done + // at the time of submission. + } + + // Manage the mint & burn accounting for the claim. + if err := k.SettleSessionAccounting(ctx, &claim); err != nil { + logger.Error(fmt.Sprintf("error settling session accounting for claim %s: %v", claim.SessionHeader.SessionId, err)) + return 0, 0, err + } + + claimExpiredEvent := types.EventClaimSettled{ + Claim: &claim, + ComputeUnits: claimComputeUnits, + ProofRequired: isProofRequiredForClaim, + } + if err := ctx.EventManager().EmitTypedEvent(&claimExpiredEvent); err != nil { + return 0, 0, err + } + + // The claim & proof are no longer necessary, so there's no need for them + // to take up on-chain space. + k.proofKeeper.RemoveClaim(ctx, sessionId, claim.SupplierAddress) + k.proofKeeper.RemoveProof(ctx, sessionId, claim.SupplierAddress) + + numClaimsSettled++ + logger.Info(fmt.Sprintf("Successfully settled claim %s at block height %d", claim.SessionHeader.SessionId, blockHeight)) + } + + logger.Info(fmt.Sprintf("settled %d claims at block height %d", numClaimsSettled, blockHeight)) + + return numClaimsSettled, numClaimsExpired, nil + +} + +// getExpiringClaims returns all claims that are expiring at the current block height. +// This is the height at which the proof window closes. +// If the proof window closes and a proof IS NOT required -> settle the claim. +// If the proof window closes and a proof IS required -> only settle it if a proof is available. +func (k Keeper) getExpiringClaims(ctx sdk.Context) (expiringClaims []prooftypes.Claim, err error) { + blockHeight := ctx.BlockHeight() + + // TODO_BLOCKER: query the on-chain governance parameter once available. + submitProofWindowEndHeight := sessionkeeper.GetSessionGracePeriodBlockCount() + + // TODO_BLOCKER(@Olshansk): Optimize this by indexing claims appropriately + // and only retrieving the claims that need to be settled rather than all + // of them and iterating through them one by one. + claims := k.proofKeeper.GetAllClaims(ctx) + + // Loop over all claims we need to check for expiration + for _, claim := range claims { + expirationHeight := claim.SessionHeader.SessionEndBlockHeight + submitProofWindowEndHeight + if blockHeight >= expirationHeight { + expiringClaims = append(expiringClaims, claim) + } + } + + // Return the actually expiring claims + return expiringClaims, nil +} + +// isProofRequiredForClaim checks if a proof is required for a claim. +// If it is not, the claim will be settled without a proof. +// If it is, the claim will only be settled if a valid proof is available. +func (k Keeper) isProofRequiredForClaim(_ sdk.Context, claim *prooftypes.Claim) (bool, error) { + // NB: Assumption that claim is non-nil and has a valid root sum because it + // is retrieved from the store. + root := (smt.MerkleRoot)(claim.GetRootHash()) + claimComputeUnits := root.Sum() + if claimComputeUnits < ProofRequiredComputeUnits { + return false, nil + } + return true, nil +} diff --git a/x/tokenomics/keeper/settle_session_accounting.go b/x/tokenomics/keeper/settle_session_accounting.go index 00f94d343..2bcc1ec99 100644 --- a/x/tokenomics/keeper/settle_session_accounting.go +++ b/x/tokenomics/keeper/settle_session_accounting.go @@ -21,8 +21,6 @@ const ( smstRootSize = 40 ) -// atomic.if this function is not atomic. - // SettleSessionAccounting is responsible for all of the post-session accounting // necessary to burn, mint or transfer tokens depending on the amount of work // done. The amount of "work done" complete is dictated by `sum` of `root`. @@ -31,64 +29,72 @@ const ( // against a proof BEFORE calling this function. // // TODO_BLOCKER(@Olshansk): Is there a way to limit who can call this function? -func (k Keeper) SettleSessionAccounting(ctx context.Context, claim *prooftypes.Claim) error { - // Parse the context +func (k Keeper) SettleSessionAccounting( + ctx context.Context, + claim *prooftypes.Claim, +) error { logger := k.Logger().With("method", "SettleSessionAccounting") + // Make sure the claim is not nil if claim == nil { logger.Error("received a nil claim") return types.ErrTokenomicsClaimNil } + // Retrieve & validate the session header sessionHeader := claim.GetSessionHeader() - - // Make sure the session header is not nil if sessionHeader == nil { logger.Error("received a nil session header") return types.ErrTokenomicsSessionHeaderNil } - - // Validate the session header if err := sessionHeader.ValidateBasic(); err != nil { logger.Error("received an invalid session header", "error", err) return types.ErrTokenomicsSessionHeaderInvalid } - // Decompose the claim into its constituent parts for readability supplierAddr, err := sdk.AccAddressFromBech32(claim.GetSupplierAddress()) - if err != nil { + if err != nil || supplierAddr == nil { return types.ErrTokenomicsSupplierAddressInvalid } applicationAddress, err := sdk.AccAddressFromBech32(sessionHeader.GetApplicationAddress()) - if err != nil { + if err != nil || applicationAddress == nil { return types.ErrTokenomicsApplicationAddressInvalid } - // Retrieve the application - application, found := k.applicationKeeper.GetApplication(ctx, applicationAddress.String()) - if !found { - logger.Error(fmt.Sprintf("application for claim with address %s not found", applicationAddress)) - return types.ErrTokenomicsApplicationNotFound - } - + // Retrieve the sum of the root as a proxy into the amount of work done root := (smt.MerkleRoot)(claim.GetRootHash()) // TODO_DISCUSS: This check should be the responsibility of the SMST package // since it's used to get compute units from the root hash. - if len(root) != smstRootSize { + if root == nil || len(root) != smstRootSize { logger.Error(fmt.Sprintf("received an invalid root hash of size: %d", len(root))) return types.ErrTokenomicsRootHashInvalid } - - // Retrieve the sum of the root as a proxy into the amount of work done claimComputeUnits := root.Sum() + // Helpers for logging the same metadata throughout this function calls + logger = logger.With( + "compute_units", claimComputeUnits, + "session_id", sessionHeader.GetSessionId(), + "supplier", supplierAddr, + "application", applicationAddress, + ) + + logger.Info("About to start session settlement accounting") + + // Retrieve the staked application record + application, foundApplication := k.applicationKeeper.GetApplication(ctx, applicationAddress.String()) + if !foundApplication { + logger.Error(fmt.Sprintf("application for claim with address %s not found", applicationAddress)) + return types.ErrTokenomicsApplicationNotFound + } + logger.Info(fmt.Sprintf("About to start settling claim for %d compute units", claimComputeUnits)) // Calculate the amount of tokens to mint & burn settlementAmt := k.getCoinFromComputeUnits(ctx, root) - settlementAmtCoins := sdk.NewCoins(settlementAmt) + settlementAmtuPOKT := sdk.NewCoins(settlementAmt) logger.Info(fmt.Sprintf( "%d compute units equate to %s for session %s", @@ -102,8 +108,9 @@ func (k Keeper) SettleSessionAccounting(ctx context.Context, claim *prooftypes.C // order economic effects with more optionality. This could include funds // going to pnf, delegators, enabling bonuses/rebates, etc... - // Mint uPOKT to the supplier module account - if err := k.bankKeeper.MintCoins(ctx, suppliertypes.ModuleName, settlementAmtCoins); err != nil { + // Mint new uPOKT to the supplier module account. + // These funds will be transferred to the supplier below. + if err := k.bankKeeper.MintCoins(ctx, suppliertypes.ModuleName, settlementAmtuPOKT); err != nil { return types.ErrTokenomicsSupplierModuleMintFailed.Wrapf( "minting %s to the supplier module account: %v", settlementAmt, @@ -113,9 +120,10 @@ func (k Keeper) SettleSessionAccounting(ctx context.Context, claim *prooftypes.C logger.Info(fmt.Sprintf("minted %s in the supplier module", settlementAmt)) - // Sent the minted coins to the supplier + // Send the newley minted uPOKT from the supplier module account + // to the supplier's account. if err := k.bankKeeper.SendCoinsFromModuleToAccount( - ctx, suppliertypes.ModuleName, supplierAddr, settlementAmtCoins, + ctx, suppliertypes.ModuleName, supplierAddr, settlementAmtuPOKT, ); err != nil { return types.ErrTokenomicsSupplierModuleMintFailed.Wrapf( "sending %s to supplier with address %s: %v", @@ -132,49 +140,56 @@ func (k Keeper) SettleSessionAccounting(ctx context.Context, claim *prooftypes.C logger.Error(fmt.Sprintf( "THIS SHOULD NOT HAPPEN. Application with address %s needs to be charged more than it has staked: %v > %v", applicationAddress, - settlementAmtCoins, + settlementAmtuPOKT, application.Stake, )) // TODO_BLOCKER(@Olshansk, @RawthiL): The application was over-serviced in the last session so it basically // goes "into debt". Need to design a way to handle this when we implement // probabilistic proofs and add all the parameter logic. Do we touch the application balance? // Do we just let it go into debt? Do we penalize the application? Do we unstake it? Etc... - settlementAmtCoins = sdk.NewCoins(*application.Stake) + settlementAmtuPOKT = sdk.NewCoins(*application.Stake) } - // Undelegate the amount of coins that need to be burnt from the application stake. + // Undelegate the amount of uPOKT that need to be burnt from the application's stake. // Since the application commits a certain amount of stake to the network to be able // to pay for relay mining, this stake is taken from the funds "in escrow" rather // than its balance. - if err := k.bankKeeper.UndelegateCoinsFromModuleToAccount(ctx, apptypes.ModuleName, applicationAddress, settlementAmtCoins); err != nil { + if err := k.bankKeeper.UndelegateCoinsFromModuleToAccount( + ctx, apptypes.ModuleName, applicationAddress, settlementAmtuPOKT, + ); err != nil { logger.Error(fmt.Sprintf( "THIS SHOULD NOT HAPPEN. Application with address %s needs to be charged more than it has staked: %v > %v", applicationAddress, - settlementAmtCoins, + settlementAmtuPOKT, application.Stake, )) } - // Send coins from the application to the application module account + // Update the application's on-chain stake + newAppStake := (*application.Stake).Sub(settlementAmt) + application.Stake = &newAppStake + k.applicationKeeper.SetApplication(ctx, application) + + logger.Info(fmt.Sprintf("unstaked %s uPOKT from the application with address %s to pay for on-chain service", settlementAmt, applicationAddress)) + + // Send the uPOKT to be burnt from the application's balance to the + // application module account. if err := k.bankKeeper.SendCoinsFromAccountToModule( - ctx, applicationAddress, apptypes.ModuleName, settlementAmtCoins, + ctx, applicationAddress, apptypes.ModuleName, settlementAmtuPOKT, ); err != nil { return types.ErrTokenomicsApplicationModuleFeeFailed } - logger.Info(fmt.Sprintf("took %s from application with address %s", settlementAmt, applicationAddress)) + logger.Info(fmt.Sprintf("took %s uPOKT from application with address %s", settlementAmt, applicationAddress)) // Burn uPOKT from the application module account - if err := k.bankKeeper.BurnCoins(ctx, apptypes.ModuleName, settlementAmtCoins); err != nil { + if err := k.bankKeeper.BurnCoins(ctx, apptypes.ModuleName, settlementAmtuPOKT); err != nil { return types.ErrTokenomicsApplicationModuleBurn } - logger.Info(fmt.Sprintf("burned %s in the application module", settlementAmt)) + // TODO_UPNEXT(@Olshansk): Emit burn & mint events as a result of session settlement. - // Update the application's on-chain stake - newAppStake := (*application.Stake).Sub(settlementAmt) - application.Stake = &newAppStake - k.applicationKeeper.SetApplication(ctx, application) + logger.Info(fmt.Sprintf("burned %s from the application module account", settlementAmt)) return nil } diff --git a/x/tokenomics/keeper/settle_session_accounting_test.go b/x/tokenomics/keeper/settle_session_accounting_test.go index ec7f75360..f37ef483d 100644 --- a/x/tokenomics/keeper/settle_session_accounting_test.go +++ b/x/tokenomics/keeper/settle_session_accounting_test.go @@ -11,6 +11,7 @@ import ( testkeeper "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" prooftypes "github.com/pokt-network/poktroll/x/proof/types" + sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/tokenomics/types" @@ -48,9 +49,9 @@ func TestSettleSessionAccounting_AppNotFound(t *testing.T) { Id: "svc1", Name: "svcName1", }, + SessionId: "session_id", SessionStartBlockHeight: 1, - SessionId: "1", - SessionEndBlockHeight: 5, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, RootHash: smstRootWithSum(42), } @@ -252,9 +253,9 @@ func baseClaim(appAddr, supplierAddr string, sum uint64) prooftypes.Claim { Id: "svc1", Name: "svcName1", }, + SessionId: "session_id", SessionStartBlockHeight: 1, - SessionId: "1", - SessionEndBlockHeight: 5, + SessionEndBlockHeight: 1 + sessionkeeper.NumBlocksPerSession, }, RootHash: smstRootWithSum(sum), } diff --git a/x/tokenomics/module/abci.go b/x/tokenomics/module/abci.go new file mode 100644 index 000000000..ebbdc9f49 --- /dev/null +++ b/x/tokenomics/module/abci.go @@ -0,0 +1,19 @@ +package tokenomics + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/pokt-network/poktroll/x/tokenomics/keeper" +) + +// EndBlocker called at every block and settles all pending claims. +func EndBlocker(ctx sdk.Context, k keeper.Keeper) error { + // NB: There are two main reasons why we settle expiring claims in the end + // instead of when a proof is submitted: + // 1. Logic - Probabilistic proof allows claims to be settled (i.e. rewarded) + // even without a proof to be able to scale to unbounded Claims & Proofs. + // 2. Implementation - This cannot be done from the `x/proof` module because + // it would create a circular dependency. + _, _, err := k.SettlePendingClaims(ctx) + return err +} diff --git a/x/tokenomics/module/module.go b/x/tokenomics/module/module.go index 4beeea0ea..67a431383 100644 --- a/x/tokenomics/module/module.go +++ b/x/tokenomics/module/module.go @@ -18,9 +18,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/grpc-ecosystem/grpc-gateway/runtime" - // this line is used by starport scaffolding # 1 - - modulev1 "github.com/pokt-network/poktroll/api/poktroll/tokenomics/module" + tokenomicsmodule "github.com/pokt-network/poktroll/api/poktroll/tokenomics/module" "github.com/pokt-network/poktroll/x/tokenomics/keeper" "github.com/pokt-network/poktroll/x/tokenomics/types" ) @@ -95,29 +93,29 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r type AppModule struct { AppModuleBasic - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + tokenomicsKeeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper } func NewAppModule( cdc codec.Codec, - keeper keeper.Keeper, + tokenomicsKeeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ) AppModule { return AppModule{ - AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, + AppModuleBasic: NewAppModuleBasic(cdc), + tokenomicsKeeper: tokenomicsKeeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, } } // RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.tokenomicsKeeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.tokenomicsKeeper) } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) @@ -129,12 +127,12 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) - InitGenesis(ctx, am.keeper, genState) + InitGenesis(ctx, am.tokenomicsKeeper, genState) } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) + genState := ExportGenesis(ctx, am.tokenomicsKeeper) return cdc.MustMarshalJSON(genState) } @@ -151,8 +149,9 @@ func (am AppModule) BeginBlock(_ context.Context) error { // EndBlock contains the logic that is automatically triggered at the end of each block. // The end block implementation is optional. -func (am AppModule) EndBlock(_ context.Context) error { - return nil +func (am AppModule) EndBlock(goCtx context.Context) error { + ctx := sdk.UnwrapSDKContext(goCtx) + return EndBlocker(ctx, am.tokenomicsKeeper) } // IsOnePerModuleType implements the depinject.OnePerModuleType interface. @@ -166,7 +165,7 @@ func (am AppModule) IsAppModule() {} // ---------------------------------------------------------------------------- func init() { - appmodule.Register(&modulev1.Module{}, appmodule.Provide(ProvideModule)) + appmodule.Register(&tokenomicsmodule.Module{}, appmodule.Provide(ProvideModule)) } type ModuleInputs struct { @@ -174,13 +173,13 @@ type ModuleInputs struct { StoreService store.KVStoreService Cdc codec.Codec - Config *modulev1.Module + Config *tokenomicsmodule.Module Logger log.Logger AccountKeeper types.AccountKeeper BankKeeper types.BankKeeper ApplicationKeeper types.ApplicationKeeper - SupplierKeeper types.SupplierKeeper + ProofKeeper types.ProofKeeper } type ModuleOutputs struct { @@ -204,7 +203,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { in.BankKeeper, in.AccountKeeper, in.ApplicationKeeper, - in.SupplierKeeper, + in.ProofKeeper, ) m := NewAppModule( in.Cdc, diff --git a/x/tokenomics/module/tx_update_params_test.go b/x/tokenomics/module/tx_update_params_test.go index 022af8460..586c57e45 100644 --- a/x/tokenomics/module/tx_update_params_test.go +++ b/x/tokenomics/module/tx_update_params_test.go @@ -4,15 +4,16 @@ import ( "fmt" "testing" - tmcli "github.com/cometbft/cometbft/libs/cli" + cometcli "github.com/cometbft/cometbft/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/gogo/status" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/testutil/network" tokenomics "github.com/pokt-network/poktroll/x/tokenomics/module" "github.com/pokt-network/poktroll/x/tokenomics/types" - "github.com/stretchr/testify/require" ) func TestCLI_UpdateParams(t *testing.T) { @@ -20,7 +21,7 @@ func TestCLI_UpdateParams(t *testing.T) { ctx := net.Validators[0].ClientCtx common := []string{ - fmt.Sprintf("--%s=json", tmcli.OutputFlag), + fmt.Sprintf("--%s=json", cometcli.OutputFlag), fmt.Sprintf("--%s=%s", flags.FlagFrom, net.Validators[0].Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), diff --git a/x/tokenomics/types/expected_keepers.go b/x/tokenomics/types/expected_keepers.go index 6d4edf39c..dbef4678c 100644 --- a/x/tokenomics/types/expected_keepers.go +++ b/x/tokenomics/types/expected_keepers.go @@ -1,4 +1,4 @@ -//go:generate mockgen -destination ../../../testutil/tokenomics/mocks/expected_keepers_mock.go -package mocks . AccountKeeper,BankKeeper,ApplicationKeeper,SupplierKeeper +//go:generate mockgen -destination ../../../testutil/tokenomics/mocks/expected_keepers_mock.go -package mocks . AccountKeeper,BankKeeper,ApplicationKeeper,ProofKeeper package types @@ -8,13 +8,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" apptypes "github.com/pokt-network/poktroll/x/application/types" - sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + prooftypes "github.com/pokt-network/poktroll/x/proof/types" ) // AccountKeeper defines the expected interface for the Account module. type AccountKeeper interface { GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI // only used for simulation - // Methods imported from account should be defined here } // BankKeeper defines the expected interface for the Bank module. @@ -46,6 +45,12 @@ type ApplicationKeeper interface { SetApplication(ctx context.Context, app apptypes.Application) } -type SupplierKeeper interface { - GetSupplier(ctx context.Context, suppAddr string) (supplier sharedtypes.Supplier, found bool) +type ProofKeeper interface { + GetAllClaims(ctx context.Context) []prooftypes.Claim + RemoveClaim(ctx context.Context, sessionId, supplierAddr string) + GetProof(ctx context.Context, sessionId, supplierAddr string) (proof prooftypes.Proof, isProofFound bool) + RemoveProof(ctx context.Context, sessionId, supplierAddr string) + + // Only used for testing & simulation + UpsertClaim(ctx context.Context, claim prooftypes.Claim) }