Skip to content
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

Genesis Hash #12

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
branches:
- main
- develop
- store_int

jobs:
commit-build:
Expand All @@ -27,4 +28,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
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
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;
import org.springframework.context.event.EventListener;
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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public interface GenesisDataService {

@Transactional
void setupData();
void setupData(String genesisHash);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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;
Expand All @@ -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<>())
Expand Down Expand Up @@ -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<String, Object> 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)
Expand All @@ -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())
Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion application/src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 4 additions & 1 deletion config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down