Commit Graph

748 Commits

Author SHA1 Message Date
Moritz Kiefer
b3a5c3b28d
Share test certificates (#4982)
* Share test certificates

This is primarily an attempt at making sure my contribution stats
remain negative but I think it’s a nice cleanup. The only difference
in the certs used by daml-helper which are now used everywhere is that
they use a different CN for the CA and the server. This is required to
make openssl happy (which is used by the daml-helper).

changelog_begin
changelog_end

* Fix script and trigger tests
2020-03-13 12:12:34 +01:00
Richard Kapolnai
d198f74d61
Fix ledgerId cli help message by removing note about persistent stores. (#4980)
* Fix ledgerId cli help message by removing note about persistent stores.

* format change
CHANGELOG_BEGIN
CHANGELOG_END

* Revert "format change"

This reverts commit 02e234df29.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-13 09:26:44 +00:00
Stefano Baghino
cc2e97ee51
Add functions to compute disclosure for different stream types (#4970)
* Add functions to compute disclosure for different stream types

CHANGELOG_BEGIN
CHANGELOG_END

* Address https://github.com/digital-asset/daml/pull/4970#pullrequestreview-373708955

* Optimize imports
2020-03-12 18:44:10 +01:00
Moritz Kiefer
fdeac8d69c
Make extractor and navigator work without client auth (#4966)
This PR fixes the tls configuration to work if client auth is not
enabled and adds a `--tls` flag to extractor and navigator which
allows you to enable tls without overriding any certificates.

There is a test for extractor but none for navigator since there are
no tls tests at all afaict atm. I did however test it manually.

changelog_begin

- [Navigator] Navigator can now run a TLS enabled ledger without
  client authentication. You can enable TLS without any special
  certificates by passing ``--tls``.

- [Extractor] Extractor can now run a TLS enabled ledger without
  client authentication. You can enable TLS without any special
  certificates by passing ``--tls``.

changelog_end
2020-03-12 17:33:30 +01:00
Moritz Kiefer
edd73384c4
Make client authentication in Sandbox configurable (#4965)
Currently sandbox only supports TLS if you also enable client
authentication. There is no reason for why this has to be the case and
for things like DABL we want TLS without client authentication so it’s
useful to be able to test this in sandbox. This PR introduces a
`--client-auth` flag that allows you to configure the behavior. The
default is the current one of requiring client authentication.

This PR does not yet update Java clients, however, the Haskell client
supports this already and is used to test this functionality.

I’ve also added a section in the documentation on TLS (there were no
docs at all so far).

changelog_begin

- [DAML Sandbox] When Sandbox is run with TLS enabled, you can now
  configure the requirement for client authentication via
  ``--client-auth``. See
  https://docs.daml.com/tools/sandbox.html#running-with-tls for more information.

changelog_end
2020-03-12 16:04:46 +01:00
Jussi Mäki
583c0a7749
Run most tests for ledger-dump (#4910)
We exclude the tests that create lots of data.
CommandDeduplicationIT is disabled as kvutils does not yet
have time-based deduplication.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-12 14:10:22 +01:00
simonmaxen-da
4c55a67e38
Allow time for all nodes to see contract before executing (#4909)
CHANGELOG_BEGIN
CHANGELOG_END
2020-03-12 08:57:02 +01:00
Robert Autenrieth
3cc17c0253
Command client remove deduplication (#4783)
* Remove deduplication from command client

CHANGELOG_BEGIN
CHANGELOG_END

* Adapt tests for the new behavior
2020-03-11 16:27:29 +01:00
Robert Autenrieth
42adfb1887
Fix tests not running with bazel test (#4938)
CHANGELOG_BEGIN
CHANGELOG_END
2020-03-11 15:15:02 +01:00
Robert Autenrieth
9216a68ad1
Don't read exclusive end in completions query (#4899)
* Don't read exclusive end in completions query

CHANGELOG_BEGIN
CHANGELOG_END

* Store offsets directly and do +1 only on read side

* Fix existing completions

* Add test for the completion service

Co-authored-by: Gerolf Seitz <gerolf.seitz@digitalasset.com>
2020-03-11 14:10:32 +00:00
fabiotudone-da
e4ce69ea58
Rename EC auth cmdline options in line with the standard and document them. (#4930)
* Rename EC auth cmdline options in line with the standard and document them.

CHANGELOG_BEGIN
CHANGELOG_END

* 📝 Fix doc

* Auth docs: change `RSA DSA` -> `RSA Signature` (clashed with DSA algo)

As proposed by @SamirTalwar-DA

CHANGELOG_BEGIN
[Sandbox] Rename the `--auth-jwt-ec256-crt` command line option to `--auth-jwt-es256-crt` as well as `--auth-jwt-ec256-crt` to `--auth-jwt-es256-crt` and fix their docs
CHANGELOG_END
2020-03-11 13:18:47 +00:00
Remy
bdb6179405
[DAML-LF] add submission time for contract ids seeding (#4776)
* [DAML-LF] add submission time for contract ids seeding

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-11 12:17:22 +01:00
Samir Talwar
3c6f8ed627
kvutils: Avoid casting ArgumentCaptor and friends in tests. (#4928)
* kvutils: Avoid casting `ArgumentCaptor` and friends in tests.

Instead, use generics the way they're intended.

CHANGELOG_BEGIN
CHANGELOG_END

* kvutils: In KeyValueParticipantStateWriterSpec, drop the Option.
2020-03-11 09:38:43 +00:00
Robert Autenrieth
9fd484469a
Add maxDeduplicationTime to the participant state API (#4722)
* Add max deduplication time to ledger configuration

* Add TTL to participant state API

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-11 09:49:37 +01:00
Moritz Kiefer
50a0e2eda3
Enable caching and sandboxing for canton ledger API test tool (#4923)
After some investigation, canton does not currently expose a nice way
to tell ammonite where it should write its files or even better use
the in-memory mode. However, ammonite respects $HOME so we can just
set that to a temp directory which fixes the issue.

changelog_begin
changelog_end
2020-03-10 16:34:58 +00:00
Moritz Kiefer
ffc6f4e520
Include Bazel patch to mark tests as exclusive (#4918)
* Include Bazel patch to mark tests as exclusive

This should hopefully avoid rerunning the conformance tests as often
as we do now. While this patch is not applied on Windows (since we get
it from nix), this is not really an issue since most of the exclusive
tests (in particular, all conformance tests) are disabled on Windows
anyway.

I’ve tested this locally accross a couple of runs and I get the
caching I want and looking at the code in the patch, the change looks
very reasonable. I somewhat wonder if it just broke internally at
google because they marked tests as exclusive that should have gotten
no-cache.

changelog_begin
changelog_end

* Disable caching for canton
2020-03-10 13:13:58 +01:00
Moritz Kiefer
048b3fa679
Fix warnings on mismatch between record type and constructor name (#4919)
changelog_begin
changelog_end
2020-03-10 13:01:16 +01:00
Samir Talwar
51f596daa7
Sandbox Next: Implicit party allocation. (#4894)
* ledger-api-test-tool: Fix warnings flagged by IntelliJ IDEA.

* ledger-api-test-tool: Open-world mode.

In open-world mode, parties aren't allocated; their names are just
reserved for the test case, so that no other test will accidentally use
the same party name.

This is so we can test ledgers which dynamically allocate parties, such
as Sandbox.

* sandbox: Run conformance tests in "open-world" mode.

This means that the tests don't explicitly allocate parties (except for
a few), instead relying on Sandbox's implicit party allocation feature.

This is not enabled for Sandbox Next yet.

* sandbox-next: Implicit party allocation.

This is added to the command submission service.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox-next: Don't implicitly allocate pre-existing parties.

* ledger-api-test-tool: Move pre-allocation into ParticipantTestContext.

* ledger-api-test-tool: We can reserve parties or wait for them. Not both.

Make illegal states unrepresentable as early as possible.

* sandbox: Name ApiSubmissionService's private methods a little better.

* sandbox: Move ApiSubmissionService's conditional logic into methods.

* sandbox: Document why we set `implicitPartyAllocation` to `false`.

* sandbox: Document why `implicitPartyAllocation` is dangerous.
2020-03-09 15:49:11 +00:00
Stefano Baghino
1908de10e4
Rework ValueSerializer (#4897)
* Rework ValueSerializer

- Handle errors directly in the convenience method (it's the only way in which it's used)
- Don't drop the root cause when a serialization error occurs
- Remove outdated comment

CHANGELOG_BEGIN
CHANGELOG_END

* Add alternative with error context for deserialize method

* Make error context evaluated lazily

* Rename inner helper to avoid name clash
2020-03-09 15:17:06 +01:00
Samir Talwar
9ec45eb12d
sandbox: Error when a party already exists. (#4896)
CHANGELOG_BEGIN
- [Sandbox] Respond with an error when trying to create a party that
  already exists.
CHANGELOG_END
2020-03-09 13:18:04 +00:00
Samir Talwar
3e7d016875
sandbox: Normalize language around listing all known parties. (#4895)
This renames methods backing the `ListKnownParties` request to
from `parties`, `getParties` or `listParties` to `listKnownParties`.

CHANGELOG_BEGIN
- [Ledger API Server] Renamed two metrics:
  ``daml.index.parties`` was renamed to ``daml.index.list_known_parties``
  ``daml.index.db.get_parties`` was renamed to ``daml.index.db.list_known_parties``
CHANGELOG_END
2020-03-09 13:15:33 +00:00
Samir Talwar
0f4fb9a8f5
Ledger API Server: Add the GetParties endpoint. (#4888)
* sandbox: Add a database test for storing and retrieving parties.

* sandbox: Add database queries for selecting one or many parties.

* ledger-api-test-tool: Add a test for `ListKnownParties`.

* sandbox: Add an endpoint to retrieve a single party's details.

CHANGELOG_BEGIN
- [Ledger API] Added an endpoint to retrieve a single party's details at
  ``com.digitalasset.ledger.api.v1.admin.PartyManagementService.GetParty``.
  Please consult the ledger API reference documentation for more
  information.
CHANGELOG_END

* sandbox: Add an endpoint to retrieve a multiple parties' details.

CHANGELOG_BEGIN
- [Ledger API] Added an endpoint to retrieve multiple parties's details at
  ``com.digitalasset.ledger.api.v1.admin.PartyManagementService.GetParties``.
  Please consult the ledger API reference documentation for more
  information.
CHANGELOG_END

* sandbox: Getting a single party is a special case of multiple parties.

So let's use that code path and stop duplicating work.

* sandbox: Remove `GetParty`, as it's subsumed by `GetParties`.

"Subsumed" is a great word.
2020-03-09 12:09:56 +00:00
Gerolf Seitz
cf74e74d05
Fix calculation of transaction tree projections (#4885)
Events in transaction trees should only reference other events
that:
1) are either create or exercise events
2) the requesting parties are a witness of

This applies to recalculated root nodes as well as
the child event ids referenced in exercise nodes.

CHANGELOG_BEGIN
[Sandbox]: fixed projection of transaction trees.
CHANGELOG_END
2020-03-09 12:37:14 +01:00
Gerolf Seitz
2b76d1962c
Deprecate ledger initialization with scenarios (#4864)
* Deprecate ledger initialization with scenarios

CHANGELOG_BEGIN
[Sandbox] Initializing the sandbox with scenarios is now deprecated in
favor of using DAML Script. The scenario parameter will be removed in
the near future. A warning is logged on startup.

The DAML SDK templates and quickstart guide are using DAML Script.

See the DAML Script migration guide for more information:
https://docs.daml.com/daml-script/index.html#using-daml-script-for-ledger-initialization
CHANGELOG_END
2020-03-09 09:30:18 +01:00
Samir Talwar
a0f250a727
sandbox: Avoid converting to byte arrays before deserializing. (#4865)
CHANGELOG_BEGIN
CHANGELOG_END
2020-03-06 15:40:26 +00:00
Samir Talwar
c6954c086b
sandbox-next: Error if a scenario is provided. (#4875)
* sandbox-next: Pull runner configuration into the constructor.

No need to do it on `acquire()` if it's pure.

* sandbox-next: Error if a scenario is provided.

Sandbox-Next doesn't support scenarios, instead favoring DAML Script.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-06 14:51:42 +00:00
Samir Talwar
b4a529eda9
sandbox: Format Cli.scala. (#4876)
Not sure why formatting was turned off at one point, but it seems to be
OK now.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-06 14:43:04 +00:00
Samir Talwar
82c40f2ecb
kvutils: Throw meaningful errors when dealing with a Left. (#4835)
* kvutils: On error opening an envelope, throw the correct message.

CHANGELOG_BEGIN
CHANGELOG_END

* ledger-on-sql: On error when querying state, throw the correct error.

* kvutils|ledger-on-sql: Remove unnecessary curly braces around `throw`.
2020-03-06 13:53:34 +00:00
fabiotudone-da
9635e14d56
Restore LedgerFactory inheritors' ability to use Config for setups (#4860)
CHANGELOG_BEGIN
CHANGELOG_END
2020-03-06 08:25:27 +00:00
mergify[bot]
6b851229b8
Refactor extraction of events from transaction (#4781)
* Refactor extraction of events from transaction

Closes #1909

CHANGELOG_BEGIN
CHANGELOG_END

* Remove unnecessary filtering

* Fix disclosure rule for flat transaction

* Refactor and split collection and filtering

* Replace transaction filtration with blinding info

* Move transient contract remover in transaction conversion

* Remove dangling file

* Simplify transient contract filtering

* Further refinements

* Simplify transaction tree event extraction

* Move newRoots up the file for consistency and readability

* Remove collect from GenTransaction, replace with custom iterator

* Address https://github.com/digital-asset/daml/pull/4781#discussion_r388167562

* Switch to a strict collect method

* Replaced direct access to map with contains
2020-03-05 18:06:05 +00:00
mergify[bot]
c1d601586a
ledger-on-sql: Ensure log entries are returned in the correct order. (#4854)
I have no idea how this worked previously. I think we got lucky.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-05 17:18:08 +00:00
mergify[bot]
e785bb7402
Sandbox: Re-use actor systems between the StandaloneApiServer and StandaloneIndexerServer. (#4827)
* sandbox: Re-use the root actor system in the StandaloneIndexerServer.

* kvutils/app: Don't use the ActorSystem execution context randomly.

Instead, make `Runner` a proper ResourceOwner, with an `acquire` method.

* sandbox: Re-use the root actor system in the StandaloneApiServer.

CHANGELOG_BEGIN
CHANGELOG_END

* resources: Remove the now-unused `ResourceOwner.sequence` functions.

They weren't well-thought-out anyway; they acquire resources
sequentially, rather than in parallel.
2020-03-05 14:50:18 +00:00
mergify[bot]
46a218a22f
sandbox-next: Disable ResetService tests. (#4836)
They're too flaky. We'll bring them back once we work out the
performance issues.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-05 14:06:02 +00:00
mergify[bot]
95c1e5edaa
Allow LedgerFactory to provide a full-blown ReadWriterService (#4792)
* Allow `LedgerFactory` to provide a full-blown `ReadWriterService` rather than a `LedgerReaderWriter` (needed by at least vDAML)

CHANGELOG_BEGIN
CHANGELOG_END

* Address review points

* Address Samir's review point in `SqlLedgerFactory`

* Finish addressing Samir's review point in `SqlLedgerFactory`

* Split reader and writer owners in `LedgerFactory` as suggested by Gerolf

* Remove unneeded `val` from `KeyvalueParticipantState[Reader|Writer]` constructor params

* Remove unneeded type parameter from `app.Runner`

* Leave `LedgerFactory` a full ledger builder but split hierarchy upwards and clarify responsibilities

* Rename `SimpleLedgerFactory` to `KeyValueLedgerFactory`
2020-03-05 12:02:23 +00:00
Samir Talwar
85998f8f06
Sandbox-Next: Add the ResetService. (#4802)
* sandbox-next: Make the Runner a real ResourceOwner.

* sandbox: Don't construct the ResetService twice.

* sandbox: Inline and simplify methods in StandaloneApiServer.

* resources: Define a `ResettableResource`, which can be `reset()`.

`reset()` releases the resource, performs an optional reset operation,
and then re-acquires it, binding it to the same variable.

* resources: Pass the resource value into the reset operation.

* sandbox: Fix warnings in `TestCommands`.

* sandbox-next: Add the ResetService.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox: Make sure the SandboxResetService resets asynchronously.

It was being too clever and negating its own asynchronous behavior.

* sandbox-next: Forbid no seeding.

This double negative is really hard to phrase well.

* sandbox-next: Implement ResetService for a persistent ledger.

* sandbox: Delete the comment heading StandaloneIndexerServer.

It's no longer meaningful.

* sandbox-next: No need to wrap the SandboxResetService in an owner.

* sandbox-next: Bump the ResetService test timeouts.

It looks like it's definitely slower than on Sandbox Classic™. Gonna
look into this as part of future work.

* Revert to previous asynchronous reset behavior

Co-authored-by: Gerolf Seitz <gerolf.seitz@digitalasset.com>
2020-03-04 14:40:35 +00:00
Robert Autenrieth
98095cf80d
Clean up command deduplication (#4801)
* Always return error on duplicate submissions

* Remove unnecessary submission information

Now that duplicate submissions always return an error,
we don't need to store the original submission result.

CHANGELOG_BEGIN
CHANGELOG_END

* Rename ttl to deduplicationTime/deduplicateUntil

* Store absolute deduplicateUntil in domain commands

* Fix my own initials

* Remove CommandDeduplicationEntry

Instead, use CommandDeduplicationResult everywhere,
removing the extra layer.
2020-03-04 14:08:08 +01:00
Moritz Kiefer
351091a76e
Only log message about duplicate package uploads in debug level (#4803)
It is basically impossible to not hit this all the time if you upload
more than one package so issuing a warning is a bit confusing.

changelog_begin

- [Sandbox] The warning about duplicate package uploads is no longer
  emitted by default. You can enable them by passing
  ``--log-level=debug``.

changelog_end
2020-03-04 10:36:20 +00:00
Samir Talwar
06b3c26bfe
Sandbox: Refactoring and cleanup around FlywayMigrations and JdbcIndexerFactory. (#4797)
* sandbox: Return `Future[Unit]` from migrations rather than awaiting.

I've removed the explicit error-handling, because this will be
propagated and handled at the top level.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox: Pass the JDBC URL into the JdbcIndexerFactory constructor.

* sandbox: Replace the JdbcIndexerFactory's `InitStatus` with two classes.

The `asInstanceOf` conversions put me off.

* sandbox: Stop passing around the ledger ID in JdbcIndexerFactory.

* sandbox: Remove the indexer `asyncTolerance`; it's no longer used.
2020-03-04 08:13:19 +00:00
Samir Talwar
a73b7459a7
resources: Resource.unit, as an alias for Resource.successful(()). (#4786)
* resources: `Resource.unit`, as an alias for `Resource.successful(())`.

CHANGELOG_BEGIN
CHANGELOG_END

* resources: Add `ResourceOwner.unit`.
2020-03-03 16:47:54 +00:00
Gerolf Seitz
536e793a44
Don't return witnessed contracts in ActiveContractsService (#4791)
The change to `EventFilter` and to the query in `JdbcLedgerDao` are
"duplicate work", but we need the change in EventFilter for the
InMemoryLedger, and the change in JdbcLedgerDao so that we avoid
fetching a contract that anyway would be discarded later.

CHANGELOG_BEGIN
[Sandbox]: Witnessed contracts for which a party is not a stakeholder
are no longer returned in the active contract stream.
CHANGELOG_END

Fixes #3254.
2020-03-03 16:29:55 +01:00
Remy
bb0d3f24cb
[engine] refactor transaction's usedPackages (#4793)
* [engine] refactor transaction's usedPackages

* Address Gerolf's comment

* changelog

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-03 13:59:40 +00:00
Samir Talwar
a2fd466240
ledger-on-sql: The tests are not that fast. (#4787)
Especially when they're running against PostgreSQL. Just spinning that
up takes a while.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-03 13:51:17 +00:00
Samir Talwar
6711b04a30
sandbox: Standardize logging when initializing the ledger. (#4782)
CHANGELOG_BEGIN
CHANGELOG_END
2020-03-03 09:04:32 +00:00
Samir Talwar
a99156252d
libs-scala/ports: Wrap socket ports in a type, Port. (#4784)
* libs-scala/ports: Wrap socket ports in a type, `Port`.

* sandbox: Use `Port` for the API server port, and propagate.

CHANGELOG_BEGIN
CHANGELOG_END

* extractor: Use `Port` for the server port.

* ports: Make Port a compile-time class only.

* ports: Allow port 0; it can be specified by a user.

* ports: Publish to Maven Central.
2020-03-03 08:59:15 +00:00
Samir Talwar
89c23ef85d
Heartbeats for Sandbox-Next, ledger-on-sql, and ledger-on-memory. (#4755)
* kvutils: Make the `KeyValueParticipantStateReader` tests more rigorous.

If the `offset` is specified as `None`, expect it to be `None`, not
just anything.

* kvutils: Simplify `KeyValueParticipantStateReader#stateUpdates`.

Construct the Source with `Source.apply`, not `Source.fromIterator`.

* kvutils: Use multiple entry IDs in `KeyValueParticipantStateReaderSpec`.

* kvutils: Add basic tests to `KeyValueParticipantStateReaderSpec`.

* kvutils: Add heartbeats to `LedgerReader`'s `events` output.

Heartbeats are optional, to be delivered by the ledger if and when it
deems necessary.

* sandbox-next: An observing time service backend using Akka streams.

* sandbox-next: A regular heartbeat based on Akka Streams' `tick`.

* sandbox: Replace `TimeServiceBackend.withObserver` with `.observing`.

More code, but it's more decoupled, so can more easily be sent to the
underlying backend in Sandbox Next.

CHANGELOG_BEGIN
- [Sandbox] Fixed a bug in the command completions stream when running
  Sandbox in static time. Previously, upon updating the time, the old
  time was emitted on the completions stream. The new time is now
  emitted.
CHANGELOG_END

* sandbox: TimeServiceBackend should only emit accepted changes.

* ledger-on-memory: Use `LedgerRecord` directly.

* ledger-on-memory: Stream heartbeats to the log.

* ledger-on-memory: Encapsulate mutations behind locks at all times.

* ledger-on-memory: Differentiate between reading and writing.

* ledger-on-memory: Factor out appending to the log.

* kvutils: Move the heartbeat test into the base from ledger-on-memory.

* kvutils: Log when the submission validation fails unexpectedly.

* ledger-on-sql: Add a script to hash all migrations.

* ledger-on-sql: Publish heartbeats to the log, and stream them out.

* ledger-on-sql: Log if publishing the heartbeat failed.

* ledger-on-sql: Wrap all queries in `Try`.

Just to make sure that we don't throw from a function that returns `Try`
or `Future`.

* ledger-on-sql: Allow `Long` values as the heartbeat timestamp.

`INTEGER` really does mean 32-bit, apparently.

* sandbox-next: Pipe heartbeats to the ledger.

* ledger-on-sql: Make sure we publish the correct head after a heartbeat.

Off-by-one errors are the best errors.

* ledger-on-(memory|sql): Just accept heartbeats, not their owner.

* sandbox: Update CIDs in tests to account for the extra heartbeat.

* ledger-on-memory: Fix a reference to variable in a comment.

Co-Authored-By: Gerolf Seitz <gerolf.seitz@digitalasset.com>

* ledger-on-sql: `flatMap` over `Try` rather than `Future` when possible.

* sandbox: Make sure the heartbeat queues are thread-safe.

* kvutils: Remove `LoggingContext` from the interfaces.

Keep it internally. This means we'll drop any context, but otherwise
things should work as expected.

* sandbox-next: Pull out the heartbeat interval into a constant.

* ledger-on-sql|sandbox: Clarify large levels of nesting.

Co-authored-by: Gerolf Seitz <gerolf.seitz@digitalasset.com>
2020-03-02 19:44:42 +00:00
Oliver Seeliger
95f596ec56
Lower Ledger api server rejected submissions to info (#4773)
Rejected submissions are a user-error and don't indicate a problem with the server not functioning properly. Such user
errors make it hard to spot "real" server-side warnings and errors.
i
Closes #4772

CHANGELOG_BEGIN
- The Ledger API Server now logs rejected submissions at a lower "INFO" level to remove a source of warnings/errors without relation to server health.
CHANGELOG_END
2020-03-02 19:01:47 +00:00
Moritz Kiefer
d68d3eb74a
Freeze DAML-LF 1.8 (#4770)
* Freeze DAML-LF 1.8

Two minor points that I did not mention in the previous PR:

We also include the renaming of structural records to `struct` and the
renaming of `Map` to `TextMap`.

There are some minor changes around the LF encoder tests which need to
be able to emit package metadata properly so I’ve added it to the
parser. Sorry for not splitting that out.

Following the process used for the DAML-LF 1.7 release, this does not
yet include the frozen proto file.

changelog_begin

- [DAML-LF] Release DAML-LF 1.8:

  * Rename structural records to ``Struct``. Note that
    structural records are not exposed in DAML.
  * Rename ``Map`` to ``TextMap``.
  * Add type synonyms. Note that type synonyms are not serializable.
  * Add package metadata, i.e., package names and versions.

  Note that the default output of ``damlc`` is stil DAML-LF 1.7. You
  can produce DAML-LF 1.8 by passing ``--target=1.8``.

changelog_end

* Update encoder

* Update java codegen tests

* Update comment in scala codegen

* Handle TSynApp in interface reader

* Bump lf_stable_version to 1.7

* Fix kvutils tests
2020-03-02 18:29:26 +01:00
Stefano Baghino
83da2c643b
Clean up ledger-api-common (#4774)
Removes unused classes

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-02 18:16:45 +01:00
Remy
e7ee8143cb
[kvutils] use new contract id scheme (#4741)
* Make kvutils work with the new contract id scheme

CHANGELOG_BEGIN
- [KVUtils] uses random contract id. Contract ids are made of 65 hexa decimal characters.
CHANGELOG_END

Co-authored-by: Jussi Mäki <jussi.maki@digitalasset.com>
2020-03-02 17:50:38 +01:00
Stefano Baghino
00a3a1c2bb
Tighten the loop: backend services to return API responses (#4763)
* Tighten the loop: backend services to return API responses

CHANGELOG_BEGIN
CHANGELOG_END

* Use transaction filter directly

* Remove unnecessary transition through domain objects

* Ensure transient contract remover compares sets of witnesses

* Honor verbosity in request

* Address review https://github.com/digital-asset/daml/pull/4763#pullrequestreview-367012726

- using named parameters when creating the API objects
- renamed EventOps accessors to easily recognizable names
- dropped unnecessary usage of views
- honoring verbosity level in request in all places
- replaced usage of lenses with simple copying where it made sense
2020-03-02 15:06:38 +00:00
Samir Talwar
cf8cb61327
Sandbox-Next: Wire up missing configuration. (#4728)
* sandbox: Name the arguments to `ApiServices.create` for clarity.

* sandbox: Clarify numbers and types in configuration classes.

* sandbox-next: Log the correct port on startup.

* sandbox-next: Connect up the command configuration.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox-next: Wire up TLS configuration.

* sandbox-next: Wire up the maximum inbound message size.

* sandbox-next: Set the global log level if specified.

And if it's not specified, default to the level in logback.xml, INFO.

* sandbox-next: Connect up the submission configuration.

* sandbox-next: Log the correct ledger ID.

* sandbox-next: Use `TimeProvider.UTC`.
2020-02-27 09:49:26 +00:00
Stefano Baghino
c53ba475ef
Make completion service return checkpoints (#4735)
* Make completion service return checkpoints

The new table for #4681 and the query used to retrieve completions
currently does not return checkpoints. These do not have to match
the application_id and submitting_party query since those fields
are not populated.

CHANGELOG_BEGIN
CHANGELOG_END

* Address https://github.com/digital-asset/daml/pull/4735#discussion_r384713277
2020-02-27 09:45:45 +00:00
Stefano Baghino
48241f5753
Backfill completions (#4733)
* Backfill completions

Follow up to #4681

CHANGELOG_BEGIN
CHANGELOG_END

* Add needed newline for migration's sha256
2020-02-27 09:21:39 +00:00
Shayne Fletcher
66dd112960
Remove pragma 'daml 1.2' (#4702)
changelog_begin
- The pragma 'daml 1.2' is now optional.
changelog_end
2020-02-26 13:17:45 -05:00
Gerolf Seitz
d617922618
Remove InMemoryKVParticipantState (#4674)
This removes the sample/reference implementation of kvutils
InMemoryKVParticipantState.
This used to be the only implementation of kvutils, but now with the
simplified kvutils api we have ledger-on-memory and ledger-on-sql.

InMemoryKVParticipantState was also used for the ledger dump utility,
which now uses ledger-on-memory.

* Runner now supports a multi participant configuration
This change removes the "extra participants" config and goes for consistent
participant setup with --participant.

* Run all conformance tests in the repository in verbose mode.

This means we'll print stack traces on error, which should make it
easier to figure out what's going on with flaky tests on CI.

This doesn't change the default for other users of the
ledger-api-test-tool; we just add the flag for:

  - ledger-api-test-tool-on-canton
  - ledger-on-memory
  - ledger-on-sql
  - sandbox




Fixes #4225.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-26 15:45:35 +01:00
Samir Talwar
8981ae3115
Sandbox-Next: Get the authorization service from configuration. (#4712)
* sandbox-next: Get the authorization service from configuration.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox-next: Add parameter names to Runner function calls.

It's getting very confusing what's what without them, and the mix of
with and without is more confusing.
2020-02-26 11:56:34 +00:00
Robert Autenrieth
79e7ca0627
Implement new command deduplication (#4467)
* Add TTL field to protobuf

* Add command deduplication to index service

* Wire command deduplication to DAO

* Implement in-memory command deduplication

* Remove Deduplicator

* Implement JDBC command deduplication

* Add TTL field to domain commands

* Deduplicate commands in the submission service

CHANGELOG_BEGIN
- [Sandbox] Implement a new command submission deduplication mechanism
  based on a time-to-live (TTL) for commands.
  See https://github.com/digital-asset/daml/issues/4193
CHANGELOG_END

* Remove unused command service parameter

* fixup protobuf

* Add configuration for TTL

* Fix Haskell bindings

* Rename SQL table

* Add command deduplication test

* Redesign command deduplication queries

* Address review comment

* Address review comment

* Address review comments

* Make command deduplication test optional

* Disable more tests

* Address review comments

* Address review comments

* Refine test

* Address review comments

* scalafmt

* Truncate new table on reset

* Store original command result

* Rename table columns

... to be consistent with other upcoming tables

* Rename migrations to solve conflicts

Fixes #4193.
2020-02-26 12:00:02 +01:00
fabiotudone-da
b2a79df0d8
Expand Runner's flexibility as a basis for participant servers (#4669)
* Add overridable indexer, api and auth configuration to `LedgerFactory`

CHANGELOG_BEGIN
CHANGELOG_END

* Add overridable indexer and api metrics creation to `LedgerFactory`

CHANGELOG_BEGIN
CHANGELOG_END

* Add overridable api's `TimeServiceBackend` to `LedgerFactory`

* 🎨 Fix formatting

* Port SDK ledgers based on `Runner` (and the sandbox) to `TimeServiceBackend`

* Revert to `TimeProvider` for committer usage and to `None` default for API server.
Also removed now unused `TimeServiceProvider.wallClock()`.

* Move TimeServiceBackend back to the API server.

* 🎨 Remove unneeded argument passed for parameter w/default

* Restore sandbox ledger time support

* Simplify passing a `TimeProvider` to the sandbox ledger

Co-authored-by: Samir Talwar <samir.talwar@digitalasset.com>
2020-02-26 09:31:26 +01:00
Gary Verhaegen
5a117dc358
introduce new release process (#4513)
Context
=======

After multiple discussions about our current release schedule and
process, we've come to the conclusion that we need to be able to make a
distinction between technical snapshots and marketing releases. In other
words, we need to be able to create a bundle for early adopters to test
without making it an officially-supported version, and without
necessarily implying everyone should go through the trouble of
upgrading. The underlying goal is to have less frequent but more stable
"official" releases.

This PR is a proposal for a new release process designed under the
following constraints:

- Reuse as much as possible of the existing infrastructure, to minimize
  effort but also chances of disruptions.
- Have the ability to create "snapshot"/"nightly"/... releases that are
  not meant for general public consumption, but can still be used by savvy
  users without jumping through too many extra hoops (ideally just
  swapping in a slightly-weirder version string).
- Have the ability to promote an existing snapshot release to "official"
  release status, with as few changes as possible in-between, so we can be
  confident that the official release is what we tested as a prerelease.
- Have as much of the release pipeline shared between the two types of
  releases, to avoid discovering non-transient problems while trying to
  promote a snapshot to an official release.
- Triggerring a release should still be done through a PR, so we can
  keep the same approval process for SOC2 auditability.

The gist of this proposal is to replace the current `VERSION` file with
a `LATEST` file, which would have the following format:

```
ef5d32b7438e481de0235c5538aedab419682388 0.13.53-alpha.20200214.3025.ef5d32b7
```

This file would be maintained with a script to reduce manual labor in
producing the version string. Other than that, the process will be
largely the same, with releases triggered by changes to this `LATEST`
and the release notes files.

Version numbers
===============

Because one of the goals is to reduce the velocity of our published
version numbers, we need a different version scheme for our snapshot
releases. Fortunately, most version schemes have some support for that;
unfortunately, the SDK sits at the intersection of three different
version schemes that have made incompatible choices. Without going into
too much detail:

- Semantic versioning (which we chose as the version format for the SDK
  version number) allows for "prerelease" version numbers as well as
  "metadata"; an example of a complete version string would be
  `1.2.3-nightly.201+server12.43`. The "main" part of the version string
  always has to have 3 numbers separated by dots; the "prerelease"
  (after the `-` but before the `+`) and the "metadata" (after the `+`)
  parts are optional and, if present, must consist of one or more segments
  separated by dots, where a segment can be either a number or an
  alphanumeric string. In terms of ordering, metadata is irrelevant and
  any version with a prerelease string is before the corresponding "main"
  version string alone. Amongst prereleases, segments are compared in
  order with purely numeric ones compared as numbers and mixed ones
  compared lexicographically. So 1.2.3 is more recent than 1.2.3-1,
  which is itself less recent than 1.2.3-2.
- Maven version strings are any number of segments separated by a `.`, a
  `-`, or a transition between a number and a letter. Version strings
  are compared element-wise, with numeric segments being compared as
  numbers. Alphabetic segments are treated specially if they happen to be
  one of a handful of magic words (such as "alpha", "beta" or "snapshot"
  for example) which count as "qualifiers"; a version string with a
  qualifier is "before" its prefix (`1.2.3` is before `1.2.3-alpha.3`,
  which is the same as `1.2.3-alpha3` or `1.2.3-alpha-3`), and there is a
  special ordering amongst qualifiers. Other alphabetic segments are
  compared alphabetically and count as being "after" their prefix
  (`1.2.3-really-final-this-time` counts as being released after `1.2.3`).
- GHC package numbers are comprised of any number of numeric segments
  separated by `.`, plus an optional (though deprecated) alphanumeric
  "version tag" separated by a `-`. I could not find any official
  documentation on ordering for the version tag; numeric segments are
  compared as numbers.
- npm uses semantic versioning so that is covered already.

After much more investigation than I'd care to admit, I have come up
with the following compromise as the least-bad solution. First,
obviously, the version string for stable/marketing versions is going to
be "standard" semver, i.e. major.minor.patch, all numbers, which works,
and sorts as expected, for all three schemes. For snapshot releases, we
shall use the following (semver) format:

```
0.13.53-alpha.20200214.3025.ef5d32b7
```

where the components are, respectively:

- `0.13.53`: the expected version string of the next "stable" release.
- `alpha`: a marker that hopefully scares people enough.
- `20200214`: the date of the release commit, which _MUST_ be on
  master.
- `3025`: the number of commits in master up to the release commit
  (included). Because we have a linear, append-only master branch, this
  uniquely identifies the commit.
- `ef5d32b7ù : the first 8 characters of the release commit sha. This is
  not strictly speaking necessary, but makes it a lot more convenient to
  identify the commit.

The main downsides of this format are:

1. It is not a valid format for GHC packages. We do not publish GHC
  packages from the SDK (so far we have instead opted to release our
  Haskell code as separate packages entirely), so this should not be an
  issue. However, our SDK version currently leaks to `ghc-pkg` as the
  version string for the stdlib (and prim) packages. This PR addresses
  that by tweaking the compiler to remove the offending bits, so `ghc-pkg`
  would see the above version number as `0.13.53.20200214.3025`, which
  should be enough to uniquely identify it. Note that, as far as I could
  find out, this number would never be exposed to users.
2. It is rather long, which I think is good from a human perspective as
  it makes it more scary. However, I have been told that this may be
  long enough to cause issues on Windows by pushing us past the max path
  size limitation of that "OS". I suggest we try it and see what
  happens.

The upsides are:

- It clearly indicates it is an unstable release (`alpha`).
- It clearly indicates how old it is, by including the date.
- To humans, it is immediately obvious which version is "later" even if
  they have the same date, allowing us to release same-day patches if
  needed. (Note: that is, commits that were made on the same day; the
  release date itself is irrelevant here.)
- It contains the git sha so the commit built for that release is
  immediately obvious.
- It sorts correctly under all schemes (modulo the modification for
  GHC).

Alternatives I considered:

- Pander to GHC: 0.13.53-alpha-20200214-3025-ef5d32b7. This format would
  be accepted by all schemes, but will not sort as expected under semantic
  versioning (though Maven will be fine). I have no idea how it will sort
  under GHC.
- Not having any non-numeric component, e.g. `0.13.53.20200214.3025`.
  This is not valid semantic versioning and is therefore rejected by
  npm.
- Not having detailed info: just go with `0.13.53-snapshot`. This is
  what is generally done in the Java world, but we then lose track of what
  version is actually in use and I'm concerned about bug reports. This
  would also not let us publish to the main Maven repo (at least not more
  than once), as artifacts there are supposed to be immutable.
- No having a qualifier: `0.13.53-3025` would be acceptable to all three
  version formats. However, it would not clearly indicate to humans that
  it is not meant as a stable version, and would sort differently under
  semantic versioning (which counts it as a prerelease, i.e. before
  `0.13.53`) than under maven (which counts it as a patch, so after
  `0.13.53`).
- Just counting releases: `0.13.53-alpha.1`, where we just count the
  number of prereleases in-between `0.13.52` and the next. This is
  currently the fallback plan if Windows path length causes issues. It
  would be less convenient to map releases to commits, but it could still
  be done via querying the history of the `LATEST` file.

Release notes
=============

> Note: We have decided not to have release notes for snapshot releases.

Release notes are a bit tricky. Because we want the ability to make
snapshot releases, then later on promote them to stable releases, it
follows that we want to build commits from the past. However, if we
decide post-hoc that a commit is actually a good candidate for a
release, there is no way that commit can have the appropriate release
notes: it cannot know what version number it's getting, and, moreover,
we now track changes in commit messages. And I do not think anyone wants
to go back to the release notes file being a merge bottleneck.

But release notes need to be published to the releases blog upon
releasing a stable version, and the docs website needs to be updated and
include them.

The only sensible solution here is to pick up the release notes as of
the commit that triggers the release. As the docs cron runs
asynchronously, this means walking down the git history to find the
relevant commit.

> Note: We could probably do away with the asynchronicity at this point.
> It was originally included to cover for the possibility of a release
> failing. If we are releasing commits from the past after they have been
> tested, this should not be an issue anymore. If the docs generation were
> part of the synchronous release step, it would have direct access to the
> correct release notes without having to walk down the git history.
>
> However, I think it is more prudent to keep this change as a future step,
> after we're confident the new release scheme does indeed produce much more
> reliable "stable" releases.

New release process
===================

Just like releases are currently controlled mostly by detecting
changes to the `VERSION` file, the new process will be controlled by
detecting changes to the `LATEST` file. The format of that file will
include both the version string and the corresponding SHA.

Upon detecting a change to the `LATEST` file, CI will run the entire
release process, just like it does now with the VERSION file. The main
differences are:

1. Before running the release step, CI will checkout the commit
  specified in the LATEST file. This requires separating the release
  step from the build step, which in my opinion is cleaner anyway.
2. The `//:VERSION` Bazel target is replaced by a repository rule
  that gets the version to build from an environment variable, with a
  default of `0.0.0` to remain consistent with the current `daml-head`
  behaviour.

Some of the manual steps will need to be skipped for a snapshot release.
See amended `release/RELEASE.md` in this commit for details.

The main caveat of this approach is that the official release will be a
different binary from the corresponding snapshot. It will have been
built from the same source, but with a different version string. This is
somewhat mitigated by Bazel caching, meaning any build step that does
not depend on the version string should use the cache and produce
identical results. I do not think this can be avoided when our artifact
includes its own version number.

I must note, though, that while going through the changes required after
removing the `VERSION` file, I have been quite surprised at the sheer number of
things that actually depend on the SDK version number. I believe we should
look into reducing that over time.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-25 17:01:23 +01:00
Samir Talwar
2e8bb47ef5
Sandbox: Fix two race conditions on shutdown in ReadOnlySqlLedger. (#4621)
* sandbox: Make ReadOnlySqlLedger provide a ResourceOwner, not a Resource.

* sandbox: Fix two race conditions on shutdown in ReadOnlySqlLedger.

It appears that there are two race conditions regarding the ledger end
update mechanism.

1.  The dispatcher can keep firing for a little while even after we shut
    down the source, which can cause a spurious connection failure as it
    makes a query on a closed database connection.
2.  We don't wait for the sink to complete, which means, again, we could
    shut down the connection before the last `lookupLedgerEnd` query is
    issued.

This also makes sure we actually construct a new source if the updates
fail. Previously we were re-using the same source, which looked like a
crash-loop waiting to happen.

Tested by constructing `ReadOnlySqlLedger` and closing it in a loop, and
watching for errors.

CHANGELOG_BEGIN
- [Ledger API Server] Fix a race condition on shutdown in which polling
  for the ledger end could continue even after the database connection
  was closed.
CHANGELOG_END
2020-02-25 15:53:23 +00:00
Stefano Baghino
29755b6d5f
Write command completions to a separate table (#4681)
* Write command completions to a separate table

This should improve the read time and offload filtering to the index database

CHANGELOG_BEGIN
[Ledger API Server] New indexing scheme for command completions, improved performance
CHANGELOG_END

* Allow nullable values for checkpoints

* Added necessary newlines for Flyway migrations

* Address https://github.com/digital-asset/daml/pull/4681#discussion_r383713626

* Address https://github.com/digital-asset/daml/pull/4681#discussion_r383714728

* Record offsets ready to be served by the Ledger API (i.e. the offset shifts by one)

* Address https://github.com/digital-asset/daml/pull/4681#discussion_r383859124
2020-02-25 16:53:03 +01:00
Stefano Baghino
e9a318cee2
Split Ledger API Test Tool output (#4686)
* Split Ledger API Test Tool output

Makes failure pop up even without text coloring (e.g. on Azure Pipelines)

CHANGELOG_BEGIN
[DAML Ledger Integration Kit] Ledger API Test Tool now prints errors as a separate section
CHANGELOG_END

* Successes on the right, failures on the left :)

* Add missing newline
2020-02-25 13:00:20 +00:00
Stefano Baghino
0e02690382
Make the completion service return API response directly (#4675)
* Make the completion service return API response directly

Skip intermediate transformation to CompletionEvent and return the API
response directly. This approach will be followed by a new implementation
that directly stores to and retrieves from the index instead of using the
transaction stream and filtering it.

CHANGELOG_BEGIN
CHANGELOG_END

* Fix build errors

* Address https://github.com/digital-asset/daml/pull/4675#discussion_r383405441

* Address https://github.com/digital-asset/daml/pull/4675#discussion_r383406125

* Address https://github.com/digital-asset/daml/pull/4675#discussion_r383405965
2020-02-24 18:40:45 +00:00
Samir Talwar
3f325c8e96
Sandbox: Fix a bug in the ResetServiceIT timedReset function. (#4665)
* sandbox: Fix a bug in the ResetServiceIT `timedReset` function.

It was computing the start and end times almost simultaneously.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox: Better error messages in ResetServiceIT if resets are slow.

Let the matchers do their magic.
2020-02-24 14:08:20 +00:00
Stefano Baghino
347990ca9c
Relieve Ledger API DB thread pool of unnecessary work (#4657)
Smaller sibling of #4655

CHANGELOG_BEGIN
[Ledger API Server] Better usage of computing resources, should sustain heavier loads
CHANGELOG_END
2020-02-24 11:42:51 +01:00
Remy
0321a1bb32
[Engine] push absolute contract ids inside the evaluation (#4652)
* [Engine] push absolute contract inside the evaluation
* Remove discriminator fom relative contract id

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-21 20:21:35 +01:00
Stefano Baghino
1b23be6cc3
Decode DAML-LF retrieved from the database in the server thread pool (#4655)
This relieves the database thread pool from work it's not supposed to
do.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-21 16:39:18 +00:00
Samir Talwar
d729e5135e
recovering-indexer-integration-tests: Extract from reference-v2. (#4636)
This moves IndexerIT into its own package, and swaps the dependency from
reference-v2 to ledger-on-memory.

This test should ideally live in the sandbox code, but because it
depends on ledger-on-memory, it's easier to keep it separate.

Also rewrites a lot of the code because the API is different. The tests
should now be clearer too.

I've also marked the test as flaky, because, well, it is.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-21 11:10:32 +00:00
Samir Talwar
ba1be72ebd
Revert "sandbox: Log, explaining the removal of static time and scenarios." (#4626)
* Revert "sandbox: Log, explaining the removal of static time and scenarios. (#4582)"

This reverts commit b5cb341e8d.

CHANGELOG_BEGIN
- [Sandbox] Removed the warnings regarding static time and scenarios on
  initialization. We will not deprecate these until we have a stable
  path forward.
CHANGELOG_END

* Sandbox: Include the log level in output.
2020-02-20 14:37:48 +00:00
Samir Talwar
46e046a68b
ledger-on-sql: Split read queries out from write queries. (#4620)
* ledger-on-sql: Provide queries in the transaction lambda.

* ledger-on-sql: Split read queries out from write queries.

Can't run write queries from a read transaction.

CHANGELOG_BEGIN
CHANGELOG_END

* ledger-on-sql: Pass the connection into the `Queries` constructors.

Way less typing this way round.
2020-02-20 13:48:37 +00:00
Samir Talwar
2ec710b0e3
Sandbox & kvutils: Use the existing ledger ID if no ledger ID is specified. (#4607)
* sandbox: If the ledger ID isn't provided, use the one in the database.

Previously, we would fail if working against an existing ledger, and not
explicitly providing the ledger ID. This was the case even if the ledger
ID was randomly generated initially.

CHANGELOG_BEGIN
- [Sandbox] If no ledger ID is provided when running against an existing
  ledger, use the existing ID. Previously, Sandbox would fail to start.
CHANGELOG_END

* sandbox: The ReadOnlySqlLedger should always receive a ledger ID.

It's read-only; it can't create one.

* sandbox: Stop using `equal` in SqlLedgerSpec.

* sandbox: Test that the ledger ID is as specified in SqlLedgerSpec.

* sandbox: Let the top-level runner handle a ledger ID mismatch.

And clean up the log text.

* sandbox: Initialize the ledger properly when the ID is dynamic.

* sandbox: Use `Vector`, not `List`, for SqlLedger initialization.

Append with Vector, good. List, bad.

* ledger-api-common: Make `LedgerApiMode.Dynamic` an object.

And add Java-style static factory methods.

* kvutils/app | ledger-on-{memory,sql}: Make `ledgerId` optional.

It should be generated or retrieved from the persistence layer by the
ledger itself.

* kvutils: Make the ledger ID optional in the tests.

* ledger-on-sql: Store the ledger ID, and reject conflicting IDs.

* ledger-on-sql: Make more things final.

* ledger-on-sql: Document the `ledger_meta.table_key` column better.

* sandbox: Don't hardcode the number of packages in the test DAR.

It changes.

* ledger-on-sql: Merge the `head` resource owner with the `dispatcher`.

* sandbox: Use backticks to simplify pattern match in ReadOnlySqlLedger.

* ledger-on-sql: Extract methods in `owner`.
2020-02-20 10:35:16 +00:00
Stefano Baghino
9eb28924ef
Push down completion requests to data access layer (#4609)
* Push down completion requests to data access layer

This is largely a refactoring. The externally observable behavior is unchanged, but:

- a sub-dao is created for command completions (with the intent of breaking up the dao completely in future commits)
- the command completions dao can, in theory, directly fetch completions off the index
- in practice this is not implemented here to keep this PR as small as possible

Filtering ledger entries to get completions is moved to a function that is in turn used by:
- the ledger dao
- the in-memory sandbox

The plan for the former is to add a new table where completion-relevant data is stored so that it can be fetched quickly.

The plan for the latter is to get rid of it once DAML-on-SQL ships.

CHANGELOG_BEGIN
CHANGELOG_END

* Fix off-by-one error in the in-memory sandbox
2020-02-19 17:37:07 +00:00
Moritz Kiefer
183a2ea9fa
Remove the hardcoded number of packages from JdbcLedgerDaoSpec (#4606)
This breaks every time we change this in damlc which is unnecessary
noise.

changelog_begin
changelog_end
2020-02-19 16:18:15 +00:00
Moritz Kiefer
126e9c68d8
Remove hardcode number of packages from kvutils tests (#4605)
This breaks everytime we add another package to damlc’s default output
which is unnecessary.

changelog_begin
changelog_end
2020-02-19 15:07:39 +01:00
associahedron
5db4ac8b0e
Support type-level strings in DAML. (#4571)
* Add type-level strings in DAML.

This PR adds a `PromotedText` stable package, with `PromotedText` type, which is used to encode type-level strings from DAML into DAML-LF. The reason for this is to preserve the `HasField` instance argument. This PR adds a test that `HasField` is succesfully reconstructed incontexts, during data-dependencies, which wasn't possible before.

changelog_begin
changelog_end

* adresss comments

* fix overly specific tests
2020-02-19 13:10:36 +00:00
Jussi Mäki
61a65fe16f
Use the contract key hasher in kvutils (#4542)
* Use KeyHasher to serialize contract keys in kvutils

- Use Value instead of VersionedValue in GlobalKey as the versioning does not make sense here
  and may be misleading as the a value with a different version but same meaning would still
  be the same key.

- Relocate the KeyHasher to ledger-api-common so kvutils can use it (otherwise cyclic dependencies)

- Replace storing of the contract key as a VersionedValue with the hash produced by KeyHasher.
  This is backwards incompatible. A compatible option would require us to query the key with both
  the old way and the new way which is unattenable. We're making a calculated breaking change.

CHANGELOG_BEGIN
- [DAML Ledger Integration Kit] Serialize contract keys using a hash instead of the value in kvutils.
  This is a backwards incompatible change to kvutils.
CHANGELOG_END

* Use proper hasher for contract keys and not KeyHasher

- Use Hash.scala, not KeyHasher.scala.
- Add hash to GlobalKey as we want the hash to be computed from the inside.
  The use of KeyHasher will be later deprecated and replaced by this.

* Use "sealed abstract case class" trick instead of private ctor

and rebase fix

* Revert change to unsupported value version decode error

* Reformat code

* Add kvutils changelog entry and bump the version
2020-02-19 11:56:31 +00:00
Robert Autenrieth
ba7d23bea0
Introduce new time model fields (#4558)
Those will be used for the new time model.

Fixes #4346.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-19 09:22:43 +01:00
Samir Talwar
b5cb341e8d
sandbox: Log, explaining the removal of static time and scenarios. (#4582)
CHANGELOG_BEGIN
- [Sandbox] Static time mode is being deprecated in the future. A warning has been added to notify users of this fact.
- [Sandbox] Scenarios are being deprecated in the future, in favor of `DAML Script <https://docs.daml.com/daml-script/>`_. A warning has been added to notify users of this fact.
CHANGELOG_END
2020-02-18 19:02:38 +00:00
Miklos
4ee5abc550
Allow custom commit workflow to be implemented for SubmissionValidator (#4587)
* Allow transformations to be written that have access to the ledger state.

CHANGELOG_BEGIN
CHANGELOG_END

* Added missing parameter description.
2020-02-18 18:13:35 +00:00
Samir Talwar
f231ebc1b3
Sandbox-Next: Re-establish static time support. (#4581)
* kvutils: Extract a committer from the uses of `SubmissionValidator`.

This makes the clock injectable too.

* kvutils: Provide logging contexts in the `Runner`.

* sandbox: Remove the `StaticAllowBackwards` time provider type.

It's not used anywhere.

* sandbox: Fix warnings in CliSpec.

* sandbox: Ensure that we cannot specify both static and wall-clock time.

* sandbox-next: Crash if wall clock time is not specified.

* sandbox-next: Document more known issues in the new Sandbox.

* sandbox: Add a Clock (and some tests) to TimeServiceBackend.

* sandbox-next: Support static time.

CHANGELOG_BEGIN
- [Sandbox Next] Re-establish static time mode.
CHANGELOG_END

* ledger-on-(memory|sql): Expect a `() => Instant`, not a `Clock`.
2020-02-18 17:03:15 +00:00
fabiotudone-da
c7d370025e
Fix validator accepting transactions with unallocated informees (#4551)
* Fix validator accepting transactions with unallocated informees.

CHANGELOG_BEGIN
[DAML Ledger Integration Kit] Enforce that all parties referenced as stakeholders, actors, or maintainers in a transaction have been allocated
CHANGELOG_END

* Remove unused `InputsAndEffects.subValues`

* Add unallocated informee failure `KVUtilsTransactionSpec` test

* 📝 Improve documentation of `ClosedWorldIT`

* 🎨 Better names and remove irrelevant formatting changes

* 🎨 Better names and remove useless bindings

* 🎨 Remove irrelevant formatting changes

* 🐛 Fix merge
2020-02-18 15:40:54 +00:00
Stefano Baghino
8df29ac19e
Add more tests to default run of Ledger API Test Tool (#4561)
* Add more tests to default run of Ledger API Test Tool

Furthermore, drop TimeIT, which is a sandbox-only property (and tested already as part of its integration tests)

CHANGELOG_BEGIN
[DAML Ledger Integration Kit] Ledger API Test Tool default tests modified. Use --list for the updated list of default tests. Time service test dropped from the suite.
CHANGELOG_END

* Address https://github.com/digital-asset/daml/pull/4561#discussion_r380635979

* Address https://github.com/digital-asset/daml/pull/4561#discussion_r380636989

* Optimize imports

* Only run semantic tests on Canton
2020-02-18 13:59:46 +00:00
Samir Talwar
b203ccaade
kvutils & ledger-on-sql: Avoid a race condition in dispatching. (#4546)
* kvutils/ledger-on-sql: Avoid a race condition in dispatching.

This changes the API of kvutils to allow for passing data out of the
transaction, which makes it much easier to ensure the new head makes it
to the dispatcher. Previously, we would use an `AtomicLong` to
communicate the data, but this was problematic because values could
arrive out in the wrong order. For example:

  - log index 5 is committed
  - `head` is updated to 6
  - the dispatcher is signalled with a head of 6
  - log index 6 is committed
  - log index 7 is committed
  - `head` is updated to 8
  - `head` is updated to 7
  - the dispatcher is signalled with a head of 7

In this scenario, we would have to wait until a new commit comes in
before the indexer finds out about log index 7.

* kvutils: Just return an `Either`from `SubmissionValidator`.

It was either that or introduce yet another type to split
`SubmissionValidated` into two.

CHANGELOG_BEGIN
CHANGELOG_END

* kvutils: Make ValidationFailed extend NoStackTrace.
2020-02-18 09:08:16 +00:00
Stefano Baghino
3bde5bd0cb
Refactoring: pull contract lookup query in the common queries (#4545)
* Refactoring: pull contract lookup query in the common queries

CHANGELOG_BEGIN
CHANGELOG_END

Closes #4544

* Address https://github.com/digital-asset/daml/pull/4545#discussion_r380199899
2020-02-17 17:52:43 +00:00
Remy
8de42ce062
[Sanbox] use new ContractId scheme (#4533)
CHANGELOG_BEGIN
CHANGELOG_END
2020-02-17 13:30:47 +00:00
Stefano Baghino
5b0ce8039c
Simplify engine contract lookup query (#4543)
* Simplify participant index access for contract lookups

CHANGELOG_BEGIN
[Sandbox] Participant index contract lookups simplified, should speed up command interpretation.
CHANGELOG_END

* Deserialize contracts off of the database connection thread pool
2020-02-17 12:49:59 +00:00
Stefano Baghino
bd32bd6c8f
Return proper code for invalid authentication (#4485)
* Return proper code for invalid authentication

CHANGELOG_BEGIN
[Sandbox] If authentication is enabled, requests without a valid
authentication are going to be rejected with an ``UNAUTHENTICATED``
return code instead of ``PERMISSION_DENIED``.
CHANGELOG_END

* Reduce logging noise from java-rxbindings tests

* Fix rxjava bindings tests to match new behavior

* Fix extractor tests to match new behavior

* Address https://github.com/digital-asset/daml/pull/4485#discussion_r378507478
2020-02-17 11:09:16 +00:00
Stefano Baghino
79817e7387
Reduce data surface exposed by LedgerDao interface (#4538)
CHANGELOG_BEGIN
CHANGELOG_END
2020-02-17 11:08:57 +00:00
Samir Talwar
6577ae2556
ledger-on-sql: Switch to the extra-simplified KVUtils API. (#4532)
* kvutils: Make it easier to import the Key and Value types.

Moved them into a companion object.

* kvutils: Flatten the nested `for` comprehensions in SubmissionValidator.

* kvutils: Test that results succeed before querying state updates.

If they don't, we get idle timeouts and we don't see the error, which is
unhelpful.

* sandbox: Increase log levels for failed submissions.

* kvutils: Avoid converting DamlStateKey -> ByteString -> Array[Byte].

Just convert once.

* ledger-on-sql: Use the `SubmissionValidator` from kvutils.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox: Remove unnecessary interpolation in ApiSubmissionService.
2020-02-15 22:00:04 +00:00
Oliver Seeliger
4acb92d2d3
Ledger api conformance tests: Add synchronize to LotsOfParties tests (#4528)
which are otherwise racy on multinode

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-14 14:52:36 +00:00
Samir Talwar
a589f4af0b
sandbox: Move more resource acquisition into the owner. (#4501)
* sandbox: Move more resource acquisition into the `owner`.

CHANGELOG_BEGIN
CHANGELOG_END

* sandbox: Reimplement SandboxClientResource as a resources.Resource.

* codegen: Use resources in TestUtil.

* sandbox: Manage PostgreSQL in tests with ResourceOwners.
2020-02-14 13:52:45 +00:00
Remy
8394f4ba7d
[DAML-LF] Version new contractId in Proto values (#4460)
* version new contractId

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-13 20:45:46 +01:00
Miklos
a440a3fabd
Simplified API fixes (#4505)
Removed LedgerStateAccess.participantId and renamed LedgerReader.retrieveLedgerId => ledgerId.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-13 19:17:07 +01:00
Remy
4137ff510b
[Engine] Adding a specific type for ParticipantId (#4504)
CHANGELOG_BEGIN
CHANGELOG_END
2020-02-13 17:15:34 +01:00
Miklos
34eec2399a
Index doesn't know about ReadService (#4475)
Made JdbcIndex not depend on ReadService.

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-12 15:49:12 +01:00
Moritz Kiefer
724367017d
Fix sandbox error message when both -w and -s are provided (#4482)
changelog_begin
changelog_end
2020-02-12 09:55:52 +00:00
Moritz Kiefer
36e188cac8
Translate unsupported kinds to a special Erased type (#4474)
* Translate unsupported kinds to a special Erased type

This should simplify `data-dependencies` and avoid issues like #4470
since we can match on the type instead of having to guess which types
can and which cannot be translated back to DAML.

changelog_begin
changelog_end
2020-02-12 09:03:19 +01:00
Gerolf Seitz
85db1033d7
Fix memory leak when using the reset service (#4447)
* sandbox: Don't hold on to old resources when resetting.

Now there's one hell of a memory leak.

CHANGELOG_BEGIN
- [Sandbox] Fixed a memory leak when using the ResetService; not
  everything was cleaned up correctly.
CHANGELOG_END

* sandbox: Split out SandboxClientResource from SandboxServerResource.

Gonna replace SandboxServerResource with a ResourceOwner acquisition.

* sandbox: Don't capture the API server in the SandboxServer resource.

When we reset, this is stored forever, leading to a memory leak.

Tested by rewriting the SandboxServerResource to use
`SandboxServer.owner`.

* sandbox: Revert the test client resource to calling `shutdownNow()`.

* sandbox: Make sure the fixture is recreated properly on each test run.

* sandbox: Make `SandboxState` a non-case class.

The `toString()` was unnecessarily heavy.

* sandbox: Futures, futures everywhere.

Avoid a race condition where the server is stopped before it starts by
storing a `Future[SandboxState]` rather than the `SandboxState` itself.

This doesn't trigger the same memory leak as storing a
`Resource[SandboxState]` because we don't capture the object itself in
the `flatMap` in the same way with `Future`.

* sandbox: Remove an unused parameter left in for debugging.

* sandbox: Replace `@VisibleForTesting` with a comment.

* sandbox: Add more comments to the weird logic in SandboxServer.

* sandbox: Get rid of the `Port` type alias; it was confusing.

Co-authored-by: Samir Talwar <samir.talwar@digitalasset.com>
2020-02-10 16:47:39 +00:00
Miklos
c7183979fd
Added submission validator (#4437)
CHANGELOG_BEGIN
CHANGELOG_END
2020-02-10 17:07:16 +01:00
Remy
e02e5d61bc
Engine: fork method to resolve contractIds (#4411)
* engine: fork method to resolve relative contractId

CHANGELOG_BEGIN
CHANGELOG_END
2020-02-10 16:52:06 +01:00