Search in sources :

Example 1 with RoundData

use of com.radixdlt.application.system.state.RoundData in project radixdlt by radixdlt.

the class RadixEngineStateComputerTest method preparing_system_update_from_vertex_should_fail.

@Test
public void preparing_system_update_from_vertex_should_fail() throws TxBuilderException {
    // Arrange
    var txn = radixEngine.construct(new NextRound(1, false, 0, i -> proposerElection.getProposer(View.of(i)).getKey())).buildWithoutSignature();
    var illegalTxn = TxLowLevelBuilder.newBuilder(currentForkView.currentForkConfig().engineRules().serialization()).down(SubstateId.ofSubstate(txn.getId(), 1)).up(new RoundData(2, 0)).end().build();
    var v = UnverifiedVertex.create(mock(QuorumCertificate.class), View.of(1), List.of(illegalTxn), proposerElection.getProposer(View.of(1)));
    var vertex = new VerifiedVertex(v, mock(HashCode.class));
    // Act
    var result = sut.prepare(ImmutableList.of(), vertex, 0);
    // Assert
    assertThat(result.getSuccessfulCommands()).hasSize(1);
    assertThat(result.getFailedCommands()).hasValueSatisfying(new Condition<>(e -> {
        var ex = (RadixEngineException) e;
        var cmException = (ConstraintMachineException) ex.getCause();
        return cmException.getCause() instanceof InvalidPermissionException;
    }, "Is invalid_execution_permission error"));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Module(com.google.inject.Module) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) NoOpCommittedReader(com.radixdlt.sync.NoOpCommittedReader) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) CurrentForkView(com.radixdlt.statecomputer.forks.CurrentForkView) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) NoOpForksEpochStore(com.radixdlt.statecomputer.forks.NoOpForksEpochStore) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) EngineStore(com.radixdlt.store.EngineStore) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Collectors(java.util.stream.Collectors) ForksEpochStore(com.radixdlt.statecomputer.forks.ForksEpochStore) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) Amount(com.radixdlt.application.tokens.Amount) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Serialization(com.radixdlt.serialization.Serialization) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) com.radixdlt.atom(com.radixdlt.atom) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) View(com.radixdlt.hotstuff.bft.View) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) HashCode(com.google.common.hash.HashCode) RoundData(com.radixdlt.application.system.state.RoundData) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 2 with RoundData

use of com.radixdlt.application.system.state.RoundData in project radixdlt by radixdlt.

the class NextViewConstructorV3 method construct.

@Override
public void construct(NextRound action, TxBuilder txBuilder) throws TxBuilderException {
    var prevRound = txBuilder.downSystem(RoundData.class);
    if (action.view() <= prevRound.view()) {
        throw new InvalidRoundException(prevRound.view(), action.view());
    }
    var validatorsToUpdate = new TreeMap<ECPublicKey, ValidatorBFTData>(KeyComparator.instance());
    for (long view = prevRound.view() + 1; view < action.view(); view++) {
        var missingLeader = action.leaderMapping().apply(view);
        if (!validatorsToUpdate.containsKey(missingLeader)) {
            var validatorData = txBuilder.down(ValidatorBFTData.class, missingLeader);
            validatorsToUpdate.put(missingLeader, validatorData);
        }
        var nextData = validatorsToUpdate.get(missingLeader).incrementProposalsMissed();
        validatorsToUpdate.put(missingLeader, nextData);
    }
    var curLeader = action.leaderMapping().apply(action.view());
    if (!validatorsToUpdate.containsKey(curLeader)) {
        var validatorData = txBuilder.down(ValidatorBFTData.class, curLeader);
        validatorsToUpdate.put(curLeader, validatorData);
    }
    var nextData = action.isTimeout() ? validatorsToUpdate.get(curLeader).incrementProposalsMissed() : validatorsToUpdate.get(curLeader).incrementCompletedProposals();
    validatorsToUpdate.put(curLeader, nextData);
    for (var e : validatorsToUpdate.entrySet()) {
        txBuilder.up(e.getValue());
    }
    txBuilder.up(new RoundData(action.view(), action.timestamp()));
    txBuilder.end();
}
Also used : RoundData(com.radixdlt.application.system.state.RoundData) TreeMap(java.util.TreeMap)

Example 3 with RoundData

use of com.radixdlt.application.system.state.RoundData in project radixdlt by radixdlt.

the class CreateSystemConstructorV2 method construct.

@Override
public void construct(CreateSystem action, TxBuilder builder) throws TxBuilderException {
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.UNCLAIMED_READDR.id() }));
    builder.end();
    builder.toLowLevelBuilder().syscall(Syscall.READDR_CLAIM, "sys".getBytes(StandardCharsets.UTF_8));
    builder.downREAddr(REAddr.ofSystem());
    builder.up(new EpochData(0));
    builder.up(new RoundData(0, action.timestamp()));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_META_DATA.id() }));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_STAKE_DATA.id() }));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_ALLOW_DELEGATION_FLAG.id() }));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_REGISTERED_FLAG_COPY.id() }));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_RAKE_COPY.id() }));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_OWNER_COPY.id() }));
    builder.up(new VirtualParent(new byte[] { SubstateTypeId.VALIDATOR_SYSTEM_META_DATA.id() }));
    builder.end();
}
Also used : EpochData(com.radixdlt.application.system.state.EpochData) RoundData(com.radixdlt.application.system.state.RoundData) VirtualParent(com.radixdlt.application.system.state.VirtualParent)

Aggregations

RoundData (com.radixdlt.application.system.state.RoundData)3 ImmutableList (com.google.common.collect.ImmutableList)1 HashCode (com.google.common.hash.HashCode)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Inject (com.google.inject.Inject)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 DefaultSerialization (com.radixdlt.DefaultSerialization)1 EpochData (com.radixdlt.application.system.state.EpochData)1 VirtualParent (com.radixdlt.application.system.state.VirtualParent)1 Amount (com.radixdlt.application.tokens.Amount)1 com.radixdlt.atom (com.radixdlt.atom)1 TxAction (com.radixdlt.atom.TxAction)1 PermissionLevel (com.radixdlt.constraintmachine.PermissionLevel)1 REEvent (com.radixdlt.constraintmachine.REEvent)1 ConstraintMachineException (com.radixdlt.constraintmachine.exceptions.ConstraintMachineException)1 InvalidPermissionException (com.radixdlt.constraintmachine.exceptions.InvalidPermissionException)1 SystemCounters (com.radixdlt.counters.SystemCounters)1 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)1