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
4 changes: 2 additions & 2 deletions client/elasticClientCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func loadResponseBody(body io.ReadCloser, dest interface{}) error {
return nil
}
if dest == nil {
_, err := io.Copy(ioutil.Discard, body)
_, err := io.Copy(io.Discard, body)
return err
}

Expand All @@ -56,7 +56,7 @@ func loadResponseBody(body io.ReadCloser, dest interface{}) error {

func elasticDefaultErrorResponseHandler(res *esapi.Response) error {
responseBody := map[string]interface{}{}
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("%w cannot read elastic response body bytes", err)
}
Expand Down
7 changes: 2 additions & 5 deletions client/elasticClientScroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand All @@ -23,9 +23,6 @@ func (ec *elasticClient) DoCountRequest(ctx context.Context, index string, body
if err != nil {
return 0, err
}
if err != nil {
return 0, err
}

bodyBytes, err := getBytesFromResponse(res)
if err != nil {
Expand Down Expand Up @@ -139,7 +136,7 @@ func getBytesFromResponse(res *esapi.Response) ([]byte, error) {
}
defer closeBody(res)

bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/elasticClientScroll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package client

import (
"context"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -24,7 +24,7 @@ func TestElasticClient_DoCountRequest(t *testing.T) {
jsonFile, err := os.Open("./testsData/response-count-request.json")
require.Nil(t, err)

byteValue, _ := ioutil.ReadAll(jsonFile)
byteValue, _ := io.ReadAll(jsonFile)
_, _ = w.Write(byteValue)
}

Expand Down
5 changes: 2 additions & 3 deletions client/logging/customLogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package logging

import (
"io"
"io/ioutil"
"net/http"
"time"

Expand All @@ -28,10 +27,10 @@ func (cl *CustomLogger) LogRoundTrip(
)

if req != nil && req.Body != nil && req.Body != http.NoBody {
reqSize, _ = io.Copy(ioutil.Discard, req.Body)
reqSize, _ = io.Copy(io.Discard, req.Body)
}
if res != nil && res.Body != nil && res.Body != http.NoBody {
resSize, _ = io.Copy(ioutil.Discard, res.Body)
resSize, _ = io.Copy(io.Discard, res.Body)
}

if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion data/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package data

import (
"time"

"github.com/multiversx/mx-chain-core-go/data/api"
)

// Block is a structure containing all the fields that need
Expand All @@ -18,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 All @@ -39,6 +41,7 @@ type Block struct {
MaxGasLimit uint64 `json:"maxGasLimit"`
ScheduledData *ScheduledData `json:"scheduledData,omitempty"`
EpochStartShardsData []*EpochStartShardData `json:"epochStartShardsData,omitempty"`
Proof *api.HeaderProof `json:"proof,omitempty"`
RandSeed string `json:"randSeed,omitempty"`
PrevRandSeed string `json:"prevRandSeed,omitempty"`
Signature string `json:"signature,omitempty"`
Expand All @@ -47,6 +50,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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/gin-contrib/cors v1.4.0
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.24
github.com/multiversx/mx-chain-communication-go v1.2.0
github.com/multiversx/mx-chain-core-go v1.3.1
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
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
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.24 h1:O0X7N9GfNVUCE9fukXA+dvfCRRjViYn88zOaE7feUog=
github.com/multiversx/mx-chain-core-go v1.2.24/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-communication-go v1.2.0 h1:0wOoLldiRbvaOPxwICbnRCqCpLqPewg8M/FMbC/0OXY=
github.com/multiversx/mx-chain-communication-go v1.2.0/go.mod h1:wS3aAwkmHbC9mlzQdvL6p7l8Rqw3vmzhj7WZW1dTveA=
github.com/multiversx/mx-chain-core-go v1.3.1 h1:r8DAkl9a9t6z38jjbtGNrz295pBeM6fwTq91TP8xX6U=
github.com/multiversx/mx-chain-core-go v1.3.1/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
4 changes: 2 additions & 2 deletions integrationtests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand All @@ -22,6 +21,7 @@ import (
)

var (
// nolint
log = logger.GetOrCreate("integration-tests")
pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, addressPrefix)
)
Expand Down Expand Up @@ -93,7 +93,7 @@ func getIndexMappings(index string) (string, error) {
return "", err
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return "", err
}
Expand Down
50 changes: 35 additions & 15 deletions process/elasticproc/block/blockProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/multiversx/mx-chain-core-go/data/api"
"strconv"
"time"

Expand Down Expand Up @@ -33,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 @@ -74,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 @@ -85,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 @@ -131,9 +137,31 @@ func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader)
appendBlockDetailsFromHeaders(elasticBlock, obh.Header, obh.BlockData.Body, obh.TransactionPool)
appendBlockDetailsFromIntraShardMbs(elasticBlock, obh.BlockData.IntraShardMiniBlocks, obh.TransactionPool, len(obh.Header.GetMiniBlockHeaderHandlers()))

addProofs(elasticBlock, obh)

return elasticBlock, nil
}

func addProofs(elasticBlock *data.Block, obh *outport.OutportBlockWithHeader) {
if obh.BlockData.HeaderProof != nil {
elasticBlock.Proof = proofToAPIProof(obh.BlockData.HeaderProof)
elasticBlock.PubKeyBitmap = elasticBlock.Proof.PubKeysBitmap
}
}

func proofToAPIProof(headerProof coreData.HeaderProofHandler) *api.HeaderProof {
return &api.HeaderProof{
PubKeysBitmap: hex.EncodeToString(headerProof.GetPubKeysBitmap()),
AggregatedSignature: hex.EncodeToString(headerProof.GetAggregatedSignature()),
HeaderHash: hex.EncodeToString(headerProof.GetHeaderHash()),
HeaderEpoch: headerProof.GetHeaderEpoch(),
HeaderNonce: headerProof.GetHeaderNonce(),
HeaderShardId: headerProof.GetHeaderShardId(),
HeaderRound: headerProof.GetHeaderRound(),
IsStartOfEpoch: headerProof.GetIsStartOfEpoch(),
}
}

func getTxsCount(header coreData.HeaderHandler) (numTxs, notarizedTxs uint32) {
numTxs = header.GetTxCount()

Expand Down Expand Up @@ -368,14 +396,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
Loading
Loading