Search in sources :

Example 11 with ContractKey

use of com.hedera.services.state.virtual.ContractKey in project hedera-services by hashgraph.

the class AddBench method add500Leaves.

@Benchmark
public void add500Leaves(DatabaseMergingState databaseState) throws IOException {
    final long firstLeafPath = databaseState.dataSource.getFirstLeafPath();
    final long lastLeafPath = databaseState.dataSource.getLastLeafPath();
    final long newFirstLeafPath = firstLeafPath + NUMBER_OF_LEAVES_ADDED_PER_FLUSH;
    final long newLastLeafPath = lastLeafPath + NUMBER_OF_LEAVES_ADDED_PER_FLUSH + NUMBER_OF_LEAVES_ADDED_PER_FLUSH;
    var internalRecordStream = LongStream.range(firstLeafPath, newFirstLeafPath).mapToObj(path -> new VirtualInternalRecord(path, hash((int) path)));
    var leafRecordStream = LongStream.range(lastLeafPath, newLastLeafPath + 1).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path)));
    databaseState.dataSource.saveRecords(newFirstLeafPath, newLastLeafPath, internalRecordStream, leafRecordStream, Stream.empty());
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 12 with ContractKey

use of com.hedera.services.state.virtual.ContractKey in project hedera-services by hashgraph.

the class DatabaseState method setupDatabase.

@Setup(Level.Trial)
public void setupDatabase() throws IOException {
    System.out.println("dataSourcePath = " + dataSourcePath + " mergingEnabled=" + mergingEnabled);
    if (Files.exists(dataSourcePath)) {
        System.err.println("!!!!!!!!!!!!! Deleting old db.");
        deleteDirectoryAndContents(dataSourcePath);
    }
    if (Files.exists(dataSourceSnapshotPath)) {
        System.err.println("!!!!!!!!!!!!! Deleting old db snapshot.");
        deleteDirectoryAndContents(dataSourceSnapshotPath);
    }
    // create data source
    VirtualLeafRecordSerializer<ContractKey, ContractValue> virtualLeafRecordSerializer = new VirtualLeafRecordSerializer<>((short) 1, DigestType.SHA_384, (short) 1, DataFileCommon.VARIABLE_DATA_SIZE, new ContractKeySupplier(), (short) 1, ContractValue.SERIALIZED_SIZE, new ContractValueSupplier(), true);
    JasperDbBuilder<ContractKey, ContractValue> dbBuilder = new JasperDbBuilder<>();
    dbBuilder.virtualLeafRecordSerializer(virtualLeafRecordSerializer).virtualInternalRecordSerializer(new VirtualInternalRecordSerializer()).keySerializer(new ContractKeySerializer()).storageDir(dataSourcePath).maxNumOfKeys(500_000_000).preferDiskBasedIndexes(false).internalHashesRamToDiskThreshold(0).mergingEnabled(mergingEnabled);
    dataSource = dbBuilder.build("jdb", "4dbState");
    // populate with initial data
    System.out.printf("Creating initial data set of %,d leaves\n", initialDataSize);
    progressPercentage = 0;
    final long firstLeafPath = initialDataSize;
    final long lastLeafPath = firstLeafPath + initialDataSize;
    var internalRecordStream = LongStream.range(0, firstLeafPath).mapToObj(path -> new VirtualInternalRecord(path, hash((int) path))).peek(internalRecord -> printProgress(internalRecord.getPath(), lastLeafPath));
    var leafRecordStream = LongStream.range(firstLeafPath, lastLeafPath + 1).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path))).peek(leaf -> printProgress(leaf.getPath(), lastLeafPath));
    dataSource.saveRecords(firstLeafPath, lastLeafPath, internalRecordStream, leafRecordStream, Stream.empty());
    System.out.printf("Done creating initial data set of %,d leaves\n", initialDataSize);
}
Also used : ContractValueSupplier(com.hedera.services.state.virtual.ContractValueSupplier) JasperDbBuilder(com.swirlds.jasperdb.JasperDbBuilder) ContractKey(com.hedera.services.state.virtual.ContractKey) VirtualInternalRecordSerializer(com.swirlds.jasperdb.VirtualInternalRecordSerializer) CommonTestUtils.deleteDirectoryAndContents(utils.CommonTestUtils.deleteDirectoryAndContents) VirtualLeafRecordSerializer(com.swirlds.jasperdb.VirtualLeafRecordSerializer) DataFileCommon(com.swirlds.jasperdb.files.DataFileCommon) Scope(org.openjdk.jmh.annotations.Scope) ContractKeySupplier(com.hedera.services.state.virtual.ContractKeySupplier) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) Path(java.nio.file.Path) CommonTestUtils.hash(utils.CommonTestUtils.hash) Setup(org.openjdk.jmh.annotations.Setup) LongStream(java.util.stream.LongStream) VirtualDataSourceJasperDB(com.swirlds.jasperdb.VirtualDataSourceJasperDB) Files(java.nio.file.Files) ContractValue(com.hedera.services.state.virtual.ContractValue) Param(org.openjdk.jmh.annotations.Param) IOException(java.io.IOException) State(org.openjdk.jmh.annotations.State) DigestType(com.swirlds.common.crypto.DigestType) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) Stream(java.util.stream.Stream) Level(org.openjdk.jmh.annotations.Level) ContractKeySerializer(com.hedera.services.state.virtual.ContractKeySerializer) VirtualLeafRecordSerializer(com.swirlds.jasperdb.VirtualLeafRecordSerializer) JasperDbBuilder(com.swirlds.jasperdb.JasperDbBuilder) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) ContractValueSupplier(com.hedera.services.state.virtual.ContractValueSupplier) VirtualInternalRecordSerializer(com.swirlds.jasperdb.VirtualInternalRecordSerializer) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) ContractKeySerializer(com.hedera.services.state.virtual.ContractKeySerializer) ContractKeySupplier(com.hedera.services.state.virtual.ContractKeySupplier) Setup(org.openjdk.jmh.annotations.Setup)

Example 13 with ContractKey

use of com.hedera.services.state.virtual.ContractKey in project hedera-services by hashgraph.

the class StaticEntityAccess method getStorage.

@Override
public UInt256 getStorage(AccountID id, UInt256 key) {
    final var contractKey = new ContractKey(id.getAccountNum(), key.toArray());
    ContractValue value = storage.get(contractKey);
    return value == null ? UInt256.ZERO : UInt256.fromBytes(Bytes32.wrap(value.getValue()));
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey)

Example 14 with ContractKey

use of com.hedera.services.state.virtual.ContractKey in project hedera-services by hashgraph.

the class StateViewTest method setup.

@BeforeEach
@SuppressWarnings("unchecked")
private void setup() throws Throwable {
    metadata = new HFileMeta(false, TxnHandlingScenario.MISC_FILE_WACL_KT.asJKey(), expiry, fileMemo);
    immutableMetadata = new HFileMeta(false, StateView.EMPTY_WACL, expiry);
    expectedImmutable = FileGetInfoResponse.FileInfo.newBuilder().setLedgerId(ledgerId).setDeleted(false).setExpirationTime(Timestamp.newBuilder().setSeconds(expiry)).setFileID(target).setSize(data.length).build();
    expected = expectedImmutable.toBuilder().setKeys(TxnHandlingScenario.MISC_FILE_WACL_KT.asKey().getKeyList()).setMemo(fileMemo).build();
    tokenAccount = MerkleAccountFactory.newAccount().isSmartContract(false).tokens(tokenId).get();
    tokenAccount.setNftsOwned(10);
    tokenAccount.setMaxAutomaticAssociations(123);
    tokenAccount.setAlias(TxnHandlingScenario.TOKEN_ADMIN_KT.asKey().getEd25519());
    contract = MerkleAccountFactory.newAccount().alias(create2Address).memo("Stay cold...").numKvPairs(wellKnownNumKvPairs).isSmartContract(true).accountKeys(COMPLEX_KEY_ACCOUNT_KT).proxy(asAccount("0.0.3")).senderThreshold(1_234L).receiverThreshold(4_321L).receiverSigRequired(true).balance(555L).autoRenewPeriod(1_000_000L).deleted(true).expirationTime(9_999_999L).get();
    contracts = (MerkleMap<EntityNum, MerkleAccount>) mock(MerkleMap.class);
    topics = (MerkleMap<EntityNum, MerkleTopic>) mock(MerkleMap.class);
    tokenRels = new MerkleMap<>();
    tokenRels.put(EntityNumPair.fromLongs(tokenAccountId.getAccountNum(), tokenId.getTokenNum()), new MerkleTokenRelStatus(123L, false, true, true));
    tokenStore = mock(TokenStore.class);
    token = new MerkleToken(Long.MAX_VALUE, 100, 1, "UnfrozenToken", "UnfrozenTokenName", true, true, new EntityId(0, 0, 3));
    token.setMemo(tokenMemo);
    token.setAdminKey(TxnHandlingScenario.TOKEN_ADMIN_KT.asJKey());
    token.setFreezeKey(TxnHandlingScenario.TOKEN_FREEZE_KT.asJKey());
    token.setKycKey(TxnHandlingScenario.TOKEN_KYC_KT.asJKey());
    token.setSupplyKey(COMPLEX_KEY_ACCOUNT_KT.asJKey());
    token.setWipeKey(MISC_ACCOUNT_KT.asJKey());
    token.setFeeScheduleKey(MISC_ACCOUNT_KT.asJKey());
    token.setPauseKey(TxnHandlingScenario.TOKEN_PAUSE_KT.asJKey());
    token.setAutoRenewAccount(EntityId.fromGrpcAccountId(autoRenew));
    token.setExpiry(expiry);
    token.setAutoRenewPeriod(autoRenewPeriod);
    token.setDeleted(true);
    token.setPaused(true);
    token.setTokenType(TokenType.FUNGIBLE_COMMON);
    token.setSupplyType(TokenSupplyType.FINITE);
    token.setFeeScheduleFrom(grpcCustomFees);
    scheduleStore = mock(ScheduleStore.class);
    final var scheduleMemo = "For what but eye and ear";
    parentScheduleCreate = scheduleCreateTxnWith(SCHEDULE_ADMIN_KT.asKey(), scheduleMemo, payerAccountId, creatorAccountID, MiscUtils.asTimestamp(now.toJava()));
    schedule = MerkleSchedule.from(parentScheduleCreate.toByteArray(), expiry);
    schedule.witnessValidSignature("01234567890123456789012345678901".getBytes());
    schedule.witnessValidSignature("_123456789_123456789_123456789_1".getBytes());
    schedule.witnessValidSignature("_o23456789_o23456789_o23456789_o".getBytes());
    contents = mock(Map.class);
    attrs = mock(Map.class);
    bytecode = mock(Map.class);
    specialFiles = mock(MerkleSpecialFiles.class);
    mockTokenRelsFn = (BiFunction<StateView, EntityNum, List<TokenRelationship>>) mock(BiFunction.class);
    StateView.tokenRelsFn = mockTokenRelsFn;
    final var uniqueTokens = new MerkleMap<EntityNumPair, MerkleUniqueToken>();
    uniqueTokens.put(targetNftKey, targetNft);
    uniqueTokens.put(treasuryNftKey, treasuryNft);
    storage = (VirtualMap<VirtualBlobKey, VirtualBlobValue>) mock(VirtualMap.class);
    contractStorage = (VirtualMap<ContractKey, ContractValue>) mock(VirtualMap.class);
    children = new MutableStateChildren();
    children.setUniqueTokens(uniqueTokens);
    children.setAccounts(contracts);
    children.setTokenAssociations(tokenRels);
    children.setSpecialFiles(specialFiles);
    networkInfo = mock(NetworkInfo.class);
    subject = new StateView(tokenStore, scheduleStore, children, networkInfo);
    subject.fileAttrs = attrs;
    subject.fileContents = contents;
    subject.contractBytecode = bytecode;
}
Also used : NetworkInfo(com.hedera.services.config.NetworkInfo) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleTopic(com.hedera.services.state.merkle.MerkleTopic) EntityNum(com.hedera.services.utils.EntityNum) MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) EntityId(com.hedera.services.state.submerkle.EntityId) MerkleSpecialFiles(com.hedera.services.state.merkle.MerkleSpecialFiles) ContractValue(com.hedera.services.state.virtual.ContractValue) MutableStateChildren(com.hedera.services.context.MutableStateChildren) ContractKey(com.hedera.services.state.virtual.ContractKey) HFileMeta(com.hedera.services.files.HFileMeta) MerkleMap(com.swirlds.merkle.map.MerkleMap) VirtualBlobValue(com.hedera.services.state.virtual.VirtualBlobValue) KeyList(com.hederahashgraph.api.proto.java.KeyList) List(java.util.List) TokenStore(com.hedera.services.store.tokens.TokenStore) ScheduleStore(com.hedera.services.store.schedule.ScheduleStore) Map(java.util.Map) VirtualMap(com.swirlds.virtualmap.VirtualMap) MerkleMap(com.swirlds.merkle.map.MerkleMap) VirtualBlobKey(com.hedera.services.state.virtual.VirtualBlobKey) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ContractKey (com.hedera.services.state.virtual.ContractKey)14 ContractValue (com.hedera.services.state.virtual.ContractValue)13 ContractKeySupplier (com.hedera.services.state.virtual.ContractKeySupplier)8 ContractValueSupplier (com.hedera.services.state.virtual.ContractValueSupplier)8 VirtualLeafRecordSerializer (com.swirlds.jasperdb.VirtualLeafRecordSerializer)8 VirtualInternalRecord (com.swirlds.virtualmap.datasource.VirtualInternalRecord)8 Path (java.nio.file.Path)8 ContractKeySerializer (com.hedera.services.state.virtual.ContractKeySerializer)7 VirtualLeafRecord (com.swirlds.virtualmap.datasource.VirtualLeafRecord)7 IOException (java.io.IOException)7 DigestType (com.swirlds.common.crypto.DigestType)6 JasperDbBuilder (com.swirlds.jasperdb.JasperDbBuilder)6 VirtualInternalRecordSerializer (com.swirlds.jasperdb.VirtualInternalRecordSerializer)6 DataFileCommon (com.swirlds.jasperdb.files.DataFileCommon)6 Files (java.nio.file.Files)6 LongStream (java.util.stream.LongStream)6 VirtualDataSourceJasperDB (com.swirlds.jasperdb.VirtualDataSourceJasperDB)5 Random (java.util.Random)5 Stream (java.util.stream.Stream)5 Benchmark (org.openjdk.jmh.annotations.Benchmark)4