Search in sources :

Example 16 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class BlockNumberMigrationTest method ifBlockNumberIsAlreadyCorrectDoNothing.

@Test
void ifBlockNumberIsAlreadyCorrectDoNothing() {
    List<Tuple> expectedBlockNumbersAndConsensusEnd = insertDefaultRecordFiles(Set.of(CORRECT_CONSENSUS_END)).stream().map(recordFile -> Tuple.tuple(recordFile.getConsensusEnd(), recordFile.getIndex())).collect(Collectors.toList());
    final RecordFile targetRecordFile = domainBuilder.recordFile().customize(builder -> builder.consensusEnd(CORRECT_CONSENSUS_END).index(CORRECT_BLOCK_NUMBER)).persist();
    expectedBlockNumbersAndConsensusEnd.add(Tuple.tuple(targetRecordFile.getConsensusEnd(), targetRecordFile.getIndex()));
    blockNumberMigration.doMigrate();
    assertConsensusEndAndBlockNumber(expectedBlockNumbersAndConsensusEnd);
}
Also used : Tuple(org.assertj.core.groups.Tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) BLOCK_NUMBER_MAPPING(com.hedera.mirror.importer.migration.BlockNumberMigration.BLOCK_NUMBER_MAPPING) Collectors(java.util.stream.Collectors) PREVIEWNET(com.hedera.mirror.importer.MirrorProperties.HederaNetwork.PREVIEWNET) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) List(java.util.List) MirrorProperties(com.hedera.mirror.importer.MirrorProperties) RecordFileRepository(com.hedera.mirror.importer.repository.RecordFileRepository) TESTNET(com.hedera.mirror.importer.MirrorProperties.HederaNetwork.TESTNET) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Tag(org.junit.jupiter.api.Tag) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 17 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class BlockNumberMigrationTest method insertDefaultRecordFiles.

private List<RecordFile> insertDefaultRecordFiles(Set<Long> skipRecordFileWithConsensusEnd) {
    long[] consensusEnd = { 1570800761443132000L, CORRECT_CONSENSUS_END, 1570801906238879002L };
    long[] blockNumber = { 0L, 8L, 9L };
    var recordFiles = new ArrayList<RecordFile>(consensusEnd.length);
    for (int i = 0; i < consensusEnd.length; i++) {
        if (skipRecordFileWithConsensusEnd.contains(consensusEnd[i])) {
            continue;
        }
        final long currConsensusEnd = consensusEnd[i];
        final long currBlockNumber = blockNumber[i];
        RecordFile recordFile = domainBuilder.recordFile().customize(builder -> builder.consensusEnd(currConsensusEnd).index(currBlockNumber)).persist();
        recordFiles.add(recordFile);
    }
    return recordFiles;
}
Also used : Tuple(org.assertj.core.groups.Tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) BLOCK_NUMBER_MAPPING(com.hedera.mirror.importer.migration.BlockNumberMigration.BLOCK_NUMBER_MAPPING) Collectors(java.util.stream.Collectors) PREVIEWNET(com.hedera.mirror.importer.MirrorProperties.HederaNetwork.PREVIEWNET) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) List(java.util.List) MirrorProperties(com.hedera.mirror.importer.MirrorProperties) RecordFileRepository(com.hedera.mirror.importer.repository.RecordFileRepository) TESTNET(com.hedera.mirror.importer.MirrorProperties.HederaNetwork.TESTNET) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Tag(org.junit.jupiter.api.Tag) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ArrayList(java.util.ArrayList)

Example 18 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class AbstractDownloaderTest method differentFilenames.

private void differentFilenames(Duration offset) throws Exception {
    mirrorProperties.setStartBlockNumber(null);
    // Copy all files and modify only node 0.0.3's files to have a different timestamp
    fileCopier.filterFiles(file2 + "*").copy();
    Path basePath = fileCopier.getTo().resolve(streamType.getNodePrefix() + "0.0.3");
    // Construct a new filename with the offset added to the last valid file
    long nanoOffset = getCloseInterval().plus(offset).toNanos();
    Instant instant = file1Instant.plusNanos(nanoOffset);
    // Rename the good files to have a bad timestamp
    String data = StreamFilename.getFilename(streamType, DATA, instant);
    String signature = StreamFilename.getFilename(streamType, SIGNATURE, instant);
    Files.move(basePath.resolve(file2), basePath.resolve(data));
    Files.move(basePath.resolve(file2 + "_sig"), basePath.resolve(signature));
    RecordFile recordFile = new RecordFile();
    recordFile.setName(file1);
    expectLastStreamFile(Instant.EPOCH);
    downloader.download();
    verifyStreamFiles(List.of(file2));
}
Also used : Path(java.nio.file.Path) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Instant(java.time.Instant)

Example 19 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class RecordFileV5DownloaderTest method getRecordFileMap.

@Override
protected Map<String, RecordFile> getRecordFileMap() {
    Map<String, RecordFile> allRecordFileMap = TestRecordFiles.getAll();
    RecordFile recordFile1 = allRecordFileMap.get("2021-01-11T22_09_24.063739000Z.rcd");
    RecordFile recordFile2 = allRecordFileMap.get("2021-01-11T22_09_34.097416003Z.rcd");
    return Map.of(recordFile1.getName(), recordFile1, recordFile2.getName(), recordFile2);
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile)

Example 20 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class RecordFileReaderImplV5 method read.

@Override
public RecordFile read(StreamFileData streamFileData) {
    MessageDigest messageDigestFile = createMessageDigest(DIGEST_ALGORITHM);
    MessageDigest messageDigestMetadata = createMessageDigest(DIGEST_ALGORITHM);
    String filename = streamFileData.getFilename();
    // first DigestInputStream is needed to avoid digesting some class ID fields twice.
    try (DigestInputStream digestInputStream = new DigestInputStream(new BufferedInputStream(new DigestInputStream(streamFileData.getInputStream(), messageDigestFile)), messageDigestMetadata);
        ValidatedDataInputStream vdis = new ValidatedDataInputStream(digestInputStream, filename)) {
        RecordFile recordFile = new RecordFile();
        recordFile.setBytes(streamFileData.getBytes());
        recordFile.setDigestAlgorithm(DIGEST_ALGORITHM);
        recordFile.setLoadStart(Instant.now().getEpochSecond());
        recordFile.setName(filename);
        readHeader(vdis, recordFile);
        readBody(vdis, digestInputStream, recordFile);
        recordFile.setFileHash(Hex.encodeHexString(messageDigestFile.digest()));
        recordFile.setMetadataHash(Hex.encodeHexString(messageDigestMetadata.digest()));
        return recordFile;
    } catch (IOException e) {
        throw new StreamFileReaderException("Error reading record file " + filename, e);
    }
}
Also used : DigestInputStream(java.security.DigestInputStream) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) BufferedInputStream(java.io.BufferedInputStream) ValidatedDataInputStream(com.hedera.mirror.importer.reader.ValidatedDataInputStream) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest)

Aggregations

RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)33 Test (org.junit.jupiter.api.Test)9 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)8 Instant (java.time.Instant)5 ByteString (com.google.protobuf.ByteString)4 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)3 StreamFileReaderException (com.hedera.mirror.importer.exception.StreamFileReaderException)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 RequiredArgsConstructor (lombok.RequiredArgsConstructor)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 TestFactory (org.junit.jupiter.api.TestFactory)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MirrorProperties (com.hedera.mirror.importer.MirrorProperties)2 PREVIEWNET (com.hedera.mirror.importer.MirrorProperties.HederaNetwork.PREVIEWNET)2 TESTNET (com.hedera.mirror.importer.MirrorProperties.HederaNetwork.TESTNET)2