From eba1fad81e9d1c5770218c5a55c155d3c36298be Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 23 Dec 2024 15:51:19 +0200 Subject: [PATCH 1/2] extend /block endpoint --- go.mod | 2 +- go.sum | 4 ++-- node/external/blockAPI/baseBlock.go | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cc5f4259b96..d0690da2d1c 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.1 - github.com/multiversx/mx-chain-core-go v1.2.23 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20241223124350-686902f86816 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.10 github.com/multiversx/mx-chain-logger-go v1.0.15 diff --git a/go.sum b/go.sum index b4ebd7201e0..4ec328ed38e 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= 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.23 h1:8WlCGqJHR2HQ0vN4feJwb7W4VrCwBGIzPPHunOOg5Wc= -github.com/multiversx/mx-chain-core-go v1.2.23/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241223124350-686902f86816 h1:Z4IZQsECQUItUfXc6WMhBYnuYn5HJ+hl1TiDdOY6RpI= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241223124350-686902f86816/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.10 h1:Umi7WN8h4BOXLw7CM3VgvaWkLGef7nXtaPIGbjBCT3U= diff --git a/node/external/blockAPI/baseBlock.go b/node/external/blockAPI/baseBlock.go index 63bfe673f37..df637f338d6 100644 --- a/node/external/blockAPI/baseBlock.go +++ b/node/external/blockAPI/baseBlock.go @@ -125,6 +125,18 @@ func (bap *baseAPIBlockProcessor) getAndAttachTxsToMb( firstProcessed := mbHeader.GetIndexOfFirstTxProcessed() lastProcessed := mbHeader.GetIndexOfLastTxProcessed() + + // When options.ForHyperblock is true, there are two scenarios: + // 1 - If not all transactions were executed, no transactions will be returned. + // 2 - If all transactions were executed, all transactions starting from index 0 will be returned. + if options.ForHyperblock { + allTxsWereExecuted := lastProcessed == int32(len(miniBlock.TxHashes)-1) + if !allTxsWereExecuted { + return nil + } + firstProcessed = 0 + } + return bap.getAndAttachTxsToMbByEpoch(miniblockHash, miniBlock, header, apiMiniblock, firstProcessed, lastProcessed, options) } From 07627b90489a4edde0a460ac8b1c76d9ca7441e5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 9 Jan 2025 11:12:24 +0200 Subject: [PATCH 2/2] extract forHyperblock from block requests --- api/groups/blockGroup.go | 8 +++++++- api/groups/blockGroup_test.go | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/groups/blockGroup.go b/api/groups/blockGroup.go index 26d9c05b000..f9f0ed81fd8 100644 --- a/api/groups/blockGroup.go +++ b/api/groups/blockGroup.go @@ -26,6 +26,7 @@ const ( urlParamTokensFilter = "tokens" urlParamWithTxs = "withTxs" urlParamWithLogs = "withLogs" + urlParamForHyperblock = "forHyperblock" ) // blockFacadeHandler defines the methods to be implemented by a facade for handling block requests @@ -219,7 +220,12 @@ func parseBlockQueryOptions(c *gin.Context) (api.BlockQueryOptions, error) { return api.BlockQueryOptions{}, err } - options := api.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs} + forHyperBlock, err := parseBoolUrlParam(c, urlParamForHyperblock) + if err != nil { + return api.BlockQueryOptions{}, err + } + + options := api.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs, ForHyperblock: forHyperBlock} return options, nil } diff --git a/api/groups/blockGroup_test.go b/api/groups/blockGroup_test.go index b190c2f0561..a2ebc61548b 100644 --- a/api/groups/blockGroup_test.go +++ b/api/groups/blockGroup_test.go @@ -90,7 +90,7 @@ func TestBlockGroup_getBlockByNonce(t *testing.T) { t.Parallel() providedNonce := uint64(37) - expectedOptions := api.BlockQueryOptions{WithTransactions: true} + expectedOptions := api.BlockQueryOptions{WithTransactions: true, ForHyperblock: true} expectedBlock := api.Block{ Nonce: 37, Round: 39, @@ -107,7 +107,7 @@ func TestBlockGroup_getBlockByNonce(t *testing.T) { loadBlockGroupResponse( t, facade, - fmt.Sprintf("/block/by-nonce/%d?withTxs=true", providedNonce), + fmt.Sprintf("/block/by-nonce/%d?withTxs=true&forHyperblock=true", providedNonce), "GET", nil, response,