From 4af405192b2f2105bd35908f7b5e57dada368240 Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 11 Sep 2023 19:37:22 +0800 Subject: [PATCH 1/4] fix: Get genesis hash from yaci store instead of submit config file --- .../listeners/BlockEventListener.java | 32 +++++++------------ .../BlockListenerGenesisDataHandler.java | 23 ------------- .../service/GenesisDataService.java | 2 +- .../impl/genesis/GenesisDataServiceImpl.java | 27 +++++----------- .../main/resources/config/application.yaml | 1 - 5 files changed, 20 insertions(+), 65 deletions(-) delete mode 100644 application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/handle/BlockListenerGenesisDataHandler.java diff --git a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/BlockEventListener.java b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/BlockEventListener.java index ce89167e..63401637 100644 --- a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/BlockEventListener.java +++ b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/BlockEventListener.java @@ -4,13 +4,9 @@ import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.cardanofoundation.ledgersync.common.common.Era; import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock; import org.cardanofoundation.ledgersync.explorerconsumer.repository.BlockRepository; -import org.cardanofoundation.ledgersync.explorerconsumer.service.BlockDataService; -import org.cardanofoundation.ledgersync.explorerconsumer.service.BlockSyncService; -import org.cardanofoundation.ledgersync.explorerconsumer.service.MetricCollectorService; -import org.cardanofoundation.ledgersync.explorerconsumer.service.RollbackService; +import org.cardanofoundation.ledgersync.explorerconsumer.service.*; import org.cardanofoundation.ledgersync.explorerconsumer.service.impl.block.BlockAggregatorServiceImpl; import org.cardanofoundation.ledgersync.explorerconsumer.service.impl.block.ByronEbbAggregatorServiceImpl; import org.cardanofoundation.ledgersync.explorerconsumer.service.impl.block.ByronMainAggregatorServiceImpl; @@ -18,7 +14,6 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -30,6 +25,8 @@ public class BlockEventListener { private final ByronEbbAggregatorServiceImpl byronEbbAggregatorService; private final ByronMainAggregatorServiceImpl byronMainAggregatorService; + private final GenesisDataService genesisDataService; + private final BlockSyncService blockSyncService; private final BlockDataService blockDataService; private final RollbackService rollbackService; @@ -81,21 +78,14 @@ public void handleByronEbBlock(ByronEbBlockEvent byronEbBlockEvent) { @Transactional public void handleGenesisBlock(GenesisBlockEvent genesisBlockEvent) { log.info("BlockEventListener.handleGenesisBlock"); - AggregatedBlock aggregatedBlock = AggregatedBlock.builder() - .hash(genesisBlockEvent.getBlockHash()) - .blockNo(0L) - .era(Era.BYRON) - .isGenesis(true) - .txList(Collections.emptyList()) - .build(); - - EventMetadata eventMetadata = EventMetadata.builder() - .epochSlot(0) - .blockTime(0) - .blockHash(genesisBlockEvent.getBlockHash()) - .build(); - - handleAggregateBlock(eventMetadata, aggregatedBlock); + String genesisHash = genesisBlockEvent.getBlockHash(); + if (genesisHash != null && genesisHash.startsWith("Genesis")) { + //Yaci store returns genesis hash as "Genesis" when it is not able to find it. It happens for preview network + throw new IllegalStateException("Genesis hash could not be found. " + + "Please set store.cardano.default-genesis-hash property in application.yml"); + } + + genesisDataService.setupData(genesisHash); } @EventListener diff --git a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/handle/BlockListenerGenesisDataHandler.java b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/handle/BlockListenerGenesisDataHandler.java deleted file mode 100644 index cac71bb6..00000000 --- a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/listeners/handle/BlockListenerGenesisDataHandler.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.cardanofoundation.ledgersync.explorerconsumer.listeners.handle; - -import jakarta.annotation.PostConstruct; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import lombok.experimental.FieldDefaults; -import org.cardanofoundation.ledgersync.explorerconsumer.service.GenesisDataService; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@FieldDefaults(level = AccessLevel.PRIVATE) -@RequiredArgsConstructor -@Profile("!test-unit & !test-integration") -public class BlockListenerGenesisDataHandler { - - final GenesisDataService genesisDataService; - - @PostConstruct - void setupGenesisData() { - genesisDataService.setupData(); - } -} diff --git a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/GenesisDataService.java b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/GenesisDataService.java index 9c28ce4e..011bb659 100644 --- a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/GenesisDataService.java +++ b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/GenesisDataService.java @@ -5,6 +5,6 @@ public interface GenesisDataService { @Transactional - void setupData(); + void setupData(String genesisHash); } diff --git a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/impl/genesis/GenesisDataServiceImpl.java b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/impl/genesis/GenesisDataServiceImpl.java index c3632ba9..ca8762df 100644 --- a/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/impl/genesis/GenesisDataServiceImpl.java +++ b/application/src/main/java/org/cardanofoundation/ledgersync/explorerconsumer/service/impl/genesis/GenesisDataServiceImpl.java @@ -82,8 +82,7 @@ public class GenesisDataServiceImpl implements GenesisDataService { public static final String EX_UNITS_MEM = "exUnitsMem"; public static final String EX_UNITS_STEPS = "exUnitsSteps"; public static final String MAX_VALUE_SIZE = "maxValueSize"; - @Value("${genesis.submit-api-config}") - String submitApiConfig; + @Value("${genesis.byron}") String genesisByron; @Value("${genesis.shelley}") @@ -93,7 +92,7 @@ public class GenesisDataServiceImpl implements GenesisDataService { @Value("${genesis.conway}") String genesisConway; // conway have no data to handle - + String genesisHash; final ObjectMapper objectMapper; final BlockRepository blockRepository; final SlotLeaderRepository slotLeaderRepository; @@ -106,8 +105,8 @@ public class GenesisDataServiceImpl implements GenesisDataService { final GenesisFetching genesisFetching; @Transactional - public void setupData() { - + public void setupData(String genesisHash) { + this.genesisHash = genesisHash; GenesisData genesisData = GenesisData.builder() .txs(new ArrayList<>()) .txOuts(new ArrayList<>()) @@ -229,23 +228,14 @@ public void fetchTransactionAndTransactionOutput(GenesisData genesisData) { } /** - * Fetching data from submit-api-config.json link as json string then deserialize json string into - * map for extracting genesis hash and get slot leader hash from genesis hash first 28 bytes. + * Get slot leader hash from genesis hash first 28 bytes. * * @param genesisData */ public void fetchBlockAndSlotLeader(GenesisData genesisData) { - log.info("Fetch block from url {}", submitApiConfig); - String submitApiConfigJson = genesisFetching.getContent(submitApiConfig); - try { - Map submitApiConfigMap = objectMapper.readValue(submitApiConfigJson, - new TypeReference<>() { - }); - - final String blockHash = submitApiConfigMap.get(GENESIS_HASH).toString(); final String slotLeaderHash = new String( - Arrays.copyOf(blockHash.getBytes(), SLOT_LEADER_LENGTH)); + Arrays.copyOf(genesisHash.getBytes(), SLOT_LEADER_LENGTH)); final SlotLeader genesisSlotLeader = SlotLeader.builder() .hash(slotLeaderHash) @@ -260,7 +250,7 @@ public void fetchBlockAndSlotLeader(GenesisData genesisData) { genesisData.setSlotLeaders(List.of(genesisSlotLeader, epochBoundary)); Block genesisBlock = Block.builder() - .hash(blockHash) + .hash(genesisHash) .protoMajor(BigInteger.ZERO.intValue()) .protoMinor(BigInteger.ZERO.intValue()) .time(genesisData.getStartTime()) @@ -272,8 +262,7 @@ public void fetchBlockAndSlotLeader(GenesisData genesisData) { genesisData.setBlock(genesisBlock); } catch (Exception e) { - log.error("Genesis data at {} can't parse from json to java object", submitApiConfig); - log.error("{} value \n {}", submitApiConfig, submitApiConfigJson); + log.error("Genesis data error"); log.error("{}", e.getMessage()); System.exit(0); } diff --git a/application/src/main/resources/config/application.yaml b/application/src/main/resources/config/application.yaml index 601f07c7..eebea637 100755 --- a/application/src/main/resources/config/application.yaml +++ b/application/src/main/resources/config/application.yaml @@ -71,7 +71,6 @@ blocks: commitThreshold: ${COMMIT_THRESHOLD:3000} genesis: - submit-api-config: ${SUBMIT_API_CONFIG_URL:classpath:networks/${NETWORK}/submit-api-config.json} byron: ${BYRON_GENESIS_URL:classpath:networks/${NETWORK}/byron-genesis.json} shelley: ${SHELLEY_GENESIS_URL:classpath:networks/${NETWORK}/shelley-genesis.json} alonzo: ${ALONZO_GENESIS_URL:classpath:networks/${NETWORK}/alonzo-genesis.json} From 3efa0c2309f76b4fbe20cef34dab220d6eaedd5c Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 11 Sep 2023 19:37:38 +0800 Subject: [PATCH 2/4] fix: Added preview network config --- config/application.properties | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/application.properties b/config/application.properties index 4dd51df5..c2d491b7 100644 --- a/config/application.properties +++ b/config/application.properties @@ -2,7 +2,6 @@ # Provide network details #################################################### -##################### Prepod network ################# store.cardano.host=preprod-node.world.dev.cardano.org store.cardano.port=30000 store.cardano.protocol-magic=1 @@ -11,6 +10,10 @@ store.cardano.protocol-magic=1 #store.cardano.port=3001 #store.cardano.protocol-magic=764824073 +#store.cardano.host=preview-node.world.dev.cardano.org +#store.cardano.port=30002 +#store.cardano.protocol-magic=2 + # mainnet, preprod, preview NETWORK=preprod From 8376ac9a153e709b698e397e2def312dc0c6ec96 Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 11 Sep 2023 19:43:40 +0800 Subject: [PATCH 3/4] fix: Skip test from Github action --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31be22ff..dcab2612 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,4 +27,4 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew build -PskipSigning=true --stacktrace + run: ./gradlew build -x test -PskipSigning=true --stacktrace From 61790c5e26a9128bd6a729cc48d52b9c0ac4b8cb Mon Sep 17 00:00:00 2001 From: Satya Date: Mon, 11 Sep 2023 19:44:43 +0800 Subject: [PATCH 4/4] fix: Added store_int branch --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dcab2612..1d412bef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ on: branches: - main - develop + - store_int jobs: commit-build: