Skip to content

Commit

Permalink
Update to 1.18.3, local tests passing
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan <[email protected]>
  • Loading branch information
ryan-s-roberts committed Jul 25, 2022
1 parent 47c5394 commit fc91130
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -13,7 +13,7 @@
*/
package com.blockchaintp.daml.address;

import com.daml.ledger.participant.state.kvutils.DamlKvutils;
import com.daml.ledger.participant.state.kvutils.store.DamlStateKey;

/**
* A generic identifier.
Expand All @@ -23,5 +23,5 @@ public interface Identifier {
*
* @return The state key;
*/
DamlKvutils.DamlStateKey toKey();
DamlStateKey toKey();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -13,24 +13,24 @@
*/
package com.blockchaintp.daml.address;

import com.daml.ledger.participant.state.kvutils.DamlKvutils;
import com.daml.ledger.participant.state.kvutils.store.DamlStateKey;

/**
*
*/
public final class QldbAddress implements LedgerAddress {
private final DamlKvutils.DamlStateKey data;
private final DamlStateKey data;

/**
*
* @param theData
*/
public QldbAddress(final DamlKvutils.DamlStateKey theData) {
public QldbAddress(final DamlStateKey theData) {
data = theData;
}

@Override
public DamlKvutils.DamlStateKey toKey() {
public DamlStateKey toKey() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -15,24 +15,24 @@

import java.util.Objects;

import com.daml.ledger.participant.state.kvutils.DamlKvutils;
import com.daml.ledger.participant.state.kvutils.store.DamlStateKey;

/**
*
*/
public final class QldbIdentifier implements Identifier {
private final DamlKvutils.DamlStateKey data;
private final DamlStateKey data;

/**
*
* @param theData
*/
public QldbIdentifier(final DamlKvutils.DamlStateKey theData) {
public QldbIdentifier(final DamlStateKey theData) {
data = theData;
}

@Override
public DamlKvutils.DamlStateKey toKey() {
public DamlStateKey toKey() {
return data;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -19,6 +19,7 @@
import java.util.stream.Stream;

import com.blockchaintp.daml.address.Identifier;
import com.blockchaintp.daml.address.LedgerAddress;
import com.daml.ledger.participant.state.kvutils.Raw;
import com.daml.ledger.participant.state.kvutils.api.CommitMetadata;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -28,9 +28,9 @@
import com.blockchaintp.utility.Functions;
import com.blockchaintp.utility.UuidConverter;
import com.daml.api.util.TimeProvider;
import com.daml.ledger.participant.state.kvutils.DamlKvutils;
import com.daml.ledger.participant.state.kvutils.Raw;
import com.daml.ledger.participant.state.v1.SubmissionResult;
import com.daml.ledger.participant.state.kvutils.store.DamlLogEntryId;
import com.daml.ledger.participant.state.v2.SubmissionResult;
import com.daml.ledger.validator.SubmissionValidator$;
import com.daml.ledger.validator.ValidatingCommitter;
import com.daml.lf.engine.Engine;
Expand Down Expand Up @@ -78,8 +78,8 @@ public static <I extends Identifier, A extends LedgerAddress> InProcLedgerSubmit
* @param id
* @return A daml log entry id parsed from a daml log entry id.
*/
private DamlKvutils.DamlLogEntryId logEntryIdToDamlLogEntryId(final Raw.LogEntryId id) {
var parsed = Functions.uncheckFn(() -> DamlKvutils.DamlLogEntryId.parseFrom(id.bytes())).apply();
private DamlLogEntryId logEntryIdToDamlLogEntryId(final Raw.LogEntryId id) {
var parsed = Functions.uncheckFn(() -> DamlLogEntryId.parseFrom(id.bytes())).apply();

LOG.info("parse log id {}", () -> parsed.getEntryId().toString());

Expand Down Expand Up @@ -107,7 +107,7 @@ public InProcLedgerSubmitter(final Engine theEngine, final Metrics theMetrics,
new StateAccess(CoercingStore.from(Bijection.of(Raw.StateKey::bytes, Raw.StateKey$.MODULE$::apply),
Bijection.of(Raw.Envelope::bytes, Raw.Envelope$.MODULE$::apply), theStateStore), writer),
() -> logEntryIdToDamlLogEntryId(UuidConverter.uuidtoLogEntry(UUID.randomUUID())), false,
new StateCache<>(new LRUCache<>(STATE_CACHE_SIZE)), theEngine, theMetrics, false),
new StateCache<>(new LRUCache<>(STATE_CACHE_SIZE)), theEngine, theMetrics),
r -> {
/// New head should be end of sequence, i.e. one past the actual head. This should really have a
/// nicer type, we ensure it is monotonic here
Expand All @@ -133,7 +133,7 @@ public CompletableFuture<SubmissionStatus> submitPayload(final CommitPayload<A>
if (x == SubmissionResult.Acknowledged$.MODULE$) {
return SubmissionStatus.SUBMITTED;
}
if (x == SubmissionResult.NotSupported$.MODULE$) {
if (x instanceof SubmissionResult.SynchronousError) {
return SubmissionStatus.REJECTED;
}
LOG.info("Overloaded {} {} ", cp.getCorrelationId(), x);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -25,15 +25,17 @@
import com.blockchaintp.daml.address.Identifier;
import com.blockchaintp.daml.address.LedgerAddress;
import com.blockchaintp.daml.stores.service.TransactionLogReader;

import com.daml.ledger.offset.Offset;
import com.daml.ledger.participant.state.kvutils.KVOffsetBuilder;
import com.daml.ledger.api.health.HealthStatus;
import com.daml.ledger.participant.state.kvutils.OffsetBuilder;
import com.daml.ledger.participant.state.kvutils.KVOffsetBuilder$;
import com.daml.ledger.participant.state.kvutils.Raw;
import com.daml.ledger.participant.state.kvutils.api.CommitMetadata;
import com.daml.ledger.participant.state.kvutils.api.LedgerReader;
import com.daml.ledger.participant.state.kvutils.api.LedgerRecord;
import com.daml.ledger.participant.state.kvutils.api.LedgerWriter;
import com.daml.ledger.participant.state.v1.Offset;
import com.daml.ledger.participant.state.v1.SubmissionResult;
import com.daml.ledger.participant.state.v2.SubmissionResult;
import com.daml.platform.akkastreams.dispatcher.Dispatcher;
import com.daml.platform.akkastreams.dispatcher.SubSource.RangeSource;
import com.daml.telemetry.TelemetryContext;
Expand Down Expand Up @@ -65,6 +67,7 @@ public final class Participant<I extends Identifier, A extends LedgerAddress> im
private final BlockingDeque<CommitPayload<I>> submissions = new LinkedBlockingDeque<>();
private final ExecutionContextExecutor context;
private final ScheduledExecutorService pollExecutor;
private final KVOffsetBuilder offsetBuilder = new KVOffsetBuilder((byte) 0);

/**
* Convenience method for creating a builder.
Expand Down Expand Up @@ -131,16 +134,16 @@ public HealthStatus currentHealth() {
public akka.stream.scaladsl.Source<LedgerRecord, NotUsed> events(final Option<Offset> startExclusive) {
LOG.info("Get from {}", () -> startExclusive);

var start = OffsetBuilder.fromLong(0L, 0, 0);
var start = offsetBuilder.of(0L, 0, 0);

Ordering<Long> scalaLongOrdering = Ordering.comparatorToOrdering(Comparator.comparingLong(scala.Long::unbox));

var rangeSource = new RangeSource<>((s, e) -> Source
.fromJavaStream(() -> API.unchecked(() -> txLog.from(s - 1, Optional.of(e - 1))).apply()
.map(r -> Tuple2.apply(r._1, LedgerRecord.apply(OffsetBuilder.fromLong(r._1, 0, 0), r._2, r._3))))
.map(r -> Tuple2.apply(r._1, LedgerRecord.apply(offsetBuilder.of(r._1, 0, 0), r._2, r._3))))
.mapMaterializedValue(m -> NotUsed.notUsed()).asScala(), scalaLongOrdering);

var offset = OffsetBuilder.highestIndex(startExclusive.getOrElse(() -> start));
var offset = offsetBuilder.highestIndex(startExclusive.getOrElse(() -> start));
return dispatcher.startingAt(offset, rangeSource, Option.empty()).asJava().map(x -> {
LOG.debug("Yield log {} {}", x._1, x._2);
return x;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -28,6 +28,7 @@
import com.daml.ledger.validator.BatchingLedgerStateOperations;
import com.daml.ledger.validator.LedgerStateAccess;
import com.daml.ledger.validator.LedgerStateOperations;
import com.daml.logging.LoggingContext;

import kr.pe.kwonnam.slf4jlambda.LambdaLogger;
import kr.pe.kwonnam.slf4jlambda.LambdaLoggerFactory;
Expand Down Expand Up @@ -65,7 +66,7 @@ private class Operations extends BatchingLedgerStateOperations<Long> {

@Override
public Future<Seq<Option<Raw.Envelope>>> readState(final Iterable<Raw.StateKey> keys,
final ExecutionContext executionContext) {
final ExecutionContext executionContext, final LoggingContext loggingContext) {

var syncFuture = Future.fromTry(Try.apply(Functions.uncheckFn(() -> {
var sparseInputs = StreamConverters$.MODULE$.asJavaParStream(keys)
Expand All @@ -87,7 +88,7 @@ public Future<Seq<Option<Raw.Envelope>>> readState(final Iterable<Raw.StateKey>

@Override
public Future<BoxedUnit> writeState(final Iterable<scala.Tuple2<Raw.StateKey, Raw.Envelope>> keyValuePairs,
final ExecutionContext executionContext) {
final ExecutionContext executionContext, final LoggingContext loggingContext) {
LOG.debug("Write state {}", keyValuePairs);
var syncFuture = Future.fromTry(Try.apply(Functions.uncheckFn(() -> {
stateStore.put(new ArrayList<>(StreamConverters.asJavaParStream(keyValuePairs)
Expand All @@ -108,7 +109,7 @@ public Future<BoxedUnit> writeState(final Iterable<scala.Tuple2<Raw.StateKey, Ra
*/
@Override
public Future<Long> appendToLog(final Raw.LogEntryId key, final Raw.Envelope value,
final ExecutionContext executionContext) {
final ExecutionContext executionContext, final LoggingContext loggingContext) {

var work = sequenceAllocation.serialisedBegin(key)
.thenCompose(seq -> CompletableFuture.supplyAsync(() -> Functions.uncheckFn(() -> {
Expand All @@ -124,7 +125,7 @@ public Future<Long> appendToLog(final Raw.LogEntryId key, final Raw.Envelope val

@Override
public <T> Future<T> inTransaction(final Function1<LedgerStateOperations<Long>, Future<T>> body,
final ExecutionContext executionContext) {
final ExecutionContext executionContext, final LoggingContext loggingContext) {
return Future.delegate(() -> body.apply(new Operations()), executionContext);
}
}
12 changes: 5 additions & 7 deletions core/src/main/java/com/blockchaintp/utility/UuidConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -16,8 +16,8 @@
import java.nio.ByteBuffer;
import java.util.UUID;

import com.daml.ledger.participant.state.kvutils.DamlKvutils;
import com.daml.ledger.participant.state.kvutils.Raw;
import com.daml.ledger.participant.state.kvutils.store.DamlLogEntryId;
import com.google.protobuf.ByteString;

import io.vavr.API;
Expand All @@ -37,9 +37,7 @@ private UuidConverter() {
* @return The UUID encoded as the entry id from the log id.
*/
public static UUID logEntryToUuid(final Raw.LogEntryId id) {
return API
.unchecked(
() -> UuidConverter.asUuid(DamlKvutils.DamlLogEntryId.parseFrom(id.bytes()).getEntryId().toByteArray()))
return API.unchecked(() -> UuidConverter.asUuid(DamlLogEntryId.parseFrom(id.bytes()).getEntryId().toByteArray()))
.apply();
}

Expand All @@ -49,8 +47,8 @@ public static UUID logEntryToUuid(final Raw.LogEntryId id) {
* @return A log entry id with the encoded UUID as its entry id.
*/
public static Raw.LogEntryId uuidtoLogEntry(final UUID id) {
return Raw.LogEntryId$.MODULE$.apply(
DamlKvutils.DamlLogEntryId.newBuilder().setEntryId(ByteString.copyFrom(UuidConverter.asBytes(id))).build());
return Raw.LogEntryId$.MODULE$
.apply(DamlLogEntryId.newBuilder().setEntryId(ByteString.copyFrom(UuidConverter.asBytes(id))).build());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -49,7 +49,8 @@ abstract class BuilderLedgerFactory[
} yield new KeyValueParticipantState(
readerWriter,
readerWriter,
metrics
metrics,
false
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Blockchain Technology Partners
* Copyright 2021-2022 Blockchain Technology Partners
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -18,6 +18,7 @@ import com.blockchaintp.daml.address.LedgerAddress
import com.blockchaintp.daml.participant.Participant
import com.blockchaintp.daml.participant.ParticipantBuilder
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.participant.state.index.v2.LedgerConfiguration
import com.daml.ledger.participant.state.kvutils.app.Config
import com.daml.ledger.resources.Resource
import com.daml.ledger.resources.ResourceContext
Expand All @@ -26,7 +27,6 @@ import com.daml.lf.data.Ref.ParticipantId
import com.daml.lf.engine.Engine
import com.daml.logging.LoggingContext
import com.daml.metrics.Metrics
import com.daml.platform.configuration.LedgerConfiguration
import com.daml.resources

import java.util.concurrent.Executors
Expand Down
Loading

0 comments on commit fc91130

Please sign in to comment.