Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Block struct {
MiniBlocksDetails []*MiniBlocksDetails `json:"miniBlocksDetails,omitempty"`
NotarizedBlocksHashes []string `json:"notarizedBlocksHashes"`
Proposer uint64 `json:"proposer"`
Validators []uint64 `json:"validators"`
Validators []uint64 `json:"validators,omitempty"`
PubKeyBitmap string `json:"pubKeyBitmap"`
Size int64 `json:"size"`
SizeTxs int64 `json:"sizeTxs"`
Expand Down Expand Up @@ -51,6 +51,7 @@ type Block struct {
SoftwareVersion string `json:"softwareVersion,omitempty"`
ReceiptsHash string `json:"receiptsHash,omitempty"`
Reserved []byte `json:"reserved,omitempty"`
ProposerBlsKey string `json:"proposerBlsKey,omitempty"`
}

// MiniBlocksDetails is a structure that hold information about mini-blocks execution details
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/multiversx/mx-chain-communication-go v1.1.1
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250219104810-75b7a8ff6bbb
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250306125819-46a071b85ade
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-vm-common-go v1.5.16
github.com/prometheus/client_model v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM=
github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250219104810-75b7a8ff6bbb h1:XoFaZ3/KEaI7N0o1gqiek+2s/PlqmcvwukAT4iCvAIM=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250219104810-75b7a8ff6bbb/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250306125819-46a071b85ade h1:jLSSdm/X8T2H+I9/+wHvFuS9FBbXjTfNPJYZpzDdj/I=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250306125819-46a071b85ade/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=
Expand Down
29 changes: 14 additions & 15 deletions process/elasticproc/block/blockProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@ var (
)

type blockProcessor struct {
hasher hashing.Hasher
marshalizer marshal.Marshalizer
hasher hashing.Hasher
marshalizer marshal.Marshalizer
validatorsPubKeyConverter core.PubkeyConverter
}

// NewBlockProcessor will create a new instance of block processor
func NewBlockProcessor(hasher hashing.Hasher, marshalizer marshal.Marshalizer) (*blockProcessor, error) {
func NewBlockProcessor(hasher hashing.Hasher, marshalizer marshal.Marshalizer, validatorsPubKeyConverter core.PubkeyConverter) (*blockProcessor, error) {
if check.IfNil(hasher) {
return nil, indexer.ErrNilHasher
}
if check.IfNil(marshalizer) {
return nil, indexer.ErrNilMarshalizer
}
if check.IfNil(validatorsPubKeyConverter) {
return nil, indexer.ErrNilPubkeyConverter
}

return &blockProcessor{
hasher: hasher,
marshalizer: marshalizer,
hasher: hasher,
marshalizer: marshalizer,
validatorsPubKeyConverter: validatorsPubKeyConverter,
}, nil
}

Expand All @@ -75,7 +80,6 @@ func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader)

sizeTxs := computeSizeOfTransactions(obh.TransactionPool)
miniblocksHashes := bp.getEncodedMBSHashes(obh.BlockData.Body, obh.BlockData.IntraShardMiniBlocks)
leaderIndex := bp.getLeaderIndex(obh.SignersIndexes)

numTxs, notarizedTxs := getTxsCount(obh.Header)
elasticBlock := &data.Block{
Expand All @@ -86,7 +90,8 @@ func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader)
Hash: hex.EncodeToString(obh.BlockData.HeaderHash),
MiniBlocksHashes: miniblocksHashes,
NotarizedBlocksHashes: obh.NotarizedHeadersHashes,
Proposer: leaderIndex,
Proposer: obh.LeaderIndex,
ProposerBlsKey: hex.EncodeToString(obh.LeaderBLSKey),
Validators: obh.SignersIndexes,
PubKeyBitmap: hex.EncodeToString(obh.Header.GetPubKeysBitmap()),
Size: int64(blockSizeInBytes),
Expand Down Expand Up @@ -140,13 +145,15 @@ func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader)
func addProofs(elasticBlock *data.Block, obh *outport.OutportBlockWithHeader) {
if obh.BlockData.HeaderProof != nil {
elasticBlock.Proof = proofToAPIProof(obh.BlockData.HeaderProof)
elasticBlock.PubKeyBitmap = elasticBlock.Proof.PubKeysBitmap
}

prevHeaderProof := obh.Header.GetPreviousProof()
if check.IfNilReflect(prevHeaderProof) {
return
}
elasticBlock.PreviousHeaderProof = proofToAPIProof(prevHeaderProof)

}

func proofToAPIProof(headerProof coreData.HeaderProofHandler) *api.HeaderProof {
Expand Down Expand Up @@ -396,14 +403,6 @@ func (bp *blockProcessor) computeBlockSize(headerBytes []byte, body *block.Body)
return blockSize, nil
}

func (bp *blockProcessor) getLeaderIndex(signersIndexes []uint64) uint64 {
if len(signersIndexes) > 0 {
return signersIndexes[0]
}

return 0
}

func computeBlockSearchOrder(header coreData.HeaderHandler) uint64 {
shardIdentifier := createShardIdentifier(header.GetShardID())
stringOrder := fmt.Sprintf("1%02d%d", shardIdentifier, header.GetNonce())
Expand Down
39 changes: 23 additions & 16 deletions process/elasticproc/block/blockProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,34 @@ func TestNewBlockProcessor(t *testing.T) {

tests := []struct {
name string
argsFunc func() (hashing.Hasher, marshal.Marshalizer)
argsFunc func() (hashing.Hasher, marshal.Marshalizer, core.PubkeyConverter)
exErr error
}{
{
name: "NilMarshalizer",
argsFunc: func() (hashing.Hasher, marshal.Marshalizer) {
return &mock.HasherMock{}, nil
argsFunc: func() (hashing.Hasher, marshal.Marshalizer, core.PubkeyConverter) {
return &mock.HasherMock{}, nil, nil
},
exErr: indexer.ErrNilMarshalizer,
},
{
name: "NilHasher",
argsFunc: func() (hashing.Hasher, marshal.Marshalizer) {
return nil, &mock.MarshalizerMock{}
argsFunc: func() (hashing.Hasher, marshal.Marshalizer, core.PubkeyConverter) {
return nil, &mock.MarshalizerMock{}, nil
},
exErr: indexer.ErrNilHasher,
},
{
name: "NilValidatorPubKeyConverter",
argsFunc: func() (hashing.Hasher, marshal.Marshalizer, core.PubkeyConverter) {
return &mock.HasherMock{}, &mock.MarshalizerMock{}, nil
},
exErr: indexer.ErrNilPubkeyConverter,
},
{
name: "ShouldWork",
argsFunc: func() (hashing.Hasher, marshal.Marshalizer) {
return &mock.HasherMock{}, &mock.MarshalizerMock{}
argsFunc: func() (hashing.Hasher, marshal.Marshalizer, core.PubkeyConverter) {
return &mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{}
},
exErr: nil,
},
Expand All @@ -61,7 +68,7 @@ func TestNewBlockProcessor(t *testing.T) {
func TestBlockProcessor_PrepareBlockForDBShouldWork(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

outportBlockWithHeader := &outport.OutportBlockWithHeader{
Header: &dataBlock.Header{
Expand Down Expand Up @@ -123,7 +130,7 @@ func TestBlockProcessor_PrepareBlockForDBShouldWork(t *testing.T) {
func TestBlockProcessor_PrepareBlockForDBNilHeader(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

outportBlockWithHeader := &outport.OutportBlockWithHeader{}
dbBlock, err := bp.PrepareBlockForDB(outportBlockWithHeader)
Expand All @@ -134,7 +141,7 @@ func TestBlockProcessor_PrepareBlockForDBNilHeader(t *testing.T) {
func TestBlockProcessor_PrepareBlockForDBNilBody(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

outportBlockWithHeader := &outport.OutportBlockWithHeader{
Header: &dataBlock.MetaBlock{},
Expand All @@ -155,7 +162,7 @@ func TestBlockProcessor_PrepareBlockForDBMarshalFailHeader(t *testing.T) {
MarshalCalled: func(obj interface{}) ([]byte, error) {
return nil, expectedErr
},
})
}, &mock.PubkeyConverterMock{})

outportBlockWithHeader := &outport.OutportBlockWithHeader{
Header: &dataBlock.Header{},
Expand All @@ -182,7 +189,7 @@ func TestBlockProcessor_PrepareBlockForDBMarshalFailBlock(t *testing.T) {
MarshalCalled: func(obj interface{}) ([]byte, error) {
return nil, expectedErr
},
})
}, &mock.PubkeyConverterMock{})

outportBlockWithHeader := &outport.OutportBlockWithHeader{
Header: &dataBlock.Header{},
Expand All @@ -204,7 +211,7 @@ func TestBlockProcessor_PrepareBlockForDBMarshalFailBlock(t *testing.T) {
func TestBlockProcessor_ComputeHeaderHash(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

header := &dataBlock.Header{}
hashBytes, err := bp.ComputeHeaderHash(header)
Expand All @@ -215,7 +222,7 @@ func TestBlockProcessor_ComputeHeaderHash(t *testing.T) {
func TestBlockProcessor_PrepareBlockForDBEpochStartMeta(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

header := &dataBlock.MetaBlock{
TxCount: 1000,
Expand Down Expand Up @@ -313,7 +320,7 @@ func TestBlockProcessor_PrepareBlockForDBEpochStartMeta(t *testing.T) {
NotarizedBlocksHashes: nil,
Proposer: 0,
Validators: nil,
PubKeyBitmap: "",
PubKeyBitmap: "6269746d617031",
Size: 1090,
SizeTxs: 0,
Timestamp: 0,
Expand Down Expand Up @@ -405,7 +412,7 @@ func TestBlockProcessor_PrepareBlockForDBMiniBlocksDetails(t *testing.T) {
t.Parallel()

gogoMarshaller := &marshal.GogoProtoMarshalizer{}
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

mbhr := &dataBlock.MiniBlockHeaderReserved{
IndexOfFirstTxProcessed: 0,
Expand Down
12 changes: 6 additions & 6 deletions process/elasticproc/block/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestBlockProcessor_SerializeBlockNilElasticBlockErrors(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

err := bp.SerializeBlock(nil, nil, "")
require.True(t, errors.Is(err, dataindexer.ErrNilElasticBlock))
Expand All @@ -25,20 +25,20 @@ func TestBlockProcessor_SerializeBlockNilElasticBlockErrors(t *testing.T) {
func TestBlockProcessor_SerializeBlock(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

buffSlice := data.NewBufferSlice(data.DefaultMaxBulkSize)
err := bp.SerializeBlock(&data.Block{Nonce: 1}, buffSlice, "blocks")
require.Nil(t, err)
require.Equal(t, `{ "index" : { "_index":"blocks", "_id" : "" } }
{"uuid":"","nonce":1,"round":0,"epoch":0,"miniBlocksHashes":null,"notarizedBlocksHashes":null,"proposer":0,"validators":null,"pubKeyBitmap":"","size":0,"sizeTxs":0,"timestamp":0,"stateRootHash":"","prevHash":"","shardId":0,"txCount":0,"notarizedTxsCount":0,"accumulatedFees":"","developerFees":"","epochStartBlock":false,"searchOrder":0,"gasProvided":0,"gasRefunded":0,"gasPenalized":0,"maxGasLimit":0}
{"uuid":"","nonce":1,"round":0,"epoch":0,"miniBlocksHashes":null,"notarizedBlocksHashes":null,"proposer":0,"pubKeyBitmap":"","size":0,"sizeTxs":0,"timestamp":0,"stateRootHash":"","prevHash":"","shardId":0,"txCount":0,"notarizedTxsCount":0,"accumulatedFees":"","developerFees":"","epochStartBlock":false,"searchOrder":0,"gasProvided":0,"gasRefunded":0,"gasPenalized":0,"maxGasLimit":0}
`, buffSlice.Buffers()[0].String())
}

func TestBlockProcessor_SerializeEpochInfoDataErrors(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

err := bp.SerializeEpochInfoData(nil, nil, "")
require.Equal(t, dataindexer.ErrNilHeaderHandler, err)
Expand All @@ -50,7 +50,7 @@ func TestBlockProcessor_SerializeEpochInfoDataErrors(t *testing.T) {
func TestBlockProcessor_SerializeEpochInfoData(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

buffSlice := data.NewBufferSlice(data.DefaultMaxBulkSize)
err := bp.SerializeEpochInfoData(&dataBlock.MetaBlock{
Expand All @@ -66,7 +66,7 @@ func TestBlockProcessor_SerializeEpochInfoData(t *testing.T) {
func TestBlockProcessor_SerializeBlockEpochStartMeta(t *testing.T) {
t.Parallel()

bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

buffSlice := data.NewBufferSlice(data.DefaultMaxBulkSize)
err := bp.SerializeBlock(&data.Block{
Expand Down
6 changes: 3 additions & 3 deletions process/elasticproc/elasticProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func createMockElasticProcessorArgs() *ArgElasticProcessor {
balanceConverter, _ := converters.NewBalanceConverter(10)

acp, _ := accounts.NewAccountsProcessor(&mock.PubkeyConverterMock{}, balanceConverter)
bp, _ := block.NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
bp, _ := block.NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})
mp, _ := miniblocks.NewMiniblocksProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
vp, _ := validators.NewValidatorsProcessor(mock.NewPubkeyConverterMock(32), 0)
args := logsevents.ArgsLogsAndEventsProcessor{
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestElasticProcessor_RemoveHeader(t *testing.T) {
},
}

args.BlockProc, _ = block.NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
args.BlockProc, _ = block.NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})

elasticProc, err := NewElasticProcessor(args)
require.NoError(t, err)
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestElasticseachDatabaseSaveHeader_RequestError(t *testing.T) {
return localErr
},
}
arguments.BlockProc, _ = block.NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{})
arguments.BlockProc, _ = block.NewBlockProcessor(&mock.HasherMock{}, &mock.MarshalizerMock{}, &mock.PubkeyConverterMock{})
elasticDatabase := newElasticsearchProcessor(dbWriter, arguments)

err := elasticDatabase.SaveHeader(createEmptyOutportBlockWithHeader())
Expand Down
2 changes: 1 addition & 1 deletion process/elasticproc/factory/elasticProcessorFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func CreateElasticProcessor(arguments ArgElasticProcessorFactory) (dataindexer.E
return nil, err
}

blockProcHandler, err := blockProc.NewBlockProcessor(arguments.Hasher, arguments.Marshalizer)
blockProcHandler, err := blockProc.NewBlockProcessor(arguments.Hasher, arguments.Marshalizer, arguments.ValidatorPubkeyConverter)
if err != nil {
return nil, err
}
Expand Down