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

feat: HIP-904 Introduce unlimitedAutoAssociations feature flag #13041

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
public record EntitiesConfig(
@ConfigProperty(defaultValue = "3153600000") @NetworkProperty long maxLifetime,
// @ConfigProperty(defaultValue = "FILE") Set<EntityType> systemDeletable
@ConfigProperty(defaultValue = "false") @NetworkProperty boolean limitTokenAssociations) {}
@ConfigProperty(defaultValue = "false") @NetworkProperty boolean limitTokenAssociations,
@ConfigProperty(defaultValue = "true") @NetworkProperty boolean unlimitedAutoAssociationsEnabled) {}
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ protected TokenRelation autoAssociate(
entitiesConfig.limitTokenAssociations() && numAssociations >= tokensConfig.maxPerAccount(),
TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED);

// TODO: check for unlimited associations flag and include -1 as infinite associations
final var maxAutoAssociations = account.maxAutoAssociations();
final var usedAutoAssociations = account.usedAutoAssociations();
validateFalse(usedAutoAssociations >= maxAutoAssociations, NO_REMAINING_AUTOMATIC_ASSOCIATIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,16 @@ private void validateSemantics(
// validate auto associations
if (op.hasMaxAutomaticTokenAssociations()) {
final long newMax = builderAccount.maxAutoAssociations();
// first validate if the associations are limited and the new max is within
validateFalse(
entitiesConfig.limitTokenAssociations() && newMax > tokensConfig.maxPerAccount(),
REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT);
// TODO: check for unlimited associations flag and include -1 as infinite associations
validateFalse(
newMax < updateAccount.usedAutoAssociations(), EXISTING_AUTOMATIC_ASSOCIATIONS_EXCEED_GIVEN_LIMIT);
validateFalse(
newMax > ledgerConfig.maxAutoAssociations(),
REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT);
validateFalse(
entitiesConfig.limitTokenAssociations() && newMax > tokensConfig.maxPerAccount(),
REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT);
}

// validate if account is not deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public boolean tooManyAutoAssociations(
@NonNull final LedgerConfig ledgerConfig,
@NonNull final EntitiesConfig entitiesConfig,
@NonNull final TokensConfig tokensConfig) {
return n > ledgerConfig.maxAutoAssociations()
|| (entitiesConfig.limitTokenAssociations() && n > tokensConfig.maxPerAccount());
return (entitiesConfig.limitTokenAssociations() && n > tokensConfig.maxPerAccount())
|| n > ledgerConfig.maxAutoAssociations()
|| (n < 0 && !entitiesConfig.unlimitedAutoAssociationsEnabled())
|| (n < -1 && entitiesConfig.unlimitedAutoAssociationsEnabled());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void setUp() {
.withValue("cryptoCreateWithAlias.enabled", true)
.withValue("ledger.maxAutoAssociations", 5000)
.withValue("entities.limitTokenAssociations", false)
.withValue("tokens.maxPerAccount", 1000);
.withValue("tokens.maxPerAccount", 1000)
.withValue("entities.unlimitedAutoAssociations", true);
}

// @Test
Expand Down Expand Up @@ -116,6 +117,7 @@ void checkTooManyAutoAssociations() {
getConfigs(configuration);
assertTrue(subject.tooManyAutoAssociations(5001, ledgerConfig, entitiesConfig, tokensConfig));
assertFalse(subject.tooManyAutoAssociations(3000, ledgerConfig, entitiesConfig, tokensConfig));
assertFalse(subject.tooManyAutoAssociations(-1, ledgerConfig, entitiesConfig, tokensConfig));
}

@Test
Expand All @@ -125,6 +127,9 @@ void checkDiffTooManyAutoAssociations() {
getConfigs(configuration);
assertTrue(subject.tooManyAutoAssociations(1001, ledgerConfig, entitiesConfig, tokensConfig));
assertFalse(subject.tooManyAutoAssociations(999, ledgerConfig, entitiesConfig, tokensConfig));
assertFalse(subject.tooManyAutoAssociations(-1, ledgerConfig, entitiesConfig, tokensConfig));
assertTrue(subject.tooManyAutoAssociations(-2, ledgerConfig, entitiesConfig, tokensConfig));
assertTrue(subject.tooManyAutoAssociations(-100000, ledgerConfig, entitiesConfig, tokensConfig));
}

private void getConfigs(Configuration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ private Map<String, String> all(final String choice, @NonNull final List<String>
"contracts.precompile.atomicCryptoTransfer.enabled",
"scheduling.longTermEnabled",
// Not being tested
"contracts.evm.version.dynamic"
"contracts.evm.version.dynamic",
// HIP-904
"entities.unlimitedAutoAssociationsEnabled"
};
}