diff --git a/data/batch/batch.go b/data/batch/batch.go index 28601c5df..6bcb7d228 100644 --- a/data/batch/batch.go +++ b/data/batch/batch.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. batch.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. batch.proto package batch // New returns a new batch from given buffers diff --git a/data/batch/proto/batch.proto b/data/batch/batch.proto similarity index 100% rename from data/batch/proto/batch.proto rename to data/batch/batch.proto diff --git a/data/block/block.go b/data/block/block.go index 509d67599..4007849ad 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -1,12 +1,17 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. block.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. block.proto package block import ( "math/big" "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" ) +// TODO: add access protection through wrappers +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 type MiniBlockSlice []*MiniBlock @@ -18,101 +23,194 @@ type MiniblockAndHash struct { } // SetNonce sets header nonce -func (h *Header) SetNonce(n uint64) { +func (h *Header) SetNonce(n uint64) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.Nonce = n + return nil } // SetEpoch sets header epoch -func (h *Header) SetEpoch(e uint32) { +func (h *Header) SetEpoch(e uint32) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.Epoch = e + return nil } // SetRound sets header round -func (h *Header) SetRound(r uint64) { +func (h *Header) SetRound(r uint64) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.Round = r + return nil } // SetRootHash sets root hash -func (h *Header) SetRootHash(rHash []byte) { +func (h *Header) SetRootHash(rHash []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.RootHash = rHash + return nil } // SetValidatorStatsRootHash sets the root hash for the validator statistics trie func (h *Header) SetValidatorStatsRootHash(_ []byte) { } +// SetPrevHash sets prev hash +func (h *Header) SetPrevHash(pvHash []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + + h.PrevHash = pvHash + return nil +} + // GetValidatorStatsRootHash returns the root hash for the validator statistics trie func (h *Header) GetValidatorStatsRootHash() []byte { return []byte{} } -// SetPrevHash sets prev hash -func (h *Header) SetPrevHash(pvHash []byte) { - h.PrevHash = pvHash -} - // SetPrevRandSeed sets previous random seed -func (h *Header) SetPrevRandSeed(pvRandSeed []byte) { +func (h *Header) SetPrevRandSeed(pvRandSeed []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.PrevRandSeed = pvRandSeed + return nil } // SetRandSeed sets previous random seed -func (h *Header) SetRandSeed(randSeed []byte) { +func (h *Header) SetRandSeed(randSeed []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.RandSeed = randSeed + return nil } // SetPubKeysBitmap sets public key bitmap -func (h *Header) SetPubKeysBitmap(pkbm []byte) { +func (h *Header) SetPubKeysBitmap(pkbm []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.PubKeysBitmap = pkbm + return nil } // SetSignature sets header signature -func (h *Header) SetSignature(sg []byte) { +func (h *Header) SetSignature(sg []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.Signature = sg + return nil } // SetLeaderSignature will set the leader's signature -func (h *Header) SetLeaderSignature(sg []byte) { +func (h *Header) SetLeaderSignature(sg []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.LeaderSignature = sg + return nil } // SetChainID sets the chain ID on which this block is valid on -func (h *Header) SetChainID(chainID []byte) { +func (h *Header) SetChainID(chainID []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.ChainID = chainID + return nil } // SetSoftwareVersion sets the software version of the header -func (h *Header) SetSoftwareVersion(version []byte) { +func (h *Header) SetSoftwareVersion(version []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.SoftwareVersion = version + return nil } // SetTimeStamp sets header timestamp -func (h *Header) SetTimeStamp(ts uint64) { +func (h *Header) SetTimeStamp(ts uint64) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.TimeStamp = ts + return nil } // SetAccumulatedFees sets the accumulated fees in the header -func (h *Header) SetAccumulatedFees(value *big.Int) { +func (h *Header) SetAccumulatedFees(value *big.Int) error { + if h == nil { + return data.ErrNilPointerReceiver + } + if h.AccumulatedFees == nil { + h.AccumulatedFees = big.NewInt(0) + } h.AccumulatedFees.Set(value) + return nil } // SetDeveloperFees sets the developer fees in the header -func (h *Header) SetDeveloperFees(value *big.Int) { +func (h *Header) SetDeveloperFees(value *big.Int) error { + if h == nil { + return data.ErrNilPointerReceiver + } + if h.DeveloperFees == nil { + h.DeveloperFees = big.NewInt(0) + } h.DeveloperFees.Set(value) + return nil } // SetTxCount sets the transaction count of the block associated with this header -func (h *Header) SetTxCount(txCount uint32) { +func (h *Header) SetTxCount(txCount uint32) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.TxCount = txCount + return nil } // SetShardID sets header shard ID -func (h *Header) SetShardID(shId uint32) { +func (h *Header) SetShardID(shId uint32) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.ShardID = shId + return nil } // GetMiniBlockHeadersWithDst as a map of hashes and sender IDs func (h *Header) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { + if h == nil { + return nil + } + hashDst := make(map[string]uint32) for _, val := range h.MiniBlockHeaders { if val.ReceiverShardID == destId && val.SenderShardID != destId { @@ -125,6 +223,9 @@ func (h *Header) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { // 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 (h *Header) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { + if h == nil { + return nil + } miniBlocks := make([]*data.MiniBlockInfo, 0) for _, mb := range h.MiniBlockHeaders { @@ -142,6 +243,10 @@ func (h *Header) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlo // GetMiniBlockHeadersHashes gets the miniblock hashes func (h *Header) GetMiniBlockHeadersHashes() [][]byte { + if h == nil { + return nil + } + result := make([][]byte, 0, len(h.MiniBlockHeaders)) for _, miniblock := range h.MiniBlockHeaders { result = append(result, miniblock.Hash) @@ -151,6 +256,10 @@ func (h *Header) GetMiniBlockHeadersHashes() [][]byte { // MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs func (h *Header) MapMiniBlockHashesToShards() map[string]uint32 { + if h == nil { + return nil + } + hashDst := make(map[string]uint32) for _, val := range h.MiniBlockHeaders { hashDst[string(val.Hash)] = val.SenderShardID @@ -158,16 +267,128 @@ func (h *Header) MapMiniBlockHashesToShards() map[string]uint32 { return hashDst } -// Clone returns a clone of the object -func (h *Header) Clone() data.HeaderHandler { +// ShallowClone returns a clone of the object +func (h *Header) ShallowClone() data.HeaderHandler { + if h == nil { + return nil + } + headerCopy := *h return &headerCopy } +// IsInterfaceNil returns true if there is no value under the interface +func (h *Header) IsInterfaceNil() bool { + return h == nil +} + +// IsStartOfEpochBlock verifies if the block is of type start of epoch +func (h *Header) IsStartOfEpochBlock() bool { + if h == nil { + return false + } + + return len(h.EpochStartMetaHash) > 0 +} + +// GetBlockBodyTypeInt32 returns the block body type as int32 +func (h *Header) GetBlockBodyTypeInt32() int32 { + if h == nil { + return -1 + } + + return int32(h.GetBlockBodyType()) +} + +// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers +func (h *Header) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if h == nil { + return nil + } + + mbHeaders := h.GetMiniBlockHeaders() + mbHeaderHandlers := make([]data.MiniBlockHeaderHandler, len(mbHeaders)) + + for i := range mbHeaders { + mbHeaderHandlers[i] = &mbHeaders[i] + } + + return mbHeaderHandlers +} + +// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers +func (h *Header) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if h == nil { + return data.ErrNilPointerReceiver + } + if len(mbHeaderHandlers) == 0 { + h.MiniBlockHeaders = nil + return nil + } + + miniBlockHeaders := make([]MiniBlockHeader, len(mbHeaderHandlers)) + h.MiniBlockHeaders = make([]MiniBlockHeader, len(mbHeaderHandlers)) + for i, mbHeaderHandler := range mbHeaderHandlers { + mbHeader, ok := mbHeaderHandler.(*MiniBlockHeader) + if !ok { + return data.ErrInvalidTypeAssertion + } + if mbHeader == nil { + return data.ErrNilPointerDereference + } + miniBlockHeaders[i] = *mbHeader + } + + h.MiniBlockHeaders = miniBlockHeaders + return nil +} + +// SetReceiptsHash sets the receipts hash +func (h *Header) SetReceiptsHash(hash []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.ReceiptsHash = hash + return nil +} + +// SetMetaBlockHashes sets the metaBlock hashes +func (h *Header) SetMetaBlockHashes(hashes [][]byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.MetaBlockHashes = hashes + return nil +} + +// SetScheduledRootHash not supported by V1 header +func (h *Header) SetScheduledRootHash(_ []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + + return data.ErrScheduledRootHashNotSupported +} + +// SetEpochStartMetaHash sets the epoch start metaBlock hash +func (h *Header) SetEpochStartMetaHash(hash []byte) error { + if h == nil { + return data.ErrNilPointerReceiver + } + h.EpochStartMetaHash = hash + return nil +} + +// ValidateHeaderVersion does extra validation for header version +func (h *Header) ValidateHeaderVersion() error { + // no extra validation for v1 header + return nil +} + // IntegrityAndValidity checks if data is valid func (b *Body) IntegrityAndValidity() error { - if b.IsInterfaceNil() { - return data.ErrNilBlockBody + if b == nil { + return data.ErrNilPointerReceiver } for i := 0; i < len(b.MiniBlocks); i++ { @@ -181,6 +402,10 @@ func (b *Body) IntegrityAndValidity() error { // Clone returns a clone of the object func (b *Body) Clone() data.BodyHandler { + if b == nil { + return nil + } + bodyCopy := *b return &bodyCopy @@ -191,18 +416,12 @@ func (b *Body) IsInterfaceNil() bool { return b == nil } -// IsInterfaceNil returns true if there is no value under the interface -func (h *Header) IsInterfaceNil() bool { - return h == nil -} - -// IsStartOfEpochBlock verifies if the block is of type start of epoch -func (h *Header) IsStartOfEpochBlock() bool { - return len(h.EpochStartMetaHash) > 0 -} - // Clone the underlying data func (mb *MiniBlock) Clone() *MiniBlock { + if mb == nil { + return nil + } + newMb := &MiniBlock{ ReceiverShardID: mb.ReceiverShardID, SenderShardID: mb.SenderShardID, @@ -211,5 +430,135 @@ func (mb *MiniBlock) Clone() *MiniBlock { newMb.TxHashes = make([][]byte, len(mb.TxHashes)) copy(newMb.TxHashes, mb.TxHashes) + newMb.Reserved = make([]byte, len(mb.Reserved)) + copy(newMb.Reserved, mb.Reserved) + return newMb } + +// GetMiniBlockReserved returns the unmarshalled reserved field for the miniblock +func (mb *MiniBlock) GetMiniBlockReserved() (*MiniBlockReserved, error) { + if len(mb.Reserved) > 0 { + mbr := &MiniBlockReserved{} + err := mbr.Unmarshal(mb.Reserved) + if err != nil { + return nil, err + } + + return mbr, nil + } + return nil, nil +} + +// SetMiniBlockReserved sets the reserved field for the miniBlock with the given parameter +func (mb *MiniBlock) SetMiniBlockReserved(mbr *MiniBlockReserved) error { + if mbr == nil { + mb.Reserved = nil + return nil + } + + reserved, err := mbr.Marshal() + if err != nil { + return err + } + mb.Reserved = reserved + + return nil +} + +// IsScheduledMiniBlock returns if the mini block is of type scheduled or not +func (mb *MiniBlock) IsScheduledMiniBlock() bool { + if mb == nil || len(mb.Reserved) == 0 { + return false + } + + mbr := &MiniBlockReserved{} + err := mbr.Unmarshal(mb.Reserved) + if err != nil { + return false + } + return mbr.ExecutionType == Scheduled +} + +// GetTxsTypeFromMiniBlock returns all the txs type from mini block +func (mb *MiniBlock) GetTxsTypeFromMiniBlock() ([]Type, error) { + if mb == nil { + return nil, data.ErrNilPointerReceiver + } + + if len(mb.Reserved) == 0 { + return mb.getTxsTypeOfMiniBlock() + } + + mbr := &MiniBlockReserved{} + err := mbr.Unmarshal(mb.Reserved) + if err != nil { + return nil, err + } + + if len(mbr.TransactionsType) == 0 { + return mb.getTxsTypeOfMiniBlock() + } + + return mb.getTxsType(mbr) +} + +func (mb *MiniBlock) getTxsTypeOfMiniBlock() ([]Type, error) { + numTxs := len(mb.TxHashes) + txsType := make([]Type, numTxs) + for i := 0; i < numTxs; i++ { + txsType[i] = mb.Type + } + return txsType, nil +} + +func (mb *MiniBlock) getTxsType(mbr *MiniBlockReserved) ([]Type, error) { + numTxs := len(mb.TxHashes) + err := checkTransactionsTypeValidity(mbr, numTxs) + if err != nil { + return nil, err + } + + txsType := make([]Type, numTxs) + for i := 0; i < numTxs; i++ { + isTxBlockType := (mbr.TransactionsType[i/8] & (1 << (uint16(i) % 8))) == 0 + if isTxBlockType { + txsType[i] = TxBlock + } else { + // we assume that we have only two types of txs, TxBlock and SmartContractResultBlock, included in mini blocks of type TxBlock + txsType[i] = SmartContractResultBlock + } + } + + return txsType, nil +} + +func checkTransactionsTypeValidity(mbr *MiniBlockReserved, numTxs int) error { + transactionsTypeSize := numTxs / 8 + if numTxs%8 != 0 { + transactionsTypeSize++ + } + + if len(mbr.TransactionsType) != transactionsTypeSize { + return data.ErrWrongTransactionsTypeSize + } + + return nil +} + +// SetAdditionalData sets the additional data for the header +func (h *Header) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { + // first header version does not have any additional data + return nil +} + +// HasScheduledSupport returns false as the first block version does not support scheduled data +func (h *Header) HasScheduledSupport() bool { + return false +} + +// GetAdditionalData gets the additional version-related data for the header +func (h *Header) GetAdditionalData() headerVersionData.HeaderAdditionalData { + // no extra data for the initial version of shard block header + return nil +} diff --git a/data/block/block.pb.go b/data/block/block.pb.go index 28d9aef77..eb9486ec8 100644 --- a/data/block/block.pb.go +++ b/data/block/block.pb.go @@ -66,6 +66,27 @@ func (Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor_8e550b1f5926e92d, []int{0} } +type ProcessingType int32 + +const ( + Normal ProcessingType = 0 + Scheduled ProcessingType = 1 +) + +var ProcessingType_name = map[int32]string{ + 0: "Normal", + 1: "Scheduled", +} + +var ProcessingType_value = map[string]int32{ + "Normal": 0, + "Scheduled": 1, +} + +func (ProcessingType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_8e550b1f5926e92d, []int{1} +} + type MiniBlock struct { TxHashes [][]byte `protobuf:"bytes,1,rep,name=TxHashes,proto3" json:"TxHashes,omitempty"` ReceiverShardID uint32 `protobuf:"varint,2,opt,name=ReceiverShardID,proto3" json:"ReceiverShardID,omitempty"` @@ -578,6 +599,7 @@ func (m *BodyHeaderPair) GetHeader() []byte { func init() { proto.RegisterEnum("proto.Type", Type_name, Type_value) + proto.RegisterEnum("proto.ProcessingType", ProcessingType_name, ProcessingType_value) proto.RegisterType((*MiniBlock)(nil), "proto.MiniBlock") proto.RegisterType((*MiniBlockHeader)(nil), "proto.MiniBlockHeader") proto.RegisterType((*PeerChange)(nil), "proto.PeerChange") @@ -589,63 +611,65 @@ func init() { func init() { proto.RegisterFile("block.proto", fileDescriptor_8e550b1f5926e92d) } var fileDescriptor_8e550b1f5926e92d = []byte{ - // 888 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x3f, 0x6f, 0x1b, 0xc7, - 0x13, 0xe5, 0x4a, 0x24, 0x2d, 0x2d, 0x49, 0x89, 0xda, 0x9f, 0x7f, 0xca, 0xc2, 0x30, 0x4e, 0x04, - 0xe1, 0x82, 0x08, 0x20, 0x32, 0x51, 0x9a, 0x04, 0x31, 0x10, 0x84, 0x94, 0x05, 0x31, 0x89, 0x0d, - 0xe1, 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 0x17, 0xe2, 0x64, 0xac, - 0x6d, 0xf4, 0x35, 0xab, 0xd3, 0x6a, 0x3f, 0x9a, 0x89, 0x71, 0x18, 0x58, 0xe6, 0x92, 0xed, 0x2d, - 0x8c, 0x64, 0x99, 0x9f, 0x88, 0xa5, 0x2e, 0x84, 0x0a, 0x62, 0x4b, 0xfd, 0x4d, 0xba, 0x5f, 0x5d, - 0xdf, 0x3a, 0x85, 0x9b, 0x5b, 0xa7, 0xf0, 0xe1, 0xd6, 0x21, 0xef, 0xe6, 0x0e, 0xf9, 0x79, 0xee, - 0x90, 0xf7, 0x73, 0x87, 0x5c, 0xcf, 0x1d, 0x72, 0x33, 0x77, 0xc8, 0x9f, 0x73, 0x87, 0xfc, 0x35, - 0x77, 0x0a, 0x1f, 0xe6, 0x0e, 0xf9, 0xf1, 0xce, 0x29, 0x5c, 0xdf, 0x39, 0x85, 0x9b, 0x3b, 0xa7, - 0xf0, 0xba, 0x84, 0xff, 0x50, 0x07, 0x65, 0x1c, 0xd3, 0x67, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, - 0xea, 0x56, 0x3d, 0x0e, 0x60, 0x07, 0x00, 0x00, + // 918 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x3d, 0x6f, 0x1b, 0x47, + 0x10, 0xe5, 0x4a, 0x24, 0x2d, 0x2d, 0x3f, 0x44, 0x6d, 0x1c, 0xe5, 0x60, 0x18, 0x27, 0x82, 0x70, + 0x41, 0x38, 0x10, 0x99, 0x28, 0x4d, 0x82, 0x18, 0x08, 0x42, 0xca, 0x82, 0x98, 0xc4, 0x02, 0x71, + 0x27, 0xa4, 0x70, 0xb7, 0xbc, 0x1b, 0x93, 0x07, 0x93, 0xb7, 0xc4, 0xde, 0x1e, 0x25, 0x75, 0x2e, + 0x53, 0xa6, 0xca, 0x6f, 0x08, 0x52, 0xe7, 0x47, 0xb8, 0x48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0x43, 0x9d, 0x73, 0xe9, 0x47, 0x86, 0xfa, 0x97, 0x3c, 0xff, 0x94, 0x56, + 0xfb, 0x52, 0x78, 0x10, 0x45, 0x41, 0x38, 0x44, 0x4d, 0x94, 0x16, 0x4f, 0x85, 0x9c, 0xf0, 0x71, + 0x2d, 0xa7, 0x25, 0xb8, 0xde, 0x08, 0xfc, 0x78, 0x0c, 0x7e, 0x8d, 0x74, 0xbe, 0xb9, 0xba, 0xb1, + 0x73, 0xd7, 0x37, 0x76, 0xee, 0xee, 0xc6, 0x26, 0xef, 0xe6, 0x36, 0xf9, 0x75, 0x6e, 0x93, 0xf7, + 0x73, 0x9b, 0x5c, 0xcd, 0x6d, 0x72, 0x3d, 0xb7, 0xc9, 0xdf, 0x73, 0x9b, 0xfc, 0x33, 0xb7, 0x73, + 0x77, 0x73, 0x9b, 0xfc, 0x7c, 0x6b, 0xe7, 0xae, 0x6e, 0xed, 0xdc, 0xf5, 0xad, 0x9d, 0x7b, 0x5d, + 0xc0, 0xff, 0xbe, 0x83, 0x22, 0xce, 0xf4, 0x8b, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb2, 0xe6, + 0x66, 0x84, 0x8d, 0x07, 0x00, 0x00, } func (x Type) String() string { @@ -655,6 +679,13 @@ func (x Type) String() string { } return strconv.Itoa(int(x)) } +func (x ProcessingType) String() string { + s, ok := ProcessingType_name[int32(x)] + if ok { + return s + } + return strconv.Itoa(int(x)) +} func (this *MiniBlock) Equal(that interface{}) bool { if that == nil { return this == nil diff --git a/data/block/proto/block.proto b/data/block/block.proto similarity index 91% rename from data/block/proto/block.proto rename to data/block/block.proto index 44694111d..89acc6b2e 100644 --- a/data/block/proto/block.proto +++ b/data/block/block.proto @@ -15,13 +15,18 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; // Type identifies the type of the block enum Type { - TxBlock = 0; - StateBlock = 30; - PeerBlock = 60; - SmartContractResultBlock = 90; - InvalidBlock = 120; - ReceiptBlock = 150; - RewardsBlock = 255; + TxBlock = 0; + StateBlock = 30; + PeerBlock = 60; + SmartContractResultBlock = 90; + InvalidBlock = 120; + ReceiptBlock = 150; + RewardsBlock = 255; +} + +enum ProcessingType { + Normal = 0; + Scheduled = 1; } message MiniBlock { diff --git a/data/block/blockV2.go b/data/block/blockV2.go new file mode 100644 index 000000000..923b08076 --- /dev/null +++ b/data/block/blockV2.go @@ -0,0 +1,614 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. blockV2.proto +package block + +import ( + "math/big" + + "github.com/ElrondNetwork/elrond-go-core/core/check" + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" +) + +// GetShardID returns the header shardID +func (hv2 *HeaderV2) GetShardID() uint32 { + if hv2 == nil { + return 0 + } + + return hv2.Header.GetShardID() +} + +// GetNonce returns the header nonce +func (hv2 *HeaderV2) GetNonce() uint64 { + if hv2 == nil { + return 0 + } + + return hv2.Header.GetNonce() +} + +// GetEpoch returns the header epoch +func (hv2 *HeaderV2) GetEpoch() uint32 { + if hv2 == nil { + return 0 + } + + return hv2.Header.GetEpoch() +} + +// GetRound returns the header round +func (hv2 *HeaderV2) GetRound() uint64 { + if hv2 == nil { + return 0 + } + + return hv2.Header.GetRound() +} + +// GetRootHash returns the header root hash +func (hv2 *HeaderV2) GetRootHash() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetRootHash() +} + +// GetPrevHash returns the header previous header hash +func (hv2 *HeaderV2) GetPrevHash() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetPrevHash() +} + +// GetPrevRandSeed returns the header previous random seed +func (hv2 *HeaderV2) GetPrevRandSeed() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetPrevRandSeed() +} + +// GetRandSeed returns the header random seed +func (hv2 *HeaderV2) GetRandSeed() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetRandSeed() +} + +// GetPubKeysBitmap returns the header public key bitmap for the aggregated signatures +func (hv2 *HeaderV2) GetPubKeysBitmap() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetPubKeysBitmap() +} + +// GetSignature returns the header aggregated signature +func (hv2 *HeaderV2) GetSignature() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetSignature() +} + +// GetLeaderSignature returns the leader signature on top of the finalized (signed) header +func (hv2 *HeaderV2) GetLeaderSignature() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetLeaderSignature() +} + +// GetChainID returns the chain ID +func (hv2 *HeaderV2) GetChainID() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetChainID() +} + +// GetSoftwareVersion returns the header software version +func (hv2 *HeaderV2) GetSoftwareVersion() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetSoftwareVersion() +} + +// GetTimeStamp returns the header timestamp +func (hv2 *HeaderV2) GetTimeStamp() uint64 { + if hv2 == nil { + return 0 + } + + return hv2.Header.GetTimeStamp() +} + +// GetTxCount returns the number of txs included in the block +func (hv2 *HeaderV2) GetTxCount() uint32 { + if hv2 == nil { + return 0 + } + + return hv2.Header.GetTxCount() +} + +// GetReceiptsHash returns the header receipt hash +func (hv2 *HeaderV2) GetReceiptsHash() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetReceiptsHash() +} + +// GetAccumulatedFees returns the block accumulated fees +func (hv2 *HeaderV2) GetAccumulatedFees() *big.Int { + if hv2 == nil { + return nil + } + + return hv2.Header.GetAccumulatedFees() +} + +// GetDeveloperFees returns the block developer fees +func (hv2 *HeaderV2) GetDeveloperFees() *big.Int { + if hv2 == nil { + return nil + } + + return hv2.Header.GetDeveloperFees() +} + +// GetReserved returns the reserved field +func (hv2 *HeaderV2) GetReserved() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetReserved() +} + +// GetMetaBlockHashes returns the metaBlock hashes +func (hv2 *HeaderV2) GetMetaBlockHashes() [][]byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetMetaBlockHashes() +} + +// GetEpochStartMetaHash returns the epoch start metaBlock hash +func (hv2 *HeaderV2) GetEpochStartMetaHash() []byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetEpochStartMetaHash() +} + +// SetNonce sets header nonce +func (hv2 *HeaderV2) SetNonce(n uint64) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + return hv2.Header.SetNonce(n) +} + +// SetEpoch sets header epoch +func (hv2 *HeaderV2) SetEpoch(e uint32) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetEpoch(e) +} + +// SetRound sets header round +func (hv2 *HeaderV2) SetRound(r uint64) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetRound(r) +} + +// SetRootHash sets root hash +func (hv2 *HeaderV2) SetRootHash(rHash []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetRootHash(rHash) +} + +// SetPrevHash sets prev hash +func (hv2 *HeaderV2) SetPrevHash(pvHash []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetPrevHash(pvHash) +} + +// SetPrevRandSeed sets previous random seed +func (hv2 *HeaderV2) SetPrevRandSeed(pvRandSeed []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetPrevRandSeed(pvRandSeed) +} + +// SetRandSeed sets previous random seed +func (hv2 *HeaderV2) SetRandSeed(randSeed []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetRandSeed(randSeed) +} + +// SetPubKeysBitmap sets public key bitmap +func (hv2 *HeaderV2) SetPubKeysBitmap(pkbm []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetPubKeysBitmap(pkbm) +} + +// SetSignature sets header signature +func (hv2 *HeaderV2) SetSignature(sg []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetSignature(sg) +} + +// SetLeaderSignature will set the leader's signature +func (hv2 *HeaderV2) SetLeaderSignature(sg []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetLeaderSignature(sg) +} + +// SetChainID sets the chain ID on which this block is valid on +func (hv2 *HeaderV2) SetChainID(chainID []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetChainID(chainID) +} + +// SetSoftwareVersion sets the software version of the header +func (hv2 *HeaderV2) SetSoftwareVersion(version []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetSoftwareVersion(version) +} + +// SetTimeStamp sets header timestamp +func (hv2 *HeaderV2) SetTimeStamp(ts uint64) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetTimeStamp(ts) +} + +// SetAccumulatedFees sets the accumulated fees in the header +func (hv2 *HeaderV2) SetAccumulatedFees(value *big.Int) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetAccumulatedFees(value) +} + +// SetDeveloperFees sets the developer fees in the header +func (hv2 *HeaderV2) SetDeveloperFees(value *big.Int) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetDeveloperFees(value) +} + +// SetTxCount sets the transaction count of the block associated with this header +func (hv2 *HeaderV2) SetTxCount(txCount uint32) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetTxCount(txCount) +} + +// SetShardID sets header shard ID +func (hv2 *HeaderV2) SetShardID(shId uint32) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetShardID(shId) +} + +// GetMiniBlockHeadersWithDst as a map of hashes and sender IDs +func (hv2 *HeaderV2) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { + if hv2 == nil { + return nil + } + + return hv2.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 (hv2 *HeaderV2) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { + if hv2 == nil { + return nil + } + + return hv2.Header.GetOrderedCrossMiniblocksWithDst(destId) +} + +// GetMiniBlockHeadersHashes gets the miniblock hashes +func (hv2 *HeaderV2) GetMiniBlockHeadersHashes() [][]byte { + if hv2 == nil { + return nil + } + + return hv2.Header.GetMiniBlockHeadersHashes() +} + +// MapMiniBlockHashesToShards is a map of mini block hashes and sender IDs +func (hv2 *HeaderV2) MapMiniBlockHashesToShards() map[string]uint32 { + if hv2 == nil { + return nil + } + + return hv2.Header.MapMiniBlockHashesToShards() +} + +// ShallowClone returns a clone of the object +func (hv2 *HeaderV2) ShallowClone() data.HeaderHandler { + if hv2 == nil || hv2.Header == nil { + return nil + } + + internalHeaderCopy := *hv2.Header + headerCopy := *hv2 + headerCopy.Header = &internalHeaderCopy + + return &headerCopy +} + +// IsInterfaceNil returns true if there is no value under the interface +func (hv2 *HeaderV2) IsInterfaceNil() bool { + return hv2 == nil +} + +// IsStartOfEpochBlock verifies if the block is of type start of epoch +func (hv2 *HeaderV2) IsStartOfEpochBlock() bool { + if hv2 == nil { + return false + } + + return hv2.Header.IsStartOfEpochBlock() +} + +// GetBlockBodyTypeInt32 returns the block body type as int32 +func (hv2 *HeaderV2) GetBlockBodyTypeInt32() int32 { + if hv2 == nil { + return -1 + } + + return hv2.Header.GetBlockBodyTypeInt32() +} + +// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers +func (hv2 *HeaderV2) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if hv2 == nil { + return nil + } + + return hv2.Header.GetMiniBlockHeaderHandlers() +} + +// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers +func (hv2 *HeaderV2) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetMiniBlockHeaderHandlers(mbHeaderHandlers) +} + +// SetReceiptsHash sets the receipts hash +func (hv2 *HeaderV2) SetReceiptsHash(hash []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetReceiptsHash(hash) +} + +// SetMetaBlockHashes sets the metaBlock hashes +func (hv2 *HeaderV2) SetMetaBlockHashes(hashes [][]byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetMetaBlockHashes(hashes) +} + +// SetEpochStartMetaHash sets the epoch start metaBlock hash +func (hv2 *HeaderV2) SetEpochStartMetaHash(hash []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + return hv2.Header.SetEpochStartMetaHash(hash) +} + +// HasScheduledSupport returns true as the second block version does support scheduled data +func (hv2 *HeaderV2) HasScheduledSupport() bool { + return true +} + +// SetScheduledRootHash sets the scheduled root hash +func (hv2 *HeaderV2) SetScheduledRootHash(rootHash []byte) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + hv2.ScheduledRootHash = rootHash + + return nil +} + +// SetScheduledAccumulatedFees sets the scheduled accumulated fees +func (hv2 *HeaderV2) SetScheduledAccumulatedFees(value *big.Int) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + if hv2.ScheduledAccumulatedFees == nil { + hv2.ScheduledAccumulatedFees = big.NewInt(0) + } + if value == nil { + value = big.NewInt(0) + } + + hv2.ScheduledAccumulatedFees.Set(value) + return nil +} + +// SetScheduledDeveloperFees sets the scheduled developer fees +func (hv2 *HeaderV2) SetScheduledDeveloperFees(value *big.Int) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + if hv2.ScheduledDeveloperFees == nil { + hv2.ScheduledDeveloperFees = big.NewInt(0) + } + if value == nil { + value = big.NewInt(0) + } + + hv2.ScheduledDeveloperFees.Set(value) + return nil +} + +// SetScheduledGasProvided sets the scheduled SC calls provided gas +func (hv2 *HeaderV2) SetScheduledGasProvided(gasProvided uint64) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + hv2.ScheduledGasProvided = gasProvided + + return nil +} + +// SetScheduledGasPenalized sets the scheduled SC calls penalized gas +func (hv2 *HeaderV2) SetScheduledGasPenalized(gasPenalized uint64) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + hv2.ScheduledGasPenalized = gasPenalized + + return nil +} + +// SetScheduledGasRefunded sets the scheduled SC calls refunded gas +func (hv2 *HeaderV2) SetScheduledGasRefunded(gasRefunded uint64) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + hv2.ScheduledGasRefunded = gasRefunded + + return nil +} + +// ValidateHeaderVersion does extra validation for header version +func (hv2 *HeaderV2) ValidateHeaderVersion() error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + // the header needs to have a not nil & not empty scheduled root hash + if len(hv2.ScheduledRootHash) == 0 { + return data.ErrNilScheduledRootHash + } + + return hv2.Header.ValidateHeaderVersion() +} + +// SetAdditionalData sets the additional version related data for the header +func (hv2 *HeaderV2) SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + + if check.IfNil(headerVersionData) { + return data.ErrNilPointerDereference + } + + err := hv2.SetScheduledRootHash(headerVersionData.GetScheduledRootHash()) + if err != nil { + return err + } + + hv2.ScheduledGasProvided = headerVersionData.GetScheduledGasProvided() + hv2.ScheduledGasPenalized = headerVersionData.GetScheduledGasPenalized() + hv2.ScheduledGasRefunded = headerVersionData.GetScheduledGasRefunded() + + err = hv2.SetScheduledAccumulatedFees(headerVersionData.GetScheduledAccumulatedFees()) + if err != nil { + return err + } + + return hv2.SetScheduledDeveloperFees(headerVersionData.GetScheduledDeveloperFees()) +} + +// GetAdditionalData gets the additional version related data for the header +func (hv2 *HeaderV2) GetAdditionalData() headerVersionData.HeaderAdditionalData { + if hv2 == nil { + return nil + } + + accFees := big.NewInt(0) + if hv2.GetScheduledAccumulatedFees() != nil { + accFees = big.NewInt(0).Set(hv2.GetScheduledAccumulatedFees()) + } + devFees := big.NewInt(0) + if hv2.GetScheduledDeveloperFees() != nil { + devFees = big.NewInt(0).Set(hv2.GetScheduledDeveloperFees()) + } + + additionalVersionData := &headerVersionData.AdditionalData{ + ScheduledRootHash: hv2.GetScheduledRootHash(), + ScheduledAccumulatedFees: accFees, + ScheduledDeveloperFees: devFees, + ScheduledGasProvided: hv2.GetScheduledGasProvided(), + ScheduledGasPenalized: hv2.GetScheduledGasPenalized(), + ScheduledGasRefunded: hv2.GetScheduledGasRefunded(), + } + return additionalVersionData +} diff --git a/data/block/blockV2.pb.go b/data/block/blockV2.pb.go new file mode 100644 index 000000000..9f267f452 --- /dev/null +++ b/data/block/blockV2.pb.go @@ -0,0 +1,981 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: blockV2.proto + +package block + +import ( + bytes "bytes" + fmt "fmt" + github_com_ElrondNetwork_elrond_go_core_data "github.com/ElrondNetwork/elrond-go-core/data" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + 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 + +// HeaderV2 extends the Header structure with extra fields for version 2 +type HeaderV2 struct { + Header *Header `protobuf:"bytes,1,opt,name=Header,proto3" json:"Header,omitempty"` + ScheduledRootHash []byte `protobuf:"bytes,2,opt,name=ScheduledRootHash,proto3" json:"ScheduledRootHash,omitempty"` + ScheduledAccumulatedFees *math_big.Int `protobuf:"bytes,3,opt,name=ScheduledAccumulatedFees,proto3,casttypewith=math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster" json:"ScheduledAccumulatedFees,omitempty"` + ScheduledDeveloperFees *math_big.Int `protobuf:"bytes,4,opt,name=ScheduledDeveloperFees,proto3,casttypewith=math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster" json:"ScheduledDeveloperFees,omitempty"` + ScheduledGasProvided uint64 `protobuf:"varint,5,opt,name=ScheduledGasProvided,proto3" json:"ScheduledGasProvided,omitempty"` + ScheduledGasPenalized uint64 `protobuf:"varint,6,opt,name=ScheduledGasPenalized,proto3" json:"ScheduledGasPenalized,omitempty"` + ScheduledGasRefunded uint64 `protobuf:"varint,7,opt,name=ScheduledGasRefunded,proto3" json:"ScheduledGasRefunded,omitempty"` +} + +func (m *HeaderV2) Reset() { *m = HeaderV2{} } +func (*HeaderV2) ProtoMessage() {} +func (*HeaderV2) Descriptor() ([]byte, []int) { + return fileDescriptor_17a3844aa051366e, []int{0} +} +func (m *HeaderV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *HeaderV2) 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 *HeaderV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_HeaderV2.Merge(m, src) +} +func (m *HeaderV2) XXX_Size() int { + return m.Size() +} +func (m *HeaderV2) XXX_DiscardUnknown() { + xxx_messageInfo_HeaderV2.DiscardUnknown(m) +} + +var xxx_messageInfo_HeaderV2 proto.InternalMessageInfo + +func (m *HeaderV2) GetHeader() *Header { + if m != nil { + return m.Header + } + return nil +} + +func (m *HeaderV2) GetScheduledRootHash() []byte { + if m != nil { + return m.ScheduledRootHash + } + return nil +} + +func (m *HeaderV2) GetScheduledAccumulatedFees() *math_big.Int { + if m != nil { + return m.ScheduledAccumulatedFees + } + return nil +} + +func (m *HeaderV2) GetScheduledDeveloperFees() *math_big.Int { + if m != nil { + return m.ScheduledDeveloperFees + } + return nil +} + +func (m *HeaderV2) GetScheduledGasProvided() uint64 { + if m != nil { + return m.ScheduledGasProvided + } + return 0 +} + +func (m *HeaderV2) GetScheduledGasPenalized() uint64 { + if m != nil { + return m.ScheduledGasPenalized + } + return 0 +} + +func (m *HeaderV2) GetScheduledGasRefunded() uint64 { + if m != nil { + return m.ScheduledGasRefunded + } + return 0 +} + +type MiniBlockReserved struct { + ExecutionType ProcessingType `protobuf:"varint,1,opt,name=ExecutionType,proto3,enum=proto.ProcessingType" json:"ExecutionType,omitempty"` + TransactionsType []byte `protobuf:"bytes,2,opt,name=TransactionsType,proto3" json:"TransactionsType,omitempty"` +} + +func (m *MiniBlockReserved) Reset() { *m = MiniBlockReserved{} } +func (*MiniBlockReserved) ProtoMessage() {} +func (*MiniBlockReserved) Descriptor() ([]byte, []int) { + return fileDescriptor_17a3844aa051366e, []int{1} +} +func (m *MiniBlockReserved) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MiniBlockReserved) 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 *MiniBlockReserved) XXX_Merge(src proto.Message) { + xxx_messageInfo_MiniBlockReserved.Merge(m, src) +} +func (m *MiniBlockReserved) XXX_Size() int { + return m.Size() +} +func (m *MiniBlockReserved) XXX_DiscardUnknown() { + xxx_messageInfo_MiniBlockReserved.DiscardUnknown(m) +} + +var xxx_messageInfo_MiniBlockReserved proto.InternalMessageInfo + +func (m *MiniBlockReserved) GetExecutionType() ProcessingType { + if m != nil { + return m.ExecutionType + } + return Normal +} + +func (m *MiniBlockReserved) GetTransactionsType() []byte { + if m != nil { + return m.TransactionsType + } + return nil +} + +func init() { + proto.RegisterType((*HeaderV2)(nil), "proto.HeaderV2") + proto.RegisterType((*MiniBlockReserved)(nil), "proto.MiniBlockReserved") +} + +func init() { proto.RegisterFile("blockV2.proto", fileDescriptor_17a3844aa051366e) } + +var fileDescriptor_17a3844aa051366e = []byte{ + // 457 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x92, 0x3f, 0x6f, 0xd3, 0x40, + 0x18, 0xc6, 0x7d, 0x90, 0x04, 0x74, 0x25, 0x88, 0x5a, 0x14, 0x59, 0x1d, 0x8e, 0xa8, 0x12, 0x52, + 0x84, 0x88, 0x2d, 0x19, 0xb6, 0x0e, 0x88, 0x40, 0x4b, 0x8b, 0x04, 0xaa, 0x4c, 0xd5, 0x81, 0xed, + 0x7c, 0xf7, 0xd6, 0x39, 0xd5, 0xb9, 0x8b, 0xee, 0xce, 0xe1, 0x8f, 0x18, 0x10, 0x03, 0x0b, 0x0b, + 0x1f, 0x03, 0xf1, 0x49, 0x18, 0x33, 0x66, 0x83, 0x38, 0x0b, 0x63, 0x3f, 0x02, 0xf2, 0xb9, 0x44, + 0x94, 0x34, 0x1b, 0x93, 0xef, 0x7d, 0x7e, 0xf7, 0xf8, 0x79, 0x4f, 0x7a, 0x70, 0x3b, 0xcd, 0x15, + 0x3b, 0x39, 0x8a, 0xc3, 0x91, 0x56, 0x56, 0xf9, 0x4d, 0xf7, 0xd9, 0xec, 0x65, 0xc2, 0x0e, 0x8a, + 0x34, 0x64, 0x6a, 0x18, 0x65, 0x2a, 0x53, 0x91, 0x93, 0xd3, 0xe2, 0xd8, 0x4d, 0x6e, 0x70, 0xa7, + 0xda, 0xb5, 0xb9, 0xe6, 0x7e, 0x52, 0x0f, 0x5b, 0x9f, 0x1b, 0xf8, 0xea, 0x1e, 0x50, 0x0e, 0xfa, + 0x28, 0xf6, 0xef, 0xe0, 0x56, 0x7d, 0x0e, 0x50, 0x07, 0x75, 0xd7, 0xe2, 0x76, 0x7d, 0x29, 0xac, + 0xc5, 0xe4, 0x0c, 0xfa, 0xf7, 0xf0, 0xfa, 0x4b, 0x36, 0x00, 0x5e, 0xe4, 0xc0, 0x13, 0xa5, 0xec, + 0x1e, 0x35, 0x83, 0xe0, 0x52, 0x07, 0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x31, 0x30, 0x46, 0xc8, + 0xac, 0x82, 0xc9, 0xf9, 0xbb, 0xfe, 0x5d, 0x7c, 0xe3, 0x50, 0x53, 0x69, 0x28, 0xab, 0x24, 0xe3, + 0xfc, 0x75, 0x55, 0x96, 0xf4, 0xfe, 0xc3, 0xc9, 0x8c, 0x78, 0xd3, 0x19, 0xf1, 0x4e, 0x67, 0x04, + 0x7d, 0x28, 0x09, 0xfa, 0x5a, 0x12, 0xf4, 0xbd, 0x24, 0x68, 0x52, 0x12, 0x34, 0x2d, 0x09, 0xfa, + 0x59, 0x12, 0xf4, 0xab, 0x24, 0xde, 0x69, 0x49, 0xd0, 0x97, 0x39, 0xf1, 0x26, 0x73, 0xe2, 0x4d, + 0xe7, 0xc4, 0x7b, 0xd5, 0x74, 0x95, 0x4e, 0x5b, 0x6e, 0xa3, 0xfb, 0xbf, 0x03, 0x00, 0x00, 0xff, + 0xff, 0x64, 0xf6, 0x9f, 0x37, 0x27, 0x03, 0x00, 0x00, +} + +func (this *HeaderV2) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*HeaderV2) + if !ok { + that2, ok := that.(HeaderV2) + 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.ScheduledRootHash, that1.ScheduledRootHash) { + return false + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if !__caster.Equal(this.ScheduledAccumulatedFees, that1.ScheduledAccumulatedFees) { + return false + } + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if !__caster.Equal(this.ScheduledDeveloperFees, that1.ScheduledDeveloperFees) { + return false + } + } + if this.ScheduledGasProvided != that1.ScheduledGasProvided { + return false + } + if this.ScheduledGasPenalized != that1.ScheduledGasPenalized { + return false + } + if this.ScheduledGasRefunded != that1.ScheduledGasRefunded { + return false + } + return true +} +func (this *MiniBlockReserved) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MiniBlockReserved) + if !ok { + that2, ok := that.(MiniBlockReserved) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.ExecutionType != that1.ExecutionType { + return false + } + if !bytes.Equal(this.TransactionsType, that1.TransactionsType) { + return false + } + return true +} +func (this *HeaderV2) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 11) + s = append(s, "&block.HeaderV2{") + if this.Header != nil { + s = append(s, "Header: "+fmt.Sprintf("%#v", this.Header)+",\n") + } + s = append(s, "ScheduledRootHash: "+fmt.Sprintf("%#v", this.ScheduledRootHash)+",\n") + s = append(s, "ScheduledAccumulatedFees: "+fmt.Sprintf("%#v", this.ScheduledAccumulatedFees)+",\n") + s = append(s, "ScheduledDeveloperFees: "+fmt.Sprintf("%#v", this.ScheduledDeveloperFees)+",\n") + s = append(s, "ScheduledGasProvided: "+fmt.Sprintf("%#v", this.ScheduledGasProvided)+",\n") + s = append(s, "ScheduledGasPenalized: "+fmt.Sprintf("%#v", this.ScheduledGasPenalized)+",\n") + s = append(s, "ScheduledGasRefunded: "+fmt.Sprintf("%#v", this.ScheduledGasRefunded)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *MiniBlockReserved) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&block.MiniBlockReserved{") + s = append(s, "ExecutionType: "+fmt.Sprintf("%#v", this.ExecutionType)+",\n") + s = append(s, "TransactionsType: "+fmt.Sprintf("%#v", this.TransactionsType)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringBlockV2(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 *HeaderV2) 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 *HeaderV2) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *HeaderV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ScheduledGasRefunded != 0 { + i = encodeVarintBlockV2(dAtA, i, uint64(m.ScheduledGasRefunded)) + i-- + dAtA[i] = 0x38 + } + if m.ScheduledGasPenalized != 0 { + i = encodeVarintBlockV2(dAtA, i, uint64(m.ScheduledGasPenalized)) + i-- + dAtA[i] = 0x30 + } + if m.ScheduledGasProvided != 0 { + i = encodeVarintBlockV2(dAtA, i, uint64(m.ScheduledGasProvided)) + i-- + dAtA[i] = 0x28 + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + size := __caster.Size(m.ScheduledDeveloperFees) + i -= size + if _, err := __caster.MarshalTo(m.ScheduledDeveloperFees, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBlockV2(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + size := __caster.Size(m.ScheduledAccumulatedFees) + i -= size + if _, err := __caster.MarshalTo(m.ScheduledAccumulatedFees, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBlockV2(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.ScheduledRootHash) > 0 { + i -= len(m.ScheduledRootHash) + copy(dAtA[i:], m.ScheduledRootHash) + i = encodeVarintBlockV2(dAtA, i, uint64(len(m.ScheduledRootHash))) + i-- + dAtA[i] = 0x12 + } + if m.Header != nil { + { + size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintBlockV2(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MiniBlockReserved) 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 *MiniBlockReserved) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MiniBlockReserved) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TransactionsType) > 0 { + i -= len(m.TransactionsType) + copy(dAtA[i:], m.TransactionsType) + i = encodeVarintBlockV2(dAtA, i, uint64(len(m.TransactionsType))) + i-- + dAtA[i] = 0x12 + } + if m.ExecutionType != 0 { + i = encodeVarintBlockV2(dAtA, i, uint64(m.ExecutionType)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintBlockV2(dAtA []byte, offset int, v uint64) int { + offset -= sovBlockV2(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *HeaderV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Header != nil { + l = m.Header.Size() + n += 1 + l + sovBlockV2(uint64(l)) + } + l = len(m.ScheduledRootHash) + if l > 0 { + n += 1 + l + sovBlockV2(uint64(l)) + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + l = __caster.Size(m.ScheduledAccumulatedFees) + n += 1 + l + sovBlockV2(uint64(l)) + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + l = __caster.Size(m.ScheduledDeveloperFees) + n += 1 + l + sovBlockV2(uint64(l)) + } + if m.ScheduledGasProvided != 0 { + n += 1 + sovBlockV2(uint64(m.ScheduledGasProvided)) + } + if m.ScheduledGasPenalized != 0 { + n += 1 + sovBlockV2(uint64(m.ScheduledGasPenalized)) + } + if m.ScheduledGasRefunded != 0 { + n += 1 + sovBlockV2(uint64(m.ScheduledGasRefunded)) + } + return n +} + +func (m *MiniBlockReserved) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ExecutionType != 0 { + n += 1 + sovBlockV2(uint64(m.ExecutionType)) + } + l = len(m.TransactionsType) + if l > 0 { + n += 1 + l + sovBlockV2(uint64(l)) + } + return n +} + +func sovBlockV2(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBlockV2(x uint64) (n int) { + return sovBlockV2(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *HeaderV2) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&HeaderV2{`, + `Header:` + strings.Replace(fmt.Sprintf("%v", this.Header), "Header", "Header", 1) + `,`, + `ScheduledRootHash:` + fmt.Sprintf("%v", this.ScheduledRootHash) + `,`, + `ScheduledAccumulatedFees:` + fmt.Sprintf("%v", this.ScheduledAccumulatedFees) + `,`, + `ScheduledDeveloperFees:` + fmt.Sprintf("%v", this.ScheduledDeveloperFees) + `,`, + `ScheduledGasProvided:` + fmt.Sprintf("%v", this.ScheduledGasProvided) + `,`, + `ScheduledGasPenalized:` + fmt.Sprintf("%v", this.ScheduledGasPenalized) + `,`, + `ScheduledGasRefunded:` + fmt.Sprintf("%v", this.ScheduledGasRefunded) + `,`, + `}`, + }, "") + return s +} +func (this *MiniBlockReserved) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&MiniBlockReserved{`, + `ExecutionType:` + fmt.Sprintf("%v", this.ExecutionType) + `,`, + `TransactionsType:` + fmt.Sprintf("%v", this.TransactionsType) + `,`, + `}`, + }, "") + return s +} +func valueToStringBlockV2(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *HeaderV2) 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 ErrIntOverflowBlockV2 + } + 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: HeaderV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: HeaderV2: 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 ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthBlockV2 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthBlockV2 + } + 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 ScheduledRootHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlockV2 + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlockV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ScheduledRootHash = append(m.ScheduledRootHash[:0], dAtA[iNdEx:postIndex]...) + if m.ScheduledRootHash == nil { + m.ScheduledRootHash = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduledAccumulatedFees", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlockV2 + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlockV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.ScheduledAccumulatedFees = tmp + } + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduledDeveloperFees", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlockV2 + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlockV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.ScheduledDeveloperFees = tmp + } + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduledGasProvided", wireType) + } + m.ScheduledGasProvided = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ScheduledGasProvided |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduledGasPenalized", wireType) + } + m.ScheduledGasPenalized = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ScheduledGasPenalized |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduledGasRefunded", wireType) + } + m.ScheduledGasRefunded = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ScheduledGasRefunded |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipBlockV2(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthBlockV2 + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthBlockV2 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MiniBlockReserved) 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 ErrIntOverflowBlockV2 + } + 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: MiniBlockReserved: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MiniBlockReserved: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecutionType", wireType) + } + m.ExecutionType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecutionType |= ProcessingType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TransactionsType", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBlockV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthBlockV2 + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthBlockV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TransactionsType = append(m.TransactionsType[:0], dAtA[iNdEx:postIndex]...) + if m.TransactionsType == nil { + m.TransactionsType = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBlockV2(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthBlockV2 + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthBlockV2 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBlockV2(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, ErrIntOverflowBlockV2 + } + 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, ErrIntOverflowBlockV2 + } + 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, ErrIntOverflowBlockV2 + } + 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, ErrInvalidLengthBlockV2 + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBlockV2 + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBlockV2 + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBlockV2 = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBlockV2 = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBlockV2 = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/block/blockV2.proto b/data/block/blockV2.proto new file mode 100644 index 000000000..0f640ff1b --- /dev/null +++ b/data/block/blockV2.proto @@ -0,0 +1,26 @@ +// 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"; + +// HeaderV2 extends the Header structure with extra fields for version 2 +message HeaderV2 { + Header Header = 1; + bytes ScheduledRootHash = 2; + bytes ScheduledAccumulatedFees = 3 [(gogoproto.casttypewith) = "math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster"]; + bytes ScheduledDeveloperFees = 4 [(gogoproto.casttypewith) = "math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster"]; + uint64 ScheduledGasProvided = 5; + uint64 ScheduledGasPenalized = 6; + uint64 ScheduledGasRefunded = 7; +} + +message MiniBlockReserved { + ProcessingType ExecutionType = 1; + bytes TransactionsType = 2; +} diff --git a/data/block/blockV2_test.go b/data/block/blockV2_test.go new file mode 100644 index 000000000..5596b26d8 --- /dev/null +++ b/data/block/blockV2_test.go @@ -0,0 +1,742 @@ +package block_test + +import ( + "math/big" + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" + "github.com/stretchr/testify/require" +) + +func TestHeaderV2_GetEpochNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, uint32(0), h.GetEpoch()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, uint32(0), h.GetEpoch()) +} + +func TestHeaderV2_GetEpoch(t *testing.T) { + t.Parallel() + + epoch := uint32(1) + h := &block.HeaderV2{ + Header: &block.Header{ + Epoch: epoch, + }, + } + + require.Equal(t, epoch, h.GetEpoch()) +} + +func TestHeaderV2_GetShardNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, uint32(0), h.GetShardID()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, uint32(0), h.GetShardID()) +} + +func TestHeaderV2_GetShard(t *testing.T) { + t.Parallel() + + shardId := uint32(2) + h := &block.HeaderV2{ + Header: &block.Header{ + ShardID: shardId, + }, + } + + require.Equal(t, shardId, h.GetShardID()) +} +func TestHeaderV2_GetNonceNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, uint64(0), h.GetNonce()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, uint64(0), h.GetNonce()) +} + +func TestHeaderV2_GetNonce(t *testing.T) { + t.Parallel() + + nonce := uint64(2) + h := &block.HeaderV2{ + Header: &block.Header{ + Nonce: nonce, + }, + } + + require.Equal(t, nonce, h.GetNonce()) +} + +func TestHeaderV2_GetPrevHashNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, []byte(nil), h.GetPrevHash()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, []byte(nil), h.GetPrevHash()) +} + +func TestHeaderV2_GetPrevHash(t *testing.T) { + t.Parallel() + + prevHash := []byte("prev hash") + h := &block.HeaderV2{ + Header: &block.Header{ + PrevHash: prevHash, + }, + } + + require.Equal(t, prevHash, h.GetPrevHash()) +} + +func TestHeaderV2_GetPrevRandSeedNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, []byte(nil), h.GetPrevRandSeed()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, []byte(nil), h.GetPrevRandSeed()) +} + +func TestHeaderV2_GetPrevRandSeed(t *testing.T) { + t.Parallel() + + prevRandSeed := []byte("prev random seed") + h := &block.HeaderV2{ + Header: &block.Header{ + PrevRandSeed: prevRandSeed, + }, + } + + require.Equal(t, prevRandSeed, h.GetPrevRandSeed()) +} + +func TestHeaderV2_GetRandSeedNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, []byte(nil), h.GetRandSeed()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, []byte(nil), h.GetRandSeed()) +} + +func TestHeaderV2_GetRandSeed(t *testing.T) { + t.Parallel() + + randSeed := []byte("random seed") + h := &block.HeaderV2{ + Header: &block.Header{ + RandSeed: randSeed, + }, + } + + require.Equal(t, randSeed, h.GetRandSeed()) +} +func TestHeaderV2_GetPubKeysBitmapNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, []byte(nil), h.GetPubKeysBitmap()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, []byte(nil), h.GetPubKeysBitmap()) +} + +func TestHeaderV2_GetPubKeysBitmap(t *testing.T) { + t.Parallel() + + pubKeysBitmap := []byte{10, 11, 12, 13} + h := &block.HeaderV2{ + Header: &block.Header{ + PubKeysBitmap: pubKeysBitmap, + }, + } + + require.Equal(t, pubKeysBitmap, h.GetPubKeysBitmap()) +} + +func TestHeaderV2_GetRootHashNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, []byte(nil), h.GetRootHash()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, []byte(nil), h.GetRootHash()) +} + +func TestHeaderV2_GetRootHash(t *testing.T) { + t.Parallel() + + rootHash := []byte("root hash") + h := &block.HeaderV2{ + Header: &block.Header{ + RootHash: rootHash, + }, + } + + require.Equal(t, rootHash, h.GetRootHash()) +} + +func TestHeaderV2_GetRoundNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, uint64(0), h.GetRound()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, uint64(0), h.GetRound()) +} + +func TestHeaderV2_GetRound(t *testing.T) { + t.Parallel() + + round := uint64(1234) + h := &block.HeaderV2{ + Header: &block.Header{ + Round: round, + }, + } + + require.Equal(t, round, h.GetRound()) +} + +func TestHeaderV2_GetSignatureNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, []byte(nil), h.GetSignature()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, []byte(nil), h.GetSignature()) +} + +func TestHeaderV2_GetSignature(t *testing.T) { + t.Parallel() + + signature := []byte("signature") + h := &block.HeaderV2{ + Header: &block.Header{ + Signature: signature, + }, + } + + require.Equal(t, signature, h.GetSignature()) +} + +func TestHeaderV2_GetTxCountNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, uint32(0), h.GetTxCount()) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, uint32(0), h.GetTxCount()) +} + +func TestHeaderV2_GetTxCount(t *testing.T) { + t.Parallel() + + txCount := uint32(10) + h := &block.HeaderV2{ + Header: &block.Header{ + TxCount: txCount, + }, + } + + require.Equal(t, txCount, h.GetTxCount()) +} + +func TestHeaderV2_SetEpochNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetEpoch(1)) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetEpoch(1)) +} + +func TestHeaderV2_SetEpoch(t *testing.T) { + t.Parallel() + + epoch := uint32(10) + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetEpoch(epoch) + require.Nil(t, err) + require.Equal(t, epoch, h.GetEpoch()) +} + +func TestHeaderV2_SetNonceNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetNonce(1)) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetNonce(1)) +} + +func TestHeaderV2_SetNonce(t *testing.T) { + t.Parallel() + + nonce := uint64(11) + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetNonce(nonce) + require.Nil(t, err) + require.Equal(t, nonce, h.GetNonce()) +} + +func TestHeaderV2_SetPrevHashNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetPrevHash([]byte("prev hash"))) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetPrevHash([]byte("prev hash"))) +} + +func TestHeaderV2_SetPrevHash(t *testing.T) { + t.Parallel() + + prevHash := []byte("prev hash") + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetPrevHash(prevHash) + require.Nil(t, err) + require.Equal(t, prevHash, h.GetPrevHash()) +} + +func TestHeaderV2_SetPrevRandSeedNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetPrevRandSeed([]byte("prev rand seed"))) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetPrevRandSeed([]byte("prev rand seed"))) +} + +func TestHeaderV2_SetPrevRandSeed(t *testing.T) { + t.Parallel() + + prevRandSeed := []byte("prev random seed") + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetPrevRandSeed(prevRandSeed) + require.Nil(t, err) + require.Equal(t, prevRandSeed, h.GetPrevRandSeed()) +} + +func TestHeaderV2_SetRandSeedNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetRandSeed([]byte("rand seed"))) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetRandSeed([]byte("rand seed"))) +} + +func TestHeaderV2_SetRandSeed(t *testing.T) { + t.Parallel() + + randSeed := []byte("random seed") + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetRandSeed(randSeed) + require.Nil(t, err) + require.Equal(t, randSeed, h.GetRandSeed()) +} + +func TestHeaderV2_SetPubKeysBitmapNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetPubKeysBitmap([]byte("pub key bitmap"))) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetPubKeysBitmap([]byte("pub key bitmap"))) +} + +func TestHeaderV2_SetPubKeysBitmap(t *testing.T) { + t.Parallel() + + pubKeysBitmap := []byte{12, 13, 14, 15} + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetPubKeysBitmap(pubKeysBitmap) + require.Nil(t, err) + require.Equal(t, pubKeysBitmap, h.GetPubKeysBitmap()) +} + +func TestHeaderV2_SetRootHashNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetRootHash([]byte("root hash"))) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetRootHash([]byte("root hash"))) +} + +func TestHeaderV2_SetRootHash(t *testing.T) { + t.Parallel() + + rootHash := []byte("root hash") + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetRootHash(rootHash) + require.Nil(t, err) + require.Equal(t, rootHash, h.GetRootHash()) +} + +func TestHeaderV2_SetRoundNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetRound(1)) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetRound(1)) +} + +func TestHeaderV2_SetRound(t *testing.T) { + t.Parallel() + + round := uint64(10) + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetRound(round) + require.Nil(t, err) + require.Equal(t, round, h.GetRound()) +} + +func TestHeaderV2_SetSignatureNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetSignature([]byte("signature"))) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetSignature([]byte("signature"))) +} + +func TestHeaderV2_SetSignature(t *testing.T) { + t.Parallel() + + signature := []byte("signature") + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetSignature(signature) + require.Nil(t, err) + require.Equal(t, signature, h.GetSignature()) +} + +func TestHeaderV2_SetTimeStampNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetTimeStamp(100000)) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetTimeStamp(100000)) +} + +func TestHeaderV2_SetTimeStamp(t *testing.T) { + t.Parallel() + + timeStamp := uint64(100000) + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetTimeStamp(timeStamp) + require.Nil(t, err) + require.Equal(t, timeStamp, h.GetTimeStamp()) +} + +func TestHeaderV2_SetTxCountNilPointerReceiverOrInnerHeader(t *testing.T) { + t.Parallel() + + var h *block.HeaderV2 + require.Equal(t, data.ErrNilPointerReceiver, h.SetTxCount(10000)) + + h = &block.HeaderV2{ + Header: nil, + } + require.Equal(t, data.ErrNilPointerReceiver, h.SetTxCount(10000)) +} + +func TestHeaderV2_SetTxCount(t *testing.T) { + t.Parallel() + + txCount := uint32(10) + h := &block.HeaderV2{ + Header: &block.Header{}, + } + + err := h.SetTxCount(txCount) + require.Nil(t, err) + require.Equal(t, txCount, h.GetTxCount()) +} + +func TestHeaderV2_GetMiniBlockHeadersWithDstShouldWork(t *testing.T) { + t.Parallel() + + hashS0R0 := []byte("hash_0_0") + hashS0R1 := []byte("hash_0_1") + hash1S0R2 := []byte("hash_0_2") + hash2S0R2 := []byte("hash2_0_2") + + hdr := &block.Header{ + MiniBlockHeaders: []block.MiniBlockHeader{ + { + SenderShardID: 0, + ReceiverShardID: 0, + Hash: hashS0R0, + }, + { + SenderShardID: 0, + ReceiverShardID: 1, + Hash: hashS0R1, + }, + { + SenderShardID: 0, + ReceiverShardID: 2, + Hash: hash1S0R2, + }, + { + SenderShardID: 0, + ReceiverShardID: 2, + Hash: hash2S0R2, + }, + }, + } + + hashesWithDest2 := hdr.GetMiniBlockHeadersWithDst(2) + + require.Equal(t, uint32(0), hashesWithDest2[string(hash1S0R2)]) + require.Equal(t, uint32(0), hashesWithDest2[string(hash2S0R2)]) +} + +func TestHeaderV2_GetOrderedCrossMiniblocksWithDstShouldWork(t *testing.T) { + t.Parallel() + + hashSh0ToSh0 := []byte("hash_0_0") + hashSh0ToSh1 := []byte("hash_0_1") + hash1Sh0ToSh2 := []byte("hash1_0_2") + hash2Sh0ToSh2 := []byte("hash2_0_2") + + hdr := &block.Header{ + Round: 10, + MiniBlockHeaders: []block.MiniBlockHeader{ + { + SenderShardID: 0, + ReceiverShardID: 0, + Hash: hashSh0ToSh0, + }, + { + SenderShardID: 0, + ReceiverShardID: 1, + Hash: hashSh0ToSh1, + }, + { + SenderShardID: 0, + ReceiverShardID: 2, + Hash: hash1Sh0ToSh2, + }, + { + SenderShardID: 0, + ReceiverShardID: 2, + Hash: hash2Sh0ToSh2, + }, + }, + } + + miniBlocksInfo := hdr.GetOrderedCrossMiniblocksWithDst(2) + + require.Equal(t, 2, len(miniBlocksInfo)) + require.Equal(t, hash1Sh0ToSh2, miniBlocksInfo[0].Hash) + require.Equal(t, hdr.Round, miniBlocksInfo[0].Round) + require.Equal(t, hash2Sh0ToSh2, miniBlocksInfo[1].Hash) + require.Equal(t, hdr.Round, miniBlocksInfo[1].Round) +} + +func TestHeaderV2_SetScheduledRootHash(t *testing.T) { + t.Parallel() + + hv2 := block.HeaderV2{ + Header: &block.Header{}, + } + require.Nil(t, hv2.ScheduledRootHash) + + rootHash := []byte("root hash") + err := hv2.SetScheduledRootHash(rootHash) + require.Nil(t, err) + require.Equal(t, rootHash, hv2.ScheduledRootHash) +} + +func TestHeaderV2_ValidateHeaderVersion(t *testing.T) { + t.Parallel() + + hv2 := block.HeaderV2{ + Header: &block.Header{}, + } + + err := hv2.ValidateHeaderVersion() + require.Equal(t, data.ErrNilScheduledRootHash, err) + + hv2.ScheduledRootHash = make([]byte, 0) + err = hv2.ValidateHeaderVersion() + require.Equal(t, data.ErrNilScheduledRootHash, err) + + hv2.ScheduledRootHash = make([]byte, 32) + err = hv2.ValidateHeaderVersion() + require.Nil(t, err) +} + +func TestHeaderV2_SetAdditionalDataNilAdditionalDataShouldErr(t *testing.T) { + t.Parallel() + + shardBlock := &block.HeaderV2{ + Header: &block.Header{}, + ScheduledRootHash: nil, + } + + err := shardBlock.SetAdditionalData(nil) + + require.NotNil(t, err) + require.Equal(t, data.ErrNilPointerDereference, err) +} + +func TestHeaderV2_SetAdditionalDataEmptyFeesShouldWork(t *testing.T) { + t.Parallel() + + shardBlock := &block.HeaderV2{ + Header: &block.Header{}, + ScheduledRootHash: nil, + } + + scRootHash := []byte("scheduledRootHash") + err := shardBlock.SetAdditionalData(&headerVersionData.AdditionalData{ + ScheduledRootHash: scRootHash, + }) + + require.Nil(t, err) + require.Equal(t, scRootHash, shardBlock.ScheduledRootHash) + require.Equal(t, big.NewInt(0), shardBlock.ScheduledAccumulatedFees) + require.Equal(t, big.NewInt(0), shardBlock.ScheduledDeveloperFees) + require.Equal(t, uint64(0), shardBlock.GetScheduledGasPenalized()) + require.Equal(t, uint64(0), shardBlock.GetScheduledGasRefunded()) + require.Equal(t, uint64(0), shardBlock.GetScheduledGasProvided()) +} + +func TestHeaderV2_SetAdditionalDataShouldWork(t *testing.T) { + t.Parallel() + + shardBlock := &block.HeaderV2{ + Header: &block.Header{}, + ScheduledRootHash: nil, + } + + scRootHash := []byte("scheduledRootHash") + accFees := big.NewInt(100) + devFees := big.NewInt(10) + gasProvided := uint64(60) + gasRefunded := uint64(10) + gasPenalized := uint64(20) + err := shardBlock.SetAdditionalData(&headerVersionData.AdditionalData{ + ScheduledRootHash: scRootHash, + ScheduledAccumulatedFees: accFees, + ScheduledDeveloperFees: devFees, + ScheduledGasProvided: gasProvided, + ScheduledGasPenalized: gasPenalized, + ScheduledGasRefunded: gasRefunded, + }) + + require.Nil(t, err) + require.Equal(t, scRootHash, shardBlock.ScheduledRootHash) + require.Equal(t, accFees, shardBlock.ScheduledAccumulatedFees) + require.Equal(t, devFees, shardBlock.ScheduledDeveloperFees) + require.Equal(t, gasPenalized, shardBlock.GetScheduledGasPenalized()) + require.Equal(t, gasRefunded, shardBlock.GetScheduledGasRefunded()) + require.Equal(t, gasProvided, shardBlock.GetScheduledGasProvided()) +} diff --git a/data/block/block_test.go b/data/block/block_test.go index a9b58b09b..194a19497 100644 --- a/data/block/block_test.go +++ b/data/block/block_test.go @@ -6,6 +6,7 @@ import ( "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -136,8 +137,9 @@ func TestHeader_SetEpoch(t *testing.T) { epoch := uint32(10) h := block.Header{} - h.SetEpoch(epoch) + err := h.SetEpoch(epoch) + assert.Nil(t, err) assert.Equal(t, epoch, h.GetEpoch()) } @@ -146,8 +148,9 @@ func TestHeader_SetNonce(t *testing.T) { nonce := uint64(11) h := block.Header{} - h.SetNonce(nonce) + err := h.SetNonce(nonce) + assert.Nil(t, err) assert.Equal(t, nonce, h.GetNonce()) } @@ -156,8 +159,9 @@ func TestHeader_SetPrevHash(t *testing.T) { prevHash := []byte("prev hash") h := block.Header{} - h.SetPrevHash(prevHash) + err := h.SetPrevHash(prevHash) + assert.Nil(t, err) assert.Equal(t, prevHash, h.GetPrevHash()) } @@ -166,8 +170,9 @@ func TestHeader_SetPrevRandSeed(t *testing.T) { prevRandSeed := []byte("prev random seed") h := block.Header{} - h.SetPrevRandSeed(prevRandSeed) + err := h.SetPrevRandSeed(prevRandSeed) + assert.Nil(t, err) assert.Equal(t, prevRandSeed, h.GetPrevRandSeed()) } @@ -176,8 +181,9 @@ func TestHeader_SetRandSeed(t *testing.T) { randSeed := []byte("random seed") h := block.Header{} - h.SetRandSeed(randSeed) + err := h.SetRandSeed(randSeed) + assert.Nil(t, err) assert.Equal(t, randSeed, h.GetRandSeed()) } @@ -186,8 +192,9 @@ func TestHeader_SetPubKeysBitmap(t *testing.T) { pubKeysBitmap := []byte{12, 13, 14, 15} h := block.Header{} - h.SetPubKeysBitmap(pubKeysBitmap) + err := h.SetPubKeysBitmap(pubKeysBitmap) + assert.Nil(t, err) assert.Equal(t, pubKeysBitmap, h.GetPubKeysBitmap()) } @@ -196,8 +203,9 @@ func TestHeader_SetRootHash(t *testing.T) { rootHash := []byte("root hash") h := block.Header{} - h.SetRootHash(rootHash) + err := h.SetRootHash(rootHash) + assert.Nil(t, err) assert.Equal(t, rootHash, h.GetRootHash()) } @@ -206,8 +214,9 @@ func TestHeader_SetRound(t *testing.T) { rootHash := []byte("root hash") h := block.Header{} - h.SetRootHash(rootHash) + err := h.SetRootHash(rootHash) + assert.Nil(t, err) assert.Equal(t, rootHash, h.GetRootHash()) } @@ -216,8 +225,9 @@ func TestHeader_SetSignature(t *testing.T) { signature := []byte("signature") h := block.Header{} - h.SetSignature(signature) + err := h.SetSignature(signature) + assert.Nil(t, err) assert.Equal(t, signature, h.GetSignature()) } @@ -226,8 +236,9 @@ func TestHeader_SetTimeStamp(t *testing.T) { timeStamp := uint64(100000) h := block.Header{} - h.SetTimeStamp(timeStamp) + err := h.SetTimeStamp(timeStamp) + assert.Nil(t, err) assert.Equal(t, timeStamp, h.GetTimeStamp()) } @@ -236,8 +247,9 @@ func TestHeader_SetTxCount(t *testing.T) { txCount := uint32(10) h := block.Header{} - h.SetTxCount(txCount) + err := h.SetTxCount(txCount) + assert.Nil(t, err) assert.Equal(t, txCount, h.GetTxCount()) } @@ -245,7 +257,7 @@ func TestBody_IntegrityAndValidityNil(t *testing.T) { t.Parallel() var body *block.Body = nil - assert.Equal(t, data.ErrNilBlockBody, body.IntegrityAndValidity()) + assert.Equal(t, data.ErrNilPointerReceiver, body.IntegrityAndValidity()) } func TestBody_IntegrityAndValidityEmptyMiniblockShouldThrowException(t *testing.T) { @@ -373,9 +385,36 @@ func TestMiniBlock_Clone(t *testing.T) { ReceiverShardID: 1, SenderShardID: 2, Type: 0, + Reserved: []byte("something"), } clonedMB := miniBlock.Clone() assert.True(t, reflect.DeepEqual(miniBlock, clonedMB)) } + +func TestHeader_SetScheduledRootHash(t *testing.T) { + t.Parallel() + + header := &block.Header{} + err := header.SetScheduledRootHash([]byte("root hash")) + require.Equal(t, data.ErrScheduledRootHashNotSupported, err) +} + +func TestHeader_ValidateHeaderVersion(t *testing.T) { + t.Parallel() + + header := &block.Header{} + err := header.ValidateHeaderVersion() + require.Nil(t, err) +} + +func TestHeader_SetAdditionalDataShouldDoNothing(t *testing.T) { + t.Parallel() + + var shardBlock *block.Header + + //goland:noinspection ALL + err := shardBlock.SetAdditionalData(&headerVersionData.AdditionalData{}) + assert.Nil(t, err) +} diff --git a/data/block/economicsHandler.go b/data/block/economicsHandler.go new file mode 100644 index 000000000..689a077bd --- /dev/null +++ b/data/block/economicsHandler.go @@ -0,0 +1,129 @@ +package block + +import ( + "math/big" + + "github.com/ElrondNetwork/elrond-go-core/data" +) + +// SetTotalSupply sets the total supply +func (e *Economics) SetTotalSupply(totalSupply *big.Int) error { + if e == nil { + return data.ErrNilPointerReceiver + } + if totalSupply == nil{ + return data.ErrInvalidValue + } + if e.TotalSupply == nil { + e.TotalSupply = big.NewInt(0) + } + + e.TotalSupply.Set(totalSupply) + + return nil +} + +// SetTotalToDistribute sets the total to be distributed +func (e *Economics) SetTotalToDistribute(totalToDistribute *big.Int) error { + if e == nil { + return data.ErrNilPointerReceiver + } + if totalToDistribute == nil { + return data.ErrInvalidValue + } + if e.TotalToDistribute == nil { + e.TotalToDistribute = big.NewInt(0) + } + + e.TotalToDistribute.Set(totalToDistribute) + + return nil +} + +// SetTotalNewlyMinted sets the total number of minted tokens +func (e *Economics) SetTotalNewlyMinted(totalNewlyMinted *big.Int) error { + if e == nil { + return data.ErrNilPointerReceiver + } + if totalNewlyMinted == nil{ + return data.ErrInvalidValue + } + if e.TotalNewlyMinted == nil{ + e.TotalNewlyMinted = big.NewInt(0) + } + + e.TotalNewlyMinted.Set(totalNewlyMinted) + + return nil +} + +// SetRewardsPerBlock sets the rewards per block +func (e *Economics) SetRewardsPerBlock(rewardsPerBlock *big.Int) error { + if e == nil { + return data.ErrNilPointerReceiver + } + if rewardsPerBlock == nil{ + return data.ErrInvalidValue + } + if e.RewardsPerBlock == nil{ + e.RewardsPerBlock = big.NewInt(0) + } + + e.RewardsPerBlock.Set(rewardsPerBlock) + + return nil +} + +// SetRewardsForProtocolSustainability sets the rewards for protocol sustainability +func (e *Economics) SetRewardsForProtocolSustainability(rewardsForProtocolSustainability *big.Int) error { + if e == nil { + return data.ErrNilPointerReceiver + } + if rewardsForProtocolSustainability == nil{ + return data.ErrInvalidValue + } + if e.RewardsForProtocolSustainability == nil{ + e.RewardsForProtocolSustainability = big.NewInt(0) + } + + e.RewardsForProtocolSustainability.Set(rewardsForProtocolSustainability) + + return nil +} + +// SetNodePrice sets the node price +func (e *Economics) SetNodePrice(nodePrice *big.Int) error { + if e == nil { + return data.ErrNilPointerReceiver + } + if nodePrice == nil{ + return data.ErrInvalidValue + } + if e.NodePrice == nil{ + e.NodePrice = big.NewInt(0) + } + + e.NodePrice.Set(nodePrice) + + return nil +} + +// SetPrevEpochStartRound sets the previous epoch start round +func (e *Economics) SetPrevEpochStartRound(prevEpochStartRound uint64) error { + if e == nil { + return data.ErrNilPointerReceiver + } + + e.PrevEpochStartRound = prevEpochStartRound + return nil +} + +// SetPrevEpochStartHash sets the previous epoch start hash +func (e *Economics) SetPrevEpochStartHash(prevEpochStartHash []byte) error { + if e == nil { + return data.ErrNilPointerReceiver + } + + e.PrevEpochStartHash = prevEpochStartHash + return nil +} diff --git a/data/block/epochStartHandler.go b/data/block/epochStartHandler.go new file mode 100644 index 000000000..5c5fde24b --- /dev/null +++ b/data/block/epochStartHandler.go @@ -0,0 +1,70 @@ +package block + +import ( + "github.com/ElrondNetwork/elrond-go-core/data" +) + +// GetLastFinalizedHeaderHandlers returns the last finalized header handlers +func (es *EpochStart) GetLastFinalizedHeaderHandlers() []data.EpochStartShardDataHandler { + if es == nil { + return nil + } + + epochStartShardDataHandlers := make([]data.EpochStartShardDataHandler, len(es.LastFinalizedHeaders)) + for i := range es.LastFinalizedHeaders { + epochStartShardDataHandlers[i] = &es.LastFinalizedHeaders[i] + } + + return epochStartShardDataHandlers +} + +// GetEconomicsHandler returns the economics handler +func (es *EpochStart) GetEconomicsHandler() data.EconomicsHandler { + if es == nil { + return nil + } + + return &es.Economics +} + +// SetLastFinalizedHeaders sets the last finalized header +func (es *EpochStart) SetLastFinalizedHeaders(epochStartDataHandlers []data.EpochStartShardDataHandler) error { + if es == nil { + return data.ErrNilPointerReceiver + } + + epochStartData := make([]EpochStartShardData, len(epochStartDataHandlers)) + for i := range epochStartDataHandlers { + shardData, ok := epochStartDataHandlers[i].(*EpochStartShardData) + if !ok { + return data.ErrInvalidTypeAssertion + } + if shardData == nil { + return data.ErrNilPointerDereference + } + epochStartData[i] = *shardData + } + + es.LastFinalizedHeaders = epochStartData + + return nil +} + +// SetEconomics sets the economics data +func (es *EpochStart) SetEconomics(economicsHandler data.EconomicsHandler) error { + if es == nil { + return data.ErrNilPointerReceiver + } + + ec, ok := economicsHandler.(*Economics) + if !ok { + return data.ErrInvalidTypeAssertion + } + if ec == nil { + return data.ErrNilPointerDereference + } + + es.Economics = *ec + + return nil +} diff --git a/data/block/epochStartShardDataHandler.go b/data/block/epochStartShardDataHandler.go new file mode 100644 index 000000000..0bc329193 --- /dev/null +++ b/data/block/epochStartShardDataHandler.go @@ -0,0 +1,139 @@ +package block + +import "github.com/ElrondNetwork/elrond-go-core/data" + +// GetPendingMiniBlockHeaderHandlers returns the pending miniBlock header handlers +func (essd *EpochStartShardData) GetPendingMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if essd == nil { + return nil + } + + pendingMbHeaderHandlers := make([]data.MiniBlockHeaderHandler, len(essd.PendingMiniBlockHeaders)) + for i := range essd.PendingMiniBlockHeaders { + pendingMbHeaderHandlers[i] = &essd.PendingMiniBlockHeaders[i] + } + + return pendingMbHeaderHandlers +} + +// SetShardID sets the epoch start shardData shardID +func (essd *EpochStartShardData) SetShardID(shardID uint32) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.ShardID = shardID + + return nil +} + +// SetEpoch sets the epoch start shardData epoch +func (essd *EpochStartShardData) SetEpoch(epoch uint32) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Epoch = epoch + + return nil +} + +// SetRound sets the epoch start shardData round +func (essd *EpochStartShardData) SetRound(round uint64) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Round = round + + return nil +} + +// SetNonce sets the epoch start shardData nonce +func (essd *EpochStartShardData) SetNonce(nonce uint64) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.Nonce = nonce + + return nil +} + +// SetHeaderHash sets the epoch start shardData header hash +func (essd *EpochStartShardData) SetHeaderHash(hash []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.HeaderHash = hash + + return nil +} + +// SetRootHash sets the epoch start shardData root hash +func (essd *EpochStartShardData) SetRootHash(rootHash []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.RootHash = rootHash + + return nil +} + +// SetFirstPendingMetaBlock sets the epoch start shardData first pending metaBlock +func (essd *EpochStartShardData) SetFirstPendingMetaBlock(metaBlock []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.FirstPendingMetaBlock = metaBlock + + return nil +} + +// SetLastFinishedMetaBlock sets the epoch start shardData last finished metaBlock +func (essd *EpochStartShardData) SetLastFinishedMetaBlock(lastFinishedMetaBlock []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.LastFinishedMetaBlock = lastFinishedMetaBlock + + return nil +} + +// SetPendingMiniBlockHeaders sets the epoch start shardData pending miniBlock headers +func (essd *EpochStartShardData) SetPendingMiniBlockHeaders(miniBlockHeaderHandlers []data.MiniBlockHeaderHandler) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + pendingMiniBlockHeaders := make([]MiniBlockHeader, len(miniBlockHeaderHandlers)) + for i := range miniBlockHeaderHandlers { + mbHeader, ok := miniBlockHeaderHandlers[i].(*MiniBlockHeader) + if !ok { + return data.ErrInvalidTypeAssertion + } + if mbHeader == nil { + return data.ErrNilPointerDereference + } + pendingMiniBlockHeaders[i] = *mbHeader + } + + essd.PendingMiniBlockHeaders = pendingMiniBlockHeaders + + return nil +} + +// SetScheduledRootHash sets the scheduled root hash +func (essd *EpochStartShardData) SetScheduledRootHash(schRootHash []byte) error { + if essd == nil { + return data.ErrNilPointerReceiver + } + + essd.ScheduledRootHash = schRootHash + + return nil +} diff --git a/data/block/metaBlock.go b/data/block/metaBlock.go index 919a24d7d..9ff547d02 100644 --- a/data/block/metaBlock.go +++ b/data/block/metaBlock.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. metaBlock.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. metaBlock.proto package block import ( @@ -7,10 +7,12 @@ import ( "github.com/ElrondNetwork/elrond-go-core/core" "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" ) // don't break the interface var _ = data.HeaderHandler(&MetaBlock{}) +var _ = data.MetaHeaderHandler(&MetaBlock{}) // GetShardID returns the metachain shard id func (m *MetaBlock) GetShardID() uint32 { @@ -18,96 +20,253 @@ func (m *MetaBlock) GetShardID() uint32 { } // SetNonce sets header nonce -func (m *MetaBlock) SetNonce(n uint64) { +func (m *MetaBlock) SetNonce(n uint64) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.Nonce = n + + return nil } // SetEpoch sets header epoch -func (m *MetaBlock) SetEpoch(e uint32) { +func (m *MetaBlock) SetEpoch(e uint32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.Epoch = e + + return nil } // SetRound sets header round -func (m *MetaBlock) SetRound(r uint64) { +func (m *MetaBlock) SetRound(r uint64) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.Round = r + + return nil } // SetRootHash sets root hash -func (m *MetaBlock) SetRootHash(rHash []byte) { +func (m *MetaBlock) SetRootHash(rHash []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.RootHash = rHash + + return nil } // SetValidatorStatsRootHash sets the root hash for the validator statistics trie -func (m *MetaBlock) SetValidatorStatsRootHash(rHash []byte) { +func (m *MetaBlock) SetValidatorStatsRootHash(rHash []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.ValidatorStatsRootHash = rHash + + return nil } // SetPrevHash sets prev hash -func (m *MetaBlock) SetPrevHash(pvHash []byte) { +func (m *MetaBlock) SetPrevHash(pvHash []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.PrevHash = pvHash + + return nil } // SetPrevRandSeed sets the previous randomness seed -func (m *MetaBlock) SetPrevRandSeed(pvRandSeed []byte) { +func (m *MetaBlock) SetPrevRandSeed(pvRandSeed []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.PrevRandSeed = pvRandSeed + + return nil } // SetRandSeed sets the current random seed -func (m *MetaBlock) SetRandSeed(randSeed []byte) { +func (m *MetaBlock) SetRandSeed(randSeed []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.RandSeed = randSeed + + return nil } -// SetPubKeysBitmap sets publick key bitmap -func (m *MetaBlock) SetPubKeysBitmap(pkbm []byte) { +// SetPubKeysBitmap sets public key bitmap +func (m *MetaBlock) SetPubKeysBitmap(pkbm []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.PubKeysBitmap = pkbm + + return nil } // SetSignature set header signature -func (m *MetaBlock) SetSignature(sg []byte) { +func (m *MetaBlock) SetSignature(sg []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.Signature = sg + + return nil } // SetLeaderSignature will set the leader's signature -func (m *MetaBlock) SetLeaderSignature(sg []byte) { +func (m *MetaBlock) SetLeaderSignature(sg []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.LeaderSignature = sg + + return nil } // SetChainID sets the chain ID on which this block is valid on -func (m *MetaBlock) SetChainID(chainID []byte) { +func (m *MetaBlock) SetChainID(chainID []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.ChainID = chainID + + return nil } // SetSoftwareVersion sets the software version of the block -func (m *MetaBlock) SetSoftwareVersion(version []byte) { +func (m *MetaBlock) SetSoftwareVersion(version []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.SoftwareVersion = version + + return nil } // SetAccumulatedFees sets the accumulated fees in the header -func (m *MetaBlock) SetAccumulatedFees(value *big.Int) { +func (m *MetaBlock) SetAccumulatedFees(value *big.Int) error { + if m == nil { + return data.ErrNilPointerReceiver + } + if value == nil { + return data.ErrInvalidValue + } + if m.AccumulatedFees == nil { + m.AccumulatedFees = big.NewInt(0) + } + m.AccumulatedFees.Set(value) + + return nil +} + +// SetAccumulatedFeesInEpoch sets the epoch accumulated fees in the header +func (m *MetaBlock) SetAccumulatedFeesInEpoch(value *big.Int) error { + if m == nil { + return data.ErrNilPointerReceiver + } + if value == nil { + return data.ErrInvalidValue + } + if m.AccumulatedFeesInEpoch == nil { + m.AccumulatedFeesInEpoch = big.NewInt(0) + } + + m.AccumulatedFeesInEpoch.Set(value) + + return nil } // SetDeveloperFees sets the developer fees in the header -func (m *MetaBlock) SetDeveloperFees(value *big.Int) { +func (m *MetaBlock) SetDeveloperFees(value *big.Int) error { + if m == nil { + return data.ErrNilPointerReceiver + } + if value == nil { + return data.ErrInvalidValue + } + if m.DeveloperFees == nil { + m.DeveloperFees = big.NewInt(0) + } + m.DeveloperFees.Set(value) + + return nil +} + +// SetDevFeesInEpoch sets the developer fees in the header +func (m *MetaBlock) SetDevFeesInEpoch(value *big.Int) error { + if m == nil { + return data.ErrNilPointerReceiver + } + if value == nil { + return data.ErrInvalidValue + } + if m.DevFeesInEpoch == nil { + m.DevFeesInEpoch = big.NewInt(0) + } + + m.DevFeesInEpoch.Set(value) + + return nil } // SetTimeStamp sets header timestamp -func (m *MetaBlock) SetTimeStamp(ts uint64) { +func (m *MetaBlock) SetTimeStamp(ts uint64) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.TimeStamp = ts + + return nil } // SetTxCount sets the transaction count of the current meta block -func (m *MetaBlock) SetTxCount(txCount uint32) { +func (m *MetaBlock) SetTxCount(txCount uint32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + m.TxCount = txCount + + return nil } // SetShardID sets header shard ID -func (m *MetaBlock) SetShardID(_ uint32) { +func (m *MetaBlock) SetShardID(_ uint32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + return nil } // GetMiniBlockHeadersWithDst as a map of hashes and sender IDs func (m *MetaBlock) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { + if m == nil { + return nil + } + hashDst := make(map[string]uint32) for i := 0; i < len(m.ShardInfo); i++ { if m.ShardInfo[i].ShardID == destId { @@ -136,6 +295,10 @@ func (m *MetaBlock) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 // 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 (m *MetaBlock) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { + if m == nil { + return nil + } + miniBlocks := make([]*data.MiniBlockInfo, 0) for i := 0; i < len(m.ShardInfo); i++ { @@ -176,10 +339,15 @@ func (m *MetaBlock) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.Mini // GetMiniBlockHeadersHashes gets the miniblock hashes func (m *MetaBlock) GetMiniBlockHeadersHashes() [][]byte { + if m == nil { + return nil + } + result := make([][]byte, 0, len(m.MiniBlockHeaders)) for _, miniblock := range m.MiniBlockHeaders { result = append(result, miniblock.Hash) } + return result } @@ -190,16 +358,151 @@ func (m *MetaBlock) IsInterfaceNil() bool { // IsStartOfEpochBlock verifies if the block is of type start of epoch func (m *MetaBlock) IsStartOfEpochBlock() bool { + if m == nil { + return false + } + return len(m.EpochStart.LastFinalizedHeaders) > 0 } -// Clone will return a clone of the object -func (m *MetaBlock) Clone() data.HeaderHandler { +// ShallowClone will return a clone of the object +func (m *MetaBlock) ShallowClone() data.HeaderHandler { + if m == nil { + return nil + } + metaBlockCopy := *m + return &metaBlockCopy } -// GetEpochStartMetaHash returns the hash of the epoch start meta block -func (m *MetaBlock) GetEpochStartMetaHash() []byte { +// GetMiniBlockHeaderHandlers returns the miniBlock headers as an array of miniBlock header handlers +func (m *MetaBlock) GetMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if m == nil { + return nil + } + + mbHeaders := m.GetMiniBlockHeaders() + mbHeaderHandlers := make([]data.MiniBlockHeaderHandler, len(mbHeaders)) + + for i := range mbHeaders { + mbHeaderHandlers[i] = &mbHeaders[i] + } + + return mbHeaderHandlers +} + +// HasScheduledSupport returns false as the initial metaBlock version does not support scheduled data +func (m *MetaBlock) HasScheduledSupport() bool { + return false +} + +// SetMiniBlockHeaderHandlers sets the miniBlock headers from the given miniBlock header handlers +func (m *MetaBlock) SetMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + if mbHeaderHandlers == nil { + m.MiniBlockHeaders = nil + return nil + } + + mbHeaders := make([]MiniBlockHeader, len(mbHeaderHandlers)) + for i := range mbHeaderHandlers { + mbHeader, ok := mbHeaderHandlers[i].(*MiniBlockHeader) + if !ok { + return data.ErrInvalidTypeAssertion + } + if mbHeader == nil { + return data.ErrNilPointerDereference + } + mbHeaders[i] = *mbHeader + } + + m.MiniBlockHeaders = mbHeaders + + return nil +} + +// SetReceiptsHash sets the receipts hash +func (m *MetaBlock) SetReceiptsHash(hash []byte) error { + if m == nil { + return nil + } + + m.ReceiptsHash = hash + + return nil +} + +// GetShardInfoHandlers - gets the shardInfo as an array of ShardDataHandler +func (m *MetaBlock) GetShardInfoHandlers() []data.ShardDataHandler { + if m == nil || m.ShardInfo == nil { + return nil + } + + shardInfoHandlers := make([]data.ShardDataHandler, len(m.ShardInfo)) + for i := range m.ShardInfo { + shardInfoHandlers[i] = &m.ShardInfo[i] + } + + return shardInfoHandlers +} + +// GetEpochStartHandler - +func (m *MetaBlock) GetEpochStartHandler() data.EpochStartHandler { + if m == nil { + return nil + } + + return &m.EpochStart +} + +// SetShardInfoHandlers - +func (m *MetaBlock) SetShardInfoHandlers(shardInfo []data.ShardDataHandler) error { + if m == nil { + return data.ErrNilPointerReceiver + } + if shardInfo == nil { + m.ShardInfo = nil + return nil + } + + sInfo := make([]ShardData, len(shardInfo)) + for i := range shardInfo { + shData, ok := shardInfo[i].(*ShardData) + if !ok { + return data.ErrInvalidTypeAssertion + } + if shData == nil { + return data.ErrNilPointerDereference + } + sInfo[i] = *shData + } + + m.ShardInfo = sInfo + + return nil +} + +// SetScheduledRootHash not supported on the first version of metablock +func (m *MetaBlock) SetScheduledRootHash(_ []byte) error { + return data.ErrScheduledRootHashNotSupported +} + +// ValidateHeaderVersion - always valid for initial version +func (m *MetaBlock) ValidateHeaderVersion() error { + return nil +} + +// SetAdditionalData sets the additional version-related data +func (m *MetaBlock) SetAdditionalData(_ headerVersionData.HeaderAdditionalData) error { + // no extra data for the initial version metaBlock header + return nil +} + +// GetAdditionalData gets the additional version-related data for the header +func (m *MetaBlock) GetAdditionalData() headerVersionData.HeaderAdditionalData { + // no extra data for the initial version of meta block header return nil } diff --git a/data/block/metaBlock.pb.go b/data/block/metaBlock.pb.go index 922d9b0ee..bce26ae0a 100644 --- a/data/block/metaBlock.pb.go +++ b/data/block/metaBlock.pb.go @@ -295,6 +295,7 @@ type EpochStartShardData struct { Nonce uint64 `protobuf:"varint,8,opt,name=Nonce,proto3" json:"Nonce,omitempty"` HeaderHash []byte `protobuf:"bytes,2,opt,name=HeaderHash,proto3" json:"HeaderHash,omitempty"` RootHash []byte `protobuf:"bytes,3,opt,name=RootHash,proto3" json:"RootHash,omitempty"` + ScheduledRootHash []byte `protobuf:"bytes,10,opt,name=ScheduledRootHash,proto3" json:"ScheduledRootHash,omitempty"` FirstPendingMetaBlock []byte `protobuf:"bytes,4,opt,name=FirstPendingMetaBlock,proto3" json:"FirstPendingMetaBlock,omitempty"` LastFinishedMetaBlock []byte `protobuf:"bytes,5,opt,name=LastFinishedMetaBlock,proto3" json:"LastFinishedMetaBlock,omitempty"` PendingMiniBlockHeaders []MiniBlockHeader `protobuf:"bytes,6,rep,name=PendingMiniBlockHeaders,proto3" json:"PendingMiniBlockHeaders"` @@ -370,6 +371,13 @@ func (m *EpochStartShardData) GetRootHash() []byte { return nil } +func (m *EpochStartShardData) GetScheduledRootHash() []byte { + if m != nil { + return m.ScheduledRootHash + } + return nil +} + func (m *EpochStartShardData) GetFirstPendingMetaBlock() []byte { if m != nil { return m.FirstPendingMetaBlock @@ -780,86 +788,88 @@ func init() { func init() { proto.RegisterFile("metaBlock.proto", fileDescriptor_87b91ab531130b2b) } var fileDescriptor_87b91ab531130b2b = []byte{ - // 1264 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x3f, 0x6f, 0xdb, 0x46, - 0x14, 0x17, 0x6d, 0xcb, 0xb6, 0x9e, 0x2c, 0x9b, 0xbe, 0x38, 0x0e, 0x6b, 0x14, 0x8c, 0x21, 0x74, - 0x70, 0x0b, 0xc4, 0x6e, 0xdd, 0xa0, 0x1d, 0x3a, 0x14, 0xb1, 0x1d, 0x23, 0xca, 0x1f, 0x43, 0xa0, - 0x5c, 0x0f, 0xdd, 0x4e, 0xe4, 0x8b, 0x74, 0x30, 0xc5, 0x13, 0x8e, 0x47, 0x3b, 0xee, 0x54, 0xf4, - 0x13, 0x74, 0x2a, 0xfa, 0x01, 0x3a, 0x14, 0xdd, 0xfb, 0x15, 0x8a, 0x8c, 0x19, 0x33, 0x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 0x1d, 0x56, 0x43, 0x0d, 0xeb, 0x46, 0x32, - 0xac, 0x25, 0xdb, 0x2e, 0x19, 0xd8, 0x52, 0x6b, 0x72, 0x37, 0x37, 0xac, 0x6a, 0x52, 0xea, 0xbb, - 0x66, 0xea, 0x2a, 0xc5, 0x13, 0x07, 0xd9, 0xc1, 0xe6, 0x3f, 0x35, 0xa8, 0x65, 0x9b, 0x64, 0xbc, - 0x07, 0x8d, 0xfc, 0x1e, 0x1c, 0x6f, 0xd2, 0x99, 0xd2, 0x4d, 0x3a, 0x9b, 0xdf, 0xa4, 0xff, 0xcf, - 0x75, 0xee, 0x26, 0xe4, 0xa3, 0x15, 0x3c, 0xe5, 0x56, 0x55, 0x5d, 0x37, 0xfd, 0x8d, 0xc5, 0x4b, - 0x66, 0x07, 0xc9, 0x27, 0x9a, 0xae, 0x29, 0x23, 0xbd, 0xd0, 0x56, 0x72, 0x64, 0x2b, 0x67, 0x33, - 0x3e, 0x76, 0x99, 0x1a, 0x2c, 0x14, 0xa9, 0xc1, 0x16, 0xac, 0x3c, 0x56, 0x59, 0xcb, 0xce, 0xe8, - 0xe2, 0x15, 0xe1, 0x49, 0x22, 0x52, 0x2b, 0x23, 0x22, 0x79, 0x52, 0x01, 0x05, 0x52, 0x51, 0xa4, - 0x3b, 0xf5, 0x12, 0xba, 0x13, 0x3f, 0x24, 0xa9, 0x7e, 0x29, 0x79, 0x48, 0xf2, 0xba, 0xf4, 0x91, - 0x69, 0x14, 0x1e, 0x99, 0xcf, 0x60, 0xfd, 0x84, 0xfa, 0xcc, 0xa3, 0x92, 0x8b, 0x8e, 0xa4, 0x32, - 0x1c, 0x9f, 0x54, 0x6c, 0xc1, 0xb9, 0x42, 0x4b, 0x1e, 0x80, 0x39, 0xf1, 0x52, 0x98, 0xef, 0xf0, - 0x52, 0x98, 0x65, 0x64, 0xce, 0x41, 0x17, 0xd9, 0x50, 0x86, 0x2a, 0xee, 0xaa, 0xbe, 0x5d, 0x1e, - 0x23, 0x9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 0x82, 0x07, + 0xde, 0x11, 0xca, 0x73, 0x2e, 0x4e, 0x77, 0x50, 0x49, 0xb7, 0xfb, 0xfc, 0xb6, 0xcb, 0x05, 0xee, + 0x78, 0x54, 0xd2, 0xed, 0x3d, 0xd6, 0x6f, 0x07, 0x72, 0x9f, 0x86, 0x12, 0x85, 0x93, 0x3f, 0xbe, + 0xf5, 0x6b, 0x0d, 0xea, 0xdd, 0x01, 0x15, 0x9e, 0xba, 0xbc, 0x0d, 0x70, 0x1f, 0xa9, 0x87, 0xe2, + 0x3e, 0x0d, 0x07, 0xc9, 0x1d, 0x73, 0x08, 0x71, 0xe0, 0x86, 0x32, 0x7e, 0xcc, 0x02, 0xa6, 0x8a, + 0xa0, 0x75, 0xa1, 0x55, 0xdd, 0xac, 0x6e, 0x35, 0x76, 0xd7, 0x93, 0x3b, 0x17, 0xd4, 0x7b, 0x73, + 0xcf, 0x7e, 0xbf, 0x55, 0x71, 0xca, 0x5d, 0x49, 0x0b, 0x96, 0x3a, 0x02, 0xcf, 0x1c, 0x1a, 0x78, + 0x5d, 0x44, 0x4f, 0x25, 0x64, 0xc9, 0xb9, 0x84, 0x91, 0xf7, 0xa0, 0xd9, 0x89, 0x7a, 0x0f, 0xf1, + 0x22, 0xdc, 0x63, 0x72, 0x48, 0x47, 0x3a, 0x2b, 0xce, 0x65, 0x30, 0xce, 0x6b, 0x97, 0xf5, 0x03, + 0x2a, 0x23, 0x81, 0xd6, 0xbc, 0x2e, 0xd0, 0x04, 0x20, 0x6b, 0x50, 0x73, 0x78, 0x14, 0x78, 0xd6, + 0xa2, 0xca, 0xb8, 0x16, 0xc8, 0x06, 0x2c, 0xc6, 0x91, 0xd4, 0x7d, 0xeb, 0xca, 0x65, 0x22, 0xc7, + 0x1e, 0x47, 0x3c, 0x70, 0xd1, 0x02, 0xed, 0xa1, 0x04, 0x22, 0x61, 0xe5, 0xae, 0xeb, 0x46, 0xc3, + 0xc8, 0xa7, 0x12, 0xbd, 0x43, 0xc4,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, 0x8d, 0x18, 0xe9, 0xfa, 0x34, 0xe6, 0x73, 0xe6, 0x7c, 0x0a, 0x38, 0xf1, 0xb6, 0x3c, + 0x45, 0x73, 0x61, 0xef, 0x8b, 0xe7, 0x2f, 0xed, 0xca, 0x8b, 0x97, 0x76, 0xe5, 0xf5, 0x4b, 0xdb, + 0xf8, 0x66, 0x6c, 0x1b, 0x3f, 0x8f, 0x6d, 0xe3, 0xd9, 0xd8, 0x36, 0x9e, 0x8f, 0x6d, 0xe3, 0xc5, + 0xd8, 0x36, 0xfe, 0x1c, 0xdb, 0xc6, 0x5f, 0x63, 0xbb, 0xf2, 0x7a, 0x6c, 0x1b, 0xdf, 0xbd, 0xb2, + 0x2b, 0xcf, 0x5f, 0xd9, 0x95, 0x17, 0xaf, 0xec, 0xca, 0x57, 0x35, 0xf5, 0x79, 0xdc, 0x9b, 0x57, + 0x63, 0xf6, 0xc9, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x10, 0x9d, 0x19, 0x75, 0x0f, 0x00, + 0x00, } func (x PeerAction) String() string { @@ -1019,6 +1029,9 @@ func (this *EpochStartShardData) Equal(that interface{}) bool { if !bytes.Equal(this.RootHash, that1.RootHash) { return false } + if !bytes.Equal(this.ScheduledRootHash, that1.ScheduledRootHash) { + return false + } if !bytes.Equal(this.FirstPendingMetaBlock, that1.FirstPendingMetaBlock) { return false } @@ -1300,7 +1313,7 @@ func (this *EpochStartShardData) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 13) + s := make([]string, 0, 14) s = append(s, "&block.EpochStartShardData{") s = append(s, "ShardID: "+fmt.Sprintf("%#v", this.ShardID)+",\n") s = append(s, "Epoch: "+fmt.Sprintf("%#v", this.Epoch)+",\n") @@ -1308,6 +1321,7 @@ func (this *EpochStartShardData) GoString() string { s = append(s, "Nonce: "+fmt.Sprintf("%#v", this.Nonce)+",\n") s = append(s, "HeaderHash: "+fmt.Sprintf("%#v", this.HeaderHash)+",\n") s = append(s, "RootHash: "+fmt.Sprintf("%#v", this.RootHash)+",\n") + s = append(s, "ScheduledRootHash: "+fmt.Sprintf("%#v", this.ScheduledRootHash)+",\n") s = append(s, "FirstPendingMetaBlock: "+fmt.Sprintf("%#v", this.FirstPendingMetaBlock)+",\n") s = append(s, "LastFinishedMetaBlock: "+fmt.Sprintf("%#v", this.LastFinishedMetaBlock)+",\n") if this.PendingMiniBlockHeaders != nil { @@ -1616,6 +1630,13 @@ func (m *EpochStartShardData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.ScheduledRootHash) > 0 { + i -= len(m.ScheduledRootHash) + copy(dAtA[i:], m.ScheduledRootHash) + i = encodeVarintMetaBlock(dAtA, i, uint64(len(m.ScheduledRootHash))) + i-- + dAtA[i] = 0x52 + } if m.Epoch != 0 { i = encodeVarintMetaBlock(dAtA, i, uint64(m.Epoch)) i-- @@ -2221,6 +2242,10 @@ func (m *EpochStartShardData) Size() (n int) { if m.Epoch != 0 { n += 1 + sovMetaBlock(uint64(m.Epoch)) } + l = len(m.ScheduledRootHash) + if l > 0 { + n += 1 + l + sovMetaBlock(uint64(l)) + } return n } @@ -2466,6 +2491,7 @@ func (this *EpochStartShardData) String() string { `Round:` + fmt.Sprintf("%v", this.Round) + `,`, `Nonce:` + fmt.Sprintf("%v", this.Nonce) + `,`, `Epoch:` + fmt.Sprintf("%v", this.Epoch) + `,`, + `ScheduledRootHash:` + fmt.Sprintf("%v", this.ScheduledRootHash) + `,`, `}`, }, "") return s @@ -3479,6 +3505,40 @@ func (m *EpochStartShardData) Unmarshal(dAtA []byte) error { break } } + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ScheduledRootHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetaBlock + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMetaBlock + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthMetaBlock + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ScheduledRootHash = append(m.ScheduledRootHash[:0], dAtA[iNdEx:postIndex]...) + if m.ScheduledRootHash == nil { + m.ScheduledRootHash = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMetaBlock(dAtA[iNdEx:]) diff --git a/data/block/proto/metaBlock.proto b/data/block/metaBlock.proto similarity index 98% rename from data/block/proto/metaBlock.proto rename to data/block/metaBlock.proto index 450933136..c90c2d2f8 100644 --- a/data/block/proto/metaBlock.proto +++ b/data/block/metaBlock.proto @@ -60,6 +60,7 @@ message EpochStartShardData { uint64 Nonce = 8; bytes HeaderHash = 2; bytes RootHash = 3; + bytes ScheduledRootHash = 10; bytes FirstPendingMetaBlock = 4; bytes LastFinishedMetaBlock = 5; repeated MiniBlockHeader PendingMiniBlockHeaders = 6 [(gogoproto.nullable) = false]; diff --git a/data/block/metaBlock_test.go b/data/block/metaBlock_test.go index a98eb5007..56ec35cd3 100644 --- a/data/block/metaBlock_test.go +++ b/data/block/metaBlock_test.go @@ -4,7 +4,9 @@ import ( "testing" "github.com/ElrondNetwork/elrond-go-core/core" + "github.com/ElrondNetwork/elrond-go-core/data" "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -143,8 +145,9 @@ func TestMetaBlock_SetEpoch(t *testing.T) { epoch := uint32(10) m := block.MetaBlock{} - m.SetEpoch(epoch) + err := m.SetEpoch(epoch) + assert.Nil(t, err) assert.Equal(t, epoch, m.GetEpoch()) } @@ -153,8 +156,9 @@ func TestMetaBlock_SetNonce(t *testing.T) { nonce := uint64(11) m := block.MetaBlock{} - m.SetNonce(nonce) + err := m.SetNonce(nonce) + assert.Nil(t, err) assert.Equal(t, nonce, m.GetNonce()) } @@ -163,8 +167,9 @@ func TestMetaBlock_SetPrevHash(t *testing.T) { prevHash := []byte("prev hash") m := block.MetaBlock{} - m.SetPrevHash(prevHash) + err := m.SetPrevHash(prevHash) + assert.Nil(t, err) assert.Equal(t, prevHash, m.GetPrevHash()) } @@ -173,8 +178,9 @@ func TestMetaBlock_SetPubKeysBitmap(t *testing.T) { pubKeysBitmap := []byte{12, 13, 14, 15} m := block.MetaBlock{} - m.SetPubKeysBitmap(pubKeysBitmap) + err := m.SetPubKeysBitmap(pubKeysBitmap) + assert.Nil(t, err) assert.Equal(t, pubKeysBitmap, m.GetPubKeysBitmap()) } @@ -183,8 +189,9 @@ func TestMetaBlock_SetPrevRandSeed(t *testing.T) { prevRandSeed := []byte("previous random seed") m := block.MetaBlock{} - m.SetPrevRandSeed(prevRandSeed) + err := m.SetPrevRandSeed(prevRandSeed) + assert.Nil(t, err) assert.Equal(t, prevRandSeed, m.GetPrevRandSeed()) } @@ -193,8 +200,9 @@ func TestMetaBlock_SetRandSeed(t *testing.T) { randSeed := []byte("random seed") m := block.MetaBlock{} - m.SetRandSeed(randSeed) + err := m.SetRandSeed(randSeed) + assert.Nil(t, err) assert.Equal(t, randSeed, m.GetRandSeed()) } @@ -203,8 +211,9 @@ func TestMetaBlock_SetRootHash(t *testing.T) { rootHash := []byte("root hash") m := block.MetaBlock{} - m.SetRootHash(rootHash) + err := m.SetRootHash(rootHash) + assert.Nil(t, err) assert.Equal(t, rootHash, m.GetRootHash()) } @@ -213,8 +222,9 @@ func TestMetaBlock_SetRound(t *testing.T) { rootHash := []byte("root hash") m := block.MetaBlock{} - m.SetRootHash(rootHash) + err := m.SetRootHash(rootHash) + assert.Nil(t, err) assert.Equal(t, rootHash, m.GetRootHash()) } @@ -223,8 +233,9 @@ func TestMetaBlock_SetSignature(t *testing.T) { signature := []byte("signature") m := block.MetaBlock{} - m.SetSignature(signature) + err := m.SetSignature(signature) + assert.Nil(t, err) assert.Equal(t, signature, m.GetSignature()) } @@ -233,8 +244,9 @@ func TestMetaBlock_SetTimeStamp(t *testing.T) { timestamp := uint64(100000) m := block.MetaBlock{} - m.SetTimeStamp(timestamp) + err := m.SetTimeStamp(timestamp) + assert.Nil(t, err) assert.Equal(t, timestamp, m.GetTimeStamp()) } @@ -243,8 +255,9 @@ func TestMetaBlock_SetTxCount(t *testing.T) { txCount := uint32(100) m := block.MetaBlock{} - m.SetTxCount(txCount) + err := m.SetTxCount(txCount) + assert.Nil(t, err) assert.Equal(t, txCount, m.GetTxCount()) } @@ -346,3 +359,29 @@ func TestMetaBlock_GetOrderedCrossMiniblocksWithDstShouldWork(t *testing.T) { assert.Equal(t, miniBlocksInfo[2].Hash, []byte("hash5")) assert.Equal(t, miniBlocksInfo[2].Round, uint64(7)) } + +func TestMetaBlock_SetScheduledRootHash(t *testing.T) { + t.Parallel() + + metaHdr := &block.MetaBlock{} + err := metaHdr.SetScheduledRootHash([]byte("")) + require.Equal(t, data.ErrScheduledRootHashNotSupported, err) +} + +func TestMetaBlock_ValidateHeaderVersion(t *testing.T) { + t.Parallel() + + metaHdr := &block.MetaBlock{} + err := metaHdr.ValidateHeaderVersion() + require.Nil(t, err) +} + +func TestMetaBlock_SetAdditionalDataShouldDoNothing(t *testing.T) { + t.Parallel() + + var metaBlock *block.MetaBlock + + //goland:noinspection ALL + err := metaBlock.SetAdditionalData(&headerVersionData.AdditionalData{}) + require.Nil(t, err) +} diff --git a/data/block/miniBlockHeader.go b/data/block/miniBlockHeader.go new file mode 100644 index 000000000..8d52709c6 --- /dev/null +++ b/data/block/miniBlockHeader.go @@ -0,0 +1,89 @@ +package block + +import "github.com/ElrondNetwork/elrond-go-core/data" + +// GetTypeInt32 gets the miniBlock type +func (m *MiniBlockHeader) GetTypeInt32() int32 { + if m == nil { + return -1 + } + + return int32(m.Type) +} + +// SetHash sets the miniBlock hash +func (m *MiniBlockHeader) SetHash(hash []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.Hash = hash + + return nil +} + +// SetSenderShardID sets the miniBlock sender shardID +func (m *MiniBlockHeader) SetSenderShardID(shardID uint32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.SenderShardID = shardID + + return nil +} + +// SetReceiverShardID sets the miniBlock receiver ShardID +func (m *MiniBlockHeader) SetReceiverShardID(shardID uint32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.ReceiverShardID = shardID + + return nil +} + +// SetTxCount sets the miniBlock txs count +func (m *MiniBlockHeader) SetTxCount(count uint32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.TxCount = count + + return nil +} + +// SetTypeInt32 sets the miniBlock type +func (m *MiniBlockHeader) SetTypeInt32(t int32) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.Type = Type(t) + + return nil +} + +// SetReserved sets the miniBlock reserved field +func (m *MiniBlockHeader) SetReserved(reserved []byte) error { + if m == nil { + return data.ErrNilPointerReceiver + } + + m.Reserved = reserved + + return nil +} + +// ShallowClone returns the miniBlockHeader swallow clone +func (m *MiniBlockHeader) ShallowClone() data.MiniBlockHeaderHandler { + if m == nil { + return nil + } + + mbhCopy := *m + + return &mbhCopy +} diff --git a/data/block/peerBlock.go b/data/block/peerBlock.go new file mode 100644 index 000000000..3b5e2e3ff --- /dev/null +++ b/data/block/peerBlock.go @@ -0,0 +1,25 @@ +package block + +import "github.com/ElrondNetwork/elrond-go-core/data" + +// SetPubKey - setter for public key +func (pc *PeerChange) SetPubKey(pubKey []byte) error { + if pc == nil { + return data.ErrNilPointerReceiver + } + + pc.PubKey = pubKey + + return nil +} + +// SetShardIdDest - setter for destination shardID +func (pc *PeerChange) SetShardIdDest(shardID uint32) error { + if pc == nil { + return data.ErrNilPointerReceiver + } + + pc.ShardIdDest = shardID + + return nil +} diff --git a/data/block/shardDataHandler.go b/data/block/shardDataHandler.go new file mode 100644 index 000000000..dce41b421 --- /dev/null +++ b/data/block/shardDataHandler.go @@ -0,0 +1,214 @@ +package block + +import ( + "math/big" + + "github.com/ElrondNetwork/elrond-go-core/data" +) + +// GetShardMiniBlockHeaderHandlers returns the shard miniBlockHeaders as MiniBlockHeaderHandlers +func (sd *ShardData) GetShardMiniBlockHeaderHandlers() []data.MiniBlockHeaderHandler { + if sd == nil || sd.ShardMiniBlockHeaders == nil { + return nil + } + + miniBlockHeaderHandlers := make([]data.MiniBlockHeaderHandler, len(sd.ShardMiniBlockHeaders)) + for i := range sd.ShardMiniBlockHeaders { + miniBlockHeaderHandlers[i] = &sd.ShardMiniBlockHeaders[i] + } + + return miniBlockHeaderHandlers +} + +// SetHeaderHash sets the header hash +func (sd *ShardData) SetHeaderHash(hash []byte) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.HeaderHash = hash + return nil +} + +// SetShardMiniBlockHeaderHandlers sets the miniBlockHeaders from a list of MiniBlockHeaderHandler +func (sd *ShardData) SetShardMiniBlockHeaderHandlers(mbHeaderHandlers []data.MiniBlockHeaderHandler) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + if mbHeaderHandlers == nil { + sd.ShardMiniBlockHeaders = nil + return nil + } + + miniBlockHeaders := make([]MiniBlockHeader, len(mbHeaderHandlers)) + for i, mbh := range mbHeaderHandlers { + mbHeader, ok := mbh.(*MiniBlockHeader) + if !ok { + return data.ErrInvalidTypeAssertion + } + if mbHeader == nil { + return data.ErrNilPointerDereference + } + + miniBlockHeaders[i] = *mbHeader + } + + sd.ShardMiniBlockHeaders = miniBlockHeaders + + return nil +} + +// SetPrevRandSeed sets the prevRandSeed +func (sd *ShardData) SetPrevRandSeed(prevRandSeed []byte) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.PrevRandSeed = prevRandSeed + + return nil +} + +// SetPubKeysBitmap sets the pubKeysBitmap +func (sd *ShardData) SetPubKeysBitmap(pubKeysBitmap []byte) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.PubKeysBitmap = pubKeysBitmap + + return nil +} + +// SetSignature sets the signature +func (sd *ShardData) SetSignature(signature []byte) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.Signature = signature + + return nil +} + +// SetRound sets the round +func (sd *ShardData) SetRound(round uint64) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.Round = round + + return nil +} + +// SetPrevHash sets the prevHash +func (sd *ShardData) SetPrevHash(prevHash []byte) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.PrevHash = prevHash + + return nil +} + +// SetNonce sets the nonce +func (sd *ShardData) SetNonce(nonce uint64) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.Nonce = nonce + + return nil +} + +// SetAccumulatedFees sets the accumulatedFees +func (sd *ShardData) SetAccumulatedFees(fees *big.Int) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + if fees == nil { + return data.ErrInvalidValue + } + if sd.AccumulatedFees == nil { + sd.AccumulatedFees = big.NewInt(0) + } + + sd.AccumulatedFees.Set(fees) + + return nil +} + +// SetDeveloperFees sets the developerFees +func (sd *ShardData) SetDeveloperFees(fees *big.Int) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + if fees == nil { + return data.ErrInvalidValue + } + if sd.DeveloperFees == nil { + sd.DeveloperFees = big.NewInt(0) + } + + sd.DeveloperFees.Set(fees) + + return nil +} + +// SetNumPendingMiniBlocks sets the number of pending miniBlocks +func (sd *ShardData) SetNumPendingMiniBlocks(num uint32) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.NumPendingMiniBlocks = num + + return nil +} + +// SetLastIncludedMetaNonce sets the last included metaBlock nonce +func (sd *ShardData) SetLastIncludedMetaNonce(nonce uint64) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.LastIncludedMetaNonce = nonce + + return nil +} + +// SetShardID sets the shardID +func (sd *ShardData) SetShardID(shardID uint32) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.ShardID = shardID + + return nil +} + +// SetTxCount sets the transaction count +func (sd *ShardData) SetTxCount(txCount uint32) error { + if sd == nil { + return data.ErrNilPointerReceiver + } + + sd.TxCount = txCount + + return nil +} + +// ShallowClone creates and returns a shallow clone of shardData +func (sd *ShardData) ShallowClone() data.ShardDataHandler { + if sd == nil { + return nil + } + + shardDataCopy := *sd + + return &shardDataCopy +} diff --git a/data/block/trigger.go b/data/block/trigger.go new file mode 100644 index 000000000..2a9a6dacf --- /dev/null +++ b/data/block/trigger.go @@ -0,0 +1,193 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. trigger.proto +package block + +import "github.com/ElrondNetwork/elrond-go-core/data" + +// GetEpochStartHeaderHandler returns the epoch start headerHandler +func (str *ShardTriggerRegistry) GetEpochStartHeaderHandler() data.HeaderHandler { + if str == nil { + return nil + } + return str.GetEpochStartShardHeader() +} + +// SetIsEpochStart sets the isEpochStart flag +func (str *ShardTriggerRegistry) SetIsEpochStart(isEpochStart bool) error { + if str == nil { + return data.ErrNilPointerReceiver + } + + str.IsEpochStart = isEpochStart + return nil +} + +// SetNewEpochHeaderReceived sets the newEpochHeaderReceived flag +func (str *ShardTriggerRegistry) SetNewEpochHeaderReceived(newEpochHeaderReceived bool) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.NewEpochHeaderReceived = newEpochHeaderReceived + return nil +} + +// SetEpoch sets the epoch +func (str *ShardTriggerRegistry) SetEpoch(epoch uint32) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.Epoch = epoch + return nil +} + +// SetMetaEpoch Sets the metaChain epoch +func (str *ShardTriggerRegistry) SetMetaEpoch(metaEpoch uint32) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.MetaEpoch = metaEpoch + return nil +} + +// SetCurrentRoundIndex sets the current round index +func (str *ShardTriggerRegistry) SetCurrentRoundIndex(roundIndex int64) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.CurrentRoundIndex = roundIndex + return nil +} + +// SetEpochStartRound sets the epoch start round +func (str *ShardTriggerRegistry) SetEpochStartRound(startRound uint64) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.EpochStartRound = startRound + return nil +} + +// SetEpochFinalityAttestingRound sets the epoch finality attesting round +func (str *ShardTriggerRegistry) SetEpochFinalityAttestingRound(finalityAttestingRound uint64) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.EpochFinalityAttestingRound = finalityAttestingRound + return nil +} + +// SetEpochMetaBlockHash sets the epoch metaChain block hash +func (str *ShardTriggerRegistry) SetEpochMetaBlockHash(epochMetaBlockHash []byte) error { + if str == nil { + return data.ErrNilPointerReceiver + } + str.EpochMetaBlockHash = epochMetaBlockHash + return nil +} + +// SetEpochStartHeaderHandler sets the epoch start header +func (str *ShardTriggerRegistry) SetEpochStartHeaderHandler(epochStartHeaderHandler data.HeaderHandler) error { + if str == nil { + return data.ErrNilPointerReceiver + } + + var ok bool + str.EpochStartShardHeader, ok = epochStartHeaderHandler.(*Header) + if !ok { + return data.ErrInvalidTypeAssertion + } + return nil +} + +// GetEpochStartHeaderHandler returns the epoch start headerHandler +func (strV2 *ShardTriggerRegistryV2) GetEpochStartHeaderHandler() data.HeaderHandler { + if strV2 == nil { + return nil + } + return strV2.GetEpochStartShardHeader() +} + +// SetIsEpochStart sets the isEpochStart flag +func (strV2 *ShardTriggerRegistryV2) SetIsEpochStart(isEpochStart bool) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.IsEpochStart = isEpochStart + return nil +} + +// SetNewEpochHeaderReceived sets the neeEpochHeaderReceived flag +func (strV2 *ShardTriggerRegistryV2) SetNewEpochHeaderReceived(newEpochHeaderReceived bool) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.NewEpochHeaderReceived = newEpochHeaderReceived + return nil +} + +// SetEpoch sets the epoch +func (strV2 *ShardTriggerRegistryV2) SetEpoch(epoch uint32) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.Epoch = epoch + return nil +} + +// SetMetaEpoch sets the metaChain epoch +func (strV2 *ShardTriggerRegistryV2) SetMetaEpoch(metaEpoch uint32) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.MetaEpoch = metaEpoch + return nil +} + +// SetCurrentRoundIndex sets the current round index +func (strV2 *ShardTriggerRegistryV2) SetCurrentRoundIndex(roundIndex int64) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.CurrentRoundIndex = roundIndex + return nil +} + +// SetEpochStartRound sets the epoch start round +func (strV2 *ShardTriggerRegistryV2) SetEpochStartRound(startRound uint64) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.EpochStartRound = startRound + return nil +} + +// SetEpochFinalityAttestingRound sets the epoch finality attesting round +func (strV2 *ShardTriggerRegistryV2) SetEpochFinalityAttestingRound(finalityAttestingRound uint64) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.EpochFinalityAttestingRound = finalityAttestingRound + return nil +} + +// SetEpochMetaBlockHash sets the epoch metaChain block hash +func (strV2 *ShardTriggerRegistryV2) SetEpochMetaBlockHash(epochMetaBlockHash []byte) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + strV2.EpochMetaBlockHash = epochMetaBlockHash + return nil +} + +// SetEpochStartHeaderHandler sets the epoch start header +func (strV2 *ShardTriggerRegistryV2) SetEpochStartHeaderHandler(epochStartHeaderHandler data.HeaderHandler) error { + if strV2 == nil { + return data.ErrNilPointerReceiver + } + + var ok bool + strV2.EpochStartShardHeader, ok = epochStartHeaderHandler.(*HeaderV2) + if !ok { + return data.ErrInvalidTypeAssertion + } + return nil +} diff --git a/data/block/trigger.pb.go b/data/block/trigger.pb.go new file mode 100644 index 000000000..3db9b3312 --- /dev/null +++ b/data/block/trigger.pb.go @@ -0,0 +1,1815 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: trigger.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 + +type ShardTriggerRegistry struct { + IsEpochStart bool `protobuf:"varint,1,opt,name=IsEpochStart,proto3" json:"IsEpochStart,omitempty"` + NewEpochHeaderReceived bool `protobuf:"varint,2,opt,name=NewEpochHeaderReceived,proto3" json:"NewEpochHeaderReceived,omitempty"` + Epoch uint32 `protobuf:"varint,3,opt,name=Epoch,proto3" json:"Epoch,omitempty"` + MetaEpoch uint32 `protobuf:"varint,4,opt,name=MetaEpoch,proto3" json:"MetaEpoch,omitempty"` + CurrentRoundIndex int64 `protobuf:"varint,5,opt,name=CurrentRoundIndex,proto3" json:"CurrentRoundIndex,omitempty"` + EpochStartRound uint64 `protobuf:"varint,6,opt,name=EpochStartRound,proto3" json:"EpochStartRound,omitempty"` + EpochFinalityAttestingRound uint64 `protobuf:"varint,7,opt,name=EpochFinalityAttestingRound,proto3" json:"EpochFinalityAttestingRound,omitempty"` + EpochMetaBlockHash []byte `protobuf:"bytes,8,opt,name=EpochMetaBlockHash,proto3" json:"EpochMetaBlockHash,omitempty"` + EpochStartShardHeader *Header `protobuf:"bytes,9,opt,name=EpochStartShardHeader,proto3" json:"EpochStartShardHeader,omitempty"` +} + +func (m *ShardTriggerRegistry) Reset() { *m = ShardTriggerRegistry{} } +func (*ShardTriggerRegistry) ProtoMessage() {} +func (*ShardTriggerRegistry) Descriptor() ([]byte, []int) { + return fileDescriptor_8c31e6d8b4368946, []int{0} +} +func (m *ShardTriggerRegistry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ShardTriggerRegistry) 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 *ShardTriggerRegistry) XXX_Merge(src proto.Message) { + xxx_messageInfo_ShardTriggerRegistry.Merge(m, src) +} +func (m *ShardTriggerRegistry) XXX_Size() int { + return m.Size() +} +func (m *ShardTriggerRegistry) XXX_DiscardUnknown() { + xxx_messageInfo_ShardTriggerRegistry.DiscardUnknown(m) +} + +var xxx_messageInfo_ShardTriggerRegistry proto.InternalMessageInfo + +func (m *ShardTriggerRegistry) GetIsEpochStart() bool { + if m != nil { + return m.IsEpochStart + } + return false +} + +func (m *ShardTriggerRegistry) GetNewEpochHeaderReceived() bool { + if m != nil { + return m.NewEpochHeaderReceived + } + return false +} + +func (m *ShardTriggerRegistry) GetEpoch() uint32 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *ShardTriggerRegistry) GetMetaEpoch() uint32 { + if m != nil { + return m.MetaEpoch + } + return 0 +} + +func (m *ShardTriggerRegistry) GetCurrentRoundIndex() int64 { + if m != nil { + return m.CurrentRoundIndex + } + return 0 +} + +func (m *ShardTriggerRegistry) GetEpochStartRound() uint64 { + if m != nil { + return m.EpochStartRound + } + return 0 +} + +func (m *ShardTriggerRegistry) GetEpochFinalityAttestingRound() uint64 { + if m != nil { + return m.EpochFinalityAttestingRound + } + return 0 +} + +func (m *ShardTriggerRegistry) GetEpochMetaBlockHash() []byte { + if m != nil { + return m.EpochMetaBlockHash + } + return nil +} + +func (m *ShardTriggerRegistry) GetEpochStartShardHeader() *Header { + if m != nil { + return m.EpochStartShardHeader + } + return nil +} + +type ShardTriggerRegistryV2 struct { + EpochStartShardHeader *HeaderV2 `protobuf:"bytes,1,opt,name=EpochStartShardHeader,proto3" json:"EpochStartShardHeader,omitempty"` + IsEpochStart bool `protobuf:"varint,2,opt,name=IsEpochStart,proto3" json:"IsEpochStart,omitempty"` + NewEpochHeaderReceived bool `protobuf:"varint,3,opt,name=NewEpochHeaderReceived,proto3" json:"NewEpochHeaderReceived,omitempty"` + Epoch uint32 `protobuf:"varint,4,opt,name=Epoch,proto3" json:"Epoch,omitempty"` + MetaEpoch uint32 `protobuf:"varint,5,opt,name=MetaEpoch,proto3" json:"MetaEpoch,omitempty"` + CurrentRoundIndex int64 `protobuf:"varint,6,opt,name=CurrentRoundIndex,proto3" json:"CurrentRoundIndex,omitempty"` + EpochStartRound uint64 `protobuf:"varint,7,opt,name=EpochStartRound,proto3" json:"EpochStartRound,omitempty"` + EpochFinalityAttestingRound uint64 `protobuf:"varint,8,opt,name=EpochFinalityAttestingRound,proto3" json:"EpochFinalityAttestingRound,omitempty"` + EpochMetaBlockHash []byte `protobuf:"bytes,9,opt,name=EpochMetaBlockHash,proto3" json:"EpochMetaBlockHash,omitempty"` +} + +func (m *ShardTriggerRegistryV2) Reset() { *m = ShardTriggerRegistryV2{} } +func (*ShardTriggerRegistryV2) ProtoMessage() {} +func (*ShardTriggerRegistryV2) Descriptor() ([]byte, []int) { + return fileDescriptor_8c31e6d8b4368946, []int{1} +} +func (m *ShardTriggerRegistryV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ShardTriggerRegistryV2) 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 *ShardTriggerRegistryV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_ShardTriggerRegistryV2.Merge(m, src) +} +func (m *ShardTriggerRegistryV2) XXX_Size() int { + return m.Size() +} +func (m *ShardTriggerRegistryV2) XXX_DiscardUnknown() { + xxx_messageInfo_ShardTriggerRegistryV2.DiscardUnknown(m) +} + +var xxx_messageInfo_ShardTriggerRegistryV2 proto.InternalMessageInfo + +func (m *ShardTriggerRegistryV2) GetEpochStartShardHeader() *HeaderV2 { + if m != nil { + return m.EpochStartShardHeader + } + return nil +} + +func (m *ShardTriggerRegistryV2) GetIsEpochStart() bool { + if m != nil { + return m.IsEpochStart + } + return false +} + +func (m *ShardTriggerRegistryV2) GetNewEpochHeaderReceived() bool { + if m != nil { + return m.NewEpochHeaderReceived + } + return false +} + +func (m *ShardTriggerRegistryV2) GetEpoch() uint32 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *ShardTriggerRegistryV2) GetMetaEpoch() uint32 { + if m != nil { + return m.MetaEpoch + } + return 0 +} + +func (m *ShardTriggerRegistryV2) GetCurrentRoundIndex() int64 { + if m != nil { + return m.CurrentRoundIndex + } + return 0 +} + +func (m *ShardTriggerRegistryV2) GetEpochStartRound() uint64 { + if m != nil { + return m.EpochStartRound + } + return 0 +} + +func (m *ShardTriggerRegistryV2) GetEpochFinalityAttestingRound() uint64 { + if m != nil { + return m.EpochFinalityAttestingRound + } + return 0 +} + +func (m *ShardTriggerRegistryV2) GetEpochMetaBlockHash() []byte { + if m != nil { + return m.EpochMetaBlockHash + } + return nil +} + +type MetaTriggerRegistry 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"` + EpochStartMeta *MetaBlock `protobuf:"bytes,7,opt,name=EpochStartMeta,proto3" json:"EpochStartMeta,omitempty"` +} + +func (m *MetaTriggerRegistry) Reset() { *m = MetaTriggerRegistry{} } +func (*MetaTriggerRegistry) ProtoMessage() {} +func (*MetaTriggerRegistry) Descriptor() ([]byte, []int) { + return fileDescriptor_8c31e6d8b4368946, []int{2} +} +func (m *MetaTriggerRegistry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MetaTriggerRegistry) 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 *MetaTriggerRegistry) XXX_Merge(src proto.Message) { + xxx_messageInfo_MetaTriggerRegistry.Merge(m, src) +} +func (m *MetaTriggerRegistry) XXX_Size() int { + return m.Size() +} +func (m *MetaTriggerRegistry) XXX_DiscardUnknown() { + xxx_messageInfo_MetaTriggerRegistry.DiscardUnknown(m) +} + +var xxx_messageInfo_MetaTriggerRegistry proto.InternalMessageInfo + +func (m *MetaTriggerRegistry) GetEpoch() uint32 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *MetaTriggerRegistry) GetCurrentRound() uint64 { + if m != nil { + return m.CurrentRound + } + return 0 +} + +func (m *MetaTriggerRegistry) GetEpochFinalityAttestingRound() uint64 { + if m != nil { + return m.EpochFinalityAttestingRound + } + return 0 +} + +func (m *MetaTriggerRegistry) GetCurrEpochStartRound() uint64 { + if m != nil { + return m.CurrEpochStartRound + } + return 0 +} + +func (m *MetaTriggerRegistry) GetPrevEpochStartRound() uint64 { + if m != nil { + return m.PrevEpochStartRound + } + return 0 +} + +func (m *MetaTriggerRegistry) GetEpochStartMetaHash() []byte { + if m != nil { + return m.EpochStartMetaHash + } + return nil +} + +func (m *MetaTriggerRegistry) GetEpochStartMeta() *MetaBlock { + if m != nil { + return m.EpochStartMeta + } + return nil +} + +func init() { + proto.RegisterType((*ShardTriggerRegistry)(nil), "proto.ShardTriggerRegistry") + proto.RegisterType((*ShardTriggerRegistryV2)(nil), "proto.ShardTriggerRegistryV2") + proto.RegisterType((*MetaTriggerRegistry)(nil), "proto.MetaTriggerRegistry") +} + +func init() { proto.RegisterFile("trigger.proto", fileDescriptor_8c31e6d8b4368946) } + +var fileDescriptor_8c31e6d8b4368946 = []byte{ + // 532 bytes of a gzipped FileDescri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x2b, 0x0d, 0x80, 0x7e, + 0xad, 0x00, 0x54, 0x6f, 0x10, 0x80, 0xb5, 0x5b, 0x05, 0xa0, 0x76, 0xdb, 0x00, 0xd4, 0xcb, 0x02, + 0x60, 0xfd, 0xaa, 0xe0, 0xf5, 0x04, 0xc9, 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, +} + +func (this *ShardTriggerRegistry) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ShardTriggerRegistry) + if !ok { + that2, ok := that.(ShardTriggerRegistry) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.IsEpochStart != that1.IsEpochStart { + return false + } + if this.NewEpochHeaderReceived != that1.NewEpochHeaderReceived { + return false + } + if this.Epoch != that1.Epoch { + return false + } + if this.MetaEpoch != that1.MetaEpoch { + return false + } + if this.CurrentRoundIndex != that1.CurrentRoundIndex { + return false + } + if this.EpochStartRound != that1.EpochStartRound { + return false + } + if this.EpochFinalityAttestingRound != that1.EpochFinalityAttestingRound { + return false + } + if !bytes.Equal(this.EpochMetaBlockHash, that1.EpochMetaBlockHash) { + return false + } + if !this.EpochStartShardHeader.Equal(that1.EpochStartShardHeader) { + return false + } + return true +} +func (this *ShardTriggerRegistryV2) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ShardTriggerRegistryV2) + if !ok { + that2, ok := that.(ShardTriggerRegistryV2) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.EpochStartShardHeader.Equal(that1.EpochStartShardHeader) { + return false + } + if this.IsEpochStart != that1.IsEpochStart { + return false + } + if this.NewEpochHeaderReceived != that1.NewEpochHeaderReceived { + return false + } + if this.Epoch != that1.Epoch { + return false + } + if this.MetaEpoch != that1.MetaEpoch { + return false + } + if this.CurrentRoundIndex != that1.CurrentRoundIndex { + return false + } + if this.EpochStartRound != that1.EpochStartRound { + return false + } + if this.EpochFinalityAttestingRound != that1.EpochFinalityAttestingRound { + return false + } + if !bytes.Equal(this.EpochMetaBlockHash, that1.EpochMetaBlockHash) { + return false + } + return true +} +func (this *MetaTriggerRegistry) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*MetaTriggerRegistry) + if !ok { + that2, ok := that.(MetaTriggerRegistry) + 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.EpochStartMeta.Equal(that1.EpochStartMeta) { + return false + } + return true +} +func (this *ShardTriggerRegistry) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 13) + s = append(s, "&block.ShardTriggerRegistry{") + s = append(s, "IsEpochStart: "+fmt.Sprintf("%#v", this.IsEpochStart)+",\n") + s = append(s, "NewEpochHeaderReceived: "+fmt.Sprintf("%#v", this.NewEpochHeaderReceived)+",\n") + s = append(s, "Epoch: "+fmt.Sprintf("%#v", this.Epoch)+",\n") + s = append(s, "MetaEpoch: "+fmt.Sprintf("%#v", this.MetaEpoch)+",\n") + s = append(s, "CurrentRoundIndex: "+fmt.Sprintf("%#v", this.CurrentRoundIndex)+",\n") + s = append(s, "EpochStartRound: "+fmt.Sprintf("%#v", this.EpochStartRound)+",\n") + s = append(s, "EpochFinalityAttestingRound: "+fmt.Sprintf("%#v", this.EpochFinalityAttestingRound)+",\n") + s = append(s, "EpochMetaBlockHash: "+fmt.Sprintf("%#v", this.EpochMetaBlockHash)+",\n") + if this.EpochStartShardHeader != nil { + s = append(s, "EpochStartShardHeader: "+fmt.Sprintf("%#v", this.EpochStartShardHeader)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *ShardTriggerRegistryV2) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 13) + s = append(s, "&block.ShardTriggerRegistryV2{") + if this.EpochStartShardHeader != nil { + s = append(s, "EpochStartShardHeader: "+fmt.Sprintf("%#v", this.EpochStartShardHeader)+",\n") + } + s = append(s, "IsEpochStart: "+fmt.Sprintf("%#v", this.IsEpochStart)+",\n") + s = append(s, "NewEpochHeaderReceived: "+fmt.Sprintf("%#v", this.NewEpochHeaderReceived)+",\n") + s = append(s, "Epoch: "+fmt.Sprintf("%#v", this.Epoch)+",\n") + s = append(s, "MetaEpoch: "+fmt.Sprintf("%#v", this.MetaEpoch)+",\n") + s = append(s, "CurrentRoundIndex: "+fmt.Sprintf("%#v", this.CurrentRoundIndex)+",\n") + s = append(s, "EpochStartRound: "+fmt.Sprintf("%#v", this.EpochStartRound)+",\n") + s = append(s, "EpochFinalityAttestingRound: "+fmt.Sprintf("%#v", this.EpochFinalityAttestingRound)+",\n") + s = append(s, "EpochMetaBlockHash: "+fmt.Sprintf("%#v", this.EpochMetaBlockHash)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *MetaTriggerRegistry) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 11) + s = append(s, "&block.MetaTriggerRegistry{") + 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.EpochStartMeta != nil { + s = append(s, "EpochStartMeta: "+fmt.Sprintf("%#v", this.EpochStartMeta)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringTrigger(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 *ShardTriggerRegistry) 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 *ShardTriggerRegistry) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ShardTriggerRegistry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EpochStartShardHeader != nil { + { + size, err := m.EpochStartShardHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTrigger(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + } + if len(m.EpochMetaBlockHash) > 0 { + i -= len(m.EpochMetaBlockHash) + copy(dAtA[i:], m.EpochMetaBlockHash) + i = encodeVarintTrigger(dAtA, i, uint64(len(m.EpochMetaBlockHash))) + i-- + dAtA[i] = 0x42 + } + if m.EpochFinalityAttestingRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.EpochFinalityAttestingRound)) + i-- + dAtA[i] = 0x38 + } + if m.EpochStartRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.EpochStartRound)) + i-- + dAtA[i] = 0x30 + } + if m.CurrentRoundIndex != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.CurrentRoundIndex)) + i-- + dAtA[i] = 0x28 + } + if m.MetaEpoch != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.MetaEpoch)) + i-- + dAtA[i] = 0x20 + } + if m.Epoch != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x18 + } + if m.NewEpochHeaderReceived { + i-- + if m.NewEpochHeaderReceived { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.IsEpochStart { + i-- + if m.IsEpochStart { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ShardTriggerRegistryV2) 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 *ShardTriggerRegistryV2) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ShardTriggerRegistryV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EpochMetaBlockHash) > 0 { + i -= len(m.EpochMetaBlockHash) + copy(dAtA[i:], m.EpochMetaBlockHash) + i = encodeVarintTrigger(dAtA, i, uint64(len(m.EpochMetaBlockHash))) + i-- + dAtA[i] = 0x4a + } + if m.EpochFinalityAttestingRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.EpochFinalityAttestingRound)) + i-- + dAtA[i] = 0x40 + } + if m.EpochStartRound != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.EpochStartRound)) + i-- + dAtA[i] = 0x38 + } + if m.CurrentRoundIndex != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.CurrentRoundIndex)) + i-- + dAtA[i] = 0x30 + } + if m.MetaEpoch != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.MetaEpoch)) + i-- + dAtA[i] = 0x28 + } + if m.Epoch != 0 { + i = encodeVarintTrigger(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x20 + } + if m.NewEpochHeaderReceived { + i-- + if m.NewEpochHeaderReceived { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } + if m.IsEpochStart { + i-- + if m.IsEpochStart { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.EpochStartShardHeader != nil { + { + size, err := m.EpochStartShardHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTrigger(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MetaTriggerRegistry) 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 *MetaTriggerRegistry) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MetaTriggerRegistry) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EpochStartMeta != nil { + { + size, err := m.EpochStartMeta.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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ShardTriggerRegistry) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.IsEpochStart { + n += 2 + } + if m.NewEpochHeaderReceived { + n += 2 + } + if m.Epoch != 0 { + n += 1 + sovTrigger(uint64(m.Epoch)) + } + if m.MetaEpoch != 0 { + n += 1 + sovTrigger(uint64(m.MetaEpoch)) + } + if m.CurrentRoundIndex != 0 { + n += 1 + sovTrigger(uint64(m.CurrentRoundIndex)) + } + if m.EpochStartRound != 0 { + n += 1 + sovTrigger(uint64(m.EpochStartRound)) + } + if m.EpochFinalityAttestingRound != 0 { + n += 1 + sovTrigger(uint64(m.EpochFinalityAttestingRound)) + } + l = len(m.EpochMetaBlockHash) + if l > 0 { + n += 1 + l + sovTrigger(uint64(l)) + } + if m.EpochStartShardHeader != nil { + l = m.EpochStartShardHeader.Size() + n += 1 + l + sovTrigger(uint64(l)) + } + return n +} + +func (m *ShardTriggerRegistryV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EpochStartShardHeader != nil { + l = m.EpochStartShardHeader.Size() + n += 1 + l + sovTrigger(uint64(l)) + } + if m.IsEpochStart { + n += 2 + } + if m.NewEpochHeaderReceived { + n += 2 + } + if m.Epoch != 0 { + n += 1 + sovTrigger(uint64(m.Epoch)) + } + if m.MetaEpoch != 0 { + n += 1 + sovTrigger(uint64(m.MetaEpoch)) + } + if m.CurrentRoundIndex != 0 { + n += 1 + sovTrigger(uint64(m.CurrentRoundIndex)) + } + if m.EpochStartRound != 0 { + n += 1 + sovTrigger(uint64(m.EpochStartRound)) + } + if m.EpochFinalityAttestingRound != 0 { + n += 1 + sovTrigger(uint64(m.EpochFinalityAttestingRound)) + } + l = len(m.EpochMetaBlockHash) + if l > 0 { + n += 1 + l + sovTrigger(uint64(l)) + } + return n +} + +func (m *MetaTriggerRegistry) 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.EpochStartMeta != nil { + l = m.EpochStartMeta.Size() + n += 1 + l + sovTrigger(uint64(l)) + } + return n +} + +func sovTrigger(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTrigger(x uint64) (n int) { + return sovTrigger(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ShardTriggerRegistry) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ShardTriggerRegistry{`, + `IsEpochStart:` + fmt.Sprintf("%v", this.IsEpochStart) + `,`, + `NewEpochHeaderReceived:` + fmt.Sprintf("%v", this.NewEpochHeaderReceived) + `,`, + `Epoch:` + fmt.Sprintf("%v", this.Epoch) + `,`, + `MetaEpoch:` + fmt.Sprintf("%v", this.MetaEpoch) + `,`, + `CurrentRoundIndex:` + fmt.Sprintf("%v", this.CurrentRoundIndex) + `,`, + `EpochStartRound:` + fmt.Sprintf("%v", this.EpochStartRound) + `,`, + `EpochFinalityAttestingRound:` + fmt.Sprintf("%v", this.EpochFinalityAttestingRound) + `,`, + `EpochMetaBlockHash:` + fmt.Sprintf("%v", this.EpochMetaBlockHash) + `,`, + `EpochStartShardHeader:` + strings.Replace(fmt.Sprintf("%v", this.EpochStartShardHeader), "Header", "Header", 1) + `,`, + `}`, + }, "") + return s +} +func (this *ShardTriggerRegistryV2) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ShardTriggerRegistryV2{`, + `EpochStartShardHeader:` + strings.Replace(fmt.Sprintf("%v", this.EpochStartShardHeader), "HeaderV2", "HeaderV2", 1) + `,`, + `IsEpochStart:` + fmt.Sprintf("%v", this.IsEpochStart) + `,`, + `NewEpochHeaderReceived:` + fmt.Sprintf("%v", this.NewEpochHeaderReceived) + `,`, + `Epoch:` + fmt.Sprintf("%v", this.Epoch) + `,`, + `MetaEpoch:` + fmt.Sprintf("%v", this.MetaEpoch) + `,`, + `CurrentRoundIndex:` + fmt.Sprintf("%v", this.CurrentRoundIndex) + `,`, + `EpochStartRound:` + fmt.Sprintf("%v", this.EpochStartRound) + `,`, + `EpochFinalityAttestingRound:` + fmt.Sprintf("%v", this.EpochFinalityAttestingRound) + `,`, + `EpochMetaBlockHash:` + fmt.Sprintf("%v", this.EpochMetaBlockHash) + `,`, + `}`, + }, "") + return s +} +func (this *MetaTriggerRegistry) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&MetaTriggerRegistry{`, + `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) + `,`, + `EpochStartMeta:` + strings.Replace(fmt.Sprintf("%v", this.EpochStartMeta), "MetaBlock", "MetaBlock", 1) + `,`, + `}`, + }, "") + return s +} +func valueToStringTrigger(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *ShardTriggerRegistry) 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: ShardTriggerRegistry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ShardTriggerRegistry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsEpochStart", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsEpochStart = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NewEpochHeaderReceived", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.NewEpochHeaderReceived = bool(v != 0) + case 3: + 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 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MetaEpoch", wireType) + } + m.MetaEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MetaEpoch |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentRoundIndex", wireType) + } + m.CurrentRoundIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentRoundIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStartRound", wireType) + } + m.EpochStartRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EpochStartRound |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + 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 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochMetaBlockHash", 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.EpochMetaBlockHash = append(m.EpochMetaBlockHash[:0], dAtA[iNdEx:postIndex]...) + if m.EpochMetaBlockHash == nil { + m.EpochMetaBlockHash = []byte{} + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStartShardHeader", 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.EpochStartShardHeader == nil { + m.EpochStartShardHeader = &Header{} + } + if err := m.EpochStartShardHeader.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 (m *ShardTriggerRegistryV2) 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: ShardTriggerRegistryV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ShardTriggerRegistryV2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStartShardHeader", 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.EpochStartShardHeader == nil { + m.EpochStartShardHeader = &HeaderV2{} + } + if err := m.EpochStartShardHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsEpochStart", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsEpochStart = bool(v != 0) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NewEpochHeaderReceived", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.NewEpochHeaderReceived = bool(v != 0) + case 4: + 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 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MetaEpoch", wireType) + } + m.MetaEpoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MetaEpoch |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentRoundIndex", wireType) + } + m.CurrentRoundIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentRoundIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochStartRound", wireType) + } + m.EpochStartRound = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTrigger + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EpochStartRound |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + 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 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochMetaBlockHash", 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.EpochMetaBlockHash = append(m.EpochMetaBlockHash[:0], dAtA[iNdEx:postIndex]...) + if m.EpochMetaBlockHash == nil { + m.EpochMetaBlockHash = []byte{} + } + 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 (m *MetaTriggerRegistry) 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: MetaTriggerRegistry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MetaTriggerRegistry: 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 EpochStartMeta", 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.EpochStartMeta == nil { + m.EpochStartMeta = &MetaBlock{} + } + if err := m.EpochStartMeta.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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTrigger + } + 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, ErrIntOverflowTrigger + } + 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, ErrIntOverflowTrigger + } + 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, ErrInvalidLengthTrigger + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTrigger + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTrigger + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTrigger = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTrigger = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTrigger = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/block/trigger.proto b/data/block/trigger.proto new file mode 100644 index 000000000..ae590942c --- /dev/null +++ b/data/block/trigger.proto @@ -0,0 +1,45 @@ +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"; +import "metaBlock.proto"; + +message ShardTriggerRegistry { + bool IsEpochStart = 1; + bool NewEpochHeaderReceived = 2; + uint32 Epoch = 3; + uint32 MetaEpoch = 4; + int64 CurrentRoundIndex = 5; + uint64 EpochStartRound = 6; + uint64 EpochFinalityAttestingRound = 7; + bytes EpochMetaBlockHash = 8; + Header EpochStartShardHeader = 9; +} + +message ShardTriggerRegistryV2 { + HeaderV2 EpochStartShardHeader = 1; + bool IsEpochStart = 2; + bool NewEpochHeaderReceived = 3; + uint32 Epoch = 4; + uint32 MetaEpoch = 5; + int64 CurrentRoundIndex = 6; + uint64 EpochStartRound = 7; + uint64 EpochFinalityAttestingRound = 8; + bytes EpochMetaBlockHash = 9; +} + +message MetaTriggerRegistry { + uint32 Epoch = 1; + uint64 CurrentRound = 2; + uint64 EpochFinalityAttestingRound = 3; + uint64 CurrEpochStartRound = 4; + uint64 PrevEpochStartRound = 5; + bytes EpochStartMetaHash = 6; + MetaBlock EpochStartMeta = 7; +} diff --git a/data/block/trigger_test.go b/data/block/trigger_test.go new file mode 100644 index 000000000..3bc88a2b5 --- /dev/null +++ b/data/block/trigger_test.go @@ -0,0 +1,484 @@ +package block + +import ( + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/stretchr/testify/require" +) + +func shouldNotPanic(t *testing.T) { + if r := recover(); r != nil { + require.Fail(t, "should not have panicked") + } +} + +func createDefaultShardTriggerRegistry() *ShardTriggerRegistry { + return &ShardTriggerRegistry{ + IsEpochStart: true, + NewEpochHeaderReceived: true, + Epoch: 10, + MetaEpoch: 11, + CurrentRoundIndex: 10000, + EpochStartRound: 10000, + EpochFinalityAttestingRound: 10002, + EpochMetaBlockHash: []byte("metaBlockHash"), + EpochStartShardHeader: &Header{}, + } +} + +func createDefaultShardTriggerRegistryV2() *ShardTriggerRegistryV2 { + return &ShardTriggerRegistryV2{ + EpochStartShardHeader: &HeaderV2{}, + IsEpochStart: true, + NewEpochHeaderReceived: true, + Epoch: 10, + MetaEpoch: 11, + CurrentRoundIndex: 10000, + EpochStartRound: 10000, + EpochFinalityAttestingRound: 10002, + EpochMetaBlockHash: []byte("metaBlockHash"), + } +} + +func TestShardTriggerRegistry_GetEpochStartHeaderHandlerNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + epochStartHeaderHandler := str.GetEpochStartHeaderHandler() + require.Nil(t, epochStartHeaderHandler) +} + +func TestShardTriggerRegistry_GetEpochStartHeaderHandlerOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + header := &Header{Epoch: 15} + str.EpochStartShardHeader = header + epochStartHeaderHandler := str.GetEpochStartHeaderHandler() + require.Equal(t, header, epochStartHeaderHandler) +} + +func TestShardTriggerRegistry_SetIsEpochStartNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetIsEpochStart(true) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetIsEpochStartOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.IsEpochStart = false + err := str.SetIsEpochStart(true) + require.Nil(t, err) + require.Equal(t, true, str.IsEpochStart) +} + +func TestShardTriggerRegistry_SetNewEpochHeaderReceivedNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetNewEpochHeaderReceived(true) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetNewEpochHeaderReceivedOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.NewEpochHeaderReceived = false + err := str.SetNewEpochHeaderReceived(true) + require.Nil(t, err) + require.Equal(t, true, str.NewEpochHeaderReceived) +} + +func TestShardTriggerRegistry_SetEpochNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetEpoch(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetEpochOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.Epoch = 0 + err := str.SetEpoch(20) + require.Nil(t, err) + require.Equal(t, uint32(20), str.Epoch) +} + +func TestShardTriggerRegistry_SetMetaEpochNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetMetaEpoch(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetMetaEpochOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.MetaEpoch = 0 + err := str.SetMetaEpoch(20) + require.Nil(t, err) + require.Equal(t, uint32(20), str.MetaEpoch) +} + +func TestShardTriggerRegistry_SetCurrentRoundIndexNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetCurrentRoundIndex(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetCurrentRoundIndexOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.CurrentRoundIndex = 0 + err := str.SetCurrentRoundIndex(20) + require.Nil(t, err) + require.Equal(t, int64(20), str.CurrentRoundIndex) +} + +func TestShardTriggerRegistry_SetEpochStartRoundNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetEpochStartRound(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetEpochStartRoundOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.EpochStartRound = 0 + err := str.SetEpochStartRound(20) + require.Nil(t, err) + require.Equal(t, uint64(20), str.EpochStartRound) +} + +func TestShardTriggerRegistry_SetEpochFinalityAttestingRoundNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetEpochFinalityAttestingRound(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetEpochFinalityAttestingRoundOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.EpochFinalityAttestingRound = 0 + err := str.SetEpochFinalityAttestingRound(20) + require.Nil(t, err) + require.Equal(t, uint64(20), str.EpochFinalityAttestingRound) +} + +func TestShardTriggerRegistry_SetEpochMetaBlockHashNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetEpochMetaBlockHash([]byte("meta block hash")) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetEpochMetaBlockHashOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.EpochMetaBlockHash = []byte("hash") + metaBlockHash := []byte("meta block hash") + err := str.SetEpochMetaBlockHash(metaBlockHash) + require.Nil(t, err) + require.Equal(t, metaBlockHash, str.EpochMetaBlockHash) +} + +func TestShardTriggerRegistry_SetEpochStartHeaderHandlerNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistry + err := str.SetEpochStartHeaderHandler(&Header{}) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistry_SetEpochStartHeaderHandlerNilHeaderToSet(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.EpochStartShardHeader = &Header{ + Epoch: 10, + } + setHeader := data.HeaderHandler(nil) + err := str.SetEpochStartHeaderHandler(setHeader) + require.Equal(t, data.ErrInvalidTypeAssertion, err) +} + +func TestShardTriggerRegistry_SetEpochStartHeaderHandlerOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistry() + str.EpochStartShardHeader = &Header{ + Epoch: 10, + } + setHeader := &Header{ + Epoch: 20, + } + err := str.SetEpochStartHeaderHandler(setHeader) + require.Nil(t, err) + require.Equal(t, setHeader, str.EpochStartShardHeader) +} + +func TestShardTriggerRegistryV2_GetEpochStartHeaderHandlerNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + epochStartHeaderHandler := str.GetEpochStartHeaderHandler() + require.Nil(t, epochStartHeaderHandler) +} + +func TestShardTriggerRegistryV2_GetEpochStartHeaderHandlerOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.EpochStartShardHeader = &HeaderV2{ + Header: &Header{}, + ScheduledRootHash: []byte("scheduledRootHash"), + } + epochStartHeaderHandler := str.GetEpochStartHeaderHandler() + require.Equal(t, str.EpochStartShardHeader, epochStartHeaderHandler) +} + +func TestShardTriggerRegistryV2_SetIsEpochStartNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetIsEpochStart(false) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetIsEpochStartOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.IsEpochStart = false + err := str.SetIsEpochStart(true) + require.Nil(t, err) + require.Equal(t, true, str.IsEpochStart) +} + +func TestShardTriggerRegistryV2_SetNewEpochHeaderReceivedNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetNewEpochHeaderReceived(false) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetNewEpochHeaderReceivedOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.NewEpochHeaderReceived = false + err := str.SetNewEpochHeaderReceived(true) + require.Nil(t, err) + require.Equal(t, true, str.NewEpochHeaderReceived) +} + +func TestShardTriggerRegistryV2_SetEpochNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetEpoch(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetEpochOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.Epoch = 0 + err := str.SetEpoch(20) + require.Nil(t, err) + require.Equal(t, uint32(20), str.Epoch) +} + +func TestShardTriggerRegistryV2_SetMetaEpochNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetMetaEpoch(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetMetaEpochOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.Epoch = 0 + err := str.SetMetaEpoch(20) + require.Nil(t, err) + require.Equal(t, uint32(20), str.MetaEpoch) +} + +func TestShardTriggerRegistryV2_SetCurrentRoundIndexNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetCurrentRoundIndex(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetCurrentRoundIndexOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.CurrentRoundIndex = 0 + err := str.SetCurrentRoundIndex(20) + require.Nil(t, err) + require.Equal(t, int64(20), str.CurrentRoundIndex) +} + +func TestShardTriggerRegistryV2_SetEpochStartRoundNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetEpochStartRound(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} +func TestShardTriggerRegistryV2_SetEpochStartRoundOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.EpochStartRound = 0 + err := str.SetEpochStartRound(20) + require.Nil(t, err) + require.Equal(t, uint64(20), str.EpochStartRound) +} + +func TestShardTriggerRegistryV2_SetEpochFinalityAttestingRoundNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetEpochFinalityAttestingRound(20) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetEpochFinalityAttestingRoundOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.EpochFinalityAttestingRound = 0 + err := str.SetEpochFinalityAttestingRound(20) + require.Nil(t, err) + require.Equal(t, uint64(20), str.EpochFinalityAttestingRound) +} + +func TestShardTriggerRegistryV2_SetEpochMetaBlockHashNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetEpochMetaBlockHash([]byte("epoch meta block hash")) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetEpochMetaBlockHashOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.EpochMetaBlockHash = []byte("meta hash") + setMetaBlockHash := []byte("set meta hash") + err := str.SetEpochMetaBlockHash(setMetaBlockHash) + require.Nil(t, err) + require.Equal(t, setMetaBlockHash, str.EpochMetaBlockHash) +} + +func TestShardTriggerRegistryV2_SetEpochStartHeaderHandlerNilShardTriggerRegistry(t *testing.T) { + t.Parallel() + + defer shouldNotPanic(t) + + var str *ShardTriggerRegistryV2 + err := str.SetEpochStartHeaderHandler(&HeaderV2{}) + require.Equal(t, data.ErrNilPointerReceiver, err) +} + +func TestShardTriggerRegistryV2_SetEpochStartHeaderHandlerNilHeaderToSet(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.EpochStartShardHeader = &HeaderV2{ + Header: &Header{}, + ScheduledRootHash: []byte("scheduled root hash"), + } + setHeader := data.HeaderHandler(nil) + err := str.SetEpochStartHeaderHandler(setHeader) + require.Equal(t, data.ErrInvalidTypeAssertion, err) +} + +func TestShardTriggerRegistryV2_SetEpochStartHeaderHandlerOK(t *testing.T) { + t.Parallel() + + str := createDefaultShardTriggerRegistryV2() + str.EpochStartShardHeader = &HeaderV2{ + Header: &Header{Epoch: 1}, + ScheduledRootHash: []byte("scheduled root hash"), + } + + setHeader := &HeaderV2{ + Header: &Header{Epoch: 10}, + ScheduledRootHash: []byte("set scheduled root hash"), + } + + err := str.SetEpochStartHeaderHandler(setHeader) + require.Nil(t, err) + require.Equal(t, setHeader, str.EpochStartShardHeader) +} diff --git a/data/errors.go b/data/errors.go index 191a9cb0e..048aeac46 100644 --- a/data/errors.go +++ b/data/errors.go @@ -60,3 +60,21 @@ var ErrNilRcvAddr = errors.New("nil receiver address") // ErrNilSndAddr signals that an operation has been attempted to or with a nil sender address var ErrNilSndAddr = errors.New("nil sender address") + +// ErrNilPointerReceiver signals that a nil pointer receiver was used +var ErrNilPointerReceiver = errors.New("nil pointer receiver") + +// ErrNilPointerDereference signals that a nil pointer dereference was detected and avoided +var ErrNilPointerDereference = errors.New("nil pointer dereference") + +// ErrInvalidTypeAssertion signals an invalid type assertion +var ErrInvalidTypeAssertion = errors.New("invalid type assertion") + +// ErrNilScheduledRootHash signals that a nil scheduled root hash was used +var ErrNilScheduledRootHash = errors.New("scheduled root hash is nil") + +// ErrScheduledRootHashNotSupported signals that a scheduled root hash is not supported +var ErrScheduledRootHashNotSupported = errors.New("scheduled root hash is not supported") + +// ErrWrongTransactionsTypeSize signals that size of transactions type buffer from mini block reserved field is wrong +var ErrWrongTransactionsTypeSize = errors.New("wrong transactions type size") diff --git a/data/headerVersionData/shardHeader.go b/data/headerVersionData/shardHeader.go new file mode 100644 index 000000000..f3bcf1a2b --- /dev/null +++ b/data/headerVersionData/shardHeader.go @@ -0,0 +1,90 @@ +package headerVersionData + +import "math/big" + +// HeaderAdditionalData holds getters for the additional version related header data for new versions +// for future versions this interface can grow +type HeaderAdditionalData interface { + GetScheduledRootHash() []byte + GetScheduledAccumulatedFees() *big.Int + GetScheduledDeveloperFees() *big.Int + GetScheduledGasProvided() uint64 + GetScheduledGasPenalized() uint64 + GetScheduledGasRefunded() uint64 + IsInterfaceNil() bool +} + +// AdditionalData holds the additional version related header data +// for future header versions this structure can grow +type AdditionalData struct { + ScheduledRootHash []byte + ScheduledAccumulatedFees *big.Int + ScheduledDeveloperFees *big.Int + ScheduledGasProvided uint64 + ScheduledGasPenalized uint64 + ScheduledGasRefunded uint64 +} + +// GetScheduledRootHash returns the scheduled RootHash +func (ad *AdditionalData) GetScheduledRootHash() []byte { + if ad == nil { + return nil + } + + return ad.ScheduledRootHash +} + +// GetScheduledAccumulatedFees returns the accumulated fees on scheduled SC calls +func (ad *AdditionalData) GetScheduledAccumulatedFees() *big.Int { + if ad == nil { + return nil + } + if ad.ScheduledAccumulatedFees == nil { + return big.NewInt(0) + } + return big.NewInt(0).Set(ad.ScheduledAccumulatedFees) +} + +// GetScheduledDeveloperFees returns the developer fees on scheduled SC calls +func (ad *AdditionalData) GetScheduledDeveloperFees() *big.Int { + if ad == nil { + return nil + } + if ad.ScheduledDeveloperFees == nil { + return big.NewInt(0) + } + + return big.NewInt(0).Set(ad.ScheduledDeveloperFees) +} + +// GetScheduledGasProvided returns the gas provided on scheduled SC calls for previous block +func (ad *AdditionalData) GetScheduledGasProvided() uint64 { + if ad == nil { + return 0 + } + + return ad.ScheduledGasProvided +} + +// GetScheduledGasPenalized returns the gas penalized on scheduled SC calls for previous block +func (ad *AdditionalData) GetScheduledGasPenalized() uint64 { + if ad == nil { + return 0 + } + + return ad.ScheduledGasPenalized +} + +// GetScheduledGasRefunded returns the gas refunded on scheduled SC calls for previous block +func (ad *AdditionalData) GetScheduledGasRefunded() uint64 { + if ad == nil { + return 0 + } + + return ad.ScheduledGasRefunded +} + +// IsInterfaceNil returns true if there is no value under the interface +func (ad *AdditionalData) IsInterfaceNil() bool { + return ad == nil +} diff --git a/data/interface.go b/data/interface.go index 84306d9be..d7eb22c9e 100644 --- a/data/interface.go +++ b/data/interface.go @@ -2,8 +2,33 @@ package data import ( "math/big" + + "github.com/ElrondNetwork/elrond-go-core/data/headerVersionData" ) +// TriggerRegistryHandler defines getters and setters for the trigger registry +type TriggerRegistryHandler interface { + GetIsEpochStart() bool + GetNewEpochHeaderReceived() bool + GetEpoch() uint32 + GetMetaEpoch() uint32 + GetCurrentRoundIndex() int64 + GetEpochStartRound() uint64 + GetEpochFinalityAttestingRound() uint64 + GetEpochMetaBlockHash() []byte + GetEpochStartHeaderHandler() HeaderHandler + + SetIsEpochStart(isEpochStart bool) error + SetNewEpochHeaderReceived(newEpochHeaderReceived bool) error + SetEpoch(epoch uint32) error + SetMetaEpoch(metaEpoch uint32) error + SetCurrentRoundIndex(roundIndex int64) error + SetEpochStartRound(startRound uint64) error + SetEpochFinalityAttestingRound(finalityAttestingRound uint64) error + SetEpochMetaBlockHash(epochMetaBlockHash []byte) error + SetEpochStartHeaderHandler(epochStartHeaderHandler HeaderHandler) error +} + // HeaderHandler defines getters and setters for header data holder type HeaderHandler interface { GetShardID() uint32 @@ -11,7 +36,6 @@ type HeaderHandler interface { GetEpoch() uint32 GetRound() uint64 GetRootHash() []byte - GetValidatorStatsRootHash() []byte GetPrevHash() []byte GetPrevRandSeed() []byte GetRandSeed() []byte @@ -25,35 +49,178 @@ type HeaderHandler interface { GetReceiptsHash() []byte GetAccumulatedFees() *big.Int GetDeveloperFees() *big.Int - GetEpochStartMetaHash() []byte GetReserved() []byte - - SetAccumulatedFees(value *big.Int) - SetDeveloperFees(value *big.Int) - SetShardID(shId uint32) - SetNonce(n uint64) - SetEpoch(e uint32) - SetRound(r uint64) - SetTimeStamp(ts uint64) - SetRootHash(rHash []byte) - SetValidatorStatsRootHash(rHash []byte) - SetPrevHash(pvHash []byte) - SetPrevRandSeed(pvRandSeed []byte) - SetRandSeed(randSeed []byte) - SetPubKeysBitmap(pkbm []byte) - SetSignature(sg []byte) - SetLeaderSignature(sg []byte) - SetChainID(chainID []byte) - SetSoftwareVersion(version []byte) - SetTxCount(txCount uint32) - - IsStartOfEpochBlock() bool GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 GetOrderedCrossMiniblocksWithDst(destId uint32) []*MiniBlockInfo GetMiniBlockHeadersHashes() [][]byte + GetMiniBlockHeaderHandlers() []MiniBlockHeaderHandler + HasScheduledSupport() bool + GetAdditionalData() headerVersionData.HeaderAdditionalData + 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 + SetTimeStamp(ts uint64) error + SetRootHash(rHash []byte) error + SetPrevHash(pvHash []byte) error + SetPrevRandSeed(pvRandSeed []byte) error + SetRandSeed(randSeed []byte) error + SetPubKeysBitmap(pkbm []byte) error + SetSignature(sg []byte) error + SetLeaderSignature(sg []byte) error + SetChainID(chainID []byte) error + SetSoftwareVersion(version []byte) error + SetTxCount(txCount uint32) error + SetMiniBlockHeaderHandlers(mbHeaderHandlers []MiniBlockHeaderHandler) error + SetReceiptsHash(hash []byte) error + SetScheduledRootHash(rootHash []byte) error + ValidateHeaderVersion() error + SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error + IsStartOfEpochBlock() bool + ShallowClone() HeaderHandler IsInterfaceNil() bool - Clone() HeaderHandler +} + +// ShardHeaderHandler defines getters and setters for the shard block header +type ShardHeaderHandler interface { + HeaderHandler + GetMetaBlockHashes() [][]byte + GetEpochStartMetaHash() []byte + SetEpochStartMetaHash(hash []byte) error + GetBlockBodyTypeInt32() int32 + SetMetaBlockHashes(hashes [][]byte) error + MapMiniBlockHashesToShards() map[string]uint32 +} + +// 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 +} + +// MiniBlockHeaderHandler defines setters and getters for miniBlock headers +type MiniBlockHeaderHandler interface { + GetHash() []byte + GetSenderShardID() uint32 + GetReceiverShardID() uint32 + GetTxCount() uint32 + GetTypeInt32() int32 + GetReserved() []byte + + SetHash(hash []byte) error + SetSenderShardID(shardID uint32) error + SetReceiverShardID(shardID uint32) error + SetTxCount(count uint32) error + SetTypeInt32(t int32) error + SetReserved(reserved []byte) error + ShallowClone() MiniBlockHeaderHandler +} + +// PeerChangeHandler defines setters and getters for PeerChange +type PeerChangeHandler interface { + GetPubKey() []byte + GetShardIdDest() uint32 + + SetPubKey(pubKey []byte) error + SetShardIdDest(shardID uint32) error +} + +// ShardDataHandler defines setters and getters for ShardDataHandler +type ShardDataHandler interface { + GetHeaderHash() []byte + GetShardMiniBlockHeaderHandlers() []MiniBlockHeaderHandler + GetPrevRandSeed() []byte + GetPubKeysBitmap() []byte + GetSignature() []byte + GetRound() uint64 + GetPrevHash() []byte + GetNonce() uint64 + GetAccumulatedFees() *big.Int + GetDeveloperFees() *big.Int + GetNumPendingMiniBlocks() uint32 + GetLastIncludedMetaNonce() uint64 + GetShardID() uint32 + GetTxCount() uint32 + + SetHeaderHash(hash []byte) error + SetShardMiniBlockHeaderHandlers(mbHeaderHandlers []MiniBlockHeaderHandler) error + SetPrevRandSeed(prevRandSeed []byte) error + SetPubKeysBitmap(pubKeysBitmap []byte) error + SetSignature(signature []byte) error + SetRound(round uint64) error + SetPrevHash(prevHash []byte) error + SetNonce(nonce uint64) error + SetAccumulatedFees(fees *big.Int) error + SetDeveloperFees(fees *big.Int) error + SetNumPendingMiniBlocks(num uint32) error + SetLastIncludedMetaNonce(nonce uint64) error + SetShardID(shardID uint32) error + SetTxCount(txCount uint32) error + + ShallowClone() ShardDataHandler +} + +// EpochStartShardDataHandler defines setters and getters for EpochStartShardData +type EpochStartShardDataHandler 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 + SetRootHash([]byte) error + SetFirstPendingMetaBlock([]byte) error + SetLastFinishedMetaBlock([]byte) error + SetPendingMiniBlockHeaders([]MiniBlockHeaderHandler) error +} + +// EconomicHandler defines setters and getters for Economics +type EconomicsHandler interface { + GetTotalSupply() *big.Int + GetTotalToDistribute() *big.Int + GetTotalNewlyMinted() *big.Int + GetRewardsPerBlock() *big.Int + GetRewardsForProtocolSustainability() *big.Int + GetNodePrice() *big.Int + GetPrevEpochStartRound() uint64 + GetPrevEpochStartHash() []byte + + SetTotalSupply(totalSupply *big.Int) error + SetTotalToDistribute(totalToDistribute *big.Int) error + SetTotalNewlyMinted(totalNewlyMinted *big.Int) error + SetRewardsPerBlock(rewardsPerBlock *big.Int) error + SetRewardsForProtocolSustainability(rewardsForProtocolSustainability *big.Int) error + SetNodePrice(nodePrice *big.Int) error + SetPrevEpochStartRound(prevEpochStartRound uint64) error + SetPrevEpochStartHash(prevEpochStartHash []byte) error +} + +// EpochStartHandler defines setters and getters for EpochStart +type EpochStartHandler interface { + GetLastFinalizedHeaderHandlers() []EpochStartShardDataHandler + GetEconomicsHandler() EconomicsHandler + + SetLastFinalizedHeaders(epochStartShardDataHandlers []EpochStartShardDataHandler) error + SetEconomics(economicsHandler EconomicsHandler) error } // BodyHandler interface for a block body @@ -76,7 +243,6 @@ type ChainHandler interface { GetCurrentBlockHeaderHash() []byte SetCurrentBlockHeaderHash(hash []byte) IsInterfaceNil() bool - CreateNewHeader() HeaderHandler } // TransactionHandler defines the type of executable transaction diff --git a/data/metrics/metrics.go b/data/metrics/metrics.go index 7857a8658..50bd26191 100644 --- a/data/metrics/metrics.go +++ b/data/metrics/metrics.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. metrics.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. metrics.proto package metrics // ListFromMap returns a list of values from the provided map diff --git a/data/metrics/proto/metrics.proto b/data/metrics/metrics.proto similarity index 100% rename from data/metrics/proto/metrics.proto rename to data/metrics/metrics.proto diff --git a/data/receipt/receipt.go b/data/receipt/receipt.go index ed2729cf1..d96bef783 100644 --- a/data/receipt/receipt.go +++ b/data/receipt/receipt.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. receipt.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. receipt.proto package receipt import ( diff --git a/data/receipt/proto/receipt.proto b/data/receipt/receipt.proto similarity index 100% rename from data/receipt/proto/receipt.proto rename to data/receipt/receipt.proto diff --git a/data/rewardTx/rewardTx.go b/data/rewardTx/rewardTx.go index 0f2cdee4e..024fc4fcf 100644 --- a/data/rewardTx/rewardTx.go +++ b/data/rewardTx/rewardTx.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. rewardTx.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. rewardTx.proto package rewardTx import ( @@ -20,32 +20,32 @@ func (rtx *RewardTx) SetValue(value *big.Int) { } // GetNonce returns 0 as reward transactions do not have a nonce -func (_ *RewardTx) GetNonce() uint64 { +func (rtx *RewardTx) GetNonce() uint64 { return 0 } // GetData returns the data of the reward transaction -func (_ *RewardTx) GetData() []byte { +func (rtx *RewardTx) GetData() []byte { return []byte("") } // GetSndAddr returns the sender address from the reward transaction -func (_ *RewardTx) GetSndAddr() []byte { +func (rtx *RewardTx) GetSndAddr() []byte { return nil } // GetGasLimit returns the gas limit of the smart reward transaction -func (_ *RewardTx) GetGasLimit() uint64 { +func (rtx *RewardTx) GetGasLimit() uint64 { return 0 } // GetGasPrice returns the gas price of the smart reward transaction -func (_ *RewardTx) GetGasPrice() uint64 { +func (rtx *RewardTx) GetGasPrice() uint64 { return 0 } // SetData sets the data of the reward transaction -func (_ *RewardTx) SetData(data []byte) { +func (rtx *RewardTx) SetData(_ []byte) { } // SetRcvAddr sets the receiver address of the reward transaction @@ -54,11 +54,11 @@ func (rtx *RewardTx) SetRcvAddr(addr []byte) { } // SetSndAddr sets the sender address of the reward transaction -func (_ *RewardTx) SetSndAddr(addr []byte) { +func (rtx *RewardTx) SetSndAddr(_ []byte) { } // GetRcvUserName returns the receiver user name from the reward transaction -func (_ *RewardTx) GetRcvUserName() []byte { +func (rtx *RewardTx) GetRcvUserName() []byte { return nil } diff --git a/data/rewardTx/proto/rewardTx.proto b/data/rewardTx/rewardTx.proto similarity index 100% rename from data/rewardTx/proto/rewardTx.proto rename to data/rewardTx/rewardTx.proto diff --git a/data/scheduled/scheduled.go b/data/scheduled/scheduled.go new file mode 100644 index 000000000..c7f1303bb --- /dev/null +++ b/data/scheduled/scheduled.go @@ -0,0 +1,65 @@ +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. scheduled.proto +package scheduled + +import ( + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/smartContractResult" +) + +// GetTransactionHandlersMap returns the smart contract results as a map of transaction handlers +func (sscr *ScheduledSCRs) GetTransactionHandlersMap() map[block.Type][]data.TransactionHandler { + if sscr == nil { + return nil + } + if len(sscr.Scrs) == 0 { + return nil + } + + result := make(map[block.Type][]data.TransactionHandler) + for i, scrs := range sscr.Scrs { + if len(scrs.TxHandlers) == 0 { + result[block.Type(i)] = nil + continue + } + transactionHandlers := make([]data.TransactionHandler, len(scrs.TxHandlers)) + for j := range scrs.TxHandlers { + transactionHandlers[j] = scrs.TxHandlers[j] + } + result[block.Type(i)] = transactionHandlers + } + + return result +} + +// SetTransactionHandlersMap fills the smart contract results map from the given transaction handlers map +func (sscr *ScheduledSCRs) SetTransactionHandlersMap(txHandlersMap map[block.Type][]data.TransactionHandler) error { + if sscr == nil { + return data.ErrNilPointerReceiver + } + if txHandlersMap == nil { + sscr.Scrs = nil + return nil + } + + sscr.Scrs = make(map[int32]SmartContractResults) + for i, txHandlers := range txHandlersMap { + if len(txHandlers) == 0 { + sscr.Scrs[int32(i)] = SmartContractResults{} + continue + } + scrs := make([]*smartContractResult.SmartContractResult, len(txHandlers)) + for j := range txHandlers { + scr, ok := txHandlers[j].(*smartContractResult.SmartContractResult) + if !ok { + return data.ErrInvalidTypeAssertion + } + scrs[j] = scr + } + sscr.Scrs[int32(i)] = SmartContractResults{ + TxHandlers: scrs, + } + } + + return nil +} diff --git a/data/scheduled/scheduled.pb.go b/data/scheduled/scheduled.pb.go new file mode 100644 index 000000000..32d9604e3 --- /dev/null +++ b/data/scheduled/scheduled.pb.go @@ -0,0 +1,1316 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: scheduled.proto + +package scheduled + +import ( + bytes "bytes" + fmt "fmt" + github_com_ElrondNetwork_elrond_go_core_data "github.com/ElrondNetwork/elrond-go-core/data" + smartContractResult "github.com/ElrondNetwork/elrond-go-core/data/smartContractResult" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" + 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 SmartContractResults struct { + TxHandlers []*smartContractResult.SmartContractResult `protobuf:"bytes,1,rep,name=TxHandlers,proto3" json:"TxHandlers,omitempty"` +} + +func (m *SmartContractResults) Reset() { *m = SmartContractResults{} } +func (*SmartContractResults) ProtoMessage() {} +func (*SmartContractResults) Descriptor() ([]byte, []int) { + return fileDescriptor_f80076f37bd30c16, []int{0} +} +func (m *SmartContractResults) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SmartContractResults) 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 *SmartContractResults) XXX_Merge(src proto.Message) { + xxx_messageInfo_SmartContractResults.Merge(m, src) +} +func (m *SmartContractResults) XXX_Size() int { + return m.Size() +} +func (m *SmartContractResults) XXX_DiscardUnknown() { + xxx_messageInfo_SmartContractResults.DiscardUnknown(m) +} + +var xxx_messageInfo_SmartContractResults proto.InternalMessageInfo + +func (m *SmartContractResults) GetTxHandlers() []*smartContractResult.SmartContractResult { + if m != nil { + return m.TxHandlers + } + return nil +} + +type GasAndFees struct { + AccumulatedFees *math_big.Int `protobuf:"bytes,1,opt,name=AccumulatedFees,proto3,casttypewith=math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster" json:"AccumulatedFees,omitempty"` + DeveloperFees *math_big.Int `protobuf:"bytes,2,opt,name=DeveloperFees,proto3,casttypewith=math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster" json:"DeveloperFees,omitempty"` + GasProvided uint64 `protobuf:"varint,3,opt,name=GasProvided,proto3" json:"GasProvided,omitempty"` + GasPenalized uint64 `protobuf:"varint,4,opt,name=GasPenalized,proto3" json:"GasPenalized,omitempty"` + GasRefunded uint64 `protobuf:"varint,5,opt,name=GasRefunded,proto3" json:"GasRefunded,omitempty"` +} + +func (m *GasAndFees) Reset() { *m = GasAndFees{} } +func (*GasAndFees) ProtoMessage() {} +func (*GasAndFees) Descriptor() ([]byte, []int) { + return fileDescriptor_f80076f37bd30c16, []int{1} +} +func (m *GasAndFees) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GasAndFees) 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 *GasAndFees) XXX_Merge(src proto.Message) { + xxx_messageInfo_GasAndFees.Merge(m, src) +} +func (m *GasAndFees) XXX_Size() int { + return m.Size() +} +func (m *GasAndFees) XXX_DiscardUnknown() { + xxx_messageInfo_GasAndFees.DiscardUnknown(m) +} + +var xxx_messageInfo_GasAndFees proto.InternalMessageInfo + +func (m *GasAndFees) GetAccumulatedFees() *math_big.Int { + if m != nil { + return m.AccumulatedFees + } + return nil +} + +func (m *GasAndFees) GetDeveloperFees() *math_big.Int { + if m != nil { + return m.DeveloperFees + } + return nil +} + +func (m *GasAndFees) GetGasProvided() uint64 { + if m != nil { + return m.GasProvided + } + return 0 +} + +func (m *GasAndFees) GetGasPenalized() uint64 { + if m != nil { + return m.GasPenalized + } + return 0 +} + +func (m *GasAndFees) GetGasRefunded() uint64 { + if m != nil { + return m.GasRefunded + } + return 0 +} + +type ScheduledSCRs struct { + RootHash []byte `protobuf:"bytes,1,opt,name=rootHash,proto3" json:"rootHash,omitempty"` + Scrs map[int32]SmartContractResults `protobuf:"bytes,2,rep,name=scrs,proto3" json:"scrs" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + GasAndFees *GasAndFees `protobuf:"bytes,3,opt,name=gasAndFees,proto3" json:"gasAndFees,omitempty"` +} + +func (m *ScheduledSCRs) Reset() { *m = ScheduledSCRs{} } +func (*ScheduledSCRs) ProtoMessage() {} +func (*ScheduledSCRs) Descriptor() ([]byte, []int) { + return fileDescriptor_f80076f37bd30c16, []int{2} +} +func (m *ScheduledSCRs) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ScheduledSCRs) 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 *ScheduledSCRs) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScheduledSCRs.Merge(m, src) +} +func (m *ScheduledSCRs) XXX_Size() int { + return m.Size() +} +func (m *ScheduledSCRs) XXX_DiscardUnknown() { + xxx_messageInfo_ScheduledSCRs.DiscardUnknown(m) +} + +var xxx_messageInfo_ScheduledSCRs proto.InternalMessageInfo + +func (m *ScheduledSCRs) GetRootHash() []byte { + if m != nil { + return m.RootHash + } + return nil +} + +func (m *ScheduledSCRs) GetScrs() map[int32]SmartContractResults { + if m != nil { + return m.Scrs + } + return nil +} + +func (m *ScheduledSCRs) GetGasAndFees() *GasAndFees { + if m != nil { + return m.GasAndFees + } + return nil +} + +func init() { + proto.RegisterType((*SmartContractResults)(nil), "proto.SmartContractResults") + proto.RegisterType((*GasAndFees)(nil), "proto.GasAndFees") + proto.RegisterType((*ScheduledSCRs)(nil), "proto.ScheduledSCRs") + proto.RegisterMapType((map[int32]SmartContractResults)(nil), "proto.ScheduledSCRs.ScrsEntry") +} + +func init() { proto.RegisterFile("scheduled.proto", fileDescriptor_f80076f37bd30c16) } + +var fileDescriptor_f80076f37bd30c16 = []byte{ + // 498 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x3d, 0x6f, 0xd3, 0x40, + 0x18, 0xf6, 0xe5, 0x03, 0xd1, 0x4b, 0xab, 0xc2, 0x89, 0x21, 0x32, 0xd2, 0x35, 0xca, 0x94, 0x25, + 0xb6, 0x1a, 0x96, 0xaa, 0x4c, 0x4d, 0xe8, 0x17, 0x03, 0x42, 0x97, 0x4e, 0xdd, 0x2e, 0xf6, 0x5b, + 0xc7, 0xaa, 0xe3, 0x8b, 0xee, 0xce, 0x81, 0x32, 0xf1, 0x13, 0xf8, 0x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a, 0xe5, 0xcc, 0xfd, 0xca, 0x1e, 0xea, 0x0f, 0xe6, + 0x4b, 0x6a, 0x2d, 0x96, 0xd4, 0xba, 0x59, 0x52, 0xf4, 0x3e, 0xa5, 0xe8, 0x63, 0x4a, 0xd1, 0x75, + 0x4a, 0xd1, 0x3c, 0xa5, 0x68, 0x91, 0x52, 0xf4, 0x2d, 0xa5, 0xe8, 0x7b, 0x4a, 0xad, 0x9b, 0x94, + 0xa2, 0x0f, 0x2b, 0x6a, 0xcd, 0x57, 0xd4, 0x5a, 0xac, 0xa8, 0x75, 0xbe, 0x51, 0x7c, 0x80, 0xa3, + 0x07, 0x26, 0xeb, 0xd9, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xc2, 0x3d, 0x31, 0x94, 0x03, + 0x00, 0x00, +} + +func (this *SmartContractResults) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*SmartContractResults) + if !ok { + that2, ok := that.(SmartContractResults) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.TxHandlers) != len(that1.TxHandlers) { + return false + } + for i := range this.TxHandlers { + if !this.TxHandlers[i].Equal(that1.TxHandlers[i]) { + return false + } + } + return true +} +func (this *GasAndFees) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*GasAndFees) + if !ok { + that2, ok := that.(GasAndFees) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if !__caster.Equal(this.AccumulatedFees, that1.AccumulatedFees) { + return false + } + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if !__caster.Equal(this.DeveloperFees, that1.DeveloperFees) { + return false + } + } + if this.GasProvided != that1.GasProvided { + return false + } + if this.GasPenalized != that1.GasPenalized { + return false + } + if this.GasRefunded != that1.GasRefunded { + return false + } + return true +} +func (this *ScheduledSCRs) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ScheduledSCRs) + if !ok { + that2, ok := that.(ScheduledSCRs) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.RootHash, that1.RootHash) { + return false + } + if len(this.Scrs) != len(that1.Scrs) { + return false + } + for i := range this.Scrs { + a := this.Scrs[i] + b := that1.Scrs[i] + if !(&a).Equal(&b) { + return false + } + } + if !this.GasAndFees.Equal(that1.GasAndFees) { + return false + } + return true +} +func (this *SmartContractResults) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&scheduled.SmartContractResults{") + if this.TxHandlers != nil { + s = append(s, "TxHandlers: "+fmt.Sprintf("%#v", this.TxHandlers)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *GasAndFees) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 9) + s = append(s, "&scheduled.GasAndFees{") + s = append(s, "AccumulatedFees: "+fmt.Sprintf("%#v", this.AccumulatedFees)+",\n") + s = append(s, "DeveloperFees: "+fmt.Sprintf("%#v", this.DeveloperFees)+",\n") + s = append(s, "GasProvided: "+fmt.Sprintf("%#v", this.GasProvided)+",\n") + s = append(s, "GasPenalized: "+fmt.Sprintf("%#v", this.GasPenalized)+",\n") + s = append(s, "GasRefunded: "+fmt.Sprintf("%#v", this.GasRefunded)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *ScheduledSCRs) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 7) + s = append(s, "&scheduled.ScheduledSCRs{") + s = append(s, "RootHash: "+fmt.Sprintf("%#v", this.RootHash)+",\n") + keysForScrs := make([]int32, 0, len(this.Scrs)) + for k, _ := range this.Scrs { + keysForScrs = append(keysForScrs, k) + } + github_com_gogo_protobuf_sortkeys.Int32s(keysForScrs) + mapStringForScrs := "map[int32]SmartContractResults{" + for _, k := range keysForScrs { + mapStringForScrs += fmt.Sprintf("%#v: %#v,", k, this.Scrs[k]) + } + mapStringForScrs += "}" + if this.Scrs != nil { + s = append(s, "Scrs: "+mapStringForScrs+",\n") + } + if this.GasAndFees != nil { + s = append(s, "GasAndFees: "+fmt.Sprintf("%#v", this.GasAndFees)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringScheduled(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 *SmartContractResults) 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 *SmartContractResults) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SmartContractResults) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TxHandlers) > 0 { + for iNdEx := len(m.TxHandlers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TxHandlers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintScheduled(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *GasAndFees) 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 *GasAndFees) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GasAndFees) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.GasRefunded != 0 { + i = encodeVarintScheduled(dAtA, i, uint64(m.GasRefunded)) + i-- + dAtA[i] = 0x28 + } + if m.GasPenalized != 0 { + i = encodeVarintScheduled(dAtA, i, uint64(m.GasPenalized)) + i-- + dAtA[i] = 0x20 + } + if m.GasProvided != 0 { + i = encodeVarintScheduled(dAtA, i, uint64(m.GasProvided)) + i-- + dAtA[i] = 0x18 + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + size := __caster.Size(m.DeveloperFees) + i -= size + if _, err := __caster.MarshalTo(m.DeveloperFees, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintScheduled(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + size := __caster.Size(m.AccumulatedFees) + i -= size + if _, err := __caster.MarshalTo(m.AccumulatedFees, dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintScheduled(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ScheduledSCRs) 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 *ScheduledSCRs) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ScheduledSCRs) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.GasAndFees != nil { + { + size, err := m.GasAndFees.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintScheduled(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.Scrs) > 0 { + keysForScrs := make([]int32, 0, len(m.Scrs)) + for k := range m.Scrs { + keysForScrs = append(keysForScrs, int32(k)) + } + github_com_gogo_protobuf_sortkeys.Int32s(keysForScrs) + for iNdEx := len(keysForScrs) - 1; iNdEx >= 0; iNdEx-- { + v := m.Scrs[int32(keysForScrs[iNdEx])] + baseI := i + { + size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintScheduled(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + i = encodeVarintScheduled(dAtA, i, uint64(keysForScrs[iNdEx])) + i-- + dAtA[i] = 0x8 + i = encodeVarintScheduled(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + if len(m.RootHash) > 0 { + i -= len(m.RootHash) + copy(dAtA[i:], m.RootHash) + i = encodeVarintScheduled(dAtA, i, uint64(len(m.RootHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintScheduled(dAtA []byte, offset int, v uint64) int { + offset -= sovScheduled(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *SmartContractResults) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.TxHandlers) > 0 { + for _, e := range m.TxHandlers { + l = e.Size() + n += 1 + l + sovScheduled(uint64(l)) + } + } + return n +} + +func (m *GasAndFees) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + l = __caster.Size(m.AccumulatedFees) + n += 1 + l + sovScheduled(uint64(l)) + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + l = __caster.Size(m.DeveloperFees) + n += 1 + l + sovScheduled(uint64(l)) + } + if m.GasProvided != 0 { + n += 1 + sovScheduled(uint64(m.GasProvided)) + } + if m.GasPenalized != 0 { + n += 1 + sovScheduled(uint64(m.GasPenalized)) + } + if m.GasRefunded != 0 { + n += 1 + sovScheduled(uint64(m.GasRefunded)) + } + return n +} + +func (m *ScheduledSCRs) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.RootHash) + if l > 0 { + n += 1 + l + sovScheduled(uint64(l)) + } + if len(m.Scrs) > 0 { + for k, v := range m.Scrs { + _ = k + _ = v + l = v.Size() + mapEntrySize := 1 + sovScheduled(uint64(k)) + 1 + l + sovScheduled(uint64(l)) + n += mapEntrySize + 1 + sovScheduled(uint64(mapEntrySize)) + } + } + if m.GasAndFees != nil { + l = m.GasAndFees.Size() + n += 1 + l + sovScheduled(uint64(l)) + } + return n +} + +func sovScheduled(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozScheduled(x uint64) (n int) { + return sovScheduled(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *SmartContractResults) String() string { + if this == nil { + return "nil" + } + repeatedStringForTxHandlers := "[]*SmartContractResult{" + for _, f := range this.TxHandlers { + repeatedStringForTxHandlers += strings.Replace(fmt.Sprintf("%v", f), "SmartContractResult", "smartContractResult.SmartContractResult", 1) + "," + } + repeatedStringForTxHandlers += "}" + s := strings.Join([]string{`&SmartContractResults{`, + `TxHandlers:` + repeatedStringForTxHandlers + `,`, + `}`, + }, "") + return s +} +func (this *GasAndFees) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&GasAndFees{`, + `AccumulatedFees:` + fmt.Sprintf("%v", this.AccumulatedFees) + `,`, + `DeveloperFees:` + fmt.Sprintf("%v", this.DeveloperFees) + `,`, + `GasProvided:` + fmt.Sprintf("%v", this.GasProvided) + `,`, + `GasPenalized:` + fmt.Sprintf("%v", this.GasPenalized) + `,`, + `GasRefunded:` + fmt.Sprintf("%v", this.GasRefunded) + `,`, + `}`, + }, "") + return s +} +func (this *ScheduledSCRs) String() string { + if this == nil { + return "nil" + } + keysForScrs := make([]int32, 0, len(this.Scrs)) + for k, _ := range this.Scrs { + keysForScrs = append(keysForScrs, k) + } + github_com_gogo_protobuf_sortkeys.Int32s(keysForScrs) + mapStringForScrs := "map[int32]SmartContractResults{" + for _, k := range keysForScrs { + mapStringForScrs += fmt.Sprintf("%v: %v,", k, this.Scrs[k]) + } + mapStringForScrs += "}" + s := strings.Join([]string{`&ScheduledSCRs{`, + `RootHash:` + fmt.Sprintf("%v", this.RootHash) + `,`, + `Scrs:` + mapStringForScrs + `,`, + `GasAndFees:` + strings.Replace(this.GasAndFees.String(), "GasAndFees", "GasAndFees", 1) + `,`, + `}`, + }, "") + return s +} +func valueToStringScheduled(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *SmartContractResults) 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 ErrIntOverflowScheduled + } + 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: SmartContractResults: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SmartContractResults: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxHandlers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthScheduled + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthScheduled + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxHandlers = append(m.TxHandlers, &smartContractResult.SmartContractResult{}) + if err := m.TxHandlers[len(m.TxHandlers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipScheduled(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GasAndFees) 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 ErrIntOverflowScheduled + } + 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: GasAndFees: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GasAndFees: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AccumulatedFees", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthScheduled + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthScheduled + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.AccumulatedFees = tmp + } + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeveloperFees", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthScheduled + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthScheduled + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + { + __caster := &github_com_ElrondNetwork_elrond_go_core_data.BigIntCaster{} + if tmp, err := __caster.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } else { + m.DeveloperFees = tmp + } + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasProvided", wireType) + } + m.GasProvided = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasProvided |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasPenalized", wireType) + } + m.GasPenalized = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasPenalized |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasRefunded", wireType) + } + m.GasRefunded = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasRefunded |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipScheduled(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ScheduledSCRs) 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 ErrIntOverflowScheduled + } + 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: ScheduledSCRs: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ScheduledSCRs: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RootHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthScheduled + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthScheduled + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RootHash = append(m.RootHash[:0], dAtA[iNdEx:postIndex]...) + if m.RootHash == nil { + m.RootHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Scrs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthScheduled + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthScheduled + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Scrs == nil { + m.Scrs = make(map[int32]SmartContractResults) + } + var mapkey int32 + mapvalue := &SmartContractResults{} + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapkey |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthScheduled + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthScheduled + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &SmartContractResults{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipScheduled(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Scrs[mapkey] = *mapvalue + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GasAndFees", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowScheduled + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthScheduled + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthScheduled + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.GasAndFees == nil { + m.GasAndFees = &GasAndFees{} + } + if err := m.GasAndFees.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipScheduled(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthScheduled + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipScheduled(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, ErrIntOverflowScheduled + } + 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, ErrIntOverflowScheduled + } + 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, ErrIntOverflowScheduled + } + 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, ErrInvalidLengthScheduled + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupScheduled + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthScheduled + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthScheduled = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowScheduled = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupScheduled = fmt.Errorf("proto: unexpected end of group") +) diff --git a/data/scheduled/scheduled.proto b/data/scheduled/scheduled.proto new file mode 100644 index 000000000..853deb297 --- /dev/null +++ b/data/scheduled/scheduled.proto @@ -0,0 +1,28 @@ + +syntax = "proto3"; + +package proto; + +option go_package = "scheduled"; +option (gogoproto.stable_marshaler_all) = true; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; +import "github.com/ElrondNetwork/elrond-go-core/data/smartContractResult/smartContractResult.proto"; + +message SmartContractResults { + repeated SmartContractResult TxHandlers = 1; +} + +message GasAndFees { + bytes AccumulatedFees = 1 [(gogoproto.casttypewith) = "math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster"]; + bytes DeveloperFees = 2 [(gogoproto.casttypewith) = "math/big.Int;github.com/ElrondNetwork/elrond-go-core/data.BigIntCaster"]; + uint64 GasProvided = 3; + uint64 GasPenalized = 4; + uint64 GasRefunded = 5; +} + +message ScheduledSCRs { + bytes rootHash = 1; + map scrs = 2 [(gogoproto.nullable) = false]; + GasAndFees gasAndFees = 3; +} diff --git a/data/scheduled/scheduled_test.go b/data/scheduled/scheduled_test.go new file mode 100644 index 000000000..d98842709 --- /dev/null +++ b/data/scheduled/scheduled_test.go @@ -0,0 +1,131 @@ +package scheduled_test + +import ( + "testing" + + "github.com/ElrondNetwork/elrond-go-core/data" + "github.com/ElrondNetwork/elrond-go-core/data/block" + "github.com/ElrondNetwork/elrond-go-core/data/scheduled" + "github.com/ElrondNetwork/elrond-go-core/data/smartContractResult" + "github.com/stretchr/testify/require" +) + +func TestScheduledSCRs_GetTransactionHandlersMapNilSCRsList(t *testing.T) { + scheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + Scrs: createInitializedSCRsMap(20), + } + scheduledSCRs.Scrs[int32(block.TxBlock)] = scheduled.SmartContractResults{ + TxHandlers: nil, + } + + expectedTxHandlersMap := createInitializedTransactionHandlerMap(20) + expectedTxHandlersMap[block.TxBlock] = nil + txHandlersMap := scheduledSCRs.GetTransactionHandlersMap() + require.NotNil(t, txHandlersMap) + require.Equal(t, expectedTxHandlersMap, txHandlersMap) +} + +func TestScheduledSCRs_GetTransactionHandlersMapNilSCRsMap(t *testing.T) { + scheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + Scrs: nil, + } + + txHandlersMap := scheduledSCRs.GetTransactionHandlersMap() + require.Nil(t, txHandlersMap) +} + +func TestScheduledSCRs_GetTransactionHandlersMapOK(t *testing.T) { + scheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + Scrs: createInitializedSCRsMap(20), + } + + expectedTxHandlersMap := createInitializedTransactionHandlerMap(20) + txHandlersMap := scheduledSCRs.GetTransactionHandlersMap() + require.NotNil(t, txHandlersMap) + require.Equal(t, expectedTxHandlersMap, txHandlersMap) +} + +func TestScheduledSCRs_SetTransactionHandlersMapNilSCRsMap(t *testing.T) { + scheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + } + expectedScheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + } + err := scheduledSCRs.SetTransactionHandlersMap(nil) + require.Nil(t, err) + require.Equal(t, scheduledSCRs, expectedScheduledSCRs) +} + +func TestScheduledSCRs_SetTransactionHandlersMapNilSCRsList(t *testing.T) { + scheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + } + expectedScheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + } + expectedScheduledSCRs.Scrs = createInitializedSCRsMap(20) + expectedScheduledSCRs.Scrs[int32(block.TxBlock)] = scheduled.SmartContractResults{TxHandlers: nil} + + txHandlersMap := createInitializedTransactionHandlerMap(20) + txHandlersMap[block.TxBlock] = nil + + err := scheduledSCRs.SetTransactionHandlersMap(txHandlersMap) + require.Nil(t, err) + require.Equal(t, scheduledSCRs, expectedScheduledSCRs) +} + +func TestScheduledSCRs_SetTransactionHandlersMapOK(t *testing.T) { + scheduledSCRs := &scheduled.ScheduledSCRs{ + RootHash: []byte("root hash"), + Scrs: createInitializedSCRsMap(20), + } + + expectedTxHandlersMap := createInitializedTransactionHandlerMap(20) + actualTxHandlersMap := scheduledSCRs.GetTransactionHandlersMap() + require.NotNil(t, actualTxHandlersMap) + require.Equal(t, actualTxHandlersMap, expectedTxHandlersMap) +} + +func createInitializedTransactionHandlerMap(nbTxsPerIndex int) map[block.Type][]data.TransactionHandler { + result := make(map[block.Type][]data.TransactionHandler) + result[block.TxBlock] = createInitializedTransactionHandlerArray(nbTxsPerIndex) + result[block.RewardsBlock] = createInitializedTransactionHandlerArray(nbTxsPerIndex) + + return result +} + +func createInitializedSCRsMap(nbSCRsPerIndex int) map[int32]scheduled.SmartContractResults { + result := make(map[int32]scheduled.SmartContractResults) + result[int32(block.TxBlock)] = scheduled.SmartContractResults{ + TxHandlers: createInitializedSCRPointerArray(nbSCRsPerIndex), + } + result[int32(block.RewardsBlock)] = scheduled.SmartContractResults{ + TxHandlers: createInitializedSCRPointerArray(nbSCRsPerIndex), + } + + return result +} + +func createInitializedTransactionHandlerArray(nbTxs int) []data.TransactionHandler { + result := make([]data.TransactionHandler, nbTxs) + for i := 0; i < nbTxs; i++ { + result[i] = &smartContractResult.SmartContractResult{ + Nonce: uint64(i), + } + } + return result +} + +func createInitializedSCRPointerArray(nbSCRs int) []*smartContractResult.SmartContractResult { + result := make([]*smartContractResult.SmartContractResult, nbSCRs) + for i := 0; i < nbSCRs; i++ { + result[i] = &smartContractResult.SmartContractResult{ + Nonce: uint64(i), + } + } + return result +} diff --git a/data/smartContractResult/smartContractResult.go b/data/smartContractResult/smartContractResult.go index 87a6253c0..22ca32668 100644 --- a/data/smartContractResult/smartContractResult.go +++ b/data/smartContractResult/smartContractResult.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. smartContractResult.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. smartContractResult.proto package smartContractResult import ( diff --git a/data/smartContractResult/proto/smartContractResult.proto b/data/smartContractResult/smartContractResult.proto similarity index 100% rename from data/smartContractResult/proto/smartContractResult.proto rename to data/smartContractResult/smartContractResult.proto diff --git a/data/transaction/log.go b/data/transaction/log.go index e58274eb6..2bd9b6d17 100644 --- a/data/transaction/log.go +++ b/data/transaction/log.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. log.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. log.proto package transaction import ( diff --git a/data/transaction/proto/log.proto b/data/transaction/log.proto similarity index 100% rename from data/transaction/proto/log.proto rename to data/transaction/log.proto diff --git a/data/transaction/transaction.go b/data/transaction/transaction.go index eb0801640..951b10cf8 100644 --- a/data/transaction/transaction.go +++ b/data/transaction/transaction.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. transaction.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. transaction.proto package transaction import ( diff --git a/data/transaction/proto/transaction.proto b/data/transaction/transaction.proto similarity index 100% rename from data/transaction/proto/transaction.proto rename to data/transaction/transaction.proto diff --git a/marshal/testSizeCheckUnmarshal/proto/testStruct.proto b/marshal/testSizeCheckUnmarshal/testStruct.proto similarity index 100% rename from marshal/testSizeCheckUnmarshal/proto/testStruct.proto rename to marshal/testSizeCheckUnmarshal/testStruct.proto diff --git a/marshal/testSizeCheckUnmarshal/testStructs_test.go b/marshal/testSizeCheckUnmarshal/testStructs_test.go index efb404cf7..fbe2a92c2 100644 --- a/marshal/testSizeCheckUnmarshal/testStructs_test.go +++ b/marshal/testSizeCheckUnmarshal/testStructs_test.go @@ -1,4 +1,4 @@ -//go:generate protoc -I=proto -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. testStruct.proto +//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/ElrondNetwork/protobuf/protobuf --gogoslick_out=. testStruct.proto package testSizeCheckUnmarshal