Search in sources :

Example 1 with ValidatorBFTData

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

the class RoundUpdateConstraintScrypt method main.

@Override
public void main(Loader os) {
    os.substate(new SubstateDefinition<>(ValidatorBFTData.class, SubstateTypeId.VALIDATOR_BFT_DATA.id(), buf -> {
        REFieldSerialization.deserializeReservedByte(buf);
        var key = REFieldSerialization.deserializeKey(buf);
        var proposalsCompleted = REFieldSerialization.deserializeNonNegativeLong(buf);
        var proposalsMissed = REFieldSerialization.deserializeNonNegativeLong(buf);
        return new ValidatorBFTData(key, proposalsCompleted, proposalsMissed);
    }, (s, buf) -> {
        REFieldSerialization.serializeReservedByte(buf);
        REFieldSerialization.serializeKey(buf, s.validatorKey());
        buf.putLong(s.completedProposals());
        buf.putLong(s.missedProposals());
    }, (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k)));
    os.procedure(new DownProcedure<>(VoidReducerState.class, RoundData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
    }), (d, s, r, c) -> ReducerResult.incomplete(new EndPrevRound(d))));
    os.procedure(new DownProcedure<>(EndPrevRound.class, ValidatorBFTData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
    }), (d, s, r, c) -> {
        var closedRound = s.getClosedRound().view();
        var next = new StartValidatorBFTUpdate(closedRound);
        next.beginUpdate(d);
        return ReducerResult.incomplete(next);
    }));
    os.procedure(new DownProcedure<>(StartValidatorBFTUpdate.class, ValidatorBFTData.class, d -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
    }), (d, s, r, c) -> ReducerResult.incomplete(s.beginUpdate(d))));
    os.procedure(new UpProcedure<>(StartValidatorBFTUpdate.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
    }), (s, u, c, r) -> {
        var next = s.exit();
        return ReducerResult.incomplete(next.update(u, c));
    }));
    os.procedure(new UpProcedure<>(UpdatingValidatorBFTData.class, ValidatorBFTData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
    }), (s, u, c, r) -> ReducerResult.incomplete(s.update(u, c))));
    os.procedure(new UpProcedure<>(StartNextRound.class, RoundData.class, u -> new Authorization(PermissionLevel.SUPER_USER, (r, c) -> {
    }), (s, u, c, r) -> {
        s.update(u);
        return ReducerResult.complete();
    }));
}
Also used : SubstateTypeId(com.radixdlt.atom.SubstateTypeId) ReducerResult(com.radixdlt.constraintmachine.ReducerResult) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) Loader(com.radixdlt.atomos.Loader) ReducerState(com.radixdlt.constraintmachine.ReducerState) REFieldSerialization(com.radixdlt.atom.REFieldSerialization) Authorization(com.radixdlt.constraintmachine.Authorization) SubstateDefinition(com.radixdlt.atomos.SubstateDefinition) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) ECPublicKey(com.radixdlt.crypto.ECPublicKey) RoundData(com.radixdlt.application.system.state.RoundData) UpProcedure(com.radixdlt.constraintmachine.UpProcedure) TreeMap(java.util.TreeMap) ConstraintScrypt(com.radixdlt.atomos.ConstraintScrypt) KeyComparator(com.radixdlt.utils.KeyComparator) DownProcedure(com.radixdlt.constraintmachine.DownProcedure) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException) ValidatorBFTData(com.radixdlt.application.system.state.ValidatorBFTData) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) RoundData(com.radixdlt.application.system.state.RoundData) ValidatorBFTData(com.radixdlt.application.system.state.ValidatorBFTData) Authorization(com.radixdlt.constraintmachine.Authorization)

Aggregations

RoundData (com.radixdlt.application.system.state.RoundData)1 ValidatorBFTData (com.radixdlt.application.system.state.ValidatorBFTData)1 REFieldSerialization (com.radixdlt.atom.REFieldSerialization)1 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)1 ConstraintScrypt (com.radixdlt.atomos.ConstraintScrypt)1 Loader (com.radixdlt.atomos.Loader)1 SubstateDefinition (com.radixdlt.atomos.SubstateDefinition)1 Authorization (com.radixdlt.constraintmachine.Authorization)1 DownProcedure (com.radixdlt.constraintmachine.DownProcedure)1 PermissionLevel (com.radixdlt.constraintmachine.PermissionLevel)1 ReducerResult (com.radixdlt.constraintmachine.ReducerResult)1 ReducerState (com.radixdlt.constraintmachine.ReducerState)1 UpProcedure (com.radixdlt.constraintmachine.UpProcedure)1 VoidReducerState (com.radixdlt.constraintmachine.VoidReducerState)1 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)1 ECPublicKey (com.radixdlt.crypto.ECPublicKey)1 KeyComparator (com.radixdlt.utils.KeyComparator)1 TreeMap (java.util.TreeMap)1