Search in sources :

Example 6 with AliasManager

use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.

the class RenewalHelperTest method removesAutoAccountEntityWhenExpired.

@Test
void removesAutoAccountEntityWhenExpired() {
    MerkleMap<EntityNum, MerkleAccount> accountsMap = new MerkleMap<>();
    accountsMap.put(EntityNum.fromLong(nonExpiredAccountNum), nonExpiredAccount);
    accountsMap.put(EntityNum.fromLong(brokeExpiredAccountNum), expiredAccountZeroBalance);
    AliasManager liveAliasManager = new AliasManager();
    linkWellKnownEntities(liveAliasManager);
    final var backingAccounts = new BackingAccounts(() -> accountsMap);
    backingAccounts.put(IdUtils.asAccount("0.0." + nonExpiredAccountNum), nonExpiredAccount);
    backingAccounts.put(IdUtils.asAccount("0.0." + brokeExpiredAccountNum), expiredAccountZeroBalance);
    subject = new RenewalHelper(tokenStore, sigImpactHistorian, dynamicProps, () -> tokens, () -> accountsMap, () -> tokenRels, backingAccounts, liveAliasManager);
    final var expiredKey = EntityNum.fromLong(brokeExpiredAccountNum);
    givenTokenPresent(deletedTokenId, deletedToken);
    givenTokenPresent(survivedTokenId, longLivedToken);
    givenRelPresent(expiredKey, deletedTokenId, Long.MAX_VALUE);
    givenRelPresent(expiredKey, survivedTokenId, tokenBalance);
    givenRelPresent(expiredKey, EntityNum.fromTokenId(missingTokenGrpcId), 0);
    givenModifiableRelPresent(EntityNum.fromAccountId(treasuryGrpcId), survivedTokenId, 0L);
    assertTrue(liveAliasManager.contains(expiredAccountZeroBalance.getAlias()));
    assertTrue(backingAccounts.contains(AccountID.newBuilder().setAccountNum(brokeExpiredAccountNum).build()));
    subject.classify(brokeExpiredAccountNum, now);
    subject.removeLastClassifiedAccount();
    assertFalse(backingAccounts.contains(AccountID.newBuilder().setAccountNum(brokeExpiredAccountNum).build()));
}
Also used : AliasManager(com.hedera.services.ledger.accounts.AliasManager) BackingAccounts(com.hedera.services.ledger.backing.BackingAccounts) MerkleMap(com.swirlds.merkle.map.MerkleMap) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) EntityNum(com.hedera.services.utils.EntityNum) Test(org.junit.jupiter.api.Test)

Example 7 with AliasManager

use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.

the class SigOpsRegressionTest method invokePayerSigActivationScenario.

private boolean invokePayerSigActivationScenario(List<TransactionSignature> knownSigs) {
    SigRequirements keysOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var impliedOrdering = keysOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
    final var impliedKey = impliedOrdering.getPayerKey();
    platformTxn.setSigMeta(RationalizedSigMeta.forPayerOnly(impliedKey, new ArrayList<>(knownSigs)));
    return payerSigIsActive(platformTxn, ONLY_IF_SIG_IS_VALID);
}
Also used : OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) MiscUtils.asKeyUnchecked(com.hedera.services.utils.MiscUtils.asKeyUnchecked) COMPLEX_KEY_ACCOUNT_KT(com.hedera.test.factories.scenarios.CryptoCreateScenarios.COMPLEX_KEY_ACCOUNT_KT) ONLY_IF_SIG_IS_VALID(com.hedera.services.keys.HederaKeyActivation.ONLY_IF_SIG_IS_VALID) SigRequirements(com.hedera.services.sigs.order.SigRequirements) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine) SigWrappers.asValid(com.hedera.test.factories.sigs.SigWrappers.asValid) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleMap(com.swirlds.merkle.map.MerkleMap) CODE_ORDER_RESULT_FACTORY(com.hedera.services.sigs.order.CodeOrderResultFactory.CODE_ORDER_RESULT_FACTORY) EntityNum(com.hedera.services.utils.EntityNum) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_ADD_NEW_KEY_SCENARIO(com.hedera.test.factories.scenarios.CryptoUpdateScenarios.CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_ADD_NEW_KEY_SCENARIO) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) INVALID(com.swirlds.common.crypto.VerificationStatus.INVALID) SigningOrderResultFactory(com.hedera.services.sigs.order.SigningOrderResultFactory) Predicate(java.util.function.Predicate) CRYPTO_CREATE_RECEIVER_SIG_SCENARIO(com.hedera.test.factories.scenarios.CryptoCreateScenarios.CRYPTO_CREATE_RECEIVER_SIG_SCENARIO) PojoSigMapPubKeyToSigBytes(com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes) VerificationStatus(com.swirlds.common.crypto.VerificationStatus) RationalizedSigMeta(com.hedera.services.utils.RationalizedSigMeta) Test(org.junit.jupiter.api.Test) List(java.util.List) MiscRunningAvgs(com.hedera.services.stats.MiscRunningAvgs) DelegatingSigMetadataLookup.defaultLookupsFor(com.hedera.services.sigs.metadata.DelegatingSigMetadataLookup.defaultLookupsFor) JKey(com.hedera.services.legacy.core.jproto.JKey) SignatureWaivers(com.hedera.services.sigs.order.SignatureWaivers) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) PolicyBasedSigWaivers(com.hedera.services.sigs.order.PolicyBasedSigWaivers) MiscSpeedometers(com.hedera.services.stats.MiscSpeedometers) EntityNumbers(com.hedera.services.config.EntityNumbers) KeyActivationCharacteristics(com.hedera.services.keys.KeyActivationCharacteristics) NEW_ACCOUNT_KT(com.hedera.test.factories.scenarios.CryptoCreateScenarios.NEW_ACCOUNT_KT) FileNumbers(com.hedera.services.config.FileNumbers) HederaKeyActivation(com.hedera.services.keys.HederaKeyActivation) SystemOpPolicies(com.hedera.services.txns.auth.SystemOpPolicies) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) DEFAULT_ACTIVATION_CHARACTERISTICS(com.hedera.services.keys.DefaultActivationCharacteristics.DEFAULT_ACTIVATION_CHARACTERISTICS) CRYPTO_CREATE_COMPLEX_PAYER_RECEIVER_SIG_SCENARIO(com.hedera.test.factories.scenarios.CryptoCreateScenarios.CRYPTO_CREATE_COMPLEX_PAYER_RECEIVER_SIG_SCENARIO) DEFAULT_PAYER_KT(com.hedera.test.factories.txns.SignedTxnFactory.DEFAULT_PAYER_KT) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SigningOrderResult(com.hedera.services.sigs.order.SigningOrderResult) HederaToPlatformSigOps.expandIn(com.hedera.services.sigs.HederaToPlatformSigOps.expandIn) TxnHandlingScenario(com.hedera.test.factories.scenarios.TxnHandlingScenario) CryptoCreateFactory(com.hedera.test.factories.txns.CryptoCreateFactory) SigWrappers.asKind(com.hedera.test.factories.sigs.SigWrappers.asKind) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_SCENARIO(com.hedera.test.factories.scenarios.CryptoUpdateScenarios.CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_SCENARIO) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) VALID(com.swirlds.common.crypto.VerificationStatus.VALID) MockEntityNumbers(com.hedera.services.config.MockEntityNumbers) HederaFs(com.hedera.services.files.HederaFs) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) HederaKeyActivation.payerSigIsActive(com.hedera.services.keys.HederaKeyActivation.payerSigIsActive) AbstractMap(java.util.AbstractMap) INVALID_PAYER_ID_SCENARIO(com.hedera.test.factories.scenarios.BadPayerScenarios.INVALID_PAYER_ID_SCENARIO) BDDMockito.mock(org.mockito.BDDMockito.mock) SigMetadataLookup(com.hedera.services.sigs.metadata.SigMetadataLookup) MockFileNumbers(com.hedera.services.config.MockFileNumbers) CRYPTO_UPDATE_MISSING_ACCOUNT_SCENARIO(com.hedera.test.factories.scenarios.CryptoUpdateScenarios.CRYPTO_UPDATE_MISSING_ACCOUNT_SCENARIO) AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) ArrayList(java.util.ArrayList)

Example 8 with AliasManager

use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.

the class SigOpsRegressionTest method invokeOtherPartySigActivationScenario.

private boolean invokeOtherPartySigActivationScenario(List<TransactionSignature> knownSigs) {
    platformTxn.getPlatformTxn().clear();
    platformTxn.getPlatformTxn().addAll(knownSigs.toArray(new TransactionSignature[0]));
    final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
    SigRequirements keysOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, null, ref -> null, ref -> null), mockSignatureWaivers);
    return otherPartySigsAreActive(platformTxn, keysOrder, CODE_ORDER_RESULT_FACTORY);
}
Also used : OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) MiscUtils.asKeyUnchecked(com.hedera.services.utils.MiscUtils.asKeyUnchecked) COMPLEX_KEY_ACCOUNT_KT(com.hedera.test.factories.scenarios.CryptoCreateScenarios.COMPLEX_KEY_ACCOUNT_KT) ONLY_IF_SIG_IS_VALID(com.hedera.services.keys.HederaKeyActivation.ONLY_IF_SIG_IS_VALID) SigRequirements(com.hedera.services.sigs.order.SigRequirements) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine) SigWrappers.asValid(com.hedera.test.factories.sigs.SigWrappers.asValid) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) MerkleMap(com.swirlds.merkle.map.MerkleMap) CODE_ORDER_RESULT_FACTORY(com.hedera.services.sigs.order.CodeOrderResultFactory.CODE_ORDER_RESULT_FACTORY) EntityNum(com.hedera.services.utils.EntityNum) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_ADD_NEW_KEY_SCENARIO(com.hedera.test.factories.scenarios.CryptoUpdateScenarios.CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_ADD_NEW_KEY_SCENARIO) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) INVALID(com.swirlds.common.crypto.VerificationStatus.INVALID) SigningOrderResultFactory(com.hedera.services.sigs.order.SigningOrderResultFactory) Predicate(java.util.function.Predicate) CRYPTO_CREATE_RECEIVER_SIG_SCENARIO(com.hedera.test.factories.scenarios.CryptoCreateScenarios.CRYPTO_CREATE_RECEIVER_SIG_SCENARIO) PojoSigMapPubKeyToSigBytes(com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes) VerificationStatus(com.swirlds.common.crypto.VerificationStatus) RationalizedSigMeta(com.hedera.services.utils.RationalizedSigMeta) Test(org.junit.jupiter.api.Test) List(java.util.List) MiscRunningAvgs(com.hedera.services.stats.MiscRunningAvgs) DelegatingSigMetadataLookup.defaultLookupsFor(com.hedera.services.sigs.metadata.DelegatingSigMetadataLookup.defaultLookupsFor) JKey(com.hedera.services.legacy.core.jproto.JKey) SignatureWaivers(com.hedera.services.sigs.order.SignatureWaivers) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) PolicyBasedSigWaivers(com.hedera.services.sigs.order.PolicyBasedSigWaivers) MiscSpeedometers(com.hedera.services.stats.MiscSpeedometers) EntityNumbers(com.hedera.services.config.EntityNumbers) KeyActivationCharacteristics(com.hedera.services.keys.KeyActivationCharacteristics) NEW_ACCOUNT_KT(com.hedera.test.factories.scenarios.CryptoCreateScenarios.NEW_ACCOUNT_KT) FileNumbers(com.hedera.services.config.FileNumbers) HederaKeyActivation(com.hedera.services.keys.HederaKeyActivation) SystemOpPolicies(com.hedera.services.txns.auth.SystemOpPolicies) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) DEFAULT_ACTIVATION_CHARACTERISTICS(com.hedera.services.keys.DefaultActivationCharacteristics.DEFAULT_ACTIVATION_CHARACTERISTICS) CRYPTO_CREATE_COMPLEX_PAYER_RECEIVER_SIG_SCENARIO(com.hedera.test.factories.scenarios.CryptoCreateScenarios.CRYPTO_CREATE_COMPLEX_PAYER_RECEIVER_SIG_SCENARIO) DEFAULT_PAYER_KT(com.hedera.test.factories.txns.SignedTxnFactory.DEFAULT_PAYER_KT) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SigningOrderResult(com.hedera.services.sigs.order.SigningOrderResult) HederaToPlatformSigOps.expandIn(com.hedera.services.sigs.HederaToPlatformSigOps.expandIn) TxnHandlingScenario(com.hedera.test.factories.scenarios.TxnHandlingScenario) CryptoCreateFactory(com.hedera.test.factories.txns.CryptoCreateFactory) SigWrappers.asKind(com.hedera.test.factories.sigs.SigWrappers.asKind) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_SCENARIO(com.hedera.test.factories.scenarios.CryptoUpdateScenarios.CRYPTO_UPDATE_COMPLEX_KEY_ACCOUNT_SCENARIO) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) VALID(com.swirlds.common.crypto.VerificationStatus.VALID) MockEntityNumbers(com.hedera.services.config.MockEntityNumbers) HederaFs(com.hedera.services.files.HederaFs) TransactionSignature(com.swirlds.common.crypto.TransactionSignature) HederaKeyActivation.payerSigIsActive(com.hedera.services.keys.HederaKeyActivation.payerSigIsActive) AbstractMap(java.util.AbstractMap) INVALID_PAYER_ID_SCENARIO(com.hedera.test.factories.scenarios.BadPayerScenarios.INVALID_PAYER_ID_SCENARIO) BDDMockito.mock(org.mockito.BDDMockito.mock) SigMetadataLookup(com.hedera.services.sigs.metadata.SigMetadataLookup) MockFileNumbers(com.hedera.services.config.MockFileNumbers) CRYPTO_UPDATE_MISSING_ACCOUNT_SCENARIO(com.hedera.test.factories.scenarios.CryptoUpdateScenarios.CRYPTO_UPDATE_MISSING_ACCOUNT_SCENARIO) AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) TransactionSignature(com.swirlds.common.crypto.TransactionSignature)

Example 9 with AliasManager

use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.

the class SignedTxnAccessorTest method parsesLegacyCorrectly.

@Test
void parsesLegacyCorrectly() throws Exception {
    final Key aPrimitiveKey = Key.newBuilder().setEd25519(ByteString.copyFromUtf8("01234567890123456789012345678901")).build();
    final ByteString aNewAlias = aPrimitiveKey.toByteString();
    final AliasManager aliasManager = mock(AliasManager.class);
    given(aliasManager.lookupIdBy(any())).willReturn(EntityNum.MISSING_NUM);
    final long offeredFee = 100_000_000L;
    var xferNoAliases = RequestBuilder.getCryptoTransferRequest(1234l, 0l, 0l, 3l, 0l, 0l, offeredFee, Timestamp.getDefaultInstance(), Duration.getDefaultInstance(), false, zeroByteMemo, 5678l, -70000l, 5679l, 70000l);
    xferNoAliases = xferNoAliases.toBuilder().setSigMap(expectedMap).build();
    var xferWithAutoCreation = RequestBuilder.getHbarCryptoTransferRequestToAlias(1234l, 0l, 0l, 3l, 0l, 0l, offeredFee, Timestamp.getDefaultInstance(), Duration.getDefaultInstance(), false, zeroByteMemo, 5678l, -70000l, aNewAlias, 70000l);
    xferWithAutoCreation = xferWithAutoCreation.toBuilder().setSigMap(expectedMap).build();
    var xferWithAliasesNoAutoCreation = RequestBuilder.getTokenTransferRequestToAlias(1234l, 0l, 0l, 3l, 0l, 0l, offeredFee, Timestamp.getDefaultInstance(), Duration.getDefaultInstance(), false, zeroByteMemo, 5678l, 5555l, -70000l, ByteString.copyFromUtf8("aaaa"), 70000l);
    xferWithAliasesNoAutoCreation = xferWithAliasesNoAutoCreation.toBuilder().setSigMap(expectedMap).build();
    final var body = CommonUtils.extractTransactionBody(xferNoAliases);
    var accessor = SignedTxnAccessor.uncheckedFrom(xferNoAliases);
    accessor.countAutoCreationsWith(aliasManager);
    final var txnUsageMeta = accessor.baseUsageMeta();
    assertEquals(xferNoAliases, accessor.getSignedTxnWrapper());
    assertArrayEquals(xferNoAliases.toByteArray(), accessor.getSignedTxnWrapperBytes());
    assertEquals(body, accessor.getTxn());
    assertArrayEquals(body.toByteArray(), accessor.getTxnBytes());
    assertEquals(body.getTransactionID(), accessor.getTxnId());
    assertEquals(1234l, accessor.getPayer().getAccountNum());
    assertEquals(HederaFunctionality.CryptoTransfer, accessor.getFunction());
    assertEquals(offeredFee, accessor.getOfferedFee());
    assertArrayEquals(CommonUtils.noThrowSha384HashOf(xferNoAliases.toByteArray()), accessor.getHash());
    assertEquals(expectedMap, accessor.getSigMap());
    assertArrayEquals("irst".getBytes(), accessor.getPkToSigsFn().sigBytesFor("f".getBytes()));
    assertArrayEquals(zeroByteMemoUtf8Bytes, accessor.getMemoUtf8Bytes());
    assertTrue(accessor.memoHasZeroByte());
    assertEquals(FeeBuilder.getSignatureCount(accessor.getSignedTxnWrapper()), accessor.numSigPairs());
    assertEquals(FeeBuilder.getSignatureSize(accessor.getSignedTxnWrapper()), accessor.sigMapSize());
    assertEquals(zeroByteMemo, accessor.getMemo());
    assertEquals(false, accessor.isTriggeredTxn());
    assertEquals(false, accessor.canTriggerTxn());
    assertEquals(0, accessor.getNumAutoCreations());
    assertEquals(memoUtf8Bytes.length, txnUsageMeta.memoUtf8Bytes());
    accessor = SignedTxnAccessor.uncheckedFrom(xferWithAutoCreation);
    accessor.countAutoCreationsWith(aliasManager);
    assertEquals(1, accessor.getNumAutoCreations());
    accessor = SignedTxnAccessor.uncheckedFrom(xferWithAliasesNoAutoCreation);
    accessor.countAutoCreationsWith(aliasManager);
    assertEquals(0, accessor.getNumAutoCreations());
}
Also used : AliasManager(com.hedera.services.ledger.accounts.AliasManager) ByteString(com.google.protobuf.ByteString) Key(com.hederahashgraph.api.proto.java.Key) Test(org.junit.jupiter.api.Test)

Aggregations

AliasManager (com.hedera.services.ledger.accounts.AliasManager)9 Test (org.junit.jupiter.api.Test)6 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)5 SigRequirements (com.hedera.services.sigs.order.SigRequirements)4 MerkleMap (com.swirlds.merkle.map.MerkleMap)4 ReusableBodySigningFactory (com.hedera.services.sigs.factories.ReusableBodySigningFactory)3 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)3 PojoSigMapPubKeyToSigBytes (com.hedera.services.sigs.sourcing.PojoSigMapPubKeyToSigBytes)3 SyncVerifier (com.hedera.services.sigs.verification.SyncVerifier)3 MiscRunningAvgs (com.hedera.services.stats.MiscRunningAvgs)3 MiscSpeedometers (com.hedera.services.stats.MiscSpeedometers)3 EntityNum (com.hedera.services.utils.EntityNum)3 EntityNumbers (com.hedera.services.config.EntityNumbers)2 FileNumbers (com.hedera.services.config.FileNumbers)2 MockEntityNumbers (com.hedera.services.config.MockEntityNumbers)2 MockFileNumbers (com.hedera.services.config.MockFileNumbers)2 HederaFs (com.hedera.services.files.HederaFs)2 DEFAULT_ACTIVATION_CHARACTERISTICS (com.hedera.services.keys.DefaultActivationCharacteristics.DEFAULT_ACTIVATION_CHARACTERISTICS)2 HederaKeyActivation (com.hedera.services.keys.HederaKeyActivation)2 ONLY_IF_SIG_IS_VALID (com.hedera.services.keys.HederaKeyActivation.ONLY_IF_SIG_IS_VALID)2