-
Notifications
You must be signed in to change notification settings - Fork 226
Fixes api block #7797
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
base: feat/supernova-async-exec
Are you sure you want to change the base?
Fixes api block #7797
Changes from 2 commits
601eece
71ff436
415cacd
051f3df
5618527
b3b2757
b542cf9
225c731
839cef7
37ff483
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |||||
|
|
||||||
| "github.com/multiversx/mx-chain-core-go/core" | ||||||
| apiBlock "github.com/multiversx/mx-chain-core-go/data/api" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/block" | ||||||
| "github.com/multiversx/mx-chain-core-go/data/transaction" | ||||||
| "github.com/stretchr/testify/assert" | ||||||
| "github.com/stretchr/testify/require" | ||||||
|
|
@@ -585,6 +586,96 @@ func TestSimulator_SendTransactions(t *testing.T) { | |||||
| chainSimulatorCommon.CheckGenerateTransactions(t, chainSimulator) | ||||||
| } | ||||||
|
|
||||||
| func TestSimilator_MoveBalanceCheckReceipt(t *testing.T) { | ||||||
|
||||||
| func TestSimilator_MoveBalanceCheckReceipt(t *testing.T) { | |
| func TestSimulator_MoveBalanceCheckReceipt(t *testing.T) { |
Outdated
Copilot
AI
Mar 23, 2026
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.
Inside checkReceipts, assertions mostly use the te parameter, but the final assertion uses the outer t (require.True(t, called)). This can report failures on the wrong *testing.T (especially if this helper is reused in subtests). Use te consistently for all assertions in this helper.
| require.True(t, called) | |
| require.True(te, called) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,12 +63,13 @@ type baseAPIBlockProcessor struct { | |||||||||||||||||||||
| enableEpochsHandler common.EnableEpochsHandler | ||||||||||||||||||||||
| proofsPool dataRetriever.ProofsPool | ||||||||||||||||||||||
| blockchain data.ChainHandler | ||||||||||||||||||||||
| enableRoundsHandler common.EnableRoundsHandler | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var log = logger.GetOrCreate("node/blockAPI") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (bap *baseAPIBlockProcessor) getIntrashardMiniblocksFromReceiptsStorage(header data.HeaderHandler, headerHash []byte, options api.BlockQueryOptions) ([]*api.MiniBlock, error) { | ||||||||||||||||||||||
| receiptsHolder, err := bap.receiptsRepository.LoadReceipts(header, headerHash) | ||||||||||||||||||||||
| func (bap *baseAPIBlockProcessor) getIntrashardMiniblocksFromReceiptsStorage(receiptsHash []byte, header data.HeaderHandler, headerHash []byte, options api.BlockQueryOptions) ([]*api.MiniBlock, error) { | ||||||||||||||||||||||
| receiptsHolder, err := bap.receiptsRepository.LoadReceipts(receiptsHash, header, headerHash) | ||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -234,7 +235,7 @@ func (bap *baseAPIBlockProcessor) getAndAttachTxsToMbByEpoch( | |||||||||||||||||||||
| case block.InvalidBlock: | ||||||||||||||||||||||
| apiMiniblock.Transactions, err = bap.getTxsFromMiniblock(miniBlock, miniblockHash, header, transaction.TxTypeInvalid, dataRetriever.TransactionUnit, firstProcessedTxIndex, lastProcessedTxIndex) | ||||||||||||||||||||||
| case block.ReceiptBlock: | ||||||||||||||||||||||
| apiMiniblock.Receipts, err = bap.getReceiptsFromMiniblock(miniBlock, header.GetEpoch()) | ||||||||||||||||||||||
| apiMiniblock.Receipts, err = bap.getReceiptsFromMiniblock(miniBlock, header.GetEpoch(), header.GetRound()) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||
|
|
@@ -251,8 +252,16 @@ func (bap *baseAPIBlockProcessor) getAndAttachTxsToMbByEpoch( | |||||||||||||||||||||
| return nil | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (bap *baseAPIBlockProcessor) getReceiptsFromMiniblock(miniblock *block.MiniBlock, epoch uint32) ([]*transaction.ApiReceipt, error) { | ||||||||||||||||||||||
| storer, err := bap.store.GetStorer(dataRetriever.UnsignedTransactionUnit) | ||||||||||||||||||||||
| func (bap *baseAPIBlockProcessor) getReceiptsStorerUnitType(round uint64) dataRetriever.UnitType { | ||||||||||||||||||||||
| if bap.enableRoundsHandler.IsFlagEnabledInRound(common.SupernovaRoundFlag, round) { | ||||||||||||||||||||||
| return dataRetriever.ReceiptsUnit | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return dataRetriever.UnsignedTransactionUnit | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (bap *baseAPIBlockProcessor) getReceiptsFromMiniblock(miniblock *block.MiniBlock, epoch uint32, round uint64) ([]*transaction.ApiReceipt, error) { | ||||||||||||||||||||||
| unit := bap.getReceiptsStorerUnitType(round) | ||||||||||||||||||||||
| storer, err := bap.store.GetStorer(unit) | ||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -757,7 +766,8 @@ func (bap *baseAPIBlockProcessor) addMbsAndNumTxsAsyncExecution(apiBlock *api.Bl | |||||||||||||||||||||
| mbsBeforeExecutionAndCleanup := removeExecutedTxsFromMbs(mbsBeforeExecution, executedTxsMap) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| allMbs := append(mbsBeforeExecutionAndCleanup, mbsAfterExecution...) | ||||||||||||||||||||||
| intraMb, err := bap.getIntrashardMiniblocksFromReceiptsStorage(blockHeader, headerHash, options) | ||||||||||||||||||||||
| receiptsHash := executionResultHandler.GetReceiptsHash() | ||||||||||||||||||||||
|
||||||||||||||||||||||
| receiptsHash := executionResultHandler.GetReceiptsHash() | |
| receiptsHash := executionResultHandler.GetReceiptsHash() | |
| if len(receiptsHash) == 0 { | |
| // Fallback to the block header receipts hash for older/default async results | |
| receiptsHash = blockHeader.GetReceiptsHash() | |
| } | |
| if len(receiptsHash) == 0 { | |
| // If still empty, use the predefined empty receipts hash | |
| receiptsHash = bap.emptyReceiptsHash | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ type ArgAPIBlockProcessor struct { | |||||
| AccountsRepository state.AccountsRepository | ||||||
| ScheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler | ||||||
| EnableEpochsHandler common.EnableEpochsHandler | ||||||
| EnableRoundHandler common.EnableRoundsHandler | ||||||
|
||||||
| EnableRoundHandler common.EnableRoundsHandler | |
| EnableRoundsHandler common.EnableRoundsHandler |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ func newMetaApiBlockProcessor(arg *ArgAPIBlockProcessor, emptyReceiptsHash []byt | |
| enableEpochsHandler: arg.EnableEpochsHandler, | ||
| proofsPool: arg.ProofsPool, | ||
| blockchain: arg.BlockChain, | ||
| enableRoundsHandler: arg.EnableRoundHandler, | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -176,43 +177,6 @@ func (mbp *metaAPIBlockProcessor) convertMetaBlockBytesToAPIBlock(hash []byte, b | |
| return nil, err | ||
| } | ||
|
|
||
| numOfTxs := uint32(0) | ||
| miniblocks := make([]*api.MiniBlock, 0) | ||
| for _, mb := range blockHeader.GetMiniBlockHeaderHandlers() { | ||
| if mb.GetTypeInt32() == int32(block.PeerBlock) { | ||
| continue | ||
| } | ||
|
|
||
| numOfTxs += mb.GetTxCount() | ||
|
|
||
| miniblockAPI := &api.MiniBlock{ | ||
| Hash: hex.EncodeToString(mb.GetHash()), | ||
| Type: block.ProcessingType(mb.GetProcessingType()).String(), | ||
| SourceShard: mb.GetSenderShardID(), | ||
| DestinationShard: mb.GetReceiverShardID(), | ||
| } | ||
| if options.WithTransactions { | ||
| miniBlockCopy := mb | ||
| err = mbp.getAndAttachTxsToMb(miniBlockCopy, blockHeader, miniblockAPI, options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| miniblocks = append(miniblocks, miniblockAPI) | ||
| } | ||
|
|
||
| intraMb, err := mbp.getIntrashardMiniblocksFromReceiptsStorage(blockHeader, hash, options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if len(intraMb) > 0 { | ||
| miniblocks = append(miniblocks, intraMb...) | ||
| } | ||
|
|
||
| miniblocks = filterOutDuplicatedMiniblocks(miniblocks) | ||
|
|
||
| notarizedBlocks := make([]*api.NotarizedBlock, 0, len(blockHeader.GetShardInfoHandlers())) | ||
| for _, shardData := range blockHeader.GetShardInfoHandlers() { | ||
| notarizedBlock := &api.NotarizedBlock{ | ||
|
|
@@ -237,9 +201,7 @@ func (mbp *metaAPIBlockProcessor) convertMetaBlockBytesToAPIBlock(hash []byte, b | |
| Shard: core.MetachainShardId, | ||
| Hash: hex.EncodeToString(hash), | ||
| PrevBlockHash: hex.EncodeToString(blockHeader.GetPrevHash()), | ||
| NumTxs: numOfTxs, | ||
| NotarizedBlocks: notarizedBlocks, | ||
| MiniBlocks: miniblocks, | ||
|
Comment on lines
-240
to
-242
Contributor
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. add activation flag check for this? or maybe better keep it as before, with propored miniblocks and num of txs? |
||
| AccumulatedFees: blockHeader.GetAccumulatedFees().String(), | ||
| DeveloperFees: blockHeader.GetDeveloperFees().String(), | ||
| AccumulatedFeesInEpoch: blockHeader.GetAccumulatedFeesInEpoch().String(), | ||
|
|
@@ -320,7 +282,7 @@ func (mbp *metaAPIBlockProcessor) addMbsAndNumTxsV1(apiBlock *api.Block, blockHe | |
| return err | ||
| } | ||
|
|
||
| intraMb, err := mbp.getIntrashardMiniblocksFromReceiptsStorage(blockHeader, headerHash, options) | ||
| intraMb, err := mbp.getIntrashardMiniblocksFromReceiptsStorage(blockHeader.GetReceiptsHash(), blockHeader, headerHash, options) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ func newShardApiBlockProcessor(arg *ArgAPIBlockProcessor, emptyReceiptsHash []by | |
| enableEpochsHandler: arg.EnableEpochsHandler, | ||
| proofsPool: arg.ProofsPool, | ||
| blockchain: arg.BlockChain, | ||
| enableRoundsHandler: arg.EnableRoundHandler, | ||
| }, | ||
| } | ||
| } | ||
|
|
@@ -178,45 +179,6 @@ func (sbp *shardAPIBlockProcessor) convertShardBlockBytesToAPIBlock(hash []byte, | |
| return nil, err | ||
| } | ||
|
|
||
| numOfTxs := uint32(0) | ||
| miniblocks := make([]*api.MiniBlock, 0) | ||
|
|
||
| for _, mb := range blockHeader.GetMiniBlockHeaderHandlers() { | ||
| if block.Type(mb.GetTypeInt32()) == block.PeerBlock { | ||
| continue | ||
| } | ||
|
|
||
| numOfTxs += mb.GetTxCount() | ||
|
|
||
| miniblockAPI := &api.MiniBlock{ | ||
| Hash: hex.EncodeToString(mb.GetHash()), | ||
| Type: block.Type(mb.GetTypeInt32()).String(), | ||
| SourceShard: mb.GetSenderShardID(), | ||
| DestinationShard: mb.GetReceiverShardID(), | ||
| ProcessingType: block.ProcessingType(mb.GetProcessingType()).String(), | ||
| ConstructionState: block.MiniBlockState(mb.GetConstructionState()).String(), | ||
| IndexOfFirstTxProcessed: mb.GetIndexOfFirstTxProcessed(), | ||
| IndexOfLastTxProcessed: mb.GetIndexOfLastTxProcessed(), | ||
| } | ||
| if options.WithTransactions { | ||
| miniBlockCopy := mb | ||
| err = sbp.getAndAttachTxsToMb(miniBlockCopy, blockHeader, miniblockAPI, options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| miniblocks = append(miniblocks, miniblockAPI) | ||
| } | ||
|
|
||
| intraMb, err := sbp.getIntrashardMiniblocksFromReceiptsStorage(blockHeader, hash, options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| miniblocks = append(miniblocks, intraMb...) | ||
| miniblocks = filterOutDuplicatedMiniblocks(miniblocks) | ||
|
|
||
| timestampSec, timestampMs, err := common.GetHeaderTimestamps(blockHeader, sbp.enableEpochsHandler) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -229,8 +191,6 @@ func (sbp *shardAPIBlockProcessor) convertShardBlockBytesToAPIBlock(hash []byte, | |
| Shard: blockHeader.GetShardID(), | ||
| Hash: hex.EncodeToString(hash), | ||
| PrevBlockHash: hex.EncodeToString(blockHeader.GetPrevHash()), | ||
| NumTxs: numOfTxs, | ||
| MiniBlocks: miniblocks, | ||
|
Comment on lines
-232
to
-233
Contributor
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. same here |
||
| AccumulatedFees: blockHeader.GetAccumulatedFees().String(), | ||
| DeveloperFees: blockHeader.GetDeveloperFees().String(), | ||
| Timestamp: int64(timestampSec), | ||
|
|
@@ -321,7 +281,7 @@ func (sbp *shardAPIBlockProcessor) addMbsAndNumTxsV1(apiBlock *api.Block, blockH | |
| miniblocks = append(miniblocks, miniblockAPI) | ||
| } | ||
|
|
||
| intraMb, err := sbp.getIntrashardMiniblocksFromReceiptsStorage(blockHeader, headerHash, options) | ||
| intraMb, err := sbp.getIntrashardMiniblocksFromReceiptsStorage(blockHeader.GetReceiptsHash(), blockHeader, headerHash, options) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
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.
Simulator instead of Similator
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.
fixed