-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve requesting of missing mini blocks dest me #5176
Changes from 7 commits
8386818
0fe5f12
e9c70a3
6cee2bf
80506b2
b6b7a79
58471d7
6a58519
25b4247
df85f69
c8d11af
3be0203
fb2d97d
c2221e4
de19299
fcb9359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ type transactionCoordinator struct { | |
mutRequestedTxs sync.RWMutex | ||
requestedTxs map[block.Type]int | ||
|
||
onRequestMiniBlock func(shardId uint32, mbHash []byte) | ||
onRequestMiniBlocks func(shardId uint32, mbHashes [][]byte) | ||
gasHandler process.GasHandler | ||
feeHandler process.TransactionFeeHandler | ||
blockSizeComputation preprocess.BlockSizeComputationHandler | ||
|
@@ -126,7 +126,7 @@ func NewTransactionCoordinator(args ArgTransactionCoordinator) (*transactionCoor | |
} | ||
|
||
tc.miniBlockPool = args.MiniBlockPool | ||
tc.onRequestMiniBlock = args.RequestHandler.RequestMiniBlock | ||
tc.onRequestMiniBlocks = args.RequestHandler.RequestMiniBlocks | ||
tc.requestedTxs = make(map[block.Type]int) | ||
tc.txPreProcessors = make(map[block.Type]process.PreProcessor) | ||
tc.interimProcessors = make(map[block.Type]process.IntermediateTransactionHandler) | ||
|
@@ -604,6 +604,8 @@ func (tc *transactionCoordinator) CreateMbsAndProcessCrossShardTransactionsDstMe | |
"total gas penalized", tc.gasHandler.TotalGasPenalized()) | ||
}() | ||
|
||
tc.requestMissingMiniBlocks(finalCrossMiniBlockInfos) | ||
|
||
for _, miniBlockInfo := range finalCrossMiniBlockInfos { | ||
if !haveTime() && !haveAdditionalTime() { | ||
log.Debug("CreateMbsAndProcessCrossShardTransactionsDstMe", | ||
|
@@ -643,7 +645,6 @@ func (tc *transactionCoordinator) CreateMbsAndProcessCrossShardTransactionsDstMe | |
|
||
miniVal, _ := tc.miniBlockPool.Peek(miniBlockInfo.Hash) | ||
if miniVal == nil { | ||
go tc.onRequestMiniBlock(miniBlockInfo.SenderShardID, miniBlockInfo.Hash) | ||
shouldSkipShard[miniBlockInfo.SenderShardID] = true | ||
log.Trace("transactionCoordinator.CreateMbsAndProcessCrossShardTransactionsDstMe: mini block not found and was requested", | ||
"scheduled mode", scheduledMode, | ||
|
@@ -748,6 +749,29 @@ func (tc *transactionCoordinator) CreateMbsAndProcessCrossShardTransactionsDstMe | |
return createMBDestMeExecutionInfo.miniBlocks, createMBDestMeExecutionInfo.numTxAdded, allMBsProcessed, nil | ||
} | ||
|
||
func (tc *transactionCoordinator) requestMissingMiniBlocks(mbsInfo []*data.MiniBlockInfo) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. functionality of requestMissingMiniBlocks and RequestMiniBlocks is very similar, could the refactored with a method that gets a list of miniblockHashes and does the request for those and be called from both other methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, will do this refactor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
mapMissingMiniBlocksPerShard := make(map[uint32][][]byte) | ||
|
||
tc.requestedItemsHandler.Sweep() | ||
|
||
for _, mbInfo := range mbsInfo { | ||
_, isMiniBlockFound := tc.miniBlockPool.Peek(mbInfo.Hash) | ||
if !isMiniBlockFound { | ||
log.Debug("transactionCoordinator.requestMissingMiniBlocks: mini block not found and was requested", | ||
"sender shard", mbInfo.SenderShardID, | ||
"hash", mbInfo.Hash, | ||
"round", mbInfo.Round, | ||
) | ||
mapMissingMiniBlocksPerShard[mbInfo.SenderShardID] = append(mapMissingMiniBlocksPerShard[mbInfo.SenderShardID], mbInfo.Hash) | ||
_ = tc.requestedItemsHandler.Add(string(mbInfo.Hash)) | ||
} | ||
} | ||
|
||
for senderShardID, mbsHashes := range mapMissingMiniBlocksPerShard { | ||
go tc.onRequestMiniBlocks(senderShardID, mbsHashes) | ||
} | ||
} | ||
|
||
func initMiniBlockDestMeExecutionInfo() *createMiniBlockDestMeExecutionInfo { | ||
return &createMiniBlockDestMeExecutionInfo{ | ||
processedTxHashes: make([][]byte, 0), | ||
|
@@ -1084,14 +1108,24 @@ func (tc *transactionCoordinator) RequestMiniBlocks(header data.HeaderHandler) { | |
|
||
tc.requestedItemsHandler.Sweep() | ||
|
||
mapMissingMiniBlocksPerShard := make(map[uint32][][]byte) | ||
finalCrossMiniBlockHashes := tc.getFinalCrossMiniBlockHashes(header) | ||
for key, senderShardId := range finalCrossMiniBlockHashes { | ||
obj, _ := tc.miniBlockPool.Peek([]byte(key)) | ||
if obj == nil { | ||
go tc.onRequestMiniBlock(senderShardId, []byte(key)) | ||
_, isMiniBlockFound := tc.miniBlockPool.Peek([]byte(key)) | ||
if !isMiniBlockFound { | ||
log.Debug("transactionCoordinator.RequestMiniBlocks: mini block not found and was requested", | ||
"sender shard", senderShardId, | ||
"hash", []byte(key), | ||
"round", header.GetRound(), | ||
) | ||
mapMissingMiniBlocksPerShard[senderShardId] = append(mapMissingMiniBlocksPerShard[senderShardId], []byte(key)) | ||
_ = tc.requestedItemsHandler.Add(key) | ||
} | ||
} | ||
|
||
for senderShardID, mbsHashes := range mapMissingMiniBlocksPerShard { | ||
go tc.onRequestMiniBlocks(senderShardID, mbsHashes) | ||
} | ||
} | ||
|
||
func (tc *transactionCoordinator) getFinalCrossMiniBlockHashes(headerHandler data.HeaderHandler) map[string]uint32 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one other problem is to stop requesting transactions after the first miniblock where there are requestedTxs (line 689):
if requestedTxs > 0 { shouldSkipShard[miniBlockInfo.SenderShardID] = true
The requests could be done for all the miniblocks that could be processed in a round.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this is solved with this new approach by calling requestMissingMiniBlocks above. For all these mbs requested in this method, once they will be received in L1138 -> method func (tc *transactionCoordinator) receivedMiniBlock(key []byte, value interface{}) we will finally know all the tx hashes and request them if missing in L1162 -> numTxsRequested := preproc.RequestTransactionsForMiniBlock(miniBlock). Actually you cannot request txs for the missing mbs as you don't know their hashes. But I can add the txs request for all the miniblocks which are not missing in the same method -> requestMissingMiniBlocks.