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

01761: Finalize NFT changes #1762

Merged
merged 8 commits into from
Jul 7, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public FeeData get() {
return ESTIMATOR_UTILS.withDefaultQueryPartitioning(usage);
}

public void updateRb(long amount) {
public void addRb(long amount) {
rb += amount;
}

public void updateTb(long amount) {
public void addTb(long amount) {
tb += amount;
}

public void updateSb(long amount) {
public void addSb(long amount) {
sb += amount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@
public class ContractGetInfoUsage extends QueryUsage {
private ContractGetInfoUsage(Query query) {
super(query.getContractGetInfo().getHeader().getResponseType());
updateTb(BASIC_ENTITY_ID_SIZE);
updateRb(CONTRACT_ENTITY_SIZES.fixedBytesInContractRepr());
addTb(BASIC_ENTITY_ID_SIZE);
addRb(CONTRACT_ENTITY_SIZES.fixedBytesInContractRepr());
}

public static ContractGetInfoUsage newEstimate(Query query) {
return new ContractGetInfoUsage(query);
}

public ContractGetInfoUsage givenCurrentKey(Key key) {
updateRb(getAccountKeyStorageSize(key));
addRb(getAccountKeyStorageSize(key));
return this;
}

public ContractGetInfoUsage givenCurrentMemo(String memo) {
updateRb(memo.getBytes(Charset.forName("UTF-8")).length);
addRb(memo.getBytes(Charset.forName("UTF-8")).length);
return this;
}

public ContractGetInfoUsage givenCurrentTokenAssocs(int count) {
updateRb(count * CRYPTO_ENTITY_SIZES.bytesInTokenAssocRepr());
addRb(count * CRYPTO_ENTITY_SIZES.bytesInTokenAssocRepr());
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@
public class CryptoGetInfoUsage extends QueryUsage {
private CryptoGetInfoUsage(Query query) {
super(query.getCryptoGetInfo().getHeader().getResponseType());
updateTb(BASIC_ENTITY_ID_SIZE);
updateRb(CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr());
addTb(BASIC_ENTITY_ID_SIZE);
addRb(CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr());
}

public static CryptoGetInfoUsage newEstimate(Query query) {
return new CryptoGetInfoUsage(query);
}

public CryptoGetInfoUsage givenCurrentKey(Key key) {
updateRb(getAccountKeyStorageSize(key));
addRb(getAccountKeyStorageSize(key));
return this;
}

public CryptoGetInfoUsage givenCurrentMemo(String memo) {
updateRb(memo.getBytes(Charset.forName("UTF-8")).length);
addRb(memo.getBytes(Charset.forName("UTF-8")).length);
return this;
}

public CryptoGetInfoUsage givenCurrentTokenAssocs(int count) {
updateRb(count * CRYPTO_ENTITY_SIZES.bytesInTokenAssocRepr());
addRb(count * CRYPTO_ENTITY_SIZES.bytesInTokenAssocRepr());
return this;
}

public CryptoGetInfoUsage givenCurrentlyUsingProxy() {
updateRb(BASIC_ENTITY_ID_SIZE);
addRb(BASIC_ENTITY_ID_SIZE);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public FeeData cryptoInfoUsage(Query cryptoInfoReq, ExtantCryptoContext ctx) {
var op = cryptoInfoReq.getCryptoGetInfo();

var estimate = queryEstimateFactory.apply(op.getHeader().getResponseType());
estimate.updateTb(BASIC_ENTITY_ID_SIZE);
estimate.addTb(BASIC_ENTITY_ID_SIZE);
long extraRb = 0;
extraRb += ctx.currentMemo().getBytes(StandardCharsets.UTF_8).length;
extraRb += getAccountKeyStorageSize(ctx.currentKey());
if (ctx.currentlyHasProxy()) {
extraRb += BASIC_ENTITY_ID_SIZE;
}
extraRb += ctx.currentNumTokenRels() * TOKEN_ENTITY_SIZES.bytesUsedPerAccountRelationship();
estimate.updateRb(CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + extraRb);
estimate.addRb(CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + extraRb);

return estimate.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public FeeData fileInfoUsage(Query fileInfoReq, ExtantFileContext ctx) {
var op = fileInfoReq.getFileGetInfo();

var estimate = queryEstimateFactory.apply(op.getHeader().getResponseType());
estimate.updateTb(BASIC_ENTITY_ID_SIZE);
estimate.addTb(BASIC_ENTITY_ID_SIZE);
long extraSb = 0;
extraSb += ctx.currentMemo().getBytes(StandardCharsets.UTF_8).length;
extraSb += getAccountKeyStorageSize(asKey(ctx.currentWacl()));
estimate.updateSb(BASE_FILEINFO_SIZE + extraSb);
estimate.addSb(BASE_FILEINFO_SIZE + extraSb);

return estimate.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public FeeData scheduleInfoUsage(Query scheduleInfo, ExtantScheduleContext ctx)
var op = scheduleInfo.getScheduleGetInfo();

var estimate = queryEstimateFactory.apply(op.getHeader().getResponseType());
estimate.updateTb(BASIC_ENTITY_ID_SIZE);
estimate.updateRb(ctx.nonBaseRb());
estimate.addTb(BASIC_ENTITY_ID_SIZE);
estimate.addRb(ctx.nonBaseRb());

return estimate.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class TokenGetAccountNftInfosUsage extends QueryUsage {

public TokenGetAccountNftInfosUsage(Query query) {
super(query.getTokenGetAccountNftInfos().getHeader().getResponseType());
updateTb(BASIC_ENTITY_ID_SIZE);
updateTb(2 * INT_SIZE_AS_LONG);
addTb(BASIC_ENTITY_ID_SIZE);
addTb(2 * INT_SIZE_AS_LONG);
}

public static TokenGetAccountNftInfosUsage newEstimate(Query query) {
Expand All @@ -48,8 +48,8 @@ public TokenGetAccountNftInfosUsage givenMetadata(List<ByteString> metadata) {
for (ByteString m : metadata) {
additionalRb += m.size();
}
updateRb(additionalRb);
updateRb(NFT_ENTITY_SIZES.fixedBytesInNftRepr() * metadata.size());
addRb(additionalRb);
addRb(NFT_ENTITY_SIZES.fixedBytesInNftRepr() * metadata.size());
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,56 @@
public class TokenGetInfoUsage extends QueryUsage {
private TokenGetInfoUsage(Query query) {
super(query.getTokenGetInfo().getHeader().getResponseType());
updateTb(BASIC_ENTITY_ID_SIZE);
updateRb(TOKEN_ENTITY_SIZES.fixedBytesInTokenRepr());
addTb(BASIC_ENTITY_ID_SIZE);
addRb(TOKEN_ENTITY_SIZES.fixedBytesInTokenRepr());
}

public static TokenGetInfoUsage newEstimate(Query query) {
return new TokenGetInfoUsage(query);
}

public TokenGetInfoUsage givenCurrentAdminKey(Optional<Key> adminKey) {
adminKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::updateRb);
adminKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::addRb);
return this;
}

public TokenGetInfoUsage givenCurrentWipeKey(Optional<Key> wipeKey) {
wipeKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::updateRb);
wipeKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::addRb);
return this;
}

public TokenGetInfoUsage givenCurrentSupplyKey(Optional<Key> supplyKey) {
supplyKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::updateRb);
supplyKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::addRb);
return this;
}

public TokenGetInfoUsage givenCurrentFreezeKey(Optional<Key> freezeKey) {
freezeKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::updateRb);
freezeKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::addRb);
return this;
}

public TokenGetInfoUsage givenCurrentKycKey(Optional<Key> kycKey) {
kycKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::updateRb);
kycKey.map(FeeBuilder::getAccountKeyStorageSize).ifPresent(this::addRb);
return this;
}

public TokenGetInfoUsage givenCurrentMemo(String memo) {
updateRb(memo.length());
addRb(memo.length());
return this;
}

public TokenGetInfoUsage givenCurrentName(String name) {
updateRb(name.length());
addRb(name.length());
return this;
}

public TokenGetInfoUsage givenCurrentSymbol(String symbol) {
updateRb(symbol.length());
addRb(symbol.length());
return this;
}

public TokenGetInfoUsage givenCurrentlyUsingAutoRenewAccount() {
updateRb(BASIC_ENTITY_ID_SIZE);
addRb(BASIC_ENTITY_ID_SIZE);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
public class TokenGetNftInfoUsage extends QueryUsage {
public TokenGetNftInfoUsage(Query query) {
super(query.getTokenGetNftInfo().getHeader().getResponseType());
updateTb(BASIC_ENTITY_ID_SIZE);
updateTb(LONG_SIZE);
updateRb(NFT_ENTITY_SIZES.fixedBytesInNftRepr());
addTb(BASIC_ENTITY_ID_SIZE);
addTb(LONG_SIZE);
addRb(NFT_ENTITY_SIZES.fixedBytesInNftRepr());
}

public static TokenGetNftInfoUsage newEstimate(Query query) {
return new TokenGetNftInfoUsage(query);
}

public TokenGetNftInfoUsage givenMetadata(String memo) {
updateRb(memo.length());
addRb(memo.length());
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.hedera.services.usage.token;

/*
* -
*
* Hedera Services Fees
*
/*-
* ‌
* Hedera Services API Fees
* ​
* Copyright (C) 2018 - 2021 Hedera Hashgraph, LLC
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ‍
*/

import com.google.protobuf.ByteString;
Expand All @@ -31,11 +31,11 @@
import static com.hederahashgraph.fee.FeeBuilder.INT_SIZE;

public class TokenGetNftInfosUsage extends QueryUsage {
final static long INT_SIZE_AS_LONG = INT_SIZE;
static final long INT_SIZE_AS_LONG = INT_SIZE;

public TokenGetNftInfosUsage(Query query) {
super(query.getTokenGetNftInfos().getHeader().getResponseType());
updateTb(BASIC_ENTITY_ID_SIZE + 2 * INT_SIZE_AS_LONG);
addTb(BASIC_ENTITY_ID_SIZE + 2 * INT_SIZE_AS_LONG);
}

public static TokenGetNftInfosUsage newEstimate(Query query) {
Expand All @@ -47,9 +47,9 @@ public TokenGetNftInfosUsage givenMetadata(List<ByteString> metadata) {
for (ByteString m : metadata) {
additionalRb += m.size();
}
updateRb(additionalRb);
updateRb(NFT_ENTITY_SIZES.fixedBytesInNftRepr() * metadata.size());
addRb(additionalRb);
addRb(NFT_ENTITY_SIZES.fixedBytesInNftRepr() * metadata.size());

return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -253,7 +253,7 @@ void safeAccumulateFourWorks() {
private final FeeData mockUsage = ESTIMATOR_UTILS.withDefaultTxnPartitioning(
mockUsageVector, SubType.DEFAULT, network_rbh, 3);

public static void copyData(FeeData feeData, UsageAccumulator into) {
private static void copyData(FeeData feeData, UsageAccumulator into) {
into.setNumPayerKeys(feeData.getNodedata().getVpt());
into.addVpt(feeData.getNetworkdata().getVpt());
into.addBpt(feeData.getNetworkdata().getBpt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
16 changes: 8 additions & 8 deletions hapi-fees/src/test/java/com/hedera/services/test/KeyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -42,12 +42,12 @@ public class KeyUtils {
.build();
public static Key A_KEY_LIST = Key.newBuilder()
.setKeyList(KeyList.newBuilder()
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes())))
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb".getBytes())))
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom("cccccccccccccccccccccccccccccccc".getBytes()))))
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes())))
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb".getBytes())))
.addKeys(Key.newBuilder()
.setEd25519(ByteString.copyFrom("cccccccccccccccccccccccccccccccc".getBytes()))))
.build();
public static Key A_COMPLEX_KEY = Key.newBuilder()
.setThresholdKey(ThresholdKey.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
Loading