From 33aa79b05f7bf42c639c8dbad1d1d33579be3adf Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 25 Jan 2023 17:34:57 +0200 Subject: [PATCH 1/8] export prepare args save block data --- websocketOutportDriver/payloadParser.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/websocketOutportDriver/payloadParser.go b/websocketOutportDriver/payloadParser.go index ca752fdd..43f68224 100644 --- a/websocketOutportDriver/payloadParser.go +++ b/websocketOutportDriver/payloadParser.go @@ -106,7 +106,8 @@ func padUint32ByteSlice(initial []byte) []byte { return append(padding, initial...) } -func prepareArgsSaveBlock(args outport.ArgsSaveBlockData) outport.ArgsSaveBlockData { +// PrepareArgsSaveBlock will prepare save block data +func PrepareArgsSaveBlock(args outport.ArgsSaveBlockData) outport.ArgsSaveBlockData { var pool *outport.Pool if args.TransactionsPool != nil { pool = &outport.Pool{ From bded9ba51a64b11ed1a91941d511bf241d9acd02 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 25 Jan 2023 17:38:28 +0200 Subject: [PATCH 2/8] export prepare args save block data - rename --- websocketOutportDriver/websocketOutportDriverNodePart.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websocketOutportDriver/websocketOutportDriverNodePart.go b/websocketOutportDriver/websocketOutportDriverNodePart.go index 3244c71b..dd374fd6 100644 --- a/websocketOutportDriver/websocketOutportDriverNodePart.go +++ b/websocketOutportDriver/websocketOutportDriverNodePart.go @@ -61,7 +61,7 @@ func NewWebsocketOutportDriverNodePart(args WebsocketOutportDriverNodePartArgs) func (o *websocketOutportDriverNodePart) SaveBlock(args *outport.ArgsSaveBlockData) error { argsSaveBlock := outportSenderData.ArgsSaveBlock{ HeaderType: core.GetHeaderType(args.Header), - ArgsSaveBlockData: prepareArgsSaveBlock(*args), + ArgsSaveBlockData: PrepareArgsSaveBlock(*args), } return o.handleAction(argsSaveBlock, outportSenderData.OperationSaveBlock) From efd8d1a003e6b73a68ab129460f03694ee4d9ba1 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Mon, 30 Jan 2023 13:20:45 +0200 Subject: [PATCH 3/8] extend transaction structure --- data/transaction/apiTransactionResult.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/transaction/apiTransactionResult.go b/data/transaction/apiTransactionResult.go index 1fa95e50..52b28e25 100644 --- a/data/transaction/apiTransactionResult.go +++ b/data/transaction/apiTransactionResult.go @@ -25,6 +25,7 @@ type ApiTransactionResult struct { ReceiverUsername []byte `json:"receiverUsername,omitempty"` GasPrice uint64 `json:"gasPrice,omitempty"` GasLimit uint64 `json:"gasLimit,omitempty"` + GasUsed uint64 `json:"gasUsed"` Data []byte `json:"data,omitempty"` CodeMetadata []byte `json:"codeMetadata,omitempty"` Code string `json:"code,omitempty"` @@ -57,6 +58,7 @@ type ApiTransactionResult struct { Operation string `json:"operation,omitempty"` Function string `json:"function,omitempty"` InitiallyPaidFee string `json:"initiallyPaidFee,omitempty"` + Fee string `json:"fee"` IsRelayed bool `json:"isRelayed,omitempty"` IsRefund bool `json:"isRefund,omitempty"` CallType string `json:"callType,omitempty"` From ebccba0c240f5fff8a9b158f5dc9dc6ce3ecf8a5 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Tue, 31 Jan 2023 10:32:43 +0200 Subject: [PATCH 4/8] omit empty --- data/transaction/apiTransactionResult.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/transaction/apiTransactionResult.go b/data/transaction/apiTransactionResult.go index 52b28e25..20bdfcfa 100644 --- a/data/transaction/apiTransactionResult.go +++ b/data/transaction/apiTransactionResult.go @@ -25,7 +25,7 @@ type ApiTransactionResult struct { ReceiverUsername []byte `json:"receiverUsername,omitempty"` GasPrice uint64 `json:"gasPrice,omitempty"` GasLimit uint64 `json:"gasLimit,omitempty"` - GasUsed uint64 `json:"gasUsed"` + GasUsed uint64 `json:"gasUsed,omitempty"` Data []byte `json:"data,omitempty"` CodeMetadata []byte `json:"codeMetadata,omitempty"` Code string `json:"code,omitempty"` @@ -58,7 +58,7 @@ type ApiTransactionResult struct { Operation string `json:"operation,omitempty"` Function string `json:"function,omitempty"` InitiallyPaidFee string `json:"initiallyPaidFee,omitempty"` - Fee string `json:"fee"` + Fee string `json:"fee,omitempty"` IsRelayed bool `json:"isRelayed,omitempty"` IsRefund bool `json:"isRefund,omitempty"` CallType string `json:"callType,omitempty"` From fa4f94e6b5f7c04e75de755517a83df51bb8d55c Mon Sep 17 00:00:00 2001 From: jules01 Date: Tue, 31 Jan 2023 18:34:52 +0200 Subject: [PATCH 5/8] - added extra checks (moved from mx-chain-go in mx-chain-core-go) --- data/block/block.go | 37 +++++++ data/block/blockChecks_test.go | 149 +++++++++++++++++++++++++++++ data/block/blockV2.go | 23 +++++ data/block/blockV2Checks_test.go | 87 +++++++++++++++++ data/block/metaBlock.go | 43 +++++++++ data/block/metaBlockChecks_test.go | 59 ++++++++++++ 6 files changed, 398 insertions(+) create mode 100644 data/block/blockChecks_test.go create mode 100644 data/block/blockV2Checks_test.go create mode 100644 data/block/metaBlockChecks_test.go diff --git a/data/block/block.go b/data/block/block.go index 5147be5d..eeabaf68 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -2,6 +2,7 @@ package block import ( + "fmt" "math/big" "github.com/multiversx/mx-chain-core-go/data" @@ -581,3 +582,39 @@ func (h *Header) GetAdditionalData() headerVersionData.HeaderAdditionalData { // no extra data for the initial version of shard block header return nil } + +// CheckFieldsForNil checks a predefined set of fields for nil values +func (h *Header) CheckFieldsForNil() error { + if h == nil { + return data.ErrNilPointerReceiver + } + if h.PrevHash == nil { + return fmt.Errorf("%w in Header.PrevHash", data.ErrNilValue) + } + if h.PrevRandSeed == nil { + return fmt.Errorf("%w in Header.PrevRandSeed", data.ErrNilValue) + } + if h.RandSeed == nil { + return fmt.Errorf("%w in Header.RandSeed", data.ErrNilValue) + } + if h.PubKeysBitmap == nil { + return fmt.Errorf("%w in Header.PubKeysBitmap", data.ErrNilValue) + } + if h.RootHash == nil { + return fmt.Errorf("%w in Header.RootHash", data.ErrNilValue) + } + if h.ChainID == nil { + return fmt.Errorf("%w in Header.ChainID", data.ErrNilValue) + } + if h.SoftwareVersion == nil { + return fmt.Errorf("%w in Header.SoftwareVersion", data.ErrNilValue) + } + if h.AccumulatedFees == nil { + return fmt.Errorf("%w in Header.AccumulatedFees", data.ErrNilValue) + } + if h.DeveloperFees == nil { + return fmt.Errorf("%w in Header.DeveloperFees", data.ErrNilValue) + } + + return nil +} diff --git a/data/block/blockChecks_test.go b/data/block/blockChecks_test.go new file mode 100644 index 00000000..c4060c24 --- /dev/null +++ b/data/block/blockChecks_test.go @@ -0,0 +1,149 @@ +package block + +import ( + "fmt" + "math/big" + "reflect" + "testing" + + "github.com/multiversx/mx-chain-core-go/data" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var headerV1ExceptionFields = []string{ + "Signature", + "LeaderSignature", + "MetaBlockHashes", + "EpochStartMetaHash", + "ReceiptsHash", + "Reserved", +} + +type field struct { + name string + typeValue string + objFieldIndex int +} + +type fieldsChecker interface { + CheckFieldsForNil() error +} + +func prepareFieldsList(object interface{}, fieldNameExceptions ...string) []field { + list := make([]field, 0) + val := reflect.ValueOf(object).Elem() + for i := 0; i < val.NumField(); i++ { + fieldName := val.Type().Field(i).Name + fieldType := fmt.Sprintf("%v", val.Field(i).Type()) + switch fieldType { + case "uint64", "uint32", "int", "string": + continue + case "block.Type", "[]block.MiniBlockHeader", "[]block.PeerChange": + continue + } + if search(fieldName, fieldNameExceptions...) { + continue + } + + list = append(list, field{ + name: fieldName, + typeValue: fieldType, + objFieldIndex: i, + }) + } + + return list +} + +func search(needle string, haystack ...string) bool { + for _, item := range haystack { + if item == needle { + return true + } + } + return false +} + +func populateFieldsWithRandomValue(tb testing.TB, object interface{}, fields []field) { + val := reflect.ValueOf(object) + for counter, f := range fields { + fieldValue := val.Elem().FieldByName(f.name) + + switch f.typeValue { + case "[]uint8": + fieldValue.SetBytes([]byte(fmt.Sprintf("test field %d", counter))) + case "[][]uint8": + fieldValue.Set(reflect.ValueOf([][]byte{ + []byte(fmt.Sprintf("test field1 %d", counter)), + []byte(fmt.Sprintf("test field2 %d", counter)), + })) + case "*big.Int": + fieldValue.Set(reflect.ValueOf(big.NewInt(int64(counter)))) + default: + assert.Fail(tb, "unimplemented field type "+f.typeValue+" for field "+f.name) + } + } +} + +func unsetField(tb testing.TB, object interface{}, f field) { + v := reflect.ValueOf(object) + + fieldValue := v.Elem().FieldByName(f.name) + switch f.typeValue { + case "[]uint8", "[][]uint8", "*big.Int": + fieldValue.Set(reflect.Zero(fieldValue.Type())) + default: + assert.Fail(tb, "unimplemented field type "+f.typeValue+" for field "+f.name) + } +} + +func testField(tb testing.TB, object interface{}, fields []field, fieldIndex int) { + f := fields[fieldIndex] + fmt.Printf(" testing field %s of type %s\n", f.name, f.typeValue) + populateFieldsWithRandomValue(tb, object, fields) + unsetField(tb, object, fields[fieldIndex]) + + checker := object.(fieldsChecker) + err := checker.CheckFieldsForNil() + require.NotNil(tb, err, "should have return a non nil error for nil field %s", f.name) + assert.ErrorIs(tb, err, data.ErrNilValue) +} + +func TestBlockHeader_Checks(t *testing.T) { + t.Parallel() + + t.Run("nil pointer receiver", func(t *testing.T) { + t.Parallel() + + var objectToTest *Header + err := objectToTest.CheckFieldsForNil() + require.NotNil(t, err) + assert.ErrorIs(t, err, data.ErrNilPointerReceiver) + }) + t.Run("test all fields when set", func(t *testing.T) { + t.Parallel() + + objectToTest := &Header{} + + fields := prepareFieldsList(objectToTest, headerV1ExceptionFields...) + assert.NotEmpty(t, fields) + }) + t.Run("test all fields when one is unset", func(t *testing.T) { + t.Parallel() + + objectToTest := &Header{} + + fields := prepareFieldsList(objectToTest, headerV1ExceptionFields...) + assert.NotEmpty(t, fields) + + populateFieldsWithRandomValue(t, objectToTest, fields) + err := objectToTest.CheckFieldsForNil() + require.Nil(t, err) + + fmt.Printf("fields tests on %T\n", objectToTest) + for i := 0; i < len(fields); i++ { + testField(t, objectToTest, fields, i) + } + }) +} diff --git a/data/block/blockV2.go b/data/block/blockV2.go index 1d020c06..6d9e071f 100644 --- a/data/block/blockV2.go +++ b/data/block/blockV2.go @@ -2,6 +2,7 @@ package block import ( + "fmt" "math/big" "github.com/multiversx/mx-chain-core-go/core/check" @@ -629,3 +630,25 @@ func (hv2 *HeaderV2) GetAdditionalData() headerVersionData.HeaderAdditionalData } return additionalVersionData } + +// CheckFieldsForNil checks a predefined set of fields for nil values +func (hv2 *HeaderV2) CheckFieldsForNil() error { + if hv2 == nil { + return data.ErrNilPointerReceiver + } + err := hv2.Header.CheckFieldsForNil() + if err != nil { + return err + } + if hv2.ScheduledRootHash == nil { + return fmt.Errorf("%w in HeaderV2.ScheduledRootHash", data.ErrNilValue) + } + if hv2.ScheduledAccumulatedFees == nil { + return fmt.Errorf("%w in HeaderV2.ScheduledAccumulatedFees", data.ErrNilValue) + } + if hv2.ScheduledDeveloperFees == nil { + return fmt.Errorf("%w in HeaderV2.ScheduledDeveloperFees", data.ErrNilValue) + } + + return nil +} diff --git a/data/block/blockV2Checks_test.go b/data/block/blockV2Checks_test.go new file mode 100644 index 00000000..95ecd53c --- /dev/null +++ b/data/block/blockV2Checks_test.go @@ -0,0 +1,87 @@ +package block + +import ( + "fmt" + "testing" + + "github.com/multiversx/mx-chain-core-go/data" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var headerV2ExceptionFields = []string{"Header"} + +func TestBlockHeaderV2_Checks(t *testing.T) { + t.Parallel() + + t.Run("nil pointer receiver", func(t *testing.T) { + t.Parallel() + + var objectToTest *HeaderV2 + err := objectToTest.CheckFieldsForNil() + require.NotNil(t, err) + assert.ErrorIs(t, err, data.ErrNilPointerReceiver) + }) + t.Run("inner header is a nil pointer receiver", func(t *testing.T) { + t.Parallel() + + objectToTest := &HeaderV2{} + err := objectToTest.CheckFieldsForNil() + require.NotNil(t, err) + assert.ErrorIs(t, err, data.ErrNilPointerReceiver) + }) + t.Run("test all fields when set", func(t *testing.T) { + t.Parallel() + + objectToTest := &HeaderV2{} + + fields := prepareFieldsList(objectToTest, headerV1ExceptionFields...) + assert.NotEmpty(t, fields) + }) + t.Run("test all fields when one is unset on inner Header", func(t *testing.T) { + t.Parallel() + + objectToTest := &HeaderV2{ + Header: &Header{}, + } + + fieldsForHeaderV2 := prepareFieldsList(objectToTest, headerV2ExceptionFields...) + assert.NotEmpty(t, fieldsForHeaderV2) + populateFieldsWithRandomValue(t, objectToTest, fieldsForHeaderV2) + + fieldsForHeaderV1 := prepareFieldsList(objectToTest.Header, headerV1ExceptionFields...) + assert.NotEmpty(t, fieldsForHeaderV1) + + populateFieldsWithRandomValue(t, objectToTest.Header, fieldsForHeaderV1) + err := objectToTest.CheckFieldsForNil() + require.Nil(t, err) + + fmt.Printf("fields tests on %T\n", objectToTest.Header) + for i := 0; i < len(fieldsForHeaderV1); i++ { + testField(t, objectToTest.Header, fieldsForHeaderV1, i) + } + }) + t.Run("test all fields when one is unset on HeaderV2", func(t *testing.T) { + t.Parallel() + + objectToTest := &HeaderV2{ + Header: &Header{}, + } + + fieldsForHeaderV1 := prepareFieldsList(objectToTest.Header, headerV1ExceptionFields...) + assert.NotEmpty(t, fieldsForHeaderV1) + populateFieldsWithRandomValue(t, objectToTest.Header, fieldsForHeaderV1) + + fields := prepareFieldsList(objectToTest, headerV2ExceptionFields...) + assert.NotEmpty(t, fields) + + populateFieldsWithRandomValue(t, objectToTest, fields) + err := objectToTest.CheckFieldsForNil() + require.Nil(t, err) + + fmt.Printf("fields tests on %T\n", objectToTest) + for i := 0; i < len(fields); i++ { + testField(t, objectToTest, fields, i) + } + }) +} diff --git a/data/block/metaBlock.go b/data/block/metaBlock.go index 3d78d575..ebaf8da8 100644 --- a/data/block/metaBlock.go +++ b/data/block/metaBlock.go @@ -2,6 +2,7 @@ package block import ( + "fmt" "math/big" "sort" @@ -523,3 +524,45 @@ func (m *MetaBlock) GetAdditionalData() headerVersionData.HeaderAdditionalData { // no extra data for the initial version of meta block header return nil } + +// CheckFieldsForNil checks a predefined set of fields for nil values +func (m *MetaBlock) CheckFieldsForNil() error { + if m == nil { + return data.ErrNilPointerReceiver + } + if m.PrevHash == nil { + return fmt.Errorf("%w in MetaBlock.PrevHash", data.ErrNilValue) + } + if m.PrevRandSeed == nil { + return fmt.Errorf("%w in MetaBlock.PrevRandSeed", data.ErrNilValue) + } + if m.RandSeed == nil { + return fmt.Errorf("%w in MetaBlock.RandSeed", data.ErrNilValue) + } + if m.RootHash == nil { + return fmt.Errorf("%w in MetaBlock.RootHash", data.ErrNilValue) + } + if m.ValidatorStatsRootHash == nil { + return fmt.Errorf("%w in MetaBlock.ValidatorStatsRootHash", data.ErrNilValue) + } + if m.ChainID == nil { + return fmt.Errorf("%w in MetaBlock.ChainID", data.ErrNilValue) + } + if m.SoftwareVersion == nil { + return fmt.Errorf("%w in MetaBlock.SoftwareVersion", data.ErrNilValue) + } + if m.AccumulatedFees == nil { + return fmt.Errorf("%w in MetaBlock.AccumulatedFees", data.ErrNilValue) + } + if m.AccumulatedFeesInEpoch == nil { + return fmt.Errorf("%w in MetaBlock.AccumulatedFeesInEpoch", data.ErrNilValue) + } + if m.DeveloperFees == nil { + return fmt.Errorf("%w in MetaBlock.DeveloperFees", data.ErrNilValue) + } + if m.DevFeesInEpoch == nil { + return fmt.Errorf("%w in MetaBlock.DevFeesInEpoch", data.ErrNilValue) + } + + return nil +} diff --git a/data/block/metaBlockChecks_test.go b/data/block/metaBlockChecks_test.go new file mode 100644 index 00000000..befb3377 --- /dev/null +++ b/data/block/metaBlockChecks_test.go @@ -0,0 +1,59 @@ +package block + +import ( + "fmt" + "testing" + + "github.com/multiversx/mx-chain-core-go/data" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var metablockExceptionFields = []string{ + "ShardInfo", + "PeerInfo", + "EpochStart", + "Signature", + "LeaderSignature", + "PubKeysBitmap", + "ReceiptsHash", + "Reserved", +} + +func TestMetaBlockHeader_Checks(t *testing.T) { + t.Parallel() + + t.Run("nil pointer receiver", func(t *testing.T) { + t.Parallel() + + var objectToTest *MetaBlock + err := objectToTest.CheckFieldsForNil() + require.NotNil(t, err) + assert.ErrorIs(t, err, data.ErrNilPointerReceiver) + }) + t.Run("test all fields when set", func(t *testing.T) { + t.Parallel() + + objectToTest := &MetaBlock{} + + fields := prepareFieldsList(objectToTest, headerV1ExceptionFields...) + assert.NotEmpty(t, fields) + }) + t.Run("test all fields when one is unset", func(t *testing.T) { + t.Parallel() + + objectToTest := &MetaBlock{} + + fields := prepareFieldsList(objectToTest, metablockExceptionFields...) + assert.NotEmpty(t, fields) + + populateFieldsWithRandomValue(t, objectToTest, fields) + err := objectToTest.CheckFieldsForNil() + require.Nil(t, err) + + fmt.Printf("fields tests on %T\n", objectToTest) + for i := 0; i < len(fields); i++ { + testField(t, objectToTest, fields, i) + } + }) +} From ccb72c674e406cec42a505f775067eca60d847ff Mon Sep 17 00:00:00 2001 From: jules01 Date: Tue, 31 Jan 2023 20:12:09 +0200 Subject: [PATCH 6/8] - extended the interface, removed deprecated stub --- core/mock/headerHandlerStub.go | 255 --------------------------------- data/interface.go | 1 + 2 files changed, 1 insertion(+), 255 deletions(-) delete mode 100644 core/mock/headerHandlerStub.go diff --git a/core/mock/headerHandlerStub.go b/core/mock/headerHandlerStub.go deleted file mode 100644 index fe319899..00000000 --- a/core/mock/headerHandlerStub.go +++ /dev/null @@ -1,255 +0,0 @@ -package mock - -import ( - "math/big" - - "github.com/multiversx/mx-chain-core-go/data" -) - -// HeaderHandlerStub - -type HeaderHandlerStub struct { - EpochField uint32 - TimestampField uint64 - GetMiniBlockHeadersWithDstCalled func(destId uint32) map[string]uint32 - GetOrderedCrossMiniblocksWithDstCalled func(destId uint32) []*data.MiniBlockInfo - GetPubKeysBitmapCalled func() []byte - GetSignatureCalled func() []byte - GetRootHashCalled func() []byte - GetRandSeedCalled func() []byte - GetPrevRandSeedCalled func() []byte - GetPrevHashCalled func() []byte - CloneCalled func() data.HeaderHandler - GetChainIDCalled func() []byte - CheckChainIDCalled func(reference []byte) error - GetReservedCalled func() []byte - IsStartOfEpochBlockCalled func() bool -} - -// GetAccumulatedFees - -func (hhs *HeaderHandlerStub) GetAccumulatedFees() *big.Int { - return big.NewInt(0) -} - -// GetDeveloperFees - -func (hhs *HeaderHandlerStub) GetDeveloperFees() *big.Int { - return big.NewInt(0) -} - -// SetAccumulatedFees - -func (hhs *HeaderHandlerStub) SetAccumulatedFees(_ *big.Int) { -} - -// SetDeveloperFees - -func (hhs *HeaderHandlerStub) SetDeveloperFees(_ *big.Int) { -} - -// GetReceiptsHash - -func (hhs *HeaderHandlerStub) GetReceiptsHash() []byte { - return []byte("receipt") -} - -// SetShardID - -func (hhs *HeaderHandlerStub) SetShardID(_ uint32) { -} - -// IsStartOfEpochBlock - -func (hhs *HeaderHandlerStub) IsStartOfEpochBlock() bool { - if hhs.IsStartOfEpochBlockCalled != nil { - return hhs.IsStartOfEpochBlockCalled() - } - - return false -} - -// Clone - -func (hhs *HeaderHandlerStub) Clone() data.HeaderHandler { - return hhs.CloneCalled() -} - -// GetShardID - -func (hhs *HeaderHandlerStub) GetShardID() uint32 { - return 1 -} - -// GetNonce - -func (hhs *HeaderHandlerStub) GetNonce() uint64 { - return 1 -} - -// GetEpoch - -func (hhs *HeaderHandlerStub) GetEpoch() uint32 { - return hhs.EpochField -} - -// GetRound - -func (hhs *HeaderHandlerStub) GetRound() uint64 { - return 1 -} - -// GetTimeStamp - -func (hhs *HeaderHandlerStub) GetTimeStamp() uint64 { - return hhs.TimestampField -} - -// GetRootHash - -func (hhs *HeaderHandlerStub) GetRootHash() []byte { - return hhs.GetRootHashCalled() -} - -// GetPrevHash - -func (hhs *HeaderHandlerStub) GetPrevHash() []byte { - return hhs.GetPrevHashCalled() -} - -// GetPrevRandSeed - -func (hhs *HeaderHandlerStub) GetPrevRandSeed() []byte { - return hhs.GetPrevRandSeedCalled() -} - -// GetRandSeed - -func (hhs *HeaderHandlerStub) GetRandSeed() []byte { - return hhs.GetRandSeedCalled() -} - -// GetPubKeysBitmap - -func (hhs *HeaderHandlerStub) GetPubKeysBitmap() []byte { - return hhs.GetPubKeysBitmapCalled() -} - -// GetSignature - -func (hhs *HeaderHandlerStub) GetSignature() []byte { - return hhs.GetSignatureCalled() -} - -// GetLeaderSignature - -func (hhs *HeaderHandlerStub) GetLeaderSignature() []byte { - return hhs.GetSignatureCalled() -} - -// GetChainID - -func (hhs *HeaderHandlerStub) GetChainID() []byte { - return hhs.GetChainIDCalled() -} - -// GetTxCount - -func (hhs *HeaderHandlerStub) GetTxCount() uint32 { - return 0 -} - -// GetReserved - -func (hhs *HeaderHandlerStub) GetReserved() []byte { - if hhs.GetReservedCalled != nil { - return hhs.GetReservedCalled() - } - - return nil -} - -// SetNonce - -func (hhs *HeaderHandlerStub) SetNonce(_ uint64) { - panic("implement me") -} - -// SetEpoch - -func (hhs *HeaderHandlerStub) SetEpoch(_ uint32) { - panic("implement me") -} - -// SetRound - -func (hhs *HeaderHandlerStub) SetRound(_ uint64) { - panic("implement me") -} - -// SetTimeStamp - -func (hhs *HeaderHandlerStub) SetTimeStamp(_ uint64) { - panic("implement me") -} - -// SetRootHash - -func (hhs *HeaderHandlerStub) SetRootHash(_ []byte) { - panic("implement me") -} - -// SetPrevHash - -func (hhs *HeaderHandlerStub) SetPrevHash(_ []byte) { - panic("implement me") -} - -// SetPrevRandSeed - -func (hhs *HeaderHandlerStub) SetPrevRandSeed(_ []byte) { - panic("implement me") -} - -// SetRandSeed - -func (hhs *HeaderHandlerStub) SetRandSeed(_ []byte) { - panic("implement me") -} - -// SetPubKeysBitmap - -func (hhs *HeaderHandlerStub) SetPubKeysBitmap(_ []byte) { - panic("implement me") -} - -// SetSignature - -func (hhs *HeaderHandlerStub) SetSignature(_ []byte) { - panic("implement me") -} - -// SetLeaderSignature - -func (hhs *HeaderHandlerStub) SetLeaderSignature(_ []byte) { - panic("implement me") -} - -// SetChainID - -func (hhs *HeaderHandlerStub) SetChainID(_ []byte) { - panic("implement me") -} - -// SetTxCount - -func (hhs *HeaderHandlerStub) SetTxCount(_ uint32) { - panic("implement me") -} - -// GetMiniBlockHeadersWithDst - -func (hhs *HeaderHandlerStub) GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32 { - return hhs.GetMiniBlockHeadersWithDstCalled(destId) -} - -// GetOrderedCrossMiniblocksWithDst - -func (hhs *HeaderHandlerStub) GetOrderedCrossMiniblocksWithDst(destId uint32) []*data.MiniBlockInfo { - return hhs.GetOrderedCrossMiniblocksWithDstCalled(destId) -} - -// GetMiniBlockHeadersHashes - -func (hhs *HeaderHandlerStub) GetMiniBlockHeadersHashes() [][]byte { - panic("implement me") -} - -// GetValidatorStatsRootHash - -func (hhs *HeaderHandlerStub) GetValidatorStatsRootHash() []byte { - return []byte("vs root hash") -} - -// SetValidatorStatsRootHash - -func (hhs *HeaderHandlerStub) SetValidatorStatsRootHash(_ []byte) { - panic("implement me") -} - -// IsInterfaceNil returns true if there is no value under the interface -func (hhs *HeaderHandlerStub) IsInterfaceNil() bool { - return hhs == nil -} - -// GetEpochStartMetaHash - -func (hhs *HeaderHandlerStub) GetEpochStartMetaHash() []byte { - panic("implement me") -} - -// GetSoftwareVersion - -func (hhs *HeaderHandlerStub) GetSoftwareVersion() []byte { - return []byte("softwareVersion") -} - -// SetSoftwareVersion - -func (hhs *HeaderHandlerStub) SetSoftwareVersion(_ []byte) { -} diff --git a/data/interface.go b/data/interface.go index 270bd6bd..8d4fed91 100644 --- a/data/interface.go +++ b/data/interface.go @@ -82,6 +82,7 @@ type HeaderHandler interface { SetAdditionalData(headerVersionData headerVersionData.HeaderAdditionalData) error IsStartOfEpochBlock() bool ShallowClone() HeaderHandler + CheckFieldsForNil() error IsInterfaceNil() bool } From c566f47dcb90abd9c4104e84a14ae0cff66f1d49 Mon Sep 17 00:00:00 2001 From: jules01 Date: Tue, 31 Jan 2023 20:56:01 +0200 Subject: [PATCH 7/8] - removed PubKeysBitmap check on the shard header --- data/block/block.go | 3 --- data/block/blockChecks_test.go | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/data/block/block.go b/data/block/block.go index eeabaf68..cc8a1fd8 100644 --- a/data/block/block.go +++ b/data/block/block.go @@ -597,9 +597,6 @@ func (h *Header) CheckFieldsForNil() error { if h.RandSeed == nil { return fmt.Errorf("%w in Header.RandSeed", data.ErrNilValue) } - if h.PubKeysBitmap == nil { - return fmt.Errorf("%w in Header.PubKeysBitmap", data.ErrNilValue) - } if h.RootHash == nil { return fmt.Errorf("%w in Header.RootHash", data.ErrNilValue) } diff --git a/data/block/blockChecks_test.go b/data/block/blockChecks_test.go index c4060c24..e4d99a80 100644 --- a/data/block/blockChecks_test.go +++ b/data/block/blockChecks_test.go @@ -14,6 +14,7 @@ import ( var headerV1ExceptionFields = []string{ "Signature", "LeaderSignature", + "PubKeysBitmap", "MetaBlockHashes", "EpochStartMetaHash", "ReceiptsHash", From 951073354ac9258286ba89696b386d9f4bac6789 Mon Sep 17 00:00:00 2001 From: jules01 Date: Tue, 31 Jan 2023 20:58:32 +0200 Subject: [PATCH 8/8] - removed ScheduledRootHash check on the shard header v2 --- data/block/blockV2.go | 4 +--- data/block/blockV2Checks_test.go | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/data/block/blockV2.go b/data/block/blockV2.go index 6d9e071f..0a690e2e 100644 --- a/data/block/blockV2.go +++ b/data/block/blockV2.go @@ -640,9 +640,7 @@ func (hv2 *HeaderV2) CheckFieldsForNil() error { if err != nil { return err } - if hv2.ScheduledRootHash == nil { - return fmt.Errorf("%w in HeaderV2.ScheduledRootHash", data.ErrNilValue) - } + if hv2.ScheduledAccumulatedFees == nil { return fmt.Errorf("%w in HeaderV2.ScheduledAccumulatedFees", data.ErrNilValue) } diff --git a/data/block/blockV2Checks_test.go b/data/block/blockV2Checks_test.go index 95ecd53c..b44e2d43 100644 --- a/data/block/blockV2Checks_test.go +++ b/data/block/blockV2Checks_test.go @@ -9,7 +9,10 @@ import ( "github.com/stretchr/testify/require" ) -var headerV2ExceptionFields = []string{"Header"} +var headerV2ExceptionFields = []string{ + "Header", + "ScheduledRootHash", +} func TestBlockHeaderV2_Checks(t *testing.T) { t.Parallel()