From 4100146caf4a43d1f4cc763623e04383b2f1473b Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 12 Sep 2022 14:03:05 +0300 Subject: [PATCH 01/87] added new interface for simple header --- data/interface.go | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/data/interface.go b/data/interface.go index 1ef3280e5..702e91dff 100644 --- a/data/interface.go +++ b/data/interface.go @@ -29,9 +29,8 @@ type TriggerRegistryHandler interface { SetEpochStartHeaderHandler(epochStartHeaderHandler HeaderHandler) error } -// HeaderHandler defines getters and setters for header data holder -type HeaderHandler interface { - GetShardID() uint32 +// CommonHeaderHandler defines getters and setters for header data holder +type CommonHeaderHandler interface { GetNonce() uint64 GetEpoch() uint32 GetRound() uint64 @@ -47,20 +46,12 @@ type HeaderHandler interface { GetTimeStamp() uint64 GetTxCount() uint32 GetReceiptsHash() []byte + GetReserved() []byte GetAccumulatedFees() *big.Int GetDeveloperFees() *big.Int - GetReserved() []byte - GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 - GetOrderedCrossMiniblocksWithDst(destId uint32) []*MiniBlockInfo GetMiniBlockHeadersHashes() [][]byte GetMiniBlockHeaderHandlers() []MiniBlockHeaderHandler - HasScheduledSupport() bool - GetAdditionalData() headerVersionData.HeaderAdditionalData - HasScheduledMiniBlocks() bool - SetAccumulatedFees(value *big.Int) error - SetDeveloperFees(value *big.Int) error - SetShardID(shId uint32) error SetNonce(n uint64) error SetEpoch(e uint32) error SetRound(r uint64) error @@ -75,14 +66,36 @@ type HeaderHandler interface { SetChainID(chainID []byte) error SetSoftwareVersion(version []byte) error SetTxCount(txCount uint32) error + SetDeveloperFees(value *big.Int) error + SetAccumulatedFees(value *big.Int) error SetMiniBlockHeaderHandlers(mbHeaderHandlers []MiniBlockHeaderHandler) error SetReceiptsHash(hash []byte) error - SetScheduledRootHash(rootHash []byte) error ValidateHeaderVersion() error + IsInterfaceNil() bool +} + +// ValidatorStatisticsInfoHandler simple handler needed for validator info +type ValidatorStatisticsInfoHandler interface { + SetValidatorStatsRootHash(rHash []byte) error + GetValidatorStatsRootHash() []byte + IsInterfaceNil() bool +} + +// HeaderHandler defines getters and setters for header data holder +type HeaderHandler interface { + CommonHeaderHandler + GetShardID() uint32 + GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 + GetOrderedCrossMiniblocksWithDst(destId uint32) []*MiniBlockInfo + HasScheduledSupport() bool + GetAdditionalData() headerVersionData.HeaderAdditionalData + HasScheduledMiniBlocks() bool + + SetShardID(shId uint32) error + SetScheduledRootHash(rootHash []byte) error SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error IsStartOfEpochBlock() bool ShallowClone() HeaderHandler - IsInterfaceNil() bool } // ShardHeaderHandler defines getters and setters for the shard block header From f35204299d8820f71442ce624ecf6c95da0b68b6 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 12 Sep 2022 16:25:25 +0300 Subject: [PATCH 02/87] new header proto --- data/block/sovereignBlock.proto | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 data/block/sovereignBlock.proto diff --git a/data/block/sovereignBlock.proto b/data/block/sovereignBlock.proto new file mode 100644 index 000000000..f0993f505 --- /dev/null +++ b/data/block/sovereignBlock.proto @@ -0,0 +1,16 @@ +// This file holds the data structures related with the functionality of a shard block V2 +syntax = "proto3"; + +package proto; + +option go_package = "block"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "block.proto"; + +// HeaderWithValidatorStats extends the Header structure with extra fields for validator statistics +message HeaderWithValidatorStats { + Header Header = 1; + bytes ValidatorStatsRootHash = 2; +} From 8abc09ee7027d69f6bcbd4732f2f6ef587bd5ee4 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 12 Sep 2022 17:09:57 +0300 Subject: [PATCH 03/87] new header proto --- data/block/headerWithValidatorStats.go | 2 ++ .../{sovereignBlock.proto => headerWithValidatorStats.proto} | 0 2 files changed, 2 insertions(+) create mode 100644 data/block/headerWithValidatorStats.go rename data/block/{sovereignBlock.proto => headerWithValidatorStats.proto} (100%) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go new file mode 100644 index 000000000..8d8d53e7e --- /dev/null +++ b/data/block/headerWithValidatorStats.go @@ -0,0 +1,2 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. headerWithValidatorStats.proto +package block diff --git a/data/block/sovereignBlock.proto b/data/block/headerWithValidatorStats.proto similarity index 100% rename from data/block/sovereignBlock.proto rename to data/block/headerWithValidatorStats.proto From 693d2e173dc78667238b044ccb9a752cfde271fc Mon Sep 17 00:00:00 2001 From: radu chis Date: Mon, 12 Sep 2022 17:56:11 +0300 Subject: [PATCH 04/87] go generate headerWithValidatorStats.pb.go --- data/block/headerWithValidatorStats.pb.go | 450 ++++++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 data/block/headerWithValidatorStats.pb.go diff --git a/data/block/headerWithValidatorStats.pb.go b/data/block/headerWithValidatorStats.pb.go new file mode 100644 index 000000000..681297958 --- /dev/null +++ b/data/block/headerWithValidatorStats.pb.go @@ -0,0 +1,450 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: headerWithValidatorStats.proto + +package block + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// HeaderWithValidatorStats extends the Header structure with extra fields for validator statistics +type HeaderWithValidatorStats struct { + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"ValidatorStatsRootHash,omitempty"` +} + +func (m *HeaderWithValidatorStats) Reset() { *m = HeaderWithValidatorStats{} } +func (*HeaderWithValidatorStats) ProtoMessage() {} +func (*HeaderWithValidatorStats) Descriptor() ([]byte, []int) { + return fileDescriptor_c2e2729e77d170be, []int{0} +} +func (m *HeaderWithValidatorStats) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HeaderWithValidatorStats) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *HeaderWithValidatorStats) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeaderWithValidatorStats.Merge(m, src) +} +func (m *HeaderWithValidatorStats) XXX_Size() int { + return m.Size() +} +func (m *HeaderWithValidatorStats) XXX_DiscardUnknown() { + xxx_messageInfo_HeaderWithValidatorStats.DiscardUnknown(m) +} + +var xxx_messageInfo_HeaderWithValidatorStats proto.InternalMessageInfo + +func (m *HeaderWithValidatorStats) GetHeader() *Header { + if m != nil { + return m.Header + } + return nil +} + +func (m *HeaderWithValidatorStats) GetValidatorStatsRootHash() []byte { + if m != nil { + return m.ValidatorStatsRootHash + } + return nil +} + +func init() { + proto.RegisterType((*HeaderWithValidatorStats)(nil), "proto.HeaderWithValidatorStats") +} + +func init() { proto.RegisterFile("headerWithValidatorStats.proto", fileDescriptor_c2e2729e77d170be) } + +var fileDescriptor_c2e2729e77d170be = []byte{ + // 222 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcb, 0x48, 0x4d, 0x4c, + 0x49, 0x2d, 0x0a, 0xcf, 0x2c, 0xc9, 0x08, 0x4b, 0xcc, 0xc9, 0x4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x00, 0x00, 0x00, 0xff, 0xff, 0x9c, 0xd7, 0x84, 0x46, 0x27, 0x01, 0x00, 0x00, +} + +func (this *HeaderWithValidatorStats) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HeaderWithValidatorStats) + if !ok { + that2, ok := that.(HeaderWithValidatorStats) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Header.Equal(that1.Header) { + return false + } + if !bytes.Equal(this.ValidatorStatsRootHash, that1.ValidatorStatsRootHash) { + return false + } + return true +} +func (this *HeaderWithValidatorStats) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&block.HeaderWithValidatorStats{") + if this.Header != nil { + s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") + } + s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringHeaderWithValidatorStats(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *HeaderWithValidatorStats) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *HeaderWithValidatorStats) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HeaderWithValidatorStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorStatsRootHash) > 0 { + i -= len(m.ValidatorStatsRootHash) + copy(dAtA[i:], m.ValidatorStatsRootHash) + i = encodeVarintHeaderWithValidatorStats(dAtA, i, uint64(len(m.ValidatorStatsRootHash))) + i-- + dAtA[i] = 0x12 + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintHeaderWithValidatorStats(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintHeaderWithValidatorStats(dAtA []byte, offset int, v uint64) int { + offset -= sovHeaderWithValidatorStats(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HeaderWithValidatorStats) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovHeaderWithValidatorStats(uint64(l)) + } + l = len(m.ValidatorStatsRootHash) + if l > 0 { + n += 1 + l + sovHeaderWithValidatorStats(uint64(l)) + } + return n +} + +func sovHeaderWithValidatorStats(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozHeaderWithValidatorStats(x uint64) (n int) { + return sovHeaderWithValidatorStats(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *HeaderWithValidatorStats) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&HeaderWithValidatorStats{`, + `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, + `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, + `}`, + }, "") + return s +} +func valueToStringHeaderWithValidatorStats(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *HeaderWithValidatorStats) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeaderWithValidatorStats + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: HeaderWithValidatorStats: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HeaderWithValidatorStats: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeaderWithValidatorStats + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthHeaderWithValidatorStats + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthHeaderWithValidatorStats + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Header == nil { + m.Header = &Header{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorStatsRootHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowHeaderWithValidatorStats + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthHeaderWithValidatorStats + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthHeaderWithValidatorStats + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorStatsRootHash = append(m.ValidatorStatsRootHash[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorStatsRootHash == nil { + m.ValidatorStatsRootHash = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipHeaderWithValidatorStats(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthHeaderWithValidatorStats + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthHeaderWithValidatorStats + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipHeaderWithValidatorStats(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHeaderWithValidatorStats + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHeaderWithValidatorStats + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowHeaderWithValidatorStats + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthHeaderWithValidatorStats + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupHeaderWithValidatorStats + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthHeaderWithValidatorStats + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthHeaderWithValidatorStats = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowHeaderWithValidatorStats = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupHeaderWithValidatorStats = fmt.Errorf("proto: unexpected end of group") +) From b048d64b018c3873316de90b40e7309a7951946c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 12 Sep 2022 19:07:40 +0300 Subject: [PATCH 05/87] new header proto --- data/block/headerWithValidatorStats.go | 449 +++++++++++++++++++++++++ 1 file changed, 449 insertions(+) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index 8d8d53e7e..986eea2b1 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -1,2 +1,451 @@ //go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. headerWithValidatorStats.proto package block + +import ( + "math/big" + + "github.com/ElrondNetwork/elrond-go-core/data" +) + +// GetShardID returns the header shardID +func (hv *HeaderWithValidatorStats) GetShardID() uint32 { + return 0 +} + +// GetNonce returns the header nonce +func (hv *HeaderWithValidatorStats) GetNonce() uint64 { + if hv == nil { + return 0 + } + + return hv.Header.GetNonce() +} + +// GetEpoch returns the header epoch +func (hv *HeaderWithValidatorStats) GetEpoch() uint32 { + if hv == nil { + return 0 + } + + return hv.Header.GetEpoch() +} + +// GetRound returns the header round +func (hv *HeaderWithValidatorStats) GetRound() uint64 { + if hv == nil { + return 0 + } + + return hv.Header.GetRound() +} + +// GetRootHash returns the header root hash +func (hv *HeaderWithValidatorStats) GetRootHash() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetRootHash() +} + +// GetPrevHash returns the header previous header hash +func (hv *HeaderWithValidatorStats) GetPrevHash() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetPrevHash() +} + +// GetPrevRandSeed returns the header previous random seed +func (hv *HeaderWithValidatorStats) GetPrevRandSeed() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetPrevRandSeed() +} + +// GetRandSeed returns the header random seed +func (hv *HeaderWithValidatorStats) GetRandSeed() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetRandSeed() +} + +// GetPubKeysBitmap returns the header public key bitmap for the aggregated signatures +func (hv *HeaderWithValidatorStats) GetPubKeysBitmap() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetPubKeysBitmap() +} + +// GetSignature returns the header aggregated signature +func (hv *HeaderWithValidatorStats) GetSignature() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetSignature() +} + +// GetLeaderSignature returns the leader signature on top of the finalized (signed) header +func (hv *HeaderWithValidatorStats) GetLeaderSignature() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetLeaderSignature() +} + +// GetChainID returns the chain ID +func (hv *HeaderWithValidatorStats) GetChainID() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetChainID() +} + +// GetSoftwareVersion returns the header software version +func (hv *HeaderWithValidatorStats) GetSoftwareVersion() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetSoftwareVersion() +} + +// GetTimeStamp returns the header timestamp +func (hv *HeaderWithValidatorStats) GetTimeStamp() uint64 { + if hv == nil { + return 0 + } + + return hv.Header.GetTimeStamp() +} + +// GetTxCount returns the number of txs included in the block +func (hv *HeaderWithValidatorStats) GetTxCount() uint32 { + if hv == nil { + return 0 + } + + return hv.Header.GetTxCount() +} + +// GetReceiptsHash returns the header receipt hash +func (hv *HeaderWithValidatorStats) GetReceiptsHash() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetReceiptsHash() +} + +// GetAccumulatedFees returns the block accumulated fees +func (hv *HeaderWithValidatorStats) GetAccumulatedFees() *big.Int { + if hv == nil { + return nil + } + + return hv.Header.GetAccumulatedFees() +} + +// GetDeveloperFees returns the block developer fees +func (hv *HeaderWithValidatorStats) GetDeveloperFees() *big.Int { + if hv == nil { + return nil + } + + return hv.Header.GetDeveloperFees() +} + +// GetReserved returns the reserved field +func (hv *HeaderWithValidatorStats) GetReserved() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetReserved() +} + +// GetMetaBlockHashes returns the metaBlock hashes +func (hv *HeaderWithValidatorStats) GetMetaBlockHashes() [][]byte { + if hv == nil { + return nil + } + + return hv.Header.GetMetaBlockHashes() +} + +// GetEpochStartMetaHash returns the epoch start metaBlock hash +func (hv *HeaderWithValidatorStats) GetEpochStartMetaHash() []byte { + if hv == nil { + return nil + } + + return hv.Header.GetEpochStartMetaHash() +} + +// SetNonce sets header nonce +func (hv *HeaderWithValidatorStats) SetNonce(n uint64) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + return hv.Header.SetNonce(n) +} + +// SetEpoch sets header epoch +func (hv *HeaderWithValidatorStats) SetEpoch(e uint32) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetEpoch(e) +} + +// SetRound sets header round +func (hv *HeaderWithValidatorStats) SetRound(r uint64) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetRound(r) +} + +// SetRootHash sets root hash +func (hv *HeaderWithValidatorStats) SetRootHash(rHash []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetRootHash(rHash) +} + +// SetPrevHash sets prev hash +func (hv *HeaderWithValidatorStats) SetPrevHash(pvHash []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetPrevHash(pvHash) +} + +// SetPrevRandSeed sets previous random seed +func (hv *HeaderWithValidatorStats) SetPrevRandSeed(pvRandSeed []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetPrevRandSeed(pvRandSeed) +} + +// SetRandSeed sets previous random seed +func (hv *HeaderWithValidatorStats) SetRandSeed(randSeed []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetRandSeed(randSeed) +} + +// SetPubKeysBitmap sets public key bitmap +func (hv *HeaderWithValidatorStats) SetPubKeysBitmap(pkbm []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetPubKeysBitmap(pkbm) +} + +// SetSignature sets header signature +func (hv *HeaderWithValidatorStats) SetSignature(sg []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetSignature(sg) +} + +// SetLeaderSignature will set the leader's signature +func (hv *HeaderWithValidatorStats) SetLeaderSignature(sg []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetLeaderSignature(sg) +} + +// SetChainID sets the chain ID on which this block is valid on +func (hv *HeaderWithValidatorStats) SetChainID(chainID []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetChainID(chainID) +} + +// SetSoftwareVersion sets the software version of the header +func (hv *HeaderWithValidatorStats) SetSoftwareVersion(version []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetSoftwareVersion(version) +} + +// SetTimeStamp sets header timestamp +func (hv *HeaderWithValidatorStats) SetTimeStamp(ts uint64) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetTimeStamp(ts) +} + +// SetAccumulatedFees sets the accumulated fees in the header +func (hv *HeaderWithValidatorStats) SetAccumulatedFees(value *big.Int) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetAccumulatedFees(value) +} + +// SetDeveloperFees sets the developer fees in the header +func (hv *HeaderWithValidatorStats) SetDeveloperFees(value *big.Int) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetDeveloperFees(value) +} + +// SetTxCount sets the transaction count of the block associated with this header +func (hv *HeaderWithValidatorStats) SetTxCount(txCount uint32) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetTxCount(txCount) +} + +// SetShardID sets header shard ID +func (hv *HeaderWithValidatorStats) SetShardID(_ uint32) error { + return nil +} + +// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { + if hv == nil { + return nil + } + + return hv.Header.GetMiniBlockHeadersWithDst(destId) +} + +// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a +// chronological way, taking into consideration the round in which they were created/executed in the sender shard +func (hv *HeaderWithValidatorStats) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { + if hv == nil { + return nil + } + + return hv.Header.GetOrderedCrossMiniblocksWithDst(destId) +} + +// GetMiniBlockHeadersHashes gets the miniblock hashes +func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersHashes() [][]byte { + if hv == nil { + return nil + } + + return hv.Header.GetMiniBlockHeadersHashes() +} + +// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs +func (hv *HeaderWithValidatorStats) MapMiniBlockHashesToShards() map[string]uint32 { + if hv == nil { + return nil + } + + return hv.Header.MapMiniBlockHashesToShards() +} + +// ShallowClone returns a clone of the object +func (hv *HeaderWithValidatorStats) ShallowClone() data.CommonHeaderHandler { + if hv == nil || hv.Header == nil { + return nil + } + + internalHeaderCopy := *hv.Header + headerCopy := *hv + headerCopy.Header = &internalHeaderCopy + + return &headerCopy +} + +// IsInterfaceNil returns true if there is no value under the interface +func (hv *HeaderWithValidatorStats) IsInterfaceNil() bool { + return hv == nil +} + +// IsStartOfEpochBlock verifies if the block is of type start of epoch +func (hv *HeaderWithValidatorStats) IsStartOfEpochBlock() bool { + return false +} + +// GetBlockBodyTypeInt32 returns the block body type as int32 +func (hv *HeaderWithValidatorStats) GetBlockBodyTypeInt32() int32 { + if hv == nil { + return -1 + } + + return hv.Header.GetBlockBodyTypeInt32() +} + +// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers +func (hv *HeaderWithValidatorStats) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if hv == nil { + return nil + } + + return hv.Header.GetMiniBlockHeaderHandlers() +} + +// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers +func (hv *HeaderWithValidatorStats) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetMiniBlockHeaderHandlers(mbHeaderHandlers) +} + +// SetReceiptsHash sets the receipts hash +func (hv *HeaderWithValidatorStats) SetReceiptsHash(hash []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetReceiptsHash(hash) +} + +// HasScheduledSupport returns true as the second block version does support scheduled data +func (hv *HeaderWithValidatorStats) HasScheduledSupport() bool { + return false +} + +// ValidateHeaderVersion does extra validation for header version +func (hv *HeaderWithValidatorStats) ValidateHeaderVersion() error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return nil +} From 76a58c46cea87d7aa341a76ca882ec9d9dddd321 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Sep 2022 10:42:45 +0300 Subject: [PATCH 06/87] new header proto and implementation --- data/block/headerWithValidatorStats.go | 11 +++++++++++ data/interface.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index 986eea2b1..59bd27103 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -340,6 +340,17 @@ func (hv *HeaderWithValidatorStats) SetShardID(_ uint32) error { return nil } +// SetValidatorStatsRootHash sets the root hash for the validator statistics trie +func (hv *HeaderWithValidatorStats) SetValidatorStatsRootHash(rHash []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + hv.ValidatorStatsRootHash = rHash + + return nil +} + // GetMiniBlockHeadersWithDst as a map of hashes and sender IDs func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { if hv == nil { diff --git a/data/interface.go b/data/interface.go index 746d7dd76..c3bac809a 100644 --- a/data/interface.go +++ b/data/interface.go @@ -31,6 +31,7 @@ type TriggerRegistryHandler interface { // CommonHeaderHandler defines getters and setters for header data holder type CommonHeaderHandler interface { + GetShardID() uint32 GetNonce() uint64 GetEpoch() uint32 GetRound() uint64 @@ -84,7 +85,6 @@ type ValidatorStatisticsInfoHandler interface { // HeaderHandler defines getters and setters for header data holder type HeaderHandler interface { CommonHeaderHandler - GetShardID() uint32 GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 GetOrderedCrossMiniblocksWithDst(destId uint32) []*MiniBlockInfo HasScheduledSupport() bool From ca1525b53f44d963f5aa54c55062124abccab03d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Sep 2022 11:17:01 +0300 Subject: [PATCH 07/87] new header proto and implementation --- data/interface.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/interface.go b/data/interface.go index c3bac809a..e7fee7442 100644 --- a/data/interface.go +++ b/data/interface.go @@ -72,6 +72,7 @@ type CommonHeaderHandler interface { SetMiniBlockHeaderHandlers(mbHeaderHandlers []MiniBlockHeaderHandler) error SetReceiptsHash(hash []byte) error ValidateHeaderVersion() error + IsStartOfEpochBlock() bool IsInterfaceNil() bool } @@ -94,7 +95,6 @@ type HeaderHandler interface { SetShardID(shId uint32) error SetScheduledRootHash(rootHash []byte) error SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error - IsStartOfEpochBlock() bool ShallowClone() HeaderHandler } From 9abb87c7e9ffa13cf22656af8df83ef97e23f75c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Sep 2022 11:34:10 +0300 Subject: [PATCH 08/87] new header proto and implementation --- data/block/headerWithValidatorStats.go | 47 +++++++++++++++++++------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index 59bd27103..28ed40573 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -5,8 +5,42 @@ import ( "math/big" "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" ) +// GetAdditionalData returns nil +func (hv *HeaderWithValidatorStats) GetAdditionalData() headerVersionData.HeaderAdditionalData { + return nil +} + +// HasScheduledMiniBlocks returns false +func (hv *HeaderWithValidatorStats) HasScheduledMiniBlocks() bool { + return false +} + +// SetScheduledRootHash returns nil +func (hv *HeaderWithValidatorStats) SetScheduledRootHash(_ []byte) error { + return nil +} + +// SetAdditionalData will not do anything +func (hv *HeaderWithValidatorStats) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { + return nil +} + +// ShallowClone will return a clone of the object +func (hv *HeaderWithValidatorStats) ShallowClone() data.HeaderHandler { + if hv == nil || hv.Header == nil { + return nil + } + + internalHeaderCopy := *hv.Header + headerCopy := *hv + headerCopy.Header = &internalHeaderCopy + + return &headerCopy +} + // GetShardID returns the header shardID func (hv *HeaderWithValidatorStats) GetShardID() uint32 { return 0 @@ -388,19 +422,6 @@ func (hv *HeaderWithValidatorStats) MapMiniBlockHashesToShards() map[string]uint return hv.Header.MapMiniBlockHashesToShards() } -// ShallowClone returns a clone of the object -func (hv *HeaderWithValidatorStats) ShallowClone() data.CommonHeaderHandler { - if hv == nil || hv.Header == nil { - return nil - } - - internalHeaderCopy := *hv.Header - headerCopy := *hv - headerCopy.Header = &internalHeaderCopy - - return &headerCopy -} - // IsInterfaceNil returns true if there is no value under the interface func (hv *HeaderWithValidatorStats) IsInterfaceNil() bool { return hv == nil From dfff257a8b5a0548804736f91103881bf4946874 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Sep 2022 18:55:07 +0300 Subject: [PATCH 09/87] new interface and set function --- data/block/block.go | 37 +++++++++++++++++++++++++++++++++++-- data/errors.go | 3 +++ data/interface.go | 8 ++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/data/block/block.go b/data/block/block.go index bc1e91a29..050227c6e 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -384,6 +384,39 @@ func (h *Header) ValidateHeaderVersion() error { return nil } +// Clone creates a clones the miniblock +func (m *MiniBlock) Clone() data.MiniBlockHandler { + if m == nil { + return nil + } + + return m.DeepClone() +} + +// IsInterfaceNil returns true if underlying object is nil +func (m *MiniBlock) IsInterfaceNil() bool { + return m == nil +} + +// SetMiniBlocks will set a new set of miniblocks +func (b *Body) SetMiniBlocks(miniBlocks []data.MiniBlockHandler) error { + if b == nil { + return data.ErrNilPointerReceiver + } + + b.MiniBlocks = make([]*MiniBlock, len(miniBlocks)) + for i, mb := range miniBlocks { + mbHandlerClone := mb.Clone() + mbClone, ok := mbHandlerClone.(*MiniBlock) + if !ok { + return data.ErrWrongTypeAssertion + } + b.MiniBlocks[i] = mbClone + } + + return nil +} + // IntegrityAndValidity checks if data is valid func (b *Body) IntegrityAndValidity() error { if b == nil { @@ -415,8 +448,8 @@ func (b *Body) IsInterfaceNil() bool { return b == nil } -// Clone the underlying data -func (mb *MiniBlock) Clone() *MiniBlock { +// DeepClone the underlying data +func (mb *MiniBlock) DeepClone() *MiniBlock { if mb == nil { return nil } diff --git a/data/errors.go b/data/errors.go index 048aeac46..036d1bacc 100644 --- a/data/errors.go +++ b/data/errors.go @@ -78,3 +78,6 @@ var ErrScheduledRootHashNotSupported = errors.New("scheduled root hash is not su // ErrWrongTransactionsTypeSize signals that size of transactions type buffer from mini block reserved field is wrong var ErrWrongTransactionsTypeSize = errors.New("wrong transactions type size") + +// ErrWrongTypeAssertion signals that there was a wrong type assertion +var ErrWrongTypeAssertion = errors.New("wrong type assertion") diff --git a/data/interface.go b/data/interface.go index e7fee7442..852b9ae8f 100644 --- a/data/interface.go +++ b/data/interface.go @@ -246,8 +246,16 @@ type EpochStartHandler interface { SetEconomics(economicsHandler EconomicsHandler) error } +// MiniBlockHandler interface for miniblock +type MiniBlockHandler interface { + Clone() MiniBlockHandler + // IsInterfaceNil returns true if there is no value under the interface + IsInterfaceNil() bool +} + // BodyHandler interface for a block body type BodyHandler interface { + SetMiniBlocks(miniBlocks []MiniBlockHandler) error Clone() BodyHandler // IntegrityAndValidity checks the integrity and validity of the block IntegrityAndValidity() error From 76a8d820d1d6607ae9525bbca043d8998d087bfa Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Mon, 16 Jan 2023 12:41:09 +0200 Subject: [PATCH 10/87] * Updated go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 22eb60163..15e661242 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/ElrondNetwork/elrond-go-core +module github.com/multiversx/mx-chain-core-go go 1.17 From c9fa8b127a79404f1f4eb5aa8722f579e7c779f4 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Mon, 16 Jan 2023 12:49:07 +0200 Subject: [PATCH 11/87] * Updated go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 15e661242..22eb60163 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/multiversx/mx-chain-core-go +module github.com/ElrondNetwork/elrond-go-core go 1.17 From 846af7174260dc61003a9515620050b9fa1acaa2 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Mon, 16 Jan 2023 13:48:57 +0200 Subject: [PATCH 12/87] * Fixed imports --- data/block/headerWithValidatorStats.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index 28ed40573..b5372d8c9 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -4,8 +4,8 @@ package block import ( "math/big" - "github.com/ElrondNetwork/elrond-go-core/data" - "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/headerVersionData" ) // GetAdditionalData returns nil From f8302bba6703e78b23e94e84c9cfb0dfd479a701 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Mon, 16 Jan 2023 14:19:12 +0200 Subject: [PATCH 13/87] * Fixed go:generate --- data/block/headerWithValidatorStats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index b5372d8c9..aa9b57284 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. headerWithValidatorStats.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. block.proto package block import ( From 633918f0ca0eb3d9d3bbdb69ed6d4030171fc78e Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Fri, 3 Feb 2023 19:49:35 +0200 Subject: [PATCH 14/87] * Fixed after merge --- data/block/headerWithValidatorStats.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index aa9b57284..9b68c1b3c 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -2,6 +2,7 @@ package block import ( + "fmt" "math/big" "github.com/multiversx/mx-chain-core-go/data" @@ -481,3 +482,20 @@ func (hv *HeaderWithValidatorStats) ValidateHeaderVersion() error { return nil } + +// CheckFieldsForNil checks a predefined set of fields for nil values +func (hv *HeaderWithValidatorStats) CheckFieldsForNil() error { + if hv == nil { + return data.ErrNilPointerReceiver + } + err := hv.Header.CheckFieldsForNil() + if err != nil { + return err + } + + if hv.ValidatorStatsRootHash == nil { + return fmt.Errorf("%w in hv.ValidatorStatsRootHash", data.ErrNilValue) + } + + return nil +} From 6b8252f81bf534f1d5b1e2324acc96d88e96ee98 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Mon, 20 Feb 2023 12:33:12 +0200 Subject: [PATCH 15/87] * Expanded HeaderHandler interface with ValidatorStatsRootHash setter and getter --- data/block/block.go | 13 +++++++------ data/block/blockV2.go | 10 ++++++++++ data/interface.go | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/data/block/block.go b/data/block/block.go index 86d72b775..f056fa01c 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -64,7 +64,8 @@ func (h *Header) SetRootHash(rHash []byte) error { } // SetValidatorStatsRootHash sets the root hash for the validator statistics trie -func (h *Header) SetValidatorStatsRootHash(_ []byte) { +func (h *Header) SetValidatorStatsRootHash(_ []byte) error { + return nil } // SetPrevHash sets prev hash @@ -77,11 +78,6 @@ func (h *Header) SetPrevHash(pvHash []byte) error { return nil } -// GetValidatorStatsRootHash returns the root hash for the validator statistics trie -func (h *Header) GetValidatorStatsRootHash() []byte { - return []byte{} -} - // SetPrevRandSeed sets previous random seed func (h *Header) SetPrevRandSeed(pvRandSeed []byte) error { if h == nil { @@ -616,6 +612,11 @@ func (h *Header) GetAdditionalData() headerVersionData.HeaderAdditionalData { return nil } +// GetValidatorStatsRootHash returns the root hash for the validator statistics trie +func (h *Header) GetValidatorStatsRootHash() []byte { + return []byte{} +} + // CheckFieldsForNil checks a predefined set of fields for nil values func (h *Header) CheckFieldsForNil() error { if h == nil { diff --git a/data/block/blockV2.go b/data/block/blockV2.go index 0a690e2ee..a4870fc2e 100644 --- a/data/block/blockV2.go +++ b/data/block/blockV2.go @@ -234,6 +234,11 @@ func (hv2 *HeaderV2) SetRootHash(rHash []byte) error { return hv2.Header.SetRootHash(rHash) } +// SetValidatorStatsRootHash sets the root hash for the validator statistics trie +func (hv2 *HeaderV2) SetValidatorStatsRootHash(_ []byte) error { + return nil +} + // SetPrevHash sets prev hash func (hv2 *HeaderV2) SetPrevHash(pvHash []byte) error { if hv2 == nil { @@ -631,6 +636,11 @@ func (hv2 *HeaderV2) GetAdditionalData() headerVersionData.HeaderAdditionalData return additionalVersionData } +// GetValidatorStatsRootHash returns the root hash for the validator statistics trie +func (hv2 *HeaderV2) GetValidatorStatsRootHash() []byte { + return []byte{} +} + // CheckFieldsForNil checks a predefined set of fields for nil values func (hv2 *HeaderV2) CheckFieldsForNil() error { if hv2 == nil { diff --git a/data/interface.go b/data/interface.go index 8af37e00f..96ad4b1c1 100644 --- a/data/interface.go +++ b/data/interface.go @@ -93,10 +93,12 @@ type HeaderHandler interface { HasScheduledSupport() bool GetAdditionalData() headerVersionData.HeaderAdditionalData HasScheduledMiniBlocks() bool + GetValidatorStatsRootHash() []byte SetShardID(shId uint32) error SetScheduledRootHash(rootHash []byte) error SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error + SetValidatorStatsRootHash(rHash []byte) error ShallowClone() HeaderHandler } @@ -114,11 +116,9 @@ type ShardHeaderHandler interface { // MetaHeaderHandler defines getters and setters for the meta block header type MetaHeaderHandler interface { HeaderHandler - GetValidatorStatsRootHash() []byte GetEpochStartHandler() EpochStartHandler GetDevFeesInEpoch() *big.Int GetShardInfoHandlers() []ShardDataHandler - SetValidatorStatsRootHash(rHash []byte) error SetDevFeesInEpoch(value *big.Int) error SetShardInfoHandlers(shardInfo []ShardDataHandler) error SetAccumulatedFeesInEpoch(value *big.Int) error From 40209be8e88b4f743c7e88f63710b91d3b5f4206 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Mon, 20 Feb 2023 14:59:24 +0200 Subject: [PATCH 16/87] * Added in headerWithValidatorStats implementation, methods SetMetaBlockHashes and SetEpochStartMetaHash needed by ShardHeaderHandler interface --- data/block/headerWithValidatorStats.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index 9b68c1b3c..4868c34bc 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -469,6 +469,24 @@ func (hv *HeaderWithValidatorStats) SetReceiptsHash(hash []byte) error { return hv.Header.SetReceiptsHash(hash) } +// SetMetaBlockHashes sets the metaBlock hashes +func (hv *HeaderWithValidatorStats) SetMetaBlockHashes(hashes [][]byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetMetaBlockHashes(hashes) +} + +// SetEpochStartMetaHash sets the epoch start metaBlock hash +func (hv *HeaderWithValidatorStats) SetEpochStartMetaHash(hash []byte) error { + if hv == nil { + return data.ErrNilPointerReceiver + } + + return hv.Header.SetEpochStartMetaHash(hash) +} + // HasScheduledSupport returns true as the second block version does support scheduled data func (hv *HeaderWithValidatorStats) HasScheduledSupport() bool { return false From 866caabcaf7899ae95d10b796370d0c1bd0d66e4 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Wed, 15 Mar 2023 21:56:22 +0200 Subject: [PATCH 17/87] * Added new structures and interfaces needed by sovereign chain --- data/block/headerWithValidatorStats.go | 519 ---------- data/block/headerWithValidatorStats.pb.go | 450 --------- data/block/shardHeaderExtended.go | 894 ++++++++++++++++++ data/block/shardHeaderExtended.pb.go | 476 ++++++++++ data/block/shardHeaderExtended.proto | 17 + data/block/sovereignChainHeader.go | 530 +++++++++++ data/block/sovereignChainHeader.pb.go | 518 ++++++++++ ...Stats.proto => sovereignChainHeader.proto} | 9 +- data/errors.go | 3 + data/interface.go | 15 +- 10 files changed, 2455 insertions(+), 976 deletions(-) delete mode 100644 data/block/headerWithValidatorStats.go delete mode 100644 data/block/headerWithValidatorStats.pb.go create mode 100644 data/block/shardHeaderExtended.go create mode 100644 data/block/shardHeaderExtended.pb.go create mode 100644 data/block/shardHeaderExtended.proto create mode 100644 data/block/sovereignChainHeader.go create mode 100644 data/block/sovereignChainHeader.pb.go rename data/block/{headerWithValidatorStats.proto => sovereignChainHeader.proto} (53%) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go deleted file mode 100644 index 4868c34bc..000000000 --- a/data/block/headerWithValidatorStats.go +++ /dev/null @@ -1,519 +0,0 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. block.proto -package block - -import ( - "fmt" - "math/big" - - "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-core-go/data/headerVersionData" -) - -// GetAdditionalData returns nil -func (hv *HeaderWithValidatorStats) GetAdditionalData() headerVersionData.HeaderAdditionalData { - return nil -} - -// HasScheduledMiniBlocks returns false -func (hv *HeaderWithValidatorStats) HasScheduledMiniBlocks() bool { - return false -} - -// SetScheduledRootHash returns nil -func (hv *HeaderWithValidatorStats) SetScheduledRootHash(_ []byte) error { - return nil -} - -// SetAdditionalData will not do anything -func (hv *HeaderWithValidatorStats) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { - return nil -} - -// ShallowClone will return a clone of the object -func (hv *HeaderWithValidatorStats) ShallowClone() data.HeaderHandler { - if hv == nil || hv.Header == nil { - return nil - } - - internalHeaderCopy := *hv.Header - headerCopy := *hv - headerCopy.Header = &internalHeaderCopy - - return &headerCopy -} - -// GetShardID returns the header shardID -func (hv *HeaderWithValidatorStats) GetShardID() uint32 { - return 0 -} - -// GetNonce returns the header nonce -func (hv *HeaderWithValidatorStats) GetNonce() uint64 { - if hv == nil { - return 0 - } - - return hv.Header.GetNonce() -} - -// GetEpoch returns the header epoch -func (hv *HeaderWithValidatorStats) GetEpoch() uint32 { - if hv == nil { - return 0 - } - - return hv.Header.GetEpoch() -} - -// GetRound returns the header round -func (hv *HeaderWithValidatorStats) GetRound() uint64 { - if hv == nil { - return 0 - } - - return hv.Header.GetRound() -} - -// GetRootHash returns the header root hash -func (hv *HeaderWithValidatorStats) GetRootHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetRootHash() -} - -// GetPrevHash returns the header previous header hash -func (hv *HeaderWithValidatorStats) GetPrevHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetPrevHash() -} - -// GetPrevRandSeed returns the header previous random seed -func (hv *HeaderWithValidatorStats) GetPrevRandSeed() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetPrevRandSeed() -} - -// GetRandSeed returns the header random seed -func (hv *HeaderWithValidatorStats) GetRandSeed() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetRandSeed() -} - -// GetPubKeysBitmap returns the header public key bitmap for the aggregated signatures -func (hv *HeaderWithValidatorStats) GetPubKeysBitmap() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetPubKeysBitmap() -} - -// GetSignature returns the header aggregated signature -func (hv *HeaderWithValidatorStats) GetSignature() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetSignature() -} - -// GetLeaderSignature returns the leader signature on top of the finalized (signed) header -func (hv *HeaderWithValidatorStats) GetLeaderSignature() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetLeaderSignature() -} - -// GetChainID returns the chain ID -func (hv *HeaderWithValidatorStats) GetChainID() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetChainID() -} - -// GetSoftwareVersion returns the header software version -func (hv *HeaderWithValidatorStats) GetSoftwareVersion() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetSoftwareVersion() -} - -// GetTimeStamp returns the header timestamp -func (hv *HeaderWithValidatorStats) GetTimeStamp() uint64 { - if hv == nil { - return 0 - } - - return hv.Header.GetTimeStamp() -} - -// GetTxCount returns the number of txs included in the block -func (hv *HeaderWithValidatorStats) GetTxCount() uint32 { - if hv == nil { - return 0 - } - - return hv.Header.GetTxCount() -} - -// GetReceiptsHash returns the header receipt hash -func (hv *HeaderWithValidatorStats) GetReceiptsHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetReceiptsHash() -} - -// GetAccumulatedFees returns the block accumulated fees -func (hv *HeaderWithValidatorStats) GetAccumulatedFees() *big.Int { - if hv == nil { - return nil - } - - return hv.Header.GetAccumulatedFees() -} - -// GetDeveloperFees returns the block developer fees -func (hv *HeaderWithValidatorStats) GetDeveloperFees() *big.Int { - if hv == nil { - return nil - } - - return hv.Header.GetDeveloperFees() -} - -// GetReserved returns the reserved field -func (hv *HeaderWithValidatorStats) GetReserved() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetReserved() -} - -// GetMetaBlockHashes returns the metaBlock hashes -func (hv *HeaderWithValidatorStats) GetMetaBlockHashes() [][]byte { - if hv == nil { - return nil - } - - return hv.Header.GetMetaBlockHashes() -} - -// GetEpochStartMetaHash returns the epoch start metaBlock hash -func (hv *HeaderWithValidatorStats) GetEpochStartMetaHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetEpochStartMetaHash() -} - -// SetNonce sets header nonce -func (hv *HeaderWithValidatorStats) SetNonce(n uint64) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - return hv.Header.SetNonce(n) -} - -// SetEpoch sets header epoch -func (hv *HeaderWithValidatorStats) SetEpoch(e uint32) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetEpoch(e) -} - -// SetRound sets header round -func (hv *HeaderWithValidatorStats) SetRound(r uint64) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetRound(r) -} - -// SetRootHash sets root hash -func (hv *HeaderWithValidatorStats) SetRootHash(rHash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetRootHash(rHash) -} - -// SetPrevHash sets prev hash -func (hv *HeaderWithValidatorStats) SetPrevHash(pvHash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetPrevHash(pvHash) -} - -// SetPrevRandSeed sets previous random seed -func (hv *HeaderWithValidatorStats) SetPrevRandSeed(pvRandSeed []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetPrevRandSeed(pvRandSeed) -} - -// SetRandSeed sets previous random seed -func (hv *HeaderWithValidatorStats) SetRandSeed(randSeed []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetRandSeed(randSeed) -} - -// SetPubKeysBitmap sets public key bitmap -func (hv *HeaderWithValidatorStats) SetPubKeysBitmap(pkbm []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetPubKeysBitmap(pkbm) -} - -// SetSignature sets header signature -func (hv *HeaderWithValidatorStats) SetSignature(sg []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetSignature(sg) -} - -// SetLeaderSignature will set the leader's signature -func (hv *HeaderWithValidatorStats) SetLeaderSignature(sg []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetLeaderSignature(sg) -} - -// SetChainID sets the chain ID on which this block is valid on -func (hv *HeaderWithValidatorStats) SetChainID(chainID []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetChainID(chainID) -} - -// SetSoftwareVersion sets the software version of the header -func (hv *HeaderWithValidatorStats) SetSoftwareVersion(version []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetSoftwareVersion(version) -} - -// SetTimeStamp sets header timestamp -func (hv *HeaderWithValidatorStats) SetTimeStamp(ts uint64) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetTimeStamp(ts) -} - -// SetAccumulatedFees sets the accumulated fees in the header -func (hv *HeaderWithValidatorStats) SetAccumulatedFees(value *big.Int) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetAccumulatedFees(value) -} - -// SetDeveloperFees sets the developer fees in the header -func (hv *HeaderWithValidatorStats) SetDeveloperFees(value *big.Int) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetDeveloperFees(value) -} - -// SetTxCount sets the transaction count of the block associated with this header -func (hv *HeaderWithValidatorStats) SetTxCount(txCount uint32) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetTxCount(txCount) -} - -// SetShardID sets header shard ID -func (hv *HeaderWithValidatorStats) SetShardID(_ uint32) error { - return nil -} - -// SetValidatorStatsRootHash sets the root hash for the validator statistics trie -func (hv *HeaderWithValidatorStats) SetValidatorStatsRootHash(rHash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - hv.ValidatorStatsRootHash = rHash - - return nil -} - -// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs -func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { - if hv == nil { - return nil - } - - return hv.Header.GetMiniBlockHeadersWithDst(destId) -} - -// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a -// chronological way, taking into consideration the round in which they were created/executed in the sender shard -func (hv *HeaderWithValidatorStats) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { - if hv == nil { - return nil - } - - return hv.Header.GetOrderedCrossMiniblocksWithDst(destId) -} - -// GetMiniBlockHeadersHashes gets the miniblock hashes -func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersHashes() [][]byte { - if hv == nil { - return nil - } - - return hv.Header.GetMiniBlockHeadersHashes() -} - -// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs -func (hv *HeaderWithValidatorStats) MapMiniBlockHashesToShards() map[string]uint32 { - if hv == nil { - return nil - } - - return hv.Header.MapMiniBlockHashesToShards() -} - -// IsInterfaceNil returns true if there is no value under the interface -func (hv *HeaderWithValidatorStats) IsInterfaceNil() bool { - return hv == nil -} - -// IsStartOfEpochBlock verifies if the block is of type start of epoch -func (hv *HeaderWithValidatorStats) IsStartOfEpochBlock() bool { - return false -} - -// GetBlockBodyTypeInt32 returns the block body type as int32 -func (hv *HeaderWithValidatorStats) GetBlockBodyTypeInt32() int32 { - if hv == nil { - return -1 - } - - return hv.Header.GetBlockBodyTypeInt32() -} - -// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers -func (hv *HeaderWithValidatorStats) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { - if hv == nil { - return nil - } - - return hv.Header.GetMiniBlockHeaderHandlers() -} - -// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers -func (hv *HeaderWithValidatorStats) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetMiniBlockHeaderHandlers(mbHeaderHandlers) -} - -// SetReceiptsHash sets the receipts hash -func (hv *HeaderWithValidatorStats) SetReceiptsHash(hash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetReceiptsHash(hash) -} - -// SetMetaBlockHashes sets the metaBlock hashes -func (hv *HeaderWithValidatorStats) SetMetaBlockHashes(hashes [][]byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetMetaBlockHashes(hashes) -} - -// SetEpochStartMetaHash sets the epoch start metaBlock hash -func (hv *HeaderWithValidatorStats) SetEpochStartMetaHash(hash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetEpochStartMetaHash(hash) -} - -// HasScheduledSupport returns true as the second block version does support scheduled data -func (hv *HeaderWithValidatorStats) HasScheduledSupport() bool { - return false -} - -// ValidateHeaderVersion does extra validation for header version -func (hv *HeaderWithValidatorStats) ValidateHeaderVersion() error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return nil -} - -// CheckFieldsForNil checks a predefined set of fields for nil values -func (hv *HeaderWithValidatorStats) CheckFieldsForNil() error { - if hv == nil { - return data.ErrNilPointerReceiver - } - err := hv.Header.CheckFieldsForNil() - if err != nil { - return err - } - - if hv.ValidatorStatsRootHash == nil { - return fmt.Errorf("%w in hv.ValidatorStatsRootHash", data.ErrNilValue) - } - - return nil -} diff --git a/data/block/headerWithValidatorStats.pb.go b/data/block/headerWithValidatorStats.pb.go deleted file mode 100644 index 681297958..000000000 --- a/data/block/headerWithValidatorStats.pb.go +++ /dev/null @@ -1,450 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: headerWithValidatorStats.proto - -package block - -import ( - bytes "bytes" - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// HeaderWithValidatorStats extends the Header structure with extra fields for validator statistics -type HeaderWithValidatorStats struct { - Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` - ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"ValidatorStatsRootHash,omitempty"` -} - -func (m *HeaderWithValidatorStats) Reset() { *m = HeaderWithValidatorStats{} } -func (*HeaderWithValidatorStats) ProtoMessage() {} -func (*HeaderWithValidatorStats) Descriptor() ([]byte, []int) { - return fileDescriptor_c2e2729e77d170be, []int{0} -} -func (m *HeaderWithValidatorStats) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HeaderWithValidatorStats) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *HeaderWithValidatorStats) XXX_Merge(src proto.Message) { - xxx_messageInfo_HeaderWithValidatorStats.Merge(m, src) -} -func (m *HeaderWithValidatorStats) XXX_Size() int { - return m.Size() -} -func (m *HeaderWithValidatorStats) XXX_DiscardUnknown() { - xxx_messageInfo_HeaderWithValidatorStats.DiscardUnknown(m) -} - -var xxx_messageInfo_HeaderWithValidatorStats proto.InternalMessageInfo - -func (m *HeaderWithValidatorStats) GetHeader() *Header { - if m != nil { - return m.Header - } - return nil -} - -func (m *HeaderWithValidatorStats) GetValidatorStatsRootHash() []byte { - if m != nil { - return m.ValidatorStatsRootHash - } - return nil -} - -func init() { - proto.RegisterType((*HeaderWithValidatorStats)(nil), "proto.HeaderWithValidatorStats") -} - -func init() { proto.RegisterFile("headerWithValidatorStats.proto", fileDescriptor_c2e2729e77d170be) } - -var fileDescriptor_c2e2729e77d170be = []byte{ - // 222 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcb, 0x48, 0x4d, 0x4c, - 0x49, 0x2d, 0x0a, 0xcf, 0x2c, 0xc9, 0x08, 0x4b, 0xcc, 0xc9, 0x4c, 0x49, 0x2c, 0xc9, 0x2f, 0x0a, - 0x2e, 0x49, 0x2c, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, - 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, - 0x60, 0xe1, 0xa4, 0xd2, 0x34, 0x30, 0x0f, 0xcc, 0x01, 0xb3, 0x20, 0xba, 0xa4, 0xb8, 0x93, 0x72, - 0xf2, 0x93, 0xb3, 0x21, 0x1c, 0xa5, 0x4a, 0x2e, 0x09, 0x0f, 0x1c, 0x96, 0x08, 0xa9, 0x72, 0xb1, - 0x41, 0xe4, 0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x78, 0x21, 0x7a, 0xf4, 0x20, 0x82, 0x41, - 0x50, 0x49, 0x21, 0x33, 0x2e, 0x31, 0x54, 0x8d, 0x41, 0xf9, 0xf9, 0x25, 0x1e, 0x89, 0xc5, 0x19, - 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x38, 0x64, 0x9d, 0xec, 0x2f, 0x3c, 0x94, 0x63, 0xb8, - 0xf1, 0x50, 0x8e, 0xe1, 0xc3, 0x43, 0x39, 0xc6, 0x86, 0x47, 0x72, 0x8c, 0x2b, 0x1e, 0xc9, 0x31, - 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x8d, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, - 0x31, 0xbe, 0x78, 0x24, 0xc7, 0xf0, 0xe1, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, - 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xc5, 0x0a, 0xf6, 0x41, 0x12, 0x1b, 0xd8, 0x39, 0xc6, - 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9c, 0xd7, 0x84, 0x46, 0x27, 0x01, 0x00, 0x00, -} - -func (this *HeaderWithValidatorStats) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*HeaderWithValidatorStats) - if !ok { - that2, ok := that.(HeaderWithValidatorStats) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Header.Equal(that1.Header) { - return false - } - if !bytes.Equal(this.ValidatorStatsRootHash, that1.ValidatorStatsRootHash) { - return false - } - return true -} -func (this *HeaderWithValidatorStats) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&block.HeaderWithValidatorStats{") - if this.Header != nil { - s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") - } - s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringHeaderWithValidatorStats(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *HeaderWithValidatorStats) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HeaderWithValidatorStats) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HeaderWithValidatorStats) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.ValidatorStatsRootHash) > 0 { - i -= len(m.ValidatorStatsRootHash) - copy(dAtA[i:], m.ValidatorStatsRootHash) - i = encodeVarintHeaderWithValidatorStats(dAtA, i, uint64(len(m.ValidatorStatsRootHash))) - i-- - dAtA[i] = 0x12 - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintHeaderWithValidatorStats(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintHeaderWithValidatorStats(dAtA []byte, offset int, v uint64) int { - offset -= sovHeaderWithValidatorStats(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *HeaderWithValidatorStats) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovHeaderWithValidatorStats(uint64(l)) - } - l = len(m.ValidatorStatsRootHash) - if l > 0 { - n += 1 + l + sovHeaderWithValidatorStats(uint64(l)) - } - return n -} - -func sovHeaderWithValidatorStats(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozHeaderWithValidatorStats(x uint64) (n int) { - return sovHeaderWithValidatorStats(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *HeaderWithValidatorStats) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&HeaderWithValidatorStats{`, - `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, - `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, - `}`, - }, "") - return s -} -func valueToStringHeaderWithValidatorStats(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *HeaderWithValidatorStats) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHeaderWithValidatorStats - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HeaderWithValidatorStats: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HeaderWithValidatorStats: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHeaderWithValidatorStats - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthHeaderWithValidatorStats - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthHeaderWithValidatorStats - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &Header{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ValidatorStatsRootHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHeaderWithValidatorStats - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthHeaderWithValidatorStats - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthHeaderWithValidatorStats - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ValidatorStatsRootHash = append(m.ValidatorStatsRootHash[:0], dAtA[iNdEx:postIndex]...) - if m.ValidatorStatsRootHash == nil { - m.ValidatorStatsRootHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipHeaderWithValidatorStats(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthHeaderWithValidatorStats - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthHeaderWithValidatorStats - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipHeaderWithValidatorStats(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHeaderWithValidatorStats - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHeaderWithValidatorStats - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHeaderWithValidatorStats - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthHeaderWithValidatorStats - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupHeaderWithValidatorStats - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthHeaderWithValidatorStats - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthHeaderWithValidatorStats = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowHeaderWithValidatorStats = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupHeaderWithValidatorStats = fmt.Errorf("proto: unexpected end of group") -) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go new file mode 100644 index 000000000..450c9bafd --- /dev/null +++ b/data/block/shardHeaderExtended.go @@ -0,0 +1,894 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. shardHeaderExtended.proto +package block + +import ( + "fmt" + "math/big" + + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/headerVersionData" +) + +// GetShardID returns the header shardID +func (she *ShardHeaderExtended) GetShardID() uint32 { + if she == nil { + return 0 + } + if she.Header == nil { + return 0 + } + + return she.Header.GetShardID() +} + +// GetNonce returns the header nonce +func (she *ShardHeaderExtended) GetNonce() uint64 { + if she == nil { + return 0 + } + if she.Header == nil { + return 0 + } + + return she.Header.GetNonce() +} + +// GetEpoch returns the header epoch +func (she *ShardHeaderExtended) GetEpoch() uint32 { + if she == nil { + return 0 + } + if she.Header == nil { + return 0 + } + + return she.Header.GetEpoch() +} + +// GetRound returns the header round +func (she *ShardHeaderExtended) GetRound() uint64 { + if she == nil { + return 0 + } + if she.Header == nil { + return 0 + } + + return she.Header.GetRound() +} + +// GetRootHash returns the header root hash +func (she *ShardHeaderExtended) GetRootHash() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetRootHash() +} + +// GetPrevHash returns the header previous header hash +func (she *ShardHeaderExtended) GetPrevHash() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetPrevHash() +} + +// GetPrevRandSeed returns the header previous random seed +func (she *ShardHeaderExtended) GetPrevRandSeed() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetPrevRandSeed() +} + +// GetRandSeed returns the header random seed +func (she *ShardHeaderExtended) GetRandSeed() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetRandSeed() +} + +// GetPubKeysBitmap returns the header public key bitmap for the aggregated signatures +func (she *ShardHeaderExtended) GetPubKeysBitmap() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetPubKeysBitmap() +} + +// GetSignature returns the header aggregated signature +func (she *ShardHeaderExtended) GetSignature() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetSignature() +} + +// GetLeaderSignature returns the leader signature on top of the finalized (signed) header +func (she *ShardHeaderExtended) GetLeaderSignature() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetLeaderSignature() +} + +// GetChainID returns the chain ID +func (she *ShardHeaderExtended) GetChainID() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetChainID() +} + +// GetSoftwareVersion returns the header software version +func (she *ShardHeaderExtended) GetSoftwareVersion() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetSoftwareVersion() +} + +// GetTimeStamp returns the header timestamp +func (she *ShardHeaderExtended) GetTimeStamp() uint64 { + if she == nil { + return 0 + } + if she.Header == nil { + return 0 + } + + return she.Header.GetTimeStamp() +} + +// GetTxCount returns the number of txs included in the block +func (she *ShardHeaderExtended) GetTxCount() uint32 { + if she == nil { + return 0 + } + if she.Header == nil { + return 0 + } + + return she.Header.GetTxCount() +} + +// GetReceiptsHash returns the header receipt hash +func (she *ShardHeaderExtended) GetReceiptsHash() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetReceiptsHash() +} + +// GetAccumulatedFees returns the block accumulated fees +func (she *ShardHeaderExtended) GetAccumulatedFees() *big.Int { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetAccumulatedFees() +} + +// GetDeveloperFees returns the block developer fees +func (she *ShardHeaderExtended) GetDeveloperFees() *big.Int { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetDeveloperFees() +} + +// GetReserved returns the reserved field +func (she *ShardHeaderExtended) GetReserved() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetReserved() +} + +// GetMetaBlockHashes returns the metaBlock hashes +func (she *ShardHeaderExtended) GetMetaBlockHashes() [][]byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetMetaBlockHashes() +} + +// GetEpochStartMetaHash returns the epoch start metaBlock hash +func (she *ShardHeaderExtended) GetEpochStartMetaHash() []byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetEpochStartMetaHash() +} + +// SetNonce sets header nonce +func (she *ShardHeaderExtended) SetNonce(n uint64) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetNonce(n) +} + +// SetEpoch sets header epoch +func (she *ShardHeaderExtended) SetEpoch(e uint32) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetEpoch(e) +} + +// SetRound sets header round +func (she *ShardHeaderExtended) SetRound(r uint64) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetRound(r) +} + +// SetRootHash sets root hash +func (she *ShardHeaderExtended) SetRootHash(rHash []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetRootHash(rHash) +} + +// SetValidatorStatsRootHash sets the root hash for the validator statistics trie +func (she *ShardHeaderExtended) SetValidatorStatsRootHash(_ []byte) error { + return nil +} + +// SetPrevHash sets prev hash +func (she *ShardHeaderExtended) SetPrevHash(pvHash []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetPrevHash(pvHash) +} + +// SetPrevRandSeed sets previous random seed +func (she *ShardHeaderExtended) SetPrevRandSeed(pvRandSeed []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetPrevRandSeed(pvRandSeed) +} + +// SetRandSeed sets previous random seed +func (she *ShardHeaderExtended) SetRandSeed(randSeed []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetRandSeed(randSeed) +} + +// SetPubKeysBitmap sets public key bitmap +func (she *ShardHeaderExtended) SetPubKeysBitmap(pkbm []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetPubKeysBitmap(pkbm) +} + +// SetSignature sets header signature +func (she *ShardHeaderExtended) SetSignature(sg []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetSignature(sg) +} + +// SetLeaderSignature will set the leader's signature +func (she *ShardHeaderExtended) SetLeaderSignature(sg []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetLeaderSignature(sg) +} + +// SetChainID sets the chain ID on which this block is valid on +func (she *ShardHeaderExtended) SetChainID(chainID []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetChainID(chainID) +} + +// SetSoftwareVersion sets the software version of the header +func (she *ShardHeaderExtended) SetSoftwareVersion(version []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetSoftwareVersion(version) +} + +// SetTimeStamp sets header timestamp +func (she *ShardHeaderExtended) SetTimeStamp(ts uint64) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetTimeStamp(ts) +} + +// SetAccumulatedFees sets the accumulated fees in the header +func (she *ShardHeaderExtended) SetAccumulatedFees(value *big.Int) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetAccumulatedFees(value) +} + +// SetDeveloperFees sets the developer fees in the header +func (she *ShardHeaderExtended) SetDeveloperFees(value *big.Int) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetDeveloperFees(value) +} + +// SetTxCount sets the transaction count of the block associated with this header +func (she *ShardHeaderExtended) SetTxCount(txCount uint32) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetTxCount(txCount) +} + +// SetShardID sets header shard ID +func (she *ShardHeaderExtended) SetShardID(shId uint32) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetShardID(shId) +} + +// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +func (she *ShardHeaderExtended) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetMiniBlockHeadersWithDst(destId) +} + +// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a +// chronological way, taking into consideration the round in which they were created/executed in the sender shard +func (she *ShardHeaderExtended) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetOrderedCrossMiniblocksWithDst(destId) +} + +// GetMiniBlockHeadersHashes gets the miniblock hashes +func (she *ShardHeaderExtended) GetMiniBlockHeadersHashes() [][]byte { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetMiniBlockHeadersHashes() +} + +// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs +func (she *ShardHeaderExtended) MapMiniBlockHashesToShards() map[string]uint32 { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.MapMiniBlockHashesToShards() +} + +// ShallowClone returns a clone of the object +func (she *ShardHeaderExtended) ShallowClone() data.HeaderHandler { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + internalHeaderCopy := *she.Header + headerCopy := *she + headerCopy.Header = &internalHeaderCopy + + return &headerCopy +} + +// IsInterfaceNil returns true if there is no value under the interface +func (she *ShardHeaderExtended) IsInterfaceNil() bool { + return she == nil +} + +// IsStartOfEpochBlock verifies if the block is of type start of epoch +func (she *ShardHeaderExtended) IsStartOfEpochBlock() bool { + if she == nil { + return false + } + if she.Header == nil { + return false + } + + return she.Header.IsStartOfEpochBlock() +} + +// GetBlockBodyTypeInt32 returns the block body type as int32 +func (she *ShardHeaderExtended) GetBlockBodyTypeInt32() int32 { + if she == nil { + return -1 + } + if she.Header == nil { + return -1 + } + + return she.Header.GetBlockBodyTypeInt32() +} + +// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers +func (she *ShardHeaderExtended) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + return she.Header.GetMiniBlockHeaderHandlers() +} + +// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers +func (she *ShardHeaderExtended) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetMiniBlockHeaderHandlers(mbHeaderHandlers) +} + +// SetReceiptsHash sets the receipts hash +func (she *ShardHeaderExtended) SetReceiptsHash(hash []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetReceiptsHash(hash) +} + +// SetMetaBlockHashes sets the metaBlock hashes +func (she *ShardHeaderExtended) SetMetaBlockHashes(hashes [][]byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetMetaBlockHashes(hashes) +} + +// SetEpochStartMetaHash sets the epoch start metaBlock hash +func (she *ShardHeaderExtended) SetEpochStartMetaHash(hash []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + return she.Header.SetEpochStartMetaHash(hash) +} + +// HasScheduledSupport returns true as the second block version does support scheduled data +func (she *ShardHeaderExtended) HasScheduledSupport() bool { + return true +} + +// HasScheduledMiniBlocks returns true if the header has scheduled miniBlock headers +func (she *ShardHeaderExtended) HasScheduledMiniBlocks() bool { + if she == nil { + return false + } + + mbHeaderHandlers := she.GetMiniBlockHeaderHandlers() + for _, mbHeader := range mbHeaderHandlers { + processingType := ProcessingType(mbHeader.GetProcessingType()) + if processingType == Scheduled { + return true + } + } + + return false +} + +// SetScheduledRootHash sets the scheduled root hash +func (she *ShardHeaderExtended) SetScheduledRootHash(rootHash []byte) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + she.Header.ScheduledRootHash = rootHash + + return nil +} + +// SetScheduledAccumulatedFees sets the scheduled accumulated fees +func (she *ShardHeaderExtended) SetScheduledAccumulatedFees(value *big.Int) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + if she.Header.ScheduledAccumulatedFees == nil { + she.Header.ScheduledAccumulatedFees = big.NewInt(0) + } + if value == nil { + value = big.NewInt(0) + } + + she.Header.ScheduledAccumulatedFees.Set(value) + + return nil +} + +// SetScheduledDeveloperFees sets the scheduled developer fees +func (she *ShardHeaderExtended) SetScheduledDeveloperFees(value *big.Int) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + if she.Header.ScheduledDeveloperFees == nil { + she.Header.ScheduledDeveloperFees = big.NewInt(0) + } + if value == nil { + value = big.NewInt(0) + } + + she.Header.ScheduledDeveloperFees.Set(value) + + return nil +} + +// SetScheduledGasProvided sets the scheduled SC calls provided gas +func (she *ShardHeaderExtended) SetScheduledGasProvided(gasProvided uint64) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + she.Header.ScheduledGasProvided = gasProvided + + return nil +} + +// SetScheduledGasPenalized sets the scheduled SC calls penalized gas +func (she *ShardHeaderExtended) SetScheduledGasPenalized(gasPenalized uint64) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + she.Header.ScheduledGasPenalized = gasPenalized + + return nil +} + +// SetScheduledGasRefunded sets the scheduled SC calls refunded gas +func (she *ShardHeaderExtended) SetScheduledGasRefunded(gasRefunded uint64) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + she.Header.ScheduledGasRefunded = gasRefunded + + return nil +} + +// ValidateHeaderVersion does extra validation for header version +func (she *ShardHeaderExtended) ValidateHeaderVersion() error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + + // the header needs to have a not nil & not empty scheduled root hash + if len(she.Header.ScheduledRootHash) == 0 { + return data.ErrNilScheduledRootHash + } + + return she.Header.ValidateHeaderVersion() +} + +// SetAdditionalData sets the additional version related data for the header +func (she *ShardHeaderExtended) SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + if check.IfNil(headerVersionData) { + return data.ErrNilPointerDereference + } + + err := she.SetScheduledRootHash(headerVersionData.GetScheduledRootHash()) + if err != nil { + return err + } + + she.Header.ScheduledGasProvided = headerVersionData.GetScheduledGasProvided() + she.Header.ScheduledGasPenalized = headerVersionData.GetScheduledGasPenalized() + she.Header.ScheduledGasRefunded = headerVersionData.GetScheduledGasRefunded() + + err = she.SetScheduledAccumulatedFees(headerVersionData.GetScheduledAccumulatedFees()) + if err != nil { + return err + } + + return she.SetScheduledDeveloperFees(headerVersionData.GetScheduledDeveloperFees()) +} + +// GetAdditionalData gets the additional version related data for the header +func (she *ShardHeaderExtended) GetAdditionalData() headerVersionData.HeaderAdditionalData { + if she == nil { + return nil + } + if she.Header == nil { + return nil + } + + accFees := big.NewInt(0) + if she.Header.GetScheduledAccumulatedFees() != nil { + accFees = big.NewInt(0).Set(she.Header.GetScheduledAccumulatedFees()) + } + devFees := big.NewInt(0) + if she.Header.GetScheduledDeveloperFees() != nil { + devFees = big.NewInt(0).Set(she.Header.GetScheduledDeveloperFees()) + } + + additionalVersionData := &headerVersionData.AdditionalData{ + ScheduledRootHash: she.Header.GetScheduledRootHash(), + ScheduledAccumulatedFees: accFees, + ScheduledDeveloperFees: devFees, + ScheduledGasProvided: she.Header.GetScheduledGasProvided(), + ScheduledGasPenalized: she.Header.GetScheduledGasPenalized(), + ScheduledGasRefunded: she.Header.GetScheduledGasRefunded(), + } + + return additionalVersionData +} + +// GetValidatorStatsRootHash returns the root hash for the validator statistics trie +func (she *ShardHeaderExtended) GetValidatorStatsRootHash() []byte { + return []byte{} +} + +// CheckFieldsForNil checks a predefined set of fields for nil values +func (she *ShardHeaderExtended) CheckFieldsForNil() error { + if she == nil { + return data.ErrNilPointerReceiver + } + if she.Header == nil { + return data.ErrNilHeader + } + err := she.Header.CheckFieldsForNil() + if err != nil { + return err + } + if she.Header.ScheduledAccumulatedFees == nil { + return fmt.Errorf("%w in ShardHeaderExtended.ScheduledAccumulatedFees", data.ErrNilValue) + } + if she.Header.ScheduledDeveloperFees == nil { + return fmt.Errorf("%w in ShardHeaderExtended.ScheduledDeveloperFees", data.ErrNilValue) + } + + return nil +} + +// GetIncomingMiniBlockHeaderHandlers gets the incoming mini blocks headers as an array of mini blocks headers handlers +func (she *ShardHeaderExtended) GetIncomingMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if she == nil { + return nil + } + + mbHeaders := she.GetIncomingMiniBlockHeaders() + mbHeaderHandlers := make([]data.MiniBlockHeaderHandler, len(mbHeaders)) + + for i := range mbHeaders { + mbHeaderHandlers[i] = &mbHeaders[i] + } + + return mbHeaderHandlers +} + +// SetIncomingMiniBlockHeaderHandlers sets the incoming mini blocks headers from the given array of mini blocks headers handlers +func (she *ShardHeaderExtended) SetIncomingMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if she == nil { + return data.ErrNilPointerReceiver + } + if len(mbHeaderHandlers) == 0 { + she.IncomingMiniBlockHeaders = nil + return nil + } + + incomingMiniBlockHeaders := make([]MiniBlockHeader, len(mbHeaderHandlers)) + for i, mbHeaderHandler := range mbHeaderHandlers { + mbHeader, ok := mbHeaderHandler.(*MiniBlockHeader) + if !ok { + return data.ErrInvalidTypeAssertion + } + + if mbHeader == nil { + return data.ErrNilPointerDereference + } + + incomingMiniBlockHeaders[i] = *mbHeader + } + + she.IncomingMiniBlockHeaders = incomingMiniBlockHeaders + + return nil +} diff --git a/data/block/shardHeaderExtended.pb.go b/data/block/shardHeaderExtended.pb.go new file mode 100644 index 000000000..5aaa8de39 --- /dev/null +++ b/data/block/shardHeaderExtended.pb.go @@ -0,0 +1,476 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: shardHeaderExtended.proto + +package block + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// ShardHeaderExtended extends the Header structure with extra fields for an extended shard header needed by sovereign chain +type ShardHeaderExtended struct { + Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + IncomingMiniBlockHeaders []MiniBlockHeader `protobuf:"bytes,2,rep,name=IncomingMiniBlockHeaders,proto3" json:"IncomingMiniBlockHeaders"` +} + +func (m *ShardHeaderExtended) Reset() { *m = ShardHeaderExtended{} } +func (*ShardHeaderExtended) ProtoMessage() {} +func (*ShardHeaderExtended) Descriptor() ([]byte, []int) { + return fileDescriptor_549610f8c128bd02, []int{0} +} +func (m *ShardHeaderExtended) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ShardHeaderExtended) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *ShardHeaderExtended) XXX_Merge(src proto.Message) { + xxx_messageInfo_ShardHeaderExtended.Merge(m, src) +} +func (m *ShardHeaderExtended) XXX_Size() int { + return m.Size() +} +func (m *ShardHeaderExtended) XXX_DiscardUnknown() { + xxx_messageInfo_ShardHeaderExtended.DiscardUnknown(m) +} + +var xxx_messageInfo_ShardHeaderExtended proto.InternalMessageInfo + +func (m *ShardHeaderExtended) GetHeader() *HeaderV2 { + if m != nil { + return m.Header + } + return nil +} + +func (m *ShardHeaderExtended) GetIncomingMiniBlockHeaders() []MiniBlockHeader { + if m != nil { + return m.IncomingMiniBlockHeaders + } + return nil +} + +func init() { + proto.RegisterType((*ShardHeaderExtended)(nil), "proto.ShardHeaderExtended") +} + +func init() { proto.RegisterFile("shardHeaderExtended.proto", fileDescriptor_549610f8c128bd02) } + +var fileDescriptor_549610f8c128bd02 = []byte{ + // 246 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0xce, 0x48, 0x2c, + 0x4a, 0xf1, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x72, 0xad, 0x28, 0x49, 0xcd, 0x4b, 0x49, 0x4d, 0xd1, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, + 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, 0x60, 0xe1, 0xa4, 0xd2, 0x34, + 0x30, 0x0f, 0xcc, 0x01, 0xb3, 0x20, 0xba, 0xa4, 0xb8, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xa1, 0x1c, + 0x5e, 0x30, 0x27, 0xcc, 0x08, 0xc2, 0x55, 0x9a, 0xc1, 0xc8, 0x25, 0x1c, 0x8c, 0x69, 0x9f, 0x90, + 0x3a, 0x17, 0x1b, 0x44, 0x44, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x88, 0x1f, 0xa2, 0x5e, 0x0f, + 0x22, 0x18, 0x66, 0x14, 0x04, 0x95, 0x16, 0x8a, 0xe0, 0x92, 0xf0, 0xcc, 0x4b, 0xce, 0xcf, 0xcd, + 0xcc, 0x4b, 0xf7, 0xcd, 0xcc, 0xcb, 0x74, 0x02, 0x99, 0x0e, 0x91, 0x2a, 0x96, 0x60, 0x52, 0x60, + 0xd6, 0xe0, 0x36, 0x12, 0x83, 0x6a, 0x45, 0x93, 0x76, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x08, + 0xa7, 0x6e, 0x27, 0xfb, 0x0b, 0x0f, 0xe5, 0x18, 0x6e, 0x3c, 0x94, 0x63, 0xf8, 0xf0, 0x50, 0x8e, + 0xb1, 0xe1, 0x91, 0x1c, 0xe3, 0x8a, 0x47, 0x72, 0x8c, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0x78, 0xe3, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x2f, 0x1e, 0xc9, 0x31, 0x7c, 0x78, + 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, + 0xb1, 0x82, 0xfd, 0x98, 0xc4, 0x06, 0xb6, 0xd7, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x8f, 0x4e, + 0x23, 0xd8, 0x51, 0x01, 0x00, 0x00, +} + +func (this *ShardHeaderExtended) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ShardHeaderExtended) + if !ok { + that2, ok := that.(ShardHeaderExtended) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Header.Equal(that1.Header) { + return false + } + if len(this.IncomingMiniBlockHeaders) != len(that1.IncomingMiniBlockHeaders) { + return false + } + for i := range this.IncomingMiniBlockHeaders { + if !this.IncomingMiniBlockHeaders[i].Equal(&that1.IncomingMiniBlockHeaders[i]) { + return false + } + } + return true +} +func (this *ShardHeaderExtended) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&block.ShardHeaderExtended{") + if this.Header != nil { + s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") + } + if this.IncomingMiniBlockHeaders != nil { + vs := make([]MiniBlockHeader, len(this.IncomingMiniBlockHeaders)) + for i := range vs { + vs[i] = this.IncomingMiniBlockHeaders[i] + } + s = append(s, "IncomingMiniBlockHeaders: "+fmt.Sprintf("%#v", vs)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringShardHeaderExtended(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *ShardHeaderExtended) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ShardHeaderExtended) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ShardHeaderExtended) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.IncomingMiniBlockHeaders) > 0 { + for iNdEx := len(m.IncomingMiniBlockHeaders) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IncomingMiniBlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintShardHeaderExtended(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintShardHeaderExtended(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintShardHeaderExtended(dAtA []byte, offset int, v uint64) int { + offset -= sovShardHeaderExtended(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ShardHeaderExtended) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovShardHeaderExtended(uint64(l)) + } + if len(m.IncomingMiniBlockHeaders) > 0 { + for _, e := range m.IncomingMiniBlockHeaders { + l = e.Size() + n += 1 + l + sovShardHeaderExtended(uint64(l)) + } + } + return n +} + +func sovShardHeaderExtended(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozShardHeaderExtended(x uint64) (n int) { + return sovShardHeaderExtended(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ShardHeaderExtended) String() string { + if this == nil { + return "nil" + } + repeatedStringForIncomingMiniBlockHeaders := "[]MiniBlockHeader{" + for _, f := range this.IncomingMiniBlockHeaders { + repeatedStringForIncomingMiniBlockHeaders += fmt.Sprintf("%v", f) + "," + } + repeatedStringForIncomingMiniBlockHeaders += "}" + s := strings.Join([]string{`&ShardHeaderExtended{`, + `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, + `IncomingMiniBlockHeaders:` + repeatedStringForIncomingMiniBlockHeaders + `,`, + `}`, + }, "") + return s +} +func valueToStringShardHeaderExtended(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *ShardHeaderExtended) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ShardHeaderExtended: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ShardHeaderExtended: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthShardHeaderExtended + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthShardHeaderExtended + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Header == nil { + m.Header = &HeaderV2{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IncomingMiniBlockHeaders", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthShardHeaderExtended + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthShardHeaderExtended + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IncomingMiniBlockHeaders = append(m.IncomingMiniBlockHeaders, MiniBlockHeader{}) + if err := m.IncomingMiniBlockHeaders[len(m.IncomingMiniBlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipShardHeaderExtended(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthShardHeaderExtended + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthShardHeaderExtended + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipShardHeaderExtended(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthShardHeaderExtended + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupShardHeaderExtended + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthShardHeaderExtended + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthShardHeaderExtended = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowShardHeaderExtended = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupShardHeaderExtended = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/block/shardHeaderExtended.proto b/data/block/shardHeaderExtended.proto new file mode 100644 index 000000000..56ff974e2 --- /dev/null +++ b/data/block/shardHeaderExtended.proto @@ -0,0 +1,17 @@ +// This file holds the data structures related with the functionality of an extended shard header needed by sovereign chain +syntax = "proto3"; + +package proto; + +option go_package = "block"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "block.proto"; +import "blockV2.proto"; + +// ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain +message ShardHeaderExtended { + HeaderV2 Header = 1; + repeated MiniBlockHeader IncomingMiniBlockHeaders = 2 [(gogoproto.nullable) = false]; +} diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go new file mode 100644 index 000000000..3d663d22d --- /dev/null +++ b/data/block/sovereignChainHeader.go @@ -0,0 +1,530 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. sovereignChainHeader.proto +package block + +import ( + "fmt" + "math/big" + + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/headerVersionData" +) + +// GetAdditionalData returns nil +func (sch *SovereignChainHeader) GetAdditionalData() headerVersionData.HeaderAdditionalData { + return nil +} + +// HasScheduledMiniBlocks returns false +func (sch *SovereignChainHeader) HasScheduledMiniBlocks() bool { + return false +} + +// SetScheduledRootHash returns nil +func (sch *SovereignChainHeader) SetScheduledRootHash(_ []byte) error { + return nil +} + +// SetAdditionalData will not do anything +func (sch *SovereignChainHeader) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { + return nil +} + +// ShallowClone will return a clone of the object +func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { + if sch == nil || sch.Header == nil { + return nil + } + + internalHeaderCopy := *sch.Header + headerCopy := *sch + headerCopy.Header = &internalHeaderCopy + + return &headerCopy +} + +// GetShardID returns the header shardID +func (sch *SovereignChainHeader) GetShardID() uint32 { + return 0 +} + +// GetNonce returns the header nonce +func (sch *SovereignChainHeader) GetNonce() uint64 { + if sch == nil { + return 0 + } + + return sch.Header.GetNonce() +} + +// GetEpoch returns the header epoch +func (sch *SovereignChainHeader) GetEpoch() uint32 { + if sch == nil { + return 0 + } + + return sch.Header.GetEpoch() +} + +// GetRound returns the header round +func (sch *SovereignChainHeader) GetRound() uint64 { + if sch == nil { + return 0 + } + + return sch.Header.GetRound() +} + +// GetRootHash returns the header root hash +func (sch *SovereignChainHeader) GetRootHash() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetRootHash() +} + +// GetPrevHash returns the header previous header hash +func (sch *SovereignChainHeader) GetPrevHash() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetPrevHash() +} + +// GetPrevRandSeed returns the header previous random seed +func (sch *SovereignChainHeader) GetPrevRandSeed() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetPrevRandSeed() +} + +// GetRandSeed returns the header random seed +func (sch *SovereignChainHeader) GetRandSeed() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetRandSeed() +} + +// GetPubKeysBitmap returns the header public key bitmap for the aggregated signatures +func (sch *SovereignChainHeader) GetPubKeysBitmap() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetPubKeysBitmap() +} + +// GetSignature returns the header aggregated signature +func (sch *SovereignChainHeader) GetSignature() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetSignature() +} + +// GetLeaderSignature returns the leader signature on top of the finalized (signed) header +func (sch *SovereignChainHeader) GetLeaderSignature() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetLeaderSignature() +} + +// GetChainID returns the chain ID +func (sch *SovereignChainHeader) GetChainID() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetChainID() +} + +// GetSoftwareVersion returns the header software version +func (sch *SovereignChainHeader) GetSoftwareVersion() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetSoftwareVersion() +} + +// GetTimeStamp returns the header timestamp +func (sch *SovereignChainHeader) GetTimeStamp() uint64 { + if sch == nil { + return 0 + } + + return sch.Header.GetTimeStamp() +} + +// GetTxCount returns the number of txs included in the block +func (sch *SovereignChainHeader) GetTxCount() uint32 { + if sch == nil { + return 0 + } + + return sch.Header.GetTxCount() +} + +// GetReceiptsHash returns the header receipt hash +func (sch *SovereignChainHeader) GetReceiptsHash() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetReceiptsHash() +} + +// GetAccumulatedFees returns the block accumulated fees +func (sch *SovereignChainHeader) GetAccumulatedFees() *big.Int { + if sch == nil { + return nil + } + + return sch.Header.GetAccumulatedFees() +} + +// GetDeveloperFees returns the block developer fees +func (sch *SovereignChainHeader) GetDeveloperFees() *big.Int { + if sch == nil { + return nil + } + + return sch.Header.GetDeveloperFees() +} + +// GetReserved returns the reserved field +func (sch *SovereignChainHeader) GetReserved() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetReserved() +} + +// GetMetaBlockHashes returns the metaBlock hashes +func (sch *SovereignChainHeader) GetMetaBlockHashes() [][]byte { + if sch == nil { + return nil + } + + return sch.Header.GetMetaBlockHashes() +} + +// GetEpochStartMetaHash returns the epoch start metaBlock hash +func (sch *SovereignChainHeader) GetEpochStartMetaHash() []byte { + if sch == nil { + return nil + } + + return sch.Header.GetEpochStartMetaHash() +} + +// SetNonce sets header nonce +func (sch *SovereignChainHeader) SetNonce(n uint64) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + return sch.Header.SetNonce(n) +} + +// SetEpoch sets header epoch +func (sch *SovereignChainHeader) SetEpoch(e uint32) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetEpoch(e) +} + +// SetRound sets header round +func (sch *SovereignChainHeader) SetRound(r uint64) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetRound(r) +} + +// SetRootHash sets root hash +func (sch *SovereignChainHeader) SetRootHash(rHash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetRootHash(rHash) +} + +// SetPrevHash sets prev hash +func (sch *SovereignChainHeader) SetPrevHash(pvHash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetPrevHash(pvHash) +} + +// SetPrevRandSeed sets previous random seed +func (sch *SovereignChainHeader) SetPrevRandSeed(pvRandSeed []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetPrevRandSeed(pvRandSeed) +} + +// SetRandSeed sets previous random seed +func (sch *SovereignChainHeader) SetRandSeed(randSeed []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetRandSeed(randSeed) +} + +// SetPubKeysBitmap sets public key bitmap +func (sch *SovereignChainHeader) SetPubKeysBitmap(pkbm []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetPubKeysBitmap(pkbm) +} + +// SetSignature sets header signature +func (sch *SovereignChainHeader) SetSignature(sg []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetSignature(sg) +} + +// SetLeaderSignature will set the leader's signature +func (sch *SovereignChainHeader) SetLeaderSignature(sg []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetLeaderSignature(sg) +} + +// SetChainID sets the chain ID on which this block is valid on +func (sch *SovereignChainHeader) SetChainID(chainID []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetChainID(chainID) +} + +// SetSoftwareVersion sets the software version of the header +func (sch *SovereignChainHeader) SetSoftwareVersion(version []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetSoftwareVersion(version) +} + +// SetTimeStamp sets header timestamp +func (sch *SovereignChainHeader) SetTimeStamp(ts uint64) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetTimeStamp(ts) +} + +// SetAccumulatedFees sets the accumulated fees in the header +func (sch *SovereignChainHeader) SetAccumulatedFees(value *big.Int) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetAccumulatedFees(value) +} + +// SetDeveloperFees sets the developer fees in the header +func (sch *SovereignChainHeader) SetDeveloperFees(value *big.Int) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetDeveloperFees(value) +} + +// SetTxCount sets the transaction count of the block associated with this header +func (sch *SovereignChainHeader) SetTxCount(txCount uint32) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetTxCount(txCount) +} + +// SetShardID sets header shard ID +func (sch *SovereignChainHeader) SetShardID(_ uint32) error { + return nil +} + +// SetValidatorStatsRootHash sets the root hash for the validator statistics trie +func (sch *SovereignChainHeader) SetValidatorStatsRootHash(rHash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + sch.ValidatorStatsRootHash = rHash + + return nil +} + +// SetMainChainShardHeaderHashes sets the main chain shard header hashes +func (sch *SovereignChainHeader) SetMainChainShardHeaderHashes(hdrHashes [][]byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + sch.MainChainShardHeaderHashes = hdrHashes + + return nil +} + +// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +func (sch *SovereignChainHeader) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { + if sch == nil { + return nil + } + + return sch.Header.GetMiniBlockHeadersWithDst(destId) +} + +// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a +// chronological way, taking into consideration the round in which they were created/executed in the sender shard +func (sch *SovereignChainHeader) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { + if sch == nil { + return nil + } + + return sch.Header.GetOrderedCrossMiniblocksWithDst(destId) +} + +// GetMiniBlockHeadersHashes gets the miniblock hashes +func (sch *SovereignChainHeader) GetMiniBlockHeadersHashes() [][]byte { + if sch == nil { + return nil + } + + return sch.Header.GetMiniBlockHeadersHashes() +} + +// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs +func (sch *SovereignChainHeader) MapMiniBlockHashesToShards() map[string]uint32 { + if sch == nil { + return nil + } + + return sch.Header.MapMiniBlockHashesToShards() +} + +// IsInterfaceNil returns true if there is no value under the interface +func (sch *SovereignChainHeader) IsInterfaceNil() bool { + return sch == nil +} + +// IsStartOfEpochBlock verifies if the block is of type start of epoch +func (sch *SovereignChainHeader) IsStartOfEpochBlock() bool { + return false +} + +// GetBlockBodyTypeInt32 returns the block body type as int32 +func (sch *SovereignChainHeader) GetBlockBodyTypeInt32() int32 { + if sch == nil { + return -1 + } + + return sch.Header.GetBlockBodyTypeInt32() +} + +// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers +func (sch *SovereignChainHeader) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if sch == nil { + return nil + } + + return sch.Header.GetMiniBlockHeaderHandlers() +} + +// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers +func (sch *SovereignChainHeader) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetMiniBlockHeaderHandlers(mbHeaderHandlers) +} + +// SetReceiptsHash sets the receipts hash +func (sch *SovereignChainHeader) SetReceiptsHash(hash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetReceiptsHash(hash) +} + +// SetMetaBlockHashes sets the metaBlock hashes +func (sch *SovereignChainHeader) SetMetaBlockHashes(hashes [][]byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetMetaBlockHashes(hashes) +} + +// SetEpochStartMetaHash sets the epoch start metaBlock hash +func (sch *SovereignChainHeader) SetEpochStartMetaHash(hash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetEpochStartMetaHash(hash) +} + +// HasScheduledSupport returns true as the second block version does support scheduled data +func (sch *SovereignChainHeader) HasScheduledSupport() bool { + return false +} + +// ValidateHeaderVersion does extra validation for header version +func (sch *SovereignChainHeader) ValidateHeaderVersion() error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return nil +} + +// CheckFieldsForNil checks a predefined set of fields for nil values +func (sch *SovereignChainHeader) CheckFieldsForNil() error { + if sch == nil { + return data.ErrNilPointerReceiver + } + err := sch.Header.CheckFieldsForNil() + if err != nil { + return err + } + + if sch.ValidatorStatsRootHash == nil { + return fmt.Errorf("%w in sch.ValidatorStatsRootHash", data.ErrNilValue) + } + + return nil +} diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go new file mode 100644 index 000000000..58f8ad30a --- /dev/null +++ b/data/block/sovereignChainHeader.pb.go @@ -0,0 +1,518 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sovereignChainHeader.proto + +package block + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain +type SovereignChainHeader struct { + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"ValidatorStatsRootHash,omitempty"` + MainChainShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=MainChainShardHeaderHashes,proto3" json:"MainChainShardHeaderHashes,omitempty"` +} + +func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } +func (*SovereignChainHeader) ProtoMessage() {} +func (*SovereignChainHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_b9b8ff297a820152, []int{0} +} +func (m *SovereignChainHeader) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SovereignChainHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *SovereignChainHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_SovereignChainHeader.Merge(m, src) +} +func (m *SovereignChainHeader) XXX_Size() int { + return m.Size() +} +func (m *SovereignChainHeader) XXX_DiscardUnknown() { + xxx_messageInfo_SovereignChainHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_SovereignChainHeader proto.InternalMessageInfo + +func (m *SovereignChainHeader) GetHeader() *Header { + if m != nil { + return m.Header + } + return nil +} + +func (m *SovereignChainHeader) GetValidatorStatsRootHash() []byte { + if m != nil { + return m.ValidatorStatsRootHash + } + return nil +} + +func (m *SovereignChainHeader) GetMainChainShardHeaderHashes() [][]byte { + if m != nil { + return m.MainChainShardHeaderHashes + } + return nil +} + +func init() { + proto.RegisterType((*SovereignChainHeader)(nil), "proto.SovereignChainHeader") +} + +func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } + +var fileDescriptor_b9b8ff297a820152 = []byte{ + // 260 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0xce, 0x2f, 0x4b, + 0x2d, 0x4a, 0xcd, 0x4c, 0xcf, 0x73, 0xce, 0x48, 0xcc, 0xcc, 0xf3, 0x48, 0x4d, 0x4c, 0x49, 0x2d, + 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, + 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, 0x60, 0xe1, 0xa4, 0xd2, + 0x34, 0x30, 0x0f, 0xcc, 0x01, 0xb3, 0x20, 0xba, 0xa4, 0xb8, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0x21, + 0x1c, 0xa5, 0xad, 0x8c, 0x5c, 0x22, 0xc1, 0x58, 0x6c, 0x10, 0x52, 0xe5, 0x62, 0x83, 0xb0, 0x24, + 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x78, 0x21, 0x1a, 0xf4, 0x20, 0x82, 0x41, 0x50, 0x49, 0x21, + 0x33, 0x2e, 0xb1, 0xb0, 0xc4, 0x9c, 0xcc, 0x94, 0xc4, 0x92, 0xfc, 0xa2, 0xe0, 0x92, 0xc4, 0x92, + 0xe2, 0xa0, 0xfc, 0xfc, 0x12, 0x8f, 0xc4, 0xe2, 0x0c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, + 0x1c, 0xb2, 0x42, 0x76, 0x5c, 0x52, 0xbe, 0x89, 0x99, 0x10, 0x1b, 0x83, 0x33, 0x12, 0x8b, 0x52, + 0x20, 0xe6, 0x81, 0xe4, 0x52, 0x8b, 0x25, 0x98, 0x15, 0x98, 0x35, 0x78, 0x82, 0xf0, 0xa8, 0x70, + 0xb2, 0xbf, 0xf0, 0x50, 0x8e, 0xe1, 0xc6, 0x43, 0x39, 0x86, 0x0f, 0x0f, 0xe5, 0x18, 0x1b, 0x1e, + 0xc9, 0x31, 0xae, 0x78, 0x24, 0xc7, 0x78, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x37, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0xf8, 0xe2, 0x91, 0x1c, 0xc3, 0x87, 0x47, 0x72, 0x8c, + 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x14, 0x2b, 0xd8, + 0xfb, 0x49, 0x6c, 0x60, 0xef, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x5e, 0xff, 0xd4, + 0x60, 0x01, 0x00, 0x00, +} + +func (this *SovereignChainHeader) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*SovereignChainHeader) + if !ok { + that2, ok := that.(SovereignChainHeader) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Header.Equal(that1.Header) { + return false + } + if !bytes.Equal(this.ValidatorStatsRootHash, that1.ValidatorStatsRootHash) { + return false + } + if len(this.MainChainShardHeaderHashes) != len(that1.MainChainShardHeaderHashes) { + return false + } + for i := range this.MainChainShardHeaderHashes { + if !bytes.Equal(this.MainChainShardHeaderHashes[i], that1.MainChainShardHeaderHashes[i]) { + return false + } + } + return true +} +func (this *SovereignChainHeader) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 7) + s = append(s, "&block.SovereignChainHeader{") + if this.Header != nil { + s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") + } + s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") + s = append(s, "MainChainShardHeaderHashes: "+fmt.Sprintf("%#v", this.MainChainShardHeaderHashes)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringSovereignChainHeader(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *SovereignChainHeader) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SovereignChainHeader) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.MainChainShardHeaderHashes) > 0 { + for iNdEx := len(m.MainChainShardHeaderHashes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.MainChainShardHeaderHashes[iNdEx]) + copy(dAtA[i:], m.MainChainShardHeaderHashes[iNdEx]) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.MainChainShardHeaderHashes[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.ValidatorStatsRootHash) > 0 { + i -= len(m.ValidatorStatsRootHash) + copy(dAtA[i:], m.ValidatorStatsRootHash) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.ValidatorStatsRootHash))) + i-- + dAtA[i] = 0x12 + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintSovereignChainHeader(dAtA []byte, offset int, v uint64) int { + offset -= sovSovereignChainHeader(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SovereignChainHeader) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + l = len(m.ValidatorStatsRootHash) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + if len(m.MainChainShardHeaderHashes) > 0 { + for _, b := range m.MainChainShardHeaderHashes { + l = len(b) + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + } + return n +} + +func sovSovereignChainHeader(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSovereignChainHeader(x uint64) (n int) { + return sovSovereignChainHeader(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *SovereignChainHeader) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&SovereignChainHeader{`, + `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, + `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, + `MainChainShardHeaderHashes:` + fmt.Sprintf("%v", this.MainChainShardHeaderHashes) + `,`, + `}`, + }, "") + return s +} +func valueToStringSovereignChainHeader(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SovereignChainHeader: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SovereignChainHeader: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Header == nil { + m.Header = &Header{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorStatsRootHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorStatsRootHash = append(m.ValidatorStatsRootHash[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorStatsRootHash == nil { + m.ValidatorStatsRootHash = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MainChainShardHeaderHashes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MainChainShardHeaderHashes = append(m.MainChainShardHeaderHashes, make([]byte, postIndex-iNdEx)) + copy(m.MainChainShardHeaderHashes[len(m.MainChainShardHeaderHashes)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSovereignChainHeader(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSovereignChainHeader + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSovereignChainHeader + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSovereignChainHeader + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSovereignChainHeader = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSovereignChainHeader = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSovereignChainHeader = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/block/headerWithValidatorStats.proto b/data/block/sovereignChainHeader.proto similarity index 53% rename from data/block/headerWithValidatorStats.proto rename to data/block/sovereignChainHeader.proto index f0993f505..621e1788c 100644 --- a/data/block/headerWithValidatorStats.proto +++ b/data/block/sovereignChainHeader.proto @@ -1,4 +1,4 @@ -// This file holds the data structures related with the functionality of a shard block V2 +// This file holds the data structures related with the functionality of a sovereign chain header syntax = "proto3"; package proto; @@ -9,8 +9,9 @@ option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "block.proto"; -// HeaderWithValidatorStats extends the Header structure with extra fields for validator statistics -message HeaderWithValidatorStats { +// SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain +message SovereignChainHeader { Header Header = 1; - bytes ValidatorStatsRootHash = 2; + bytes ValidatorStatsRootHash = 2; + repeated bytes MainChainShardHeaderHashes = 3; } diff --git a/data/errors.go b/data/errors.go index b6ea00c95..34e2a1f54 100644 --- a/data/errors.go +++ b/data/errors.go @@ -84,3 +84,6 @@ var ErrNilReservedField = errors.New("reserved field is nil") // ErrWrongTypeAssertion signals that there was a wrong type assertion var ErrWrongTypeAssertion = errors.New("wrong type assertion") + +// ErrNilHeader signals that a nil header has been provided +var ErrNilHeader = errors.New("nil header") diff --git a/data/interface.go b/data/interface.go index 96ad4b1c1..0b46d2ff5 100644 --- a/data/interface.go +++ b/data/interface.go @@ -78,11 +78,13 @@ type CommonHeaderHandler interface { IsInterfaceNil() bool } -// ValidatorStatisticsInfoHandler simple handler needed for validator info -type ValidatorStatisticsInfoHandler interface { +// SovereignChainHeaderHandler defines getters and setters for the sovereign chain header +type SovereignChainHeaderHandler interface { + CommonHeaderHandler SetValidatorStatsRootHash(rHash []byte) error GetValidatorStatsRootHash() []byte - IsInterfaceNil() bool + SetMainChainShardHeaderHashes(hdrHashes [][]byte) error + GetMainChainShardHeaderHashes() [][]byte } // HeaderHandler defines getters and setters for header data holder @@ -412,3 +414,10 @@ type UserAccountHandler interface { AddressBytes() []byte IsInterfaceNil() bool } + +// ShardHeaderExtendedHandler extends ShardHeaderHandler interface, by also including incoming mini blocks needed by sovereign chain +type ShardHeaderExtendedHandler interface { + ShardHeaderHandler + GetIncomingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler + SetIncomingMiniBlockHeaderHandlers(mbHeaderHandlers []MiniBlockHeaderHandler) error +} From 5b728ddbdaf000c779db631ea33a641662a3db1c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 16 Mar 2023 12:18:44 +0200 Subject: [PATCH 18/87] fix after review --- data/block/headerWithValidatorStats.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go index 4868c34bc..a858c68b2 100644 --- a/data/block/headerWithValidatorStats.go +++ b/data/block/headerWithValidatorStats.go @@ -386,7 +386,7 @@ func (hv *HeaderWithValidatorStats) SetValidatorStatsRootHash(rHash []byte) erro return nil } -// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +// GetMiniBlockHeadersWithDst returns the miniblocks headers hashes for the destination shard func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { if hv == nil { return nil @@ -487,7 +487,7 @@ func (hv *HeaderWithValidatorStats) SetEpochStartMetaHash(hash []byte) error { return hv.Header.SetEpochStartMetaHash(hash) } -// HasScheduledSupport returns true as the second block version does support scheduled data +// HasScheduledSupport returns true for headerWithValidatorStats func (hv *HeaderWithValidatorStats) HasScheduledSupport() bool { return false } From b78e771c628a4e343ebc207adf0f95b90243143d Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 16 Mar 2023 16:52:01 +0200 Subject: [PATCH 19/87] * Added new structures and interfaces needed by sovereign chain --- data/block/headerWithValidatorStats.go | 519 ------------------------- data/block/sovereignChainHeader.go | 8 +- data/interface.go | 2 +- 3 files changed, 5 insertions(+), 524 deletions(-) delete mode 100644 data/block/headerWithValidatorStats.go diff --git a/data/block/headerWithValidatorStats.go b/data/block/headerWithValidatorStats.go deleted file mode 100644 index a858c68b2..000000000 --- a/data/block/headerWithValidatorStats.go +++ /dev/null @@ -1,519 +0,0 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. block.proto -package block - -import ( - "fmt" - "math/big" - - "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-core-go/data/headerVersionData" -) - -// GetAdditionalData returns nil -func (hv *HeaderWithValidatorStats) GetAdditionalData() headerVersionData.HeaderAdditionalData { - return nil -} - -// HasScheduledMiniBlocks returns false -func (hv *HeaderWithValidatorStats) HasScheduledMiniBlocks() bool { - return false -} - -// SetScheduledRootHash returns nil -func (hv *HeaderWithValidatorStats) SetScheduledRootHash(_ []byte) error { - return nil -} - -// SetAdditionalData will not do anything -func (hv *HeaderWithValidatorStats) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { - return nil -} - -// ShallowClone will return a clone of the object -func (hv *HeaderWithValidatorStats) ShallowClone() data.HeaderHandler { - if hv == nil || hv.Header == nil { - return nil - } - - internalHeaderCopy := *hv.Header - headerCopy := *hv - headerCopy.Header = &internalHeaderCopy - - return &headerCopy -} - -// GetShardID returns the header shardID -func (hv *HeaderWithValidatorStats) GetShardID() uint32 { - return 0 -} - -// GetNonce returns the header nonce -func (hv *HeaderWithValidatorStats) GetNonce() uint64 { - if hv == nil { - return 0 - } - - return hv.Header.GetNonce() -} - -// GetEpoch returns the header epoch -func (hv *HeaderWithValidatorStats) GetEpoch() uint32 { - if hv == nil { - return 0 - } - - return hv.Header.GetEpoch() -} - -// GetRound returns the header round -func (hv *HeaderWithValidatorStats) GetRound() uint64 { - if hv == nil { - return 0 - } - - return hv.Header.GetRound() -} - -// GetRootHash returns the header root hash -func (hv *HeaderWithValidatorStats) GetRootHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetRootHash() -} - -// GetPrevHash returns the header previous header hash -func (hv *HeaderWithValidatorStats) GetPrevHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetPrevHash() -} - -// GetPrevRandSeed returns the header previous random seed -func (hv *HeaderWithValidatorStats) GetPrevRandSeed() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetPrevRandSeed() -} - -// GetRandSeed returns the header random seed -func (hv *HeaderWithValidatorStats) GetRandSeed() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetRandSeed() -} - -// GetPubKeysBitmap returns the header public key bitmap for the aggregated signatures -func (hv *HeaderWithValidatorStats) GetPubKeysBitmap() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetPubKeysBitmap() -} - -// GetSignature returns the header aggregated signature -func (hv *HeaderWithValidatorStats) GetSignature() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetSignature() -} - -// GetLeaderSignature returns the leader signature on top of the finalized (signed) header -func (hv *HeaderWithValidatorStats) GetLeaderSignature() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetLeaderSignature() -} - -// GetChainID returns the chain ID -func (hv *HeaderWithValidatorStats) GetChainID() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetChainID() -} - -// GetSoftwareVersion returns the header software version -func (hv *HeaderWithValidatorStats) GetSoftwareVersion() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetSoftwareVersion() -} - -// GetTimeStamp returns the header timestamp -func (hv *HeaderWithValidatorStats) GetTimeStamp() uint64 { - if hv == nil { - return 0 - } - - return hv.Header.GetTimeStamp() -} - -// GetTxCount returns the number of txs included in the block -func (hv *HeaderWithValidatorStats) GetTxCount() uint32 { - if hv == nil { - return 0 - } - - return hv.Header.GetTxCount() -} - -// GetReceiptsHash returns the header receipt hash -func (hv *HeaderWithValidatorStats) GetReceiptsHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetReceiptsHash() -} - -// GetAccumulatedFees returns the block accumulated fees -func (hv *HeaderWithValidatorStats) GetAccumulatedFees() *big.Int { - if hv == nil { - return nil - } - - return hv.Header.GetAccumulatedFees() -} - -// GetDeveloperFees returns the block developer fees -func (hv *HeaderWithValidatorStats) GetDeveloperFees() *big.Int { - if hv == nil { - return nil - } - - return hv.Header.GetDeveloperFees() -} - -// GetReserved returns the reserved field -func (hv *HeaderWithValidatorStats) GetReserved() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetReserved() -} - -// GetMetaBlockHashes returns the metaBlock hashes -func (hv *HeaderWithValidatorStats) GetMetaBlockHashes() [][]byte { - if hv == nil { - return nil - } - - return hv.Header.GetMetaBlockHashes() -} - -// GetEpochStartMetaHash returns the epoch start metaBlock hash -func (hv *HeaderWithValidatorStats) GetEpochStartMetaHash() []byte { - if hv == nil { - return nil - } - - return hv.Header.GetEpochStartMetaHash() -} - -// SetNonce sets header nonce -func (hv *HeaderWithValidatorStats) SetNonce(n uint64) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - return hv.Header.SetNonce(n) -} - -// SetEpoch sets header epoch -func (hv *HeaderWithValidatorStats) SetEpoch(e uint32) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetEpoch(e) -} - -// SetRound sets header round -func (hv *HeaderWithValidatorStats) SetRound(r uint64) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetRound(r) -} - -// SetRootHash sets root hash -func (hv *HeaderWithValidatorStats) SetRootHash(rHash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetRootHash(rHash) -} - -// SetPrevHash sets prev hash -func (hv *HeaderWithValidatorStats) SetPrevHash(pvHash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetPrevHash(pvHash) -} - -// SetPrevRandSeed sets previous random seed -func (hv *HeaderWithValidatorStats) SetPrevRandSeed(pvRandSeed []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetPrevRandSeed(pvRandSeed) -} - -// SetRandSeed sets previous random seed -func (hv *HeaderWithValidatorStats) SetRandSeed(randSeed []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetRandSeed(randSeed) -} - -// SetPubKeysBitmap sets public key bitmap -func (hv *HeaderWithValidatorStats) SetPubKeysBitmap(pkbm []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetPubKeysBitmap(pkbm) -} - -// SetSignature sets header signature -func (hv *HeaderWithValidatorStats) SetSignature(sg []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetSignature(sg) -} - -// SetLeaderSignature will set the leader's signature -func (hv *HeaderWithValidatorStats) SetLeaderSignature(sg []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetLeaderSignature(sg) -} - -// SetChainID sets the chain ID on which this block is valid on -func (hv *HeaderWithValidatorStats) SetChainID(chainID []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetChainID(chainID) -} - -// SetSoftwareVersion sets the software version of the header -func (hv *HeaderWithValidatorStats) SetSoftwareVersion(version []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetSoftwareVersion(version) -} - -// SetTimeStamp sets header timestamp -func (hv *HeaderWithValidatorStats) SetTimeStamp(ts uint64) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetTimeStamp(ts) -} - -// SetAccumulatedFees sets the accumulated fees in the header -func (hv *HeaderWithValidatorStats) SetAccumulatedFees(value *big.Int) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetAccumulatedFees(value) -} - -// SetDeveloperFees sets the developer fees in the header -func (hv *HeaderWithValidatorStats) SetDeveloperFees(value *big.Int) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetDeveloperFees(value) -} - -// SetTxCount sets the transaction count of the block associated with this header -func (hv *HeaderWithValidatorStats) SetTxCount(txCount uint32) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetTxCount(txCount) -} - -// SetShardID sets header shard ID -func (hv *HeaderWithValidatorStats) SetShardID(_ uint32) error { - return nil -} - -// SetValidatorStatsRootHash sets the root hash for the validator statistics trie -func (hv *HeaderWithValidatorStats) SetValidatorStatsRootHash(rHash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - hv.ValidatorStatsRootHash = rHash - - return nil -} - -// GetMiniBlockHeadersWithDst returns the miniblocks headers hashes for the destination shard -func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { - if hv == nil { - return nil - } - - return hv.Header.GetMiniBlockHeadersWithDst(destId) -} - -// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a -// chronological way, taking into consideration the round in which they were created/executed in the sender shard -func (hv *HeaderWithValidatorStats) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { - if hv == nil { - return nil - } - - return hv.Header.GetOrderedCrossMiniblocksWithDst(destId) -} - -// GetMiniBlockHeadersHashes gets the miniblock hashes -func (hv *HeaderWithValidatorStats) GetMiniBlockHeadersHashes() [][]byte { - if hv == nil { - return nil - } - - return hv.Header.GetMiniBlockHeadersHashes() -} - -// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs -func (hv *HeaderWithValidatorStats) MapMiniBlockHashesToShards() map[string]uint32 { - if hv == nil { - return nil - } - - return hv.Header.MapMiniBlockHashesToShards() -} - -// IsInterfaceNil returns true if there is no value under the interface -func (hv *HeaderWithValidatorStats) IsInterfaceNil() bool { - return hv == nil -} - -// IsStartOfEpochBlock verifies if the block is of type start of epoch -func (hv *HeaderWithValidatorStats) IsStartOfEpochBlock() bool { - return false -} - -// GetBlockBodyTypeInt32 returns the block body type as int32 -func (hv *HeaderWithValidatorStats) GetBlockBodyTypeInt32() int32 { - if hv == nil { - return -1 - } - - return hv.Header.GetBlockBodyTypeInt32() -} - -// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers -func (hv *HeaderWithValidatorStats) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { - if hv == nil { - return nil - } - - return hv.Header.GetMiniBlockHeaderHandlers() -} - -// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers -func (hv *HeaderWithValidatorStats) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetMiniBlockHeaderHandlers(mbHeaderHandlers) -} - -// SetReceiptsHash sets the receipts hash -func (hv *HeaderWithValidatorStats) SetReceiptsHash(hash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetReceiptsHash(hash) -} - -// SetMetaBlockHashes sets the metaBlock hashes -func (hv *HeaderWithValidatorStats) SetMetaBlockHashes(hashes [][]byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetMetaBlockHashes(hashes) -} - -// SetEpochStartMetaHash sets the epoch start metaBlock hash -func (hv *HeaderWithValidatorStats) SetEpochStartMetaHash(hash []byte) error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return hv.Header.SetEpochStartMetaHash(hash) -} - -// HasScheduledSupport returns true for headerWithValidatorStats -func (hv *HeaderWithValidatorStats) HasScheduledSupport() bool { - return false -} - -// ValidateHeaderVersion does extra validation for header version -func (hv *HeaderWithValidatorStats) ValidateHeaderVersion() error { - if hv == nil { - return data.ErrNilPointerReceiver - } - - return nil -} - -// CheckFieldsForNil checks a predefined set of fields for nil values -func (hv *HeaderWithValidatorStats) CheckFieldsForNil() error { - if hv == nil { - return data.ErrNilPointerReceiver - } - err := hv.Header.CheckFieldsForNil() - if err != nil { - return err - } - - if hv.ValidatorStatsRootHash == nil { - return fmt.Errorf("%w in hv.ValidatorStatsRootHash", data.ErrNilValue) - } - - return nil -} diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 3d663d22d..426485d36 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -376,12 +376,12 @@ func (sch *SovereignChainHeader) SetShardID(_ uint32) error { } // SetValidatorStatsRootHash sets the root hash for the validator statistics trie -func (sch *SovereignChainHeader) SetValidatorStatsRootHash(rHash []byte) error { +func (sch *SovereignChainHeader) SetValidatorStatsRootHash(rootHash []byte) error { if sch == nil { return data.ErrNilPointerReceiver } - sch.ValidatorStatsRootHash = rHash + sch.ValidatorStatsRootHash = rootHash return nil } @@ -397,7 +397,7 @@ func (sch *SovereignChainHeader) SetMainChainShardHeaderHashes(hdrHashes [][]byt return nil } -// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +// GetMiniBlockHeadersWithDst returns the miniblocks headers hashes for the destination shard func (sch *SovereignChainHeader) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { if sch == nil { return nil @@ -498,7 +498,7 @@ func (sch *SovereignChainHeader) SetEpochStartMetaHash(hash []byte) error { return sch.Header.SetEpochStartMetaHash(hash) } -// HasScheduledSupport returns true as the second block version does support scheduled data +// HasScheduledSupport returns false for sovereign chain header func (sch *SovereignChainHeader) HasScheduledSupport() bool { return false } diff --git a/data/interface.go b/data/interface.go index 0b46d2ff5..aa6787818 100644 --- a/data/interface.go +++ b/data/interface.go @@ -81,7 +81,7 @@ type CommonHeaderHandler interface { // SovereignChainHeaderHandler defines getters and setters for the sovereign chain header type SovereignChainHeaderHandler interface { CommonHeaderHandler - SetValidatorStatsRootHash(rHash []byte) error + SetValidatorStatsRootHash(rootHash []byte) error GetValidatorStatsRootHash() []byte SetMainChainShardHeaderHashes(hdrHashes [][]byte) error GetMainChainShardHeaderHashes() [][]byte From 0301933918440dde327a76fb6d69b4be0c79dbcb Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 16 Mar 2023 19:44:01 +0200 Subject: [PATCH 20/87] * Fixed after review --- data/block/shardHeaderExtended.go | 40 ++++++++++++------------ data/block/sovereignChainHeader.go | 50 +++++++++++++++--------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index 450c9bafd..8cb86bd79 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -262,7 +262,7 @@ func (she *ShardHeaderExtended) GetEpochStartMetaHash() []byte { return she.Header.GetEpochStartMetaHash() } -// SetNonce sets header nonce +// SetNonce sets the header nonce func (she *ShardHeaderExtended) SetNonce(n uint64) error { if she == nil { return data.ErrNilPointerReceiver @@ -274,7 +274,7 @@ func (she *ShardHeaderExtended) SetNonce(n uint64) error { return she.Header.SetNonce(n) } -// SetEpoch sets header epoch +// SetEpoch sets the header epoch func (she *ShardHeaderExtended) SetEpoch(e uint32) error { if she == nil { return data.ErrNilPointerReceiver @@ -286,7 +286,7 @@ func (she *ShardHeaderExtended) SetEpoch(e uint32) error { return she.Header.SetEpoch(e) } -// SetRound sets header round +// SetRound sets the header round func (she *ShardHeaderExtended) SetRound(r uint64) error { if she == nil { return data.ErrNilPointerReceiver @@ -298,7 +298,7 @@ func (she *ShardHeaderExtended) SetRound(r uint64) error { return she.Header.SetRound(r) } -// SetRootHash sets root hash +// SetRootHash sets the root hash func (she *ShardHeaderExtended) SetRootHash(rHash []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -310,12 +310,12 @@ func (she *ShardHeaderExtended) SetRootHash(rHash []byte) error { return she.Header.SetRootHash(rHash) } -// SetValidatorStatsRootHash sets the root hash for the validator statistics trie +// SetValidatorStatsRootHash does nothing and returns nil func (she *ShardHeaderExtended) SetValidatorStatsRootHash(_ []byte) error { return nil } -// SetPrevHash sets prev hash +// SetPrevHash sets the previous hash func (she *ShardHeaderExtended) SetPrevHash(pvHash []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -327,7 +327,7 @@ func (she *ShardHeaderExtended) SetPrevHash(pvHash []byte) error { return she.Header.SetPrevHash(pvHash) } -// SetPrevRandSeed sets previous random seed +// SetPrevRandSeed sets the previous random seed func (she *ShardHeaderExtended) SetPrevRandSeed(pvRandSeed []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -339,7 +339,7 @@ func (she *ShardHeaderExtended) SetPrevRandSeed(pvRandSeed []byte) error { return she.Header.SetPrevRandSeed(pvRandSeed) } -// SetRandSeed sets previous random seed +// SetRandSeed sets the random seed func (she *ShardHeaderExtended) SetRandSeed(randSeed []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -351,7 +351,7 @@ func (she *ShardHeaderExtended) SetRandSeed(randSeed []byte) error { return she.Header.SetRandSeed(randSeed) } -// SetPubKeysBitmap sets public key bitmap +// SetPubKeysBitmap sets the public key bitmap func (she *ShardHeaderExtended) SetPubKeysBitmap(pkbm []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -363,7 +363,7 @@ func (she *ShardHeaderExtended) SetPubKeysBitmap(pkbm []byte) error { return she.Header.SetPubKeysBitmap(pkbm) } -// SetSignature sets header signature +// SetSignature sets the header signature func (she *ShardHeaderExtended) SetSignature(sg []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -375,7 +375,7 @@ func (she *ShardHeaderExtended) SetSignature(sg []byte) error { return she.Header.SetSignature(sg) } -// SetLeaderSignature will set the leader's signature +// SetLeaderSignature sets the leader's signature func (she *ShardHeaderExtended) SetLeaderSignature(sg []byte) error { if she == nil { return data.ErrNilPointerReceiver @@ -411,7 +411,7 @@ func (she *ShardHeaderExtended) SetSoftwareVersion(version []byte) error { return she.Header.SetSoftwareVersion(version) } -// SetTimeStamp sets header timestamp +// SetTimeStamp sets the header timestamp func (she *ShardHeaderExtended) SetTimeStamp(ts uint64) error { if she == nil { return data.ErrNilPointerReceiver @@ -459,7 +459,7 @@ func (she *ShardHeaderExtended) SetTxCount(txCount uint32) error { return she.Header.SetTxCount(txCount) } -// SetShardID sets header shard ID +// SetShardID sets the header shard ID func (she *ShardHeaderExtended) SetShardID(shId uint32) error { if she == nil { return data.ErrNilPointerReceiver @@ -471,7 +471,7 @@ func (she *ShardHeaderExtended) SetShardID(shId uint32) error { return she.Header.SetShardID(shId) } -// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +// GetMiniBlockHeadersWithDst gets the map of miniBlockHeader hashes and sender IDs func (she *ShardHeaderExtended) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { if she == nil { return nil @@ -483,7 +483,7 @@ func (she *ShardHeaderExtended) GetMiniBlockHeadersWithDst(destId uint32) map[st return she.Header.GetMiniBlockHeadersWithDst(destId) } -// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a +// GetOrderedCrossMiniblocksWithDst gets all the cross miniBlocks with the given destination shard ID, ordered in a // chronological way, taking into consideration the round in which they were created/executed in the sender shard func (she *ShardHeaderExtended) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { if she == nil { @@ -496,7 +496,7 @@ func (she *ShardHeaderExtended) GetOrderedCrossMiniblocksWithDst(destId uint32) return she.Header.GetOrderedCrossMiniblocksWithDst(destId) } -// GetMiniBlockHeadersHashes gets the miniblock hashes +// GetMiniBlockHeadersHashes gets the miniBlock hashes func (she *ShardHeaderExtended) GetMiniBlockHeadersHashes() [][]byte { if she == nil { return nil @@ -508,7 +508,7 @@ func (she *ShardHeaderExtended) GetMiniBlockHeadersHashes() [][]byte { return she.Header.GetMiniBlockHeadersHashes() } -// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs +// MapMiniBlockHashesToShards gets the map of miniBlock hashes and sender IDs func (she *ShardHeaderExtended) MapMiniBlockHashesToShards() map[string]uint32 { if she == nil { return nil @@ -553,7 +553,7 @@ func (she *ShardHeaderExtended) IsStartOfEpochBlock() bool { return she.Header.IsStartOfEpochBlock() } -// GetBlockBodyTypeInt32 returns the block body type as int32 +// GetBlockBodyTypeInt32 returns the blockBody type as int32 func (she *ShardHeaderExtended) GetBlockBodyTypeInt32() int32 { if she == nil { return -1 @@ -821,9 +821,9 @@ func (she *ShardHeaderExtended) GetAdditionalData() headerVersionData.HeaderAddi return additionalVersionData } -// GetValidatorStatsRootHash returns the root hash for the validator statistics trie +// GetValidatorStatsRootHash returns an empty byte slice func (she *ShardHeaderExtended) GetValidatorStatsRootHash() []byte { - return []byte{} + return make([]byte, 0) } // CheckFieldsForNil checks a predefined set of fields for nil values diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 426485d36..42e845ec9 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -9,27 +9,27 @@ import ( "github.com/multiversx/mx-chain-core-go/data/headerVersionData" ) -// GetAdditionalData returns nil +// GetAdditionalData returns nil for the sovereign chain header func (sch *SovereignChainHeader) GetAdditionalData() headerVersionData.HeaderAdditionalData { return nil } -// HasScheduledMiniBlocks returns false +// HasScheduledMiniBlocks returns false for the sovereign chain header func (sch *SovereignChainHeader) HasScheduledMiniBlocks() bool { return false } -// SetScheduledRootHash returns nil +// SetScheduledRootHash does nothing and returns nil for the sovereign chain header func (sch *SovereignChainHeader) SetScheduledRootHash(_ []byte) error { return nil } -// SetAdditionalData will not do anything +// SetAdditionalData does nothing and returns nil for the sovereign chain header func (sch *SovereignChainHeader) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { return nil } -// ShallowClone will return a clone of the object +// ShallowClone returns a clone of the object func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { if sch == nil || sch.Header == nil { return nil @@ -42,7 +42,7 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { return &headerCopy } -// GetShardID returns the header shardID +// GetShardID returns 0 as the shardID for the sovereign chain header func (sch *SovereignChainHeader) GetShardID() uint32 { return 0 } @@ -227,7 +227,7 @@ func (sch *SovereignChainHeader) GetEpochStartMetaHash() []byte { return sch.Header.GetEpochStartMetaHash() } -// SetNonce sets header nonce +// SetNonce sets the header nonce func (sch *SovereignChainHeader) SetNonce(n uint64) error { if sch == nil { return data.ErrNilPointerReceiver @@ -235,7 +235,7 @@ func (sch *SovereignChainHeader) SetNonce(n uint64) error { return sch.Header.SetNonce(n) } -// SetEpoch sets header epoch +// SetEpoch sets the header epoch func (sch *SovereignChainHeader) SetEpoch(e uint32) error { if sch == nil { return data.ErrNilPointerReceiver @@ -244,7 +244,7 @@ func (sch *SovereignChainHeader) SetEpoch(e uint32) error { return sch.Header.SetEpoch(e) } -// SetRound sets header round +// SetRound sets the header round func (sch *SovereignChainHeader) SetRound(r uint64) error { if sch == nil { return data.ErrNilPointerReceiver @@ -253,7 +253,7 @@ func (sch *SovereignChainHeader) SetRound(r uint64) error { return sch.Header.SetRound(r) } -// SetRootHash sets root hash +// SetRootHash sets the root hash func (sch *SovereignChainHeader) SetRootHash(rHash []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -262,7 +262,7 @@ func (sch *SovereignChainHeader) SetRootHash(rHash []byte) error { return sch.Header.SetRootHash(rHash) } -// SetPrevHash sets prev hash +// SetPrevHash sets the previous hash func (sch *SovereignChainHeader) SetPrevHash(pvHash []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -271,7 +271,7 @@ func (sch *SovereignChainHeader) SetPrevHash(pvHash []byte) error { return sch.Header.SetPrevHash(pvHash) } -// SetPrevRandSeed sets previous random seed +// SetPrevRandSeed sets the previous random seed func (sch *SovereignChainHeader) SetPrevRandSeed(pvRandSeed []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -280,7 +280,7 @@ func (sch *SovereignChainHeader) SetPrevRandSeed(pvRandSeed []byte) error { return sch.Header.SetPrevRandSeed(pvRandSeed) } -// SetRandSeed sets previous random seed +// SetRandSeed sets the random seed func (sch *SovereignChainHeader) SetRandSeed(randSeed []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -289,7 +289,7 @@ func (sch *SovereignChainHeader) SetRandSeed(randSeed []byte) error { return sch.Header.SetRandSeed(randSeed) } -// SetPubKeysBitmap sets public key bitmap +// SetPubKeysBitmap sets the public key bitmap func (sch *SovereignChainHeader) SetPubKeysBitmap(pkbm []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -298,7 +298,7 @@ func (sch *SovereignChainHeader) SetPubKeysBitmap(pkbm []byte) error { return sch.Header.SetPubKeysBitmap(pkbm) } -// SetSignature sets header signature +// SetSignature sets the header signature func (sch *SovereignChainHeader) SetSignature(sg []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -307,7 +307,7 @@ func (sch *SovereignChainHeader) SetSignature(sg []byte) error { return sch.Header.SetSignature(sg) } -// SetLeaderSignature will set the leader's signature +// SetLeaderSignature sets the leader's signature func (sch *SovereignChainHeader) SetLeaderSignature(sg []byte) error { if sch == nil { return data.ErrNilPointerReceiver @@ -334,7 +334,7 @@ func (sch *SovereignChainHeader) SetSoftwareVersion(version []byte) error { return sch.Header.SetSoftwareVersion(version) } -// SetTimeStamp sets header timestamp +// SetTimeStamp sets the header timestamp func (sch *SovereignChainHeader) SetTimeStamp(ts uint64) error { if sch == nil { return data.ErrNilPointerReceiver @@ -370,7 +370,7 @@ func (sch *SovereignChainHeader) SetTxCount(txCount uint32) error { return sch.Header.SetTxCount(txCount) } -// SetShardID sets header shard ID +// SetShardID does nothing and returns nil for the sovereign chain header func (sch *SovereignChainHeader) SetShardID(_ uint32) error { return nil } @@ -406,7 +406,7 @@ func (sch *SovereignChainHeader) GetMiniBlockHeadersWithDst(destId uint32) map[s return sch.Header.GetMiniBlockHeadersWithDst(destId) } -// GetOrderedCrossMiniblocksWithDst gets all cross miniblocks with the given destination shard ID, ordered in a +// GetOrderedCrossMiniblocksWithDst gets all the cross miniblocks with the given destination shard ID, ordered in a // chronological way, taking into consideration the round in which they were created/executed in the sender shard func (sch *SovereignChainHeader) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { if sch == nil { @@ -416,7 +416,7 @@ func (sch *SovereignChainHeader) GetOrderedCrossMiniblocksWithDst(destId uint32) return sch.Header.GetOrderedCrossMiniblocksWithDst(destId) } -// GetMiniBlockHeadersHashes gets the miniblock hashes +// GetMiniBlockHeadersHashes gets the miniBlock hashes func (sch *SovereignChainHeader) GetMiniBlockHeadersHashes() [][]byte { if sch == nil { return nil @@ -425,7 +425,7 @@ func (sch *SovereignChainHeader) GetMiniBlockHeadersHashes() [][]byte { return sch.Header.GetMiniBlockHeadersHashes() } -// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs +// MapMiniBlockHashesToShards gets the map of miniBlock hashes and sender IDs func (sch *SovereignChainHeader) MapMiniBlockHashesToShards() map[string]uint32 { if sch == nil { return nil @@ -439,12 +439,12 @@ func (sch *SovereignChainHeader) IsInterfaceNil() bool { return sch == nil } -// IsStartOfEpochBlock verifies if the block is of type start of epoch +// IsStartOfEpochBlock returns false for the sovereign chain header func (sch *SovereignChainHeader) IsStartOfEpochBlock() bool { return false } -// GetBlockBodyTypeInt32 returns the block body type as int32 +// GetBlockBodyTypeInt32 returns the blockBody type as int32 func (sch *SovereignChainHeader) GetBlockBodyTypeInt32() int32 { if sch == nil { return -1 @@ -498,12 +498,12 @@ func (sch *SovereignChainHeader) SetEpochStartMetaHash(hash []byte) error { return sch.Header.SetEpochStartMetaHash(hash) } -// HasScheduledSupport returns false for sovereign chain header +// HasScheduledSupport returns false for the sovereign chain header func (sch *SovereignChainHeader) HasScheduledSupport() bool { return false } -// ValidateHeaderVersion does extra validation for header version +// ValidateHeaderVersion does extra validation for the header version func (sch *SovereignChainHeader) ValidateHeaderVersion() error { if sch == nil { return data.ErrNilPointerReceiver From 7005f2163e00f2b5a0b176d6bb191dff6d078a7c Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 16 Mar 2023 20:55:42 +0200 Subject: [PATCH 21/87] * Added validator statistics info handler interface --- data/interface.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/data/interface.go b/data/interface.go index aa6787818..784b14ad0 100644 --- a/data/interface.go +++ b/data/interface.go @@ -78,6 +78,13 @@ type CommonHeaderHandler interface { IsInterfaceNil() bool } +// ValidatorStatisticsInfoHandler is a simple handler needed for validator statistics info +type ValidatorStatisticsInfoHandler interface { + SetValidatorStatsRootHash(rHash []byte) error + GetValidatorStatsRootHash() []byte + IsInterfaceNil() bool +} + // SovereignChainHeaderHandler defines getters and setters for the sovereign chain header type SovereignChainHeaderHandler interface { CommonHeaderHandler From 341f4325b7be99d6355c239b76c49b04583450c2 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 16 Mar 2023 20:57:53 +0200 Subject: [PATCH 22/87] * Renamed parameter --- data/interface.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/interface.go b/data/interface.go index 784b14ad0..9f9812a98 100644 --- a/data/interface.go +++ b/data/interface.go @@ -80,7 +80,7 @@ type CommonHeaderHandler interface { // ValidatorStatisticsInfoHandler is a simple handler needed for validator statistics info type ValidatorStatisticsInfoHandler interface { - SetValidatorStatsRootHash(rHash []byte) error + SetValidatorStatsRootHash(rootHash []byte) error GetValidatorStatsRootHash() []byte IsInterfaceNil() bool } From 3a3403a32e281127a3d18b254f54fb0bcdd206f5 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Wed, 22 Mar 2023 16:45:33 +0200 Subject: [PATCH 23/87] * Refactored shard header extended DTO --- data/block/shardHeaderExtended.go | 42 +++++----------- data/block/shardHeaderExtended.pb.go | 73 +++++++++++++--------------- data/block/shardHeaderExtended.proto | 2 +- data/interface.go | 5 +- 4 files changed, 49 insertions(+), 73 deletions(-) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index 8cb86bd79..b036c8ee0 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -848,47 +848,27 @@ func (she *ShardHeaderExtended) CheckFieldsForNil() error { return nil } -// GetIncomingMiniBlockHeaderHandlers gets the incoming mini blocks headers as an array of mini blocks headers handlers -func (she *ShardHeaderExtended) GetIncomingMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { - if she == nil { - return nil - } - - mbHeaders := she.GetIncomingMiniBlockHeaders() - mbHeaderHandlers := make([]data.MiniBlockHeaderHandler, len(mbHeaders)) - - for i := range mbHeaders { - mbHeaderHandlers[i] = &mbHeaders[i] - } - - return mbHeaderHandlers -} - -// SetIncomingMiniBlockHeaderHandlers sets the incoming mini blocks headers from the given array of mini blocks headers handlers -func (she *ShardHeaderExtended) SetIncomingMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { +// SetIncomingMiniBlocks sets the incoming mini blocks from the given array of mini blocks +func (she *ShardHeaderExtended) SetIncomingMiniBlocks(miniBlocksHandlers []data.MiniBlockHandler) error { if she == nil { return data.ErrNilPointerReceiver } - if len(mbHeaderHandlers) == 0 { - she.IncomingMiniBlockHeaders = nil + if len(miniBlocksHandlers) == 0 { + she.IncomingMiniBlocks = nil return nil } - incomingMiniBlockHeaders := make([]MiniBlockHeader, len(mbHeaderHandlers)) - for i, mbHeaderHandler := range mbHeaderHandlers { - mbHeader, ok := mbHeaderHandler.(*MiniBlockHeader) + incomingMiniBlocks := make([]*MiniBlock, len(miniBlocksHandlers)) + for i, miniBlockHandler := range miniBlocksHandlers { + miniBlockHandlerClone := miniBlockHandler.Clone() + miniBlock, ok := miniBlockHandlerClone.(*MiniBlock) if !ok { - return data.ErrInvalidTypeAssertion + return data.ErrWrongTypeAssertion } - - if mbHeader == nil { - return data.ErrNilPointerDereference - } - - incomingMiniBlockHeaders[i] = *mbHeader + she.IncomingMiniBlocks[i] = miniBlock } - she.IncomingMiniBlockHeaders = incomingMiniBlockHeaders + she.IncomingMiniBlocks = incomingMiniBlocks return nil } diff --git a/data/block/shardHeaderExtended.pb.go b/data/block/shardHeaderExtended.pb.go index 5aaa8de39..9b0f93837 100644 --- a/data/block/shardHeaderExtended.pb.go +++ b/data/block/shardHeaderExtended.pb.go @@ -25,10 +25,10 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// ShardHeaderExtended extends the Header structure with extra fields for an extended shard header needed by sovereign chain +// ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain type ShardHeaderExtended struct { - Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` - IncomingMiniBlockHeaders []MiniBlockHeader `protobuf:"bytes,2,rep,name=IncomingMiniBlockHeaders,proto3" json:"IncomingMiniBlockHeaders"` + Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"IncomingMiniBlocks,omitempty"` } func (m *ShardHeaderExtended) Reset() { *m = ShardHeaderExtended{} } @@ -66,9 +66,9 @@ func (m *ShardHeaderExtended) GetHeader() *HeaderV2 { return nil } -func (m *ShardHeaderExtended) GetIncomingMiniBlockHeaders() []MiniBlockHeader { +func (m *ShardHeaderExtended) GetIncomingMiniBlocks() []*MiniBlock { if m != nil { - return m.IncomingMiniBlockHeaders + return m.IncomingMiniBlocks } return nil } @@ -80,23 +80,22 @@ func init() { func init() { proto.RegisterFile("shardHeaderExtended.proto", fileDescriptor_549610f8c128bd02) } var fileDescriptor_549610f8c128bd02 = []byte{ - // 246 bytes of a gzipped FileDescriptorProto + // 238 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0xce, 0x48, 0x2c, 0x4a, 0xf1, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x72, 0xad, 0x28, 0x49, 0xcd, 0x4b, 0x49, 0x4d, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, 0x60, 0xe1, 0xa4, 0xd2, 0x34, 0x30, 0x0f, 0xcc, 0x01, 0xb3, 0x20, 0xba, 0xa4, 0xb8, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xa1, 0x1c, - 0x5e, 0x30, 0x27, 0xcc, 0x08, 0xc2, 0x55, 0x9a, 0xc1, 0xc8, 0x25, 0x1c, 0x8c, 0x69, 0x9f, 0x90, - 0x3a, 0x17, 0x1b, 0x44, 0x44, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x88, 0x1f, 0xa2, 0x5e, 0x0f, - 0x22, 0x18, 0x66, 0x14, 0x04, 0x95, 0x16, 0x8a, 0xe0, 0x92, 0xf0, 0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0x52, 0x60, 0xd6, 0xe0, + 0x36, 0x12, 0x80, 0x6a, 0x82, 0x4b, 0x04, 0x61, 0x51, 0xeb, 0x64, 0x7f, 0xe1, 0xa1, 0x1c, 0xc3, + 0x8d, 0x87, 0x72, 0x0c, 0x1f, 0x1e, 0xca, 0x31, 0x36, 0x3c, 0x92, 0x63, 0x5c, 0xf1, 0x48, 0x8e, + 0xf1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x6f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, + 0x8e, 0xf1, 0xc5, 0x23, 0x39, 0x86, 0x0f, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, + 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x56, 0xb0, 0x5f, 0x92, 0xd8, 0xc0, 0xb6, 0x18, + 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xc7, 0xa2, 0xea, 0x4d, 0x39, 0x01, 0x00, 0x00, } func (this *ShardHeaderExtended) Equal(that interface{}) bool { @@ -121,11 +120,11 @@ func (this *ShardHeaderExtended) Equal(that interface{}) bool { if !this.Header.Equal(that1.Header) { return false } - if len(this.IncomingMiniBlockHeaders) != len(that1.IncomingMiniBlockHeaders) { + if len(this.IncomingMiniBlocks) != len(that1.IncomingMiniBlocks) { return false } - for i := range this.IncomingMiniBlockHeaders { - if !this.IncomingMiniBlockHeaders[i].Equal(&that1.IncomingMiniBlockHeaders[i]) { + for i := range this.IncomingMiniBlocks { + if !this.IncomingMiniBlocks[i].Equal(that1.IncomingMiniBlocks[i]) { return false } } @@ -140,12 +139,8 @@ func (this *ShardHeaderExtended) GoString() string { if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") } - if this.IncomingMiniBlockHeaders != nil { - vs := make([]MiniBlockHeader, len(this.IncomingMiniBlockHeaders)) - for i := range vs { - vs[i] = this.IncomingMiniBlockHeaders[i] - } - s = append(s, "IncomingMiniBlockHeaders: "+fmt.Sprintf("%#v", vs)+",\n") + if this.IncomingMiniBlocks != nil { + s = append(s, "IncomingMiniBlocks: "+fmt.Sprintf("%#v", this.IncomingMiniBlocks)+",\n") } s = append(s, "}") return strings.Join(s, "") @@ -178,10 +173,10 @@ func (m *ShardHeaderExtended) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.IncomingMiniBlockHeaders) > 0 { - for iNdEx := len(m.IncomingMiniBlockHeaders) - 1; iNdEx >= 0; iNdEx-- { + if len(m.IncomingMiniBlocks) > 0 { + for iNdEx := len(m.IncomingMiniBlocks) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.IncomingMiniBlockHeaders[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.IncomingMiniBlocks[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -228,8 +223,8 @@ func (m *ShardHeaderExtended) Size() (n int) { l = m.Header.Size() n += 1 + l + sovShardHeaderExtended(uint64(l)) } - if len(m.IncomingMiniBlockHeaders) > 0 { - for _, e := range m.IncomingMiniBlockHeaders { + if len(m.IncomingMiniBlocks) > 0 { + for _, e := range m.IncomingMiniBlocks { l = e.Size() n += 1 + l + sovShardHeaderExtended(uint64(l)) } @@ -247,14 +242,14 @@ func (this *ShardHeaderExtended) String() string { if this == nil { return "nil" } - repeatedStringForIncomingMiniBlockHeaders := "[]MiniBlockHeader{" - for _, f := range this.IncomingMiniBlockHeaders { - repeatedStringForIncomingMiniBlockHeaders += fmt.Sprintf("%v", f) + "," + repeatedStringForIncomingMiniBlocks := "[]*MiniBlock{" + for _, f := range this.IncomingMiniBlocks { + repeatedStringForIncomingMiniBlocks += strings.Replace(fmt.Sprintf("%v", f), "MiniBlock", "MiniBlock", 1) + "," } - repeatedStringForIncomingMiniBlockHeaders += "}" + repeatedStringForIncomingMiniBlocks += "}" s := strings.Join([]string{`&ShardHeaderExtended{`, `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, - `IncomingMiniBlockHeaders:` + repeatedStringForIncomingMiniBlockHeaders + `,`, + `IncomingMiniBlocks:` + repeatedStringForIncomingMiniBlocks + `,`, `}`, }, "") return s @@ -334,7 +329,7 @@ func (m *ShardHeaderExtended) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field IncomingMiniBlockHeaders", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field IncomingMiniBlocks", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -361,8 +356,8 @@ func (m *ShardHeaderExtended) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.IncomingMiniBlockHeaders = append(m.IncomingMiniBlockHeaders, MiniBlockHeader{}) - if err := m.IncomingMiniBlockHeaders[len(m.IncomingMiniBlockHeaders)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.IncomingMiniBlocks = append(m.IncomingMiniBlocks, &MiniBlock{}) + if err := m.IncomingMiniBlocks[len(m.IncomingMiniBlocks)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/data/block/shardHeaderExtended.proto b/data/block/shardHeaderExtended.proto index 56ff974e2..04ee31542 100644 --- a/data/block/shardHeaderExtended.proto +++ b/data/block/shardHeaderExtended.proto @@ -13,5 +13,5 @@ import "blockV2.proto"; // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain message ShardHeaderExtended { HeaderV2 Header = 1; - repeated MiniBlockHeader IncomingMiniBlockHeaders = 2 [(gogoproto.nullable) = false]; + repeated MiniBlock IncomingMiniBlocks = 2; } diff --git a/data/interface.go b/data/interface.go index 9f9812a98..979e7adba 100644 --- a/data/interface.go +++ b/data/interface.go @@ -3,6 +3,7 @@ package data import ( "math/big" + "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" ) @@ -425,6 +426,6 @@ type UserAccountHandler interface { // ShardHeaderExtendedHandler extends ShardHeaderHandler interface, by also including incoming mini blocks needed by sovereign chain type ShardHeaderExtendedHandler interface { ShardHeaderHandler - GetIncomingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler - SetIncomingMiniBlockHeaderHandlers(mbHeaderHandlers []MiniBlockHeaderHandler) error + GetIncomingMiniBlocks() []*block.MiniBlock + SetIncomingMiniBlocks(miniBlocksHandlers []MiniBlockHandler) error } From 87025744048586853c9aacbca6a529ecc0e3332d Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Wed, 22 Mar 2023 17:03:41 +0200 Subject: [PATCH 24/87] * Renamed input parameter --- data/block/shardHeaderExtended.go | 8 ++++---- data/interface.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index b036c8ee0..25e1d7b7a 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -849,17 +849,17 @@ func (she *ShardHeaderExtended) CheckFieldsForNil() error { } // SetIncomingMiniBlocks sets the incoming mini blocks from the given array of mini blocks -func (she *ShardHeaderExtended) SetIncomingMiniBlocks(miniBlocksHandlers []data.MiniBlockHandler) error { +func (she *ShardHeaderExtended) SetIncomingMiniBlocks(miniBlockHandlers []data.MiniBlockHandler) error { if she == nil { return data.ErrNilPointerReceiver } - if len(miniBlocksHandlers) == 0 { + if len(miniBlockHandlers) == 0 { she.IncomingMiniBlocks = nil return nil } - incomingMiniBlocks := make([]*MiniBlock, len(miniBlocksHandlers)) - for i, miniBlockHandler := range miniBlocksHandlers { + incomingMiniBlocks := make([]*MiniBlock, len(miniBlockHandlers)) + for i, miniBlockHandler := range miniBlockHandlers { miniBlockHandlerClone := miniBlockHandler.Clone() miniBlock, ok := miniBlockHandlerClone.(*MiniBlock) if !ok { diff --git a/data/interface.go b/data/interface.go index 979e7adba..5fb40cede 100644 --- a/data/interface.go +++ b/data/interface.go @@ -427,5 +427,5 @@ type UserAccountHandler interface { type ShardHeaderExtendedHandler interface { ShardHeaderHandler GetIncomingMiniBlocks() []*block.MiniBlock - SetIncomingMiniBlocks(miniBlocksHandlers []MiniBlockHandler) error + SetIncomingMiniBlocks(miniBlockHandlers []MiniBlockHandler) error } From 3e413d0e5d337fda85883d918b1aeab562d1309d Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Wed, 22 Mar 2023 17:32:59 +0200 Subject: [PATCH 25/87] * Fixed cycle imports --- data/block/shardHeaderExtended.go | 20 ++++++++++++++++++-- data/interface.go | 5 ++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index 25e1d7b7a..2007a2f9a 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -848,8 +848,24 @@ func (she *ShardHeaderExtended) CheckFieldsForNil() error { return nil } -// SetIncomingMiniBlocks sets the incoming mini blocks from the given array of mini blocks -func (she *ShardHeaderExtended) SetIncomingMiniBlocks(miniBlockHandlers []data.MiniBlockHandler) error { +// GetIncomingMiniBlockHandlers gets the incoming mini blocks as an array of mini blocks handlers +func (she *ShardHeaderExtended) GetIncomingMiniBlockHandlers() []data.MiniBlockHandler { + if she == nil { + return nil + } + + miniBlocks := she.GetIncomingMiniBlocks() + miniBlockHandlers := make([]data.MiniBlockHandler, len(miniBlocks)) + + for i := range miniBlocks { + miniBlockHandlers[i] = miniBlocks[i] + } + + return miniBlockHandlers +} + +// SetIncomingMiniBlockHandlers sets the incoming mini blocks from the given array of mini blocks handlers +func (she *ShardHeaderExtended) SetIncomingMiniBlockHandlers(miniBlockHandlers []data.MiniBlockHandler) error { if she == nil { return data.ErrNilPointerReceiver } diff --git a/data/interface.go b/data/interface.go index 5fb40cede..7bc99f23d 100644 --- a/data/interface.go +++ b/data/interface.go @@ -3,7 +3,6 @@ package data import ( "math/big" - "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" ) @@ -426,6 +425,6 @@ type UserAccountHandler interface { // ShardHeaderExtendedHandler extends ShardHeaderHandler interface, by also including incoming mini blocks needed by sovereign chain type ShardHeaderExtendedHandler interface { ShardHeaderHandler - GetIncomingMiniBlocks() []*block.MiniBlock - SetIncomingMiniBlocks(miniBlockHandlers []MiniBlockHandler) error + GetIncomingMiniBlockHandlers() []MiniBlockHandler + SetIncomingMiniBlockHandlers(miniBlockHandlers []MiniBlockHandler) error } From d8949193df9e25b514455701cbaf839566901fc1 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Wed, 22 Mar 2023 17:35:34 +0200 Subject: [PATCH 26/87] * Fixed set of incoming mini blocks --- data/block/shardHeaderExtended.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index 2007a2f9a..dc5b2b25c 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -881,7 +881,8 @@ func (she *ShardHeaderExtended) SetIncomingMiniBlockHandlers(miniBlockHandlers [ if !ok { return data.ErrWrongTypeAssertion } - she.IncomingMiniBlocks[i] = miniBlock + + incomingMiniBlocks[i] = miniBlock } she.IncomingMiniBlocks = incomingMiniBlocks From 8a3d5f673d638e747231c258602c1b65bb60516c Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Wed, 22 Mar 2023 21:57:23 +0200 Subject: [PATCH 27/87] * Added support for sovereign transaction --- data/sovereignTx/sovereignTx.go | 57 +++ data/sovereignTx/sovereignTx.pb.go | 701 +++++++++++++++++++++++++++ data/sovereignTx/sovereignTx.proto | 19 + data/sovereignTx/sovereignTx_test.go | 85 ++++ 4 files changed, 862 insertions(+) create mode 100644 data/sovereignTx/sovereignTx.go create mode 100644 data/sovereignTx/sovereignTx.pb.go create mode 100644 data/sovereignTx/sovereignTx.proto create mode 100644 data/sovereignTx/sovereignTx_test.go diff --git a/data/sovereignTx/sovereignTx.go b/data/sovereignTx/sovereignTx.go new file mode 100644 index 000000000..a2fedab14 --- /dev/null +++ b/data/sovereignTx/sovereignTx.go @@ -0,0 +1,57 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. sovereignTx.proto +package sovereignTx + +import ( + "github.com/multiversx/mx-chain-core-go/data" + "math/big" +) + +var _ = data.TransactionHandler(&SovereignTx{}) + +// IsInterfaceNil verifies if underlying object is nil +func (stx *SovereignTx) IsInterfaceNil() bool { + return stx == nil +} + +// SetValue sets the value of the sovereign transaction +func (stx *SovereignTx) SetValue(value *big.Int) { + stx.Value = value +} + +// SetData sets the data of the sovereign transaction +func (stx *SovereignTx) SetData(data []byte) { + stx.Data = data +} + +// SetRcvAddr sets the receiver address of the sovereign transaction +func (stx *SovereignTx) SetRcvAddr(addr []byte) { + stx.RcvAddr = addr +} + +// SetSndAddr sets the sender address of the sovereign transaction +func (stx *SovereignTx) SetSndAddr(addr []byte) { + stx.SndAddr = addr +} + +// GetRcvUserName returns nil for sovereign transaction +func (stx *SovereignTx) GetRcvUserName() []byte { + return nil +} + +// CheckIntegrity checks the integrity of sovereign transaction's fields +func (stx *SovereignTx) CheckIntegrity() error { + if len(stx.RcvAddr) == 0 { + return data.ErrNilRcvAddr + } + if len(stx.SndAddr) == 0 { + return data.ErrNilSndAddr + } + if stx.Value == nil { + return data.ErrNilValue + } + if stx.Value.Sign() < 0 { + return data.ErrNegativeValue + } + + return nil +} diff --git a/data/sovereignTx/sovereignTx.pb.go b/data/sovereignTx/sovereignTx.pb.go new file mode 100644 index 000000000..a3f4a3e35 --- /dev/null +++ b/data/sovereignTx/sovereignTx.pb.go @@ -0,0 +1,701 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sovereignTx.proto + +package sovereignTx + +import ( + bytes "bytes" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_multiversx_mx_chain_core_go_data "github.com/multiversx/mx-chain-core-go/data" + io "io" + math "math" + math_big "math/big" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type SovereignTx struct { + Nonce uint64 `protobuf:"varint,1,opt,name=Nonce,proto3" json:"nonce"` + Value *math_big.Int `protobuf:"bytes,2,opt,name=Value,proto3,casttypewith=math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster" json:"value"` + RcvAddr []byte `protobuf:"bytes,3,opt,name=RcvAddr,proto3" json:"receiver"` + SndAddr []byte `protobuf:"bytes,4,opt,name=SndAddr,proto3" json:"sender"` + GasLimit uint64 `protobuf:"varint,5,opt,name=GasLimit,proto3" json:"gasLimit"` + GasPrice uint64 `protobuf:"varint,6,opt,name=GasPrice,proto3" json:"gasPrice"` + Data []byte `protobuf:"bytes,7,opt,name=Data,proto3" json:"data,omitempty"` +} + +func (m *SovereignTx) Reset() { *m = SovereignTx{} } +func (*SovereignTx) ProtoMessage() {} +func (*SovereignTx) Descriptor() ([]byte, []int) { + return fileDescriptor_3309200ee9b6aa5f, []int{0} +} +func (m *SovereignTx) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SovereignTx) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *SovereignTx) XXX_Merge(src proto.Message) { + xxx_messageInfo_SovereignTx.Merge(m, src) +} +func (m *SovereignTx) XXX_Size() int { + return m.Size() +} +func (m *SovereignTx) XXX_DiscardUnknown() { + xxx_messageInfo_SovereignTx.DiscardUnknown(m) +} + +var xxx_messageInfo_SovereignTx proto.InternalMessageInfo + +func (m *SovereignTx) GetNonce() uint64 { + if m != nil { + return m.Nonce + } + return 0 +} + +func (m *SovereignTx) GetValue() *math_big.Int { + if m != nil { + return m.Value + } + return nil +} + +func (m *SovereignTx) GetRcvAddr() []byte { + if m != nil { + return m.RcvAddr + } + return nil +} + +func (m *SovereignTx) GetSndAddr() []byte { + if m != nil { + return m.SndAddr + } + return nil +} + +func (m *SovereignTx) GetGasLimit() uint64 { + if m != nil { + return m.GasLimit + } + return 0 +} + +func (m *SovereignTx) GetGasPrice() uint64 { + if m != nil { + return m.GasPrice + } + return 0 +} + +func (m *SovereignTx) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func init() { + proto.RegisterType((*SovereignTx)(nil), "proto.SovereignTx") +} + +func init() { proto.RegisterFile("sovereignTx.proto", fileDescriptor_3309200ee9b6aa5f) } + +var fileDescriptor_3309200ee9b6aa5f = []byte{ + // 385 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0xb1, 0xae, 0xd3, 0x30, + 0x14, 0x86, 0xe3, 0x4b, 0xd3, 0x5e, 0x7c, 0xaf, 0x90, 0xf0, 0x14, 0x31, 0x38, 0x57, 0x08, 0x5d, + 0x75, 0x20, 0xc9, 0xc0, 0xc8, 0x44, 0xe0, 0x0a, 0x55, 0x42, 0x08, 0xb9, 0x88, 0x81, 0xcd, 0x49, + 0x8c, 0x63, 0xa9, 0xb1, 0x2b, 0xc7, 0x89, 0xca, 0xc6, 0x23, 0xf0, 0x18, 0x88, 0x27, 0x61, 0xec, + 0xd8, 0x29, 0x50, 0x77, 0x41, 0x99, 0xfa, 0x08, 0x28, 0x6e, 0x29, 0x65, 0xb2, 0xcf, 0xff, 0x7f, + 0x3e, 0xbf, 0x8f, 0x0e, 0x7c, 0x58, 0xab, 0x96, 0x69, 0x26, 0xb8, 0x7c, 0xbf,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, 0xf8, 0x51, 0x23, 0x27, 0xf7, 0x48, 0xbe, 0xd3, 0x22, 0x67, 0xc1, 0xf8, 0x3f, + 0xd2, 0x69, 0xe4, 0xe4, 0xa2, 0x5b, 0x38, 0x7a, 0x45, 0x0d, 0x0d, 0x26, 0x2e, 0x16, 0xf5, 0x5d, + 0xf8, 0x60, 0x98, 0xe6, 0xa9, 0xaa, 0x84, 0x61, 0xd5, 0xd2, 0x7c, 0x26, 0xce, 0x4f, 0xef, 0xd6, + 0x5b, 0xec, 0x6d, 0xb6, 0xd8, 0xdb, 0x6f, 0x31, 0xf8, 0x62, 0x31, 0xf8, 0x66, 0x31, 0xf8, 0x61, + 0x31, 0x58, 0x5b, 0x0c, 0x36, 0x16, 0x83, 0x5f, 0x16, 0x83, 0xdf, 0x16, 0x7b, 0x7b, 0x8b, 0xc1, + 0xd7, 0x1d, 0xf6, 0xd6, 0x3b, 0xec, 0x6d, 0x76, 0xd8, 0xfb, 0x78, 0x75, 0xb6, 0xe7, 0x6c, 0xec, + 0x56, 0xf6, 0xec, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x87, 0xb5, 0xbe, 0x2f, 0xfd, 0x01, 0x00, + 0x00, +} + +func (this *SovereignTx) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*SovereignTx) + if !ok { + that2, ok := that.(SovereignTx) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Nonce != that1.Nonce { + return false + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + if !__caster.Equal(this.Value, that1.Value) { + return false + } + } + if !bytes.Equal(this.RcvAddr, that1.RcvAddr) { + return false + } + if !bytes.Equal(this.SndAddr, that1.SndAddr) { + return false + } + if this.GasLimit != that1.GasLimit { + return false + } + if this.GasPrice != that1.GasPrice { + return false + } + if !bytes.Equal(this.Data, that1.Data) { + return false + } + return true +} +func (this *SovereignTx) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 11) + s = append(s, "&sovereignTx.SovereignTx{") + s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") + s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") + s = append(s, "RcvAddr: "+fmt.Sprintf("%#v", this.RcvAddr)+",\n") + s = append(s, "SndAddr: "+fmt.Sprintf("%#v", this.SndAddr)+",\n") + s = append(s, "GasLimit: "+fmt.Sprintf("%#v", this.GasLimit)+",\n") + s = append(s, "GasPrice: "+fmt.Sprintf("%#v", this.GasPrice)+",\n") + s = append(s, "Data: "+fmt.Sprintf("%#v", this.Data)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringSovereignTx(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *SovereignTx) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SovereignTx) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SovereignTx) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintSovereignTx(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x3a + } + if m.GasPrice != 0 { + i = encodeVarintSovereignTx(dAtA, i, uint64(m.GasPrice)) + i-- + dAtA[i] = 0x30 + } + if m.GasLimit != 0 { + i = encodeVarintSovereignTx(dAtA, i, uint64(m.GasLimit)) + i-- + dAtA[i] = 0x28 + } + if len(m.SndAddr) > 0 { + i -= len(m.SndAddr) + copy(dAtA[i:], m.SndAddr) + i = encodeVarintSovereignTx(dAtA, i, uint64(len(m.SndAddr))) + i-- + dAtA[i] = 0x22 + } + if len(m.RcvAddr) > 0 { + i -= len(m.RcvAddr) + copy(dAtA[i:], m.RcvAddr) + i = encodeVarintSovereignTx(dAtA, i, uint64(len(m.RcvAddr))) + i-- + dAtA[i] = 0x1a + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + size := __caster.Size(m.Value) + i -= size + if _, err := __caster.MarshalTo(m.Value, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintSovereignTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.Nonce != 0 { + i = encodeVarintSovereignTx(dAtA, i, uint64(m.Nonce)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintSovereignTx(dAtA []byte, offset int, v uint64) int { + offset -= sovSovereignTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SovereignTx) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Nonce != 0 { + n += 1 + sovSovereignTx(uint64(m.Nonce)) + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + l = __caster.Size(m.Value) + n += 1 + l + sovSovereignTx(uint64(l)) + } + l = len(m.RcvAddr) + if l > 0 { + n += 1 + l + sovSovereignTx(uint64(l)) + } + l = len(m.SndAddr) + if l > 0 { + n += 1 + l + sovSovereignTx(uint64(l)) + } + if m.GasLimit != 0 { + n += 1 + sovSovereignTx(uint64(m.GasLimit)) + } + if m.GasPrice != 0 { + n += 1 + sovSovereignTx(uint64(m.GasPrice)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovSovereignTx(uint64(l)) + } + return n +} + +func sovSovereignTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSovereignTx(x uint64) (n int) { + return sovSovereignTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *SovereignTx) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&SovereignTx{`, + `Nonce:` + fmt.Sprintf("%v", this.Nonce) + `,`, + `Value:` + fmt.Sprintf("%v", this.Value) + `,`, + `RcvAddr:` + fmt.Sprintf("%v", this.RcvAddr) + `,`, + `SndAddr:` + fmt.Sprintf("%v", this.SndAddr) + `,`, + `GasLimit:` + fmt.Sprintf("%v", this.GasLimit) + `,`, + `GasPrice:` + fmt.Sprintf("%v", this.GasPrice) + `,`, + `Data:` + fmt.Sprintf("%v", this.Data) + `,`, + `}`, + }, "") + return s +} +func valueToStringSovereignTx(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *SovereignTx) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SovereignTx: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SovereignTx: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Nonce", wireType) + } + m.Nonce = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Nonce |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.Value = tmp + } + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RcvAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RcvAddr = append(m.RcvAddr[:0], dAtA[iNdEx:postIndex]...) + if m.RcvAddr == nil { + m.RcvAddr = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SndAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SndAddr = append(m.SndAddr[:0], dAtA[iNdEx:postIndex]...) + if m.SndAddr == nil { + m.SndAddr = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasLimit", wireType) + } + m.GasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasPrice", wireType) + } + m.GasPrice = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasPrice |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSovereignTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSovereignTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSovereignTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSovereignTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSovereignTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSovereignTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSovereignTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSovereignTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSovereignTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSovereignTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSovereignTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/sovereignTx/sovereignTx.proto b/data/sovereignTx/sovereignTx.proto new file mode 100644 index 000000000..033ec71f9 --- /dev/null +++ b/data/sovereignTx/sovereignTx.proto @@ -0,0 +1,19 @@ + +syntax = "proto3"; + +package proto; + +option go_package = "sovereignTx"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +message SovereignTx { + uint64 Nonce = 1 [(gogoproto.jsontag) = "nonce"]; + bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; + bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"]; + bytes SndAddr = 4 [(gogoproto.jsontag) = "sender"]; + uint64 GasLimit = 5 [(gogoproto.jsontag) = "gasLimit"]; + uint64 GasPrice = 6 [(gogoproto.jsontag) = "gasPrice"]; + bytes Data = 7 [(gogoproto.jsontag) = "data,omitempty"]; +} diff --git a/data/sovereignTx/sovereignTx_test.go b/data/sovereignTx/sovereignTx_test.go new file mode 100644 index 000000000..fea8cf087 --- /dev/null +++ b/data/sovereignTx/sovereignTx_test.go @@ -0,0 +1,85 @@ +package sovereignTx_test + +import ( + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/sovereignTx" + "github.com/stretchr/testify/assert" +) + +func TestSovereignTx_SettersAndGetters(t *testing.T) { + t.Parallel() + + nonce := uint64(5) + gasPrice := uint64(1) + gasLimit := uint64(10) + stx := sovereignTx.SovereignTx{ + Nonce: nonce, + GasPrice: gasPrice, + GasLimit: gasLimit, + } + + rcvAddr := []byte("rcv address") + sndAddr := []byte("snd address") + value := big.NewInt(37) + txData := []byte("data") + + stx.SetRcvAddr(rcvAddr) + stx.SetSndAddr(sndAddr) + stx.SetValue(value) + stx.SetData(txData) + + assert.Equal(t, sndAddr, stx.GetSndAddr()) + assert.Equal(t, rcvAddr, stx.GetRcvAddr()) + assert.Equal(t, value, stx.GetValue()) + assert.Equal(t, txData, stx.GetData()) + assert.Equal(t, gasLimit, stx.GetGasLimit()) + assert.Equal(t, gasPrice, stx.GetGasPrice()) + assert.Equal(t, nonce, stx.GetNonce()) +} + +func TestSovereignTx_CheckIntegrityShouldWork(t *testing.T) { + t.Parallel() + + stx := &sovereignTx.SovereignTx{ + Nonce: 1, + Value: big.NewInt(10), + GasPrice: 1, + GasLimit: 10, + Data: []byte("data"), + RcvAddr: []byte("rcv-address"), + SndAddr: []byte("snd-address"), + } + + err := stx.CheckIntegrity() + assert.Nil(t, err) +} + +func TestSovereignTx_CheckIntegrityShouldErr(t *testing.T) { + t.Parallel() + + stx := &sovereignTx.SovereignTx{ + Nonce: 1, + Data: []byte("data"), + } + + err := stx.CheckIntegrity() + assert.Equal(t, data.ErrNilRcvAddr, err) + + stx.RcvAddr = []byte("rcv-address") + + err = stx.CheckIntegrity() + assert.Equal(t, data.ErrNilSndAddr, err) + + stx.SndAddr = []byte("snd-address") + + err = stx.CheckIntegrity() + assert.Equal(t, data.ErrNilValue, err) + + stx.Value = big.NewInt(-1) + + err = stx.CheckIntegrity() + assert.Equal(t, data.ErrNegativeValue, err) +} From 506e228d289700a96146f5b08cd133e5124fb15b Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 23 Mar 2023 11:27:37 +0200 Subject: [PATCH 28/87] * Fixed after review --- data/sovereignTx/sovereignTx_test.go | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/data/sovereignTx/sovereignTx_test.go b/data/sovereignTx/sovereignTx_test.go index fea8cf087..eaf601d5a 100644 --- a/data/sovereignTx/sovereignTx_test.go +++ b/data/sovereignTx/sovereignTx_test.go @@ -40,10 +40,8 @@ func TestSovereignTx_SettersAndGetters(t *testing.T) { assert.Equal(t, nonce, stx.GetNonce()) } -func TestSovereignTx_CheckIntegrityShouldWork(t *testing.T) { - t.Parallel() - - stx := &sovereignTx.SovereignTx{ +func createValidSovereignTx() *sovereignTx.SovereignTx { + return &sovereignTx.SovereignTx{ Nonce: 1, Value: big.NewInt(10), GasPrice: 1, @@ -52,34 +50,41 @@ func TestSovereignTx_CheckIntegrityShouldWork(t *testing.T) { RcvAddr: []byte("rcv-address"), SndAddr: []byte("snd-address"), } +} +func TestSovereignTx_CheckIntegrityShouldWork(t *testing.T) { + t.Parallel() + + stx := createValidSovereignTx() err := stx.CheckIntegrity() + assert.Nil(t, err) } func TestSovereignTx_CheckIntegrityShouldErr(t *testing.T) { t.Parallel() - stx := &sovereignTx.SovereignTx{ - Nonce: 1, - Data: []byte("data"), - } - + stx := createValidSovereignTx() + stx.RcvAddr = nil err := stx.CheckIntegrity() - assert.Equal(t, data.ErrNilRcvAddr, err) - stx.RcvAddr = []byte("rcv-address") + assert.Equal(t, data.ErrNilRcvAddr, err) + stx = createValidSovereignTx() + stx.SndAddr = nil err = stx.CheckIntegrity() - assert.Equal(t, data.ErrNilSndAddr, err) - stx.SndAddr = []byte("snd-address") + assert.Equal(t, data.ErrNilSndAddr, err) + stx = createValidSovereignTx() + stx.Value = nil err = stx.CheckIntegrity() + assert.Equal(t, data.ErrNilValue, err) + stx = createValidSovereignTx() stx.Value = big.NewInt(-1) - err = stx.CheckIntegrity() + assert.Equal(t, data.ErrNegativeValue, err) } From 6f35754387dd5da9d78dcab4d4a7f71568b4d905 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Fri, 24 Mar 2023 16:16:34 +0200 Subject: [PATCH 29/87] * Added sovereign chain shard ID --- core/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/constants.go b/core/constants.go index 3c382139f..bc70b5767 100644 --- a/core/constants.go +++ b/core/constants.go @@ -34,6 +34,9 @@ const FileModeReadWrite = 0664 // MetachainShardId will be used to identify a shard ID as metachain const MetachainShardId = uint32(0xFFFFFFFF) +// SovereignChainShardId will be used to identify a shard ID as sovereign chain +const SovereignChainShardId = uint32(0xFFFFFFFE) + // AllShardId will be used to identify that a message is for all shards const AllShardId = uint32(0xFFFFFFF0) From 0b33c77b6a13a1484f3a7ea38721bc19877951a2 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 13 Apr 2023 16:55:59 +0300 Subject: [PATCH 30/87] * Moved sovereign chain constants in separated file --- core/constants.go | 3 --- core/sovereignChainConstants.go | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 core/sovereignChainConstants.go diff --git a/core/constants.go b/core/constants.go index 87a091d5c..0305419bb 100644 --- a/core/constants.go +++ b/core/constants.go @@ -34,9 +34,6 @@ const FileModeReadWrite = 0664 // MetachainShardId will be used to identify a shard ID as metachain const MetachainShardId = uint32(0xFFFFFFFF) -// SovereignChainShardId will be used to identify a shard ID as sovereign chain -const SovereignChainShardId = uint32(0xFFFFFFFE) - // AllShardId will be used to identify that a message is for all shards const AllShardId = uint32(0xFFFFFFF0) diff --git a/core/sovereignChainConstants.go b/core/sovereignChainConstants.go new file mode 100644 index 000000000..828c48b2a --- /dev/null +++ b/core/sovereignChainConstants.go @@ -0,0 +1,7 @@ +package core + +// SovereignChainShardId will be used to identify a shard ID as sovereign chain +const SovereignChainShardId = uint32(0xFFFFFFFE) + +// MainChainShardId will be used to identify a shard ID as main chain +const MainChainShardId = uint32(0xFFFFFFFD) From 268d25e4106e2bbe38db0c33d6462e1f4792652f Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Thu, 13 Apr 2023 18:48:00 +0300 Subject: [PATCH 31/87] * Fixed after review --- core/constants.go | 6 ------ core/{sovereignChainConstants.go => shardIDConstants.go} | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) rename core/{sovereignChainConstants.go => shardIDConstants.go} (53%) diff --git a/core/constants.go b/core/constants.go index 0305419bb..9953d4086 100644 --- a/core/constants.go +++ b/core/constants.go @@ -31,12 +31,6 @@ const FileModeUserReadWrite = 0600 // for others const FileModeReadWrite = 0664 -// MetachainShardId will be used to identify a shard ID as metachain -const MetachainShardId = uint32(0xFFFFFFFF) - -// AllShardId will be used to identify that a message is for all shards -const AllShardId = uint32(0xFFFFFFF0) - // MegabyteSize represents the size in bytes of a megabyte const MegabyteSize = 1024 * 1024 diff --git a/core/sovereignChainConstants.go b/core/shardIDConstants.go similarity index 53% rename from core/sovereignChainConstants.go rename to core/shardIDConstants.go index 828c48b2a..f42857abb 100644 --- a/core/sovereignChainConstants.go +++ b/core/shardIDConstants.go @@ -1,5 +1,11 @@ package core +// MetachainShardId will be used to identify a shard ID as metachain +const MetachainShardId = uint32(0xFFFFFFFF) + +// AllShardId will be used to identify that a message is for all shards +const AllShardId = uint32(0xFFFFFFF0) + // SovereignChainShardId will be used to identify a shard ID as sovereign chain const SovereignChainShardId = uint32(0xFFFFFFFE) From 299f3345e82287c5d000a7e14397fb738ff88406 Mon Sep 17 00:00:00 2001 From: SebastianMarian Date: Tue, 25 Apr 2023 12:26:51 +0300 Subject: [PATCH 32/87] * Refactor and improve sovereign chain header DTO and interface --- data/block/sovereignChainHeader.go | 6 +-- data/block/sovereignChainHeader.pb.go | 60 +++++++++++++-------------- data/block/sovereignChainHeader.proto | 2 +- data/interface.go | 5 ++- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 42e845ec9..f3471a532 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -386,13 +386,13 @@ func (sch *SovereignChainHeader) SetValidatorStatsRootHash(rootHash []byte) erro return nil } -// SetMainChainShardHeaderHashes sets the main chain shard header hashes -func (sch *SovereignChainHeader) SetMainChainShardHeaderHashes(hdrHashes [][]byte) error { +// SetExtendedShardHeaderHashes sets the extended shard header hashes +func (sch *SovereignChainHeader) SetExtendedShardHeaderHashes(hdrHashes [][]byte) error { if sch == nil { return data.ErrNilPointerReceiver } - sch.MainChainShardHeaderHashes = hdrHashes + sch.ExtendedShardHeaderHashes = hdrHashes return nil } diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index 58f8ad30a..328da36b3 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -28,9 +28,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain type SovereignChainHeader struct { - Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` - ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"ValidatorStatsRootHash,omitempty"` - MainChainShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=MainChainShardHeaderHashes,proto3" json:"MainChainShardHeaderHashes,omitempty"` + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"ValidatorStatsRootHash,omitempty"` + ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"ExtendedShardHeaderHashes,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -75,9 +75,9 @@ func (m *SovereignChainHeader) GetValidatorStatsRootHash() []byte { return nil } -func (m *SovereignChainHeader) GetMainChainShardHeaderHashes() [][]byte { +func (m *SovereignChainHeader) GetExtendedShardHeaderHashes() [][]byte { if m != nil { - return m.MainChainShardHeaderHashes + return m.ExtendedShardHeaderHashes } return nil } @@ -89,24 +89,24 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 260 bytes of a gzipped FileDescriptorProto + // 263 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0xce, 0x2f, 0x4b, 0x2d, 0x4a, 0xcd, 0x4c, 0xcf, 0x73, 0xce, 0x48, 0xcc, 0xcc, 0xf3, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0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x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0xf8, 0xe2, 0x91, 0x1c, 0xc3, 0x87, 0x47, 0x72, 0x8c, - 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x14, 0x2b, 0xd8, - 0xfb, 0x49, 0x6c, 0x60, 0xef, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x5e, 0xff, 0xd4, - 0x60, 0x01, 0x00, 0x00, + 0x1c, 0xb2, 0x42, 0x36, 0x5c, 0x92, 0xae, 0x15, 0x25, 0xa9, 0x79, 0x29, 0xa9, 0x29, 0xc1, 0x19, + 0x89, 0x45, 0x29, 0x10, 0xe3, 0x40, 0x52, 0xa9, 0xc5, 0x12, 0xcc, 0x0a, 0xcc, 0x1a, 0x3c, 0x41, + 0xb8, 0x15, 0x38, 0xd9, 0x5f, 0x78, 0x28, 0xc7, 0x70, 0xe3, 0xa1, 0x1c, 0xc3, 0x87, 0x87, 0x72, + 0x8c, 0x0d, 0x8f, 0xe4, 0x18, 0x57, 0x3c, 0x92, 0x63, 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, + 0x39, 0xc6, 0x1b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x7c, 0xf1, 0x48, 0x8e, 0xe1, 0xc3, + 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, + 0x8a, 0x15, 0xec, 0xf9, 0x24, 0x36, 0xb0, 0x67, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x09, + 0x27, 0x59, 0x6a, 0x5e, 0x01, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -134,11 +134,11 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { if !bytes.Equal(this.ValidatorStatsRootHash, that1.ValidatorStatsRootHash) { return false } - if len(this.MainChainShardHeaderHashes) != len(that1.MainChainShardHeaderHashes) { + if len(this.ExtendedShardHeaderHashes) != len(that1.ExtendedShardHeaderHashes) { return false } - for i := range this.MainChainShardHeaderHashes { - if !bytes.Equal(this.MainChainShardHeaderHashes[i], that1.MainChainShardHeaderHashes[i]) { + for i := range this.ExtendedShardHeaderHashes { + if !bytes.Equal(this.ExtendedShardHeaderHashes[i], that1.ExtendedShardHeaderHashes[i]) { return false } } @@ -154,7 +154,7 @@ func (this *SovereignChainHeader) GoString() string { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") } s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") - s = append(s, "MainChainShardHeaderHashes: "+fmt.Sprintf("%#v", this.MainChainShardHeaderHashes)+",\n") + s = append(s, "ExtendedShardHeaderHashes: "+fmt.Sprintf("%#v", this.ExtendedShardHeaderHashes)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -186,11 +186,11 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MainChainShardHeaderHashes) > 0 { - for iNdEx := len(m.MainChainShardHeaderHashes) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.MainChainShardHeaderHashes[iNdEx]) - copy(dAtA[i:], m.MainChainShardHeaderHashes[iNdEx]) - i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.MainChainShardHeaderHashes[iNdEx]))) + if len(m.ExtendedShardHeaderHashes) > 0 { + for iNdEx := len(m.ExtendedShardHeaderHashes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ExtendedShardHeaderHashes[iNdEx]) + copy(dAtA[i:], m.ExtendedShardHeaderHashes[iNdEx]) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.ExtendedShardHeaderHashes[iNdEx]))) i-- dAtA[i] = 0x1a } @@ -242,8 +242,8 @@ func (m *SovereignChainHeader) Size() (n int) { if l > 0 { n += 1 + l + sovSovereignChainHeader(uint64(l)) } - if len(m.MainChainShardHeaderHashes) > 0 { - for _, b := range m.MainChainShardHeaderHashes { + if len(m.ExtendedShardHeaderHashes) > 0 { + for _, b := range m.ExtendedShardHeaderHashes { l = len(b) n += 1 + l + sovSovereignChainHeader(uint64(l)) } @@ -264,7 +264,7 @@ func (this *SovereignChainHeader) String() string { s := strings.Join([]string{`&SovereignChainHeader{`, `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, - `MainChainShardHeaderHashes:` + fmt.Sprintf("%v", this.MainChainShardHeaderHashes) + `,`, + `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, `}`, }, "") return s @@ -378,7 +378,7 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MainChainShardHeaderHashes", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ExtendedShardHeaderHashes", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -405,8 +405,8 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MainChainShardHeaderHashes = append(m.MainChainShardHeaderHashes, make([]byte, postIndex-iNdEx)) - copy(m.MainChainShardHeaderHashes[len(m.MainChainShardHeaderHashes)-1], dAtA[iNdEx:postIndex]) + m.ExtendedShardHeaderHashes = append(m.ExtendedShardHeaderHashes, make([]byte, postIndex-iNdEx)) + copy(m.ExtendedShardHeaderHashes[len(m.ExtendedShardHeaderHashes)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index 621e1788c..a35c90c99 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -13,5 +13,5 @@ import "block.proto"; message SovereignChainHeader { Header Header = 1; bytes ValidatorStatsRootHash = 2; - repeated bytes MainChainShardHeaderHashes = 3; + repeated bytes ExtendedShardHeaderHashes = 3; } diff --git a/data/interface.go b/data/interface.go index e428ebe28..3b3c6b109 100644 --- a/data/interface.go +++ b/data/interface.go @@ -88,10 +88,11 @@ type ValidatorStatisticsInfoHandler interface { // SovereignChainHeaderHandler defines getters and setters for the sovereign chain header type SovereignChainHeaderHandler interface { CommonHeaderHandler + GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 SetValidatorStatsRootHash(rootHash []byte) error GetValidatorStatsRootHash() []byte - SetMainChainShardHeaderHashes(hdrHashes [][]byte) error - GetMainChainShardHeaderHashes() [][]byte + SetExtendedShardHeaderHashes(hdrHashes [][]byte) error + GetExtendedShardHeaderHashes() [][]byte } // HeaderHandler defines getters and setters for header data holder From 0852cb712926d1ab7b2b3b9bad2946e2f0815951 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 3 May 2023 18:06:20 +0300 Subject: [PATCH 33/87] FEAT: Add incoming logs --- data/block/shardHeaderExtended.go | 18 +++- data/block/shardHeaderExtended.pb.go | 125 +++++++++++++++++++++++---- data/block/shardHeaderExtended.proto | 8 +- data/interface.go | 1 + 4 files changed, 129 insertions(+), 23 deletions(-) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index dc5b2b25c..e08ec49ef 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. shardHeaderExtended.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=$GOPATH/src/github.com/multiversx/mx-chain-core-go/data/block shardHeaderExtended.proto package block import ( @@ -889,3 +889,19 @@ func (she *ShardHeaderExtended) SetIncomingMiniBlockHandlers(miniBlockHandlers [ return nil } + +// GetIncomingLogHandlers gets the incoming logs as an array of log handlers +func (she *ShardHeaderExtended) GetIncomingLogHandlers() []data.LogHandler { + if she == nil { + return nil + } + + logs := she.GetIncomingLogs() + logHandlers := make([]data.LogHandler, len(logs)) + + for i := range logs { + logHandlers[i] = logs[i] + } + + return logHandlers +} diff --git a/data/block/shardHeaderExtended.pb.go b/data/block/shardHeaderExtended.pb.go index 9b0f93837..3c45a46ac 100644 --- a/data/block/shardHeaderExtended.pb.go +++ b/data/block/shardHeaderExtended.pb.go @@ -7,6 +7,7 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + transaction "github.com/multiversx/mx-chain-core-go/data/transaction" io "io" math "math" math_bits "math/bits" @@ -27,8 +28,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain type ShardHeaderExtended struct { - Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` - IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"IncomingMiniBlocks,omitempty"` + Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"incomingMiniBlocks,omitempty"` + IncomingLogs []*transaction.Log `protobuf:"bytes,3,rep,name=IncomingLogs,proto3" json:"incomingLogs,omitempty"` } func (m *ShardHeaderExtended) Reset() { *m = ShardHeaderExtended{} } @@ -73,6 +75,13 @@ func (m *ShardHeaderExtended) GetIncomingMiniBlocks() []*MiniBlock { return nil } +func (m *ShardHeaderExtended) GetIncomingLogs() []*transaction.Log { + if m != nil { + return m.IncomingLogs + } + return nil +} + func init() { proto.RegisterType((*ShardHeaderExtended)(nil), "proto.ShardHeaderExtended") } @@ -80,22 +89,29 @@ func init() { func init() { proto.RegisterFile("shardHeaderExtended.proto", fileDescriptor_549610f8c128bd02) } var fileDescriptor_549610f8c128bd02 = []byte{ - // 238 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0xce, 0x48, 0x2c, - 0x4a, 0xf1, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x72, 0xad, 0x28, 0x49, 0xcd, 0x4b, 0x49, 0x4d, 0xd1, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, - 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, 0x60, 0xe1, 0xa4, 0xd2, 0x34, - 0x30, 0x0f, 0xcc, 0x01, 0xb3, 0x20, 0xba, 0xa4, 0xb8, 0x93, 0x72, 0xf2, 0x93, 0xb3, 0xa1, 0x1c, - 0x5e, 0x30, 0x27, 0xcc, 0x08, 0xc2, 0x55, 0x6a, 0x60, 0xe4, 0x12, 0x0e, 0xc6, 0xb4, 0x4f, 0x48, - 0x9d, 0x8b, 0x0d, 0x22, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0xc4, 0x0f, 0x51, 0xaf, 0x07, - 0x11, 0x0c, 0x33, 0x0a, 0x82, 0x4a, 0x0b, 0x39, 0x70, 0x09, 0x79, 0xe6, 0x25, 0xe7, 0xe7, 0x66, - 0xe6, 0xa5, 0xfb, 0x66, 0xe6, 0x65, 0x3a, 0x81, 0x4c, 0x2f, 0x96, 0x60, 0x52, 0x60, 0xd6, 0xe0, - 0x36, 0x12, 0x80, 0x6a, 0x82, 0x4b, 0x04, 0x61, 0x51, 0xeb, 0x64, 0x7f, 0xe1, 0xa1, 0x1c, 0xc3, - 0x8d, 0x87, 0x72, 0x0c, 0x1f, 0x1e, 0xca, 0x31, 0x36, 0x3c, 0x92, 0x63, 0x5c, 0xf1, 0x48, 0x8e, - 0xf1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x6f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, - 0x8e, 0xf1, 0xc5, 0x23, 0x39, 0x86, 0x0f, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, - 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x56, 0xb0, 0x5f, 0x92, 0xd8, 0xc0, 0xb6, 0x18, - 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xc7, 0xa2, 0xea, 0x4d, 0x39, 0x01, 0x00, 0x00, + // 349 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xb1, 0x4e, 0xe3, 0x30, + 0x18, 0xc7, 0xe3, 0xab, 0xda, 0x21, 0xbd, 0xd3, 0x9d, 0x72, 0x12, 0x2a, 0x15, 0xfa, 0x5a, 0x31, + 0x75, 0x20, 0x8d, 0x94, 0x3e, 0x00, 0x22, 0x12, 0x12, 0xa0, 0xb2, 0x14, 0xa9, 0x03, 0x9b, 0x93, + 0x18, 0xc7, 0xa2, 0xf1, 0x57, 0x25, 0x2e, 0x2a, 0x1b, 0x8f, 0xc0, 0x63, 0xf0, 0x28, 0x8c, 0x1d, + 0x3b, 0x55, 0xd4, 0x5d, 0x50, 0xa7, 0xce, 0x4c, 0x08, 0x27, 0xa0, 0xa2, 0x32, 0xd9, 0xff, 0xbf, + 0x7f, 0xfe, 0xd9, 0x96, 0xed, 0xfd, 0x3c, 0xa1, 0x59, 0x7c, 0xc6, 0x68, 0xcc, 0xb2, 0xd3, 0xa9, + 0x62, 0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0x6c, 0x31, 0x5b, 0xc6, 0x6f, 0x7b, 0x83, 0xe3, 0xd9, + 0x12, 0xac, 0xf9, 0x12, 0xac, 0xcd, 0x12, 0xc8, 0x83, 0x06, 0xf2, 0xa4, 0x81, 0x3c, 0x6b, 0x20, + 0x33, 0x0d, 0x64, 0xae, 0x81, 0xbc, 0x68, 0x20, 0xaf, 0x1a, 0xac, 0x8d, 0x06, 0xf2, 0xb8, 0x02, + 0x6b, 0xb6, 0x02, 0x6b, 0xbe, 0x02, 0xeb, 0xba, 0x6a, 0xfe, 0x2d, 0xac, 0x99, 0x53, 0x7b, 0xef, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x6d, 0x4c, 0xb3, 0x19, 0xf6, 0x01, 0x00, 0x00, } func (this *ShardHeaderExtended) Equal(that interface{}) bool { @@ -128,13 +144,21 @@ func (this *ShardHeaderExtended) Equal(that interface{}) bool { return false } } + if len(this.IncomingLogs) != len(that1.IncomingLogs) { + return false + } + for i := range this.IncomingLogs { + if !this.IncomingLogs[i].Equal(that1.IncomingLogs[i]) { + return false + } + } return true } func (this *ShardHeaderExtended) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&block.ShardHeaderExtended{") if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") @@ -142,6 +166,9 @@ func (this *ShardHeaderExtended) GoString() string { if this.IncomingMiniBlocks != nil { s = append(s, "IncomingMiniBlocks: "+fmt.Sprintf("%#v", this.IncomingMiniBlocks)+",\n") } + if this.IncomingLogs != nil { + s = append(s, "IncomingLogs: "+fmt.Sprintf("%#v", this.IncomingLogs)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -173,6 +200,20 @@ func (m *ShardHeaderExtended) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.IncomingLogs) > 0 { + for iNdEx := len(m.IncomingLogs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IncomingLogs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintShardHeaderExtended(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } if len(m.IncomingMiniBlocks) > 0 { for iNdEx := len(m.IncomingMiniBlocks) - 1; iNdEx >= 0; iNdEx-- { { @@ -229,6 +270,12 @@ func (m *ShardHeaderExtended) Size() (n int) { n += 1 + l + sovShardHeaderExtended(uint64(l)) } } + if len(m.IncomingLogs) > 0 { + for _, e := range m.IncomingLogs { + l = e.Size() + n += 1 + l + sovShardHeaderExtended(uint64(l)) + } + } return n } @@ -247,9 +294,15 @@ func (this *ShardHeaderExtended) String() string { repeatedStringForIncomingMiniBlocks += strings.Replace(fmt.Sprintf("%v", f), "MiniBlock", "MiniBlock", 1) + "," } repeatedStringForIncomingMiniBlocks += "}" + repeatedStringForIncomingLogs := "[]*Log{" + for _, f := range this.IncomingLogs { + repeatedStringForIncomingLogs += strings.Replace(fmt.Sprintf("%v", f), "Log", "transaction.Log", 1) + "," + } + repeatedStringForIncomingLogs += "}" s := strings.Join([]string{`&ShardHeaderExtended{`, `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, `IncomingMiniBlocks:` + repeatedStringForIncomingMiniBlocks + `,`, + `IncomingLogs:` + repeatedStringForIncomingLogs + `,`, `}`, }, "") return s @@ -361,6 +414,40 @@ func (m *ShardHeaderExtended) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IncomingLogs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthShardHeaderExtended + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthShardHeaderExtended + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IncomingLogs = append(m.IncomingLogs, &transaction.Log{}) + if err := m.IncomingLogs[len(m.IncomingLogs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipShardHeaderExtended(dAtA[iNdEx:]) diff --git a/data/block/shardHeaderExtended.proto b/data/block/shardHeaderExtended.proto index 04ee31542..c15f62ca0 100644 --- a/data/block/shardHeaderExtended.proto +++ b/data/block/shardHeaderExtended.proto @@ -6,12 +6,14 @@ package proto; option go_package = "block"; option (gogoproto.stable_marshaler_all) = true; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "block.proto"; import "blockV2.proto"; +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/multiversx/mx-chain-core-go/data/transaction/log.proto"; // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain message ShardHeaderExtended { - HeaderV2 Header = 1; - repeated MiniBlock IncomingMiniBlocks = 2; + HeaderV2 Header = 1 [(gogoproto.jsontag) = "header"]; + repeated MiniBlock IncomingMiniBlocks = 2 [(gogoproto.jsontag) = "incomingMiniBlocks,omitempty"]; + repeated Log IncomingLogs = 3 [(gogoproto.jsontag) = "incomingLogs,omitempty"]; } diff --git a/data/interface.go b/data/interface.go index e428ebe28..5dc370678 100644 --- a/data/interface.go +++ b/data/interface.go @@ -417,5 +417,6 @@ type UserAccountHandler interface { type ShardHeaderExtendedHandler interface { ShardHeaderHandler GetIncomingMiniBlockHandlers() []MiniBlockHandler + GetIncomingLogHandlers() []LogHandler SetIncomingMiniBlockHandlers(miniBlockHandlers []MiniBlockHandler) error } From a57388319903d38aa13434bfeacb2a8a8557fe72 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 4 May 2023 12:47:45 +0300 Subject: [PATCH 34/87] FIX: Create IncomingHeader separate package --- data/block/shardHeaderExtended.go | 18 +- data/block/shardHeaderExtended.pb.go | 127 ++----- data/block/shardHeaderExtended.proto | 2 - data/interface.go | 1 - data/sovereign/incomingHeader.go | 30 ++ data/sovereign/incomingHeader.pb.go | 478 +++++++++++++++++++++++++++ data/sovereign/incomingHeader.proto | 17 + data/sovereign/interface.go | 8 + 8 files changed, 555 insertions(+), 126 deletions(-) create mode 100644 data/sovereign/incomingHeader.go create mode 100644 data/sovereign/incomingHeader.pb.go create mode 100644 data/sovereign/incomingHeader.proto create mode 100644 data/sovereign/interface.go diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index e08ec49ef..05bc4a8c9 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=$GOPATH/src/github.com/multiversx/mx-chain-core-go/data/block shardHeaderExtended.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. shardHeaderExtended.proto package block import ( @@ -889,19 +889,3 @@ func (she *ShardHeaderExtended) SetIncomingMiniBlockHandlers(miniBlockHandlers [ return nil } - -// GetIncomingLogHandlers gets the incoming logs as an array of log handlers -func (she *ShardHeaderExtended) GetIncomingLogHandlers() []data.LogHandler { - if she == nil { - return nil - } - - logs := she.GetIncomingLogs() - logHandlers := make([]data.LogHandler, len(logs)) - - for i := range logs { - logHandlers[i] = logs[i] - } - - return logHandlers -} diff --git a/data/block/shardHeaderExtended.pb.go b/data/block/shardHeaderExtended.pb.go index 3c45a46ac..317d02d96 100644 --- a/data/block/shardHeaderExtended.pb.go +++ b/data/block/shardHeaderExtended.pb.go @@ -7,7 +7,6 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - transaction "github.com/multiversx/mx-chain-core-go/data/transaction" io "io" math "math" math_bits "math/bits" @@ -28,9 +27,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain type ShardHeaderExtended struct { - Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` - IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"incomingMiniBlocks,omitempty"` - IncomingLogs []*transaction.Log `protobuf:"bytes,3,rep,name=IncomingLogs,proto3" json:"incomingLogs,omitempty"` + Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"incomingMiniBlocks,omitempty"` } func (m *ShardHeaderExtended) Reset() { *m = ShardHeaderExtended{} } @@ -75,13 +73,6 @@ func (m *ShardHeaderExtended) GetIncomingMiniBlocks() []*MiniBlock { return nil } -func (m *ShardHeaderExtended) GetIncomingLogs() []*transaction.Log { - if m != nil { - return m.IncomingLogs - } - return nil -} - func init() { proto.RegisterType((*ShardHeaderExtended)(nil), "proto.ShardHeaderExtended") } @@ -89,29 +80,24 @@ func init() { func init() { proto.RegisterFile("shardHeaderExtended.proto", fileDescriptor_549610f8c128bd02) } var fileDescriptor_549610f8c128bd02 = []byte{ - // 349 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xb1, 0x4e, 0xe3, 0x30, - 0x18, 0xc7, 0xe3, 0xab, 0xda, 0x21, 0xbd, 0xd3, 0x9d, 0x72, 0x12, 0x2a, 0x15, 0xfa, 0x5a, 0x31, - 0x75, 0x20, 0x8d, 0x94, 0x3e, 0x00, 0x22, 0x12, 0x12, 0xa0, 0xb2, 0x14, 0xa9, 0x03, 0x9b, 0x93, - 0x18, 0xc7, 0xa2, 0xf1, 0x57, 0x25, 0x2e, 0x2a, 0x1b,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x6b, 0x21, - 0x68, 0xaf, 0x17, 0xad, 0x03, 0xb1, 0xc3, 0x1f, 0x61, 0x2a, 0x14, 0x4b, 0xc7, 0xea, 0x7e, 0xf0, - 0x83, 0xcd, 0xb9, 0xb0, 0x7f, 0x7f, 0xb6, 0x7d, 0xe4, 0x79, 0xa3, 0x62, 0xec, 0x76, 0x69, 0xef, - 0x23, 0x0f, 0x9a, 0xeb, 0x45, 0x6b, 0x4f, 0x6c, 0x31, 0x5b, 0xc6, 0x6f, 0x7b, 0x83, 0xe3, 0xd9, - 0x12, 0xac, 0xf9, 0x12, 0xac, 0xcd, 0x12, 0xc8, 0x83, 0x06, 0xf2, 0xa4, 0x81, 0x3c, 0x6b, 0x20, - 0x33, 0x0d, 0x64, 0xae, 0x81, 0xbc, 0x68, 0x20, 0xaf, 0x1a, 0xac, 0x8d, 0x06, 0xf2, 0xb8, 0x02, - 0x6b, 0xb6, 0x02, 0x6b, 0xbe, 0x02, 0xeb, 0xba, 0x6a, 0xfe, 0x2d, 0xac, 0x99, 0x53, 0x7b, 0xef, - 0x01, 0x00, 0x00, 0xff, 0xff, 0x6d, 0x4c, 0xb3, 0x19, 0xf6, 0x01, 0x00, 0x00, + // 267 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0xce, 0x48, 0x2c, + 0x4a, 0xf1, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x72, 0xad, 0x28, 0x49, 0xcd, 0x4b, 0x49, 0x4d, 0xd1, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xdc, 0x49, 0x39, 0xf9, 0xc9, 0xd9, + 0x10, 0x31, 0x29, 0x5e, 0x30, 0x27, 0xcc, 0x08, 0xca, 0xd5, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, + 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0x0b, 0x27, 0x95, 0xa6, 0x81, + 0x79, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xae, 0xb4, 0x8e, 0x91, 0x4b, 0x38, 0x18, 0xd3, 0x3e, 0x21, + 0x63, 0x2e, 0x36, 0x88, 0x88, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x11, 0x3f, 0x44, 0xbd, 0x1e, + 0x44, 0x30, 0xcc, 0xc8, 0x89, 0xeb, 0xd5, 0x3d, 0x79, 0xb6, 0x0c, 0x30, 0x2f, 0x08, 0xaa, 0x54, + 0x28, 0x89, 0x4b, 0xc8, 0x33, 0x2f, 0x39, 0x3f, 0x37, 0x33, 0x2f, 0xdd, 0x37, 0x33, 0x2f, 0xd3, + 0x09, 0xe4, 0xb0, 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x01, 0xa8, 0x01, 0x70, 0x09, + 0x27, 0x85, 0x57, 0xf7, 0xe4, 0x65, 0x32, 0x31, 0xd4, 0xeb, 0xe4, 0xe7, 0x66, 0x96, 0xa4, 0xe6, + 0x16, 0x94, 0x54, 0x06, 0x61, 0x31, 0xcd, 0xc9, 0xfe, 0xc2, 0x43, 0x39, 0x86, 0x1b, 0x0f, 0xe5, + 0x18, 0x3e, 0x3c, 0x94, 0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, + 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x8b, + 0x47, 0x72, 0x0c, 0x1f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, + 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, 0x80, 0x4a, 0x62, 0x03, 0xbb, 0xc3, 0x18, 0x10, 0x00, + 0x00, 0xff, 0xff, 0xbc, 0xb3, 0xf2, 0x5c, 0x67, 0x01, 0x00, 0x00, } func (this *ShardHeaderExtended) Equal(that interface{}) bool { @@ -144,21 +130,13 @@ func (this *ShardHeaderExtended) Equal(that interface{}) bool { return false } } - if len(this.IncomingLogs) != len(that1.IncomingLogs) { - return false - } - for i := range this.IncomingLogs { - if !this.IncomingLogs[i].Equal(that1.IncomingLogs[i]) { - return false - } - } return true } func (this *ShardHeaderExtended) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 7) + s := make([]string, 0, 6) s = append(s, "&block.ShardHeaderExtended{") if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") @@ -166,9 +144,6 @@ func (this *ShardHeaderExtended) GoString() string { if this.IncomingMiniBlocks != nil { s = append(s, "IncomingMiniBlocks: "+fmt.Sprintf("%#v", this.IncomingMiniBlocks)+",\n") } - if this.IncomingLogs != nil { - s = append(s, "IncomingLogs: "+fmt.Sprintf("%#v", this.IncomingLogs)+",\n") - } s = append(s, "}") return strings.Join(s, "") } @@ -200,20 +175,6 @@ func (m *ShardHeaderExtended) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.IncomingLogs) > 0 { - for iNdEx := len(m.IncomingLogs) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.IncomingLogs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintShardHeaderExtended(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } if len(m.IncomingMiniBlocks) > 0 { for iNdEx := len(m.IncomingMiniBlocks) - 1; iNdEx >= 0; iNdEx-- { { @@ -270,12 +231,6 @@ func (m *ShardHeaderExtended) Size() (n int) { n += 1 + l + sovShardHeaderExtended(uint64(l)) } } - if len(m.IncomingLogs) > 0 { - for _, e := range m.IncomingLogs { - l = e.Size() - n += 1 + l + sovShardHeaderExtended(uint64(l)) - } - } return n } @@ -294,15 +249,9 @@ func (this *ShardHeaderExtended) String() string { repeatedStringForIncomingMiniBlocks += strings.Replace(fmt.Sprintf("%v", f), "MiniBlock", "MiniBlock", 1) + "," } repeatedStringForIncomingMiniBlocks += "}" - repeatedStringForIncomingLogs := "[]*Log{" - for _, f := range this.IncomingLogs { - repeatedStringForIncomingLogs += strings.Replace(fmt.Sprintf("%v", f), "Log", "transaction.Log", 1) + "," - } - repeatedStringForIncomingLogs += "}" s := strings.Join([]string{`&ShardHeaderExtended{`, `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, `IncomingMiniBlocks:` + repeatedStringForIncomingMiniBlocks + `,`, - `IncomingLogs:` + repeatedStringForIncomingLogs + `,`, `}`, }, "") return s @@ -414,40 +363,6 @@ func (m *ShardHeaderExtended) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field IncomingLogs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowShardHeaderExtended - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthShardHeaderExtended - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthShardHeaderExtended - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.IncomingLogs = append(m.IncomingLogs, &transaction.Log{}) - if err := m.IncomingLogs[len(m.IncomingLogs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipShardHeaderExtended(dAtA[iNdEx:]) diff --git a/data/block/shardHeaderExtended.proto b/data/block/shardHeaderExtended.proto index c15f62ca0..bfffa2d2f 100644 --- a/data/block/shardHeaderExtended.proto +++ b/data/block/shardHeaderExtended.proto @@ -9,11 +9,9 @@ option (gogoproto.stable_marshaler_all) = true; import "block.proto"; import "blockV2.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; -import "github.com/multiversx/mx-chain-core-go/data/transaction/log.proto"; // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain message ShardHeaderExtended { HeaderV2 Header = 1 [(gogoproto.jsontag) = "header"]; repeated MiniBlock IncomingMiniBlocks = 2 [(gogoproto.jsontag) = "incomingMiniBlocks,omitempty"]; - repeated Log IncomingLogs = 3 [(gogoproto.jsontag) = "incomingLogs,omitempty"]; } diff --git a/data/interface.go b/data/interface.go index 5dc370678..e428ebe28 100644 --- a/data/interface.go +++ b/data/interface.go @@ -417,6 +417,5 @@ type UserAccountHandler interface { type ShardHeaderExtendedHandler interface { ShardHeaderHandler GetIncomingMiniBlockHandlers() []MiniBlockHandler - GetIncomingLogHandlers() []LogHandler SetIncomingMiniBlockHandlers(miniBlockHandlers []MiniBlockHandler) error } diff --git a/data/sovereign/incomingHeader.go b/data/sovereign/incomingHeader.go new file mode 100644 index 000000000..9c2e3501c --- /dev/null +++ b/data/sovereign/incomingHeader.go @@ -0,0 +1,30 @@ +//go:generate protoc -I=. -I=$GOPATH/src/github.com/multiversx/mx-chain-core-go/data/block -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. incomingHeader.proto + +package sovereign + +import "github.com/multiversx/mx-chain-core-go/data" + +// GetIncomingLogHandlers returns the incoming logs as an array of log handlers +func (ih *IncomingHeader) GetIncomingLogHandlers() []data.LogHandler { + if ih == nil { + return nil + } + + logs := ih.GetIncomingLogs() + logHandlers := make([]data.LogHandler, len(logs)) + + for i := range logs { + logHandlers[i] = logs[i] + } + + return logHandlers +} + +// GetHeaderHandler returns the incoming headerV2 as a header handler +func (ih *IncomingHeader) GetHeaderHandler() data.HeaderHandler { + if ih == nil { + return nil + } + + return ih.GetHeader() +} diff --git a/data/sovereign/incomingHeader.pb.go b/data/sovereign/incomingHeader.pb.go new file mode 100644 index 000000000..9b502df9b --- /dev/null +++ b/data/sovereign/incomingHeader.pb.go @@ -0,0 +1,478 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: incomingHeader.proto + +package sovereign + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + block "github.com/multiversx/mx-chain-core-go/data/block" + transaction "github.com/multiversx/mx-chain-core-go/data/transaction" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain +type IncomingHeader struct { + Header *block.HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + IncomingLogs []*transaction.Log `protobuf:"bytes,2,rep,name=IncomingLogs,proto3" json:"incomingLogs,omitempty"` +} + +func (m *IncomingHeader) Reset() { *m = IncomingHeader{} } +func (*IncomingHeader) ProtoMessage() {} +func (*IncomingHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_dd583eddd7d6ee94, []int{0} +} +func (m *IncomingHeader) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IncomingHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *IncomingHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_IncomingHeader.Merge(m, src) +} +func (m *IncomingHeader) XXX_Size() int { + return m.Size() +} +func (m *IncomingHeader) XXX_DiscardUnknown() { + xxx_messageInfo_IncomingHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_IncomingHeader proto.InternalMessageInfo + +func (m *IncomingHeader) GetHeader() *block.HeaderV2 { + if m != nil { + return m.Header + } + return nil +} + +func (m *IncomingHeader) GetIncomingLogs() []*transaction.Log { + if m != nil { + return m.IncomingLogs + } + return nil +} + +func init() { + proto.RegisterType((*IncomingHeader)(nil), "proto.IncomingHeader") +} + +func init() { proto.RegisterFile("incomingHeader.proto", fileDescriptor_dd583eddd7d6ee94) } + +var fileDescriptor_dd583eddd7d6ee94 = []byte{ + // 309 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x8f, 0xb1, 0x4e, 0x72, 0x31, + 0x14, 0xc7, 0x6f, 0xbf, 0x2f, 0x92, 0x78, 0x31, 0x9a, 0x10, 0x63, 0x08, 0xc3, 0x81, 0x38, 0x31, + 0x78, 0xb9, 0xc9, 0xe5, 0x01, 0x8c, 0xb8, 0xa8, 0x61, 0x62, 0x60, 0x70, 0xeb, 0x2d, 0xb5, 0x34, + 0xd2, 0x1e, 0xd2, 0x5b, 0x08, 0x6e, 0x3e, 0x82, 0xbe, 0x85, 0x8f, 0xe2, 0xc8, 0xc8, 0x44, 0xa4, + 0x2c, 0x86, 0x89, 0x47, 0x30, 0x69, 0x31, 0x81, 0xd1, 0xa5, 0x3d, 0xff, 0x93, 0xdf, 0xff, 0xd7, + 0x34, 0x3e, 0x97, 0x9a, 0xa1, 0x92, 0x5a, 0xdc, 0x71, 0x3a, 0xe0, 0xa6, 0x35, 0x36, 0x68, 0xb1, + 0x72, 0xe4, 0xaf, 0x5a, 0x22, 0xa4, 0x1d, 0x4e, 0xf2, 0x16, 0x43, 0x95, 0x0a, 0x14, 0x98, 0xfa, + 0x75, 0x3e, 0x79, 0xf2, 0xc9, 0x07, 0x3f, 0x85, 0x56, 0xed, 0x7a, 0x0f, 0x57, 0x93, 0x91, 0x95, + 0x53, 0x6e, 0x8a, 0x59, 0xaa, 0x66, 0x09, 0x1b, 0x52, 0xa9, 0x13, 0x86, 0x86, 0x27, 0x02, 0xd3, + 0x01, 0xb5, 0x34, 0xcd, 0x47, 0xc8, 0x9e, 0xc3, 0xd9, 0xcf, 0x76, 0x82, 0x9b, 0xbf, 0x08, 0xac, + 0xa1, 0xba, 0xa0, 0xcc, 0x4a, 0xd4, 0xe9, 0x08, 0x45, 0x50, 0x5c, 0xbe, 0x93, 0xf8, 0xf4, 0xfe, + 0xe0, 0x4b, 0x95, 0x76, 0x5c, 0x0a, 0x53, 0x95, 0x34, 0x48, 0xb3, 0x9c, 0x9d, 0x05, 0xb4, 0x15, + 0x96, 0xfd, 0xac, 0x13, 0x6f, 0x96, 0xf5, 0xd2, 0xd0, 0xa7, 0xde, 0x0e, 0xad, 0x3c, 0xc4, 0x27, + 0xbf, 0x9a, 0x2e, 0x8a, 0xa2, 0xfa, 0xaf, 0xf1, 0xbf, 0x59, 0xce, 0xe2, 0x5d, 0xb5, 0x8b, 0xa2, + 0x53, 0xdb, 0x2c, 0xeb, 0x17, 0x72, 0x8f, 0xb9, 0x42, 0x25, 0x2d, 0x57, 0x63, 0xfb, 0xd2, 0x3b, + 0xe8, 0x76, 0x6e, 0xe7, 0x2b, 0x88, 0x16, 0x2b, 0x88, 0xb6, 0x2b, 0x20, 0xaf, 0x0e, 0xc8, 0x87, + 0x03, 0xf2, 0xe9, 0x80, 0xcc, 0x1d, 0x90, 0x85, 0x03, 0xf2, 0xe5, 0x80, 0x7c, 0x3b, 0x88, 0xb6, + 0x0e, 0xc8, 0xdb, 0x1a, 0xa2, 0xf9, 0x1a, 0xa2, 0xc5, 0x1a, 0xa2, 0xc7, 0xe3, 0x02, 0xa7, 0xdc, + 0x70, 0x29, 0x74, 0x5e, 0xf2, 0x2f, 0xb7, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x76, 0xa7, + 0x79, 0xb1, 0x01, 0x00, 0x00, +} + +func (this *IncomingHeader) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*IncomingHeader) + if !ok { + that2, ok := that.(IncomingHeader) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Header.Equal(that1.Header) { + return false + } + if len(this.IncomingLogs) != len(that1.IncomingLogs) { + return false + } + for i := range this.IncomingLogs { + if !this.IncomingLogs[i].Equal(that1.IncomingLogs[i]) { + return false + } + } + return true +} +func (this *IncomingHeader) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&sovereign.IncomingHeader{") + if this.Header != nil { + s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") + } + if this.IncomingLogs != nil { + s = append(s, "IncomingLogs: "+fmt.Sprintf("%#v", this.IncomingLogs)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringIncomingHeader(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *IncomingHeader) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IncomingHeader) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IncomingHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.IncomingLogs) > 0 { + for iNdEx := len(m.IncomingLogs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IncomingLogs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintIncomingHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintIncomingHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintIncomingHeader(dAtA []byte, offset int, v uint64) int { + offset -= sovIncomingHeader(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *IncomingHeader) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovIncomingHeader(uint64(l)) + } + if len(m.IncomingLogs) > 0 { + for _, e := range m.IncomingLogs { + l = e.Size() + n += 1 + l + sovIncomingHeader(uint64(l)) + } + } + return n +} + +func sovIncomingHeader(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozIncomingHeader(x uint64) (n int) { + return sovIncomingHeader(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *IncomingHeader) String() string { + if this == nil { + return "nil" + } + repeatedStringForIncomingLogs := "[]*Log{" + for _, f := range this.IncomingLogs { + repeatedStringForIncomingLogs += strings.Replace(fmt.Sprintf("%v", f), "Log", "transaction.Log", 1) + "," + } + repeatedStringForIncomingLogs += "}" + s := strings.Join([]string{`&IncomingHeader{`, + `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "block.HeaderV2", 1) + `,`, + `IncomingLogs:` + repeatedStringForIncomingLogs + `,`, + `}`, + }, "") + return s +} +func valueToStringIncomingHeader(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *IncomingHeader) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIncomingHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IncomingHeader: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IncomingHeader: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIncomingHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthIncomingHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthIncomingHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Header == nil { + m.Header = &block.HeaderV2{} + } + if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IncomingLogs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIncomingHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthIncomingHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthIncomingHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IncomingLogs = append(m.IncomingLogs, &transaction.Log{}) + if err := m.IncomingLogs[len(m.IncomingLogs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipIncomingHeader(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthIncomingHeader + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthIncomingHeader + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipIncomingHeader(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIncomingHeader + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIncomingHeader + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIncomingHeader + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthIncomingHeader + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupIncomingHeader + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthIncomingHeader + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthIncomingHeader = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowIncomingHeader = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupIncomingHeader = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/sovereign/incomingHeader.proto b/data/sovereign/incomingHeader.proto new file mode 100644 index 000000000..b512bf531 --- /dev/null +++ b/data/sovereign/incomingHeader.proto @@ -0,0 +1,17 @@ +// This file holds the data structures related with the functionality of an extended shard header needed by sovereign chain +syntax = "proto3"; + +package proto; + +option go_package = "sovereign"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/multiversx/mx-chain-core-go/data/block/blockV2.proto"; +import "github.com/multiversx/mx-chain-core-go/data/transaction/log.proto"; + +// ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain +message IncomingHeader { + HeaderV2 Header = 1 [(gogoproto.jsontag) = "header"]; + repeated Log IncomingLogs = 2 [(gogoproto.jsontag) = "incomingLogs,omitempty"]; +} diff --git a/data/sovereign/interface.go b/data/sovereign/interface.go new file mode 100644 index 000000000..070fa77bf --- /dev/null +++ b/data/sovereign/interface.go @@ -0,0 +1,8 @@ +package sovereign + +import "github.com/multiversx/mx-chain-core-go/data" + +type IncomingHeaderHandler interface { + GetIncomingLogHandlers() []data.LogHandler + GetHeaderHandler() data.HeaderHandler +} From 8c7d8ad4ecde1db7d74ee39f05e54ef0de50c465 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 4 May 2023 12:54:36 +0300 Subject: [PATCH 35/87] FIX: Comments --- data/sovereign/incomingHeader.proto | 3 ++- data/sovereign/interface.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/data/sovereign/incomingHeader.proto b/data/sovereign/incomingHeader.proto index b512bf531..338dad80f 100644 --- a/data/sovereign/incomingHeader.proto +++ b/data/sovereign/incomingHeader.proto @@ -1,4 +1,5 @@ -// This file holds the data structures related with the functionality of an extended shard header needed by sovereign chain +// This file holds data structures related to incoming headers from one chain(local/main/test/etc.) to a sovereign chain. +// This incoming header will be received from a notifier. In the future, this will also hold a proof of the incoming operations syntax = "proto3"; package proto; diff --git a/data/sovereign/interface.go b/data/sovereign/interface.go index 070fa77bf..3332b6b1f 100644 --- a/data/sovereign/interface.go +++ b/data/sovereign/interface.go @@ -2,6 +2,7 @@ package sovereign import "github.com/multiversx/mx-chain-core-go/data" +// IncomingHeaderHandler defines the incoming header to a sovereign chain that is sent by a notifier type IncomingHeaderHandler interface { GetIncomingLogHandlers() []data.LogHandler GetHeaderHandler() data.HeaderHandler From 26a3dd106fb56e6cabce4427ed9cfde51219e61f Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 4 May 2023 15:09:48 +0300 Subject: [PATCH 36/87] FIX: Use incoming events instead of logs --- data/sovereign/incomingHeader.go | 12 ++--- data/sovereign/incomingHeader.pb.go | 83 ++++++++++++++--------------- data/sovereign/incomingHeader.proto | 5 +- data/sovereign/interface.go | 2 +- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/data/sovereign/incomingHeader.go b/data/sovereign/incomingHeader.go index 9c2e3501c..eb4251df7 100644 --- a/data/sovereign/incomingHeader.go +++ b/data/sovereign/incomingHeader.go @@ -4,17 +4,17 @@ package sovereign import "github.com/multiversx/mx-chain-core-go/data" -// GetIncomingLogHandlers returns the incoming logs as an array of log handlers -func (ih *IncomingHeader) GetIncomingLogHandlers() []data.LogHandler { +// GetIncomingEventHandlers returns the incoming events as an array of event handlers +func (ih *IncomingHeader) GetIncomingEventHandlers() []data.EventHandler { if ih == nil { return nil } - logs := ih.GetIncomingLogs() - logHandlers := make([]data.LogHandler, len(logs)) + events := ih.GetIncomingEvents() + logHandlers := make([]data.EventHandler, len(events)) - for i := range logs { - logHandlers[i] = logs[i] + for i := range events { + logHandlers[i] = events[i] } return logHandlers diff --git a/data/sovereign/incomingHeader.pb.go b/data/sovereign/incomingHeader.pb.go index 9b502df9b..91b86477b 100644 --- a/data/sovereign/incomingHeader.pb.go +++ b/data/sovereign/incomingHeader.pb.go @@ -27,10 +27,9 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain type IncomingHeader struct { - Header *block.HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` - IncomingLogs []*transaction.Log `protobuf:"bytes,2,rep,name=IncomingLogs,proto3" json:"incomingLogs,omitempty"` + Header *block.HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + IncomingEvents []*transaction.Event `protobuf:"bytes,2,rep,name=IncomingEvents,proto3" json:"incomingEvents,omitempty"` } func (m *IncomingHeader) Reset() { *m = IncomingHeader{} } @@ -68,9 +67,9 @@ func (m *IncomingHeader) GetHeader() *block.HeaderV2 { return nil } -func (m *IncomingHeader) GetIncomingLogs() []*transaction.Log { +func (m *IncomingHeader) GetIncomingEvents() []*transaction.Event { if m != nil { - return m.IncomingLogs + return m.IncomingEvents } return nil } @@ -84,25 +83,25 @@ func init() { proto.RegisterFile("incomingHeader.proto", fileDescriptor_dd583edd var fileDescriptor_dd583eddd7d6ee94 = []byte{ // 309 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x8f, 0xb1, 0x4e, 0x72, 0x31, - 0x14, 0xc7, 0x6f, 0xbf, 0x2f, 0x92, 0x78, 0x31, 0x9a, 0x10, 0x63, 0x08, 0xc3, 0x81, 0x38, 0x31, - 0x78, 0xb9, 0xc9, 0xe5, 0x01, 0x8c, 0xb8, 0xa8, 0x61, 0x62, 0x60, 0x70, 0xeb, 0x2d, 0xb5, 0x34, - 0xd2, 0x1e, 0xd2, 0x5b, 0x08, 0x6e, 0x3e, 0x82, 0xbe, 0x85, 0x8f, 0xe2, 0xc8, 0xc8, 0x44, 0xa4, - 0x2c, 0x86, 0x89, 0x47, 0x30, 0x69, 0x31, 0x81, 0xd1, 0xa5, 0x3d, 0xff, 0x93, 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d2, 0x34, 0x1f, 0x23, 0x7b, 0x0c, 0xe7, 0x20, 0x2b, 0x05, 0x57, 0x7f, 0x11, + 0x58, 0x43, 0x75, 0x41, 0x99, 0x95, 0xa8, 0xd3, 0x31, 0x8a, 0xa0, 0x38, 0x7f, 0x25, 0xf1, 0xf1, + 0xdd, 0xde, 0x97, 0x6a, 0xdd, 0xb8, 0x12, 0xa6, 0x3a, 0x69, 0x91, 0x76, 0x35, 0x3b, 0x09, 0x68, + 0x27, 0x94, 0x83, 0xac, 0x17, 0x6f, 0x57, 0xcd, 0xca, 0xc8, 0xa7, 0x7e, 0x89, 0xd6, 0xfa, 0xdf, + 0x9a, 0x9b, 0x19, 0xd7, 0xb6, 0xa8, 0xff, 0x6b, 0xfd, 0x6f, 0x57, 0xb3, 0xa3, 0x72, 0xd9, 0x97, + 0xbd, 0xb3, 0xed, 0xaa, 0x59, 0x97, 0x7b, 0xdc, 0x05, 0x2a, 0x69, 0xb9, 0x9a, 0xd8, 0xa7, 0xfe, + 0x2f, 0x43, 0xef, 0x7a, 0xb1, 0x86, 0x68, 0xb9, 0x86, 0x68, 0xb7, 0x06, 0xf2, 0xec, 0x80, 0xbc, + 0x39, 0x20, 0xef, 0x0e, 0xc8, 0xc2, 0x01, 0x59, 0x3a, 0x20, 0x1f, 0x0e, 0xc8, 0xa7, 0x83, 0x68, + 0xe7, 0x80, 0xbc, 0x6c, 0x20, 0x5a, 0x6c, 0x20, 0x5a, 0x6e, 0x20, 0xba, 0x3f, 0x2c, 0x70, 0xc6, + 0x0d, 0x97, 0x42, 0xe7, 0x15, 0xff, 0x7e, 0xf7, 0x2b, 0x00, 0x00, 0xff, 0xff, 0xec, 0x68, 0xc0, + 0x62, 0xb9, 0x01, 0x00, 0x00, } func (this *IncomingHeader) Equal(that interface{}) bool { @@ -127,11 +126,11 @@ func (this *IncomingHeader) Equal(that interface{}) bool { if !this.Header.Equal(that1.Header) { return false } - if len(this.IncomingLogs) != len(that1.IncomingLogs) { + if len(this.IncomingEvents) != len(that1.IncomingEvents) { return false } - for i := range this.IncomingLogs { - if !this.IncomingLogs[i].Equal(that1.IncomingLogs[i]) { + for i := range this.IncomingEvents { + if !this.IncomingEvents[i].Equal(that1.IncomingEvents[i]) { return false } } @@ -146,8 +145,8 @@ func (this *IncomingHeader) GoString() string { if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") } - if this.IncomingLogs != nil { - s = append(s, "IncomingLogs: "+fmt.Sprintf("%#v", this.IncomingLogs)+",\n") + if this.IncomingEvents != nil { + s = append(s, "IncomingEvents: "+fmt.Sprintf("%#v", this.IncomingEvents)+",\n") } s = append(s, "}") return strings.Join(s, "") @@ -180,10 +179,10 @@ func (m *IncomingHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.IncomingLogs) > 0 { - for iNdEx := len(m.IncomingLogs) - 1; iNdEx >= 0; iNdEx-- { + if len(m.IncomingEvents) > 0 { + for iNdEx := len(m.IncomingEvents) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.IncomingLogs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.IncomingEvents[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -230,8 +229,8 @@ func (m *IncomingHeader) Size() (n int) { l = m.Header.Size() n += 1 + l + sovIncomingHeader(uint64(l)) } - if len(m.IncomingLogs) > 0 { - for _, e := range m.IncomingLogs { + if len(m.IncomingEvents) > 0 { + for _, e := range m.IncomingEvents { l = e.Size() n += 1 + l + sovIncomingHeader(uint64(l)) } @@ -249,14 +248,14 @@ func (this *IncomingHeader) String() string { if this == nil { return "nil" } - repeatedStringForIncomingLogs := "[]*Log{" - for _, f := range this.IncomingLogs { - repeatedStringForIncomingLogs += strings.Replace(fmt.Sprintf("%v", f), "Log", "transaction.Log", 1) + "," + repeatedStringForIncomingEvents := "[]*Event{" + for _, f := range this.IncomingEvents { + repeatedStringForIncomingEvents += strings.Replace(fmt.Sprintf("%v", f), "Event", "transaction.Event", 1) + "," } - repeatedStringForIncomingLogs += "}" + repeatedStringForIncomingEvents += "}" s := strings.Join([]string{`&IncomingHeader{`, `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "block.HeaderV2", 1) + `,`, - `IncomingLogs:` + repeatedStringForIncomingLogs + `,`, + `IncomingEvents:` + repeatedStringForIncomingEvents + `,`, `}`, }, "") return s @@ -336,7 +335,7 @@ func (m *IncomingHeader) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field IncomingLogs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field IncomingEvents", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -363,8 +362,8 @@ func (m *IncomingHeader) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.IncomingLogs = append(m.IncomingLogs, &transaction.Log{}) - if err := m.IncomingLogs[len(m.IncomingLogs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.IncomingEvents = append(m.IncomingEvents, &transaction.Event{}) + if err := m.IncomingEvents[len(m.IncomingEvents)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/data/sovereign/incomingHeader.proto b/data/sovereign/incomingHeader.proto index 338dad80f..1e3c6c103 100644 --- a/data/sovereign/incomingHeader.proto +++ b/data/sovereign/incomingHeader.proto @@ -11,8 +11,7 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/multiversx/mx-chain-core-go/data/block/blockV2.proto"; import "github.com/multiversx/mx-chain-core-go/data/transaction/log.proto"; -// ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain message IncomingHeader { - HeaderV2 Header = 1 [(gogoproto.jsontag) = "header"]; - repeated Log IncomingLogs = 2 [(gogoproto.jsontag) = "incomingLogs,omitempty"]; + HeaderV2 Header = 1 [(gogoproto.jsontag) = "header"]; + repeated Event IncomingEvents = 2 [(gogoproto.jsontag) = "incomingEvents,omitempty"]; } diff --git a/data/sovereign/interface.go b/data/sovereign/interface.go index 3332b6b1f..0b3356f30 100644 --- a/data/sovereign/interface.go +++ b/data/sovereign/interface.go @@ -4,6 +4,6 @@ import "github.com/multiversx/mx-chain-core-go/data" // IncomingHeaderHandler defines the incoming header to a sovereign chain that is sent by a notifier type IncomingHeaderHandler interface { - GetIncomingLogHandlers() []data.LogHandler + GetIncomingEventHandlers() []data.EventHandler GetHeaderHandler() data.HeaderHandler } From bce3602c6b289744be44b47066f23cce62dc33a4 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 10 May 2023 12:14:57 +0300 Subject: [PATCH 37/87] FIX: Add IsInterfaceNil --- data/sovereign/incomingHeader.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/sovereign/incomingHeader.go b/data/sovereign/incomingHeader.go index eb4251df7..718bb0ccf 100644 --- a/data/sovereign/incomingHeader.go +++ b/data/sovereign/incomingHeader.go @@ -28,3 +28,8 @@ func (ih *IncomingHeader) GetHeaderHandler() data.HeaderHandler { return ih.GetHeader() } + +// IsInterfaceNil checks if the underlying pointer is nil +func (ih *IncomingHeader) IsInterfaceNil() bool { + return ih == nil +} From e98de4e60dccd1003b16ae64c4a7ce6c8adf0e7e Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 10 May 2023 12:15:34 +0300 Subject: [PATCH 38/87] FIX: Add IsInterfaceNil --- data/sovereign/interface.go | 1 + 1 file changed, 1 insertion(+) diff --git a/data/sovereign/interface.go b/data/sovereign/interface.go index 0b3356f30..77c0cefbe 100644 --- a/data/sovereign/interface.go +++ b/data/sovereign/interface.go @@ -6,4 +6,5 @@ import "github.com/multiversx/mx-chain-core-go/data" type IncomingHeaderHandler interface { GetIncomingEventHandlers() []data.EventHandler GetHeaderHandler() data.HeaderHandler + IsInterfaceNil() bool } From 13c05598a5b50eed1fe8a9c52fa1f26d22a02abd Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 6 Jun 2023 12:30:14 +0300 Subject: [PATCH 39/87] FEAT: Json tags --- data/block/sovereignChainHeader.pb.go | 44 ++++++++++++++------------- data/block/sovereignChainHeader.proto | 6 ++-- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index 328da36b3..74178c190 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -28,9 +28,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain type SovereignChainHeader struct { - Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` - ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"ValidatorStatsRootHash,omitempty"` - ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"ExtendedShardHeaderHashes,omitempty"` + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` + ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -89,24 +89,26 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 263 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0xce, 0x2f, 0x4b, - 0x2d, 0x4a, 0xcd, 0x4c, 0xcf, 0x73, 0xce, 0x48, 0xcc, 0xcc, 0xf3, 0x48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, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x7c, 0xf1, 0x48, 0x8e, 0xe1, 0xc3, - 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, - 0x8a, 0x15, 0xec, 0xf9, 0x24, 0x36, 0xb0, 0x67, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x09, - 0x27, 0x59, 0x6a, 0x5e, 0x01, 0x00, 0x00, + // 299 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x50, 0xb1, 0x4e, 0xc3, 0x30, + 0x14, 0xb4, 0x5b, 0xb5, 0x83, 0x5b, 0x96, 0x08, 0x55, 0x25, 0xc3, 0x6b, 0x05, 0x03, 0x19, 0x20, + 0x15, 0xf0, 0x01, 0x48, 0x41, 0x48, 0x9d, 0x13, 0x89, 0x81, 0xcd, 0x69, 0x4c, 0x12, 0xd1, 0xc4, + 0x55, 0xe2, 0x56, 0xb0, 0x31, 0xf0, 0x01, 0x7c, 0x06, 0x9f, 0xc2, 0x98, 0x31, 0x53, 0x44, 0x9c, + 0x05, 0x65, 0xea, 0x27, 0x20, 0x6c, 0xc6, 0x66, 0xf2, 0xdd, 0xf9, 0xee, 0x9d, 0x74, 0xc4, 0xcc, + 0xf9, 0x8e, 0x65, 0x2c, 0x0e, 0xd3, 0xbb, 0x88, 0xc6, 0xe9, 0x92, 0xd1, 0x80, 0x65, 0xf6, 0x26, + 0xe3, 0x82, 0x1b, 0x03, 0xf5, 0x98, 0x97, 0x61, 0x2c, 0xa2, 0xad, 0x6f, 0xaf, 0x78, 0xb2, 0x08, + 0x79, 0xc8, 0x17, 0x4a, 0xf6, 0xb7, 0x4f, 0x8a, 0x29, 0xa2, 0x90, 0x4e, 0x99, 0x23, 0x7f, 0xcd, + 0x57, 0xcf, 0x9a, 0x9c, 0xbe, 0xf7, 0xc8, 0xb1, 0x77, 0xa0, 0xc1, 0xb8, 0x22, 0x43, 0x8d, 0xa6, + 0x78, 0x8e, 0xad, 0xd1, 0xf5, 0x91, 0x0e, 0xd8, 0x5a, 0x74, 0x48, 0x5b, 0xcd, 0x86, 0x91, 0xc2, + 0xee, 0xbf, 0xd1, 0x70, 0xc9, 0xe4, 0x81, 0xae, 0xe3, 0x80, 0x0a, 0x9e, 0x79, 0x82, 0x8a, 0xdc, + 0xe5, 0x5c, 0x2c, 0x69, 0x1e, 0x4d, 0x7b, 0x73, 0x6c, 0x8d, 0x1d, 0xb3, 0xad, 0x66, 0x93, 0xdd, + 0x41, 0x87, 0xdb, 0x91, 0x34, 0x18, 0x39, 0xb9, 0x7f, 0x11, 0x2c, 0x0d, 0x58, 0xe0, 0x45, 0x34, + 0x0b, 0x74, 0xd5, 0xdf, 0x17, 0xcb, 0xa7, 0xfd, 0x79, 0xdf, 0x1a, 0x3b, 0xe7, 0x6d, 0x35, 0x3b, + 0x63, 0x5d, 0xa6, 0x0b, 0x9e, 0xc4, 0x82, 0x25, 0x1b, 0xf1, 0xea, 0x76, 0x5f, 0x72, 0x6e, 0x8b, + 0x1a, 0x50, 0x59, 0x03, 0xda, 0xd7, 0x80, 0xdf, 0x24, 0xe0, 0x4f, 0x09, 0xf8, 0x4b, 0x02, 0x2e, + 0x24, 0xe0, 0x52, 0x02, 0xfe, 0x96, 0x80, 0x7f, 0x24, 0xa0, 0xbd, 0x04, 0xfc, 0xd1, 0x00, 0x2a, + 0x1a, 0x40, 0x65, 0x03, 0xe8, 0x71, 0xa0, 0xd6, 0xf4, 0x87, 0x6a, 0x9d, 0x9b, 0xdf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x95, 0xf1, 0x81, 0x56, 0xaf, 0x01, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index a35c90c99..a8385844b 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -11,7 +11,7 @@ import "block.proto"; // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain message SovereignChainHeader { - Header Header = 1; - bytes ValidatorStatsRootHash = 2; - repeated bytes ExtendedShardHeaderHashes = 3; + Header Header = 1 [(gogoproto.jsontag) = "header"]; + bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; + repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; } From 59f40d2b902794a98afc4bacfaa0171ea784b590 Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 17 Jul 2023 17:21:01 +0300 Subject: [PATCH 40/87] FEAT: Get + Set shard id in sovereignChainHeader --- data/block/sovereignChainHeader.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index f3471a532..c4cbb5638 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -44,7 +44,7 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { // GetShardID returns 0 as the shardID for the sovereign chain header func (sch *SovereignChainHeader) GetShardID() uint32 { - return 0 + return sch.Header.ShardID } // GetNonce returns the header nonce @@ -371,7 +371,8 @@ func (sch *SovereignChainHeader) SetTxCount(txCount uint32) error { } // SetShardID does nothing and returns nil for the sovereign chain header -func (sch *SovereignChainHeader) SetShardID(_ uint32) error { +func (sch *SovereignChainHeader) SetShardID(shardID uint32) error { + sch.Header.ShardID = shardID return nil } From a4ffe12ea77f21abe1107dc5790abc30b684d20e Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 28 Jul 2023 12:34:39 +0300 Subject: [PATCH 41/87] CLN: Make sovereign chain shard id = 0 --- core/shardIDConstants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shardIDConstants.go b/core/shardIDConstants.go index f42857abb..d16c410be 100644 --- a/core/shardIDConstants.go +++ b/core/shardIDConstants.go @@ -7,7 +7,7 @@ const MetachainShardId = uint32(0xFFFFFFFF) const AllShardId = uint32(0xFFFFFFF0) // SovereignChainShardId will be used to identify a shard ID as sovereign chain -const SovereignChainShardId = uint32(0xFFFFFFFE) +const SovereignChainShardId = uint32(0) // MainChainShardId will be used to identify a shard ID as main chain const MainChainShardId = uint32(0xFFFFFFFD) From 009294fa2f1e85d035b5b55a6a38b49e3d5a2d0b Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 25 Aug 2023 17:03:13 +0300 Subject: [PATCH 42/87] CLN: SetShardID --- data/block/sovereignChainHeader.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index c4cbb5638..47982ebd2 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -42,7 +42,7 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { return &headerCopy } -// GetShardID returns 0 as the shardID for the sovereign chain header +// GetShardID returns internal header shard id func (sch *SovereignChainHeader) GetShardID() uint32 { return sch.Header.ShardID } @@ -370,10 +370,13 @@ func (sch *SovereignChainHeader) SetTxCount(txCount uint32) error { return sch.Header.SetTxCount(txCount) } -// SetShardID does nothing and returns nil for the sovereign chain header +// SetShardID sets the shard id func (sch *SovereignChainHeader) SetShardID(shardID uint32) error { - sch.Header.ShardID = shardID - return nil + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetShardID(shardID) } // SetValidatorStatsRootHash sets the root hash for the validator statistics trie From 1f82e8efb13a3c307c75d159a29398b6e615fcaa Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 28 Aug 2023 13:17:06 +0300 Subject: [PATCH 43/87] FIX: GetShardID --- data/block/sovereignChainHeader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 47982ebd2..f7d3662b5 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -44,6 +44,10 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { // GetShardID returns internal header shard id func (sch *SovereignChainHeader) GetShardID() uint32 { + if sch == nil { + return 0 + } + return sch.Header.ShardID } From f8c2d02f1d9379b86e3e60a594f4ae46d5288819 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 30 Aug 2023 14:27:30 +0300 Subject: [PATCH 44/87] FEAT: Add sovereign proof incoming mb --- data/block/block.proto | 4 +- data/block/shardHeaderExtended.go | 25 ++++++ data/block/shardHeaderExtended.pb.go | 127 ++++++++++++++++++++++----- data/block/shardHeaderExtended.proto | 2 + data/sovereign/interface.go | 8 ++ 5 files changed, 143 insertions(+), 23 deletions(-) diff --git a/data/block/block.proto b/data/block/block.proto index 99d11d0bb..72d35fdfd 100644 --- a/data/block/block.proto +++ b/data/block/block.proto @@ -8,7 +8,7 @@ syntax = "proto3"; package proto; -option go_package = "github.com/multiversx/mx-chain-core-go/data/block;block"; +option go_package = "block"; option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; @@ -22,7 +22,7 @@ enum Type { InvalidBlock = 120; ReceiptBlock = 150; RewardsBlock = 255; -} +}; enum ProcessingType { Normal = 0; diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index 05bc4a8c9..ed69b8ac2 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -889,3 +889,28 @@ func (she *ShardHeaderExtended) SetIncomingMiniBlockHandlers(miniBlockHandlers [ return nil } + +// GetIncomingEventHandlers returns the incoming events as an array of event handlers +func (she *ShardHeaderExtended) GetIncomingEventHandlers() []data.EventHandler { + if she == nil { + return nil + } + + events := she.GetIncomingEvents() + logHandlers := make([]data.EventHandler, len(events)) + + for i := range events { + logHandlers[i] = events[i] + } + + return logHandlers +} + +// GetHeaderHandler returns the incoming headerV2 as a header handler +func (she *ShardHeaderExtended) GetHeaderHandler() data.HeaderHandler { + if she == nil { + return nil + } + + return she.GetHeader() +} diff --git a/data/block/shardHeaderExtended.pb.go b/data/block/shardHeaderExtended.pb.go index 317d02d96..c265208d6 100644 --- a/data/block/shardHeaderExtended.pb.go +++ b/data/block/shardHeaderExtended.pb.go @@ -7,6 +7,7 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + transaction "github.com/multiversx/mx-chain-core-go/data/transaction" io "io" math "math" math_bits "math/bits" @@ -27,8 +28,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain type ShardHeaderExtended struct { - Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` - IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"incomingMiniBlocks,omitempty"` + Header *HeaderV2 `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + IncomingMiniBlocks []*MiniBlock `protobuf:"bytes,2,rep,name=IncomingMiniBlocks,proto3" json:"incomingMiniBlocks,omitempty"` + IncomingEvents []*transaction.Event `protobuf:"bytes,3,rep,name=IncomingEvents,proto3" json:"incomingEvents,omitempty"` } func (m *ShardHeaderExtended) Reset() { *m = ShardHeaderExtended{} } @@ -73,6 +75,13 @@ func (m *ShardHeaderExtended) GetIncomingMiniBlocks() []*MiniBlock { return nil } +func (m *ShardHeaderExtended) GetIncomingEvents() []*transaction.Event { + if m != nil { + return m.IncomingEvents + } + return nil +} + func init() { proto.RegisterType((*ShardHeaderExtended)(nil), "proto.ShardHeaderExtended") } @@ -80,24 +89,29 @@ func init() { func init() { proto.RegisterFile("shardHeaderExtended.proto", fileDescriptor_549610f8c128bd02) } var fileDescriptor_549610f8c128bd02 = []byte{ - // 267 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0xce, 0x48, 0x2c, - 0x4a, 0xf1, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x72, 0xad, 0x28, 0x49, 0xcd, 0x4b, 0x49, 0x4d, 0xd1, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x52, 0xdc, 0x49, 0x39, 0xf9, 0xc9, 0xd9, - 0x10, 0x31, 0x29, 0x5e, 0x30, 0x27, 0xcc, 0x08, 0xca, 0xd5, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, - 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0x0b, 0x27, 0x95, 0xa6, 0x81, - 0x79, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xae, 0xb4, 0x8e, 0x91, 0x4b, 0x38, 0x18, 0xd3, 0x3e, 0x21, - 0x63, 0x2e, 0x36, 0x88, 0x88, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x11, 0x3f, 0x44, 0xbd, 0x1e, - 0x44, 0x30, 0xcc, 0xc8, 0x89, 0xeb, 0xd5, 0x3d, 0x79, 0xb6, 0x0c, 0x30, 0x2f, 0x08, 0xaa, 0x54, - 0x28, 0x89, 0x4b, 0xc8, 0x33, 0x2f, 0x39, 0x3f, 0x37, 0x33, 0x2f, 0xdd, 0x37, 0x33, 0x2f, 0xd3, - 0x09, 0xe4, 0xb0, 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x01, 0xa8, 0x01, 0x70, 0x09, - 0x27, 0x85, 0x57, 0xf7, 0xe4, 0x65, 0x32, 0x31, 0xd4, 0xeb, 0xe4, 0xe7, 0x66, 0x96, 0xa4, 0xe6, - 0x16, 0x94, 0x54, 0x06, 0x61, 0x31, 0xcd, 0xc9, 0xfe, 0xc2, 0x43, 0x39, 0x86, 0x1b, 0x0f, 0xe5, - 0x18, 0x3e, 0x3c, 0x94, 0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, - 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0xde, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x8b, - 0x47, 0x72, 0x0c, 0x1f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, - 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xac, 0xe0, 0x80, 0x4a, 0x62, 0x03, 0xbb, 0xc3, 0x18, 0x10, 0x00, - 0x00, 0xff, 0xff, 0xbc, 0xb3, 0xf2, 0x5c, 0x67, 0x01, 0x00, 0x00, + // 348 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xfa, 0x30, + 0x1c, 0xc7, 0x57, 0x08, 0x1c, 0xc6, 0xff, 0xaf, 0x66, 0x5e, 0x26, 0x21, 0x3f, 0x88, 0x27, 0x0e, + 0x8e, 0x25, 0xe3, 0x01, 0x8c, 0x4b, 0x48, 0xf4, 0xe0, 0x05, 0x13, 0x0e, 0xde, 0xba, 0xad, 0x6e, + 0x8d, 0xac, 0x25, 0x5d, 0x21, 0x78, 0x33, 0x3e, 0x81, 0x8f, 0xe1, 0xa3, 0x78, 0xe4, 0xc8, 0x89, + 0x48, 0xb9, 0x98, 0x9d, 0x78, 0x04, 0x63, 0x37, 0x0d, 0x8a, 0xa7, 0xf6, 0xfb, 0xed, 0x27, 0x9f, + 0xb6, 0xf9, 0x99, 0x27, 0x59, 0x82, 0x45, 0x74, 0x49, 0x70, 0x44, 0xc4, 0x60, 0x2e, 0x09, 0x8b, + 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x9b, 0xfe, 0xe0, 0x76, 0xbc, 0xbf, 0x0c, 0xfe, 0xf9, 0x62, 0x0d, + 0xc6, 0x72, 0x0d, 0xc6, 0x76, 0x0d, 0xe8, 0x51, 0x01, 0x7a, 0x51, 0x80, 0x5e, 0x15, 0xa0, 0x85, + 0x02, 0xb4, 0x54, 0x80, 0xde, 0x14, 0xa0, 0x77, 0x05, 0xc6, 0x56, 0x01, 0x7a, 0xde, 0x80, 0xb1, + 0xd8, 0x80, 0xb1, 0xdc, 0x80, 0x71, 0x5b, 0xd3, 0xf3, 0x0b, 0xea, 0xfa, 0xee, 0xfe, 0x47, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x1b, 0x9a, 0x02, 0x49, 0xfe, 0x01, 0x00, 0x00, } func (this *ShardHeaderExtended) Equal(that interface{}) bool { @@ -130,13 +144,21 @@ func (this *ShardHeaderExtended) Equal(that interface{}) bool { return false } } + if len(this.IncomingEvents) != len(that1.IncomingEvents) { + return false + } + for i := range this.IncomingEvents { + if !this.IncomingEvents[i].Equal(that1.IncomingEvents[i]) { + return false + } + } return true } func (this *ShardHeaderExtended) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&block.ShardHeaderExtended{") if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") @@ -144,6 +166,9 @@ func (this *ShardHeaderExtended) GoString() string { if this.IncomingMiniBlocks != nil { s = append(s, "IncomingMiniBlocks: "+fmt.Sprintf("%#v", this.IncomingMiniBlocks)+",\n") } + if this.IncomingEvents != nil { + s = append(s, "IncomingEvents: "+fmt.Sprintf("%#v", this.IncomingEvents)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -175,6 +200,20 @@ func (m *ShardHeaderExtended) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.IncomingEvents) > 0 { + for iNdEx := len(m.IncomingEvents) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IncomingEvents[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintShardHeaderExtended(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } if len(m.IncomingMiniBlocks) > 0 { for iNdEx := len(m.IncomingMiniBlocks) - 1; iNdEx >= 0; iNdEx-- { { @@ -231,6 +270,12 @@ func (m *ShardHeaderExtended) Size() (n int) { n += 1 + l + sovShardHeaderExtended(uint64(l)) } } + if len(m.IncomingEvents) > 0 { + for _, e := range m.IncomingEvents { + l = e.Size() + n += 1 + l + sovShardHeaderExtended(uint64(l)) + } + } return n } @@ -249,9 +294,15 @@ func (this *ShardHeaderExtended) String() string { repeatedStringForIncomingMiniBlocks += strings.Replace(fmt.Sprintf("%v", f), "MiniBlock", "MiniBlock", 1) + "," } repeatedStringForIncomingMiniBlocks += "}" + repeatedStringForIncomingEvents := "[]*Event{" + for _, f := range this.IncomingEvents { + repeatedStringForIncomingEvents += strings.Replace(fmt.Sprintf("%v", f), "Event", "transaction.Event", 1) + "," + } + repeatedStringForIncomingEvents += "}" s := strings.Join([]string{`&ShardHeaderExtended{`, `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "HeaderV2", "HeaderV2", 1) + `,`, `IncomingMiniBlocks:` + repeatedStringForIncomingMiniBlocks + `,`, + `IncomingEvents:` + repeatedStringForIncomingEvents + `,`, `}`, }, "") return s @@ -363,6 +414,40 @@ func (m *ShardHeaderExtended) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IncomingEvents", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowShardHeaderExtended + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthShardHeaderExtended + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthShardHeaderExtended + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IncomingEvents = append(m.IncomingEvents, &transaction.Event{}) + if err := m.IncomingEvents[len(m.IncomingEvents)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipShardHeaderExtended(dAtA[iNdEx:]) diff --git a/data/block/shardHeaderExtended.proto b/data/block/shardHeaderExtended.proto index bfffa2d2f..3a3ea6057 100644 --- a/data/block/shardHeaderExtended.proto +++ b/data/block/shardHeaderExtended.proto @@ -9,9 +9,11 @@ option (gogoproto.stable_marshaler_all) = true; import "block.proto"; import "blockV2.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/multiversx/mx-chain-core-go/data/transaction/log.proto"; // ShardHeaderExtended extends the HeaderV2 structure with extra fields needed by sovereign chain message ShardHeaderExtended { HeaderV2 Header = 1 [(gogoproto.jsontag) = "header"]; repeated MiniBlock IncomingMiniBlocks = 2 [(gogoproto.jsontag) = "incomingMiniBlocks,omitempty"]; + repeated Event IncomingEvents = 3 [(gogoproto.jsontag) = "incomingEvents,omitempty"]; } diff --git a/data/sovereign/interface.go b/data/sovereign/interface.go index 77c0cefbe..c68865da1 100644 --- a/data/sovereign/interface.go +++ b/data/sovereign/interface.go @@ -8,3 +8,11 @@ type IncomingHeaderHandler interface { GetHeaderHandler() data.HeaderHandler IsInterfaceNil() bool } + +// Proof defines the proof of proposed mini blocks, using provided incoming header and events +type Proof interface { + GetHeaderHandler() data.HeaderHandler + GetIncomingEventHandlers() []data.EventHandler + GetIncomingMiniBlockHandlers() []data.MiniBlockHandler + IsInterfaceNil() bool +} From 6819129f475516411ea483f49d53a729af5109eb Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 30 Aug 2023 14:44:25 +0300 Subject: [PATCH 45/87] FIX: Import cycle --- data/transaction/{ => status}/interface.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename data/transaction/{ => status}/interface.go (51%) diff --git a/data/transaction/interface.go b/data/transaction/status/interface.go similarity index 51% rename from data/transaction/interface.go rename to data/transaction/status/interface.go index cbc0bb1c6..d9f5de85d 100644 --- a/data/transaction/interface.go +++ b/data/transaction/status/interface.go @@ -1,13 +1,16 @@ -package transaction +package status -import "github.com/multiversx/mx-chain-core-go/data/block" +import ( + "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-core-go/data/transaction" +) // StatusComputerHandler computes a transaction status type StatusComputerHandler interface { - ComputeStatusWhenInStorageKnowingMiniblock(miniblockType block.Type, tx *ApiTransactionResult) (TxStatus, error) - ComputeStatusWhenInStorageNotKnowingMiniblock(destinationShard uint32, tx *ApiTransactionResult) (TxStatus, error) + ComputeStatusWhenInStorageKnowingMiniblock(miniblockType block.Type, tx *transaction.ApiTransactionResult) (transaction.TxStatus, error) + ComputeStatusWhenInStorageNotKnowingMiniblock(destinationShard uint32, tx *transaction.ApiTransactionResult) (transaction.TxStatus, error) SetStatusIfIsRewardReverted( - tx *ApiTransactionResult, + tx *transaction.ApiTransactionResult, miniblockType block.Type, headerNonce uint64, headerHash []byte, From 90f12eeb1e0470fb8dfee0dec8e08f8dd31d89fa Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 31 Aug 2023 12:17:26 +0300 Subject: [PATCH 46/87] FEAT: Extend ShardHeaderExtended interface --- data/interface.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/interface.go b/data/interface.go index 0d017cd6c..19e8e3861 100644 --- a/data/interface.go +++ b/data/interface.go @@ -445,4 +445,6 @@ type ShardHeaderExtendedHandler interface { ShardHeaderHandler GetIncomingMiniBlockHandlers() []MiniBlockHandler SetIncomingMiniBlockHandlers(miniBlockHandlers []MiniBlockHandler) error + GetHeaderHandler() HeaderHandler + GetIncomingEventHandlers() []EventHandler } From c4caa1905d97aae59937723fea49511e81455367 Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 26 Sep 2023 15:07:41 +0300 Subject: [PATCH 47/87] FIX: Import cycle --- data/transaction/{ => status}/interface.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename data/transaction/{ => status}/interface.go (51%) diff --git a/data/transaction/interface.go b/data/transaction/status/interface.go similarity index 51% rename from data/transaction/interface.go rename to data/transaction/status/interface.go index cbc0bb1c6..d9f5de85d 100644 --- a/data/transaction/interface.go +++ b/data/transaction/status/interface.go @@ -1,13 +1,16 @@ -package transaction +package status -import "github.com/multiversx/mx-chain-core-go/data/block" +import ( + "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-core-go/data/transaction" +) // StatusComputerHandler computes a transaction status type StatusComputerHandler interface { - ComputeStatusWhenInStorageKnowingMiniblock(miniblockType block.Type, tx *ApiTransactionResult) (TxStatus, error) - ComputeStatusWhenInStorageNotKnowingMiniblock(destinationShard uint32, tx *ApiTransactionResult) (TxStatus, error) + ComputeStatusWhenInStorageKnowingMiniblock(miniblockType block.Type, tx *transaction.ApiTransactionResult) (transaction.TxStatus, error) + ComputeStatusWhenInStorageNotKnowingMiniblock(destinationShard uint32, tx *transaction.ApiTransactionResult) (transaction.TxStatus, error) SetStatusIfIsRewardReverted( - tx *ApiTransactionResult, + tx *transaction.ApiTransactionResult, miniblockType block.Type, headerNonce uint64, headerHash []byte, From 5f47af6c09818ff831d526485170aa2861bc3990 Mon Sep 17 00:00:00 2001 From: Bogdan Rosianu Date: Thu, 28 Sep 2023 11:22:32 +0300 Subject: [PATCH 48/87] added sovereign header type --- core/constants.go | 2 ++ data/block/emptySovereignHeaderCreator.go | 20 +++++++++++++++++++ .../block/emptySovereignHeaderCreator_test.go | 15 ++++++++++++++ data/outport/common.go | 2 ++ 4 files changed, 39 insertions(+) create mode 100644 data/block/emptySovereignHeaderCreator.go create mode 100644 data/block/emptySovereignHeaderCreator_test.go diff --git a/core/constants.go b/core/constants.go index 6b1564d22..443d2be17 100644 --- a/core/constants.go +++ b/core/constants.go @@ -10,6 +10,8 @@ const ( ShardHeaderV1 HeaderType = "Header" // ShardHeaderV2 defines the type of *block.HeaderV2 ShardHeaderV2 HeaderType = "HeaderV2" + // SovereignChainHeader defines the type of *block.SovereignChainHeader + SovereignChainHeader = "SovereignChainHeader" ) // NodeType represents the node's role in the network diff --git a/data/block/emptySovereignHeaderCreator.go b/data/block/emptySovereignHeaderCreator.go new file mode 100644 index 000000000..756729d28 --- /dev/null +++ b/data/block/emptySovereignHeaderCreator.go @@ -0,0 +1,20 @@ +package block + +import "github.com/multiversx/mx-chain-core-go/data" + +type emptySovereignHeaderCreator struct{} + +// NewEmptySovereignHeaderCreator is able to create empty sovereign header instances +func NewEmptySovereignHeaderCreator() *emptySovereignHeaderCreator { + return &emptySovereignHeaderCreator{} +} + +// CreateNewHeader creates a new empty sovereign header +func (creator *emptySovereignHeaderCreator) CreateNewHeader() data.HeaderHandler { + return &SovereignChainHeader{} +} + +// IsInterfaceNil returns true if there is no value under the interface +func (creator *emptySovereignHeaderCreator) IsInterfaceNil() bool { + return creator == nil +} diff --git a/data/block/emptySovereignHeaderCreator_test.go b/data/block/emptySovereignHeaderCreator_test.go new file mode 100644 index 000000000..7a6dd604b --- /dev/null +++ b/data/block/emptySovereignHeaderCreator_test.go @@ -0,0 +1,15 @@ +package block + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_emptySovereignHeaderCreator_CreateNewHeader(t *testing.T) { + creator := NewEmptySovereignHeaderCreator() + require.False(t, creator.IsInterfaceNil()) + + hdr := creator.CreateNewHeader() + require.IsType(t, &SovereignChainHeader{}, hdr) +} diff --git a/data/outport/common.go b/data/outport/common.go index 825485116..e48757f06 100644 --- a/data/outport/common.go +++ b/data/outport/common.go @@ -25,6 +25,8 @@ func GetHeaderBytesAndType(marshaller marshal.Marshalizer, headerHandler data.He headerType = core.MetaHeader case *block.Header: headerType = core.ShardHeaderV1 + case *block.SovereignChainHeader: + headerType = core.SovereignChainHeader default: return nil, "", errInvalidHeaderType } From 8a2f422bfd1fb3e9c8c962013bdcccc23f804aef Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 27 Oct 2023 11:28:45 +0300 Subject: [PATCH 49/87] FEAT: Add outgoing operation hashes in sovereign chain header --- data/block/sovereignChainHeader.go | 9 +++ data/block/sovereignChainHeader.pb.go | 109 +++++++++++++++++++++----- data/block/sovereignChainHeader.proto | 1 + data/interface.go | 2 + 4 files changed, 100 insertions(+), 21 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index f7d3662b5..d84ee5f59 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -536,3 +536,12 @@ func (sch *SovereignChainHeader) CheckFieldsForNil() error { return nil } + +func (sch *SovereignChainHeader) SetOutGoingOperationHashes(hashes [][]byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + sch.OutGoingOperationHashes = hashes + return nil +} diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index 74178c190..98d11a0ab 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -31,6 +31,7 @@ type SovereignChainHeader struct { Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` + OutGoingOperationHashes [][]byte `protobuf:"bytes,4,rep,name=OutGoingOperationHashes,proto3" json:"outGoingOperationHashes,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -82,6 +83,13 @@ func (m *SovereignChainHeader) GetExtendedShardHeaderHashes() [][]byte { return nil } +func (m *SovereignChainHeader) GetOutGoingOperationHashes() [][]byte { + if m != nil { + return m.OutGoingOperationHashes + } + return nil +} + func init() { proto.RegisterType((*SovereignChainHeader)(nil), "proto.SovereignChainHeader") } @@ -89,26 +97,28 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 299 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x50, 0xb1, 0x4e, 0xc3, 0x30, - 0x14, 0xb4, 0x5b, 0xb5, 0x83, 0x5b, 0x96, 0x08, 0x55, 0x25, 0xc3, 0x6b, 0x05, 0x03, 0x19, 0x20, - 0x15, 0xf0, 0x01, 0x48, 0x41, 0x48, 0x9d, 0x13, 0x89, 0x81, 0xcd, 0x69, 0x4c, 0x12, 0xd1, 0xc4, - 0x55, 0xe2, 0x56, 0xb0, 0x31, 0xf0, 0x01, 0x7c, 0x06, 0x9f, 0xc2, 0x98, 0x31, 0x53, 0x44, 0x9c, - 0x05, 0x65, 0xea, 0x27, 0x20, 0x6c, 0xc6, 0x66, 0xf2, 0xdd, 0xf9, 0xee, 0x9d, 0x74, 0xc4, 0xcc, - 0xf9, 0x8e, 0x65, 0x2c, 0x0e, 0xd3, 0xbb, 0x88, 0xc6, 0xe9, 0x92, 0xd1, 0x80, 0x65, 0xf6, 0x26, - 0xe3, 0x82, 0x1b, 0x03, 0xf5, 0x98, 0x97, 0x61, 0x2c, 0xa2, 0xad, 0x6f, 0xaf, 0x78, 0xb2, 0x08, - 0x79, 0xc8, 0x17, 0x4a, 0xf6, 0xb7, 0x4f, 0x8a, 0x29, 0xa2, 0x90, 0x4e, 0x99, 0x23, 0x7f, 0xcd, - 0x57, 0xcf, 0x9a, 0x9c, 0xbe, 0xf7, 0xc8, 0xb1, 0x77, 0xa0, 0xc1, 0xb8, 0x22, 0x43, 0x8d, 0xa6, - 0x78, 0x8e, 0xad, 0xd1, 0xf5, 0x91, 0x0e, 0xd8, 0x5a, 0x74, 0x48, 0x5b, 0xcd, 0x86, 0x91, 0xc2, - 0xee, 0xbf, 0xd1, 0x70, 0xc9, 0xe4, 0x81, 0xae, 0xe3, 0x80, 0x0a, 0x9e, 0x79, 0x82, 0x8a, 0xdc, - 0xe5, 0x5c, 0x2c, 0x69, 0x1e, 0x4d, 0x7b, 0x73, 0x6c, 0x8d, 0x1d, 0xb3, 0xad, 0x66, 0x93, 0xdd, - 0x41, 0x87, 0xdb, 0x91, 0x34, 0x18, 0x39, 0xb9, 0x7f, 0x11, 0x2c, 0x0d, 0x58, 0xe0, 0x45, 0x34, - 0x0b, 0x74, 0xd5, 0xdf, 0x17, 0xcb, 0xa7, 0xfd, 0x79, 0xdf, 0x1a, 0x3b, 0xe7, 0x6d, 0x35, 0x3b, - 0x63, 0x5d, 0xa6, 0x0b, 0x9e, 0xc4, 0x82, 0x25, 0x1b, 0xf1, 0xea, 0x76, 0x5f, 0x72, 0x6e, 0x8b, - 0x1a, 0x50, 0x59, 0x03, 0xda, 0xd7, 0x80, 0xdf, 0x24, 0xe0, 0x4f, 0x09, 0xf8, 0x4b, 0x02, 0x2e, - 0x24, 0xe0, 0x52, 0x02, 0xfe, 0x96, 0x80, 0x7f, 0x24, 0xa0, 0xbd, 0x04, 0xfc, 0xd1, 0x00, 0x2a, - 0x1a, 0x40, 0x65, 0x03, 0xe8, 0x71, 0xa0, 0xd6, 0xf4, 0x87, 0x6a, 0x9d, 0x9b, 0xdf, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x95, 0xf1, 0x81, 0x56, 0xaf, 0x01, 0x00, 0x00, + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xb1, 0x4e, 0xc2, 0x40, + 0x18, 0xc7, 0x7b, 0x20, 0x0c, 0x07, 0x2e, 0x8d, 0x41, 0xec, 0xf0, 0x15, 0x35, 0x46, 0x06, 0x85, + 0xa8, 0x0f, 0x60, 0x52, 0x63, 0x64, 0x23, 0x29, 0x89, 0x83, 0x8b, 0xb9, 0xd2, 0xb3, 0xbd, 0x08, + 0xfd, 0x48, 0x7b, 0x10, 0xdd, 0x7c, 0x04, 0x1f, 0xc3, 0x47, 0x71, 0x64, 0x64, 0x6a, 0xe4, 0x88, + 0x89, 0xe9, 0xc4, 0x23, 0x18, 0xaf, 0x0c, 0x0e, 0x74, 0xba, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xfb, + 0x25, 0x77, 0xd4, 0x4a, 0x70, 0xc6, 0x63, 0x2e, 0x82, 0xe8, 0x26, 0x64, 0x22, 0xea, 0x71, 0xe6, + 0xf3, 0xb8, 0x33, 0x89, 0x51, 0xa2, 0x59, 0xd1, 0x87, 0x75, 0x1e, 0x08, 0x19, 0x4e, 0xbd, 0xce, + 0x10, 0xc7, 0xdd, 0x00, 0x03, 0xec, 0xea, 0xb1, 0x37, 0x7d, 0xd2, 0x4e, 0x1b, 0xad, 0xf2, 0x96, + 0x55, 0xf3, 0x46, 0x38, 0x7c, 0xce, 0xcd, 0xd1, 0x77, 0x89, 0xee, 0x0d, 0xb6, 0x10, 0xcc, 0x0b, + 0x5a, 0xcd, 0x55, 0x93, 0xb4, 0x48, 0xbb, 0x76, 0xb9, 0x9b, 0x17, 0x3a, 0xf9, 0xd0, 0xa1, 0x59, + 0x6a, 0x57, 0x43, 0xad, 0xdd, 0x4d, 0xd0, 0x74, 0x69, 0xe3, 0x9e, 0x8d, 0x84, 0xcf, 0x24, 0xc6, + 0x03, 0xc9, 0x64, 0xe2, 0x22, 0xca, 0x1e, 0x4b, 0xc2, 0x66, 0xa9, 0x45, 0xda, 0x75, 0xc7, 0xca, + 0x52, 0xbb, 0x31, 0xdb, 0x9a, 0x70, 0x0b, 0x9a, 0x26, 0xa7, 0x07, 0xb7, 0x2f, 0x92, 0x47, 0x3e, + 0xf7, 0x07, 0x21, 0x8b, 0xfd, 0x1c, 0xf5, 0x77, 0xc5, 0x93, 0x66, 0xb9, 0x55, 0x6e, 0xd7, 0x9d, + 0xd3, 0x2c, 0xb5, 0x8f, 0x79, 0x51, 0xe8, 0x0c, 0xc7, 0x42, 0xf2, 0xf1, 0x44, 0xbe, 0xba, 0xc5, + 0x9b, 0xcc, 0x47, 0xba, 0xdf, 0x9f, 0xca, 0x3b, 0x14, 0x51, 0xd0, 0x9f, 0xf0, 0x98, 0x49, 0x81, + 0xd1, 0x06, 0xb2, 0xa3, 0x21, 0x27, 0x59, 0x6a, 0x1f, 0xe2, 0xf6, 0xc8, 0x3f, 0x44, 0xd1, 0x16, + 0xe7, 0x7a, 0xbe, 0x04, 0x63, 0xb1, 0x04, 0x63, 0xbd, 0x04, 0xf2, 0xa6, 0x80, 0x7c, 0x28, 0x20, + 0x9f, 0x0a, 0xc8, 0x5c, 0x01, 0x59, 0x28, 0x20, 0x5f, 0x0a, 0xc8, 0x8f, 0x02, 0x63, 0xad, 0x80, + 0xbc, 0xaf, 0xc0, 0x98, 0xaf, 0xc0, 0x58, 0xac, 0xc0, 0x78, 0xa8, 0xe8, 0xef, 0xf2, 0xaa, 0xfa, + 0xf9, 0xaf, 0x7e, 0x03, 0x00, 0x00, 0xff, 0xff, 0x38, 0xf5, 0xd0, 0xe5, 0x10, 0x02, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -144,19 +154,28 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { return false } } + if len(this.OutGoingOperationHashes) != len(that1.OutGoingOperationHashes) { + return false + } + for i := range this.OutGoingOperationHashes { + if !bytes.Equal(this.OutGoingOperationHashes[i], that1.OutGoingOperationHashes[i]) { + return false + } + } return true } func (this *SovereignChainHeader) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 7) + s := make([]string, 0, 8) s = append(s, "&block.SovereignChainHeader{") if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") } s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") s = append(s, "ExtendedShardHeaderHashes: "+fmt.Sprintf("%#v", this.ExtendedShardHeaderHashes)+",\n") + s = append(s, "OutGoingOperationHashes: "+fmt.Sprintf("%#v", this.OutGoingOperationHashes)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -188,6 +207,15 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.OutGoingOperationHashes) > 0 { + for iNdEx := len(m.OutGoingOperationHashes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.OutGoingOperationHashes[iNdEx]) + copy(dAtA[i:], m.OutGoingOperationHashes[iNdEx]) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.OutGoingOperationHashes[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } if len(m.ExtendedShardHeaderHashes) > 0 { for iNdEx := len(m.ExtendedShardHeaderHashes) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.ExtendedShardHeaderHashes[iNdEx]) @@ -250,6 +278,12 @@ func (m *SovereignChainHeader) Size() (n int) { n += 1 + l + sovSovereignChainHeader(uint64(l)) } } + if len(m.OutGoingOperationHashes) > 0 { + for _, b := range m.OutGoingOperationHashes { + l = len(b) + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + } return n } @@ -267,6 +301,7 @@ func (this *SovereignChainHeader) String() string { `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, + `OutGoingOperationHashes:` + fmt.Sprintf("%v", this.OutGoingOperationHashes) + `,`, `}`, }, "") return s @@ -410,6 +445,38 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { m.ExtendedShardHeaderHashes = append(m.ExtendedShardHeaderHashes, make([]byte, postIndex-iNdEx)) copy(m.ExtendedShardHeaderHashes[len(m.ExtendedShardHeaderHashes)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutGoingOperationHashes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OutGoingOperationHashes = append(m.OutGoingOperationHashes, make([]byte, postIndex-iNdEx)) + copy(m.OutGoingOperationHashes[len(m.OutGoingOperationHashes)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index a8385844b..915fd3d31 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -14,4 +14,5 @@ message SovereignChainHeader { Header Header = 1 [(gogoproto.jsontag) = "header"]; bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; + repeated bytes OutGoingOperationHashes = 4 [(gogoproto.jsontag) = "outGoingOperationHashes,omitempty"]; } diff --git a/data/interface.go b/data/interface.go index 19e8e3861..84203cb4b 100644 --- a/data/interface.go +++ b/data/interface.go @@ -93,6 +93,8 @@ type SovereignChainHeaderHandler interface { GetValidatorStatsRootHash() []byte SetExtendedShardHeaderHashes(hdrHashes [][]byte) error GetExtendedShardHeaderHashes() [][]byte + SetOutGoingOperationHashes(hashes [][]byte) error + GetOutGoingOperationHashes() [][]byte } // HeaderHandler defines getters and setters for header data holder From 2ecbe85a736c8640092394cb751a66dc84ff6462 Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 31 Oct 2023 17:45:44 +0200 Subject: [PATCH 50/87] FEAT: Extend outgoing operations data struct --- data/block/sovereignChainHeader.go | 85 ++++- data/block/sovereignChainHeader.pb.go | 473 ++++++++++++++++++++++++-- data/block/sovereignChainHeader.proto | 15 +- data/interface.go | 6 + 4 files changed, 540 insertions(+), 39 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index d84ee5f59..372a6ea88 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -537,11 +537,94 @@ func (sch *SovereignChainHeader) CheckFieldsForNil() error { return nil } +// SetOutGoingOperationHashes sets outgoing operation hashes func (sch *SovereignChainHeader) SetOutGoingOperationHashes(hashes [][]byte) error { if sch == nil { return data.ErrNilPointerReceiver } - sch.OutGoingOperationHashes = hashes + if sch.OutGoingOperations == nil { + sch.OutGoingOperations = &OutGoingOperations{} + } + + sch.OutGoingOperations.OutGoingOperationHashes = hashes return nil } + +// GetOutGoingOperationHashes returns outgoing operation hashes +func (sch *SovereignChainHeader) GetOutGoingOperationHashes() [][]byte { + if sch == nil { + return nil + } + + return sch.OutGoingOperations.GetOutGoingOperationHashes() +} + +// SetOutGoingOperationsHash sets outgoing operations hash +func (sch *SovereignChainHeader) SetOutGoingOperationsHash(hash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + if sch.OutGoingOperations == nil { + sch.OutGoingOperations = &OutGoingOperations{} + } + + sch.OutGoingOperations.OutGoingOperationsHash = hash + return nil +} + +// GetOutGoingOperationsHash returns outgoing operations hash +func (sch *SovereignChainHeader) GetOutGoingOperationsHash() []byte { + if sch == nil { + return nil + } + + return sch.OutGoingOperations.GetOutGoingOperationsHash() +} + +// SetAggregatedSignatureOutGoingOperations sets aggregated signature for outgoing operations hash +func (sch *SovereignChainHeader) SetAggregatedSignatureOutGoingOperations(signature []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + if sch.OutGoingOperations == nil { + sch.OutGoingOperations = &OutGoingOperations{} + } + + sch.OutGoingOperations.AggregatedSignatureOutGoingOperations = signature + return nil +} + +// GetAggregatedSignatureOutGoingOperations returns aggregated signature for outgoing operations hash +func (sch *SovereignChainHeader) GetAggregatedSignatureOutGoingOperations() []byte { + if sch == nil { + return nil + } + + return sch.OutGoingOperations.GetAggregatedSignatureOutGoingOperations() +} + +// SetLeaderSignatureOutGoingOperations sets leader signature for outgoing operations hash +func (sch *SovereignChainHeader) SetLeaderSignatureOutGoingOperations(signature []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + if sch.OutGoingOperations == nil { + sch.OutGoingOperations = &OutGoingOperations{} + } + + sch.OutGoingOperations.LeaderSignatureOutGoingOperations = signature + return nil +} + +// GetLeaderSignatureOutGoingOperations returns leader signature for outgoing operations hash +func (sch *SovereignChainHeader) GetLeaderSignatureOutGoingOperations() []byte { + if sch == nil { + return nil + } + + return sch.OutGoingOperations.GetLeaderSignatureOutGoingOperations() +} diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index 98d11a0ab..b5db11615 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -28,10 +28,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain type SovereignChainHeader struct { - Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` - ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` - ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` - OutGoingOperationHashes [][]byte `protobuf:"bytes,4,rep,name=OutGoingOperationHashes,proto3" json:"outGoingOperationHashes,omitempty"` + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` + ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` + OutGoingOperations *OutGoingOperations `protobuf:"bytes,4,opt,name=OutGoingOperations,proto3" json:"outGoingOperations,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -83,42 +83,114 @@ func (m *SovereignChainHeader) GetExtendedShardHeaderHashes() [][]byte { return nil } -func (m *SovereignChainHeader) GetOutGoingOperationHashes() [][]byte { +func (m *SovereignChainHeader) GetOutGoingOperations() *OutGoingOperations { + if m != nil { + return m.OutGoingOperations + } + return nil +} + +type OutGoingOperations struct { + OutGoingOperationHashes [][]byte `protobuf:"bytes,1,rep,name=OutGoingOperationHashes,proto3" json:"outGoingOperationHashes,omitempty"` + OutGoingOperationsHash []byte `protobuf:"bytes,2,opt,name=OutGoingOperationsHash,proto3" json:"outGoingOperationsHash,omitempty"` + AggregatedSignatureOutGoingOperations []byte `protobuf:"bytes,3,opt,name=AggregatedSignatureOutGoingOperations,proto3" json:"aggregatedSignatureOutGoingOperations,omitempty"` + LeaderSignatureOutGoingOperations []byte `protobuf:"bytes,4,opt,name=LeaderSignatureOutGoingOperations,proto3" json:"leaderSignatureOutGoingOperations,omitempty"` +} + +func (m *OutGoingOperations) Reset() { *m = OutGoingOperations{} } +func (*OutGoingOperations) ProtoMessage() {} +func (*OutGoingOperations) Descriptor() ([]byte, []int) { + return fileDescriptor_b9b8ff297a820152, []int{1} +} +func (m *OutGoingOperations) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OutGoingOperations) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *OutGoingOperations) XXX_Merge(src proto.Message) { + xxx_messageInfo_OutGoingOperations.Merge(m, src) +} +func (m *OutGoingOperations) XXX_Size() int { + return m.Size() +} +func (m *OutGoingOperations) XXX_DiscardUnknown() { + xxx_messageInfo_OutGoingOperations.DiscardUnknown(m) +} + +var xxx_messageInfo_OutGoingOperations proto.InternalMessageInfo + +func (m *OutGoingOperations) GetOutGoingOperationHashes() [][]byte { if m != nil { return m.OutGoingOperationHashes } return nil } +func (m *OutGoingOperations) GetOutGoingOperationsHash() []byte { + if m != nil { + return m.OutGoingOperationsHash + } + return nil +} + +func (m *OutGoingOperations) GetAggregatedSignatureOutGoingOperations() []byte { + if m != nil { + return m.AggregatedSignatureOutGoingOperations + } + return nil +} + +func (m *OutGoingOperations) GetLeaderSignatureOutGoingOperations() []byte { + if m != nil { + return m.LeaderSignatureOutGoingOperations + } + return nil +} + func init() { proto.RegisterType((*SovereignChainHeader)(nil), "proto.SovereignChainHeader") + proto.RegisterType((*OutGoingOperations)(nil), "proto.OutGoingOperations") } func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 336 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xb1, 0x4e, 0xc2, 0x40, - 0x18, 0xc7, 0x7b, 0x20, 0x0c, 0x07, 0x2e, 0x8d, 0x41, 0xec, 0xf0, 0x15, 0x35, 0x46, 0x06, 0x85, - 0xa8, 0x0f, 0x60, 0x52, 0x63, 0x64, 0x23, 0x29, 0x89, 0x83, 0x8b, 0xb9, 0xd2, 0xb3, 0xbd, 0x08, - 0xfd, 0x48, 0x7b, 0x10, 0xdd, 0x7c, 0x04, 0x1f, 0xc3, 0x47, 0x71, 0x64, 0x64, 0x6a, 0xe4, 0x88, - 0x89, 0xe9, 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51, 0xd0, 0x9f, 0xf0, 0x98, 0x49, 0x81, - 0xd1, 0x06, 0xb2, 0xa3, 0x21, 0x27, 0x59, 0x6a, 0x1f, 0xe2, 0xf6, 0xc8, 0x3f, 0x44, 0xd1, 0x16, - 0xe7, 0x7a, 0xbe, 0x04, 0x63, 0xb1, 0x04, 0x63, 0xbd, 0x04, 0xf2, 0xa6, 0x80, 0x7c, 0x28, 0x20, - 0x9f, 0x0a, 0xc8, 0x5c, 0x01, 0x59, 0x28, 0x20, 0x5f, 0x0a, 0xc8, 0x8f, 0x02, 0x63, 0xad, 0x80, - 0xbc, 0xaf, 0xc0, 0x98, 0xaf, 0xc0, 0x58, 0xac, 0xc0, 0x78, 0xa8, 0xe8, 0xef, 0xf2, 0xaa, 0xfa, - 0xf9, 0xaf, 0x7e, 0x03, 0x00, 0x00, 0xff, 0xff, 0x38, 0xf5, 0xd0, 0xe5, 0x10, 0x02, 0x00, 0x00, + // 455 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0xe3, 0x75, 0xeb, 0xc1, 0x1b, 0x17, 0x0b, 0x95, 0xae, 0x42, 0x4e, 0x36, 0x98, 0xa8, + 0x04, 0xb4, 0x82, 0x7d, 0x00, 0x44, 0x10, 0x62, 0x07, 0xa4, 0x49, 0xa9, 0xc4, 0x01, 0x21, 0x21, + 0x77, 0x31, 0x4e, 0xb4, 0x36, 0xaf, 0x72, 0xdc, 0x09, 0x0e, 0x48, 0x5c, 0xb9, 0xf1, 0x31, 0xf8, + 0x28, 0x1c, 0x7b, 0xec, 0xc9, 0xa2, 0xee, 0x05, 0xf9, 0x34, 0xbe, 0x01, 0xc2, 0xe9, 0x21, 0x52, + 0x92, 0xad, 0xa7, 0xbc, 0xf7, 0xf2, 0x7f, 0xff, 0xdf, 0x7b, 0x71, 0x8c, 0x7b, 0x39, 0x5c, 0x71, + 0xc9, 0x53, 0x91, 0xbd, 0x4a, 0x58, 0x9a, 0x9d, 0x71, 0x16, 0x73, 0x39, 0x98, 0x49, 0x50, 0x40, + 0xf6, 0xdc, 0xa3, 0xf7, 0x54, 0xa4, 0x2a, 0x99, 0x8f, 0x07, 0x17, 0x30, 0x1d, 0x0a, 0x10, 0x30, + 0x74, 0xe5, 0xf1, 0xfc, 0x93, 0xcb, 0x5c, 0xe2, 0xa2, 0xa2, 0xab, 0xb7, 0x3f, 0x9e, 0xc0, 0xc5, + 0x65, 0x91, 0x1c, 0xff, 0xdd, 0xc1, 0x77, 0x47, 0x35, 0x04, 0xf2, 0x0c, 0xb7, 0x8b, 0xa8, 0x8b, + 0x02, 0xd4, 0xdf, 0x7f, 0x7e, 0xa7, 0x68, 0x18, 0x14, 0xc5, 0x10, 0x5b, 0xed, 0xb7, 0x13, 0x17, + 0x47, 0x1b, 0x21, 0x89, 0x70, 0xe7, 0x1d, 0x9b, 0xa4, 0x31, 0x53, 0x20, 0x47, 0x8a, 0xa9, 0x3c, + 0x02, 0x50, 0x67, 0x2c, 0x4f, 0xba, 0x3b, 0x01, 0xea, 0x1f, 0x84, 0x3d, 0xab, 0xfd, 0xce, 0x55, + 0xad, 0x22, 0x6a, 0xe8, 0x24, 0x1c, 0x1f, 0xbe, 0xfe, 0xac, 0x78, 0x16, 0xf3, 0x78, 0x94, 0x30, + 0x19, 0x17, 0xa8, 0xff, 0xaf, 0x78, 0xde, 0x6d, 0x05, 0xad, 0xfe, 0x41, 0xf8, 0xc8, 0x6a, 0xff, + 0x01, 0x6f, 0x12, 0x3d, 0x81, 0x69, 0xaa, 0xf8, 0x74, 0xa6, 0xbe, 0x44, 0xcd, 0x4e, 0xe4, 0x12, + 0x93, 0xf3, 0xb9, 0x7a, 0x03, 0x69, 0x26, 0xce, 0x67, 0x5c, 0x32, 0x95, 0x42, 0x96, 0x77, 0x77, + 0xdd, 0xe6, 0x87, 0x9b, 0xcd, 0xab, 0x82, 0x30, 0xb0, 0xda, 0xbf, 0x0f, 0x95, 0x7a, 0x89, 0x59, + 0x63, 0x7b, 0xac, 0x5b, 0x75, 0x34, 0xf2, 0x11, 0xdf, 0xab, 0x54, 0x37, 0x8b, 0x22, 0xb7, 0xe8, + 0x89, 0xd5, 0xfe, 0x11, 0xd4, 0x4b, 0x4a, 0xc8, 0x26, 0x17, 0xf2, 0x01, 0x77, 0xaa, 0xd8, 0xd2, + 0xf9, 0x3c, 0xb4, 0xda, 0x0f, 0xa0, 0x56, 0x51, 0xb2, 0x6f, 0xf0, 0x20, 0xdf, 0x11, 0x3e, 0x79, + 0x29, 0x84, 0xe4, 0x82, 0x29, 0x1e, 0x8f, 0x52, 0x91, 0x31, 0x35, 0x97, 0xbc, 0xe6, 0xb3, 0xb6, + 0x1c, 0xed, 0xd4, 0x6a, 0x7f, 0xc8, 0xb6, 0x69, 0x28, 0xc1, 0xb7, 0x23, 0x90, 0xaf, 0xf8, 0xe8, + 0xad, 0x3b, 0xde, 0x9b, 0xc6, 0xd8, 0x75, 0x63, 0x0c, 0xad, 0xf6, 0x1f, 0x4f, 0x6e, 0x13, 0x97, + 0x46, 0xb8, 0xdd, 0x39, 0x7c, 0xb1, 0x58, 0x51, 0x6f, 0xb9, 0xa2, 0xde, 0xf5, 0x8a, 0xa2, 0x6f, + 0x86, 0xa2, 0x9f, 0x86, 0xa2, 0x5f, 0x86, 0xa2, 0x85, 0xa1, 0x68, 0x69, 0x28, 0xfa, 0x6d, 0x28, + 0xfa, 0x63, 0xa8, 0x77, 0x6d, 0x28, 0xfa, 0xb1, 0xa6, 0xde, 0x62, 0x4d, 0xbd, 0xe5, 0x9a, 0x7a, + 0xef, 0xf7, 0xdc, 0xdd, 0x1c, 0xb7, 0xdd, 0x1f, 0x77, 0xfa, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x74, + 0x9d, 0xd1, 0xa5, 0xfd, 0x03, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -154,6 +226,30 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { return false } } + if !this.OutGoingOperations.Equal(that1.OutGoingOperations) { + return false + } + return true +} +func (this *OutGoingOperations) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*OutGoingOperations) + if !ok { + that2, ok := that.(OutGoingOperations) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } if len(this.OutGoingOperationHashes) != len(that1.OutGoingOperationHashes) { return false } @@ -162,6 +258,15 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { return false } } + if !bytes.Equal(this.OutGoingOperationsHash, that1.OutGoingOperationsHash) { + return false + } + if !bytes.Equal(this.AggregatedSignatureOutGoingOperations, that1.AggregatedSignatureOutGoingOperations) { + return false + } + if !bytes.Equal(this.LeaderSignatureOutGoingOperations, that1.LeaderSignatureOutGoingOperations) { + return false + } return true } func (this *SovereignChainHeader) GoString() string { @@ -175,7 +280,22 @@ func (this *SovereignChainHeader) GoString() string { } s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") s = append(s, "ExtendedShardHeaderHashes: "+fmt.Sprintf("%#v", this.ExtendedShardHeaderHashes)+",\n") + if this.OutGoingOperations != nil { + s = append(s, "OutGoingOperations: "+fmt.Sprintf("%#v", this.OutGoingOperations)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *OutGoingOperations) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 8) + s = append(s, "&block.OutGoingOperations{") s = append(s, "OutGoingOperationHashes: "+fmt.Sprintf("%#v", this.OutGoingOperationHashes)+",\n") + s = append(s, "OutGoingOperationsHash: "+fmt.Sprintf("%#v", this.OutGoingOperationsHash)+",\n") + s = append(s, "AggregatedSignatureOutGoingOperations: "+fmt.Sprintf("%#v", this.AggregatedSignatureOutGoingOperations)+",\n") + s = append(s, "LeaderSignatureOutGoingOperations: "+fmt.Sprintf("%#v", this.LeaderSignatureOutGoingOperations)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -207,14 +327,17 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.OutGoingOperationHashes) > 0 { - for iNdEx := len(m.OutGoingOperationHashes) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.OutGoingOperationHashes[iNdEx]) - copy(dAtA[i:], m.OutGoingOperationHashes[iNdEx]) - i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.OutGoingOperationHashes[iNdEx]))) - i-- - dAtA[i] = 0x22 + if m.OutGoingOperations != nil { + { + size, err := m.OutGoingOperations.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x22 } if len(m.ExtendedShardHeaderHashes) > 0 { for iNdEx := len(m.ExtendedShardHeaderHashes) - 1; iNdEx >= 0; iNdEx-- { @@ -247,6 +370,59 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *OutGoingOperations) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OutGoingOperations) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OutGoingOperations) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LeaderSignatureOutGoingOperations) > 0 { + i -= len(m.LeaderSignatureOutGoingOperations) + copy(dAtA[i:], m.LeaderSignatureOutGoingOperations) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.LeaderSignatureOutGoingOperations))) + i-- + dAtA[i] = 0x22 + } + if len(m.AggregatedSignatureOutGoingOperations) > 0 { + i -= len(m.AggregatedSignatureOutGoingOperations) + copy(dAtA[i:], m.AggregatedSignatureOutGoingOperations) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.AggregatedSignatureOutGoingOperations))) + i-- + dAtA[i] = 0x1a + } + if len(m.OutGoingOperationsHash) > 0 { + i -= len(m.OutGoingOperationsHash) + copy(dAtA[i:], m.OutGoingOperationsHash) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.OutGoingOperationsHash))) + i-- + dAtA[i] = 0x12 + } + if len(m.OutGoingOperationHashes) > 0 { + for iNdEx := len(m.OutGoingOperationHashes) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.OutGoingOperationHashes[iNdEx]) + copy(dAtA[i:], m.OutGoingOperationHashes[iNdEx]) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.OutGoingOperationHashes[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintSovereignChainHeader(dAtA []byte, offset int, v uint64) int { offset -= sovSovereignChainHeader(v) base := offset @@ -278,12 +454,37 @@ func (m *SovereignChainHeader) Size() (n int) { n += 1 + l + sovSovereignChainHeader(uint64(l)) } } + if m.OutGoingOperations != nil { + l = m.OutGoingOperations.Size() + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + return n +} + +func (m *OutGoingOperations) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l if len(m.OutGoingOperationHashes) > 0 { for _, b := range m.OutGoingOperationHashes { l = len(b) n += 1 + l + sovSovereignChainHeader(uint64(l)) } } + l = len(m.OutGoingOperationsHash) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + l = len(m.AggregatedSignatureOutGoingOperations) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + l = len(m.LeaderSignatureOutGoingOperations) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } return n } @@ -301,7 +502,20 @@ func (this *SovereignChainHeader) String() string { `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, + `OutGoingOperations:` + strings.Replace(this.OutGoingOperations.String(), "OutGoingOperations", "OutGoingOperations", 1) + `,`, + `}`, + }, "") + return s +} +func (this *OutGoingOperations) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&OutGoingOperations{`, `OutGoingOperationHashes:` + fmt.Sprintf("%v", this.OutGoingOperationHashes) + `,`, + `OutGoingOperationsHash:` + fmt.Sprintf("%v", this.OutGoingOperationsHash) + `,`, + `AggregatedSignatureOutGoingOperations:` + fmt.Sprintf("%v", this.AggregatedSignatureOutGoingOperations) + `,`, + `LeaderSignatureOutGoingOperations:` + fmt.Sprintf("%v", this.LeaderSignatureOutGoingOperations) + `,`, `}`, }, "") return s @@ -446,6 +660,95 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { copy(m.ExtendedShardHeaderHashes[len(m.ExtendedShardHeaderHashes)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutGoingOperations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.OutGoingOperations == nil { + m.OutGoingOperations = &OutGoingOperations{} + } + if err := m.OutGoingOperations.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OutGoingOperations) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OutGoingOperations: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OutGoingOperations: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field OutGoingOperationHashes", wireType) } @@ -477,6 +780,108 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { m.OutGoingOperationHashes = append(m.OutGoingOperationHashes, make([]byte, postIndex-iNdEx)) copy(m.OutGoingOperationHashes[len(m.OutGoingOperationHashes)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutGoingOperationsHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OutGoingOperationsHash = append(m.OutGoingOperationsHash[:0], dAtA[iNdEx:postIndex]...) + if m.OutGoingOperationsHash == nil { + m.OutGoingOperationsHash = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AggregatedSignatureOutGoingOperations", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AggregatedSignatureOutGoingOperations = append(m.AggregatedSignatureOutGoingOperations[:0], dAtA[iNdEx:postIndex]...) + if m.AggregatedSignatureOutGoingOperations == nil { + m.AggregatedSignatureOutGoingOperations = []byte{} + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LeaderSignatureOutGoingOperations", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LeaderSignatureOutGoingOperations = append(m.LeaderSignatureOutGoingOperations[:0], dAtA[iNdEx:postIndex]...) + if m.LeaderSignatureOutGoingOperations == nil { + m.LeaderSignatureOutGoingOperations = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index 915fd3d31..60a4d6df6 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -11,8 +11,15 @@ import "block.proto"; // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain message SovereignChainHeader { - Header Header = 1 [(gogoproto.jsontag) = "header"]; - bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; - repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; - repeated bytes OutGoingOperationHashes = 4 [(gogoproto.jsontag) = "outGoingOperationHashes,omitempty"]; + Header Header = 1 [(gogoproto.jsontag) = "header"]; + bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; + repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; + OutGoingOperations OutGoingOperations = 4 [(gogoproto.jsontag) = "outGoingOperations,omitempty"]; +} + +message OutGoingOperations { + repeated bytes OutGoingOperationHashes = 1 [(gogoproto.jsontag) = "outGoingOperationHashes,omitempty"]; + bytes OutGoingOperationsHash = 2 [(gogoproto.jsontag) = "outGoingOperationsHash,omitempty"]; + bytes AggregatedSignatureOutGoingOperations = 3 [(gogoproto.jsontag) = "aggregatedSignatureOutGoingOperations,omitempty"]; + bytes LeaderSignatureOutGoingOperations = 4 [(gogoproto.jsontag) = "leaderSignatureOutGoingOperations,omitempty"]; } diff --git a/data/interface.go b/data/interface.go index 84203cb4b..81c7b2638 100644 --- a/data/interface.go +++ b/data/interface.go @@ -95,6 +95,12 @@ type SovereignChainHeaderHandler interface { GetExtendedShardHeaderHashes() [][]byte SetOutGoingOperationHashes(hashes [][]byte) error GetOutGoingOperationHashes() [][]byte + SetOutGoingOperationsHash(hash []byte) error + GetOutGoingOperationsHash() []byte + SetAggregatedSignatureOutGoingOperations(signature []byte) error + GetAggregatedSignatureOutGoingOperations() []byte + SetLeaderSignatureOutGoingOperations(signature []byte) error + GetLeaderSignatureOutGoingOperations() []byte } // HeaderHandler defines getters and setters for header data holder From 37c38cea0b1f217e5149c7fef2815e8e206e5488 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 1 Nov 2023 13:24:42 +0200 Subject: [PATCH 51/87] FEAT: Refactor to use outgoing miniblock header --- data/block/sovereignChainHeader.go | 94 +++++------- data/block/sovereignChainHeader.pb.go | 209 +++++++++++++------------- data/block/sovereignChainHeader.proto | 18 +-- data/interface.go | 19 ++- 4 files changed, 163 insertions(+), 177 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 372a6ea88..14f012d6e 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" ) @@ -537,94 +538,77 @@ func (sch *SovereignChainHeader) CheckFieldsForNil() error { return nil } -// SetOutGoingOperationHashes sets outgoing operation hashes -func (sch *SovereignChainHeader) SetOutGoingOperationHashes(hashes [][]byte) error { - if sch == nil { - return data.ErrNilPointerReceiver - } - - if sch.OutGoingOperations == nil { - sch.OutGoingOperations = &OutGoingOperations{} - } - - sch.OutGoingOperations.OutGoingOperationHashes = hashes - return nil -} - -// GetOutGoingOperationHashes returns outgoing operation hashes -func (sch *SovereignChainHeader) GetOutGoingOperationHashes() [][]byte { +// GetOutGoingMiniBlockHeaderHandler returns the outgoing mini block header +func (sch *SovereignChainHeader) GetOutGoingMiniBlockHeaderHandler() data.OutGoingMiniBlockHeaderHandler { if sch == nil { return nil } - return sch.OutGoingOperations.GetOutGoingOperationHashes() + return sch.GetOutGoingMiniBlockHeader() } -// SetOutGoingOperationsHash sets outgoing operations hash -func (sch *SovereignChainHeader) SetOutGoingOperationsHash(hash []byte) error { +// SetOutGoingMiniBlockHeaderHandler returns the outgoing mini block header +func (sch *SovereignChainHeader) SetOutGoingMiniBlockHeaderHandler(mbHeader data.OutGoingMiniBlockHeaderHandler) error { if sch == nil { return data.ErrNilPointerReceiver } - if sch.OutGoingOperations == nil { - sch.OutGoingOperations = &OutGoingOperations{} + if check.IfNil(mbHeader) { + sch.OutGoingMiniBlockHeader = nil + return nil + } + + sch.OutGoingMiniBlockHeader = &OutGoingMiniBlockHeader{ + Hash: mbHeader.GetHash(), + OutGoingOperationsHash: mbHeader.GetOutGoingOperationsHash(), + AggregatedSignatureOutGoingOperations: mbHeader.GetAggregatedSignatureOutGoingOperations(), + LeaderSignatureOutGoingOperations: mbHeader.GetLeaderSignatureOutGoingOperations(), } - sch.OutGoingOperations.OutGoingOperationsHash = hash return nil } -// GetOutGoingOperationsHash returns outgoing operations hash -func (sch *SovereignChainHeader) GetOutGoingOperationsHash() []byte { - if sch == nil { - return nil +// SetHash returns the hash +func (omb *OutGoingMiniBlockHeader) SetHash(hash []byte) error { + if omb == nil { + return data.ErrNilPointerReceiver } - return sch.OutGoingOperations.GetOutGoingOperationsHash() + omb.Hash = hash + return nil } -// SetAggregatedSignatureOutGoingOperations sets aggregated signature for outgoing operations hash -func (sch *SovereignChainHeader) SetAggregatedSignatureOutGoingOperations(signature []byte) error { - if sch == nil { +// SetOutGoingOperationsHash returns the outgoing operations hash +func (omb *OutGoingMiniBlockHeader) SetOutGoingOperationsHash(hash []byte) error { + if omb == nil { return data.ErrNilPointerReceiver } - if sch.OutGoingOperations == nil { - sch.OutGoingOperations = &OutGoingOperations{} - } - - sch.OutGoingOperations.AggregatedSignatureOutGoingOperations = signature + omb.OutGoingOperationsHash = hash return nil } -// GetAggregatedSignatureOutGoingOperations returns aggregated signature for outgoing operations hash -func (sch *SovereignChainHeader) GetAggregatedSignatureOutGoingOperations() []byte { - if sch == nil { - return nil +// SetLeaderSignatureOutGoingOperations returns the leader signature +func (omb *OutGoingMiniBlockHeader) SetLeaderSignatureOutGoingOperations(sig []byte) error { + if omb == nil { + return data.ErrNilPointerReceiver } - return sch.OutGoingOperations.GetAggregatedSignatureOutGoingOperations() + omb.LeaderSignatureOutGoingOperations = sig + return nil } -// SetLeaderSignatureOutGoingOperations sets leader signature for outgoing operations hash -func (sch *SovereignChainHeader) SetLeaderSignatureOutGoingOperations(signature []byte) error { - if sch == nil { +// SetAggregatedSignatureOutGoingOperations returns the aggregated signature +func (omb *OutGoingMiniBlockHeader) SetAggregatedSignatureOutGoingOperations(sig []byte) error { + if omb == nil { return data.ErrNilPointerReceiver } - if sch.OutGoingOperations == nil { - sch.OutGoingOperations = &OutGoingOperations{} - } - - sch.OutGoingOperations.LeaderSignatureOutGoingOperations = signature + omb.AggregatedSignatureOutGoingOperations = sig return nil } -// GetLeaderSignatureOutGoingOperations returns leader signature for outgoing operations hash -func (sch *SovereignChainHeader) GetLeaderSignatureOutGoingOperations() []byte { - if sch == nil { - return nil - } - - return sch.OutGoingOperations.GetLeaderSignatureOutGoingOperations() +// IsInterfaceNil checks if the underlying interface is nil +func (omb *OutGoingMiniBlockHeader) IsInterfaceNil() bool { + return omb == nil } diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index b5db11615..d9dd4d276 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -28,10 +28,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain type SovereignChainHeader struct { - Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` - ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` - ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` - OutGoingOperations *OutGoingOperations `protobuf:"bytes,4,opt,name=OutGoingOperations,proto3" json:"outGoingOperations,omitempty"` + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` + ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` + ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` + OutGoingMiniBlockHeader *OutGoingMiniBlockHeader `protobuf:"bytes,4,opt,name=OutGoingMiniBlockHeader,proto3" json:"outGoingOperations,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -83,29 +83,29 @@ func (m *SovereignChainHeader) GetExtendedShardHeaderHashes() [][]byte { return nil } -func (m *SovereignChainHeader) GetOutGoingOperations() *OutGoingOperations { +func (m *SovereignChainHeader) GetOutGoingMiniBlockHeader() *OutGoingMiniBlockHeader { if m != nil { - return m.OutGoingOperations + return m.OutGoingMiniBlockHeader } return nil } -type OutGoingOperations struct { - OutGoingOperationHashes [][]byte `protobuf:"bytes,1,rep,name=OutGoingOperationHashes,proto3" json:"outGoingOperationHashes,omitempty"` - OutGoingOperationsHash []byte `protobuf:"bytes,2,opt,name=OutGoingOperationsHash,proto3" json:"outGoingOperationsHash,omitempty"` - AggregatedSignatureOutGoingOperations []byte `protobuf:"bytes,3,opt,name=AggregatedSignatureOutGoingOperations,proto3" json:"aggregatedSignatureOutGoingOperations,omitempty"` - LeaderSignatureOutGoingOperations []byte `protobuf:"bytes,4,opt,name=LeaderSignatureOutGoingOperations,proto3" json:"leaderSignatureOutGoingOperations,omitempty"` +type OutGoingMiniBlockHeader struct { + Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"hash,omitempty"` + OutGoingOperationsHash []byte `protobuf:"bytes,2,opt,name=OutGoingOperationsHash,proto3" json:"outGoingOperationsHash,omitempty"` + AggregatedSignatureOutGoingOperations []byte `protobuf:"bytes,3,opt,name=AggregatedSignatureOutGoingOperations,proto3" json:"aggregatedSignatureOutGoingOperations,omitempty"` + LeaderSignatureOutGoingOperations []byte `protobuf:"bytes,4,opt,name=LeaderSignatureOutGoingOperations,proto3" json:"leaderSignatureOutGoingOperations,omitempty"` } -func (m *OutGoingOperations) Reset() { *m = OutGoingOperations{} } -func (*OutGoingOperations) ProtoMessage() {} -func (*OutGoingOperations) Descriptor() ([]byte, []int) { +func (m *OutGoingMiniBlockHeader) Reset() { *m = OutGoingMiniBlockHeader{} } +func (*OutGoingMiniBlockHeader) ProtoMessage() {} +func (*OutGoingMiniBlockHeader) Descriptor() ([]byte, []int) { return fileDescriptor_b9b8ff297a820152, []int{1} } -func (m *OutGoingOperations) XXX_Unmarshal(b []byte) error { +func (m *OutGoingMiniBlockHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *OutGoingOperations) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *OutGoingMiniBlockHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) if err != nil { @@ -113,40 +113,40 @@ func (m *OutGoingOperations) XXX_Marshal(b []byte, deterministic bool) ([]byte, } return b[:n], nil } -func (m *OutGoingOperations) XXX_Merge(src proto.Message) { - xxx_messageInfo_OutGoingOperations.Merge(m, src) +func (m *OutGoingMiniBlockHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_OutGoingMiniBlockHeader.Merge(m, src) } -func (m *OutGoingOperations) XXX_Size() int { +func (m *OutGoingMiniBlockHeader) XXX_Size() int { return m.Size() } -func (m *OutGoingOperations) XXX_DiscardUnknown() { - xxx_messageInfo_OutGoingOperations.DiscardUnknown(m) +func (m *OutGoingMiniBlockHeader) XXX_DiscardUnknown() { + xxx_messageInfo_OutGoingMiniBlockHeader.DiscardUnknown(m) } -var xxx_messageInfo_OutGoingOperations proto.InternalMessageInfo +var xxx_messageInfo_OutGoingMiniBlockHeader proto.InternalMessageInfo -func (m *OutGoingOperations) GetOutGoingOperationHashes() [][]byte { +func (m *OutGoingMiniBlockHeader) GetHash() []byte { if m != nil { - return m.OutGoingOperationHashes + return m.Hash } return nil } -func (m *OutGoingOperations) GetOutGoingOperationsHash() []byte { +func (m *OutGoingMiniBlockHeader) GetOutGoingOperationsHash() []byte { if m != nil { return m.OutGoingOperationsHash } return nil } -func (m *OutGoingOperations) GetAggregatedSignatureOutGoingOperations() []byte { +func (m *OutGoingMiniBlockHeader) GetAggregatedSignatureOutGoingOperations() []byte { if m != nil { return m.AggregatedSignatureOutGoingOperations } return nil } -func (m *OutGoingOperations) GetLeaderSignatureOutGoingOperations() []byte { +func (m *OutGoingMiniBlockHeader) GetLeaderSignatureOutGoingOperations() []byte { if m != nil { return m.LeaderSignatureOutGoingOperations } @@ -155,42 +155,42 @@ func (m *OutGoingOperations) GetLeaderSignatureOutGoingOperations() []byte { func init() { proto.RegisterType((*SovereignChainHeader)(nil), "proto.SovereignChainHeader") - proto.RegisterType((*OutGoingOperations)(nil), "proto.OutGoingOperations") + proto.RegisterType((*OutGoingMiniBlockHeader)(nil), "proto.OutGoingMiniBlockHeader") } func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 455 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0xe3, 0x75, 0xeb, 0xc1, 0x1b, 0x17, 0x0b, 0x95, 0xae, 0x42, 0x4e, 0x36, 0x98, 0xa8, - 0x04, 0xb4, 0x82, 0x7d, 0x00, 0x44, 0x10, 0x62, 0x07, 0xa4, 0x49, 0xa9, 0xc4, 0x01, 0x21, 0x21, - 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, 0x28, - 0xfa, 0x63, 0xa8, 0x77, 0x6d, 0x28, 0xfa, 0xb1, 0xa6, 0xde, 0x62, 0x4d, 0xbd, 0xe5, 0x9a, 0x7a, - 0xef, 0xf7, 0xdc, 0xdd, 0x1c, 0xb7, 0xdd, 0x1f, 0x77, 0xfa, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x74, - 0x9d, 0xd1, 0xa5, 0xfd, 0x03, 0x00, 0x00, + // 460 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4d, 0x8b, 0x13, 0x31, + 0x18, 0x9e, 0x38, 0xdd, 0x1e, 0xb2, 0xab, 0x87, 0x20, 0xb5, 0x16, 0x49, 0xc6, 0xf5, 0xab, 0xa0, + 0xb6, 0xe8, 0xfe, 0x00, 0x71, 0x44, 0xdc, 0x83, 0x52, 0x98, 0x82, 0x07, 0xf1, 0x92, 0xee, 0xc4, + 0x4c, 0xb0, 0x9d, 0x94, 0x4c, 0xba, 0xa8, 0x20, 0xec, 0xd5, 0x9b, 0x3f, 0x43, 0xfc, 0x25, 0x1e, + 0x7b, 0xec, 0x29, 0xd8, 0xf4, 0x22, 0x39, 0xed, 0x4f, 0x90, 0xcd, 0xcc, 0x61, 0x60, 0x3b, 0xbb, + 0x7b, 0x9a, 0xf7, 0xe3, 0x79, 0x9f, 0xe7, 0x7d, 0x1f, 0x26, 0xb0, 0x57, 0xc8, 0x63, 0xa6, 0x98, + 0xe0, 0xf9, 0xab, 0x8c, 0x8a, 0xfc, 0x90, 0xd1, 0x94, 0xa9, 0xc1, 0x5c, 0x49, 0x2d, 0xd1, 0x8e, + 0xff, 0xf4, 0x9e, 0x72, 0xa1, 0xb3, 0xc5, 0x64, 0x70, 0x24, 0x67, 0x43, 0x2e, 0xb9, 0x1c, 0xfa, + 0xf2, 0x64, 0xf1, 0xc9, 0x67, 0x3e, 0xf1, 0x51, 0x39, 0xd5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 0x76, + 0x46, 0xe7, 0xc4, 0x6b, 0xd6, 0xdf, 0x77, 0x86, 0x44, 0x72, 0x2b, 0xa2, 0xc6, 0xd5, 0xc0, 0x81, + 0x7e, 0x00, 0xf8, 0xe0, 0x25, 0xe7, 0x8a, 0x71, 0xaa, 0x59, 0x3a, 0x16, 0x3c, 0xa7, 0x7a, 0xa1, + 0xd8, 0x79, 0x74, 0x37, 0xf4, 0x6a, 0x07, 0xce, 0x90, 0x21, 0xbd, 0xca, 0x40, 0x4d, 0xfc, 0x6a, + 0x0a, 0xe8, 0x3b, 0xbc, 0xfb, 0xd6, 0x7b, 0x73, 0xd1, 0x1a, 0x2d, 0xbf, 0xc6, 0xd0, 0x19, 0xf2, + 0x78, 0x7a, 0x19, 0xb8, 0xb6, 0xc2, 0xe5, 0xcc, 0xf1, 0x8b, 0xe5, 0x1a, 0x07, 0xab, 0x35, 0x0e, + 0x4e, 0xd7, 0x18, 0x9c, 0x58, 0x0c, 0x7e, 0x59, 0x0c, 0xfe, 0x58, 0x0c, 0x96, 0x16, 0x83, 0x95, + 0xc5, 0xe0, 0xaf, 0xc5, 0xe0, 0x9f, 0xc5, 0xc1, 0xa9, 0xc5, 0xe0, 0xe7, 0x06, 0x07, 0xcb, 0x0d, + 0x0e, 0x56, 0x1b, 0x1c, 0x7c, 0xd8, 0xf1, 0xcf, 0x6e, 0xd2, 0xf6, 0xff, 0xd1, 0xc1, 0xff, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x9a, 0xfb, 0x59, 0xfb, 0xd8, 0x03, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -226,19 +226,19 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { return false } } - if !this.OutGoingOperations.Equal(that1.OutGoingOperations) { + if !this.OutGoingMiniBlockHeader.Equal(that1.OutGoingMiniBlockHeader) { return false } return true } -func (this *OutGoingOperations) Equal(that interface{}) bool { +func (this *OutGoingMiniBlockHeader) Equal(that interface{}) bool { if that == nil { return this == nil } - that1, ok := that.(*OutGoingOperations) + that1, ok := that.(*OutGoingMiniBlockHeader) if !ok { - that2, ok := that.(OutGoingOperations) + that2, ok := that.(OutGoingMiniBlockHeader) if ok { that1 = &that2 } else { @@ -250,14 +250,9 @@ func (this *OutGoingOperations) Equal(that interface{}) bool { } else if this == nil { return false } - if len(this.OutGoingOperationHashes) != len(that1.OutGoingOperationHashes) { + if !bytes.Equal(this.Hash, that1.Hash) { return false } - for i := range this.OutGoingOperationHashes { - if !bytes.Equal(this.OutGoingOperationHashes[i], that1.OutGoingOperationHashes[i]) { - return false - } - } if !bytes.Equal(this.OutGoingOperationsHash, that1.OutGoingOperationsHash) { return false } @@ -280,19 +275,19 @@ func (this *SovereignChainHeader) GoString() string { } s = append(s, "ValidatorStatsRootHash: "+fmt.Sprintf("%#v", this.ValidatorStatsRootHash)+",\n") s = append(s, "ExtendedShardHeaderHashes: "+fmt.Sprintf("%#v", this.ExtendedShardHeaderHashes)+",\n") - if this.OutGoingOperations != nil { - s = append(s, "OutGoingOperations: "+fmt.Sprintf("%#v", this.OutGoingOperations)+",\n") + if this.OutGoingMiniBlockHeader != nil { + s = append(s, "OutGoingMiniBlockHeader: "+fmt.Sprintf("%#v", this.OutGoingMiniBlockHeader)+",\n") } s = append(s, "}") return strings.Join(s, "") } -func (this *OutGoingOperations) GoString() string { +func (this *OutGoingMiniBlockHeader) GoString() string { if this == nil { return "nil" } s := make([]string, 0, 8) - s = append(s, "&block.OutGoingOperations{") - s = append(s, "OutGoingOperationHashes: "+fmt.Sprintf("%#v", this.OutGoingOperationHashes)+",\n") + s = append(s, "&block.OutGoingMiniBlockHeader{") + s = append(s, "Hash: "+fmt.Sprintf("%#v", this.Hash)+",\n") s = append(s, "OutGoingOperationsHash: "+fmt.Sprintf("%#v", this.OutGoingOperationsHash)+",\n") s = append(s, "AggregatedSignatureOutGoingOperations: "+fmt.Sprintf("%#v", this.AggregatedSignatureOutGoingOperations)+",\n") s = append(s, "LeaderSignatureOutGoingOperations: "+fmt.Sprintf("%#v", this.LeaderSignatureOutGoingOperations)+",\n") @@ -327,9 +322,9 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.OutGoingOperations != nil { + if m.OutGoingMiniBlockHeader != nil { { - size, err := m.OutGoingOperations.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.OutGoingMiniBlockHeader.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -370,7 +365,7 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *OutGoingOperations) Marshal() (dAtA []byte, err error) { +func (m *OutGoingMiniBlockHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -380,12 +375,12 @@ func (m *OutGoingOperations) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *OutGoingOperations) MarshalTo(dAtA []byte) (int, error) { +func (m *OutGoingMiniBlockHeader) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *OutGoingOperations) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *OutGoingMiniBlockHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -411,14 +406,12 @@ func (m *OutGoingOperations) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.OutGoingOperationHashes) > 0 { - for iNdEx := len(m.OutGoingOperationHashes) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.OutGoingOperationHashes[iNdEx]) - copy(dAtA[i:], m.OutGoingOperationHashes[iNdEx]) - i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.OutGoingOperationHashes[iNdEx]))) - i-- - dAtA[i] = 0xa - } + if len(m.Hash) > 0 { + i -= len(m.Hash) + copy(dAtA[i:], m.Hash) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.Hash))) + i-- + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -454,24 +447,22 @@ func (m *SovereignChainHeader) Size() (n int) { n += 1 + l + sovSovereignChainHeader(uint64(l)) } } - if m.OutGoingOperations != nil { - l = m.OutGoingOperations.Size() + if m.OutGoingMiniBlockHeader != nil { + l = m.OutGoingMiniBlockHeader.Size() n += 1 + l + sovSovereignChainHeader(uint64(l)) } return n } -func (m *OutGoingOperations) Size() (n int) { +func (m *OutGoingMiniBlockHeader) Size() (n int) { if m == nil { return 0 } var l int _ = l - if len(m.OutGoingOperationHashes) > 0 { - for _, b := range m.OutGoingOperationHashes { - l = len(b) - n += 1 + l + sovSovereignChainHeader(uint64(l)) - } + l = len(m.Hash) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) } l = len(m.OutGoingOperationsHash) if l > 0 { @@ -502,17 +493,17 @@ func (this *SovereignChainHeader) String() string { `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, - `OutGoingOperations:` + strings.Replace(this.OutGoingOperations.String(), "OutGoingOperations", "OutGoingOperations", 1) + `,`, + `OutGoingMiniBlockHeader:` + strings.Replace(this.OutGoingMiniBlockHeader.String(), "OutGoingMiniBlockHeader", "OutGoingMiniBlockHeader", 1) + `,`, `}`, }, "") return s } -func (this *OutGoingOperations) String() string { +func (this *OutGoingMiniBlockHeader) String() string { if this == nil { return "nil" } - s := strings.Join([]string{`&OutGoingOperations{`, - `OutGoingOperationHashes:` + fmt.Sprintf("%v", this.OutGoingOperationHashes) + `,`, + s := strings.Join([]string{`&OutGoingMiniBlockHeader{`, + `Hash:` + fmt.Sprintf("%v", this.Hash) + `,`, `OutGoingOperationsHash:` + fmt.Sprintf("%v", this.OutGoingOperationsHash) + `,`, `AggregatedSignatureOutGoingOperations:` + fmt.Sprintf("%v", this.AggregatedSignatureOutGoingOperations) + `,`, `LeaderSignatureOutGoingOperations:` + fmt.Sprintf("%v", this.LeaderSignatureOutGoingOperations) + `,`, @@ -661,7 +652,7 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OutGoingOperations", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field OutGoingMiniBlockHeader", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -688,10 +679,10 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.OutGoingOperations == nil { - m.OutGoingOperations = &OutGoingOperations{} + if m.OutGoingMiniBlockHeader == nil { + m.OutGoingMiniBlockHeader = &OutGoingMiniBlockHeader{} } - if err := m.OutGoingOperations.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.OutGoingMiniBlockHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -719,7 +710,7 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { } return nil } -func (m *OutGoingOperations) Unmarshal(dAtA []byte) error { +func (m *OutGoingMiniBlockHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -742,15 +733,15 @@ func (m *OutGoingOperations) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OutGoingOperations: wiretype end group for non-group") + return fmt.Errorf("proto: OutGoingMiniBlockHeader: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OutGoingOperations: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: OutGoingMiniBlockHeader: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OutGoingOperationHashes", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -777,8 +768,10 @@ func (m *OutGoingOperations) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.OutGoingOperationHashes = append(m.OutGoingOperationHashes, make([]byte, postIndex-iNdEx)) - copy(m.OutGoingOperationHashes[len(m.OutGoingOperationHashes)-1], dAtA[iNdEx:postIndex]) + m.Hash = append(m.Hash[:0], dAtA[iNdEx:postIndex]...) + if m.Hash == nil { + m.Hash = []byte{} + } iNdEx = postIndex case 2: if wireType != 2 { diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index 60a4d6df6..bdda296a5 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -11,15 +11,15 @@ import "block.proto"; // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain message SovereignChainHeader { - Header Header = 1 [(gogoproto.jsontag) = "header"]; - bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; - repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; - OutGoingOperations OutGoingOperations = 4 [(gogoproto.jsontag) = "outGoingOperations,omitempty"]; + Header Header = 1 [(gogoproto.jsontag) = "header"]; + bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; + repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; + OutGoingMiniBlockHeader OutGoingMiniBlockHeader = 4 [(gogoproto.jsontag) = "outGoingOperations,omitempty"]; } -message OutGoingOperations { - repeated bytes OutGoingOperationHashes = 1 [(gogoproto.jsontag) = "outGoingOperationHashes,omitempty"]; - bytes OutGoingOperationsHash = 2 [(gogoproto.jsontag) = "outGoingOperationsHash,omitempty"]; - bytes AggregatedSignatureOutGoingOperations = 3 [(gogoproto.jsontag) = "aggregatedSignatureOutGoingOperations,omitempty"]; - bytes LeaderSignatureOutGoingOperations = 4 [(gogoproto.jsontag) = "leaderSignatureOutGoingOperations,omitempty"]; +message OutGoingMiniBlockHeader { + bytes Hash = 1 [(gogoproto.jsontag) = "hash,omitempty"]; + bytes OutGoingOperationsHash = 2 [(gogoproto.jsontag) = "outGoingOperationsHash,omitempty"]; + bytes AggregatedSignatureOutGoingOperations = 3 [(gogoproto.jsontag) = "aggregatedSignatureOutGoingOperations,omitempty"]; + bytes LeaderSignatureOutGoingOperations = 4 [(gogoproto.jsontag) = "leaderSignatureOutGoingOperations,omitempty"]; } diff --git a/data/interface.go b/data/interface.go index 81c7b2638..ee573e621 100644 --- a/data/interface.go +++ b/data/interface.go @@ -93,14 +93,23 @@ type SovereignChainHeaderHandler interface { GetValidatorStatsRootHash() []byte SetExtendedShardHeaderHashes(hdrHashes [][]byte) error GetExtendedShardHeaderHashes() [][]byte - SetOutGoingOperationHashes(hashes [][]byte) error - GetOutGoingOperationHashes() [][]byte - SetOutGoingOperationsHash(hash []byte) error + GetOutGoingMiniBlockHeaderHandler() OutGoingMiniBlockHeaderHandler + SetOutGoingMiniBlockHeaderHandler(mbHeader OutGoingMiniBlockHeaderHandler) error +} + +// OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header +type OutGoingMiniBlockHeaderHandler interface { + GetHash() []byte GetOutGoingOperationsHash() []byte - SetAggregatedSignatureOutGoingOperations(signature []byte) error GetAggregatedSignatureOutGoingOperations() []byte - SetLeaderSignatureOutGoingOperations(signature []byte) error GetLeaderSignatureOutGoingOperations() []byte + + SetHash(hash []byte) error + SetOutGoingOperationsHash(hash []byte) error + SetLeaderSignatureOutGoingOperations(sig []byte) error + SetAggregatedSignatureOutGoingOperations(sig []byte) error + + IsInterfaceNil() bool } // HeaderHandler defines getters and setters for header data holder From a9d1582833ac273cd72d480852f3ee956cdfa210 Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 3 Nov 2023 12:37:02 +0200 Subject: [PATCH 52/87] FIX: ShallowClone in SovereignChainHeader --- data/block/sovereignChainHeader.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 14f012d6e..dd0db4be6 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -36,9 +36,7 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { return nil } - internalHeaderCopy := *sch.Header headerCopy := *sch - headerCopy.Header = &internalHeaderCopy return &headerCopy } From 932bc4ef8e7135404facfa01a59785eb798184f9 Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 3 Nov 2023 12:41:18 +0200 Subject: [PATCH 53/87] FIX: ShallowClone in SovereignChainHeader --- data/block/sovereignChainHeader.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index dd0db4be6..63f707246 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -36,7 +36,12 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { return nil } + internalHeaderCopy := *sch.Header + internalOutGoingMbHeader := *sch.OutGoingMiniBlockHeader + headerCopy := *sch + headerCopy.Header = &internalHeaderCopy + headerCopy.OutGoingMiniBlockHeader = &internalOutGoingMbHeader return &headerCopy } From 4f4d7bc1f9dc56cbc6a417b1c6b6fb24d622deae Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 3 Nov 2023 12:45:25 +0200 Subject: [PATCH 54/87] FIX: ShallowClone in SovereignChainHeader --- data/block/sovereignChainHeader.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 63f707246..abd532cf5 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -37,11 +37,14 @@ func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { } internalHeaderCopy := *sch.Header - internalOutGoingMbHeader := *sch.OutGoingMiniBlockHeader headerCopy := *sch headerCopy.Header = &internalHeaderCopy - headerCopy.OutGoingMiniBlockHeader = &internalOutGoingMbHeader + + if !check.IfNil(sch.OutGoingMiniBlockHeader) { + internalOutGoingMbHeader := *sch.OutGoingMiniBlockHeader + headerCopy.OutGoingMiniBlockHeader = &internalOutGoingMbHeader + } return &headerCopy } From 72ed6990c43cb326b454245e3f44fbb08e02fc05 Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 21 Nov 2023 14:57:00 +0200 Subject: [PATCH 55/87] FEAT: Outgoing bridge operations proto --- data/sovereign/outGoingBridgeData.go | 2 + data/sovereign/outGoingBridgeData.pb.go | 181 +++++++++++++++++++ data/sovereign/outGoingBridgeData.proto | 21 +++ data/sovereign/outGoingBridgeData_grpc.pb.go | 105 +++++++++++ go.mod | 12 +- go.sum | 26 ++- 6 files changed, 334 insertions(+), 13 deletions(-) create mode 100644 data/sovereign/outGoingBridgeData.go create mode 100644 data/sovereign/outGoingBridgeData.pb.go create mode 100644 data/sovereign/outGoingBridgeData.proto create mode 100644 data/sovereign/outGoingBridgeData_grpc.pb.go diff --git a/data/sovereign/outGoingBridgeData.go b/data/sovereign/outGoingBridgeData.go new file mode 100644 index 000000000..82e6be312 --- /dev/null +++ b/data/sovereign/outGoingBridgeData.go @@ -0,0 +1,2 @@ +//go:generate protoc -I=. --go_out=$GOPATH/src --go-grpc_out=$GOPATH/src outGoingBridgeData.proto +package sovereign diff --git a/data/sovereign/outGoingBridgeData.pb.go b/data/sovereign/outGoingBridgeData.pb.go new file mode 100644 index 000000000..90a7eed86 --- /dev/null +++ b/data/sovereign/outGoingBridgeData.pb.go @@ -0,0 +1,181 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: outGoingBridgeData.proto + +package sovereign + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type BridgeOperations struct { + Data []*BridgeOutGoingData `protobuf:"bytes,1,rep,name=Data,proto3" json:"Data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BridgeOperations) Reset() { *m = BridgeOperations{} } +func (m *BridgeOperations) String() string { return proto.CompactTextString(m) } +func (*BridgeOperations) ProtoMessage() {} +func (*BridgeOperations) Descriptor() ([]byte, []int) { + return fileDescriptor_62fb23e431426efc, []int{0} +} + +func (m *BridgeOperations) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BridgeOperations.Unmarshal(m, b) +} +func (m *BridgeOperations) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BridgeOperations.Marshal(b, m, deterministic) +} +func (m *BridgeOperations) XXX_Merge(src proto.Message) { + xxx_messageInfo_BridgeOperations.Merge(m, src) +} +func (m *BridgeOperations) XXX_Size() int { + return xxx_messageInfo_BridgeOperations.Size(m) +} +func (m *BridgeOperations) XXX_DiscardUnknown() { + xxx_messageInfo_BridgeOperations.DiscardUnknown(m) +} + +var xxx_messageInfo_BridgeOperations proto.InternalMessageInfo + +func (m *BridgeOperations) GetData() []*BridgeOutGoingData { + if m != nil { + return m.Data + } + return nil +} + +type BridgeOutGoingData struct { + Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"Hash,omitempty"` + OutGoingOperations map[string][]byte `protobuf:"bytes,2,rep,name=OutGoingOperations,proto3" json:"OutGoingOperations,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BridgeOutGoingData) Reset() { *m = BridgeOutGoingData{} } +func (m *BridgeOutGoingData) String() string { return proto.CompactTextString(m) } +func (*BridgeOutGoingData) ProtoMessage() {} +func (*BridgeOutGoingData) Descriptor() ([]byte, []int) { + return fileDescriptor_62fb23e431426efc, []int{1} +} + +func (m *BridgeOutGoingData) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BridgeOutGoingData.Unmarshal(m, b) +} +func (m *BridgeOutGoingData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BridgeOutGoingData.Marshal(b, m, deterministic) +} +func (m *BridgeOutGoingData) XXX_Merge(src proto.Message) { + xxx_messageInfo_BridgeOutGoingData.Merge(m, src) +} +func (m *BridgeOutGoingData) XXX_Size() int { + return xxx_messageInfo_BridgeOutGoingData.Size(m) +} +func (m *BridgeOutGoingData) XXX_DiscardUnknown() { + xxx_messageInfo_BridgeOutGoingData.DiscardUnknown(m) +} + +var xxx_messageInfo_BridgeOutGoingData proto.InternalMessageInfo + +func (m *BridgeOutGoingData) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func (m *BridgeOutGoingData) GetOutGoingOperations() map[string][]byte { + if m != nil { + return m.OutGoingOperations + } + return nil +} + +type BridgeOperationsResponse struct { + TxHashes [][]byte `protobuf:"bytes,1,rep,name=TxHashes,proto3" json:"TxHashes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BridgeOperationsResponse) Reset() { *m = BridgeOperationsResponse{} } +func (m *BridgeOperationsResponse) String() string { return proto.CompactTextString(m) } +func (*BridgeOperationsResponse) ProtoMessage() {} +func (*BridgeOperationsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_62fb23e431426efc, []int{2} +} + +func (m *BridgeOperationsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BridgeOperationsResponse.Unmarshal(m, b) +} +func (m *BridgeOperationsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BridgeOperationsResponse.Marshal(b, m, deterministic) +} +func (m *BridgeOperationsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BridgeOperationsResponse.Merge(m, src) +} +func (m *BridgeOperationsResponse) XXX_Size() int { + return xxx_messageInfo_BridgeOperationsResponse.Size(m) +} +func (m *BridgeOperationsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BridgeOperationsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BridgeOperationsResponse proto.InternalMessageInfo + +func (m *BridgeOperationsResponse) GetTxHashes() [][]byte { + if m != nil { + return m.TxHashes + } + return nil +} + +func init() { + proto.RegisterType((*BridgeOperations)(nil), "sovereign.BridgeOperations") + proto.RegisterType((*BridgeOutGoingData)(nil), "sovereign.BridgeOutGoingData") + proto.RegisterMapType((map[string][]byte)(nil), "sovereign.BridgeOutGoingData.OutGoingOperationsEntry") + proto.RegisterType((*BridgeOperationsResponse)(nil), "sovereign.BridgeOperationsResponse") +} + +func init() { + proto.RegisterFile("outGoingBridgeData.proto", fileDescriptor_62fb23e431426efc) +} + +var fileDescriptor_62fb23e431426efc = []byte{ + // 307 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xd1, 0x4b, 0x02, 0x41, + 0x10, 0xc6, 0x3b, 0xb5, 0xc8, 0x49, 0x42, 0x86, 0xa0, 0xc5, 0x08, 0xe4, 0x7a, 0xf1, 0xc5, 0x3b, + 0x32, 0x8a, 0xa8, 0x87, 0x48, 0x92, 0xa2, 0x97, 0x60, 0xf3, 0x29, 0x7a, 0x59, 0x75, 0x38, 0x97, + 0x74, 0x57, 0x76, 0xf7, 0xe4, 0xfc, 0x47, 0xfb, 0x7b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 0x9b, + 0xd4, 0x17, 0x3b, 0x8a, 0x6b, 0xdf, 0x70, 0xaf, 0xfb, 0xf8, 0xf1, 0x90, 0x48, 0x37, 0x4e, 0x07, + 0xd1, 0x50, 0x4f, 0xe3, 0x69, 0x3a, 0x71, 0x72, 0x4e, 0xc6, 0x66, 0xf1, 0x34, 0x6b, 0x0f, 0xc7, + 0x42, 0xaa, 0xf6, 0x50, 0x1b, 0x6a, 0x27, 0x3a, 0x1e, 0x09, 0x27, 0xe2, 0x62, 0xe6, 0x7d, 0xa1, + 0x06, 0x07, 0xfe, 0x2b, 0x5c, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x4d, 0x78, 0xca, 0xd6, 0x26, + 0x02, 0x00, 0x00, +} diff --git a/data/sovereign/outGoingBridgeData.proto b/data/sovereign/outGoingBridgeData.proto new file mode 100644 index 000000000..434d54189 --- /dev/null +++ b/data/sovereign/outGoingBridgeData.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package sovereign; +option go_package = "github.com/multiversx/mx-chain-core-go/data/sovereign;sovereign"; + +message BridgeOperations { + repeated BridgeOutGoingData Data = 1; +} + +message BridgeOutGoingData { + bytes Hash = 1; + map OutGoingOperations = 2; +} + +message BridgeOperationsResponse { + repeated bytes TxHashes = 1; +} + +service BridgeTxSender { + rpc Send(BridgeOperations) returns (BridgeOperationsResponse) {} +} diff --git a/data/sovereign/outGoingBridgeData_grpc.pb.go b/data/sovereign/outGoingBridgeData_grpc.pb.go new file mode 100644 index 000000000..b4a53d819 --- /dev/null +++ b/data/sovereign/outGoingBridgeData_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.12.4 +// source: outGoingBridgeData.proto + +package sovereign + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// BridgeTxSenderClient is the client API for BridgeTxSender service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BridgeTxSenderClient interface { + Send(ctx context.Context, in *BridgeOperations, opts ...grpc.CallOption) (*BridgeOperationsResponse, error) +} + +type bridgeTxSenderClient struct { + cc grpc.ClientConnInterface +} + +func NewBridgeTxSenderClient(cc grpc.ClientConnInterface) BridgeTxSenderClient { + return &bridgeTxSenderClient{cc} +} + +func (c *bridgeTxSenderClient) Send(ctx context.Context, in *BridgeOperations, opts ...grpc.CallOption) (*BridgeOperationsResponse, error) { + out := new(BridgeOperationsResponse) + err := c.cc.Invoke(ctx, "/sovereign.BridgeTxSender/Send", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BridgeTxSenderServer is the server API for BridgeTxSender service. +// All implementations must embed UnimplementedBridgeTxSenderServer +// for forward compatibility +type BridgeTxSenderServer interface { + Send(context.Context, *BridgeOperations) (*BridgeOperationsResponse, error) + mustEmbedUnimplementedBridgeTxSenderServer() +} + +// UnimplementedBridgeTxSenderServer must be embedded to have forward compatible implementations. +type UnimplementedBridgeTxSenderServer struct { +} + +func (UnimplementedBridgeTxSenderServer) Send(context.Context, *BridgeOperations) (*BridgeOperationsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Send not implemented") +} +func (UnimplementedBridgeTxSenderServer) mustEmbedUnimplementedBridgeTxSenderServer() {} + +// UnsafeBridgeTxSenderServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BridgeTxSenderServer will +// result in compilation errors. +type UnsafeBridgeTxSenderServer interface { + mustEmbedUnimplementedBridgeTxSenderServer() +} + +func RegisterBridgeTxSenderServer(s grpc.ServiceRegistrar, srv BridgeTxSenderServer) { + s.RegisterService(&BridgeTxSender_ServiceDesc, srv) +} + +func _BridgeTxSender_Send_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BridgeOperations) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BridgeTxSenderServer).Send(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sovereign.BridgeTxSender/Send", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BridgeTxSenderServer).Send(ctx, req.(*BridgeOperations)) + } + return interceptor(ctx, in, info, handler) +} + +// BridgeTxSender_ServiceDesc is the grpc.ServiceDesc for BridgeTxSender service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BridgeTxSender_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "sovereign.BridgeTxSender", + HandlerType: (*BridgeTxSenderServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Send", + Handler: _BridgeTxSender_Send_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "outGoingBridgeData.proto", +} diff --git a/go.mod b/go.mod index 3dc52a614..f855ea492 100644 --- a/go.mod +++ b/go.mod @@ -6,20 +6,24 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.3 github.com/denisbrodbeck/machineid v1.0.1 github.com/gogo/protobuf v1.3.2 - github.com/golang/protobuf v1.5.2 + github.com/golang/protobuf v1.5.3 github.com/hashicorp/golang-lru v0.5.4 github.com/mr-tron/base58 v1.2.0 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.0 - golang.org/x/crypto v0.3.0 + golang.org/x/crypto v0.12.0 + google.golang.org/grpc v1.59.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.2.0 // indirect - google.golang.org/protobuf v1.26.0 // indirect + golang.org/x/net v0.14.0 // indirect + golang.org/x/sys v0.11.0 // indirect + golang.org/x/text v0.12.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) diff --git a/go.sum b/go.sum index c8ab99700..3c4712706 100644 --- a/go.sum +++ b/go.sum @@ -38,14 +38,14 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -81,13 +81,15 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45 golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -98,16 +100,21 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -115,8 +122,9 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= From a96f40ee125681a0b0fe3c44e98894280d8d2993 Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 27 Nov 2023 17:12:00 +0200 Subject: [PATCH 56/87] FEAT: Add aggregated and leader signature --- data/sovereign/outGoingBridgeData.pb.go | 60 ++++++++++++++++--------- data/sovereign/outGoingBridgeData.proto | 4 +- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/data/sovereign/outGoingBridgeData.pb.go b/data/sovereign/outGoingBridgeData.pb.go index 90a7eed86..9bc15fa20 100644 --- a/data/sovereign/outGoingBridgeData.pb.go +++ b/data/sovereign/outGoingBridgeData.pb.go @@ -62,6 +62,8 @@ func (m *BridgeOperations) GetData() []*BridgeOutGoingData { type BridgeOutGoingData struct { Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"Hash,omitempty"` OutGoingOperations map[string][]byte `protobuf:"bytes,2,rep,name=OutGoingOperations,proto3" json:"OutGoingOperations,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + AggregatedSignature []byte `protobuf:"bytes,3,opt,name=AggregatedSignature,proto3" json:"AggregatedSignature,omitempty"` + LeaderSignature []byte `protobuf:"bytes,4,opt,name=LeaderSignature,proto3" json:"LeaderSignature,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -106,6 +108,20 @@ func (m *BridgeOutGoingData) GetOutGoingOperations() map[string][]byte { return nil } +func (m *BridgeOutGoingData) GetAggregatedSignature() []byte { + if m != nil { + return m.AggregatedSignature + } + return nil +} + +func (m *BridgeOutGoingData) GetLeaderSignature() []byte { + if m != nil { + return m.LeaderSignature + } + return nil +} + type BridgeOperationsResponse struct { TxHashes [][]byte `protobuf:"bytes,1,rep,name=TxHashes,proto3" json:"TxHashes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -157,25 +173,27 @@ func init() { } var fileDescriptor_62fb23e431426efc = []byte{ - // 307 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xd1, 0x4b, 0x02, 0x41, - 0x10, 0xc6, 0x3b, 0xb5, 0xc8, 0x49, 0x42, 0x86, 0xa0, 0xc5, 0x08, 0xe4, 0x7a, 0xf1, 0xc5, 0x3b, - 0x32, 0x8a, 0xa8, 0x87, 0x48, 0x92, 0xa2, 0x97, 0x60, 0xf3, 0x29, 0x7a, 0x59, 0x75, 0x38, 0x97, - 0x74, 0x57, 0x76, 0xf7, 0xe4, 0xfc, 0x47, 0xfb, 0x7b, 0xe2, 0x56, 0x3d, 0x21, 0xcb, 0xb7, 0x6f, - 0x99, 0xdf, 0xcc, 0xf7, 0xcd, 0xb0, 0xc0, 0x74, 0xea, 0x9e, 0xb5, 0x54, 0x49, 0xd7, 0xc8, 0x51, - 0x42, 0x4f, 0xc2, 0x89, 0x68, 0x66, 0xb4, 0xd3, 0x58, 0xb5, 0x7a, 0x4e, 0x86, 0x64, 0xa2, 0xc2, - 0x1e, 0xd4, 0x97, 0xe5, 0xb7, 0x19, 0x19, 0xe1, 0xa4, 0x56, 0x16, 0x2f, 0xa1, 0x92, 0xc3, 0x2c, - 0x68, 0x96, 0x5b, 0x47, 0x9d, 0xf3, 0xa8, 0xa0, 0xa3, 0x15, 0xba, 0x9a, 0x9b, 0x43, 0xdc, 0xa3, - 0xe1, 0x77, 0x00, 0xb8, 0x5d, 0x44, 0x84, 0xca, 0x8b, 0xb0, 0x63, 0x16, 0x34, 0x83, 0x56, 0x8d, - 0x7b, 0x8d, 0x04, 0xb8, 0x66, 0x36, 0x9e, 0xac, 0xe4, 0xbd, 0xae, 0x77, 0x7a, 0x45, 0xdb, 0x7d, - 0x3d, 0xe5, 0xcc, 0x82, 0xff, 0x31, 0xb0, 0xd1, 0x83, 0xd3, 0x7f, 0x70, 0xac, 0x43, 0xf9, 0x8b, - 0x16, 0x3e, 0x54, 0x95, 0xe7, 0x12, 0x4f, 0x60, 0x7f, 0x2e, 0x26, 0x29, 0xb1, 0x92, 0x0f, 0xba, - 0x7c, 0xdc, 0x95, 0x6e, 0x83, 0xf0, 0x06, 0xd8, 0xef, 0xfb, 0x70, 0xb2, 0x33, 0xad, 0x2c, 0x61, - 0x03, 0x0e, 0xfb, 0x59, 0xbe, 0x13, 0x59, 0x7f, 0xab, 0x1a, 0x2f, 0xde, 0x9d, 0x4f, 0x38, 0x5e, - 0xf6, 0xf5, 0xb3, 0x77, 0x52, 0x23, 0x32, 0xf8, 0x0a, 0x95, 0x5c, 0xe1, 0xd9, 0xf6, 0x8e, 0x9b, - 0xd4, 0x17, 0x3b, 0x8a, 0x6b, 0xdf, 0x70, 0xaf, 0xfb, 0xf8, 0xf1, 0x90, 0x48, 0x37, 0x4e, 0x07, - 0xd1, 0x50, 0x4f, 0xe3, 0x69, 0x3a, 0x71, 0x72, 0x4e, 0xc6, 0x66, 0xf1, 0x34, 0x6b, 0x0f, 0xc7, - 0x42, 0xaa, 0xf6, 0x50, 0x1b, 0x6a, 0x27, 0x3a, 0x1e, 0x09, 0x27, 0xe2, 0x62, 0xe6, 0x7d, 0xa1, - 0x06, 0x07, 0xfe, 0x2b, 0x5c, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x4d, 0x78, 0xca, 0xd6, 0x26, - 0x02, 0x00, 0x00, + // 347 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xd1, 0x4b, 0x2a, 0x41, + 0x14, 0xc6, 0xef, 0xae, 0x7b, 0x2f, 0xd7, 0x93, 0x94, 0x4c, 0x41, 0x8b, 0x11, 0xc8, 0xf6, 0xe2, + 0x8b, 0xbb, 0x65, 0x14, 0x51, 0x0f, 0xa1, 0x24, 0x45, 0x04, 0xc1, 0xea, 0x53, 0xf4, 0x32, 0xba, + 0x87, 0x71, 0x48, 0x67, 0x64, 0x66, 0x56, 0xd6, 0x7f, 0xab, 0xbf, 0x30, 0x76, 0xd4, 0x15, 0xd4, + 0x7c, 0xfb, 0x66, 0xbf, 0xdf, 0x7c, 0xdf, 0xd9, 0xb3, 0x0b, 0xbe, 0x4c, 0xcd, 0xb3, 0xe4, 0x82, + 0x75, 0x14, 0x4f, 0x18, 0x3e, 0x51, 0x43, 0xc3, 0xa9, 0x92, 0x46, 0x92, 0xb2, 0x96, 0x33, 0x54, + 0xc8, 0x99, 0x08, 0xba, 0x50, 0x5d, 0xd8, 0xef, 0x53, 0x54, 0xd4, 0x70, 0x29, 0x34, 0xb9, 0x02, + 0x2f, 0x87, 0x7d, 0xa7, 0x5e, 0x6a, 0x1c, 0xb4, 0xce, 0xc3, 0x82, 0x0e, 0x97, 0xe8, 0x32, 0x37, + 0x87, 0x62, 0x8b, 0x06, 0xdf, 0x2e, 0x90, 0x6d, 0x93, 0x10, 0xf0, 0x5e, 0xa8, 0x1e, 0xf9, 0x4e, + 0xdd, 0x69, 0x54, 0x62, 0xab, 0x09, 0x02, 0x59, 0x31, 0xeb, 0x4e, 0xdf, 0xb5, 0x5d, 0x37, 0x7b, + 0xbb, 0xc2, 0xed, 0x7b, 0x5d, 0x61, 0xd4, 0x3c, 0xde, 0x11, 0x48, 0x2e, 0xe1, 0xb8, 0xcd, 0x98, + 0x42, 0x46, 0x0d, 0x26, 0x3d, 0xce, 0x04, 0x35, 0xa9, 0x42, 0xbf, 0x64, 0x27, 0xd9, 0x65, 0x91, + 0x06, 0x1c, 0xbd, 0x21, 0x4d, 0x50, 0xad, 0x69, 0xcf, 0xd2, 0x9b, 0x8f, 0x6b, 0x5d, 0x38, 0xfd, + 0x65, 0x14, 0x52, 0x85, 0xd2, 0x17, 0xce, 0xed, 0x0b, 0x97, 0xe3, 0x5c, 0x92, 0x13, 0xf8, 0x3b, + 0xa3, 0xe3, 0x14, 0x7d, 0xd7, 0x86, 0x2d, 0x0e, 0xf7, 0xee, 0x9d, 0x13, 0xdc, 0x82, 0xbf, 0xb9, + 0xfb, 0x18, 0xf5, 0x54, 0x0a, 0x8d, 0xa4, 0x06, 0xff, 0xfb, 0x59, 0xbe, 0x2f, 0xd4, 0xf6, 0x3b, + 0x54, 0xe2, 0xe2, 0xdc, 0xfa, 0x84, 0xc3, 0xc5, 0xbd, 0x7e, 0xd6, 0x43, 0x91, 0xa0, 0x22, 0xaf, + 0xe0, 0xe5, 0x8a, 0x9c, 0x6d, 0xef, 0xaf, 0x88, 0xae, 0x5d, 0xec, 0x31, 0x57, 0xbd, 0xc1, 0x9f, + 0x4e, 0xfb, 0xe3, 0x91, 0x71, 0x33, 0x4a, 0x07, 0xe1, 0x50, 0x4e, 0xa2, 0x49, 0x3a, 0x36, 0x7c, + 0x86, 0x4a, 0x67, 0xd1, 0x24, 0x6b, 0x0e, 0x47, 0x94, 0x8b, 0xe6, 0x50, 0x2a, 0x6c, 0x32, 0x19, + 0x25, 0xd4, 0xd0, 0xa8, 0xc8, 0x7c, 0x28, 0xd4, 0xe0, 0x9f, 0xfd, 0xcd, 0xae, 0x7f, 0x02, 0x00, + 0x00, 0xff, 0xff, 0x0f, 0xac, 0xf3, 0xaf, 0x82, 0x02, 0x00, 0x00, } diff --git a/data/sovereign/outGoingBridgeData.proto b/data/sovereign/outGoingBridgeData.proto index 434d54189..9dadce6b9 100644 --- a/data/sovereign/outGoingBridgeData.proto +++ b/data/sovereign/outGoingBridgeData.proto @@ -8,8 +8,10 @@ message BridgeOperations { } message BridgeOutGoingData { - bytes Hash = 1; + bytes Hash = 1; map OutGoingOperations = 2; + bytes AggregatedSignature = 3; + bytes LeaderSignature = 4; } message BridgeOperationsResponse { From d1195643463acb1837ebdedbc723cb837290a2da Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 28 Nov 2023 15:06:45 +0200 Subject: [PATCH 57/87] FEAT: Tx hashes response to string --- data/sovereign/outGoingBridgeData.pb.go | 50 ++++++++++++------------- data/sovereign/outGoingBridgeData.proto | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/data/sovereign/outGoingBridgeData.pb.go b/data/sovereign/outGoingBridgeData.pb.go index 9bc15fa20..8eb085d5c 100644 --- a/data/sovereign/outGoingBridgeData.pb.go +++ b/data/sovereign/outGoingBridgeData.pb.go @@ -123,7 +123,7 @@ func (m *BridgeOutGoingData) GetLeaderSignature() []byte { } type BridgeOperationsResponse struct { - TxHashes [][]byte `protobuf:"bytes,1,rep,name=TxHashes,proto3" json:"TxHashes,omitempty"` + TxHashes []string `protobuf:"bytes,1,rep,name=TxHashes,proto3" json:"TxHashes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -154,7 +154,7 @@ func (m *BridgeOperationsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_BridgeOperationsResponse proto.InternalMessageInfo -func (m *BridgeOperationsResponse) GetTxHashes() [][]byte { +func (m *BridgeOperationsResponse) GetTxHashes() []string { if m != nil { return m.TxHashes } @@ -173,27 +173,27 @@ func init() { } var fileDescriptor_62fb23e431426efc = []byte{ - // 347 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xd1, 0x4b, 0x2a, 0x41, - 0x14, 0xc6, 0xef, 0xae, 0x7b, 0x2f, 0xd7, 0x93, 0x94, 0x4c, 0x41, 0x8b, 0x11, 0xc8, 0xf6, 0xe2, - 0x8b, 0xbb, 0x65, 0x14, 0x51, 0x0f, 0xa1, 0x24, 0x45, 0x04, 0xc1, 0xea, 0x53, 0xf4, 0x32, 0xba, - 0x87, 0x71, 0x48, 0x67, 0x64, 0x66, 0x56, 0xd6, 0x7f, 0xab, 0xbf, 0x30, 0x76, 0xd4, 0x15, 0xd4, - 0x7c, 0xfb, 0x66, 0xbf, 0xdf, 0x7c, 0xdf, 0xd9, 0xb3, 0x0b, 0xbe, 0x4c, 0xcd, 0xb3, 0xe4, 0x82, - 0x75, 0x14, 0x4f, 0x18, 0x3e, 0x51, 0x43, 0xc3, 0xa9, 0x92, 0x46, 0x92, 0xb2, 0x96, 0x33, 0x54, - 0xc8, 0x99, 0x08, 0xba, 0x50, 0x5d, 0xd8, 0xef, 0x53, 0x54, 0xd4, 0x70, 0x29, 0x34, 0xb9, 0x02, - 0x2f, 0x87, 0x7d, 0xa7, 0x5e, 0x6a, 0x1c, 0xb4, 0xce, 0xc3, 0x82, 0x0e, 0x97, 0xe8, 0x32, 0x37, - 0x87, 0x62, 0x8b, 0x06, 0xdf, 0x2e, 0x90, 0x6d, 0x93, 0x10, 0xf0, 0x5e, 0xa8, 0x1e, 0xf9, 0x4e, - 0xdd, 0x69, 0x54, 0x62, 0xab, 0x09, 0x02, 0x59, 0x31, 0xeb, 0x4e, 0xdf, 0xb5, 0x5d, 0x37, 0x7b, - 0xbb, 0xc2, 0xed, 0x7b, 0x5d, 0x61, 0xd4, 0x3c, 0xde, 0x11, 0x48, 0x2e, 0xe1, 0xb8, 0xcd, 0x98, - 0x42, 0x46, 0x0d, 0x26, 0x3d, 0xce, 0x04, 0x35, 0xa9, 0x42, 0xbf, 0x64, 0x27, 0xd9, 0x65, 0x91, - 0x06, 0x1c, 0xbd, 0x21, 0x4d, 0x50, 0xad, 0x69, 0xcf, 0xd2, 0x9b, 0x8f, 0x6b, 0x5d, 0x38, 0xfd, - 0x65, 0x14, 0x52, 0x85, 0xd2, 0x17, 0xce, 0xed, 0x0b, 0x97, 0xe3, 0x5c, 0x92, 0x13, 0xf8, 0x3b, - 0xa3, 0xe3, 0x14, 0x7d, 0xd7, 0x86, 0x2d, 0x0e, 0xf7, 0xee, 0x9d, 0x13, 0xdc, 0x82, 0xbf, 0xb9, - 0xfb, 0x18, 0xf5, 0x54, 0x0a, 0x8d, 0xa4, 0x06, 0xff, 0xfb, 0x59, 0xbe, 0x2f, 0xd4, 0xf6, 0x3b, - 0x54, 0xe2, 0xe2, 0xdc, 0xfa, 0x84, 0xc3, 0xc5, 0xbd, 0x7e, 0xd6, 0x43, 0x91, 0xa0, 0x22, 0xaf, - 0xe0, 0xe5, 0x8a, 0x9c, 0x6d, 0xef, 0xaf, 0x88, 0xae, 0x5d, 0xec, 0x31, 0x57, 0xbd, 0xc1, 0x9f, - 0x4e, 0xfb, 0xe3, 0x91, 0x71, 0x33, 0x4a, 0x07, 0xe1, 0x50, 0x4e, 0xa2, 0x49, 0x3a, 0x36, 0x7c, - 0x86, 0x4a, 0x67, 0xd1, 0x24, 0x6b, 0x0e, 0x47, 0x94, 0x8b, 0xe6, 0x50, 0x2a, 0x6c, 0x32, 0x19, - 0x25, 0xd4, 0xd0, 0xa8, 0xc8, 0x7c, 0x28, 0xd4, 0xe0, 0x9f, 0xfd, 0xcd, 0xae, 0x7f, 0x02, 0x00, - 0x00, 0xff, 0xff, 0x0f, 0xac, 0xf3, 0xaf, 0x82, 0x02, 0x00, 0x00, + // 346 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x51, 0x4b, 0x3a, 0x41, + 0x14, 0xc5, 0xff, 0xbb, 0xee, 0x3f, 0xf2, 0x16, 0x25, 0x53, 0xd0, 0x62, 0x04, 0xb2, 0xbd, 0xf8, + 0xe2, 0x6e, 0x19, 0x45, 0xd4, 0x43, 0x28, 0x49, 0x11, 0x41, 0xb0, 0xfa, 0x14, 0xbd, 0x8c, 0xee, + 0x65, 0x1c, 0xd2, 0x19, 0x99, 0x99, 0x95, 0xf5, 0x6b, 0xf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 0xf7, + 0x31, 0xea, 0x89, 0x14, 0x1a, 0x49, 0x15, 0xf6, 0x7b, 0x59, 0xbe, 0x2f, 0xd4, 0xf6, 0x3b, 0x94, + 0xe3, 0xe2, 0xdc, 0xfc, 0x82, 0xa3, 0xf9, 0xbd, 0x5e, 0xd6, 0x45, 0x91, 0xa0, 0x22, 0x6f, 0xe0, + 0xe5, 0x8a, 0x9c, 0x6f, 0xee, 0xaf, 0x88, 0xae, 0x5e, 0xee, 0x30, 0x97, 0xbd, 0xc1, 0xbf, 0x76, + 0xeb, 0xf3, 0x89, 0x71, 0x33, 0x4c, 0xfb, 0xe1, 0x40, 0x8e, 0xa3, 0x71, 0x3a, 0x32, 0x7c, 0x8a, + 0x4a, 0x67, 0xd1, 0x38, 0x6b, 0x0c, 0x86, 0x94, 0x8b, 0xc6, 0x40, 0x2a, 0x6c, 0x30, 0x19, 0x25, + 0xd4, 0xd0, 0xa8, 0xc8, 0x7c, 0x2c, 0x54, 0x7f, 0xcf, 0xfe, 0x66, 0x37, 0xbf, 0x01, 0x00, 0x00, + 0xff, 0xff, 0xee, 0x92, 0x65, 0xbd, 0x82, 0x02, 0x00, 0x00, } diff --git a/data/sovereign/outGoingBridgeData.proto b/data/sovereign/outGoingBridgeData.proto index 9dadce6b9..f28d7c3ab 100644 --- a/data/sovereign/outGoingBridgeData.proto +++ b/data/sovereign/outGoingBridgeData.proto @@ -15,7 +15,7 @@ message BridgeOutGoingData { } message BridgeOperationsResponse { - repeated bytes TxHashes = 1; + repeated string TxHashes = 1; } service BridgeTxSender { From 9672e1a91430070267a3a810cf814c36df5818b6 Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 4 Dec 2023 14:04:55 +0200 Subject: [PATCH 58/87] FEAT: Replace map with slice of structs --- data/sovereign/outGoingBridgeData.pb.go | 111 +++++++++++++++++------- data/sovereign/outGoingBridgeData.proto | 7 +- 2 files changed, 84 insertions(+), 34 deletions(-) diff --git a/data/sovereign/outGoingBridgeData.pb.go b/data/sovereign/outGoingBridgeData.pb.go index 8eb085d5c..01a4fa321 100644 --- a/data/sovereign/outGoingBridgeData.pb.go +++ b/data/sovereign/outGoingBridgeData.pb.go @@ -60,13 +60,13 @@ func (m *BridgeOperations) GetData() []*BridgeOutGoingData { } type BridgeOutGoingData struct { - Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"Hash,omitempty"` - OutGoingOperations map[string][]byte `protobuf:"bytes,2,rep,name=OutGoingOperations,proto3" json:"OutGoingOperations,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - AggregatedSignature []byte `protobuf:"bytes,3,opt,name=AggregatedSignature,proto3" json:"AggregatedSignature,omitempty"` - LeaderSignature []byte `protobuf:"bytes,4,opt,name=LeaderSignature,proto3" json:"LeaderSignature,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"Hash,omitempty"` + OutGoingOperations []*OutGoingOperation `protobuf:"bytes,2,rep,name=OutGoingOperations,proto3" json:"OutGoingOperations,omitempty"` + AggregatedSignature []byte `protobuf:"bytes,3,opt,name=AggregatedSignature,proto3" json:"AggregatedSignature,omitempty"` + LeaderSignature []byte `protobuf:"bytes,4,opt,name=LeaderSignature,proto3" json:"LeaderSignature,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *BridgeOutGoingData) Reset() { *m = BridgeOutGoingData{} } @@ -101,7 +101,7 @@ func (m *BridgeOutGoingData) GetHash() []byte { return nil } -func (m *BridgeOutGoingData) GetOutGoingOperations() map[string][]byte { +func (m *BridgeOutGoingData) GetOutGoingOperations() []*OutGoingOperation { if m != nil { return m.OutGoingOperations } @@ -122,6 +122,53 @@ func (m *BridgeOutGoingData) GetLeaderSignature() []byte { return nil } +type OutGoingOperation struct { + Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"Hash,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=Data,proto3" json:"Data,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *OutGoingOperation) Reset() { *m = OutGoingOperation{} } +func (m *OutGoingOperation) String() string { return proto.CompactTextString(m) } +func (*OutGoingOperation) ProtoMessage() {} +func (*OutGoingOperation) Descriptor() ([]byte, []int) { + return fileDescriptor_62fb23e431426efc, []int{2} +} + +func (m *OutGoingOperation) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_OutGoingOperation.Unmarshal(m, b) +} +func (m *OutGoingOperation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_OutGoingOperation.Marshal(b, m, deterministic) +} +func (m *OutGoingOperation) XXX_Merge(src proto.Message) { + xxx_messageInfo_OutGoingOperation.Merge(m, src) +} +func (m *OutGoingOperation) XXX_Size() int { + return xxx_messageInfo_OutGoingOperation.Size(m) +} +func (m *OutGoingOperation) XXX_DiscardUnknown() { + xxx_messageInfo_OutGoingOperation.DiscardUnknown(m) +} + +var xxx_messageInfo_OutGoingOperation proto.InternalMessageInfo + +func (m *OutGoingOperation) GetHash() []byte { + if m != nil { + return m.Hash + } + return nil +} + +func (m *OutGoingOperation) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + type BridgeOperationsResponse struct { TxHashes []string `protobuf:"bytes,1,rep,name=TxHashes,proto3" json:"TxHashes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -133,7 +180,7 @@ func (m *BridgeOperationsResponse) Reset() { *m = BridgeOperationsRespon func (m *BridgeOperationsResponse) String() string { return proto.CompactTextString(m) } func (*BridgeOperationsResponse) ProtoMessage() {} func (*BridgeOperationsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_62fb23e431426efc, []int{2} + return fileDescriptor_62fb23e431426efc, []int{3} } func (m *BridgeOperationsResponse) XXX_Unmarshal(b []byte) error { @@ -164,7 +211,7 @@ func (m *BridgeOperationsResponse) GetTxHashes() []string { func init() { proto.RegisterType((*BridgeOperations)(nil), "sovereign.BridgeOperations") proto.RegisterType((*BridgeOutGoingData)(nil), "sovereign.BridgeOutGoingData") - proto.RegisterMapType((map[string][]byte)(nil), "sovereign.BridgeOutGoingData.OutGoingOperationsEntry") + proto.RegisterType((*OutGoingOperation)(nil), "sovereign.OutGoingOperation") proto.RegisterType((*BridgeOperationsResponse)(nil), "sovereign.BridgeOperationsResponse") } @@ -173,27 +220,25 @@ func init() { } var fileDescriptor_62fb23e431426efc = []byte{ - // 346 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x51, 0x4b, 0x3a, 0x41, - 0x14, 0xc5, 0xff, 0xbb, 0xee, 0x3f, 0xf2, 0x16, 0x25, 0x53, 0xd0, 0x62, 0x04, 0xb2, 0xbd, 0xf8, - 0xe2, 0x6e, 0x19, 0x45, 0xd4, 0x43, 0x28, 0x49, 0x11, 0x41, 0xb0, 0xfa, 0x14, 0xbd, 0x8c, 0xee, - 0x65, 0x1c, 0xd2, 0x19, 0x99, 0x99, 0x95, 0xf5, 0x6b, 0xf5, 0x09, 0x63, 0x47, 0x5d, 0x41, 0xcd, - 0xb7, 0x33, 0x7b, 0x7e, 0x73, 0xce, 0xdd, 0xbb, 0x0b, 0xbe, 0x4c, 0xcd, 0x8b, 0xe4, 0x82, 0xb5, - 0x15, 0x4f, 0x18, 0x3e, 0x53, 0x43, 0xc3, 0x89, 0x92, 0x46, 0x92, 0xb2, 0x96, 0x53, 0x54, 0xc8, - 0x99, 0x08, 0x3a, 0x50, 0x99, 0xdb, 0x1f, 0x13, 0x54, 0xd4, 0x70, 0x29, 0x34, 0xb9, 0x06, 0x2f, - 0x87, 0x7d, 0xa7, 0x56, 0xa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40, 0x8e, 0xa3, 0x71, 0x3a, 0x32, 0x7c, 0x8a, - 0x4a, 0x67, 0xd1, 0x38, 0x6b, 0x0c, 0x86, 0x94, 0x8b, 0xc6, 0x40, 0x2a, 0x6c, 0x30, 0x19, 0x25, - 0xd4, 0xd0, 0xa8, 0xc8, 0x7c, 0x2c, 0x54, 0x7f, 0xcf, 0xfe, 0x66, 0x37, 0xbf, 0x01, 0x00, 0x00, - 0xff, 0xff, 0xee, 0x92, 0x65, 0xbd, 0x82, 0x02, 0x00, 0x00, + // 320 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x4f, 0x4b, 0xc3, 0x40, + 0x10, 0xc5, 0x4d, 0x1b, 0xc4, 0x8e, 0xe2, 0x9f, 0xf1, 0x12, 0xaa, 0x42, 0x89, 0x97, 0x5e, 0x9a, + 0x68, 0x05, 0x2f, 0x3d, 0x48, 0x8b, 0xa2, 0x48, 0x41, 0x48, 0x7b, 0x12, 0x2f, 0xdb, 0x66, 0xd8, + 0x2e, 0xd8, 0xdd, 0xb2, 0xbb, 0x29, 0xf9, 0x9c, 0x7e, 0x22, 0xc9, 0xb6, 0x4d, 0xa5, 0x29, 0xde, + 0x66, 0xe7, 0xfd, 0x66, 0x1e, 0xfb, 0x76, 0x21, 0x50, 0x99, 0x7d, 0x55, 0x42, 0xf2, 0x81, 0x16, + 0x29, 0xa7, 0x67, 0x66, 0x59, 0xb4, 0xd0, 0xca, 0x2a, 0x6c, 0x18, 0xb5, 0x24, 0x4d, 0x82, 0xcb, + 0xf0, 0x05, 0xce, 0x57, 0xf2, 0xc7, 0x82, 0x34, 0xb3, 0x42, 0x49, 0x83, 0xf7, 0xe0, 0x17, 0x70, + 0xe0, 0xb5, 0xea, 0xed, 0xe3, 0xee, 0x4d, 0x54, 0xd2, 0xd1, 0x1a, 0x5d, 0xef, 0x2d, 0xa0, 0xc4, + 0xa1, 0xe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0xff, 0x55, 0xb2, 0xc7, 0x90, 0x5f, 0x02, 0x00, 0x00, } diff --git a/data/sovereign/outGoingBridgeData.proto b/data/sovereign/outGoingBridgeData.proto index f28d7c3ab..63a7b2726 100644 --- a/data/sovereign/outGoingBridgeData.proto +++ b/data/sovereign/outGoingBridgeData.proto @@ -9,11 +9,16 @@ message BridgeOperations { message BridgeOutGoingData { bytes Hash = 1; - map OutGoingOperations = 2; + repeated OutGoingOperation OutGoingOperations = 2; bytes AggregatedSignature = 3; bytes LeaderSignature = 4; } +message OutGoingOperation { + bytes Hash = 1; + bytes Data = 2; +} + message BridgeOperationsResponse { repeated string TxHashes = 1; } From 5d14fce4dfd7c09efd293a2f662157ae506e9215 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 18 Jan 2024 10:27:34 +0200 Subject: [PATCH 59/87] FIX: Go mod --- go.mod | 13 ++++++------- go.sum | 26 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index f855ea492..e90f990e6 100644 --- a/go.mod +++ b/go.mod @@ -7,22 +7,21 @@ require ( github.com/denisbrodbeck/machineid v1.0.1 github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.3 - github.com/hashicorp/golang-lru v0.5.4 github.com/mr-tron/base58 v1.2.0 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.0 - golang.org/x/crypto v0.12.0 - google.golang.org/grpc v1.59.0 + golang.org/x/crypto v0.14.0 + google.golang.org/grpc v1.60.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect + golang.org/x/net v0.16.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) diff --git a/go.sum b/go.sum index 1b4ae8775..839b1b7a4 100644 --- a/go.sum +++ b/go.sum @@ -38,14 +38,14 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -79,13 +79,15 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45 golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos= +golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -96,16 +98,21 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= +google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= +google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -113,8 +120,9 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= From 72a8c6770a580274767e65e296c1eab2e3ee3772 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 5 Mar 2024 16:13:06 +0200 Subject: [PATCH 60/87] event data and operation data structs --- data/sovereign/eventData.go | 12 +++++++++ data/sovereign/operationData.go | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 data/sovereign/eventData.go create mode 100644 data/sovereign/operationData.go diff --git a/data/sovereign/eventData.go b/data/sovereign/eventData.go new file mode 100644 index 000000000..94b80535f --- /dev/null +++ b/data/sovereign/eventData.go @@ -0,0 +1,12 @@ +package sovereign + +type TransferData struct { + GasLimit uint64 + Function []byte + Args [][]byte +} + +type EventData struct { + Nonce uint64 + *TransferData +} diff --git a/data/sovereign/operationData.go b/data/sovereign/operationData.go new file mode 100644 index 000000000..f16b2f745 --- /dev/null +++ b/data/sovereign/operationData.go @@ -0,0 +1,43 @@ +package sovereign + +import "math/big" + +type Operation struct { + Address []byte + Tokens []EsdtToken + TransferData *TransferData +} + +type EsdtTokenPayment struct { + TokenIdentifier []byte + Nonce uint64 + Amount *big.Int +} + +type EsdtToken struct { + Identifier []byte + Nonce uint64 + Data EsdtTokenData +} + +type EsdtTokenType uint32 + +const ( + Fungible EsdtTokenType = iota + NonFungible + SemiFungible + Meta + Invalid +) + +type EsdtTokenData struct { + TokenType EsdtTokenType + Amount *big.Int + Frozen bool + Hash []byte + Name []byte + Attributes []byte + Creator []byte + Royalties *big.Int + Uris [][]byte +} From 2aded24ca3739a241c4614d69c0d6f967945b840 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 6 Mar 2024 18:56:32 +0200 Subject: [PATCH 61/87] removed unnecessary struct --- data/sovereign/operationData.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/data/sovereign/operationData.go b/data/sovereign/operationData.go index f16b2f745..c3b0c5031 100644 --- a/data/sovereign/operationData.go +++ b/data/sovereign/operationData.go @@ -8,12 +8,6 @@ type Operation struct { TransferData *TransferData } -type EsdtTokenPayment struct { - TokenIdentifier []byte - Nonce uint64 - Amount *big.Int -} - type EsdtToken struct { Identifier []byte Nonce uint64 From 9e4b4a851b2d95e0c4eedd9be4e5f97ffe1fab6b Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 7 Mar 2024 09:31:43 +0200 Subject: [PATCH 62/87] comments for exported types --- data/sovereign/eventData.go | 2 ++ data/sovereign/operationData.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/data/sovereign/eventData.go b/data/sovereign/eventData.go index 94b80535f..c940c5573 100644 --- a/data/sovereign/eventData.go +++ b/data/sovereign/eventData.go @@ -1,11 +1,13 @@ package sovereign +// TransferData holds the required data for a transfer to smart contract type TransferData struct { GasLimit uint64 Function []byte Args [][]byte } +// EventData holds the full event data structure type EventData struct { Nonce uint64 *TransferData diff --git a/data/sovereign/operationData.go b/data/sovereign/operationData.go index c3b0c5031..f1f6bef41 100644 --- a/data/sovereign/operationData.go +++ b/data/sovereign/operationData.go @@ -2,18 +2,21 @@ package sovereign import "math/big" +// Operation holds the data needed for a bridge transfer type Operation struct { Address []byte Tokens []EsdtToken TransferData *TransferData } +// EsdtToken holds the token data type EsdtToken struct { Identifier []byte Nonce uint64 Data EsdtTokenData } +// EsdtTokenType holds the type of the esdt token type EsdtTokenType uint32 const ( @@ -24,6 +27,7 @@ const ( Invalid ) +// EsdtTokenData holds the properties for a token type EsdtTokenData struct { TokenType EsdtTokenType Amount *big.Int From 6e868d602411ccf7b3c11e745f3a1bf1ef25489c Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 7 Mar 2024 10:42:44 +0200 Subject: [PATCH 63/87] enum deleted because already exists --- data/sovereign/operationData.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/data/sovereign/operationData.go b/data/sovereign/operationData.go index f1f6bef41..826bc742a 100644 --- a/data/sovereign/operationData.go +++ b/data/sovereign/operationData.go @@ -1,6 +1,10 @@ package sovereign -import "math/big" +import ( + "math/big" + + "github.com/multiversx/mx-chain-core-go/core" +) // Operation holds the data needed for a bridge transfer type Operation struct { @@ -16,20 +20,9 @@ type EsdtToken struct { Data EsdtTokenData } -// EsdtTokenType holds the type of the esdt token -type EsdtTokenType uint32 - -const ( - Fungible EsdtTokenType = iota - NonFungible - SemiFungible - Meta - Invalid -) - // EsdtTokenData holds the properties for a token type EsdtTokenData struct { - TokenType EsdtTokenType + TokenType core.ESDTType Amount *big.Int Frozen bool Hash []byte From 18ad5f9b27a7302af4ecb356e70c6ef18cf5ca5d Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 7 Mar 2024 10:44:27 +0200 Subject: [PATCH 64/87] comm updated --- data/sovereign/operationData.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/sovereign/operationData.go b/data/sovereign/operationData.go index 826bc742a..da722a0bb 100644 --- a/data/sovereign/operationData.go +++ b/data/sovereign/operationData.go @@ -6,7 +6,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" ) -// Operation holds the data needed for a bridge transfer +// Operation holds the data needed for an outgoing operation type Operation struct { Address []byte Tokens []EsdtToken From 5c316c2d897dc09f807652024727b30f4aeafd59 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 12 Mar 2024 14:58:46 +0200 Subject: [PATCH 65/87] operation data containing the full event data --- data/sovereign/operationData.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/sovereign/operationData.go b/data/sovereign/operationData.go index da722a0bb..b62a8253e 100644 --- a/data/sovereign/operationData.go +++ b/data/sovereign/operationData.go @@ -8,9 +8,9 @@ import ( // Operation holds the data needed for an outgoing operation type Operation struct { - Address []byte - Tokens []EsdtToken - TransferData *TransferData + Address []byte + Tokens []EsdtToken + Data *EventData } // EsdtToken holds the token data From 1b566badb9fbbd4ce0e078edc39dad9fb8dbf573 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 14 Mar 2024 13:43:07 +0200 Subject: [PATCH 66/87] sender address in event data --- data/sovereign/eventData.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/sovereign/eventData.go b/data/sovereign/eventData.go index c940c5573..386cf8f3c 100644 --- a/data/sovereign/eventData.go +++ b/data/sovereign/eventData.go @@ -9,6 +9,7 @@ type TransferData struct { // EventData holds the full event data structure type EventData struct { - Nonce uint64 + Nonce uint64 + Sender []byte *TransferData } From e35934ff1bb9743bb0e49a28bbe76279ebe7e4eb Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 25 Mar 2024 14:41:22 +0200 Subject: [PATCH 67/87] FEAT: Add SetBlockBodyTypeInt32 in sov chain hdr --- data/block/sovereignChainHeader.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index abd532cf5..b24d5231b 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -574,6 +574,15 @@ func (sch *SovereignChainHeader) SetOutGoingMiniBlockHeaderHandler(mbHeader data return nil } +// SetBlockBodyTypeInt32 sets the blockBodyType in the header +func (sch *SovereignChainHeader) SetBlockBodyTypeInt32(blockBodyType int32) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return sch.Header.SetBlockBodyTypeInt32(blockBodyType) +} + // SetHash returns the hash func (omb *OutGoingMiniBlockHeader) SetHash(hash []byte) error { if omb == nil { From 4fced051a598dfd88e0b2cb7228fca8d307c4881 Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 25 Mar 2024 14:54:42 +0200 Subject: [PATCH 68/87] FEAT: Add SetBlockBodyTypeInt32 in extended hdr --- data/block/shardHeaderExtended.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/data/block/shardHeaderExtended.go b/data/block/shardHeaderExtended.go index ed69b8ac2..6664aa451 100644 --- a/data/block/shardHeaderExtended.go +++ b/data/block/shardHeaderExtended.go @@ -914,3 +914,12 @@ func (she *ShardHeaderExtended) GetHeaderHandler() data.HeaderHandler { return she.GetHeader() } + +// SetBlockBodyTypeInt32 sets the blockBodyType in the header +func (she *ShardHeaderExtended) SetBlockBodyTypeInt32(blockBodyType int32) error { + if she == nil { + return data.ErrNilPointerReceiver + } + + return she.Header.SetBlockBodyTypeInt32(blockBodyType) +} From 68f8114d1787c68cc7f2298e85a19c566e793aee Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 27 Mar 2024 12:04:48 +0200 Subject: [PATCH 69/87] FIX: Indentation --- data/block/block.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/data/block/block.go b/data/block/block.go index 0c77a770d..5fff022e0 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -14,8 +14,7 @@ var _ = data.HeaderHandler(&Header{}) var _ = data.ShardHeaderHandler(&Header{}) // MiniBlockSlice should be used when referring to subset of mini blocks that is not -// -// necessarily representing a full block body +// necessarily representing a full block body type MiniBlockSlice []*MiniBlock // MiniblockAndHash holds the info related to a miniblock and its hash From cd91b61e73068181cc1a1262063cda3bf3b55098 Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 18 Jun 2024 12:24:22 +0300 Subject: [PATCH 70/87] FEAT: Add sovereign epoch start missing fields --- data/block/sovereignChainHeader.go | 6 +- data/block/sovereignChainHeader.pb.go | 122 +++++++++++++++++++------- data/block/sovereignChainHeader.proto | 1 + 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index b24d5231b..3119d589b 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -456,7 +456,11 @@ func (sch *SovereignChainHeader) IsInterfaceNil() bool { // IsStartOfEpochBlock returns false for the sovereign chain header func (sch *SovereignChainHeader) IsStartOfEpochBlock() bool { - return false + if sch == nil { + return false + } + + return len(sch.EpochStartHeaderHash) > 0 } // GetBlockBodyTypeInt32 returns the blockBody type as int32 diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index d9dd4d276..d3fa91ee2 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -32,6 +32,7 @@ type SovereignChainHeader struct { ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` OutGoingMiniBlockHeader *OutGoingMiniBlockHeader `protobuf:"bytes,4,opt,name=OutGoingMiniBlockHeader,proto3" json:"outGoingOperations,omitempty"` + EpochStartHeaderHash []byte `protobuf:"bytes,5,opt,name=EpochStartHeaderHash,proto3" json:"epochStartHeaderHash,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -90,6 +91,13 @@ func (m *SovereignChainHeader) GetOutGoingMiniBlockHeader() *OutGoingMiniBlockHe return nil } +func (m *SovereignChainHeader) GetEpochStartHeaderHash() []byte { + if m != nil { + return m.EpochStartHeaderHash + } + return nil +} + type OutGoingMiniBlockHeader struct { Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"hash,omitempty"` OutGoingOperationsHash []byte `protobuf:"bytes,2,opt,name=OutGoingOperationsHash,proto3" json:"outGoingOperationsHash,omitempty"` @@ -161,36 +169,38 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 460 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x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, 0xe8, 0x3b, 0xbc, 0xfb, 0xd6, 0x7b, 0x73, 0xd1, 0x1a, 0x2d, 0xbf, 0xc6, 0xd0, 0x19, 0xf2, - 0x78, 0x7a, 0x19, 0xb8, 0xb6, 0xc2, 0xe5, 0xcc, 0xf1, 0x8b, 0xe5, 0x1a, 0x07, 0xab, 0x35, 0x0e, - 0x4e, 0xd7, 0x18, 0x9c, 0x58, 0x0c, 0x7e, 0x59, 0x0c, 0xfe, 0x58, 0x0c, 0x96, 0x16, 0x83, 0x95, - 0xc5, 0xe0, 0xaf, 0xc5, 0xe0, 0x9f, 0xc5, 0xc1, 0xa9, 0xc5, 0xe0, 0xe7, 0x06, 0x07, 0xcb, 0x0d, - 0x0e, 0x56, 0x1b, 0x1c, 0x7c, 0xd8, 0xf1, 0xcf, 0x6e, 0xd2, 0xf6, 0xff, 0xd1, 0xc1, 0xff, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x9a, 0xfb, 0x59, 0xfb, 0xd8, 0x03, 0x00, 0x00, + // 484 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcf, 0x8a, 0xd3, 0x40, + 0x18, 0xcf, 0x98, 0xb6, 0x87, 0xd9, 0xd5, 0xc3, 0xb0, 0xd4, 0x58, 0x64, 0x12, 0xeb, 0xbf, 0x82, + 0xda, 0xa2, 0xfb, 0x00, 0x62, 0x64, 0x71, 0x0f, 0x4a, 0x21, 0x81, 0x3d, 0x88, 0x97, 0x69, 0x33, + 0x4e, 0x06, 0xdb, 0x4c, 0x99, 0x4e, 0x17, 0x15, 0x04, 0xaf, 0xde, 0x7c, 0x0c, 0xf1, 0x49, 0x3c, + 0xf6, 0xd8, 0xd3, 0x60, 0xd3, 0x8b, 0xcc, 0x69, 0x1f, 0x41, 0x76, 0x52, 0x30, 0xb2, 0xc9, 0x6e, + 0x4f, 0x99, 0x6f, 0xbe, 0xdf, 0x9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 0x6f, 0xb0, 0xb3, 0xdc, 0x60, 0x67, 0xb5, 0xc1, 0xce, 0xdb, 0xa6, 0xfd, + 0x9d, 0x47, 0x2d, 0xfb, 0x7d, 0x1e, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x76, 0xb3, 0xfd, 0xde, + 0x30, 0x04, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -229,6 +239,9 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { if !this.OutGoingMiniBlockHeader.Equal(that1.OutGoingMiniBlockHeader) { return false } + if !bytes.Equal(this.EpochStartHeaderHash, that1.EpochStartHeaderHash) { + return false + } return true } func (this *OutGoingMiniBlockHeader) Equal(that interface{}) bool { @@ -268,7 +281,7 @@ func (this *SovereignChainHeader) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 9) s = append(s, "&block.SovereignChainHeader{") if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") @@ -278,6 +291,7 @@ func (this *SovereignChainHeader) GoString() string { if this.OutGoingMiniBlockHeader != nil { s = append(s, "OutGoingMiniBlockHeader: "+fmt.Sprintf("%#v", this.OutGoingMiniBlockHeader)+",\n") } + s = append(s, "EpochStartHeaderHash: "+fmt.Sprintf("%#v", this.EpochStartHeaderHash)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -322,6 +336,13 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.EpochStartHeaderHash) > 0 { + i -= len(m.EpochStartHeaderHash) + copy(dAtA[i:], m.EpochStartHeaderHash) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.EpochStartHeaderHash))) + i-- + dAtA[i] = 0x2a + } if m.OutGoingMiniBlockHeader != nil { { size, err := m.OutGoingMiniBlockHeader.MarshalToSizedBuffer(dAtA[:i]) @@ -451,6 +472,10 @@ func (m *SovereignChainHeader) Size() (n int) { l = m.OutGoingMiniBlockHeader.Size() n += 1 + l + sovSovereignChainHeader(uint64(l)) } + l = len(m.EpochStartHeaderHash) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } return n } @@ -494,6 +519,7 @@ func (this *SovereignChainHeader) String() string { `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, `OutGoingMiniBlockHeader:` + strings.Replace(this.OutGoingMiniBlockHeader.String(), "OutGoingMiniBlockHeader", "OutGoingMiniBlockHeader", 1) + `,`, + `EpochStartHeaderHash:` + fmt.Sprintf("%v", this.EpochStartHeaderHash) + `,`, `}`, }, "") return s @@ -686,6 +712,40 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStartHeaderHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EpochStartHeaderHash = append(m.EpochStartHeaderHash[:0], dAtA[iNdEx:postIndex]...) + if m.EpochStartHeaderHash == nil { + m.EpochStartHeaderHash = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index bdda296a5..81b6e87e8 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -15,6 +15,7 @@ message SovereignChainHeader { bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; OutGoingMiniBlockHeader OutGoingMiniBlockHeader = 4 [(gogoproto.jsontag) = "outGoingOperations,omitempty"]; + bytes EpochStartHeaderHash = 5 [(gogoproto.jsontag) = "epochStartHeaderHash,omitempty"]; } message OutGoingMiniBlockHeader { From 94cf0abfe21dc5528d12ebd605946b4c7110214c Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 18 Jun 2024 14:56:11 +0300 Subject: [PATCH 71/87] FEAT: Extend sov header interface --- data/block/sovereignChainHeader.go | 10 ++++++++++ data/interface.go | 2 ++ 2 files changed, 12 insertions(+) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 3119d589b..6b80b5119 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -587,6 +587,16 @@ func (sch *SovereignChainHeader) SetBlockBodyTypeInt32(blockBodyType int32) erro return sch.Header.SetBlockBodyTypeInt32(blockBodyType) } +// SetEpochStartHash sets the epoch start block hash +func (sch *SovereignChainHeader) SetEpochStartHash(hash []byte) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + sch.EpochStartHeaderHash = hash + return nil +} + // SetHash returns the hash func (omb *OutGoingMiniBlockHeader) SetHash(hash []byte) error { if omb == nil { diff --git a/data/interface.go b/data/interface.go index 45fb2c292..8a4120e4e 100644 --- a/data/interface.go +++ b/data/interface.go @@ -95,6 +95,8 @@ type SovereignChainHeaderHandler interface { GetExtendedShardHeaderHashes() [][]byte GetOutGoingMiniBlockHeaderHandler() OutGoingMiniBlockHeaderHandler SetOutGoingMiniBlockHeaderHandler(mbHeader OutGoingMiniBlockHeaderHandler) error + SetEpochStartHeaderHash(hash []byte) error + GetEpochStartHeaderHash() []byte } // OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header From c7afec58fbdda043d2489679e395cc7fe4c88f8d Mon Sep 17 00:00:00 2001 From: Marius C Date: Tue, 18 Jun 2024 15:02:43 +0300 Subject: [PATCH 72/87] FIX: Interface signature --- data/block/sovereignChainHeader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 6b80b5119..bc2d69a82 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -587,8 +587,8 @@ func (sch *SovereignChainHeader) SetBlockBodyTypeInt32(blockBodyType int32) erro return sch.Header.SetBlockBodyTypeInt32(blockBodyType) } -// SetEpochStartHash sets the epoch start block hash -func (sch *SovereignChainHeader) SetEpochStartHash(hash []byte) error { +// SetEpochStartHeaderHash sets the epoch start block hash +func (sch *SovereignChainHeader) SetEpochStartHeaderHash(hash []byte) error { if sch == nil { return data.ErrNilPointerReceiver } From bdffd3df8de3f8cefbeabf4803dbd8848afe6de1 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 19 Jun 2024 16:00:06 +0300 Subject: [PATCH 73/87] FIX: Simplify start of epoch with bool flag --- data/block/sovereignChainHeader.go | 8 +- data/block/sovereignChainHeader.pb.go | 120 ++++++++++++-------------- data/block/sovereignChainHeader.proto | 2 +- data/interface.go | 3 +- 4 files changed, 60 insertions(+), 73 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index bc2d69a82..345323dbf 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -460,7 +460,7 @@ func (sch *SovereignChainHeader) IsStartOfEpochBlock() bool { return false } - return len(sch.EpochStartHeaderHash) > 0 + return sch.IsStartOfEpoch } // GetBlockBodyTypeInt32 returns the blockBody type as int32 @@ -587,13 +587,13 @@ func (sch *SovereignChainHeader) SetBlockBodyTypeInt32(blockBodyType int32) erro return sch.Header.SetBlockBodyTypeInt32(blockBodyType) } -// SetEpochStartHeaderHash sets the epoch start block hash -func (sch *SovereignChainHeader) SetEpochStartHeaderHash(hash []byte) error { +// SetStartOfEpochHeader sets the bool flag for epoch start header +func (sch *SovereignChainHeader) SetStartOfEpochHeader() error { if sch == nil { return data.ErrNilPointerReceiver } - sch.EpochStartHeaderHash = hash + sch.IsStartOfEpoch = true return nil } diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index d3fa91ee2..7d787f9a2 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -32,7 +32,7 @@ type SovereignChainHeader struct { ValidatorStatsRootHash []byte `protobuf:"bytes,2,opt,name=ValidatorStatsRootHash,proto3" json:"validatorStatsRootHash"` ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` OutGoingMiniBlockHeader *OutGoingMiniBlockHeader `protobuf:"bytes,4,opt,name=OutGoingMiniBlockHeader,proto3" json:"outGoingOperations,omitempty"` - EpochStartHeaderHash []byte `protobuf:"bytes,5,opt,name=EpochStartHeaderHash,proto3" json:"epochStartHeaderHash,omitempty"` + IsStartOfEpoch bool `protobuf:"varint,5,opt,name=IsStartOfEpoch,proto3" json:"isStartOfEpoch,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } @@ -91,11 +91,11 @@ func (m *SovereignChainHeader) GetOutGoingMiniBlockHeader() *OutGoingMiniBlockHe return nil } -func (m *SovereignChainHeader) GetEpochStartHeaderHash() []byte { +func (m *SovereignChainHeader) GetIsStartOfEpoch() bool { if m != nil { - return m.EpochStartHeaderHash + return m.IsStartOfEpoch } - return nil + return false } type OutGoingMiniBlockHeader struct { @@ -169,38 +169,38 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 484 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcf, 0x8a, 0xd3, 0x40, - 0x18, 0xcf, 0x98, 0xb6, 0x87, 0xd9, 0xd5, 0xc3, 0xb0, 0xd4, 0x58, 0x64, 0x12, 0xeb, 0xbf, 0x82, - 0xda, 0xa2, 0xfb, 0x00, 0x62, 0x64, 0x71, 0x0f, 0x4a, 0x21, 0x81, 0x3d, 0x88, 0x97, 0x69, 0x33, - 0x4e, 0x06, 0xdb, 0x4c, 0x99, 0x4e, 0x17, 0x15, 0x04, 0xaf, 0xde, 0x7c, 0x0c, 0xf1, 0x49, 0x3c, - 0xf6, 0xd8, 0xd3, 0x60, 0xd3, 0x8b, 0xcc, 0x69, 0x1f, 0x41, 0x76, 0x52, 0x30, 0xb2, 0xc9, 0x6e, - 0x4f, 0x99, 0x6f, 0xbe, 0xdf, 0x9f, 0xef, 0xf7, 0x25, 0x81, 0x9d, 0xb9, 0x38, 0xa5, 0x92, 0x72, - 0x96, 0xbd, 0x4c, 0x09, 0xcf, 0x8e, 0x29, 0x49, 0xa8, 0xec, 0xcf, 0xa4, 0x50, 0x02, 0x35, 0xed, - 0xa3, 0xf3, 0x84, 0x71, 0x95, 0x2e, 0x46, 0xfd, 0xb1, 0x98, 0x0e, 0x98, 0x60, 0x62, 0x60, 0xaf, - 0x47, 0x8b, 0xf7, 0xb6, 0xb2, 0x85, 0x3d, 0x15, 0xac, 0xce, 0xde, 0x68, 0x22, 0xc6, 0x1f, 0x8a, - 0xa2, 0xbb, 0x72, 0xe1, 0x41, 0x5c, 0xe1, 0x80, 0x9e, 0xc2, 0x56, 0x71, 0xf2, 0x40, 0x00, 0x7a, - 0x7b, 0xcf, 0xae, 0x17, 0x84, 0x7e, 0x71, 0x19, 0x42, 0xa3, 0xfd, 0x56, 0x6a, 0xcf, 0xd1, 0x16, - 0x88, 0x22, 0xd8, 0x3e, 0x21, 0x13, 0x9e, 0x10, 0x25, 0x64, 0xac, 0x88,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x4d, 0x62, 0xce, 0x32, 0xa2, 0x16, 0x92, 0x5e, 0x44, 0x7b, 0xae, 0x75, 0x3b, 0x34, 0xda, - 0x1f, 0x90, 0x5d, 0x08, 0x25, 0xf3, 0xdd, 0x1c, 0xd0, 0x17, 0x78, 0xe7, 0xb5, 0xdd, 0xcd, 0x65, - 0x63, 0x34, 0xec, 0x18, 0x03, 0xa3, 0xfd, 0x47, 0x93, 0xab, 0xc0, 0xa5, 0x11, 0xae, 0x56, 0x0e, - 0x9f, 0x2f, 0xd7, 0xd8, 0x59, 0xad, 0xb1, 0x73, 0xb6, 0xc6, 0xe0, 0x6b, 0x8e, 0xc1, 0x8f, 0x1c, - 0x83, 0x5f, 0x39, 0x06, 0xcb, 0x1c, 0x83, 0x55, 0x8e, 0xc1, 0xef, 0x1c, 0x83, 0x3f, 0x39, 0x76, - 0xce, 0x72, 0x0c, 0xbe, 0x6f, 0xb0, 0xb3, 0xdc, 0x60, 0x67, 0xb5, 0xc1, 0xce, 0xdb, 0xa6, 0xfd, - 0x9d, 0x47, 0x2d, 0xfb, 0x7d, 0x1e, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x76, 0xb3, 0xfd, 0xde, - 0x30, 0x04, 0x00, 0x00, + // 493 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4f, 0x6f, 0xd3, 0x30, + 0x14, 0x8f, 0x49, 0x5b, 0x21, 0x6f, 0xec, 0x60, 0xa1, 0x12, 0xaa, 0xc9, 0x09, 0xe3, 0x5f, 0x25, + 0xa0, 0x15, 0xec, 0x03, 0x20, 0x02, 0x13, 0x43, 0x02, 0x55, 0x4a, 0x24, 0x0e, 0x88, 0x8b, 0xdb, + 0x78, 0x8e, 0x45, 0x1b, 0x57, 0x8e, 0x3b, 0x01, 0x12, 0x12, 0x57, 0x6e, 0x7c, 0x0c, 0xc4, 0x07, + 0x41, 0x1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 0x58, 0x62, + 0xe7, 0x64, 0x89, 0xc1, 0xe7, 0x02, 0x83, 0x6f, 0x05, 0x06, 0x3f, 0x0b, 0x0c, 0xe6, 0x05, 0x06, + 0x8b, 0x02, 0x83, 0x5f, 0x05, 0x06, 0xbf, 0x0b, 0xec, 0x9c, 0x14, 0x18, 0x7c, 0x5d, 0x61, 0x67, + 0xbe, 0xc2, 0xce, 0x62, 0x85, 0x9d, 0x37, 0x4d, 0xfb, 0x78, 0x87, 0x2d, 0xfb, 0x37, 0xee, 0xff, + 0x09, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x96, 0xb1, 0x70, 0x1e, 0x04, 0x00, 0x00, } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -239,7 +239,7 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { if !this.OutGoingMiniBlockHeader.Equal(that1.OutGoingMiniBlockHeader) { return false } - if !bytes.Equal(this.EpochStartHeaderHash, that1.EpochStartHeaderHash) { + if this.IsStartOfEpoch != that1.IsStartOfEpoch { return false } return true @@ -291,7 +291,7 @@ func (this *SovereignChainHeader) GoString() string { if this.OutGoingMiniBlockHeader != nil { s = append(s, "OutGoingMiniBlockHeader: "+fmt.Sprintf("%#v", this.OutGoingMiniBlockHeader)+",\n") } - s = append(s, "EpochStartHeaderHash: "+fmt.Sprintf("%#v", this.EpochStartHeaderHash)+",\n") + s = append(s, "IsStartOfEpoch: "+fmt.Sprintf("%#v", this.IsStartOfEpoch)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -336,12 +336,15 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.EpochStartHeaderHash) > 0 { - i -= len(m.EpochStartHeaderHash) - copy(dAtA[i:], m.EpochStartHeaderHash) - i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.EpochStartHeaderHash))) + if m.IsStartOfEpoch { + i-- + if m.IsStartOfEpoch { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x28 } if m.OutGoingMiniBlockHeader != nil { { @@ -472,9 +475,8 @@ func (m *SovereignChainHeader) Size() (n int) { l = m.OutGoingMiniBlockHeader.Size() n += 1 + l + sovSovereignChainHeader(uint64(l)) } - l = len(m.EpochStartHeaderHash) - if l > 0 { - n += 1 + l + sovSovereignChainHeader(uint64(l)) + if m.IsStartOfEpoch { + n += 2 } return n } @@ -519,7 +521,7 @@ func (this *SovereignChainHeader) String() string { `ValidatorStatsRootHash:` + fmt.Sprintf("%v", this.ValidatorStatsRootHash) + `,`, `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, `OutGoingMiniBlockHeader:` + strings.Replace(this.OutGoingMiniBlockHeader.String(), "OutGoingMiniBlockHeader", "OutGoingMiniBlockHeader", 1) + `,`, - `EpochStartHeaderHash:` + fmt.Sprintf("%v", this.EpochStartHeaderHash) + `,`, + `IsStartOfEpoch:` + fmt.Sprintf("%v", this.IsStartOfEpoch) + `,`, `}`, }, "") return s @@ -713,10 +715,10 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EpochStartHeaderHash", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsStartOfEpoch", wireType) } - var byteLen int + var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowSovereignChainHeader @@ -726,26 +728,12 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { - return ErrInvalidLengthSovereignChainHeader - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSovereignChainHeader - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.EpochStartHeaderHash = append(m.EpochStartHeaderHash[:0], dAtA[iNdEx:postIndex]...) - if m.EpochStartHeaderHash == nil { - m.EpochStartHeaderHash = []byte{} - } - iNdEx = postIndex + m.IsStartOfEpoch = bool(v != 0) default: iNdEx = preIndex skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index 81b6e87e8..03f0ce882 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -15,7 +15,7 @@ message SovereignChainHeader { bytes ValidatorStatsRootHash = 2 [(gogoproto.jsontag) = "validatorStatsRootHash"]; repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; OutGoingMiniBlockHeader OutGoingMiniBlockHeader = 4 [(gogoproto.jsontag) = "outGoingOperations,omitempty"]; - bytes EpochStartHeaderHash = 5 [(gogoproto.jsontag) = "epochStartHeaderHash,omitempty"]; + bool IsStartOfEpoch = 5 [(gogoproto.jsontag) = "isStartOfEpoch,omitempty"]; } message OutGoingMiniBlockHeader { diff --git a/data/interface.go b/data/interface.go index 8a4120e4e..9f72a9c66 100644 --- a/data/interface.go +++ b/data/interface.go @@ -95,8 +95,7 @@ type SovereignChainHeaderHandler interface { GetExtendedShardHeaderHashes() [][]byte GetOutGoingMiniBlockHeaderHandler() OutGoingMiniBlockHeaderHandler SetOutGoingMiniBlockHeaderHandler(mbHeader OutGoingMiniBlockHeaderHandler) error - SetEpochStartHeaderHash(hash []byte) error - GetEpochStartHeaderHash() []byte + SetStartOfEpochHeader() error } // OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header From 22393a75aced3ba0852b2a5e2b75d1b6a5223911 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 20 Jun 2024 12:46:03 +0300 Subject: [PATCH 74/87] FEAT: Sovereign chain trigger registry --- data/block/trigger.pb.go | 554 ++++++++++++++++++++++++++++++++++++--- data/block/trigger.proto | 11 + 2 files changed, 530 insertions(+), 35 deletions(-) diff --git a/data/block/trigger.pb.go b/data/block/trigger.pb.go index 3db9b3312..6defb93c7 100644 --- a/data/block/trigger.pb.go +++ b/data/block/trigger.pb.go @@ -319,50 +319,141 @@ func (m *MetaTriggerRegistry) GetEpochStartMeta() *MetaBlock { return nil } +type SovereignShardTriggerRegistry struct { + Epoch uint32 `protobuf:"varint,1,opt,name=Epoch,proto3" json:"Epoch,omitempty"` + CurrentRound uint64 `protobuf:"varint,2,opt,name=CurrentRound,proto3" json:"CurrentRound,omitempty"` + EpochFinalityAttestingRound uint64 `protobuf:"varint,3,opt,name=EpochFinalityAttestingRound,proto3" json:"EpochFinalityAttestingRound,omitempty"` + CurrEpochStartRound uint64 `protobuf:"varint,4,opt,name=CurrEpochStartRound,proto3" json:"CurrEpochStartRound,omitempty"` + PrevEpochStartRound uint64 `protobuf:"varint,5,opt,name=PrevEpochStartRound,proto3" json:"PrevEpochStartRound,omitempty"` + EpochStartMetaHash []byte `protobuf:"bytes,6,opt,name=EpochStartMetaHash,proto3" json:"EpochStartMetaHash,omitempty"` + SovereignChainHeader *SovereignChainHeader `protobuf:"bytes,7,opt,name=SovereignChainHeader,proto3" json:"SovereignChainHeader,omitempty"` +} + +func (m *SovereignShardTriggerRegistry) Reset() { *m = SovereignShardTriggerRegistry{} } +func (*SovereignShardTriggerRegistry) ProtoMessage() {} +func (*SovereignShardTriggerRegistry) Descriptor() ([]byte, []int) { + return fileDescriptor_8c31e6d8b4368946, []int{3} +} +func (m *SovereignShardTriggerRegistry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SovereignShardTriggerRegistry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *SovereignShardTriggerRegistry) XXX_Merge(src proto.Message) { + xxx_messageInfo_SovereignShardTriggerRegistry.Merge(m, src) +} +func (m *SovereignShardTriggerRegistry) XXX_Size() int { + return m.Size() +} +func (m *SovereignShardTriggerRegistry) XXX_DiscardUnknown() { + xxx_messageInfo_SovereignShardTriggerRegistry.DiscardUnknown(m) +} + +var xxx_messageInfo_SovereignShardTriggerRegistry proto.InternalMessageInfo + +func (m *SovereignShardTriggerRegistry) GetEpoch() uint32 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *SovereignShardTriggerRegistry) GetCurrentRound() uint64 { + if m != nil { + return m.CurrentRound + } + return 0 +} + +func (m *SovereignShardTriggerRegistry) GetEpochFinalityAttestingRound() uint64 { + if m != nil { + return m.EpochFinalityAttestingRound + } + return 0 +} + +func (m *SovereignShardTriggerRegistry) GetCurrEpochStartRound() uint64 { + if m != nil { + return m.CurrEpochStartRound + } + return 0 +} + +func (m *SovereignShardTriggerRegistry) GetPrevEpochStartRound() uint64 { + if m != nil { + return m.PrevEpochStartRound + } + return 0 +} + +func (m *SovereignShardTriggerRegistry) GetEpochStartMetaHash() []byte { + if m != nil { + return m.EpochStartMetaHash + } + return nil +} + +func (m *SovereignShardTriggerRegistry) GetSovereignChainHeader() *SovereignChainHeader { + if m != nil { + return m.SovereignChainHeader + } + return nil +} + func init() { proto.RegisterType((*ShardTriggerRegistry)(nil), "proto.ShardTriggerRegistry") proto.RegisterType((*ShardTriggerRegistryV2)(nil), "proto.ShardTriggerRegistryV2") proto.RegisterType((*MetaTriggerRegistry)(nil), "proto.MetaTriggerRegistry") + proto.RegisterType((*SovereignShardTriggerRegistry)(nil), "proto.SovereignShardTriggerRegistry") } func init() { proto.RegisterFile("trigger.proto", fileDescriptor_8c31e6d8b4368946) } var fileDescriptor_8c31e6d8b4368946 = []byte{ - // 532 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcb, 0x6e, 0xd3, 0x40, - 0x14, 0xf5, 0xc4, 0x76, 0x9a, 0x4c, 0x12, 0x02, 0xd3, 0x52,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c9, 0xff, 0xe4, 0x16, 0xae, 0xa0, 0x55, 0x57, 0x2c, 0xdc, - 0x5c, 0x7d, 0x1e, 0xec, 0x41, 0x63, 0x19, 0xec, 0xaa, 0x37, 0xa8, 0x57, 0xbf, 0xe1, 0x09, 0x5e, - 0x4f, 0x26, 0xe6, 0x3d, 0xd3, 0x40, 0x59, 0x44, 0x25, 0x8a, 0xb7, 0x82, 0x9f, 0xe5, 0x15, 0x7a, - 0xaa, 0x28, 0xa0, 0x16, 0x3e, 0x01, 0x94, 0x18, 0x00, 0x3e, 0x55, 0x57, 0x7c, 0xca, 0x30, 0xe4, - 0x39, 0xbe, 0x93, 0x45, 0x61, 0x85, 0x0d, 0xe7, 0xee, 0x3c, 0xc1, 0x0b, 0x57, 0x59, 0xae, 0x6f, - 0xe7, 0xc5, 0x78, 0x4a, 0x95, 0xc9, 0x94, 0x2a, 0x17, 0x53, 0x8a, 0xbe, 0xc4, 0x14, 0x7d, 0x8b, - 0x29, 0xfa, 0x19, 0x53, 0x34, 0x8e, 0x29, 0x9a, 0xc4, 0x14, 0xfd, 0x8e, 0x29, 0xfa, 0x13, 0x53, - 0xe5, 0x22, 0xa6, 0xe8, 0xeb, 0x8c, 0x2a, 0xe3, 0x19, 0x55, 0x26, 0x33, 0xaa, 0xbc, 0xd7, 0xe1, - 0xff, 0xb2, 0x57, 0x85, 0x13, 0x9e, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x15, 0x5a, 0xda, 0x3b, - 0x91, 0x05, 0x00, 0x00, + // 581 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x55, 0x4d, 0x73, 0xd2, 0x40, + 0x18, 0xce, 0x36, 0x84, 0xc2, 0x02, 0xa2, 0x5b, 0xec, 0x64, 0xa8, 0xee, 0x64, 0x72, 0xca, 0x41, + 0xa9, 0x83, 0x33, 0x8e, 0x37, 0xb5, 0x4c, 0x9d,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6d, 0xe0, 0xad, 0x19, 0xb2, 0xfe, 0xc8, 0x2d, 0x5c, 0x41, 0xab, 0xae, 0x98, + 0xb8, 0xb8, 0x7a, 0x3c, 0xb8, 0x87, 0x0c, 0x8b, 0x61, 0x57, 0x9d, 0x41, 0xbd, 0xfa, 0x0c, 0x4f, + 0xf0, 0xd6, 0x6c, 0xe2, 0xba, 0x67, 0x19, 0x50, 0x26, 0x51, 0x33, 0xc5, 0x3b, 0xc1, 0x87, 0xeb, + 0x0a, 0x2d, 0x54, 0x24, 0x50, 0x0b, 0x9f, 0x00, 0x9a, 0x19, 0x00, 0x3e, 0x65, 0x57, 0x7c, 0x8a, + 0x31, 0xe4, 0x39, 0xbe, 0x13, 0x47, 0xe1, 0x0a, 0x0b, 0xf5, 0xbb, 0x51, 0x82, 0x17, 0xae, 0xb2, + 0xb5, 0x3e, 0xf3, 0x5c, 0xc5, 0x0f, 0x9b, 0xf3, 0x97, 0x5e, 0xe2, 0xeb, 0xed, 0xbf, 0xd7, 0x71, + 0xaf, 0xdf, 0xe2, 0x4a, 0x33, 0xe1, 0x2b, 0x11, 0x39, 0xbe, 0x13, 0x39, 0x9e, 0xd4, 0xc2, 0x12, + 0x85, 0x7b, 0x2f, 0x46, 0x13, 0xaa, 0x8c, 0x27, 0x54, 0xb9, 0x98, 0x50, 0x74, 0x1e, 0x50, 0xf4, + 0x2d, 0xa0, 0xe8, 0x67, 0x40, 0xd1, 0x28, 0xa0, 0x68, 0x1c, 0x50, 0xf4, 0x3b, 0xa0, 0xe8, 0x4f, + 0x40, 0x95, 0x8b, 0x80, 0xa2, 0xaf, 0x53, 0xaa, 0x8c, 0xa6, 0x54, 0x19, 0x4f, 0xa9, 0xf2, 0x41, + 0x83, 0xcf, 0x59, 0x3b, 0x0b, 0x4b, 0x3e, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x3a, 0xf5, 0x77, + 0x50, 0x30, 0x07, 0x00, 0x00, } func (this *ShardTriggerRegistry) Equal(that interface{}) bool { @@ -503,6 +594,48 @@ func (this *MetaTriggerRegistry) Equal(that interface{}) bool { } return true } +func (this *SovereignShardTriggerRegistry) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*SovereignShardTriggerRegistry) + if !ok { + that2, ok := that.(SovereignShardTriggerRegistry) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Epoch != that1.Epoch { + return false + } + if this.CurrentRound != that1.CurrentRound { + return false + } + if this.EpochFinalityAttestingRound != that1.EpochFinalityAttestingRound { + return false + } + if this.CurrEpochStartRound != that1.CurrEpochStartRound { + return false + } + if this.PrevEpochStartRound != that1.PrevEpochStartRound { + return false + } + if !bytes.Equal(this.EpochStartMetaHash, that1.EpochStartMetaHash) { + return false + } + if !this.SovereignChainHeader.Equal(that1.SovereignChainHeader) { + return false + } + return true +} func (this *ShardTriggerRegistry) GoString() string { if this == nil { return "nil" @@ -561,6 +694,24 @@ func (this *MetaTriggerRegistry) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *SovereignShardTriggerRegistry) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 11) + s = append(s, "&block.SovereignShardTriggerRegistry{") + s = append(s, "Epoch: "+fmt.Sprintf("%#v", this.Epoch)+",\n") + s = append(s, "CurrentRound: "+fmt.Sprintf("%#v", this.CurrentRound)+",\n") + s = append(s, "EpochFinalityAttestingRound: "+fmt.Sprintf("%#v", this.EpochFinalityAttestingRound)+",\n") + s = append(s, "CurrEpochStartRound: "+fmt.Sprintf("%#v", this.CurrEpochStartRound)+",\n") + s = append(s, "PrevEpochStartRound: "+fmt.Sprintf("%#v", this.PrevEpochStartRound)+",\n") + s = append(s, "EpochStartMetaHash: "+fmt.Sprintf("%#v", this.EpochStartMetaHash)+",\n") + if this.SovereignChainHeader != nil { + s = append(s, "SovereignChainHeader: "+fmt.Sprintf("%#v", this.SovereignChainHeader)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} func valueToGoStringTrigger(v interface{}, typ string) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -810,6 +961,73 @@ func (m *MetaTriggerRegistry) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *SovereignShardTriggerRegistry) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SovereignShardTriggerRegistry) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SovereignShardTriggerRegistry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SovereignChainHeader != nil { + { + size, err := m.SovereignChainHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTrigger(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + if len(m.EpochStartMetaHash) > 0 { + i -= len(m.EpochStartMetaHash) + copy(dAtA[i:], m.EpochStartMetaHash) + i = encodeVarintTrigger(dAtA, i, uint64(len(m.EpochStartMetaHash))) + i-- + dAtA[i] = 0x32 + } + if m.PrevEpochStartRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.PrevEpochStartRound)) + i-- + dAtA[i] = 0x28 + } + if m.CurrEpochStartRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.CurrEpochStartRound)) + i-- + dAtA[i] = 0x20 + } + if m.EpochFinalityAttestingRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.EpochFinalityAttestingRound)) + i-- + dAtA[i] = 0x18 + } + if m.CurrentRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.CurrentRound)) + i-- + dAtA[i] = 0x10 + } + if m.Epoch != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTrigger(dAtA []byte, offset int, v uint64) int { offset -= sovTrigger(v) base := offset @@ -929,6 +1147,38 @@ func (m *MetaTriggerRegistry) Size() (n int) { return n } +func (m *SovereignShardTriggerRegistry) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Epoch != 0 { + n += 1 + sovTrigger(uint64(m.Epoch)) + } + if m.CurrentRound != 0 { + n += 1 + sovTrigger(uint64(m.CurrentRound)) + } + if m.EpochFinalityAttestingRound != 0 { + n += 1 + sovTrigger(uint64(m.EpochFinalityAttestingRound)) + } + if m.CurrEpochStartRound != 0 { + n += 1 + sovTrigger(uint64(m.CurrEpochStartRound)) + } + if m.PrevEpochStartRound != 0 { + n += 1 + sovTrigger(uint64(m.PrevEpochStartRound)) + } + l = len(m.EpochStartMetaHash) + if l > 0 { + n += 1 + l + sovTrigger(uint64(l)) + } + if m.SovereignChainHeader != nil { + l = m.SovereignChainHeader.Size() + n += 1 + l + sovTrigger(uint64(l)) + } + return n +} + func sovTrigger(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -987,6 +1237,22 @@ func (this *MetaTriggerRegistry) String() string { }, "") return s } +func (this *SovereignShardTriggerRegistry) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&SovereignShardTriggerRegistry{`, + `Epoch:` + fmt.Sprintf("%v", this.Epoch) + `,`, + `CurrentRound:` + fmt.Sprintf("%v", this.CurrentRound) + `,`, + `EpochFinalityAttestingRound:` + fmt.Sprintf("%v", this.EpochFinalityAttestingRound) + `,`, + `CurrEpochStartRound:` + fmt.Sprintf("%v", this.CurrEpochStartRound) + `,`, + `PrevEpochStartRound:` + fmt.Sprintf("%v", this.PrevEpochStartRound) + `,`, + `EpochStartMetaHash:` + fmt.Sprintf("%v", this.EpochStartMetaHash) + `,`, + `SovereignChainHeader:` + strings.Replace(fmt.Sprintf("%v", this.SovereignChainHeader), "SovereignChainHeader", "SovereignChainHeader", 1) + `,`, + `}`, + }, "") + return s +} func valueToStringTrigger(v interface{}) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -1729,6 +1995,224 @@ func (m *MetaTriggerRegistry) Unmarshal(dAtA []byte) error { } return nil } +func (m *SovereignShardTriggerRegistry) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SovereignShardTriggerRegistry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SovereignShardTriggerRegistry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentRound", wireType) + } + m.CurrentRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentRound |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochFinalityAttestingRound", wireType) + } + m.EpochFinalityAttestingRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EpochFinalityAttestingRound |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrEpochStartRound", wireType) + } + m.CurrEpochStartRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrEpochStartRound |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PrevEpochStartRound", wireType) + } + m.PrevEpochStartRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PrevEpochStartRound |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStartMetaHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTrigger + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTrigger + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EpochStartMetaHash = append(m.EpochStartMetaHash[:0], dAtA[iNdEx:postIndex]...) + if m.EpochStartMetaHash == nil { + m.EpochStartMetaHash = []byte{} + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SovereignChainHeader", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTrigger + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTrigger + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SovereignChainHeader == nil { + m.SovereignChainHeader = &SovereignChainHeader{} + } + if err := m.SovereignChainHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTrigger(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTrigger + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTrigger + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTrigger(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/data/block/trigger.proto b/data/block/trigger.proto index ae590942c..87ae04cd2 100644 --- a/data/block/trigger.proto +++ b/data/block/trigger.proto @@ -9,6 +9,7 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "block.proto"; import "blockV2.proto"; import "metaBlock.proto"; +import "sovereignChainHeader.proto"; message ShardTriggerRegistry { bool IsEpochStart = 1; @@ -43,3 +44,13 @@ message MetaTriggerRegistry { bytes EpochStartMetaHash = 6; MetaBlock EpochStartMeta = 7; } + +message SovereignShardTriggerRegistry { + uint32 Epoch = 1; + uint64 CurrentRound = 2; + uint64 EpochFinalityAttestingRound = 3; + uint64 CurrEpochStartRound = 4; + uint64 PrevEpochStartRound = 5; + bytes EpochStartMetaHash = 6; + SovereignChainHeader SovereignChainHeader = 7; +} From 92f76e51ab0db9873cabfc6cc26c856a22754ea1 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 20 Jun 2024 14:50:18 +0300 Subject: [PATCH 75/87] FEAT: MetaTriggerRegistryHandler --- data/block/trigger.go | 18 ++++++++++++++++++ data/interface.go | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/data/block/trigger.go b/data/block/trigger.go index c8b511e37..6d091e1e4 100644 --- a/data/block/trigger.go +++ b/data/block/trigger.go @@ -191,3 +191,21 @@ func (strV2 *ShardTriggerRegistryV2) SetEpochStartHeaderHandler(epochStartHeader } return nil } + +// GetEpochStartHeaderHandler returns the epoch start header handler +func (m *MetaTriggerRegistry) GetEpochStartHeaderHandler() data.HeaderHandler { + if m == nil { + return nil + } + + return m.EpochStartMeta +} + +// GetEpochStartHeaderHandler returns the epoch start header handler +func (m *SovereignShardTriggerRegistry) GetEpochStartHeaderHandler() data.HeaderHandler { + if m == nil { + return nil + } + + return m.SovereignChainHeader +} diff --git a/data/interface.go b/data/interface.go index 9f72a9c66..30891e5a3 100644 --- a/data/interface.go +++ b/data/interface.go @@ -29,6 +29,17 @@ type TriggerRegistryHandler interface { SetEpochStartHeaderHandler(epochStartHeaderHandler HeaderHandler) error } +// MetaTriggerRegistryHandler defines meta chain trigger registry interface +type MetaTriggerRegistryHandler interface { + GetEpoch() uint32 + GetCurrentRound() uint64 + GetEpochFinalityAttestingRound() uint64 + GetCurrEpochStartRound() uint64 + GetPrevEpochStartRound() uint64 + GetEpochStartMetaHash() []byte + GetEpochStartHeaderHandler() HeaderHandler +} + // CommonHeaderHandler defines getters and setters for header data holder type CommonHeaderHandler interface { GetShardID() uint32 From 28d7949719fa76861c5add405f3f6216b6d17a19 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 18 Jul 2024 13:05:30 +0300 Subject: [PATCH 76/87] FEAT: Add epoch start economics in sov block --- data/block/sovereignChainHeader.go | 34 ++ data/block/sovereignChainHeader.pb.go | 497 ++++++++++++++++++++++++-- data/block/sovereignChainHeader.proto | 9 + 3 files changed, 505 insertions(+), 35 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 345323dbf..bdf583ec3 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -597,6 +597,40 @@ func (sch *SovereignChainHeader) SetStartOfEpochHeader() error { return nil } +// SetDevFeesInEpoch sets the developer fees in the header +func (sch *SovereignChainHeader) SetDevFeesInEpoch(value *big.Int) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + if value == nil { + return data.ErrInvalidValue + } + if sch.DevFeesInEpoch == nil { + sch.DevFeesInEpoch = big.NewInt(0) + } + + sch.DevFeesInEpoch.Set(value) + + return nil +} + +// SetAccumulatedFeesInEpoch sets the epoch accumulated fees in the header +func (sch *SovereignChainHeader) SetAccumulatedFeesInEpoch(value *big.Int) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + if value == nil { + return data.ErrInvalidValue + } + if sch.AccumulatedFeesInEpoch == nil { + sch.AccumulatedFeesInEpoch = big.NewInt(0) + } + + sch.AccumulatedFeesInEpoch.Set(value) + + return nil +} + // SetHash returns the hash func (omb *OutGoingMiniBlockHeader) SetHash(hash []byte) error { if omb == nil { diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index 7d787f9a2..fa19576b1 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -8,8 +8,10 @@ import ( fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + github_com_multiversx_mx_chain_core_go_data "github.com/multiversx/mx-chain-core-go/data" io "io" math "math" + math_big "math/big" math_bits "math/bits" reflect "reflect" strings "strings" @@ -26,6 +28,46 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// EpochStart holds the block information for end-of-epoch +type EpochStartSovereign struct { + Economics Economics `protobuf:"bytes,1,opt,name=Economics,proto3" json:"economics"` +} + +func (m *EpochStartSovereign) Reset() { *m = EpochStartSovereign{} } +func (*EpochStartSovereign) ProtoMessage() {} +func (*EpochStartSovereign) Descriptor() ([]byte, []int) { + return fileDescriptor_b9b8ff297a820152, []int{0} +} +func (m *EpochStartSovereign) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EpochStartSovereign) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *EpochStartSovereign) XXX_Merge(src proto.Message) { + xxx_messageInfo_EpochStartSovereign.Merge(m, src) +} +func (m *EpochStartSovereign) XXX_Size() int { + return m.Size() +} +func (m *EpochStartSovereign) XXX_DiscardUnknown() { + xxx_messageInfo_EpochStartSovereign.DiscardUnknown(m) +} + +var xxx_messageInfo_EpochStartSovereign proto.InternalMessageInfo + +func (m *EpochStartSovereign) GetEconomics() Economics { + if m != nil { + return m.Economics + } + return Economics{} +} + // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain type SovereignChainHeader struct { Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` @@ -33,12 +75,15 @@ type SovereignChainHeader struct { ExtendedShardHeaderHashes [][]byte `protobuf:"bytes,3,rep,name=ExtendedShardHeaderHashes,proto3" json:"extendedShardHeaderHashes,omitempty"` OutGoingMiniBlockHeader *OutGoingMiniBlockHeader `protobuf:"bytes,4,opt,name=OutGoingMiniBlockHeader,proto3" json:"outGoingOperations,omitempty"` IsStartOfEpoch bool `protobuf:"varint,5,opt,name=IsStartOfEpoch,proto3" json:"isStartOfEpoch,omitempty"` + AccumulatedFeesInEpoch *math_big.Int `protobuf:"bytes,6,opt,name=AccumulatedFeesInEpoch,proto3,casttypewith=math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster" json:"accumulatedFeesInEpoch,omitempty"` + DevFeesInEpoch *math_big.Int `protobuf:"bytes,7,opt,name=DevFeesInEpoch,proto3,casttypewith=math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster" json:"devFeesInEpoch,omitempty"` + EpochStart EpochStartSovereign `protobuf:"bytes,8,opt,name=EpochStart,proto3" json:"epochStart,omitempty"` } func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } func (*SovereignChainHeader) ProtoMessage() {} func (*SovereignChainHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_b9b8ff297a820152, []int{0} + return fileDescriptor_b9b8ff297a820152, []int{1} } func (m *SovereignChainHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -98,6 +143,27 @@ func (m *SovereignChainHeader) GetIsStartOfEpoch() bool { return false } +func (m *SovereignChainHeader) GetAccumulatedFeesInEpoch() *math_big.Int { + if m != nil { + return m.AccumulatedFeesInEpoch + } + return nil +} + +func (m *SovereignChainHeader) GetDevFeesInEpoch() *math_big.Int { + if m != nil { + return m.DevFeesInEpoch + } + return nil +} + +func (m *SovereignChainHeader) GetEpochStart() EpochStartSovereign { + if m != nil { + return m.EpochStart + } + return EpochStartSovereign{} +} + type OutGoingMiniBlockHeader struct { Hash []byte `protobuf:"bytes,1,opt,name=Hash,proto3" json:"hash,omitempty"` OutGoingOperationsHash []byte `protobuf:"bytes,2,opt,name=OutGoingOperationsHash,proto3" json:"outGoingOperationsHash,omitempty"` @@ -108,7 +174,7 @@ type OutGoingMiniBlockHeader struct { func (m *OutGoingMiniBlockHeader) Reset() { *m = OutGoingMiniBlockHeader{} } func (*OutGoingMiniBlockHeader) ProtoMessage() {} func (*OutGoingMiniBlockHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_b9b8ff297a820152, []int{1} + return fileDescriptor_b9b8ff297a820152, []int{2} } func (m *OutGoingMiniBlockHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -162,6 +228,7 @@ func (m *OutGoingMiniBlockHeader) GetLeaderSignatureOutGoingOperations() []byte } func init() { + proto.RegisterType((*EpochStartSovereign)(nil), "proto.EpochStartSovereign") proto.RegisterType((*SovereignChainHeader)(nil), "proto.SovereignChainHeader") proto.RegisterType((*OutGoingMiniBlockHeader)(nil), "proto.OutGoingMiniBlockHeader") } @@ -169,40 +236,76 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 493 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4f, 0x6f, 0xd3, 0x30, - 0x14, 0x8f, 0x49, 0x5b, 0x21, 0x6f, 0xec, 0x60, 0xa1, 0x12, 0xaa, 0xc9, 0x09, 0xe3, 0x5f, 0x25, - 0xa0, 0x15, 0xec, 0x03, 0x20, 0x02, 0x13, 0x43, 0x02, 0x55, 0x4a, 0x24, 0x0e, 0x88, 0x8b, 0xdb, - 0x78, 0x8e, 0x45, 0x1b, 0x57, 0x8e, 0x3b, 0x01, 0x12, 0x12, 0x57, 0x6e, 0x7c, 0x0c, 0xc4, 0x07, - 0x41, 0x1c, 0x7b, 0xec, 0xc9, 0xa2, 0xe9, 0x05, 0xf9, 0xb4, 0x8f, 0x80, 0xe6, 0xf4, 0x10, 0x58, - 0xc3, 0x76, 0xca, 0x7b, 0x7e, 0xbf, 0xf7, 0xfb, 0xbd, 0x9f, 0x5f, 0x0c, 0x3b, 0xb9, 0x38, 0xa6, - 0x92, 0x72, 0x96, 0x3d, 0x4d, 0x09, 0xcf, 0x0e, 0x29, 0x49, 0xa8, 0xec, 0x4d, 0xa5, 0x50, 0x02, - 0x35, 0xed, 0xa7, 0xf3, 0x80, 0x71, 0x95, 0xce, 0x86, 0xbd, 0x91, 0x98, 0xf4, 0x99, 0x60, 0xa2, - 0x6f, 0x8f, 0x87, 0xb3, 0x23, 0x9b, 0xd9, 0xc4, 0x46, 0x65, 0x57, 0x67, 0x6b, 0x38, 0x16, 0xa3, - 0x77, 0x65, 0xb2, 0xf7, 0xc3, 0x85, 0x57, 0xe3, 0x0d, 0x0a, 0xe8, 0x21,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, 0xd7, 0x80, 0x8c, 0xf6, 0x77, 0x52, 0x92, 0x57, 0xd9, 0x6c, 0x1d, 0xbd, 0x85, 0xed, - 0xc1, 0x19, 0x0b, 0x95, 0x05, 0xde, 0x32, 0xda, 0x0f, 0xc4, 0x46, 0x44, 0x85, 0xab, 0x86, 0x03, - 0x7d, 0x01, 0xf0, 0xf6, 0x13, 0xc6, 0x24, 0x65, 0x44, 0xd1, 0x24, 0xe6, 0x2c, 0x23, 0x6a, 0x26, - 0xe9, 0x59, 0xb4, 0xe7, 0x5a, 0xb5, 0x7d, 0xa3, 0xfd, 0x3e, 0xb9, 0x48, 0x43, 0x45, 0xfc, 0x62, - 0x0a, 0xe8, 0x13, 0xbc, 0xf1, 0xd2, 0xde, 0xcd, 0xff, 0xc6, 0x68, 0xd8, 0x31, 0xfa, 0x46, 0xfb, - 0xf7, 0xc6, 0xe7, 0x81, 0x2b, 0x23, 0x9c, 0xcf, 0x1c, 0x3e, 0x9e, 0x2f, 0xb1, 0xb3, 0x58, 0x62, - 0xe7, 0x64, 0x89, 0xc1, 0xe7, 0x02, 0x83, 0x6f, 0x05, 0x06, 0x3f, 0x0b, 0x0c, 0xe6, 0x05, 0x06, - 0x8b, 0x02, 0x83, 0x5f, 0x05, 0x06, 0xbf, 0x0b, 0xec, 0x9c, 0x14, 0x18, 0x7c, 0x5d, 0x61, 0x67, - 0xbe, 0xc2, 0xce, 0x62, 0x85, 0x9d, 0x37, 0x4d, 0xfb, 0x78, 0x87, 0x2d, 0xfb, 0x37, 0xee, 0xff, - 0x09, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x96, 0xb1, 0x70, 0x1e, 0x04, 0x00, 0x00, + // 683 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4f, 0x6f, 0xd3, 0x4a, + 0x10, 0xcf, 0xbe, 0xb4, 0x79, 0xed, 0xb6, 0xaf, 0x0f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0x9f, 0x5e, 0x44, 0x2b, 0x45, + 0xa9, 0xb6, 0x96, 0x44, 0xaa, 0x46, 0xae, 0x12, 0x90, 0x11, 0xbf, 0x9a, 0x02, 0xfa, 0x08, 0x6f, + 0xbf, 0x94, 0x6f, 0xf3, 0xa7, 0x34, 0x66, 0x64, 0x1a, 0x5a, 0x12, 0xa9, 0x0f, 0x7b, 0x97, 0x81, + 0x33, 0x29, 0x5c, 0xce, 0xac, 0x3f, 0x3b, 0x38, 0xc4, 0x85, 0xe1, 0x21, 0x2e, 0x1c, 0x1f, 0x62, + 0xf0, 0x29, 0xc6, 0xe0, 0x7b, 0x8c, 0xc1, 0x7e, 0x8c, 0xc1, 0x41, 0x8c, 0xc1, 0x30, 0xc6, 0xe0, + 0x67, 0x8c, 0xc1, 0xaf, 0x18, 0x17, 0x8e, 0x63, 0x0c, 0xbe, 0x1e, 0xe1, 0xc2, 0xc1, 0x11, 0x2e, + 0x0c, 0x8f, 0x70, 0xe1, 0xcd, 0xac, 0xfc, 0x73, 0x77, 0x4b, 0x72, 0x64, 0xd6, 0x7e, 0x07, 0x00, + 0x00, 0xff, 0xff, 0x94, 0xeb, 0x6a, 0x8a, 0x1b, 0x06, 0x00, 0x00, } +func (this *EpochStartSovereign) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EpochStartSovereign) + if !ok { + that2, ok := that.(EpochStartSovereign) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.Economics.Equal(&that1.Economics) { + return false + } + return true +} func (this *SovereignChainHeader) Equal(that interface{}) bool { if that == nil { return this == nil @@ -242,6 +345,21 @@ func (this *SovereignChainHeader) Equal(that interface{}) bool { if this.IsStartOfEpoch != that1.IsStartOfEpoch { return false } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + if !__caster.Equal(this.AccumulatedFeesInEpoch, that1.AccumulatedFeesInEpoch) { + return false + } + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + if !__caster.Equal(this.DevFeesInEpoch, that1.DevFeesInEpoch) { + return false + } + } + if !this.EpochStart.Equal(&that1.EpochStart) { + return false + } return true } func (this *OutGoingMiniBlockHeader) Equal(that interface{}) bool { @@ -277,11 +395,21 @@ func (this *OutGoingMiniBlockHeader) Equal(that interface{}) bool { } return true } +func (this *EpochStartSovereign) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&block.EpochStartSovereign{") + s = append(s, "Economics: "+strings.Replace(this.Economics.GoString(), `&`, ``, 1)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *SovereignChainHeader) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 9) + s := make([]string, 0, 12) s = append(s, "&block.SovereignChainHeader{") if this.Header != nil { s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") @@ -292,6 +420,9 @@ func (this *SovereignChainHeader) GoString() string { s = append(s, "OutGoingMiniBlockHeader: "+fmt.Sprintf("%#v", this.OutGoingMiniBlockHeader)+",\n") } s = append(s, "IsStartOfEpoch: "+fmt.Sprintf("%#v", this.IsStartOfEpoch)+",\n") + s = append(s, "AccumulatedFeesInEpoch: "+fmt.Sprintf("%#v", this.AccumulatedFeesInEpoch)+",\n") + s = append(s, "DevFeesInEpoch: "+fmt.Sprintf("%#v", this.DevFeesInEpoch)+",\n") + s = append(s, "EpochStart: "+strings.Replace(this.EpochStart.GoString(), `&`, ``, 1)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -316,6 +447,39 @@ func valueToGoStringSovereignChainHeader(v interface{}, typ string) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) } +func (m *EpochStartSovereign) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EpochStartSovereign) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EpochStartSovereign) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Economics.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func (m *SovereignChainHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -336,6 +500,38 @@ func (m *SovereignChainHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.EpochStart.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + size := __caster.Size(m.DevFeesInEpoch) + i -= size + if _, err := __caster.MarshalTo(m.DevFeesInEpoch, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + size := __caster.Size(m.AccumulatedFeesInEpoch) + i -= size + if _, err := __caster.MarshalTo(m.AccumulatedFeesInEpoch, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 if m.IsStartOfEpoch { i-- if m.IsStartOfEpoch { @@ -451,6 +647,17 @@ func encodeVarintSovereignChainHeader(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *EpochStartSovereign) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Economics.Size() + n += 1 + l + sovSovereignChainHeader(uint64(l)) + return n +} + func (m *SovereignChainHeader) Size() (n int) { if m == nil { return 0 @@ -478,6 +685,18 @@ func (m *SovereignChainHeader) Size() (n int) { if m.IsStartOfEpoch { n += 2 } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + l = __caster.Size(m.AccumulatedFeesInEpoch) + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + l = __caster.Size(m.DevFeesInEpoch) + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + l = m.EpochStart.Size() + n += 1 + l + sovSovereignChainHeader(uint64(l)) return n } @@ -512,6 +731,16 @@ func sovSovereignChainHeader(x uint64) (n int) { func sozSovereignChainHeader(x uint64) (n int) { return sovSovereignChainHeader(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (this *EpochStartSovereign) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&EpochStartSovereign{`, + `Economics:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Economics), "Economics", "Economics", 1), `&`, ``, 1) + `,`, + `}`, + }, "") + return s +} func (this *SovereignChainHeader) String() string { if this == nil { return "nil" @@ -522,6 +751,9 @@ func (this *SovereignChainHeader) String() string { `ExtendedShardHeaderHashes:` + fmt.Sprintf("%v", this.ExtendedShardHeaderHashes) + `,`, `OutGoingMiniBlockHeader:` + strings.Replace(this.OutGoingMiniBlockHeader.String(), "OutGoingMiniBlockHeader", "OutGoingMiniBlockHeader", 1) + `,`, `IsStartOfEpoch:` + fmt.Sprintf("%v", this.IsStartOfEpoch) + `,`, + `AccumulatedFeesInEpoch:` + fmt.Sprintf("%v", this.AccumulatedFeesInEpoch) + `,`, + `DevFeesInEpoch:` + fmt.Sprintf("%v", this.DevFeesInEpoch) + `,`, + `EpochStart:` + strings.Replace(strings.Replace(this.EpochStart.String(), "EpochStartSovereign", "EpochStartSovereign", 1), `&`, ``, 1) + `,`, `}`, }, "") return s @@ -547,6 +779,92 @@ func valueToStringSovereignChainHeader(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } +func (m *EpochStartSovereign) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EpochStartSovereign: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EpochStartSovereign: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Economics", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Economics.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -734,6 +1052,115 @@ func (m *SovereignChainHeader) Unmarshal(dAtA []byte) error { } } m.IsStartOfEpoch = bool(v != 0) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AccumulatedFeesInEpoch", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.AccumulatedFeesInEpoch = tmp + } + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DevFeesInEpoch", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.DevFeesInEpoch = tmp + } + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStart", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.EpochStart.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index 03f0ce882..d9c492b8b 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -8,6 +8,12 @@ option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "block.proto"; +import "metaBlock.proto"; + +// EpochStart holds the block information for end-of-epoch +message EpochStartSovereign { + Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false]; +} // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain message SovereignChainHeader { @@ -16,6 +22,9 @@ message SovereignChainHeader { repeated bytes ExtendedShardHeaderHashes = 3 [(gogoproto.jsontag) = "extendedShardHeaderHashes,omitempty"]; OutGoingMiniBlockHeader OutGoingMiniBlockHeader = 4 [(gogoproto.jsontag) = "outGoingOperations,omitempty"]; bool IsStartOfEpoch = 5 [(gogoproto.jsontag) = "isStartOfEpoch,omitempty"]; + bytes AccumulatedFeesInEpoch = 6 [(gogoproto.jsontag) = "accumulatedFeesInEpoch,omitempty", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; + bytes DevFeesInEpoch = 7 [(gogoproto.jsontag) = "devFeesInEpoch,omitempty", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; + EpochStartSovereign EpochStart = 8 [(gogoproto.jsontag) = "epochStart,omitempty", (gogoproto.nullable) = false]; } message OutGoingMiniBlockHeader { From 7cda53fe4cf06a61079fbc17941aa19f06e17873 Mon Sep 17 00:00:00 2001 From: Marius C Date: Thu, 18 Jul 2024 16:03:47 +0300 Subject: [PATCH 77/87] FEAT: Extend interface --- data/interface.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/interface.go b/data/interface.go index 30891e5a3..ce2577c88 100644 --- a/data/interface.go +++ b/data/interface.go @@ -106,6 +106,10 @@ type SovereignChainHeaderHandler interface { GetExtendedShardHeaderHashes() [][]byte GetOutGoingMiniBlockHeaderHandler() OutGoingMiniBlockHeaderHandler SetOutGoingMiniBlockHeaderHandler(mbHeader OutGoingMiniBlockHeaderHandler) error + GetDevFeesInEpoch() *big.Int + SetDevFeesInEpoch(value *big.Int) error + GetAccumulatedFeesInEpoch() *big.Int + SetAccumulatedFeesInEpoch(value *big.Int) error SetStartOfEpochHeader() error } From aeae5015072f44fe082360d4d6ff99456542c988 Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 19 Jul 2024 11:23:28 +0300 Subject: [PATCH 78/87] FEAT: Extend meta header interface --- data/interface.go | 1 + 1 file changed, 1 insertion(+) diff --git a/data/interface.go b/data/interface.go index ce2577c88..863785349 100644 --- a/data/interface.go +++ b/data/interface.go @@ -162,6 +162,7 @@ type MetaHeaderHandler interface { HeaderHandler GetEpochStartHandler() EpochStartHandler GetDevFeesInEpoch() *big.Int + GetAccumulatedFeesInEpoch() *big.Int GetShardInfoHandlers() []ShardDataHandler SetDevFeesInEpoch(value *big.Int) error SetShardInfoHandlers(shardInfo []ShardDataHandler) error From ab81ad87746ce11edcc5797eb2fd6172b6d0562f Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 19 Jul 2024 12:16:56 +0300 Subject: [PATCH 79/87] FEAT: Extend sovereign chain header --- data/block/sovereignChainHeader.go | 30 ++++++++++++++++++++++++++++++ data/interface.go | 3 +++ 2 files changed, 33 insertions(+) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index bdf583ec3..fdeed3e59 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -631,6 +631,36 @@ func (sch *SovereignChainHeader) SetAccumulatedFeesInEpoch(value *big.Int) error return nil } +// GetEpochStartHandler returns epoch start header handler as for metachain, but without last finalized headers +func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler { + if sch == nil { + return nil + } + + return &EpochStart{ + LastFinalizedHeaders: make([]EpochStartShardData, 0), + Economics: sch.EpochStart.Economics, + } +} + +// GetShardInfoHandlers returns empty slice +func (sch *SovereignChainHeader) GetShardInfoHandlers() []data.ShardDataHandler { + if sch == nil { + return nil + } + + return make([]data.ShardDataHandler, 0) +} + +// SetShardInfoHandlers does nothing +func (sch *SovereignChainHeader) SetShardInfoHandlers(_ []data.ShardDataHandler) error { + if sch == nil { + return data.ErrNilPointerReceiver + } + + return nil +} + // SetHash returns the hash func (omb *OutGoingMiniBlockHeader) SetHash(hash []byte) error { if omb == nil { diff --git a/data/interface.go b/data/interface.go index 863785349..c94648118 100644 --- a/data/interface.go +++ b/data/interface.go @@ -111,6 +111,9 @@ type SovereignChainHeaderHandler interface { GetAccumulatedFeesInEpoch() *big.Int SetAccumulatedFeesInEpoch(value *big.Int) error SetStartOfEpochHeader() error + GetEpochStartHandler() EpochStartHandler + GetShardInfoHandlers() []ShardDataHandler + SetShardInfoHandlers(shardInfo []ShardDataHandler) error } // OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header From 50ac1ae238242de58dc03f8655c5f9cae83b6be3 Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 7 Oct 2024 14:33:00 +0300 Subject: [PATCH 80/87] CLN: Delete sovereign tx --- data/sovereignTx/sovereignTx.go | 57 --- data/sovereignTx/sovereignTx.pb.go | 701 --------------------------- data/sovereignTx/sovereignTx.proto | 19 - data/sovereignTx/sovereignTx_test.go | 90 ---- 4 files changed, 867 deletions(-) delete mode 100644 data/sovereignTx/sovereignTx.go delete mode 100644 data/sovereignTx/sovereignTx.pb.go delete mode 100644 data/sovereignTx/sovereignTx.proto delete mode 100644 data/sovereignTx/sovereignTx_test.go diff --git a/data/sovereignTx/sovereignTx.go b/data/sovereignTx/sovereignTx.go deleted file mode 100644 index a2fedab14..000000000 --- a/data/sovereignTx/sovereignTx.go +++ /dev/null @@ -1,57 +0,0 @@ -//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/multiversx/protobuf/protobuf --gogoslick_out=. sovereignTx.proto -package sovereignTx - -import ( - "github.com/multiversx/mx-chain-core-go/data" - "math/big" -) - -var _ = data.TransactionHandler(&SovereignTx{}) - -// IsInterfaceNil verifies if underlying object is nil -func (stx *SovereignTx) IsInterfaceNil() bool { - return stx == nil -} - -// SetValue sets the value of the sovereign transaction -func (stx *SovereignTx) SetValue(value *big.Int) { - stx.Value = value -} - -// SetData sets the data of the sovereign transaction -func (stx *SovereignTx) SetData(data []byte) { - stx.Data = data -} - -// SetRcvAddr sets the receiver address of the sovereign transaction -func (stx *SovereignTx) SetRcvAddr(addr []byte) { - stx.RcvAddr = addr -} - -// SetSndAddr sets the sender address of the sovereign transaction -func (stx *SovereignTx) SetSndAddr(addr []byte) { - stx.SndAddr = addr -} - -// GetRcvUserName returns nil for sovereign transaction -func (stx *SovereignTx) GetRcvUserName() []byte { - return nil -} - -// CheckIntegrity checks the integrity of sovereign transaction's fields -func (stx *SovereignTx) CheckIntegrity() error { - if len(stx.RcvAddr) == 0 { - return data.ErrNilRcvAddr - } - if len(stx.SndAddr) == 0 { - return data.ErrNilSndAddr - } - if stx.Value == nil { - return data.ErrNilValue - } - if stx.Value.Sign() < 0 { - return data.ErrNegativeValue - } - - return nil -} diff --git a/data/sovereignTx/sovereignTx.pb.go b/data/sovereignTx/sovereignTx.pb.go deleted file mode 100644 index a3f4a3e35..000000000 --- a/data/sovereignTx/sovereignTx.pb.go +++ /dev/null @@ -1,701 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sovereignTx.proto - -package sovereignTx - -import ( - bytes "bytes" - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_multiversx_mx_chain_core_go_data "github.com/multiversx/mx-chain-core-go/data" - io "io" - math "math" - math_big "math/big" - math_bits "math/bits" - reflect "reflect" - strings "strings" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -type SovereignTx struct { - Nonce uint64 `protobuf:"varint,1,opt,name=Nonce,proto3" json:"nonce"` - Value *math_big.Int `protobuf:"bytes,2,opt,name=Value,proto3,casttypewith=math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster" json:"value"` - RcvAddr []byte `protobuf:"bytes,3,opt,name=RcvAddr,proto3" json:"receiver"` - SndAddr []byte `protobuf:"bytes,4,opt,name=SndAddr,proto3" json:"sender"` - GasLimit uint64 `protobuf:"varint,5,opt,name=GasLimit,proto3" json:"gasLimit"` - GasPrice uint64 `protobuf:"varint,6,opt,name=GasPrice,proto3" json:"gasPrice"` - Data []byte `protobuf:"bytes,7,opt,name=Data,proto3" json:"data,omitempty"` -} - -func (m *SovereignTx) Reset() { *m = SovereignTx{} } -func (*SovereignTx) ProtoMessage() {} -func (*SovereignTx) Descriptor() ([]byte, []int) { - return fileDescriptor_3309200ee9b6aa5f, []int{0} -} -func (m *SovereignTx) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SovereignTx) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil -} -func (m *SovereignTx) XXX_Merge(src proto.Message) { - xxx_messageInfo_SovereignTx.Merge(m, src) -} -func (m *SovereignTx) XXX_Size() int { - return m.Size() -} -func (m *SovereignTx) XXX_DiscardUnknown() { - xxx_messageInfo_SovereignTx.DiscardUnknown(m) -} - -var xxx_messageInfo_SovereignTx proto.InternalMessageInfo - -func (m *SovereignTx) GetNonce() uint64 { - if m != nil { - return m.Nonce - } - return 0 -} - -func (m *SovereignTx) GetValue() *math_big.Int { - if m != nil { - return m.Value - } - return nil -} - -func (m *SovereignTx) GetRcvAddr() []byte { - if m != nil { - return m.RcvAddr - } - return nil -} - -func (m *SovereignTx) GetSndAddr() []byte { - if m != nil { - return m.SndAddr - } - return nil -} - -func (m *SovereignTx) GetGasLimit() uint64 { - if m != nil { - return m.GasLimit - } - return 0 -} - -func (m *SovereignTx) GetGasPrice() uint64 { - if m != nil { - return m.GasPrice - } - return 0 -} - -func (m *SovereignTx) GetData() []byte { - if m != nil { - return m.Data - } - return nil -} - -func init() { - proto.RegisterType((*SovereignTx)(nil), "proto.SovereignTx") -} - -func init() { proto.RegisterFile("sovereignTx.proto", fileDescriptor_3309200ee9b6aa5f) } - -var fileDescriptor_3309200ee9b6aa5f = []byte{ - // 385 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x91, 0xb1, 0xae, 0xd3, 0x30, - 0x14, 0x86, 0xe3, 0x4b, 0xd3, 0x5e, 0x7c, 0xaf, 0x90, 0xf0, 0x14, 0x31, 0x38, 0x57, 0x08, 0x5d, - 0x75, 0x20, 0xc9, 0xc0, 0xc8, 0x44, 0xe0, 0x0a, 0x55, 0x42, 0x08, 0xb9, 0x88, 0x81, 0xcd, 0x49, - 0x8c, 0x63, 0xa9, 0xb1, 0x2b, 0xc7, 0x89, 0xca, 0xc6, 0x23, 0xf0, 0x18, 0x88, 0x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04, 0x4e, 0xe6, 0xb2, 0x70, 0xdc, 0xc8, 0x71, 0xb0, 0xef, 0xc2, 0x71, 0xcd, - 0x64, 0x31, 0x50, 0x47, 0x0b, 0x4d, 0xe1, 0xe5, 0x6b, 0x5a, 0xbf, 0x11, 0x95, 0x30, 0x81, 0xef, - 0x66, 0x73, 0xed, 0xf8, 0x51, 0x23, 0x27, 0xf7, 0x48, 0xbe, 0xd3, 0x22, 0x67, 0xc1, 0xf8, 0x3f, - 0xd2, 0x69, 0xe4, 0xe4, 0xa2, 0x5b, 0x38, 0x7a, 0x45, 0x0d, 0x0d, 0x26, 0x2e, 0x16, 0xf5, 0x5d, - 0xf8, 0x60, 0x98, 0xe6, 0xa9, 0xaa, 0x84, 0x61, 0xd5, 0xd2, 0x7c, 0x26, 0xce, 0x4f, 0xef, 0xd6, - 0x5b, 0xec, 0x6d, 0xb6, 0xd8, 0xdb, 0x6f, 0x31, 0xf8, 0x62, 0x31, 0xf8, 0x66, 0x31, 0xf8, 0x61, - 0x31, 0x58, 0x5b, 0x0c, 0x36, 0x16, 0x83, 0x5f, 0x16, 0x83, 0xdf, 0x16, 0x7b, 0x7b, 0x8b, 0xc1, - 0xd7, 0x1d, 0xf6, 0xd6, 0x3b, 0xec, 0x6d, 0x76, 0xd8, 0xfb, 0x78, 0x75, 0xb6, 0xe7, 0x6c, 0xec, - 0x56, 0xf6, 0xec, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x87, 0xb5, 0xbe, 0x2f, 0xfd, 0x01, 0x00, - 0x00, -} - -func (this *SovereignTx) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*SovereignTx) - if !ok { - that2, ok := that.(SovereignTx) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Nonce != that1.Nonce { - return false - } - { - __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} - if !__caster.Equal(this.Value, that1.Value) { - return false - } - } - if !bytes.Equal(this.RcvAddr, that1.RcvAddr) { - return false - } - if !bytes.Equal(this.SndAddr, that1.SndAddr) { - return false - } - if this.GasLimit != that1.GasLimit { - return false - } - if this.GasPrice != that1.GasPrice { - return false - } - if !bytes.Equal(this.Data, that1.Data) { - return false - } - return true -} -func (this *SovereignTx) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 11) - s = append(s, "&sovereignTx.SovereignTx{") - s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") - s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") - s = append(s, "RcvAddr: "+fmt.Sprintf("%#v", this.RcvAddr)+",\n") - s = append(s, "SndAddr: "+fmt.Sprintf("%#v", this.SndAddr)+",\n") - s = append(s, "GasLimit: "+fmt.Sprintf("%#v", this.GasLimit)+",\n") - s = append(s, "GasPrice: "+fmt.Sprintf("%#v", this.GasPrice)+",\n") - s = append(s, "Data: "+fmt.Sprintf("%#v", this.Data)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringSovereignTx(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *SovereignTx) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SovereignTx) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SovereignTx) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Data) > 0 { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintSovereignTx(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x3a - } - if m.GasPrice != 0 { - i = encodeVarintSovereignTx(dAtA, i, uint64(m.GasPrice)) - i-- - dAtA[i] = 0x30 - } - if m.GasLimit != 0 { - i = encodeVarintSovereignTx(dAtA, i, uint64(m.GasLimit)) - i-- - dAtA[i] = 0x28 - } - if len(m.SndAddr) > 0 { - i -= len(m.SndAddr) - copy(dAtA[i:], m.SndAddr) - i = encodeVarintSovereignTx(dAtA, i, uint64(len(m.SndAddr))) - i-- - dAtA[i] = 0x22 - } - if len(m.RcvAddr) > 0 { - i -= len(m.RcvAddr) - copy(dAtA[i:], m.RcvAddr) - i = encodeVarintSovereignTx(dAtA, i, uint64(len(m.RcvAddr))) - i-- - dAtA[i] = 0x1a - } - { - __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} - size := __caster.Size(m.Value) - i -= size - if _, err := __caster.MarshalTo(m.Value, dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintSovereignTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.Nonce != 0 { - i = encodeVarintSovereignTx(dAtA, i, uint64(m.Nonce)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintSovereignTx(dAtA []byte, offset int, v uint64) int { - offset -= sovSovereignTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *SovereignTx) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Nonce != 0 { - n += 1 + sovSovereignTx(uint64(m.Nonce)) - } - { - __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} - l = __caster.Size(m.Value) - n += 1 + l + sovSovereignTx(uint64(l)) - } - l = len(m.RcvAddr) - if l > 0 { - n += 1 + l + sovSovereignTx(uint64(l)) - } - l = len(m.SndAddr) - if l > 0 { - n += 1 + l + sovSovereignTx(uint64(l)) - } - if m.GasLimit != 0 { - n += 1 + sovSovereignTx(uint64(m.GasLimit)) - } - if m.GasPrice != 0 { - n += 1 + sovSovereignTx(uint64(m.GasPrice)) - } - l = len(m.Data) - if l > 0 { - n += 1 + l + sovSovereignTx(uint64(l)) - } - return n -} - -func sovSovereignTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozSovereignTx(x uint64) (n int) { - return sovSovereignTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *SovereignTx) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&SovereignTx{`, - `Nonce:` + fmt.Sprintf("%v", this.Nonce) + `,`, - `Value:` + fmt.Sprintf("%v", this.Value) + `,`, - `RcvAddr:` + fmt.Sprintf("%v", this.RcvAddr) + `,`, - `SndAddr:` + fmt.Sprintf("%v", this.SndAddr) + `,`, - `GasLimit:` + fmt.Sprintf("%v", this.GasLimit) + `,`, - `GasPrice:` + fmt.Sprintf("%v", this.GasPrice) + `,`, - `Data:` + fmt.Sprintf("%v", this.Data) + `,`, - `}`, - }, "") - return s -} -func valueToStringSovereignTx(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *SovereignTx) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SovereignTx: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SovereignTx: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Nonce", wireType) - } - m.Nonce = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Nonce |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSovereignTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSovereignTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - { - __caster := &github_com_multiversx_mx_chain_core_go_data.BigIntCaster{} - if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } else { - m.Value = tmp - } - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RcvAddr", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSovereignTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSovereignTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RcvAddr = append(m.RcvAddr[:0], dAtA[iNdEx:postIndex]...) - if m.RcvAddr == nil { - m.RcvAddr = []byte{} - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SndAddr", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSovereignTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSovereignTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SndAddr = append(m.SndAddr[:0], dAtA[iNdEx:postIndex]...) - if m.SndAddr == nil { - m.SndAddr = []byte{} - } - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasLimit", wireType) - } - m.GasLimit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GasLimit |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasPrice", wireType) - } - m.GasPrice = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GasPrice |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSovereignTx - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSovereignTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSovereignTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSovereignTx - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSovereignTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipSovereignTx(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSovereignTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthSovereignTx - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupSovereignTx - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthSovereignTx - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthSovereignTx = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSovereignTx = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupSovereignTx = fmt.Errorf("proto: unexpected end of group") -) diff --git a/data/sovereignTx/sovereignTx.proto b/data/sovereignTx/sovereignTx.proto deleted file mode 100644 index 033ec71f9..000000000 --- a/data/sovereignTx/sovereignTx.proto +++ /dev/null @@ -1,19 +0,0 @@ - -syntax = "proto3"; - -package proto; - -option go_package = "sovereignTx"; -option (gogoproto.stable_marshaler_all) = true; - -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -message SovereignTx { - uint64 Nonce = 1 [(gogoproto.jsontag) = "nonce"]; - bytes Value = 2 [(gogoproto.jsontag) = "value", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"]; - bytes RcvAddr = 3 [(gogoproto.jsontag) = "receiver"]; - bytes SndAddr = 4 [(gogoproto.jsontag) = "sender"]; - uint64 GasLimit = 5 [(gogoproto.jsontag) = "gasLimit"]; - uint64 GasPrice = 6 [(gogoproto.jsontag) = "gasPrice"]; - bytes Data = 7 [(gogoproto.jsontag) = "data,omitempty"]; -} diff --git a/data/sovereignTx/sovereignTx_test.go b/data/sovereignTx/sovereignTx_test.go deleted file mode 100644 index eaf601d5a..000000000 --- a/data/sovereignTx/sovereignTx_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package sovereignTx_test - -import ( - "math/big" - "testing" - - "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-core-go/data/sovereignTx" - "github.com/stretchr/testify/assert" -) - -func TestSovereignTx_SettersAndGetters(t *testing.T) { - t.Parallel() - - nonce := uint64(5) - gasPrice := uint64(1) - gasLimit := uint64(10) - stx := sovereignTx.SovereignTx{ - Nonce: nonce, - GasPrice: gasPrice, - GasLimit: gasLimit, - } - - rcvAddr := []byte("rcv address") - sndAddr := []byte("snd address") - value := big.NewInt(37) - txData := []byte("data") - - stx.SetRcvAddr(rcvAddr) - stx.SetSndAddr(sndAddr) - stx.SetValue(value) - stx.SetData(txData) - - assert.Equal(t, sndAddr, stx.GetSndAddr()) - assert.Equal(t, rcvAddr, stx.GetRcvAddr()) - assert.Equal(t, value, stx.GetValue()) - assert.Equal(t, txData, stx.GetData()) - assert.Equal(t, gasLimit, stx.GetGasLimit()) - assert.Equal(t, gasPrice, stx.GetGasPrice()) - assert.Equal(t, nonce, stx.GetNonce()) -} - -func createValidSovereignTx() *sovereignTx.SovereignTx { - return &sovereignTx.SovereignTx{ - Nonce: 1, - Value: big.NewInt(10), - GasPrice: 1, - GasLimit: 10, - Data: []byte("data"), - RcvAddr: []byte("rcv-address"), - SndAddr: []byte("snd-address"), - } -} - -func TestSovereignTx_CheckIntegrityShouldWork(t *testing.T) { - t.Parallel() - - stx := createValidSovereignTx() - err := stx.CheckIntegrity() - - assert.Nil(t, err) -} - -func TestSovereignTx_CheckIntegrityShouldErr(t *testing.T) { - t.Parallel() - - stx := createValidSovereignTx() - stx.RcvAddr = nil - err := stx.CheckIntegrity() - - assert.Equal(t, data.ErrNilRcvAddr, err) - - stx = createValidSovereignTx() - stx.SndAddr = nil - err = stx.CheckIntegrity() - - assert.Equal(t, data.ErrNilSndAddr, err) - - stx = createValidSovereignTx() - stx.Value = nil - err = stx.CheckIntegrity() - - assert.Equal(t, data.ErrNilValue, err) - - stx = createValidSovereignTx() - stx.Value = big.NewInt(-1) - err = stx.CheckIntegrity() - - assert.Equal(t, data.ErrNegativeValue, err) -} From c92f9091b8eaee3b6cbe9284a2f1abbccd0fc158 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 16 Oct 2024 11:25:27 +0300 Subject: [PATCH 81/87] FEAT: Add LastFinalizedCrossChainHeader --- data/block/sovereignChainHeader.go | 16 +- data/block/sovereignChainHeader.pb.go | 538 +++++++++++++++++++++++--- data/block/sovereignChainHeader.proto | 12 +- 3 files changed, 516 insertions(+), 50 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index fdeed3e59..9aef6efb2 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" @@ -637,8 +638,21 @@ func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler { return nil } + lastFinalizedCrossChainHeaderData := EpochStartShardData{ + ShardID: sch.EpochStart.LastFinalizedCrossChainHeader.ShardID, + Epoch: sch.EpochStart.LastFinalizedCrossChainHeader.Epoch, + Round: sch.EpochStart.LastFinalizedCrossChainHeader.Round, + Nonce: sch.EpochStart.LastFinalizedCrossChainHeader.Nonce, + HeaderHash: sch.EpochStart.LastFinalizedCrossChainHeader.HeaderHash, + } + + epochStartShardData := make([]EpochStartShardData, 0) + if lastFinalizedCrossChainHeaderData.ShardID == core.MainChainShardId { + epochStartShardData = append(epochStartShardData, lastFinalizedCrossChainHeaderData) + } + return &EpochStart{ - LastFinalizedHeaders: make([]EpochStartShardData, 0), + LastFinalizedHeaders: epochStartShardData, Economics: sch.EpochStart.Economics, } } diff --git a/data/block/sovereignChainHeader.pb.go b/data/block/sovereignChainHeader.pb.go index fa19576b1..e282df49c 100644 --- a/data/block/sovereignChainHeader.pb.go +++ b/data/block/sovereignChainHeader.pb.go @@ -30,7 +30,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // EpochStart holds the block information for end-of-epoch type EpochStartSovereign struct { - Economics Economics `protobuf:"bytes,1,opt,name=Economics,proto3" json:"economics"` + Economics Economics `protobuf:"bytes,1,opt,name=Economics,proto3" json:"economics"` + LastFinalizedCrossChainHeader EpochStartCrossChainData `protobuf:"bytes,2,opt,name=LastFinalizedCrossChainHeader,proto3" json:"lastFinalizedCrossChainHeader"` } func (m *EpochStartSovereign) Reset() { *m = EpochStartSovereign{} } @@ -68,6 +69,85 @@ func (m *EpochStartSovereign) GetEconomics() Economics { return Economics{} } +func (m *EpochStartSovereign) GetLastFinalizedCrossChainHeader() EpochStartCrossChainData { + if m != nil { + return m.LastFinalizedCrossChainHeader + } + return EpochStartCrossChainData{} +} + +// EpochStartShardData hold the last finalized headers hash and state root hash +type EpochStartCrossChainData struct { + ShardID uint32 `protobuf:"varint,1,opt,name=ShardID,proto3" json:"shardID"` + Epoch uint32 `protobuf:"varint,9,opt,name=Epoch,proto3" json:"epoch"` + Round uint64 `protobuf:"varint,7,opt,name=Round,proto3" json:"round"` + Nonce uint64 `protobuf:"varint,8,opt,name=Nonce,proto3" json:"nonce"` + HeaderHash []byte `protobuf:"bytes,2,opt,name=HeaderHash,proto3" json:"headerHash,omitempty"` +} + +func (m *EpochStartCrossChainData) Reset() { *m = EpochStartCrossChainData{} } +func (*EpochStartCrossChainData) ProtoMessage() {} +func (*EpochStartCrossChainData) Descriptor() ([]byte, []int) { + return fileDescriptor_b9b8ff297a820152, []int{1} +} +func (m *EpochStartCrossChainData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EpochStartCrossChainData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *EpochStartCrossChainData) XXX_Merge(src proto.Message) { + xxx_messageInfo_EpochStartCrossChainData.Merge(m, src) +} +func (m *EpochStartCrossChainData) XXX_Size() int { + return m.Size() +} +func (m *EpochStartCrossChainData) XXX_DiscardUnknown() { + xxx_messageInfo_EpochStartCrossChainData.DiscardUnknown(m) +} + +var xxx_messageInfo_EpochStartCrossChainData proto.InternalMessageInfo + +func (m *EpochStartCrossChainData) GetShardID() uint32 { + if m != nil { + return m.ShardID + } + return 0 +} + +func (m *EpochStartCrossChainData) GetEpoch() uint32 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *EpochStartCrossChainData) GetRound() uint64 { + if m != nil { + return m.Round + } + return 0 +} + +func (m *EpochStartCrossChainData) GetNonce() uint64 { + if m != nil { + return m.Nonce + } + return 0 +} + +func (m *EpochStartCrossChainData) GetHeaderHash() []byte { + if m != nil { + return m.HeaderHash + } + return nil +} + // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain type SovereignChainHeader struct { Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"header"` @@ -83,7 +163,7 @@ type SovereignChainHeader struct { func (m *SovereignChainHeader) Reset() { *m = SovereignChainHeader{} } func (*SovereignChainHeader) ProtoMessage() {} func (*SovereignChainHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_b9b8ff297a820152, []int{1} + return fileDescriptor_b9b8ff297a820152, []int{2} } func (m *SovereignChainHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -174,7 +254,7 @@ type OutGoingMiniBlockHeader struct { func (m *OutGoingMiniBlockHeader) Reset() { *m = OutGoingMiniBlockHeader{} } func (*OutGoingMiniBlockHeader) ProtoMessage() {} func (*OutGoingMiniBlockHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_b9b8ff297a820152, []int{2} + return fileDescriptor_b9b8ff297a820152, []int{3} } func (m *OutGoingMiniBlockHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -229,6 +309,7 @@ func (m *OutGoingMiniBlockHeader) GetLeaderSignatureOutGoingOperations() []byte func init() { proto.RegisterType((*EpochStartSovereign)(nil), "proto.EpochStartSovereign") + proto.RegisterType((*EpochStartCrossChainData)(nil), "proto.EpochStartCrossChainData") proto.RegisterType((*SovereignChainHeader)(nil), "proto.SovereignChainHeader") proto.RegisterType((*OutGoingMiniBlockHeader)(nil), "proto.OutGoingMiniBlockHeader") } @@ -236,50 +317,59 @@ func init() { func init() { proto.RegisterFile("sovereignChainHeader.proto", fileDescriptor_b9b8ff297a820152) } var fileDescriptor_b9b8ff297a820152 = []byte{ - // 683 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00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ae, 0x1c, 0x0e, 0xf4, 0x19, 0xc0, 0x7b, 0xeb, - 0xb6, 0xed, 0x53, 0x7b, 0xd4, 0xa5, 0x0e, 0xb3, 0x3d, 0x22, 0x42, 0x9f, 0x5e, 0x44, 0x2b, 0x45, - 0xa9, 0xb6, 0x96, 0x44, 0xaa, 0x46, 0xae, 0x12, 0x90, 0x11, 0xbf, 0x9a, 0x02, 0xfa, 0x08, 0x6f, - 0xbf, 0x94, 0x6f, 0xf3, 0xa7, 0x34, 0x66, 0x64, 0x1a, 0x5a, 0x12, 0xa9, 0x0f, 0x7b, 0x97, 0x81, - 0x33, 0x29, 0x5c, 0xce, 0xac, 0x3f, 0x3b, 0x38, 0xc4, 0x85, 0xe1, 0x21, 0x2e, 0x1c, 0x1f, 0x62, - 0xf0, 0x29, 0xc6, 0xe0, 0x7b, 0x8c, 0xc1, 0x7e, 0x8c, 0xc1, 0x41, 0x8c, 0xc1, 0x30, 0xc6, 0xe0, - 0x67, 0x8c, 0xc1, 0xaf, 0x18, 0x17, 0x8e, 0x63, 0x0c, 0xbe, 0x1e, 0xe1, 0xc2, 0xc1, 0x11, 0x2e, - 0x0c, 0x8f, 0x70, 0xe1, 0xcd, 0xac, 0xfc, 0x73, 0x77, 0x4b, 0x72, 0x64, 0xd6, 0x7e, 0x07, 0x00, - 0x00, 0xff, 0xff, 0x94, 0xeb, 0x6a, 0x8a, 0x1b, 0x06, 0x00, 0x00, + // 821 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4f, 0x8f, 0xdb, 0x44, + 0x14, 0xcf, 0xb0, 0x9b, 0xa4, 0x99, 0xb4, 0x0b, 0x0c, 0xab, 0x60, 0xa2, 0xad, 0x27, 0x04, 0x16, + 0x22, 0x41, 0x12, 0xd1, 0x5e, 0x90, 0x38, 0xa0, 0xf5, 0x26, 0xa5, 0x91, 0x0a, 0x91, 0x1c, 0x09, +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a, 0xd6, 0x91, 0x0a, 0xfe, 0x89, 0x54, 0xf0, 0x5f, 0xa4, 0x56, 0x9e, + 0x47, 0x2a, 0xf8, 0xe3, 0x52, 0xad, 0x9c, 0x5f, 0xaa, 0x95, 0xf5, 0xa5, 0x5a, 0xf9, 0xbe, 0x2a, + 0x3f, 0x95, 0xf3, 0x9a, 0x1c, 0x99, 0xfb, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x70, 0xb9, 0xae, + 0xb8, 0x8c, 0x07, 0x00, 0x00, } func (this *EpochStartSovereign) Equal(that interface{}) bool { @@ -304,6 +394,45 @@ func (this *EpochStartSovereign) Equal(that interface{}) bool { if !this.Economics.Equal(&that1.Economics) { return false } + if !this.LastFinalizedCrossChainHeader.Equal(&that1.LastFinalizedCrossChainHeader) { + return false + } + return true +} +func (this *EpochStartCrossChainData) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*EpochStartCrossChainData) + if !ok { + that2, ok := that.(EpochStartCrossChainData) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ShardID != that1.ShardID { + return false + } + if this.Epoch != that1.Epoch { + return false + } + if this.Round != that1.Round { + return false + } + if this.Nonce != that1.Nonce { + return false + } + if !bytes.Equal(this.HeaderHash, that1.HeaderHash) { + return false + } return true } func (this *SovereignChainHeader) Equal(that interface{}) bool { @@ -399,9 +528,24 @@ func (this *EpochStartSovereign) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 5) + s := make([]string, 0, 6) s = append(s, "&block.EpochStartSovereign{") s = append(s, "Economics: "+strings.Replace(this.Economics.GoString(), `&`, ``, 1)+",\n") + s = append(s, "LastFinalizedCrossChainHeader: "+strings.Replace(this.LastFinalizedCrossChainHeader.GoString(), `&`, ``, 1)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *EpochStartCrossChainData) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 9) + s = append(s, "&block.EpochStartCrossChainData{") + s = append(s, "ShardID: "+fmt.Sprintf("%#v", this.ShardID)+",\n") + s = append(s, "Epoch: "+fmt.Sprintf("%#v", this.Epoch)+",\n") + s = append(s, "Round: "+fmt.Sprintf("%#v", this.Round)+",\n") + s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") + s = append(s, "HeaderHash: "+fmt.Sprintf("%#v", this.HeaderHash)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -467,6 +611,16 @@ func (m *EpochStartSovereign) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.LastFinalizedCrossChainHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 { size, err := m.Economics.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -480,6 +634,56 @@ func (m *EpochStartSovereign) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *EpochStartCrossChainData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EpochStartCrossChainData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EpochStartCrossChainData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Epoch != 0 { + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x48 + } + if m.Nonce != 0 { + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(m.Nonce)) + i-- + dAtA[i] = 0x40 + } + if m.Round != 0 { + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(m.Round)) + i-- + dAtA[i] = 0x38 + } + if len(m.HeaderHash) > 0 { + i -= len(m.HeaderHash) + copy(dAtA[i:], m.HeaderHash) + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(len(m.HeaderHash))) + i-- + dAtA[i] = 0x12 + } + if m.ShardID != 0 { + i = encodeVarintSovereignChainHeader(dAtA, i, uint64(m.ShardID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *SovereignChainHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -655,6 +859,33 @@ func (m *EpochStartSovereign) Size() (n int) { _ = l l = m.Economics.Size() n += 1 + l + sovSovereignChainHeader(uint64(l)) + l = m.LastFinalizedCrossChainHeader.Size() + n += 1 + l + sovSovereignChainHeader(uint64(l)) + return n +} + +func (m *EpochStartCrossChainData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ShardID != 0 { + n += 1 + sovSovereignChainHeader(uint64(m.ShardID)) + } + l = len(m.HeaderHash) + if l > 0 { + n += 1 + l + sovSovereignChainHeader(uint64(l)) + } + if m.Round != 0 { + n += 1 + sovSovereignChainHeader(uint64(m.Round)) + } + if m.Nonce != 0 { + n += 1 + sovSovereignChainHeader(uint64(m.Nonce)) + } + if m.Epoch != 0 { + n += 1 + sovSovereignChainHeader(uint64(m.Epoch)) + } return n } @@ -737,6 +968,21 @@ func (this *EpochStartSovereign) String() string { } s := strings.Join([]string{`&EpochStartSovereign{`, `Economics:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Economics), "Economics", "Economics", 1), `&`, ``, 1) + `,`, + `LastFinalizedCrossChainHeader:` + strings.Replace(strings.Replace(this.LastFinalizedCrossChainHeader.String(), "EpochStartCrossChainData", "EpochStartCrossChainData", 1), `&`, ``, 1) + `,`, + `}`, + }, "") + return s +} +func (this *EpochStartCrossChainData) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&EpochStartCrossChainData{`, + `ShardID:` + fmt.Sprintf("%v", this.ShardID) + `,`, + `HeaderHash:` + fmt.Sprintf("%v", this.HeaderHash) + `,`, + `Round:` + fmt.Sprintf("%v", this.Round) + `,`, + `Nonce:` + fmt.Sprintf("%v", this.Nonce) + `,`, + `Epoch:` + fmt.Sprintf("%v", this.Epoch) + `,`, `}`, }, "") return s @@ -841,6 +1087,202 @@ func (m *EpochStartSovereign) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastFinalizedCrossChainHeader", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LastFinalizedCrossChainHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *EpochStartCrossChainData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EpochStartCrossChainData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EpochStartCrossChainData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ShardID", wireType) + } + m.ShardID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ShardID |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field HeaderHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSovereignChainHeader + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSovereignChainHeader + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.HeaderHash = append(m.HeaderHash[:0], dAtA[iNdEx:postIndex]...) + if m.HeaderHash == nil { + m.HeaderHash = []byte{} + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Round", wireType) + } + m.Round = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Round |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Nonce", wireType) + } + m.Nonce = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Nonce |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSovereignChainHeader + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipSovereignChainHeader(dAtA[iNdEx:]) diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index d9c492b8b..0c535a38c 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -12,7 +12,17 @@ import "metaBlock.proto"; // EpochStart holds the block information for end-of-epoch message EpochStartSovereign { - Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false]; + Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false]; + EpochStartCrossChainData LastFinalizedCrossChainHeader = 2 [(gogoproto.jsontag) = "lastFinalizedCrossChainHeader", (gogoproto.nullable) = false]; +} + +// EpochStartShardData hold the last finalized headers hash and state root hash +message EpochStartCrossChainData { + uint32 ShardID = 1 [(gogoproto.jsontag) = "shardID"]; + uint32 Epoch = 9 [(gogoproto.jsontag) = "epoch"]; + uint64 Round = 7 [(gogoproto.jsontag) = "round"]; + uint64 Nonce = 8 [(gogoproto.jsontag) = "nonce"]; + bytes HeaderHash = 2 [(gogoproto.jsontag) = "headerHash,omitempty"]; } // SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain From f6bd53cf977785f2515217826c21e1b28a30d2bf Mon Sep 17 00:00:00 2001 From: Marius C Date: Fri, 18 Oct 2024 15:14:22 +0300 Subject: [PATCH 82/87] FEAT: Extend sov header with EpochStartChainDataHandler interfaces --- data/block/sovereignChainHeader.go | 66 ++++++++++++++++++++++++++- data/block/sovereignChainHeader.proto | 2 +- data/interface.go | 20 +++++--- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 9aef6efb2..4ad8e3759 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -632,7 +632,7 @@ func (sch *SovereignChainHeader) SetAccumulatedFeesInEpoch(value *big.Int) error return nil } -// GetEpochStartHandler returns epoch start header handler as for metachain, but without last finalized headers +// GetEpochStartHandler returns epoch start header handler as for metachain, but with last finalized headers from main chain, if found. func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler { if sch == nil { return nil @@ -657,6 +657,15 @@ func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler { } } +// GetLastFinalizedCrossChainHeaderHandler returns the last finalized cross chain header data +func (sch *SovereignChainHeader) GetLastFinalizedCrossChainHeaderHandler() data.EpochStartChainDataHandler { + if sch == nil { + return nil + } + + return &sch.EpochStart.LastFinalizedCrossChainHeader +} + // GetShardInfoHandlers returns empty slice func (sch *SovereignChainHeader) GetShardInfoHandlers() []data.ShardDataHandler { if sch == nil { @@ -719,3 +728,58 @@ func (omb *OutGoingMiniBlockHeader) SetAggregatedSignatureOutGoingOperations(sig func (omb *OutGoingMiniBlockHeader) IsInterfaceNil() bool { return omb == nil } + +// SetShardID sets the epoch start shardID +func (essd *EpochStartCrossChainData) SetShardID(shardID uint32) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.ShardID = shardID + + return nil +} + +// SetEpoch sets the epoch start epoch +func (essd *EpochStartCrossChainData) SetEpoch(epoch uint32) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Epoch = epoch + + return nil +} + +// SetRound sets the epoch start round +func (essd *EpochStartCrossChainData) SetRound(round uint64) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Round = round + + return nil +} + +// SetNonce sets the epoch start nonce +func (essd *EpochStartCrossChainData) SetNonce(nonce uint64) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Nonce = nonce + + return nil +} + +// SetHeaderHash sets the epoch start header hash +func (essd *EpochStartCrossChainData) SetHeaderHash(hash []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.HeaderHash = hash + + return nil +} diff --git a/data/block/sovereignChainHeader.proto b/data/block/sovereignChainHeader.proto index 0c535a38c..ad63cf56a 100644 --- a/data/block/sovereignChainHeader.proto +++ b/data/block/sovereignChainHeader.proto @@ -12,7 +12,7 @@ import "metaBlock.proto"; // EpochStart holds the block information for end-of-epoch message EpochStartSovereign { - Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false]; + Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false]; EpochStartCrossChainData LastFinalizedCrossChainHeader = 2 [(gogoproto.jsontag) = "lastFinalizedCrossChainHeader", (gogoproto.nullable) = false]; } diff --git a/data/interface.go b/data/interface.go index 31d349a19..974097673 100644 --- a/data/interface.go +++ b/data/interface.go @@ -114,6 +114,7 @@ type SovereignChainHeaderHandler interface { GetEpochStartHandler() EpochStartHandler GetShardInfoHandlers() []ShardDataHandler SetShardInfoHandlers(shardInfo []ShardDataHandler) error + GetLastFinalizedCrossChainHeaderHandler() EpochStartChainDataHandler } // OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header @@ -243,23 +244,30 @@ type ShardDataHandler interface { ShallowClone() ShardDataHandler } -// EpochStartShardDataHandler defines setters and getters for EpochStartShardData -type EpochStartShardDataHandler interface { +// EpochStartChainDataHandler defines setters and getters for basic information related to epoch start data +type EpochStartChainDataHandler interface { GetShardID() uint32 GetEpoch() uint32 GetRound() uint64 GetNonce() uint64 GetHeaderHash() []byte - GetRootHash() []byte - GetFirstPendingMetaBlock() []byte - GetLastFinishedMetaBlock() []byte - GetPendingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler SetShardID(uint32) error SetEpoch(uint32) error SetRound(uint64) error SetNonce(uint64) error SetHeaderHash([]byte) error +} + +// EpochStartShardDataHandler defines setters and getters for EpochStartShardData +type EpochStartShardDataHandler interface { + EpochStartChainDataHandler + + GetRootHash() []byte + GetFirstPendingMetaBlock() []byte + GetLastFinishedMetaBlock() []byte + GetPendingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler + SetRootHash([]byte) error SetFirstPendingMetaBlock([]byte) error SetLastFinishedMetaBlock([]byte) error From e2451e147ab121ba759c5b1b76838541f0a07947 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 19 Nov 2024 10:24:58 +0200 Subject: [PATCH 83/87] token random seq correct validity check --- data/esdt/common.go | 20 +++++++++++++++++++- data/esdt/common_test.go | 10 +++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/data/esdt/common.go b/data/esdt/common.go index d2467ec4f..7d240b510 100644 --- a/data/esdt/common.go +++ b/data/esdt/common.go @@ -35,7 +35,7 @@ func IsValidPrefixedToken(token string) (string, bool) { } tokenRandSeq := tokenSplit[2] - if !(len(tokenRandSeq) >= esdtTickerNumRandChars) { + if !IsRandomSeqValid(tokenRandSeq) { return "", false } @@ -83,3 +83,21 @@ func IsTickerValid(ticker string) bool { func IsTokenTickerLenCorrect(tokenTickerLen int) bool { return !(tokenTickerLen < minLengthForTickerName || tokenTickerLen > maxLengthForTickerName) } + +// IsRandomSeqValid checks if the token random sequence is valid +func IsRandomSeqValid(randomSeq string) bool { + if len(randomSeq) != esdtTickerNumRandChars { + return false + } + + for _, ch := range randomSeq { + isSmallCharacter := ch >= 'a' && ch <= 'f' + isNumber := ch >= '0' && ch <= '9' + isReadable := isSmallCharacter || isNumber + if !isReadable { + return false + } + } + + return true +} diff --git a/data/esdt/common_test.go b/data/esdt/common_test.go index 8052c23a3..0e65fd9d5 100644 --- a/data/esdt/common_test.go +++ b/data/esdt/common_test.go @@ -7,19 +7,19 @@ import ( ) func TestIsValidPrefixedToken(t *testing.T) { - prefix, valid := IsValidPrefixedToken("sov1-TKN-coffee") + prefix, valid := IsValidPrefixedToken("sov1-TKN-c0ffee") require.True(t, valid) require.Equal(t, "sov1", prefix) - prefix, valid = IsValidPrefixedToken("sOv1-TKN-coffee") + prefix, valid = IsValidPrefixedToken("sOv1-TKN-c0ffee") require.False(t, valid) require.Equal(t, "", prefix) - prefix, valid = IsValidPrefixedToken("sov1-TkN-coffee") + prefix, valid = IsValidPrefixedToken("sov1-TkN-c0ffee") require.False(t, valid) require.Equal(t, "", prefix) - prefix, valid = IsValidPrefixedToken("sov1-TKN-coffe") + prefix, valid = IsValidPrefixedToken("sov1-TKN-c0ffe") require.False(t, valid) require.Equal(t, "", prefix) @@ -27,7 +27,7 @@ func TestIsValidPrefixedToken(t *testing.T) { require.False(t, valid) require.Equal(t, "", prefix) - prefix, valid = IsValidPrefixedToken("TKN-coffee") + prefix, valid = IsValidPrefixedToken("TKN-c0ffee") require.False(t, valid) require.Equal(t, "", prefix) } From 057bcad4b7a842f06c03a07e4e47ee49ef462a3b Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 9 Dec 2024 16:17:03 +0200 Subject: [PATCH 84/87] FEAT: Extend sovereign EpochStart data interface with correct pointer receiver --- data/block/sovereignChainHeader.go | 157 ++++++++++++++++++++++++++++- data/interface.go | 2 +- 2 files changed, 155 insertions(+), 4 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index fdeed3e59..5526e4f34 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" @@ -637,10 +638,20 @@ func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler { return nil } - return &EpochStart{ - LastFinalizedHeaders: make([]EpochStartShardData, 0), - Economics: sch.EpochStart.Economics, + lastFinalizedCrossChainHeaderData := EpochStartShardData{ + ShardID: sch.EpochStart.LastFinalizedCrossChainHeader.ShardID, + Epoch: sch.EpochStart.LastFinalizedCrossChainHeader.Epoch, + Round: sch.EpochStart.LastFinalizedCrossChainHeader.Round, + Nonce: sch.EpochStart.LastFinalizedCrossChainHeader.Nonce, + HeaderHash: sch.EpochStart.LastFinalizedCrossChainHeader.HeaderHash, } + + epochStartShardData := make([]EpochStartShardData, 0) + if lastFinalizedCrossChainHeaderData.ShardID == core.MainChainShardId { + epochStartShardData = append(epochStartShardData, lastFinalizedCrossChainHeaderData) + } + + return &sch.EpochStart } // GetShardInfoHandlers returns empty slice @@ -705,3 +716,143 @@ func (omb *OutGoingMiniBlockHeader) SetAggregatedSignatureOutGoingOperations(sig func (omb *OutGoingMiniBlockHeader) IsInterfaceNil() bool { return omb == nil } + +// SetShardID sets the epoch start shardID +func (essd *EpochStartCrossChainData) SetShardID(shardID uint32) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.ShardID = shardID + + return nil +} + +// SetEpoch sets the epoch start epoch +func (essd *EpochStartCrossChainData) SetEpoch(epoch uint32) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Epoch = epoch + + return nil +} + +// SetRound sets the epoch start round +func (essd *EpochStartCrossChainData) SetRound(round uint64) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Round = round + + return nil +} + +// SetNonce sets the epoch start nonce +func (essd *EpochStartCrossChainData) SetNonce(nonce uint64) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Nonce = nonce + + return nil +} + +// SetHeaderHash sets the epoch start header hash +func (essd *EpochStartCrossChainData) SetHeaderHash(hash []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.HeaderHash = hash + + return nil +} + +func (essd *EpochStartCrossChainData) GetRootHash() []byte { + return nil +} +func (essd *EpochStartCrossChainData) GetFirstPendingMetaBlock() []byte { + return nil +} +func (essd *EpochStartCrossChainData) GetLastFinishedMetaBlock() []byte { + return nil +} +func (essd *EpochStartCrossChainData) GetPendingMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + return make([]data.MiniBlockHeaderHandler, 0) +} + +func (essd *EpochStartCrossChainData) SetRootHash([]byte) error { + return nil +} +func (essd *EpochStartCrossChainData) SetFirstPendingMetaBlock([]byte) error { + return nil +} +func (essd *EpochStartCrossChainData) SetLastFinishedMetaBlock([]byte) error { + return nil +} +func (essd *EpochStartCrossChainData) SetPendingMiniBlockHeaders(_ []data.MiniBlockHeaderHandler) error { + return nil +} + +func (m *EpochStartSovereign) GetLastFinalizedHeaderHandlers() []data.EpochStartShardDataHandler { + if m == nil { + return nil + } + + epochStartShardData := make([]data.EpochStartShardDataHandler, 0) + if m.LastFinalizedCrossChainHeader.ShardID == core.MainChainShardId { + epochStartShardData = append(epochStartShardData, &m.LastFinalizedCrossChainHeader) + } + + return epochStartShardData +} + +func (m *EpochStartSovereign) GetEconomicsHandler() data.EconomicsHandler { + if m == nil { + return nil + } + + return &m.Economics +} + +func (m *EpochStartSovereign) SetLastFinalizedHeaders(epochStartShardDataHandlers []data.EpochStartShardDataHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + for _, epochStartShardData := range epochStartShardDataHandlers { + if epochStartShardData.GetShardID() == core.MainChainShardId { + m.LastFinalizedCrossChainHeader = EpochStartCrossChainData{ + ShardID: epochStartShardData.GetShardID(), + Epoch: epochStartShardData.GetEpoch(), + Round: epochStartShardData.GetRound(), + Nonce: epochStartShardData.GetNonce(), + HeaderHash: epochStartShardData.GetHeaderHash(), + } + } + } + + return data.ErrNilPointerReceiver +} + +func (m *EpochStartSovereign) SetEconomics(economicsHandler data.EconomicsHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + ec, ok := economicsHandler.(*Economics) + if !ok { + return data.ErrInvalidTypeAssertion + } + if ec == nil { + return data.ErrNilPointerDereference + } + + m.Economics = *ec + + return nil +} diff --git a/data/interface.go b/data/interface.go index 31d349a19..a6cf9da7e 100644 --- a/data/interface.go +++ b/data/interface.go @@ -309,7 +309,7 @@ type BodyHandler interface { Clone() BodyHandler // IntegrityAndValidity checks the integrity and validity of the block IntegrityAndValidity() error - // IsInterfaceNil returns true if there is no value under the interface + // IsInterfaceNil returns true if there is no valkue under the interface IsInterfaceNil() bool } From 1a8ee42b2c323e88a2c5c2a6213dd6e0ac48f0a0 Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 9 Dec 2024 16:22:15 +0200 Subject: [PATCH 85/87] CLN: After merge + comms --- data/block/sovereignChainHeader.go | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/data/block/sovereignChainHeader.go b/data/block/sovereignChainHeader.go index 75b773ca5..09d7941d2 100644 --- a/data/block/sovereignChainHeader.go +++ b/data/block/sovereignChainHeader.go @@ -638,19 +638,6 @@ func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler { return nil } - lastFinalizedCrossChainHeaderData := EpochStartShardData{ - ShardID: sch.EpochStart.LastFinalizedCrossChainHeader.ShardID, - Epoch: sch.EpochStart.LastFinalizedCrossChainHeader.Epoch, - Round: sch.EpochStart.LastFinalizedCrossChainHeader.Round, - Nonce: sch.EpochStart.LastFinalizedCrossChainHeader.Nonce, - HeaderHash: sch.EpochStart.LastFinalizedCrossChainHeader.HeaderHash, - } - - epochStartShardData := make([]EpochStartShardData, 0) - if lastFinalizedCrossChainHeaderData.ShardID == core.MainChainShardId { - epochStartShardData = append(epochStartShardData, lastFinalizedCrossChainHeaderData) - } - return &sch.EpochStart } @@ -781,32 +768,47 @@ func (essd *EpochStartCrossChainData) SetHeaderHash(hash []byte) error { return nil } +// GetRootHash returns nothing func (essd *EpochStartCrossChainData) GetRootHash() []byte { return nil } + +// GetFirstPendingMetaBlock returns nothing func (essd *EpochStartCrossChainData) GetFirstPendingMetaBlock() []byte { return nil } + +// GetLastFinishedMetaBlock returns nothing func (essd *EpochStartCrossChainData) GetLastFinishedMetaBlock() []byte { return nil } + +// GetPendingMiniBlockHeaderHandlers returns empty slice func (essd *EpochStartCrossChainData) GetPendingMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { return make([]data.MiniBlockHeaderHandler, 0) } +// SetRootHash does nothing func (essd *EpochStartCrossChainData) SetRootHash([]byte) error { return nil } + +// SetFirstPendingMetaBlock does nothing func (essd *EpochStartCrossChainData) SetFirstPendingMetaBlock([]byte) error { return nil } + +// SetLastFinishedMetaBlock does nothing func (essd *EpochStartCrossChainData) SetLastFinishedMetaBlock([]byte) error { return nil } + +// SetPendingMiniBlockHeaders does nothing func (essd *EpochStartCrossChainData) SetPendingMiniBlockHeaders(_ []data.MiniBlockHeaderHandler) error { return nil } +// GetLastFinalizedHeaderHandlers returns last cross main chain finalized header in a slice w.r.t to the interface func (m *EpochStartSovereign) GetLastFinalizedHeaderHandlers() []data.EpochStartShardDataHandler { if m == nil { return nil @@ -820,6 +822,7 @@ func (m *EpochStartSovereign) GetLastFinalizedHeaderHandlers() []data.EpochStart return epochStartShardData } +// GetEconomicsHandler returns the economics func (m *EpochStartSovereign) GetEconomicsHandler() data.EconomicsHandler { if m == nil { return nil @@ -828,6 +831,7 @@ func (m *EpochStartSovereign) GetEconomicsHandler() data.EconomicsHandler { return &m.Economics } +// SetLastFinalizedHeaders sets epoch start data for main chain chain only func (m *EpochStartSovereign) SetLastFinalizedHeaders(epochStartShardDataHandlers []data.EpochStartShardDataHandler) error { if m == nil { return data.ErrNilPointerReceiver @@ -845,9 +849,10 @@ func (m *EpochStartSovereign) SetLastFinalizedHeaders(epochStartShardDataHandler } } - return data.ErrNilPointerReceiver + return nil } +// SetEconomics sets economics func (m *EpochStartSovereign) SetEconomics(economicsHandler data.EconomicsHandler) error { if m == nil { return data.ErrNilPointerReceiver From 762196f8dd066b3ae6becaa6a92b1e240b918b9a Mon Sep 17 00:00:00 2001 From: Marius C Date: Mon, 9 Dec 2024 16:24:14 +0200 Subject: [PATCH 86/87] FIX: Typo --- data/interface.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/interface.go b/data/interface.go index d7040b8a0..ee2f0ed0d 100644 --- a/data/interface.go +++ b/data/interface.go @@ -317,7 +317,7 @@ type BodyHandler interface { Clone() BodyHandler // IntegrityAndValidity checks the integrity and validity of the block IntegrityAndValidity() error - // IsInterfaceNil returns true if there is no valkue under the interface + // IsInterfaceNil returns true if there is no value under the interface IsInterfaceNil() bool } From 5ea61e5dfe4b072742e9e4b52084fb48da96921b Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 11 Dec 2024 11:14:01 +0200 Subject: [PATCH 87/87] FEAT: Add unit tests sovereignChainHeader_test.go --- data/block/sovereignChainHeader_test.go | 67 +++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 data/block/sovereignChainHeader_test.go diff --git a/data/block/sovereignChainHeader_test.go b/data/block/sovereignChainHeader_test.go new file mode 100644 index 000000000..fa6535c28 --- /dev/null +++ b/data/block/sovereignChainHeader_test.go @@ -0,0 +1,67 @@ +package block + +import ( + "math/big" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data" +) + +func TestSovereignChainHeader_GetEpochStartHandler(t *testing.T) { + t.Parallel() + + economics := Economics{ + NodePrice: big.NewInt(100), + } + epochStartData := EpochStartCrossChainData{ + Round: 4, + } + epochStartSov := EpochStartSovereign{ + Economics: economics, + LastFinalizedCrossChainHeader: epochStartData, + } + sovHdr := &SovereignChainHeader{ + EpochStart: epochStartSov, + } + + require.Equal(t, &epochStartSov, sovHdr.GetEpochStartHandler()) + require.Equal(t, &economics, sovHdr.GetEpochStartHandler().GetEconomicsHandler()) + require.Empty(t, sovHdr.GetEpochStartHandler().GetLastFinalizedHeaderHandlers()) + + epochStartData.ShardID = 8 + err := sovHdr.GetEpochStartHandler().SetLastFinalizedHeaders([]data.EpochStartShardDataHandler{&epochStartData}) + require.Nil(t, err) + require.Empty(t, sovHdr.GetEpochStartHandler().GetLastFinalizedHeaderHandlers()) + + epochStartData.ShardID = core.MainChainShardId + epochStartSov.LastFinalizedCrossChainHeader = epochStartData + err = sovHdr.GetEpochStartHandler().SetLastFinalizedHeaders([]data.EpochStartShardDataHandler{&epochStartData}) + require.Nil(t, err) + + require.Equal(t, []data.EpochStartShardDataHandler{&epochStartData}, sovHdr.GetEpochStartHandler().GetLastFinalizedHeaderHandlers()) + require.Equal(t, &epochStartSov, sovHdr.GetEpochStartHandler()) +} + +func TestSovereignChainHeader_GetEconomicsHandler(t *testing.T) { + t.Parallel() + + economics := Economics{ + NodePrice: big.NewInt(100), + } + sovHdr := &SovereignChainHeader{ + EpochStart: EpochStartSovereign{ + Economics: economics, + }, + } + require.Equal(t, &economics, sovHdr.GetEpochStartHandler().GetEconomicsHandler()) + + economics2 := Economics{ + NodePrice: big.NewInt(200), + } + err := sovHdr.GetEpochStartHandler().SetEconomics(&economics2) + require.Nil(t, err) + require.Equal(t, &economics2, sovHdr.GetEpochStartHandler().GetEconomicsHandler()) +}