Skip to content

Commit 4486bce

Browse files
authored
Merge pull request #7884 from multiversx/todos2
TODOs part 2
2 parents 143c2f4 + 77dcf3a commit 4486bce

25 files changed

Lines changed: 314 additions & 37 deletions

consensus/broadcast/commonMessenger.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ func (cm *commonMessenger) BroadcastBlockData(
171171
time.Sleep(extraDelayForBroadcast)
172172

173173
if len(miniBlocks) > 0 {
174-
// TODO: check if we need to pack also miniblock into smaller chunks
175174
err := cm.BroadcastMiniBlocks(miniBlocks, pkBytes)
176175
if err != nil {
177176
log.Warn("commonMessenger.BroadcastBlockData: broadcast miniblocks", "error", err.Error())

epochStart/bootstrap/startInEpochScheduled.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ func (ses *startInEpochWithScheduledDataSyncer) IsInterfaceNil() bool {
9090
func (ses *startInEpochWithScheduledDataSyncer) getRequiredHeaderByHash(
9191
notarizedShardHeader data.ShardHeaderHandler,
9292
) (data.ShardHeaderHandler, map[string]data.HeaderHandler, error) {
93-
// TODO: analyze the requested headers in this func, after andromeda committed blocks are final
94-
// it might not be needed to request based on prev header
93+
if notarizedShardHeader.IsHeaderV3() {
94+
return notarizedShardHeader, nil, nil
95+
}
9596

9697
shardIDs, hashesToRequest := getShardIDAndHashesForIncludedMetaBlocks(notarizedShardHeader)
9798

@@ -148,10 +149,6 @@ func (ses *startInEpochWithScheduledDataSyncer) getRequiredHeaderByHash(
148149
}
149150
}
150151

151-
if notarizedShardHeader.IsHeaderV3() {
152-
headerToBeProcessed = notarizedShardHeader
153-
}
154-
155152
return headerToBeProcessed, headers, nil
156153
}
157154

epochStart/bootstrap/startInEpochScheduled_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,28 @@ func TestStartInEpochWithScheduledDataSyncer_UpdateSyncDataIfNeededScheduledEnab
182182
require.Equal(t, prevHeader, header)
183183
}
184184

185+
func TestStartInEpochWithScheduledDataSyncer_getRequiredHeaderByHashV3HeaderShouldShortCircuit(t *testing.T) {
186+
t.Parallel()
187+
188+
args := createDefaultDataSyncerFactoryArgs()
189+
syncCalled := false
190+
args.HeadersSyncer = &epochStartMocks.HeadersByHashSyncerStub{
191+
SyncMissingHeadersByHashCalled: func(shardIDs []uint32, headersHashes [][]byte, ctx context.Context) error {
192+
syncCalled = true
193+
return nil
194+
},
195+
}
196+
ds, _ := newStartInEpochShardHeaderDataSyncerWithScheduled(args.ScheduledTxsHandler, args.HeadersSyncer, args.MiniBlocksSyncer, args.TxSyncer, 0)
197+
198+
notarizedShardHeader := &block.HeaderV3{Nonce: 12, Epoch: 2, PrevHash: []byte("prevHash")}
199+
200+
header, headersMap, err := ds.getRequiredHeaderByHash(notarizedShardHeader)
201+
require.Nil(t, err)
202+
require.Nil(t, headersMap)
203+
require.Equal(t, notarizedShardHeader, header)
204+
require.False(t, syncCalled, "no prev-header sync should be performed for V3 headers")
205+
}
206+
185207
func TestStartInEpochWithScheduledDataSyncer_getRequiredHeaderByHash(t *testing.T) {
186208
// TODO: add test
187209
}

factory/processing/blockProcessorCreator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ func (pcf *processComponentsFactory) newShardBlockProcessor(
394394
return nil, err
395395
}
396396

397-
// TODO: evaluate disabling this entirely (for old flows) - the check is not triggered if async enabled but there are still some checks in the old flow
398397
blockSizeComputationHandler, err := preprocess.NewBlockSizeComputation(
399398
pcf.coreData.InternalMarshalizer(),
400399
blockSizeThrottler,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/libp2p/go-libp2p-pubsub v0.13.0
2020
github.com/mitchellh/mapstructure v1.5.0
2121
github.com/multiversx/mx-chain-communication-go v1.3.3-0.20260608072730-982186a1ad78
22-
github.com/multiversx/mx-chain-core-go v1.5.1-0.20260618090441-fe4dfcdcb341
22+
github.com/multiversx/mx-chain-core-go v1.5.1-0.20260618130450-9b7f1defd425
2323
github.com/multiversx/mx-chain-crypto-go v1.3.1
2424
github.com/multiversx/mx-chain-es-indexer-go v1.10.3-0.20260608081825-40e586306036
2525
github.com/multiversx/mx-chain-logger-go v1.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
401401
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
402402
github.com/multiversx/mx-chain-communication-go v1.3.3-0.20260608072730-982186a1ad78 h1:vdYSj8Jj83H5wMkQOcDKvBXf2yVLXgVmA1IthHuv3aY=
403403
github.com/multiversx/mx-chain-communication-go v1.3.3-0.20260608072730-982186a1ad78/go.mod h1:gDVWn6zUW6aCN1YOm/FbbT5MUmhgn/L1Rmpl8EoH3Yg=
404-
github.com/multiversx/mx-chain-core-go v1.5.1-0.20260618090441-fe4dfcdcb341 h1:Q01qsxt5WFyI2xN/rYwBe3It76CP6G5h+MH37wS+q9g=
405-
github.com/multiversx/mx-chain-core-go v1.5.1-0.20260618090441-fe4dfcdcb341/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
404+
github.com/multiversx/mx-chain-core-go v1.5.1-0.20260618130450-9b7f1defd425 h1:Y5mv8pJ7V7Qca28fAuoUoJrgVHb8wjDkSCjD/TzSfAs=
405+
github.com/multiversx/mx-chain-core-go v1.5.1-0.20260618130450-9b7f1defd425/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
406406
github.com/multiversx/mx-chain-crypto-go v1.3.1 h1:tCoGkfiv0wz97kuW6AZPW4RVL0Yp7PBo8NKQj9f2oh4=
407407
github.com/multiversx/mx-chain-crypto-go v1.3.1/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM=
408408
github.com/multiversx/mx-chain-es-indexer-go v1.10.3-0.20260608081825-40e586306036 h1:a0euQ0LrFvP3y7Uf4CJ39tXBo0tsTEzPLrvJriuO2oA=

process/block/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type MiniBlocksSelectionSession interface {
7272
GetNumTxsAdded() uint32
7373
AddMiniBlocksAndHashes(miniBlocksAndHashes []block.MiniblockAndHash) error
7474
CreateAndAddMiniBlockFromTransactions(txHashes [][]byte) error
75+
RemoveEmptyMiniBlocks()
7576
IsInterfaceNil() bool
7677
}
7778

process/block/mbsSelectionSession.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,33 @@ func (s *miniBlocksSelectionSession) AddMiniBlocksAndHashes(miniBlocksAndHashes
240240
return nil
241241
}
242242

243+
// RemoveEmptyMiniBlocks removes any mini blocks that contain no transactions, keeping the internal slices consistent
244+
func (s *miniBlocksSelectionSession) RemoveEmptyMiniBlocks() {
245+
s.mut.Lock()
246+
defer s.mut.Unlock()
247+
248+
filteredMiniBlocks := make(block.MiniBlockSlice, 0, len(s.miniBlocks))
249+
filteredHeaders := make([]data.MiniBlockHeaderHandler, 0, len(s.miniBlockHeaderHandlers))
250+
filteredHashes := make([][]byte, 0, len(s.miniBlockHashes))
251+
252+
for i, miniBlock := range s.miniBlocks {
253+
if len(miniBlock.GetTxHashes()) == 0 {
254+
log.Trace("miniBlocksSelectionSession.RemoveEmptyMiniBlocks: removed empty mini block",
255+
"hash", s.miniBlockHashes[i])
256+
delete(s.miniBlockHashesUnique, string(s.miniBlockHashes[i]))
257+
continue
258+
}
259+
260+
filteredMiniBlocks = append(filteredMiniBlocks, miniBlock)
261+
filteredHeaders = append(filteredHeaders, s.miniBlockHeaderHandlers[i])
262+
filteredHashes = append(filteredHashes, s.miniBlockHashes[i])
263+
}
264+
265+
s.miniBlocks = filteredMiniBlocks
266+
s.miniBlockHeaderHandlers = filteredHeaders
267+
s.miniBlockHashes = filteredHashes
268+
}
269+
243270
// CreateAndAddMiniBlockFromTransactions creates a mini block from the provided transaction hashes
244271
func (s *miniBlocksSelectionSession) CreateAndAddMiniBlockFromTransactions(txHashes [][]byte) error {
245272
if len(txHashes) == 0 {

process/block/mbsSelectionSession_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/multiversx/mx-chain-core-go/data"
78
"github.com/multiversx/mx-chain-core-go/data/block"
89
"github.com/multiversx/mx-chain-core-go/marshal/factory"
910
"github.com/stretchr/testify/require"
@@ -230,6 +231,42 @@ func TestMiniBlockSelectionSession_CreateAndAddMiniBlockFromTransactions(t *test
230231
})
231232
}
232233

234+
func TestMiniBlocksSelectionSession_RemoveEmptyMiniBlocks(t *testing.T) {
235+
t.Parallel()
236+
237+
marshaller := &testscommon.MarshallerStub{}
238+
hasher := &testscommon.HasherStub{}
239+
240+
newMbHeader := func(hash []byte, txCount uint32) *block.MiniBlockHeader {
241+
return &block.MiniBlockHeader{Hash: hash, SenderShardID: 1, ReceiverShardID: 1, TxCount: txCount, Type: block.TxBlock}
242+
}
243+
244+
session, _ := NewMiniBlocksSelectionSession(1, marshaller, hasher)
245+
emptyMb := &block.MiniBlock{TxHashes: nil}
246+
emptyHash := []byte("emptyHash")
247+
nonEmptyMb := &block.MiniBlock{TxHashes: [][]byte{[]byte("tx1")}}
248+
nonEmptyHash := []byte("nonEmptyHash")
249+
250+
session.miniBlocks = block.MiniBlockSlice{emptyMb, nonEmptyMb}
251+
session.miniBlockHeaderHandlers = []data.MiniBlockHeaderHandler{newMbHeader(emptyHash, 0), newMbHeader(nonEmptyHash, 1)}
252+
session.miniBlockHashes = [][]byte{emptyHash, nonEmptyHash}
253+
session.miniBlockHashesUnique[string(emptyHash)] = struct{}{}
254+
session.miniBlockHashesUnique[string(nonEmptyHash)] = struct{}{}
255+
256+
session.RemoveEmptyMiniBlocks()
257+
258+
require.Len(t, session.GetMiniBlocks(), 1)
259+
require.Len(t, session.GetMiniBlockHeaderHandlers(), 1)
260+
require.Len(t, session.GetMiniBlockHashes(), 1)
261+
require.Equal(t, nonEmptyMb, session.GetMiniBlocks()[0])
262+
require.Equal(t, nonEmptyHash, session.GetMiniBlockHashes()[0])
263+
264+
_, exists := session.miniBlockHashesUnique[string(emptyHash)]
265+
require.False(t, exists)
266+
_, exists = session.miniBlockHashesUnique[string(nonEmptyHash)]
267+
require.True(t, exists)
268+
}
269+
233270
func TestMiniBlocksSelectionSession_AddReferencedMetaBlock(t *testing.T) {
234271
t.Parallel()
235272

process/block/metablockProposal.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,6 @@ func (mp *metaProcessor) CreateBlockProposal(
170170
return nil, nil, err
171171
}
172172

173-
txsInExecutionResults, err := getTxCountExecutionResults(metaHdr)
174-
if err != nil {
175-
return nil, nil, err
176-
}
177-
178-
totalProcessedTxs := getTxCount(shardDataHandlers) + txsInExecutionResults
179-
// TODO: consider if tx count per metablock header is still needed
180-
// as we still have it in the execution results
181-
err = metaHdr.SetTxCount(totalProcessedTxs)
182-
if err != nil {
183-
return nil, nil, err
184-
}
185-
186173
marshalledBody, err := mp.marshalizer.Marshal(body)
187174
if err != nil {
188175
return nil, nil, err

0 commit comments

Comments
 (0)