From c92f9091b8eaee3b6cbe9284a2f1abbccd0fc158 Mon Sep 17 00:00:00 2001 From: Marius C Date: Wed, 16 Oct 2024 11:25:27 +0300 Subject: [PATCH 1/2] 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 fdeed3e5..9aef6efb 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 fa19576b..e282df49 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, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4f, 0x6f, 0xd3, 0x4a, - 0x10, 0xcf, 0xbe, 0xb4, 0x79, 0xed, 0xb6, 0xaf, 0x0f, 0x96, 0x2a, 0x98, 0xa8, 0x5a, 0x87, 0xf2, - 0x2f, 0x12, 0x24, 0x16, 0xf4, 0xc8, 0x01, 0xd5, 0x6d, 0xa0, 0x91, 0x40, 0x91, 0x1c, 0x09, 0x55, - 0x88, 0xcb, 0xc6, 0xde, 0xda, 0x2b, 0x62, 0x6f, 0x64, 0xaf, 0xa3, 0x82, 0x84, 0xc4, 0x95, 0x03, - 0x12, 0x5f, 0x02, 0x09, 0xf5, 0x93, 0xf4, 0xd8, 0x63, 0x4e, 0x86, 0xba, 0x17, 0xe4, 0x53, 0x3f, - 0x02, 0xca, 0xc6, 0x6d, 0xdc, 0x36, 0xa6, 0xbd, 0x70, 0xf2, 0xee, 0xcc, 0x6f, 0x7e, 0xbf, 0x99, - 0x9d, 0x19, 0xc3, 0x4a, 0xc0, 0x07, 0xd4, 0xa7, 0xcc, 0xf6, 0x36, 0x1c, 0xc2, 0xbc, 0x2d, 0x4a, - 0x2c, 0xea, 0x37, 0xfa, 0x3e, 0x17, 0x1c, 0xcd, 0xca, 0x4f, 0xa5, 0x6e, 0x33, 0xe1, 0x84, 0xdd, - 0x86, 0xc9, 0x5d, 0xcd, 0xe6, 0x36, 0xd7, 0xa4, 0xb9, 0x1b, 0xee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0x74, 0x9d, 0x96, 0xe9, 0xa9, 0x33, 0xd3, 0x95, 0x0c, - 0xd7, 0xea, 0x5e, 0x31, 0x77, 0xa8, 0xd0, 0x7d, 0x38, 0x23, 0x17, 0x03, 0xc8, 0xd2, 0x51, 0x12, - 0xa9, 0x4b, 0x0e, 0x09, 0xb2, 0xfd, 0x95, 0x7e, 0xf4, 0x16, 0x96, 0xdb, 0x17, 0x86, 0x2a, 0xb3, - 0x52, 0x77, 0x47, 0x4d, 0xe5, 0x53, 0x11, 0x19, 0xae, 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, + 0x21, 0xc4, 0x65, 0x62, 0x4f, 0xed, 0x11, 0xb1, 0x27, 0xb2, 0xc7, 0xd1, 0x52, 0x09, 0x89, 0x2b, + 0x12, 0x48, 0x7c, 0x09, 0x24, 0xd4, 0x4f, 0xd2, 0xe3, 0x1e, 0x73, 0x32, 0xac, 0xf7, 0x00, 0xf2, + 0xa9, 0x1f, 0x01, 0x79, 0xec, 0xc4, 0xde, 0x6e, 0xbc, 0xed, 0xa5, 0xa7, 0x64, 0x7e, 0xef, 0xf7, + 0x7e, 0xef, 0xcf, 0xbc, 0x37, 0x86, 0x6d, 0x9f, 0xaf, 0xa8, 0x47, 0x99, 0xe5, 0x9e, 0xda, 0x84, + 0xb9, 0x0f, 0x29, 0x31, 0xa9, 0x37, 0x58, 0x7a, 0x5c, 0x70, 0x54, 0x95, 0x3f, 0xed, 0xbe, 0xc5, + 0x84, 0x1d, 0xcc, 0x07, 0x06, 0x77, 0x86, 0x16, 0xb7, 0xf8, 0x50, 0xc2, 0xf3, 0xe0, 0xb1, 0x3c, + 0xc9, 0x83, 0xfc, 0x97, 0x7a, 0xb5, 0x9b, 0xf3, 0x05, 0x37, 0x7e, 0xcc, 0x0e, 0x6f, 0x3a, 0x54, + 0x10, 0x2d, 0x07, 0xba, 0xff, 0x02, 0xf8, 0xce, 0x78, 0xc9, 0x0d, 0x7b, 0x26, 0x88, 0x27, 0x66, + 0x9b, 0xe0, 0xe8, 0x04, 0x36, 0xc6, 0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 0xe1, 0xfb, 0x8f, 0x64, 0x6f, 0x6e, 0x4a, 0x63, 0x5f, 0xa6, 0x31, + 0x8c, 0x43, 0xfc, 0xc9, 0xe2, 0x65, 0xe4, 0x42, 0x0a, 0x2f, 0x57, 0xd6, 0xbe, 0x3c, 0xbf, 0x50, + 0x2b, 0xeb, 0x0b, 0xb5, 0xf2, 0xfc, 0x42, 0x05, 0xbf, 0x44, 0x2a, 0xf8, 0x2b, 0x52, 0xc1, 0xb3, + 0x48, 0x05, 0xe7, 0x91, 0x0a, 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 d9c492b8..0c535a38 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 2/2] 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 9aef6efb..4ad8e375 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 0c535a38..ad63cf56 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 31d349a1..97409767 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