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"));
}
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();
}
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();
}
Aggregations