Search in sources :

Example 11 with ECPublicKey

use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.

the class ValidatorUpdateRakeConstraintScrypt method main.

@Override
public void main(Loader os) {
    os.substate(new SubstateDefinition<>(ValidatorFeeCopy.class, SubstateTypeId.VALIDATOR_RAKE_COPY.id(), buf -> {
        REFieldSerialization.deserializeReservedByte(buf);
        OptionalLong epochUpdate = REFieldSerialization.deserializeOptionalNonNegativeLong(buf);
        var key = REFieldSerialization.deserializeKey(buf);
        var curRakePercentage = REFieldSerialization.deserializeInt(buf);
        if (curRakePercentage < RAKE_MIN || curRakePercentage > RAKE_MAX) {
            throw new DeserializeException("Invalid rake percentage " + curRakePercentage);
        }
        return new ValidatorFeeCopy(epochUpdate, key, curRakePercentage);
    }, (s, buf) -> {
        REFieldSerialization.serializeReservedByte(buf);
        REFieldSerialization.serializeOptionalLong(buf, s.epochUpdate());
        REFieldSerialization.serializeKey(buf, s.validatorKey());
        buf.putInt(s.curRakePercentage());
    }, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> ValidatorFeeCopy.createVirtual((ECPublicKey) k)));
    os.procedure(new DownProcedure<>(VoidReducerState.class, ValidatorFeeCopy.class, d -> new Authorization(PermissionLevel.USER, (r, c) -> {
        if (!c.key().map(d.validatorKey()::equals).orElse(false)) {
            throw new AuthorizationException("Key does not match.");
        }
    }), (d, s, r, c) -> {
        return ReducerResult.incomplete(new UpdatingRakeNeedToReadCurrentRake(d.validatorKey()));
    }));
    os.procedure(new ReadProcedure<>(UpdatingRakeNeedToReadEpoch.class, EpochData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, r) -> ReducerResult.incomplete(s.readEpoch(u))));
    os.procedure(new ReadProcedure<>(UpdatingRakeNeedToReadCurrentRake.class, ValidatorStakeData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, r) -> ReducerResult.incomplete(s.readValidatorStakeState(u))));
    os.procedure(new UpProcedure<>(UpdatingRakeReady.class, ValidatorFeeCopy.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, c, r) -> {
        s.update(u);
        return ReducerResult.complete();
    }));
}
Also used : SubstateTypeId(com.radixdlt.atom.SubstateTypeId) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) ReducerResult(com.radixdlt.constraintmachine.ReducerResult) ReadProcedure(com.radixdlt.constraintmachine.ReadProcedure) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) Loader(com.radixdlt.atomos.Loader) ReducerState(com.radixdlt.constraintmachine.ReducerState) ValidatorStakeData(com.radixdlt.application.system.state.ValidatorStakeData) 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) Objects(java.util.Objects) OptionalLong(java.util.OptionalLong) UpProcedure(com.radixdlt.constraintmachine.UpProcedure) ValidatorFeeCopy(com.radixdlt.application.validators.state.ValidatorFeeCopy) ConstraintScrypt(com.radixdlt.atomos.ConstraintScrypt) DownProcedure(com.radixdlt.constraintmachine.DownProcedure) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException) DeserializeException(com.radixdlt.serialization.DeserializeException) EpochData(com.radixdlt.application.system.state.EpochData) EpochData(com.radixdlt.application.system.state.EpochData) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) DeserializeException(com.radixdlt.serialization.DeserializeException) Authorization(com.radixdlt.constraintmachine.Authorization) ValidatorStakeData(com.radixdlt.application.system.state.ValidatorStakeData) OptionalLong(java.util.OptionalLong) ValidatorFeeCopy(com.radixdlt.application.validators.state.ValidatorFeeCopy)

Example 12 with ECPublicKey

use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.

the class ValidatorUpdateOwnerConstraintScrypt method main.

@Override
public void main(Loader os) {
    os.substate(new SubstateDefinition<>(ValidatorOwnerCopy.class, SubstateTypeId.VALIDATOR_OWNER_COPY.id(), buf -> {
        REFieldSerialization.deserializeReservedByte(buf);
        OptionalLong epochUpdate = REFieldSerialization.deserializeOptionalNonNegativeLong(buf);
        var key = REFieldSerialization.deserializeKey(buf);
        var owner = REFieldSerialization.deserializeAccountREAddr(buf);
        return new ValidatorOwnerCopy(epochUpdate, key, owner);
    }, (s, buf) -> {
        REFieldSerialization.serializeReservedByte(buf);
        REFieldSerialization.serializeOptionalLong(buf, s.epochUpdate());
        REFieldSerialization.serializeKey(buf, s.validatorKey());
        REFieldSerialization.serializeREAddr(buf, s.owner());
    }, buf -> REFieldSerialization.deserializeKey(buf), (k, buf) -> REFieldSerialization.serializeKey(buf, (ECPublicKey) k), k -> ValidatorOwnerCopy.createVirtual((ECPublicKey) k)));
    os.procedure(new DownProcedure<>(VoidReducerState.class, ValidatorOwnerCopy.class, d -> new Authorization(PermissionLevel.USER, (r, c) -> {
        if (!c.key().map(d.validatorKey()::equals).orElse(false)) {
            throw new AuthorizationException("Key does not match.");
        }
    }), (d, s, r, c) -> ReducerResult.incomplete(new UpdatingOwnerNeedToReadEpoch(d.validatorKey()))));
    os.procedure(new ReadProcedure<>(UpdatingOwnerNeedToReadEpoch.class, EpochData.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, r) -> ReducerResult.incomplete(s.readEpoch(u))));
    os.procedure(new UpProcedure<>(UpdatingValidatorOwner.class, ValidatorOwnerCopy.class, u -> new Authorization(PermissionLevel.USER, (r, c) -> {
    }), (s, u, c, r) -> {
        s.update(u);
        return ReducerResult.complete();
    }));
}
Also used : SubstateTypeId(com.radixdlt.atom.SubstateTypeId) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) ReducerResult(com.radixdlt.constraintmachine.ReducerResult) ReadProcedure(com.radixdlt.constraintmachine.ReadProcedure) 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) OptionalLong(java.util.OptionalLong) UpProcedure(com.radixdlt.constraintmachine.UpProcedure) ConstraintScrypt(com.radixdlt.atomos.ConstraintScrypt) ValidatorOwnerCopy(com.radixdlt.application.validators.state.ValidatorOwnerCopy) DownProcedure(com.radixdlt.constraintmachine.DownProcedure) ProcedureException(com.radixdlt.constraintmachine.exceptions.ProcedureException) EpochData(com.radixdlt.application.system.state.EpochData) EpochData(com.radixdlt.application.system.state.EpochData) VoidReducerState(com.radixdlt.constraintmachine.VoidReducerState) AuthorizationException(com.radixdlt.constraintmachine.exceptions.AuthorizationException) Authorization(com.radixdlt.constraintmachine.Authorization) ValidatorOwnerCopy(com.radixdlt.application.validators.state.ValidatorOwnerCopy) OptionalLong(java.util.OptionalLong)

Example 13 with ECPublicKey

use of com.radixdlt.crypto.ECPublicKey in project radixdlt by radixdlt.

the class SimulationNodes method createBFTInstance.

private Injector createBFTInstance(ECKeyPair self) {
    Module module = Modules.combine(new AbstractModule() {

        @Provides
        @Self
        private BFTNode self() {
            return BFTNode.create(self.getPublicKey());
        }

        @Provides
        @Self
        private ECPublicKey key() {
            return self.getPublicKey();
        }

        @Provides
        @LocalSigner
        HashSigner hashSigner() {
            return self::sign;
        }
    }, new NodeNetworkMessagesModule(underlyingNetwork), baseModule);
    // can break network behavior if incorrect modules are used
    if (overrideModule != null) {
        module = Modules.override(module).with(overrideModule);
    }
    Module byzantineModule = byzantineNodeModules.get(self);
    if (byzantineModule != null) {
        module = Modules.override(module).with(byzantineModule);
    }
    return Guice.createInjector(module);
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) ECPublicKey(com.radixdlt.crypto.ECPublicKey) LocalSigner(com.radixdlt.qualifier.LocalSigner) NodeNetworkMessagesModule(com.radixdlt.harness.simulation.NodeNetworkMessagesModule) HashSigner(com.radixdlt.consensus.HashSigner) Self(com.radixdlt.consensus.bft.Self) Module(com.google.inject.Module) NodeNetworkMessagesModule(com.radixdlt.harness.simulation.NodeNetworkMessagesModule) AbstractModule(com.google.inject.AbstractModule) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule)

Aggregations

ECPublicKey (com.radixdlt.crypto.ECPublicKey)13 REFieldSerialization (com.radixdlt.atom.REFieldSerialization)5 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)5 ConstraintScrypt (com.radixdlt.atomos.ConstraintScrypt)5 Loader (com.radixdlt.atomos.Loader)5 SubstateDefinition (com.radixdlt.atomos.SubstateDefinition)5 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)5 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)5 EpochData (com.radixdlt.application.system.state.EpochData)4 Authorization (com.radixdlt.constraintmachine.Authorization)4 DownProcedure (com.radixdlt.constraintmachine.DownProcedure)4 PermissionLevel (com.radixdlt.constraintmachine.PermissionLevel)4 ReducerResult (com.radixdlt.constraintmachine.ReducerResult)4 ReducerState (com.radixdlt.constraintmachine.ReducerState)4 UpProcedure (com.radixdlt.constraintmachine.UpProcedure)4 VoidReducerState (com.radixdlt.constraintmachine.VoidReducerState)4 AbstractModule (com.google.inject.AbstractModule)3 Provides (com.google.inject.Provides)3 ReadProcedure (com.radixdlt.constraintmachine.ReadProcedure)3 AuthorizationException (com.radixdlt.constraintmachine.exceptions.AuthorizationException)3