Skip to content

Commit

Permalink
Remove all FCOneToManyRelation use and update EETs to only verify N…
Browse files Browse the repository at this point in the history
…OT… (#2962)

* Remove all FCOneToManyRelation use and update EETs to only verify NOT_SUPPORTED

Signed-off-by: tinker-michaelj <michael.tinker@hedera.com>

* Fix unit test

Signed-off-by: tinker-michaelj <michael.tinker@hedera.com>

* Fix code smells

Signed-off-by: tinker-michaelj <michael.tinker@hedera.com>

* Remove unused tokens.nfts.areQueriesEnabled property, MerkleUniqueTokenId class

Signed-off-by: tinker-michaelj <michael.tinker@hedera.com>
Signed-off-by: Ray Juang <radford.juang@hedera.com>
  • Loading branch information
Michael Tinker authored and Ray Juang committed Mar 23, 2022
1 parent 71427a6 commit 0f2e430
Show file tree
Hide file tree
Showing 102 changed files with 500 additions and 5,678 deletions.
13 changes: 0 additions & 13 deletions hedera-node/src/main/java/com/hedera/services/ServicesState.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import com.swirlds.common.crypto.RunningHash;
import com.swirlds.common.merkle.MerkleNode;
import com.swirlds.common.merkle.utility.AbstractNaryMerkleInternal;
import com.swirlds.fchashmap.FCOneToManyRelation;
import com.swirlds.jasperdb.JasperDbBuilder;
import com.swirlds.merkle.map.MerkleMap;
import com.swirlds.platform.state.DualStateImpl;
Expand Down Expand Up @@ -351,18 +350,6 @@ public VirtualMap<ContractKey, ContractValue> contractStorage() {
return getChild(StateChildIndices.CONTRACT_STORAGE);
}

public FCOneToManyRelation<EntityNum, Long> uniqueTokenAssociations() {
return metadata.getUniqueTokenAssociations();
}

public FCOneToManyRelation<EntityNum, Long> uniqueOwnershipAssociations() {
return metadata.getUniqueOwnershipAssociations();
}

public FCOneToManyRelation<EntityNum, Long> uniqueTreasuryOwnershipAssociations() {
return metadata.getUniqueTreasuryOwnershipAssociations();
}

private void internalInit(
final Platform platform,
final BootstrapProperties bootstrapProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.hedera.services.utils.EntityNum;
import com.hedera.services.utils.EntityNumPair;
import com.swirlds.common.AddressBook;
import com.swirlds.fchashmap.FCOneToManyRelation;
import com.swirlds.merkle.map.MerkleMap;
import com.swirlds.virtualmap.VirtualMap;

Expand All @@ -61,9 +60,6 @@ public class MutableStateChildren implements StateChildren {
private WeakReference<VirtualMap<VirtualBlobKey, VirtualBlobValue>> storage;
private WeakReference<VirtualMap<ContractKey, ContractValue>> contractStorage;
private WeakReference<MerkleMap<EntityNumPair, MerkleTokenRelStatus>> tokenAssociations;
private WeakReference<FCOneToManyRelation<EntityNum, Long>> uniqueTokenAssociations;
private WeakReference<FCOneToManyRelation<EntityNum, Long>> uniqueOwnershipAssociations;
private WeakReference<FCOneToManyRelation<EntityNum, Long>> uniqueOwnershipTreasuryAssociations;
private WeakReference<MerkleNetworkContext> networkCtx;
private WeakReference<AddressBook> addressBook;
private WeakReference<MerkleSpecialFiles> specialFiles;
Expand Down Expand Up @@ -204,68 +200,24 @@ public void setUniqueTokens(MerkleMap<EntityNumPair, MerkleUniqueToken> uniqueTo
this.uniqueTokens = new WeakReference<>(uniqueTokens);
}

@Override
public FCOneToManyRelation<EntityNum, Long> uniqueTokenAssociations() {
final var refUniqueTokenAssociations = uniqueTokenAssociations.get();
Objects.requireNonNull(refUniqueTokenAssociations);
return refUniqueTokenAssociations;
}

public void setUniqueTokenAssociations(FCOneToManyRelation<EntityNum, Long> uniqueTokenAssociations) {
this.uniqueTokenAssociations = new WeakReference<>(uniqueTokenAssociations);
}

@Override
public FCOneToManyRelation<EntityNum, Long> uniqueOwnershipAssociations() {
final var refUniqueOwnershipAssociations = uniqueOwnershipAssociations.get();
Objects.requireNonNull(refUniqueOwnershipAssociations);
return refUniqueOwnershipAssociations;
}

public void setUniqueOwnershipAssociations(
FCOneToManyRelation<EntityNum, Long> uniqueOwnershipAssociations
) {
this.uniqueOwnershipAssociations = new WeakReference<>(uniqueOwnershipAssociations);
}

@Override
public FCOneToManyRelation<EntityNum, Long> uniqueOwnershipTreasuryAssociations() {
final var refUniqueOwnershipTreasuryAssociations = uniqueOwnershipTreasuryAssociations.get();
Objects.requireNonNull(refUniqueOwnershipTreasuryAssociations);
return refUniqueOwnershipTreasuryAssociations;
}

public void setUniqueOwnershipTreasuryAssociations(
FCOneToManyRelation<EntityNum, Long> uniqueOwnershipTreasuryAssociations
) {
this.uniqueOwnershipTreasuryAssociations = new WeakReference<>(uniqueOwnershipTreasuryAssociations);
}

@Override
public RecordsRunningHashLeaf runningHashLeaf() {
final var refRunningHashLeaf = runningHashLeaf.get();
Objects.requireNonNull(refRunningHashLeaf);
return refRunningHashLeaf;
}


public void setRunningHashLeaf(RecordsRunningHashLeaf runningHashLeaf) {
this.runningHashLeaf = new WeakReference<>(runningHashLeaf);
}

public void updateFromMaybeUninitializedState(final ServicesState signedState, final Instant signingTime) {
signedAt = signingTime;
updatePrimitiveChildrenFrom(signedState);
uniqueTokenAssociations = new WeakReference<>(null);
uniqueOwnershipAssociations = new WeakReference<>(null);
uniqueOwnershipTreasuryAssociations = new WeakReference<>(null);
}

public void updateFrom(final ServicesState state) {
updatePrimitiveChildrenFrom(state);
uniqueTokenAssociations = new WeakReference<>(state.uniqueTokenAssociations());
uniqueOwnershipAssociations = new WeakReference<>(state.uniqueOwnershipAssociations());
uniqueOwnershipTreasuryAssociations = new WeakReference<>(state.uniqueTreasuryOwnershipAssociations());
}

public void updatePrimitiveChildrenFrom(final ServicesState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.hedera.services.utils.EntityNum;
import com.hedera.services.utils.EntityNumPair;
import com.swirlds.common.AddressBook;
import com.swirlds.fchashmap.FCOneToManyRelation;
import com.swirlds.merkle.map.MerkleMap;
import com.swirlds.virtualmap.VirtualMap;

Expand Down Expand Up @@ -67,11 +66,5 @@ public interface StateChildren {

MerkleMap<EntityNumPair, MerkleUniqueToken> uniqueTokens();

FCOneToManyRelation<EntityNum, Long> uniqueTokenAssociations();

FCOneToManyRelation<EntityNum, Long> uniqueOwnershipAssociations();

FCOneToManyRelation<EntityNum, Long> uniqueOwnershipTreasuryAssociations();

RecordsRunningHashLeaf runningHashLeaf();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class ServicesInitFlow {

@Inject
public ServicesInitFlow(
StateInitializationFlow stateFlow,
StoreInitializationFlow storeFlow,
EntitiesInitializationFlow entitiesFlow
final StateInitializationFlow stateFlow,
final StoreInitializationFlow storeFlow,
final EntitiesInitializationFlow entitiesFlow
) {
this.stateFlow = stateFlow;
this.storeFlow = storeFlow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.hedera.services.store.models.NftId;
import com.hedera.services.store.schedule.ScheduleStore;
import com.hedera.services.store.tokens.TokenStore;
import com.hedera.services.store.tokens.views.UniqueTokenViewsManager;
import com.hederahashgraph.api.proto.java.AccountID;
import com.hederahashgraph.api.proto.java.TokenID;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -49,7 +48,6 @@ public class StoreInitializationFlow {
private final ScheduleStore scheduleStore;
private final StateAccessor stateAccessor;
private final AliasManager aliasManager;
private final UniqueTokenViewsManager uniqTokenViewsManager;
private final BackingStore<AccountID, MerkleAccount> backingAccounts;
private final BackingStore<TokenID, MerkleToken> backingTokens;
private final BackingStore<NftId, MerkleUniqueToken> backingNfts;
Expand All @@ -61,7 +59,6 @@ public StoreInitializationFlow(
final ScheduleStore scheduleStore,
final AliasManager aliasManager,
final @WorkingState StateAccessor stateAccessor,
final UniqueTokenViewsManager uniqTokenViewsManager,
final BackingStore<AccountID, MerkleAccount> backingAccounts,
final BackingStore<TokenID, MerkleToken> backingTokens,
final BackingStore<NftId, MerkleUniqueToken> backingNfts,
Expand All @@ -75,7 +72,6 @@ public StoreInitializationFlow(
this.backingNfts = backingNfts;
this.backingTokenRels = backingTokenRels;
this.aliasManager = aliasManager;
this.uniqTokenViewsManager = uniqTokenViewsManager;
}

public void run() {
Expand All @@ -89,9 +85,6 @@ public void run() {
scheduleStore.rebuildViews();
log.info("Store internal views rebuilt");

uniqTokenViewsManager.rebuildNotice(stateAccessor.tokens(), stateAccessor.uniqueTokens());
log.info("Unique token views rebuilt");

aliasManager.rebuildAliasesMap(stateAccessor.accounts());
log.info("Account aliases map rebuilt");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import com.hedera.services.state.virtual.VirtualBlobValue;
import com.hedera.services.store.schedule.ScheduleStore;
import com.hedera.services.store.tokens.TokenStore;
import com.hedera.services.store.tokens.views.UniqTokenView;
import com.hedera.services.store.tokens.views.UniqTokenViewFactory;
import com.hedera.services.utils.EntityNum;
import com.hedera.services.utils.EntityNumPair;
import com.hedera.services.utils.MiscUtils;
Expand Down Expand Up @@ -75,15 +73,13 @@
import com.hederahashgraph.api.proto.java.TopicID;
import com.swirlds.common.merkle.MerkleNode;
import com.swirlds.common.merkle.utility.Keyed;
import com.swirlds.fchashmap.FCOneToManyRelation;
import com.swirlds.merkle.map.MerkleMap;
import com.swirlds.virtualmap.VirtualKey;
import com.swirlds.virtualmap.VirtualMap;
import com.swirlds.virtualmap.VirtualValue;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -95,7 +91,6 @@
import static com.hedera.services.state.submerkle.EntityId.MISSING_ENTITY_ID;
import static com.hedera.services.store.schedule.ScheduleStore.MISSING_SCHEDULE;
import static com.hedera.services.store.tokens.TokenStore.MISSING_TOKEN;
import static com.hedera.services.store.tokens.views.EmptyUniqTokenViewFactory.EMPTY_UNIQ_TOKEN_VIEW_FACTORY;
import static com.hedera.services.txns.crypto.helpers.AllowanceHelpers.getCryptoAllowancesList;
import static com.hedera.services.txns.crypto.helpers.AllowanceHelpers.getFungibleTokenAllowancesList;
import static com.hedera.services.txns.crypto.helpers.AllowanceHelpers.getNftAllowancesList;
Expand All @@ -120,19 +115,17 @@ public class StateView {
static final byte[] EMPTY_BYTES = new byte[0];
static final MerkleMap<?, ?> EMPTY_FCM = new MerkleMap<>();
static final VirtualMap<?, ?> EMPTY_VM = new VirtualMap<>();
static final FCOneToManyRelation<?, ?> EMPTY_FCOTMR = new FCOneToManyRelation<>();

public static final JKey EMPTY_WACL = new JKeyList();
public static final MerkleToken REMOVED_TOKEN = new MerkleToken(
0L, 0L, 0, "", "",
false, false, MISSING_ENTITY_ID);
public static final StateView EMPTY_VIEW = new StateView(
null, null, null, EMPTY_UNIQ_TOKEN_VIEW_FACTORY, null);
null, null, null, null);

private final TokenStore tokenStore;
private final ScheduleStore scheduleStore;
private final StateChildren stateChildren;
private final UniqTokenView uniqTokenView;
private final NetworkInfo networkInfo;

Map<byte[], byte[]> contractBytecode;
Expand All @@ -143,22 +136,13 @@ public StateView(
@Nullable final TokenStore tokenStore,
@Nullable final ScheduleStore scheduleStore,
@Nullable final StateChildren stateChildren,
final UniqTokenViewFactory uniqTokenViewFactory,
final NetworkInfo networkInfo
) {
this.tokenStore = tokenStore;
this.scheduleStore = scheduleStore;
this.stateChildren = stateChildren;
this.networkInfo = networkInfo;

this.uniqTokenView = uniqTokenViewFactory.viewFor(
tokenStore,
this::tokens,
this::uniqueTokens,
this::nftsByType,
this::nftsByOwner,
this::treasuryNftsByType);

final Map<String, byte[]> blobStore = unmodifiableMap(new FcBlobsBytesStore(this::storage));

fileContents = DataMapFactory.dataMapFrom(blobStore);
Expand Down Expand Up @@ -483,27 +467,6 @@ public long numNftsOwnedBy(AccountID target) {
return account.getNftsOwned();
}

public Optional<List<TokenNftInfo>> infoForAccountNfts(@Nonnull final AccountID aid, final long start,
final long end) {
final var account = accounts().get(fromAccountId(aid));
if (account == null) {
return Optional.empty();
}
final var answer = uniqTokenView.ownedAssociations(aid, start, end);
final var infoWithLedgerId = addLedgerIdToTokenNftInfoList(answer);
return Optional.of(infoWithLedgerId);
}

public Optional<List<TokenNftInfo>> infosForTokenNfts(@Nonnull final TokenID tid, final long start,
final long end) {
if (!tokenExists(tid)) {
return Optional.empty();
}
final var answer = uniqTokenView.typedAssociations(tid, start, end);
final var infoWithLedgerId = addLedgerIdToTokenNftInfoList(answer);
return Optional.of(infoWithLedgerId);
}

public Optional<ContractGetInfoResponse.ContractInfo> infoForContract(
final ContractID id,
final AliasManager aliasManager
Expand Down Expand Up @@ -578,28 +541,6 @@ MerkleMap<EntityNum, MerkleToken> tokens() {
return stateChildren == null ? emptyMm() : stateChildren.tokens();
}

FCOneToManyRelation<EntityNum, Long> nftsByType() {
return stateChildren == null ? emptyFcotmr() : stateChildren.uniqueTokenAssociations();
}

FCOneToManyRelation<EntityNum, Long> nftsByOwner() {
return stateChildren == null ? emptyFcotmr() : stateChildren.uniqueOwnershipAssociations();
}

FCOneToManyRelation<EntityNum, Long> treasuryNftsByType() {
return stateChildren == null ? emptyFcotmr() : stateChildren.uniqueOwnershipTreasuryAssociations();
}

UniqTokenView uniqTokenView() {
return uniqTokenView;
}

private List<TokenNftInfo> addLedgerIdToTokenNftInfoList(final List<TokenNftInfo> tokenNftInfoList) {
return tokenNftInfoList.stream()
.map(info -> info.toBuilder().setLedgerId(networkInfo.ledgerId()).build())
.toList();
}

private TokenFreezeStatus tfsFor(final boolean flag) {
return flag ? TokenFreezeStatus.Frozen : TokenFreezeStatus.Unfrozen;
}
Expand Down Expand Up @@ -641,8 +582,4 @@ private static <K, V extends MerkleNode & Keyed<K>> MerkleMap<K, V> emptyMm() {
private static <K extends VirtualKey<K>, V extends VirtualValue> VirtualMap<K, V> emptyVm() {
return (VirtualMap<K, V>) EMPTY_VM;
}

private static <K, V> FCOneToManyRelation<K, V> emptyFcotmr() {
return (FCOneToManyRelation<K, V>) EMPTY_FCOTMR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ public Set<String> allPropertyNames() {
"hedera.shard",
"ledger.numSystemAccounts",
"ledger.totalTinyBarFloat",
"ledger.id",
"tokens.nfts.areQueriesEnabled"
"ledger.id"
);

static final Set<String> GLOBAL_DYNAMIC_PROPS = Set.of(
Expand Down Expand Up @@ -414,7 +413,6 @@ public static Function<String, Object> transformFor(String prop) {
entry("tokens.nfts.maxAllowedMints", AS_LONG),
entry("tokens.nfts.maxQueryRange", AS_LONG),
entry("tokens.nfts.useTreasuryWildcards", AS_BOOLEAN),
entry("tokens.nfts.areQueriesEnabled", AS_BOOLEAN),
entry("contracts.localCall.estRetBytes", AS_INT),
entry("contracts.allowCreate2", AS_BOOLEAN),
entry("contracts.defaultLifetime", AS_LONG),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
import com.hedera.services.fees.annotations.FunctionKey;
import com.hedera.services.fees.calculation.QueryResourceUsageEstimator;
import com.hedera.services.fees.calculation.TxnResourceUsageEstimator;
import com.hedera.services.fees.calculation.token.queries.GetAccountNftInfosResourceUsage;
import com.hedera.services.fees.calculation.token.queries.GetTokenInfoResourceUsage;
import com.hedera.services.fees.calculation.token.queries.GetTokenNftInfoResourceUsage;
import com.hedera.services.fees.calculation.token.queries.GetTokenNftInfosResourceUsage;
import com.hedera.services.fees.calculation.token.txns.TokenAssociateResourceUsage;
import com.hedera.services.fees.calculation.token.txns.TokenCreateResourceUsage;
import com.hedera.services.fees.calculation.token.txns.TokenDeleteResourceUsage;
Expand Down Expand Up @@ -56,15 +54,11 @@ public final class TokenFeesModule {
@ElementsIntoSet
public static Set<QueryResourceUsageEstimator> provideTokenQueryEstimators(
final GetTokenInfoResourceUsage getTokenInfoResourceUsage,
final GetTokenNftInfoResourceUsage getTokenNftInfoResourceUsage,
final GetTokenNftInfosResourceUsage getTokenNftInfosResourceUsage,
final GetAccountNftInfosResourceUsage getAccountNftInfosResourceUsage
final GetTokenNftInfoResourceUsage getTokenNftInfoResourceUsage
) {
return Set.of(
getTokenInfoResourceUsage,
getTokenNftInfoResourceUsage,
getTokenNftInfosResourceUsage,
getAccountNftInfosResourceUsage);
getTokenNftInfoResourceUsage);
}

@Provides
Expand Down
Loading

0 comments on commit 0f2e430

Please sign in to comment.