Skip to content

Commit 0a681ee

Browse files
authored
Merge pull request #331 from multiversx/prev-header-proof
Extended block structure
2 parents 21d951d + 1e626a9 commit 0a681ee

File tree

11 files changed

+88
-19
lines changed

11 files changed

+88
-19
lines changed

client/elasticClientCommon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func loadResponseBody(body io.ReadCloser, dest interface{}) error {
4646
return nil
4747
}
4848
if dest == nil {
49-
_, err := io.Copy(ioutil.Discard, body)
49+
_, err := io.Copy(io.Discard, body)
5050
return err
5151
}
5252

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

5757
func elasticDefaultErrorResponseHandler(res *esapi.Response) error {
5858
responseBody := map[string]interface{}{}
59-
bodyBytes, err := ioutil.ReadAll(res.Body)
59+
bodyBytes, err := io.ReadAll(res.Body)
6060
if err != nil {
6161
return fmt.Errorf("%w cannot read elastic response body bytes", err)
6262
}

client/elasticClientScroll.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strconv"
1010
"time"
@@ -23,9 +23,6 @@ func (ec *elasticClient) DoCountRequest(ctx context.Context, index string, body
2323
if err != nil {
2424
return 0, err
2525
}
26-
if err != nil {
27-
return 0, err
28-
}
2926

3027
bodyBytes, err := getBytesFromResponse(res)
3128
if err != nil {
@@ -139,7 +136,7 @@ func getBytesFromResponse(res *esapi.Response) ([]byte, error) {
139136
}
140137
defer closeBody(res)
141138

142-
bodyBytes, err := ioutil.ReadAll(res.Body)
139+
bodyBytes, err := io.ReadAll(res.Body)
143140
if err != nil {
144141
return nil, err
145142
}

client/elasticClientScroll_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package client
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"os"
@@ -24,7 +24,7 @@ func TestElasticClient_DoCountRequest(t *testing.T) {
2424
jsonFile, err := os.Open("./testsData/response-count-request.json")
2525
require.Nil(t, err)
2626

27-
byteValue, _ := ioutil.ReadAll(jsonFile)
27+
byteValue, _ := io.ReadAll(jsonFile)
2828
_, _ = w.Write(byteValue)
2929
}
3030

client/logging/customLogger.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package logging
22

33
import (
44
"io"
5-
"io/ioutil"
65
"net/http"
76
"time"
87

@@ -28,10 +27,10 @@ func (cl *CustomLogger) LogRoundTrip(
2827
)
2928

3029
if req != nil && req.Body != nil && req.Body != http.NoBody {
31-
reqSize, _ = io.Copy(ioutil.Discard, req.Body)
30+
reqSize, _ = io.Copy(io.Discard, req.Body)
3231
}
3332
if res != nil && res.Body != nil && res.Body != http.NoBody {
34-
resSize, _ = io.Copy(ioutil.Discard, res.Body)
33+
resSize, _ = io.Copy(io.Discard, res.Body)
3534
}
3635

3736
if err != nil {

data/block.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package data
22

33
import (
44
"time"
5+
6+
"github.com/multiversx/mx-chain-core-go/data/api"
57
)
68

79
// Block is a structure containing all the fields that need
@@ -39,6 +41,8 @@ type Block struct {
3941
MaxGasLimit uint64 `json:"maxGasLimit"`
4042
ScheduledData *ScheduledData `json:"scheduledData,omitempty"`
4143
EpochStartShardsData []*EpochStartShardData `json:"epochStartShardsData,omitempty"`
44+
Proof *api.HeaderProof `json:"proof,omitempty"`
45+
PreviousHeaderProof *api.HeaderProof `json:"previousHeaderProof,omitempty"`
4246
RandSeed string `json:"randSeed,omitempty"`
4347
PrevRandSeed string `json:"prevRandSeed,omitempty"`
4448
Signature string `json:"signature,omitempty"`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/gin-gonic/gin v1.10.0
99
github.com/google/uuid v1.6.0
1010
github.com/multiversx/mx-chain-communication-go v1.1.1
11-
github.com/multiversx/mx-chain-core-go v1.2.24
11+
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250219104810-75b7a8ff6bbb
1212
github.com/multiversx/mx-chain-logger-go v1.0.15
1313
github.com/multiversx/mx-chain-vm-common-go v1.5.16
1414
github.com/prometheus/client_model v0.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
253253
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
254254
github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM=
255255
github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM=
256-
github.com/multiversx/mx-chain-core-go v1.2.24 h1:O0X7N9GfNVUCE9fukXA+dvfCRRjViYn88zOaE7feUog=
257-
github.com/multiversx/mx-chain-core-go v1.2.24/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
256+
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250219104810-75b7a8ff6bbb h1:XoFaZ3/KEaI7N0o1gqiek+2s/PlqmcvwukAT4iCvAIM=
257+
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250219104810-75b7a8ff6bbb/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
258258
github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk=
259259
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
260260
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=

integrationtests/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"net/url"
109
"os"
@@ -22,6 +21,7 @@ import (
2221
)
2322

2423
var (
24+
// nolint
2525
log = logger.GetOrCreate("integration-tests")
2626
pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, addressPrefix)
2727
)
@@ -93,7 +93,7 @@ func getIndexMappings(index string) (string, error) {
9393
return "", err
9494
}
9595

96-
body, err := ioutil.ReadAll(res.Body)
96+
body, err := io.ReadAll(res.Body)
9797
if err != nil {
9898
return "", err
9999
}

process/elasticproc/block/blockProcessor.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"errors"
66
"fmt"
7+
"github.com/multiversx/mx-chain-core-go/data/api"
78
"strconv"
89
"time"
910

@@ -131,9 +132,36 @@ func (bp *blockProcessor) PrepareBlockForDB(obh *outport.OutportBlockWithHeader)
131132
appendBlockDetailsFromHeaders(elasticBlock, obh.Header, obh.BlockData.Body, obh.TransactionPool)
132133
appendBlockDetailsFromIntraShardMbs(elasticBlock, obh.BlockData.IntraShardMiniBlocks, obh.TransactionPool, len(obh.Header.GetMiniBlockHeaderHandlers()))
133134

135+
addProofs(elasticBlock, obh)
136+
134137
return elasticBlock, nil
135138
}
136139

140+
func addProofs(elasticBlock *data.Block, obh *outport.OutportBlockWithHeader) {
141+
if obh.BlockData.HeaderProof != nil {
142+
elasticBlock.Proof = proofToAPIProof(obh.BlockData.HeaderProof)
143+
}
144+
145+
prevHeaderProof := obh.Header.GetPreviousProof()
146+
if check.IfNilReflect(prevHeaderProof) {
147+
return
148+
}
149+
elasticBlock.PreviousHeaderProof = proofToAPIProof(prevHeaderProof)
150+
}
151+
152+
func proofToAPIProof(headerProof coreData.HeaderProofHandler) *api.HeaderProof {
153+
return &api.HeaderProof{
154+
PubKeysBitmap: hex.EncodeToString(headerProof.GetPubKeysBitmap()),
155+
AggregatedSignature: hex.EncodeToString(headerProof.GetAggregatedSignature()),
156+
HeaderHash: hex.EncodeToString(headerProof.GetHeaderHash()),
157+
HeaderEpoch: headerProof.GetHeaderEpoch(),
158+
HeaderNonce: headerProof.GetHeaderNonce(),
159+
HeaderShardId: headerProof.GetHeaderShardId(),
160+
HeaderRound: headerProof.GetHeaderRound(),
161+
IsStartOfEpoch: headerProof.GetIsStartOfEpoch(),
162+
}
163+
}
164+
137165
func getTxsCount(header coreData.HeaderHandler) (numTxs, notarizedTxs uint32) {
138166
numTxs = header.GetTxCount()
139167

process/elasticproc/block/blockProcessor_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package block
33
import (
44
"encoding/hex"
55
"errors"
6+
"github.com/multiversx/mx-chain-core-go/data/api"
67
"math/big"
78
"testing"
89

@@ -258,13 +259,33 @@ func TestBlockProcessor_PrepareBlockForDBEpochStartMeta(t *testing.T) {
258259
TxCount: 120,
259260
},
260261
},
262+
PreviousHeaderProof: &dataBlock.HeaderProof{
263+
PubKeysBitmap: []byte("bitmap"),
264+
AggregatedSignature: []byte("sig"),
265+
HeaderHash: []byte("hash"),
266+
HeaderEpoch: 1,
267+
HeaderNonce: 3,
268+
HeaderShardId: 2,
269+
HeaderRound: 4,
270+
IsStartOfEpoch: true,
271+
},
261272
}
262273

263274
headerBytes, _ := bp.marshalizer.Marshal(header)
264275
outportBlockWithHeader := &outport.OutportBlockWithHeader{
265276
Header: header,
266277
OutportBlock: &outport.OutportBlock{
267278
BlockData: &outport.BlockData{
279+
HeaderProof: &dataBlock.HeaderProof{
280+
PubKeysBitmap: []byte("bitmap1"),
281+
AggregatedSignature: []byte("sig1"),
282+
HeaderHash: []byte("hash1"),
283+
HeaderEpoch: 2,
284+
HeaderNonce: 2,
285+
HeaderShardId: 2,
286+
HeaderRound: 2,
287+
IsStartOfEpoch: false,
288+
},
268289
HeaderBytes: headerBytes,
269290
HeaderHash: []byte("hash"),
270291
Body: &dataBlock.Body{
@@ -293,7 +314,7 @@ func TestBlockProcessor_PrepareBlockForDBEpochStartMeta(t *testing.T) {
293314
Proposer: 0,
294315
Validators: nil,
295316
PubKeyBitmap: "",
296-
Size: 898,
317+
Size: 1090,
297318
SizeTxs: 0,
298319
Timestamp: 0,
299320
StateRootHash: "",
@@ -331,6 +352,26 @@ func TestBlockProcessor_PrepareBlockForDBEpochStartMeta(t *testing.T) {
331352
TxsHashes: []string{},
332353
},
333354
},
355+
Proof: &api.HeaderProof{
356+
PubKeysBitmap: "6269746d617031",
357+
AggregatedSignature: "73696731",
358+
HeaderHash: "6861736831",
359+
HeaderEpoch: 2,
360+
HeaderNonce: 2,
361+
HeaderShardId: 2,
362+
HeaderRound: 2,
363+
IsStartOfEpoch: false,
364+
},
365+
PreviousHeaderProof: &api.HeaderProof{
366+
PubKeysBitmap: "6269746d6170",
367+
AggregatedSignature: "736967",
368+
HeaderHash: "68617368",
369+
HeaderEpoch: 1,
370+
HeaderNonce: 3,
371+
HeaderShardId: 2,
372+
HeaderRound: 4,
373+
IsStartOfEpoch: true,
374+
},
334375
EpochStartShardsData: []*data.EpochStartShardData{
335376
{
336377
ShardID: 1,

0 commit comments

Comments
 (0)