From 69fee5f06401df8537864a53bd2755d81754f164 Mon Sep 17 00:00:00 2001 From: Hoon <48665813+sh-cha@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:39:02 +0900 Subject: [PATCH] no operation for finalized l1 sequence (#90) * no operation for finalized l1 sequence * remove unused error * change variable name to NextL1Sequencd * updatkey g --------- Co-authored-by: beer-1 <147697694+beer-1@users.noreply.github.com> --- api/opinit/opchild/v1/genesis.pulsar.go | 292 +++++++----------------- proto/opinit/opchild/v1/genesis.proto | 8 +- x/opchild/keeper/genesis.go | 26 +-- x/opchild/keeper/genesis_test.go | 4 +- x/opchild/keeper/keeper.go | 4 +- x/opchild/keeper/msg_server.go | 15 +- x/opchild/keeper/sequence_test.go | 26 +-- x/opchild/keeper/sequences.go | 37 ++- x/opchild/types/errors.go | 29 ++- x/opchild/types/genesis.go | 19 +- x/opchild/types/genesis.pb.go | 192 +++++----------- x/opchild/types/keys.go | 10 +- 12 files changed, 231 insertions(+), 431 deletions(-) diff --git a/api/opinit/opchild/v1/genesis.pulsar.go b/api/opinit/opchild/v1/genesis.pulsar.go index 8ecae4da..393732a1 100644 --- a/api/opinit/opchild/v1/genesis.pulsar.go +++ b/api/opinit/opchild/v1/genesis.pulsar.go @@ -117,61 +117,15 @@ func (x *_GenesisState_3_list) IsValid() bool { return x.list != nil } -var _ protoreflect.List = (*_GenesisState_7_list)(nil) - -type _GenesisState_7_list struct { - list *[]uint64 -} - -func (x *_GenesisState_7_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_GenesisState_7_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfUint64((*x.list)[i]) -} - -func (x *_GenesisState_7_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Uint() - concreteValue := valueUnwrapped - (*x.list)[i] = concreteValue -} - -func (x *_GenesisState_7_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Uint() - concreteValue := valueUnwrapped - *x.list = append(*x.list, concreteValue) -} - -func (x *_GenesisState_7_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message GenesisState at list field FinalizedL1Sequences as it is not of Message kind")) -} - -func (x *_GenesisState_7_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_GenesisState_7_list) NewElement() protoreflect.Value { - v := uint64(0) - return protoreflect.ValueOfUint64(v) -} - -func (x *_GenesisState_7_list) IsValid() bool { - return x.list != nil -} - var ( - md_GenesisState protoreflect.MessageDescriptor - fd_GenesisState_params protoreflect.FieldDescriptor - fd_GenesisState_last_validator_powers protoreflect.FieldDescriptor - fd_GenesisState_validators protoreflect.FieldDescriptor - fd_GenesisState_exported protoreflect.FieldDescriptor - fd_GenesisState_next_l2_sequence protoreflect.FieldDescriptor - fd_GenesisState_finalized_l1_sequences protoreflect.FieldDescriptor - fd_GenesisState_bridge_info protoreflect.FieldDescriptor + md_GenesisState protoreflect.MessageDescriptor + fd_GenesisState_params protoreflect.FieldDescriptor + fd_GenesisState_last_validator_powers protoreflect.FieldDescriptor + fd_GenesisState_validators protoreflect.FieldDescriptor + fd_GenesisState_exported protoreflect.FieldDescriptor + fd_GenesisState_next_l2_sequence protoreflect.FieldDescriptor + fd_GenesisState_next_l1_sequence protoreflect.FieldDescriptor + fd_GenesisState_bridge_info protoreflect.FieldDescriptor ) func init() { @@ -182,7 +136,7 @@ func init() { fd_GenesisState_validators = md_GenesisState.Fields().ByName("validators") fd_GenesisState_exported = md_GenesisState.Fields().ByName("exported") fd_GenesisState_next_l2_sequence = md_GenesisState.Fields().ByName("next_l2_sequence") - fd_GenesisState_finalized_l1_sequences = md_GenesisState.Fields().ByName("finalized_l1_sequences") + fd_GenesisState_next_l1_sequence = md_GenesisState.Fields().ByName("next_l1_sequence") fd_GenesisState_bridge_info = md_GenesisState.Fields().ByName("bridge_info") } @@ -281,9 +235,9 @@ func (x *fastReflection_GenesisState) Range(f func(protoreflect.FieldDescriptor, return } } - if len(x.FinalizedL1Sequences) != 0 { - value := protoreflect.ValueOfList(&_GenesisState_7_list{list: &x.FinalizedL1Sequences}) - if !f(fd_GenesisState_finalized_l1_sequences, value) { + if x.NextL1Sequence != uint64(0) { + value := protoreflect.ValueOfUint64(x.NextL1Sequence) + if !f(fd_GenesisState_next_l1_sequence, value) { return } } @@ -318,8 +272,8 @@ func (x *fastReflection_GenesisState) Has(fd protoreflect.FieldDescriptor) bool return x.Exported != false case "opinit.opchild.v1.GenesisState.next_l2_sequence": return x.NextL2Sequence != uint64(0) - case "opinit.opchild.v1.GenesisState.finalized_l1_sequences": - return len(x.FinalizedL1Sequences) != 0 + case "opinit.opchild.v1.GenesisState.next_l1_sequence": + return x.NextL1Sequence != uint64(0) case "opinit.opchild.v1.GenesisState.bridge_info": return x.BridgeInfo != nil default: @@ -348,8 +302,8 @@ func (x *fastReflection_GenesisState) Clear(fd protoreflect.FieldDescriptor) { x.Exported = false case "opinit.opchild.v1.GenesisState.next_l2_sequence": x.NextL2Sequence = uint64(0) - case "opinit.opchild.v1.GenesisState.finalized_l1_sequences": - x.FinalizedL1Sequences = nil + case "opinit.opchild.v1.GenesisState.next_l1_sequence": + x.NextL1Sequence = uint64(0) case "opinit.opchild.v1.GenesisState.bridge_info": x.BridgeInfo = nil default: @@ -389,12 +343,9 @@ func (x *fastReflection_GenesisState) Get(descriptor protoreflect.FieldDescripto case "opinit.opchild.v1.GenesisState.next_l2_sequence": value := x.NextL2Sequence return protoreflect.ValueOfUint64(value) - case "opinit.opchild.v1.GenesisState.finalized_l1_sequences": - if len(x.FinalizedL1Sequences) == 0 { - return protoreflect.ValueOfList(&_GenesisState_7_list{}) - } - listValue := &_GenesisState_7_list{list: &x.FinalizedL1Sequences} - return protoreflect.ValueOfList(listValue) + case "opinit.opchild.v1.GenesisState.next_l1_sequence": + value := x.NextL1Sequence + return protoreflect.ValueOfUint64(value) case "opinit.opchild.v1.GenesisState.bridge_info": value := x.BridgeInfo return protoreflect.ValueOfMessage(value.ProtoReflect()) @@ -432,10 +383,8 @@ func (x *fastReflection_GenesisState) Set(fd protoreflect.FieldDescriptor, value x.Exported = value.Bool() case "opinit.opchild.v1.GenesisState.next_l2_sequence": x.NextL2Sequence = value.Uint() - case "opinit.opchild.v1.GenesisState.finalized_l1_sequences": - lv := value.List() - clv := lv.(*_GenesisState_7_list) - x.FinalizedL1Sequences = *clv.list + case "opinit.opchild.v1.GenesisState.next_l1_sequence": + x.NextL1Sequence = value.Uint() case "opinit.opchild.v1.GenesisState.bridge_info": x.BridgeInfo = value.Message().Interface().(*BridgeInfo) default: @@ -475,12 +424,6 @@ func (x *fastReflection_GenesisState) Mutable(fd protoreflect.FieldDescriptor) p } value := &_GenesisState_3_list{list: &x.Validators} return protoreflect.ValueOfList(value) - case "opinit.opchild.v1.GenesisState.finalized_l1_sequences": - if x.FinalizedL1Sequences == nil { - x.FinalizedL1Sequences = []uint64{} - } - value := &_GenesisState_7_list{list: &x.FinalizedL1Sequences} - return protoreflect.ValueOfList(value) case "opinit.opchild.v1.GenesisState.bridge_info": if x.BridgeInfo == nil { x.BridgeInfo = new(BridgeInfo) @@ -490,6 +433,8 @@ func (x *fastReflection_GenesisState) Mutable(fd protoreflect.FieldDescriptor) p panic(fmt.Errorf("field exported of message opinit.opchild.v1.GenesisState is not mutable")) case "opinit.opchild.v1.GenesisState.next_l2_sequence": panic(fmt.Errorf("field next_l2_sequence of message opinit.opchild.v1.GenesisState is not mutable")) + case "opinit.opchild.v1.GenesisState.next_l1_sequence": + panic(fmt.Errorf("field next_l1_sequence of message opinit.opchild.v1.GenesisState is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: opinit.opchild.v1.GenesisState")) @@ -516,9 +461,8 @@ func (x *fastReflection_GenesisState) NewField(fd protoreflect.FieldDescriptor) return protoreflect.ValueOfBool(false) case "opinit.opchild.v1.GenesisState.next_l2_sequence": return protoreflect.ValueOfUint64(uint64(0)) - case "opinit.opchild.v1.GenesisState.finalized_l1_sequences": - list := []uint64{} - return protoreflect.ValueOfList(&_GenesisState_7_list{list: &list}) + case "opinit.opchild.v1.GenesisState.next_l1_sequence": + return protoreflect.ValueOfUint64(uint64(0)) case "opinit.opchild.v1.GenesisState.bridge_info": m := new(BridgeInfo) return protoreflect.ValueOfMessage(m.ProtoReflect()) @@ -613,12 +557,8 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { if x.NextL2Sequence != 0 { n += 1 + runtime.Sov(uint64(x.NextL2Sequence)) } - if len(x.FinalizedL1Sequences) > 0 { - l = 0 - for _, e := range x.FinalizedL1Sequences { - l += runtime.Sov(uint64(e)) - } - n += 1 + runtime.Sov(uint64(l)) + l + if x.NextL1Sequence != 0 { + n += 1 + runtime.Sov(uint64(x.NextL1Sequence)) } if x.BridgeInfo != nil { l = options.Size(x.BridgeInfo) @@ -667,25 +607,10 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { i-- dAtA[i] = 0x42 } - if len(x.FinalizedL1Sequences) > 0 { - var pksize2 int - for _, num := range x.FinalizedL1Sequences { - pksize2 += runtime.Sov(uint64(num)) - } - i -= pksize2 - j1 := i - for _, num := range x.FinalizedL1Sequences { - for num >= 1<<7 { - dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA[j1] = uint8(num) - j1++ - } - i = runtime.EncodeVarint(dAtA, i, uint64(pksize2)) + if x.NextL1Sequence != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.NextL1Sequence)) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x38 } if x.NextL2Sequence != 0 { i = runtime.EncodeVarint(dAtA, i, uint64(x.NextL2Sequence)) @@ -941,80 +866,23 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { } } case 7: - if wireType == 0 { - var v 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++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.FinalizedL1Sequences = append(x.FinalizedL1Sequences, v) - } else if wireType == 2 { - var packedLen 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++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NextL1Sequence", wireType) + } + x.NextL1Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow } - if postIndex > l { + if iNdEx >= l { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(x.FinalizedL1Sequences) == 0 { - x.FinalizedL1Sequences = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v 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++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.FinalizedL1Sequences = append(x.FinalizedL1Sequences, v) + b := dAtA[iNdEx] + iNdEx++ + x.NextL1Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FinalizedL1Sequences", wireType) } case 8: if wireType != 2 { @@ -1580,11 +1448,11 @@ type GenesisState struct { // of the last-block's bonded validators. LastValidatorPowers []*LastValidatorPower `protobuf:"bytes,2,rep,name=last_validator_powers,json=lastValidatorPowers,proto3" json:"last_validator_powers,omitempty"` // delegations defines the validator set at genesis. - Validators []*Validator `protobuf:"bytes,3,rep,name=validators,proto3" json:"validators,omitempty"` - Exported bool `protobuf:"varint,5,opt,name=exported,proto3" json:"exported,omitempty"` - NextL2Sequence uint64 `protobuf:"varint,6,opt,name=next_l2_sequence,json=nextL2Sequence,proto3" json:"next_l2_sequence,omitempty"` - FinalizedL1Sequences []uint64 `protobuf:"varint,7,rep,packed,name=finalized_l1_sequences,json=finalizedL1Sequences,proto3" json:"finalized_l1_sequences,omitempty"` - BridgeInfo *BridgeInfo `protobuf:"bytes,8,opt,name=bridge_info,json=bridgeInfo,proto3" json:"bridge_info,omitempty"` + Validators []*Validator `protobuf:"bytes,3,rep,name=validators,proto3" json:"validators,omitempty"` + Exported bool `protobuf:"varint,5,opt,name=exported,proto3" json:"exported,omitempty"` + NextL2Sequence uint64 `protobuf:"varint,6,opt,name=next_l2_sequence,json=nextL2Sequence,proto3" json:"next_l2_sequence,omitempty"` + NextL1Sequence uint64 `protobuf:"varint,7,opt,name=next_l1_sequence,json=nextL1Sequence,proto3" json:"next_l1_sequence,omitempty"` + BridgeInfo *BridgeInfo `protobuf:"bytes,8,opt,name=bridge_info,json=bridgeInfo,proto3" json:"bridge_info,omitempty"` } func (x *GenesisState) Reset() { @@ -1642,11 +1510,11 @@ func (x *GenesisState) GetNextL2Sequence() uint64 { return 0 } -func (x *GenesisState) GetFinalizedL1Sequences() []uint64 { +func (x *GenesisState) GetNextL1Sequence() uint64 { if x != nil { - return x.FinalizedL1Sequences + return x.NextL1Sequence } - return nil + return 0 } func (x *GenesisState) GetBridgeInfo() *BridgeInfo { @@ -1714,7 +1582,7 @@ var file_opinit_opchild_v1_genesis_proto_rawDesc = []byte{ 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x6f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2f, 0x6f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x79, 0x70, 0x65, - 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb7, 0x03, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, + 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xab, 0x03, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x3c, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x6f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x72, @@ -1734,34 +1602,34 @@ var file_opinit_opchild_v1_genesis_proto_rawDesc = []byte{ 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x6c, 0x32, 0x5f, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0e, 0x6e, 0x65, 0x78, - 0x74, 0x4c, 0x32, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x16, 0x66, - 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x5f, 0x6c, 0x31, 0x5f, 0x73, 0x65, 0x71, 0x75, - 0x65, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x04, 0x52, 0x14, 0x66, 0x69, 0x6e, - 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x4c, 0x31, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, - 0x73, 0x12, 0x3e, 0x0a, 0x0b, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x66, 0x6f, - 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2e, - 0x6f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x72, 0x69, 0x64, 0x67, - 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0a, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49, 0x6e, 0x66, - 0x6f, 0x22, 0x68, 0x0a, 0x12, 0x4c, 0x61, 0x73, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x6f, 0x72, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x07, 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, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x70, - 0x6f, 0x77, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, - 0x72, 0x3a, 0x08, 0x88, 0xa0, 0x1f, 0x00, 0xe8, 0xa0, 0x1f, 0x00, 0x42, 0xca, 0x01, 0x0a, 0x15, - 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x6f, 0x70, 0x63, 0x68, 0x69, - 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, - 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x4f, 0x50, - 0x69, 0x6e, 0x69, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2f, - 0x6f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2f, 0x76, 0x31, 0x3b, 0x6f, 0x70, 0x63, 0x68, 0x69, - 0x6c, 0x64, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x4f, 0x58, 0xaa, 0x02, 0x11, 0x4f, 0x70, 0x69, - 0x6e, 0x69, 0x74, 0x2e, 0x4f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2e, 0x56, 0x31, 0xca, 0x02, - 0x11, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x5c, 0x4f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x5c, - 0x56, 0x31, 0xe2, 0x02, 0x1d, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x5c, 0x4f, 0x70, 0x63, 0x68, - 0x69, 0x6c, 0x64, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x13, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x3a, 0x3a, 0x4f, 0x70, 0x63, - 0x68, 0x69, 0x6c, 0x64, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x4c, 0x32, 0x53, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6e, + 0x65, 0x78, 0x74, 0x5f, 0x6c, 0x31, 0x5f, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0e, 0x6e, 0x65, 0x78, 0x74, 0x4c, 0x31, 0x53, 0x65, 0x71, + 0x75, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x3e, 0x0a, 0x0b, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x5f, + 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x6f, 0x70, 0x69, + 0x6e, 0x69, 0x74, 0x2e, 0x6f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x42, + 0x72, 0x69, 0x64, 0x67, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0a, 0x62, 0x72, 0x69, 0x64, 0x67, + 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x68, 0x0a, 0x12, 0x4c, 0x61, 0x73, 0x74, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x07, 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, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, + 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x70, 0x6f, 0x77, 0x65, 0x72, 0x3a, 0x08, 0x88, 0xa0, 0x1f, 0x00, 0xe8, 0xa0, 0x1f, 0x00, 0x42, + 0xca, 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x6f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x6f, + 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, + 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x2d, 0x6c, 0x61, 0x62, + 0x73, 0x2f, 0x4f, 0x50, 0x69, 0x6e, 0x69, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6f, 0x70, 0x69, + 0x6e, 0x69, 0x74, 0x2f, 0x6f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2f, 0x76, 0x31, 0x3b, 0x6f, + 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x4f, 0x4f, 0x58, 0xaa, 0x02, + 0x11, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x2e, 0x4f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x2e, + 0x56, 0x31, 0xca, 0x02, 0x11, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x5c, 0x4f, 0x70, 0x63, 0x68, + 0x69, 0x6c, 0x64, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1d, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x5c, + 0x4f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x4f, 0x70, 0x69, 0x6e, 0x69, 0x74, 0x3a, + 0x3a, 0x4f, 0x70, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/opinit/opchild/v1/genesis.proto b/proto/opinit/opchild/v1/genesis.proto index 5c95233b..4311a9e2 100644 --- a/proto/opinit/opchild/v1/genesis.proto +++ b/proto/opinit/opchild/v1/genesis.proto @@ -20,10 +20,10 @@ message GenesisState { // delegations defines the validator set at genesis. repeated Validator validators = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; - bool exported = 5; - uint64 next_l2_sequence = 6; - repeated uint64 finalized_l1_sequences = 7; - BridgeInfo bridge_info = 8; + bool exported = 5; + uint64 next_l2_sequence = 6; + uint64 next_l1_sequence = 7; + BridgeInfo bridge_info = 8; } // LastValidatorPower required for validator set update logic. diff --git a/x/opchild/keeper/genesis.go b/x/opchild/keeper/genesis.go index 4533b805..06a0041b 100644 --- a/x/opchild/keeper/genesis.go +++ b/x/opchild/keeper/genesis.go @@ -71,10 +71,8 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res } } - for _, finalizedL1Sequence := range data.FinalizedL1Sequences { - if err := k.RecordFinalizedL1Sequence(ctx, finalizedL1Sequence); err != nil { - panic(err) - } + if err := k.SetNextL1Sequence(ctx, data.NextL1Sequence); err != nil { + panic(err) } if err := k.SetNextL2Sequence(ctx, data.NextL2Sequence); err != nil { @@ -107,11 +105,7 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { panic(err) } - var finalizedL1Sequences []uint64 - err = k.IterateFinalizedL1Sequences(ctx, func(l1Sequence uint64) (bool, error) { - finalizedL1Sequences = append(finalizedL1Sequences, l1Sequence) - return false, nil - }) + finalizedL1Sequence, err := k.GetNextL1Sequence(ctx) if err != nil { panic(err) } @@ -144,12 +138,12 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { } return &types.GenesisState{ - Params: params, - LastValidatorPowers: lastValidatorPowers, - Validators: validators, - Exported: true, - FinalizedL1Sequences: finalizedL1Sequences, - NextL2Sequence: nextL2Sequence, - BridgeInfo: bridgeInfo, + Params: params, + LastValidatorPowers: lastValidatorPowers, + Validators: validators, + Exported: true, + NextL1Sequence: finalizedL1Sequence, + NextL2Sequence: nextL2Sequence, + BridgeInfo: bridgeInfo, } } diff --git a/x/opchild/keeper/genesis_test.go b/x/opchild/keeper/genesis_test.go index 2f6c0641..943d50da 100644 --- a/x/opchild/keeper/genesis_test.go +++ b/x/opchild/keeper/genesis_test.go @@ -23,8 +23,8 @@ func Test_GenesisImportExport(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(2), seq) - input.OPChildKeeper.RecordFinalizedL1Sequence(ctx, 1) - input.OPChildKeeper.RecordFinalizedL1Sequence(ctx, 2) + input.OPChildKeeper.IncreaseNextL1Sequence(ctx) // 2 + input.OPChildKeeper.IncreaseNextL1Sequence(ctx) // 3 genState := input.OPChildKeeper.ExportGenesis(ctx) require.Nil(t, genState.BridgeInfo) diff --git a/x/opchild/keeper/keeper.go b/x/opchild/keeper/keeper.go index d51f8192..90d74f7b 100644 --- a/x/opchild/keeper/keeper.go +++ b/x/opchild/keeper/keeper.go @@ -42,10 +42,10 @@ type Keeper struct { consensusAddressCodec address.Codec Schema collections.Schema + NextL1Sequence collections.Sequence NextL2Sequence collections.Sequence Params collections.Item[types.Params] BridgeInfo collections.Item[types.BridgeInfo] - FinalizedL1Sequence collections.Map[uint64, bool] LastValidatorPowers collections.Map[[]byte, int64] Validators collections.Map[[]byte, types.Validator] ValidatorsByConsAddr collections.Map[[]byte, []byte] @@ -100,10 +100,10 @@ func NewKeeper( addressCodec: addressCodec, validatorAddressCodec: validatorAddressCodec, consensusAddressCodec: consensusAddressCodec, + NextL1Sequence: collections.NewSequence(sb, types.NextL1SequenceKey, "finalized_l1_sequence"), NextL2Sequence: collections.NewSequence(sb, types.NextL2SequenceKey, "next_l2_sequence"), Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), BridgeInfo: collections.NewItem(sb, types.BridgeInfoKey, "bridge_info", codec.CollValue[types.BridgeInfo](cdc)), - FinalizedL1Sequence: collections.NewMap(sb, types.FinalizedL1SequencePrefix, "finalized_l1_sequence", collections.Uint64Key, collections.BoolValue), LastValidatorPowers: collections.NewMap(sb, types.LastValidatorPowerPrefix, "last_validator_powers", collections.BytesKey, collections.Int64Value), Validators: collections.NewMap(sb, types.ValidatorsPrefix, "validators", collections.BytesKey, codec.CollValue[types.Validator](cdc)), ValidatorsByConsAddr: collections.NewMap(sb, types.ValidatorsByConsAddrPrefix, "validators_by_cons_addr", collections.BytesKey, collections.BytesValue), diff --git a/x/opchild/keeper/msg_server.go b/x/opchild/keeper/msg_server.go index f25234ab..78d06e59 100644 --- a/x/opchild/keeper/msg_server.go +++ b/x/opchild/keeper/msg_server.go @@ -376,11 +376,16 @@ func (ms MsgServer) FinalizeTokenDeposit(ctx context.Context, req *types.MsgFina return nil, err } - // check already finalized - if ok, err := ms.HasFinalizedL1Sequence(ctx, req.Sequence); err != nil { + finalizedL1Sequence, err := ms.GetNextL1Sequence(ctx) + if err != nil { return nil, err - } else if ok { - return nil, types.ErrDepositAlreadyFinalized + } + + if req.Sequence < finalizedL1Sequence { + // No op instead of returning an error + return &types.MsgFinalizeTokenDepositResponse{}, nil + } else if req.Sequence > finalizedL1Sequence { + return nil, types.ErrInvalidSequence } fromAddr, err := ms.authKeeper.AddressCodec().StringToBytes(req.From) @@ -408,7 +413,7 @@ func (ms MsgServer) FinalizeTokenDeposit(ctx context.Context, req *types.MsgFina } } - if err := ms.RecordFinalizedL1Sequence(ctx, req.Sequence); err != nil { + if _, err := ms.IncreaseNextL1Sequence(ctx); err != nil { return nil, err } diff --git a/x/opchild/keeper/sequence_test.go b/x/opchild/keeper/sequence_test.go index b354dfa5..b9c001f4 100644 --- a/x/opchild/keeper/sequence_test.go +++ b/x/opchild/keeper/sequence_test.go @@ -6,31 +6,17 @@ import ( "github.com/stretchr/testify/require" ) -func Test_FinalizedL1Sequence(t *testing.T) { +func Test_NextL1GetNextL1Sequence(t *testing.T) { ctx, input := createDefaultTestInput(t) - res, err := input.OPChildKeeper.HasFinalizedL1Sequence(ctx, 1) + res, err := input.OPChildKeeper.GetNextL1Sequence(ctx) require.NoError(t, err) - require.False(t, res) + require.Equal(t, uint64(1), res) - input.OPChildKeeper.RecordFinalizedL1Sequence(ctx, 1) - res, err = input.OPChildKeeper.HasFinalizedL1Sequence(ctx, 1) + input.OPChildKeeper.IncreaseNextL1Sequence(ctx) + res, err = input.OPChildKeeper.GetNextL1Sequence(ctx) require.NoError(t, err) - require.True(t, res) -} - -func Test_IterateFinalizedL1Sequences(t *testing.T) { - ctx, input := createDefaultTestInput(t) - - sequences := []uint64{1, 2, 4} - for _, v := range sequences { - input.OPChildKeeper.RecordFinalizedL1Sequence(ctx, v) - } - require.NoError(t, input.OPChildKeeper.IterateFinalizedL1Sequences(ctx, func(l1Sequence uint64) (bool, error) { - require.Equal(t, sequences[0], l1Sequence) - sequences = sequences[1:] - return false, nil - })) + require.Equal(t, uint64(2), res) } func Test_SetAndSetNextL2Sequence(t *testing.T) { diff --git a/x/opchild/keeper/sequences.go b/x/opchild/keeper/sequences.go index 91b11111..cc14d83b 100644 --- a/x/opchild/keeper/sequences.go +++ b/x/opchild/keeper/sequences.go @@ -5,20 +5,41 @@ import ( "cosmossdk.io/collections" "github.com/initia-labs/OPinit/x/opchild/types" + ophosttypes "github.com/initia-labs/OPinit/x/ophost/types" ) -func (k Keeper) RecordFinalizedL1Sequence(ctx context.Context, l1Sequence uint64) error { - return k.FinalizedL1Sequence.Set(ctx, l1Sequence, true) +func (k Keeper) GetNextL1Sequence(ctx context.Context) (uint64, error) { + finalizedL1Sequence, err := k.NextL1Sequence.Peek(ctx) + if err != nil { + return 0, err + } + + if finalizedL1Sequence == collections.DefaultSequenceStart { + return ophosttypes.DefaultL1SequenceStart, nil + } + + return finalizedL1Sequence, nil } -func (k Keeper) HasFinalizedL1Sequence(ctx context.Context, l1Sequence uint64) (bool, error) { - return k.FinalizedL1Sequence.Has(ctx, l1Sequence) +func (k Keeper) SetNextL1Sequence(ctx context.Context, l1Sequence uint64) error { + return k.NextL1Sequence.Set(ctx, l1Sequence) } -func (k Keeper) IterateFinalizedL1Sequences(ctx context.Context, cb func(l1Sequence uint64) (stop bool, err error)) error { - return k.FinalizedL1Sequence.Walk(ctx, nil, func(l1sequence uint64, _ bool) (stop bool, err error) { - return cb(l1sequence) - }) +func (k Keeper) IncreaseNextL1Sequence(ctx context.Context) (uint64, error) { + finalizedL1Sequence, err := k.NextL1Sequence.Next(ctx) + if err != nil { + return 0, err + } + + if finalizedL1Sequence == collections.DefaultSequenceStart { + if err := k.NextL1Sequence.Set(ctx, ophosttypes.DefaultL1SequenceStart+1); err != nil { + return 0, err + } + + return ophosttypes.DefaultL1SequenceStart, nil + } + + return finalizedL1Sequence, nil } func (k Keeper) SetNextL2Sequence(ctx context.Context, l2Sequence uint64) error { diff --git a/x/opchild/types/errors.go b/x/opchild/types/errors.go index 06c294ec..ede4b238 100644 --- a/x/opchild/types/errors.go +++ b/x/opchild/types/errors.go @@ -13,19 +13,18 @@ var ( ErrInvalidHistoricalInfo = errorsmod.Register(ModuleName, 6, "invalid historical info") ErrEmptyValidatorPubKey = errorsmod.Register(ModuleName, 7, "empty validator public key") ErrInvalidSigner = errorsmod.Register(ModuleName, 8, "expected `opchild` module account as only signer for system message") - ErrDepositAlreadyFinalized = errorsmod.Register(ModuleName, 9, "deposit already finalized") - ErrInvalidAmount = errorsmod.Register(ModuleName, 10, "invalid amount") - ErrInvalidSequence = errorsmod.Register(ModuleName, 11, "invalid sequence") - ErrInvalidBlockHeight = errorsmod.Register(ModuleName, 12, "invalid block height") - ErrZeroMaxValidators = errorsmod.Register(ModuleName, 13, "max validators must be non-zero") - ErrInvalidExecuteMsg = errorsmod.Register(ModuleName, 14, "invalid execute message") - ErrUnroutableExecuteMsg = errorsmod.Register(ModuleName, 15, "unroutable execute message") - ErrInvalidExecutorChangePlan = errorsmod.Register(ModuleName, 16, "invalid executor chane plan") - ErrAlreadyRegisteredHeight = errorsmod.Register(ModuleName, 17, "executor change plan already exists at the height") - ErrInvalidBridgeInfo = errorsmod.Register(ModuleName, 18, "invalid bridge info") - ErrInvalidHeight = errorsmod.Register(ModuleName, 19, "invalid oracle height") - ErrInvalidPrices = errorsmod.Register(ModuleName, 20, "invalid oracle prices") - ErrMaxValidatorsExceeded = errorsmod.Register(ModuleName, 21, "max validators exceeded") - ErrMaxValidatorsLowerThanCurrent = errorsmod.Register(ModuleName, 22, "max validators cannot be lower than current number of validators") - ErrNonL1Token = errorsmod.Register(ModuleName, 23, "token is not from L1") + ErrInvalidAmount = errorsmod.Register(ModuleName, 9, "invalid amount") + ErrInvalidSequence = errorsmod.Register(ModuleName, 10, "invalid sequence") + ErrInvalidBlockHeight = errorsmod.Register(ModuleName, 11, "invalid block height") + ErrZeroMaxValidators = errorsmod.Register(ModuleName, 12, "max validators must be non-zero") + ErrInvalidExecuteMsg = errorsmod.Register(ModuleName, 13, "invalid execute message") + ErrUnroutableExecuteMsg = errorsmod.Register(ModuleName, 14, "unroutable execute message") + ErrInvalidExecutorChangePlan = errorsmod.Register(ModuleName, 15, "invalid executor chane plan") + ErrAlreadyRegisteredHeight = errorsmod.Register(ModuleName, 16, "executor change plan already exists at the height") + ErrInvalidBridgeInfo = errorsmod.Register(ModuleName, 17, "invalid bridge info") + ErrInvalidHeight = errorsmod.Register(ModuleName, 18, "invalid oracle height") + ErrInvalidPrices = errorsmod.Register(ModuleName, 19, "invalid oracle prices") + ErrMaxValidatorsExceeded = errorsmod.Register(ModuleName, 20, "max validators exceeded") + ErrMaxValidatorsLowerThanCurrent = errorsmod.Register(ModuleName, 21, "max validators cannot be lower than current number of validators") + ErrNonL1Token = errorsmod.Register(ModuleName, 22, "token is not from L1") ) diff --git a/x/opchild/types/genesis.go b/x/opchild/types/genesis.go index 4576cf48..c7fb1aef 100644 --- a/x/opchild/types/genesis.go +++ b/x/opchild/types/genesis.go @@ -9,7 +9,10 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) -const DefaultL2SequenceStart = 1 +const ( + DefaultL1SequenceStart = 1 + DefaultL2SequenceStart = 1 +) // NewGenesisState creates a new GenesisState instance func NewGenesisState(params Params, validators []Validator, bridgeInfo *BridgeInfo) *GenesisState { @@ -25,13 +28,13 @@ func NewGenesisState(params Params, validators []Validator, bridgeInfo *BridgeIn // DefaultGenesisState gets the raw genesis raw message for testing func DefaultGenesisState() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - LastValidatorPowers: []LastValidatorPower{}, - Validators: []Validator{}, - Exported: false, - NextL2Sequence: DefaultL2SequenceStart, - FinalizedL1Sequences: []uint64{}, - BridgeInfo: nil, + Params: DefaultParams(), + LastValidatorPowers: []LastValidatorPower{}, + Validators: []Validator{}, + Exported: false, + NextL1Sequence: DefaultL1SequenceStart, + NextL2Sequence: DefaultL2SequenceStart, + BridgeInfo: nil, } } diff --git a/x/opchild/types/genesis.pb.go b/x/opchild/types/genesis.pb.go index a0014647..548c1228 100644 --- a/x/opchild/types/genesis.pb.go +++ b/x/opchild/types/genesis.pb.go @@ -33,11 +33,11 @@ type GenesisState struct { // of the last-block's bonded validators. LastValidatorPowers []LastValidatorPower `protobuf:"bytes,2,rep,name=last_validator_powers,json=lastValidatorPowers,proto3" json:"last_validator_powers"` // delegations defines the validator set at genesis. - Validators []Validator `protobuf:"bytes,3,rep,name=validators,proto3" json:"validators"` - Exported bool `protobuf:"varint,5,opt,name=exported,proto3" json:"exported,omitempty"` - NextL2Sequence uint64 `protobuf:"varint,6,opt,name=next_l2_sequence,json=nextL2Sequence,proto3" json:"next_l2_sequence,omitempty"` - FinalizedL1Sequences []uint64 `protobuf:"varint,7,rep,packed,name=finalized_l1_sequences,json=finalizedL1Sequences,proto3" json:"finalized_l1_sequences,omitempty"` - BridgeInfo *BridgeInfo `protobuf:"bytes,8,opt,name=bridge_info,json=bridgeInfo,proto3" json:"bridge_info,omitempty"` + Validators []Validator `protobuf:"bytes,3,rep,name=validators,proto3" json:"validators"` + Exported bool `protobuf:"varint,5,opt,name=exported,proto3" json:"exported,omitempty"` + NextL2Sequence uint64 `protobuf:"varint,6,opt,name=next_l2_sequence,json=nextL2Sequence,proto3" json:"next_l2_sequence,omitempty"` + NextL1Sequence uint64 `protobuf:"varint,7,opt,name=next_l1_sequence,json=nextL1Sequence,proto3" json:"next_l1_sequence,omitempty"` + BridgeInfo *BridgeInfo `protobuf:"bytes,8,opt,name=bridge_info,json=bridgeInfo,proto3" json:"bridge_info,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -108,11 +108,11 @@ func (m *GenesisState) GetNextL2Sequence() uint64 { return 0 } -func (m *GenesisState) GetFinalizedL1Sequences() []uint64 { +func (m *GenesisState) GetNextL1Sequence() uint64 { if m != nil { - return m.FinalizedL1Sequences + return m.NextL1Sequence } - return nil + return 0 } func (m *GenesisState) GetBridgeInfo() *BridgeInfo { @@ -171,38 +171,36 @@ func init() { func init() { proto.RegisterFile("opinit/opchild/v1/genesis.proto", fileDescriptor_08c29689c0e7bd55) } var fileDescriptor_08c29689c0e7bd55 = []byte{ - // 483 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xc1, 0x8a, 0xd3, 0x40, - 0x18, 0xc7, 0x33, 0x9b, 0xdd, 0x6e, 0x77, 0x2a, 0xe2, 0x8e, 0x55, 0x66, 0x8b, 0x9b, 0x86, 0x05, - 0x21, 0x08, 0x4d, 0x68, 0xf4, 0x24, 0x22, 0xd8, 0x4b, 0x11, 0x0a, 0x96, 0x14, 0x3c, 0x78, 0x09, - 0x93, 0x66, 0x9a, 0x0e, 0xa4, 0x33, 0x31, 0x33, 0x5b, 0xab, 0x4f, 0xe0, 0xd1, 0x47, 0xd8, 0xa3, - 0x47, 0x0f, 0x82, 0xaf, 0xb0, 0xc7, 0xe2, 0xc9, 0x93, 0x48, 0x7b, 0xd0, 0xc7, 0x90, 0x4e, 0xd2, -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, 0xb9, 0x63, 0x31, 0xf3, 0x36, - 0xc7, 0x66, 0xa4, 0x93, 0x92, 0x48, 0x7a, 0x6f, 0x86, 0x3a, 0x73, 0x8b, 0x2a, 0x75, 0x3a, 0x72, - 0x51, 0x4d, 0x67, 0xee, 0xe9, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb5, 0x0d, 0xf0, 0x1f, 0x0c, - 0x03, 0x00, 0x00, + // 464 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x33, 0x5b, 0xb7, 0xdb, 0x9d, 0x8a, 0xb8, 0x63, 0x85, 0x6c, 0x71, 0xd3, 0xb0, 0x20, + 0x04, 0xa1, 0x09, 0x8d, 0x37, 0x11, 0xc1, 0x5e, 0x8a, 0xb0, 0x60, 0x49, 0xc1, 0x83, 0x97, 0x30, + 0x69, 0x66, 0xd3, 0x81, 0x74, 0x26, 0xce, 0xcc, 0xd6, 0xfa, 0x0d, 0x3c, 0xfa, 0x11, 0xf6, 0x28, + 0x78, 0xf1, 0xe0, 0x87, 0xd8, 0xe3, 0xe2, 0xc9, 0x93, 0x48, 0x7b, 0xd0, 0x8f, 0x21, 0x9d, 0xc9, + 0xa6, 0x85, 0xf4, 0x32, 0xcc, 0x7b, 0xef, 0xf7, 0xfe, 0xf3, 0x98, 0xf7, 0x87, 0x3d, 0x5e, 0x50, + 0x46, 0x55, 0xc0, 0x8b, 0xe9, 0x8c, 0xe6, 0x69, 0xb0, 0x18, 0x04, 0x19, 0x61, 0x44, 0x52, 0xe9, + 0x17, 0x82, 0x2b, 0x8e, 0x4e, 0x0c, 0xe0, 0x97, 0x80, 0xbf, 0x18, 0x74, 0x4f, 0xf0, 0x9c, 0x32, + 0x1e, 0xe8, 0xd3, 0x50, 0xdd, 0xd3, 0x29, 0x97, 0x73, 0x2e, 0x63, 0x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, + 0x69, 0x46, 0x62, 0xca, 0x2e, 0xb9, 0xdd, 0xd2, 0x3f, 0x7c, 0xb6, 0x67, 0xf2, 0xa1, 0xa6, 0xde, + 0xb0, 0x4b, 0x1e, 0xc1, 0xa4, 0xba, 0x9f, 0xcf, 0x20, 0xaa, 0x7f, 0x17, 0x0a, 0xe1, 0x11, 0x4e, + 0x53, 0x41, 0xa4, 0xd9, 0xd9, 0xf1, 0xd0, 0xfe, 0xf9, 0xa3, 0xdf, 0x29, 0xbd, 0xf1, 0xda, 0x54, + 0x26, 0x4a, 0x50, 0x96, 0x45, 0x77, 0x20, 0xea, 0xc0, 0x43, 0xbd, 0x19, 0xfb, 0xc0, 0x05, 0x5e, + 0x23, 0x32, 0xc1, 0x8b, 0xd6, 0xe7, 0xeb, 0x9e, 0xf5, 0xef, 0xba, 0x67, 0x0d, 0x47, 0x37, 0x2b, + 0x07, 0xdc, 0xae, 0x1c, 0xf0, 0x67, 0xe5, 0x80, 0x2f, 0x6b, 0xc7, 0xba, 0x5d, 0x3b, 0xd6, 0xaf, + 0xb5, 0x63, 0xbd, 0xef, 0x67, 0x54, 0xcd, 0xae, 0x12, 0x7f, 0xca, 0xe7, 0xc1, 0x66, 0x6c, 0x8a, + 0xfb, 0x39, 0x4e, 0x64, 0xf0, 0x76, 0xac, 0x7d, 0xb6, 0xac, 0x9c, 0xa6, 0x6d, 0x96, 0x34, 0xb5, + 0xcf, 0x9e, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x3f, 0xd2, 0x86, 0xd7, 0x00, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -237,23 +235,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x42 } - if len(m.FinalizedL1Sequences) > 0 { - dAtA3 := make([]byte, len(m.FinalizedL1Sequences)*10) - var j2 int - for _, num := range m.FinalizedL1Sequences { - for num >= 1<<7 { - dAtA3[j2] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j2++ - } - dAtA3[j2] = uint8(num) - j2++ - } - i -= j2 - copy(dAtA[i:], dAtA3[:j2]) - i = encodeVarintGenesis(dAtA, i, uint64(j2)) + if m.NextL1Sequence != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextL1Sequence)) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x38 } if m.NextL2Sequence != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.NextL2Sequence)) @@ -383,12 +368,8 @@ func (m *GenesisState) Size() (n int) { if m.NextL2Sequence != 0 { n += 1 + sovGenesis(uint64(m.NextL2Sequence)) } - if len(m.FinalizedL1Sequences) > 0 { - l = 0 - for _, e := range m.FinalizedL1Sequences { - l += sovGenesis(uint64(e)) - } - n += 1 + sovGenesis(uint64(l)) + l + if m.NextL1Sequence != 0 { + n += 1 + sovGenesis(uint64(m.NextL1Sequence)) } if m.BridgeInfo != nil { l = m.BridgeInfo.Size() @@ -589,80 +570,23 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } } case 7: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.FinalizedL1Sequences = append(m.FinalizedL1Sequences, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextL1Sequence", wireType) + } + m.NextL1Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { return io.ErrUnexpectedEOF } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.FinalizedL1Sequences) == 0 { - m.FinalizedL1Sequences = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.FinalizedL1Sequences = append(m.FinalizedL1Sequences, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field FinalizedL1Sequences", wireType) + b := dAtA[iNdEx] + iNdEx++ + m.NextL1Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } } case 8: if wireType != 2 { diff --git a/x/opchild/types/keys.go b/x/opchild/types/keys.go index 241171df..c27f3088 100644 --- a/x/opchild/types/keys.go +++ b/x/opchild/types/keys.go @@ -17,15 +17,15 @@ var ( ParamsKey = []byte{0x11} // prefix for parameters for module x/opchild NextL2SequenceKey = []byte{0x12} // key for the outbound sequence number BridgeInfoKey = []byte{0x13} // prefix for bridge_info + NextL1SequenceKey = []byte{0x14} // prefix for inbound deposit sequence number LastValidatorPowerPrefix = []byte{0x21} // prefix for each key to a validator index, for bonded validators ValidatorsPrefix = []byte{0x31} // prefix for each key to a validator ValidatorsByConsAddrPrefix = []byte{0x41} // prefix for each key to a validator index, by pubkey - FinalizedL1SequencePrefix = []byte{0x51} // prefix for finalized deposit sequences - HistoricalInfoPrefix = []byte{0x61} // prefix for the historical info - DenomPairPrefix = []byte{0x71} // prefix for the denom pair + HistoricalInfoPrefix = []byte{0x51} // prefix for the historical info + DenomPairPrefix = []byte{0x61} // prefix for the denom pair // HostValidatorStore keys - HostHeightKey = []byte{0x81} - HostValidatorsPrefix = []byte{0x82} + HostHeightKey = []byte{0x71} + HostValidatorsPrefix = []byte{0x72} )