Search in sources :

Example 1 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class TimestampedECDSASignatures method fromJSON.

public static TimestampedECDSASignatures fromJSON(JSONArray json) throws DeserializeException {
    var builder = ImmutableMap.<BFTNode, TimestampedECDSASignature>builder();
    for (int i = 0; i < json.length(); i++) {
        var signatureJson = json.getJSONObject(i);
        try {
            var key = ECPublicKey.fromHex(signatureJson.getString("key"));
            var bytes = Bytes.fromHexString(signatureJson.getString("signature"));
            var signature = REFieldSerialization.deserializeSignature(ByteBuffer.wrap(bytes));
            var timestamp = signatureJson.getLong("timestamp");
            builder.put(BFTNode.create(key), TimestampedECDSASignature.from(timestamp, signature));
        } catch (PublicKeyException e) {
            throw new DeserializeException(e.getMessage());
        }
    }
    return new TimestampedECDSASignatures(builder.build());
}
Also used : BFTNode(com.radixdlt.consensus.bft.BFTNode) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Example 2 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class BerkeleySafetyStateStore method get.

@Override
public Optional<SafetyState> get() {
    final var start = System.nanoTime();
    try (com.sleepycat.je.Cursor cursor = this.safetyStore.openCursor(null, null)) {
        DatabaseEntry pKey = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        OperationStatus status = cursor.getLast(pKey, value, LockMode.DEFAULT);
        if (status == OperationStatus.SUCCESS) {
            addBytesRead(pKey.getSize() + value.getSize());
            try {
                final SafetyState deserializedState = serialization.fromDson(value.getData(), SafetyState.class);
                return Optional.of(deserializedState);
            } catch (DeserializeException ex) {
                logger.error("Failed to deserialize persisted SafetyState", ex);
                return Optional.empty();
            }
        } else {
            return Optional.empty();
        }
    } finally {
        addTime(start);
    }
}
Also used : SafetyState(com.radixdlt.hotstuff.safety.SafetyState) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DeserializeException(com.radixdlt.serialization.DeserializeException) Cursor(com.sleepycat.je.Cursor)

Example 3 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class CodecBenchmark method jacksonFromJsonTest.

@Benchmark
public void jacksonFromJsonTest(Blackhole bh) {
    try {
        DummyTestObject newObj = serialization.fromJson(jacksonJson, DummyTestObject.class);
        bh.consume(newObj);
    } catch (DeserializeException ex) {
        throw new IllegalStateException("While deserializing from JSON", ex);
    }
}
Also used : DummyTestObject(org.radix.serialization.DummyTestObject) DeserializeException(com.radixdlt.serialization.DeserializeException) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 4 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class CandidateForkVotesPostProcessor method extractBftNodeAndVoteIfPresent.

private Optional<Pair<BFTNode, CandidateForkVote>> extractBftNodeAndVoteIfPresent(RawSubstateBytes rawSubstateBytes) {
    try {
        final var validatorSystemMetadataSubstate = (ValidatorSystemMetadata) substateDeserialization.deserialize(rawSubstateBytes.getData());
        if (Bytes.isAllZeros(validatorSystemMetadataSubstate.data())) {
            return Optional.empty();
        }
        final var candidateForkVote = new CandidateForkVote(HashCode.fromBytes(validatorSystemMetadataSubstate.data()));
        return Optional.of(Pair.of(BFTNode.create(validatorSystemMetadataSubstate.validatorKey()), candidateForkVote));
    } catch (DeserializeException e) {
        throw new PostProcessorException("Error deserializing ValidatorSystemMetadata");
    }
}
Also used : ValidatorSystemMetadata(com.radixdlt.application.validators.state.ValidatorSystemMetadata) DeserializeException(com.radixdlt.serialization.DeserializeException) CandidateForkVote(com.radixdlt.statecomputer.forks.CandidateForkVote) PostProcessorException(com.radixdlt.engine.PostProcessorException)

Example 5 with DeserializeException

use of com.radixdlt.serialization.DeserializeException in project radixdlt by radixdlt.

the class REFieldSerialization method deserializeKey.

public static ECPublicKey deserializeKey(ByteBuffer buf) throws DeserializeException {
    try {
        var keyBytes = new byte[33];
        buf.get(keyBytes);
        return ECPublicKey.fromBytes(keyBytes);
    } catch (PublicKeyException | IllegalArgumentException e) {
        throw new DeserializeException("Could not deserialize key");
    }
}
Also used : PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Aggregations

DeserializeException (com.radixdlt.serialization.DeserializeException)13 PublicKeyException (com.radixdlt.crypto.exception.PublicKeyException)3 REFieldSerialization (com.radixdlt.atom.REFieldSerialization)2 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)2 ConstraintScrypt (com.radixdlt.atomos.ConstraintScrypt)2 Loader (com.radixdlt.atomos.Loader)2 SubstateDefinition (com.radixdlt.atomos.SubstateDefinition)2 ProcedureException (com.radixdlt.constraintmachine.exceptions.ProcedureException)2 SubstateDeserializationException (com.radixdlt.engine.parser.exceptions.SubstateDeserializationException)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 SubstateOperation (com.radixdlt.api.core.model.SubstateOperation)1 SystemConstraintScrypt (com.radixdlt.application.system.scrypt.SystemConstraintScrypt)1 EpochData (com.radixdlt.application.system.state.EpochData)1 ValidatorStakeData (com.radixdlt.application.system.state.ValidatorStakeData)1 TokenResource (com.radixdlt.application.tokens.state.TokenResource)1 TokenResourceMetadata (com.radixdlt.application.tokens.state.TokenResourceMetadata)1 TokensInAccount (com.radixdlt.application.tokens.state.TokensInAccount)1 ValidatorFeeCopy (com.radixdlt.application.validators.state.ValidatorFeeCopy)1 ValidatorSystemMetadata (com.radixdlt.application.validators.state.ValidatorSystemMetadata)1 BFTNode (com.radixdlt.consensus.bft.BFTNode)1