Skip to content

Commit

Permalink
Remove ExercisedEvent#contract_creating_event_id. (digital-asset#2262)
Browse files Browse the repository at this point in the history
This is a breaking change on the ledger api. So far we could rely on the
assumption that contractId == eventId. This assumption doesn't hold
anymore in a daml-on-x setting, where the eventId is created by the
api server, but the absolute contractId is created by the ledger
implementation.

Instead of going through weird contortions to store the relevant data in
the existing database schema, it is more viable in the long term to
remove that field and instead provide facilities to lookup transactions
by contractId.

Contributes to digital-asset#2068.
  • Loading branch information
gerolf-da authored Jul 29, 2019
1 parent 0109501 commit 136f6d1
Show file tree
Hide file tree
Showing 25 changed files with 15 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ final case class ExercisedEvent(
eventId: String,
contractId: String,
templateId: Identifier,
contractCreatingEventId: String,
choice: String,
choiceArgument: LedgerValue,
actingParties: Set[String],
Expand Down Expand Up @@ -84,7 +83,6 @@ object Event {
apiEvent.eventId,
apiEvent.contractId,
templateId,
apiEvent.contractCreatingEventId,
apiEvent.choice,
choiceArg,
apiEvent.actingParties.toSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class PostgreSQLWriter(config: ExtractorConfig, target: PostgreSQLTarget, ledger
}(scala.collection.breakOut)

val exercisedEvents: List[ExercisedEvent] = transaction.events.values.collect {
case e @ ExercisedEvent(_, _, _, _, _, _, _, _, _, _) => e
case e @ ExercisedEvent(_, _, _, _, _, _, _, _, _) => e
}(scala.collection.breakOut)

logger.trace(s"Create events: ${com.digitalasset.extractor.pformat(createdEvents)}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class MultiTableDataFormat(
if (event.consuming)
setContractArchived(
table.withSchema,
event.contractCreatingEventId,
event.contractId,
transaction.transactionId,
event.eventId).update.run.void
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ object Queries {
,contract_id TEXT NOT NULL
,package_id TEXT NOT NULL
,template TEXT NOT NULL
,contract_creating_event_id TEXT NOT NULL
,choice TEXT NOT NULL
,choice_argument JSONB NOT NULL
,acting_parties JSONB NOT NULL
Expand All @@ -143,7 +142,6 @@ object Queries {
${event.contractId},
${event.templateId.packageId},
${event.templateId.name},
${event.contractCreatingEventId},
${event.choice},
${toJsonString(event.choiceArgument)}::jsonb,
${toJsonString(event.actingParties)}::jsonb,
Expand Down Expand Up @@ -174,15 +172,15 @@ object Queries {
"""

def setContractArchived(
eventId: String,
contractId: String,
transactionId: String,
archivedByEventId: String): Fragment =
sql"""
UPDATE contract
SET
archived_by_transaction_id = ${transactionId},
archived_by_event_id = ${archivedByEventId}
WHERE event_id = ${eventId}
WHERE contract_id = ${contractId}
"""

def insertContract(event: CreatedEvent, transactionId: String, isRoot: Boolean): Fragment =
Expand Down Expand Up @@ -227,13 +225,13 @@ object Queries {

def setContractArchived(
table: String,
eventId: String,
contractId: String,
transactionId: String,
archivedByEventId: String
): Fragment =
Fragment.const(s"UPDATE ${table} SET ") ++
fr"_archived_by_transaction_id = ${transactionId}, " ++
fr"_archived_by_event_id = ${archivedByEventId} WHERE _event_id = ${eventId}"
fr"_archived_by_event_id = ${archivedByEventId} WHERE _contract_id = ${contractId}"

def insertContract(
table: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SingleTableDataFormat extends DataFormat[SingleTableState.type] {
event: ExercisedEvent
): Writer.RefreshPackages \/ ConnectionIO[Unit] = {
val query =
setContractArchived(event.contractCreatingEventId, transaction.transactionId, event.eventId)
setContractArchived(event.contractId, transaction.transactionId, event.eventId)

query.update.run.void.right
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ trait Types {
contract_id: String,
package_id: String,
template: String,
contract_creating_event_id: String,
choice: String,
choice_argument: Json,
acting_parties: Json,
Expand Down
1 change: 0 additions & 1 deletion language-support/hs/bindings/src/DA/Ledger/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ raiseTreeEvent = \case
eid <- raiseEventId exercisedEventEventId
cid <- raiseContractId exercisedEventContractId
tid <- perhaps "exercisedEventTemplateId" exercisedEventTemplateId >>= raiseTemplateId
ccEid <- raiseEventId exercisedEventContractCreatingEventId
choice <- raiseChoice exercisedEventChoice
choiceArg <- perhaps "exercisedEventChoiceArgument" exercisedEventChoiceArgument >>= raiseValue
acting <- raiseList raiseParty exercisedEventActingParties
Expand Down
1 change: 0 additions & 1 deletion language-support/hs/bindings/src/DA/Ledger/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ data TreeEvent
eid :: EventId,
cid :: ContractId,
tid :: TemplateId,
ccEid :: EventId,
choice :: Choice,
choiceArg :: Value,
acting :: [Party],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ object TransactionGenerator {
eventId <- nonEmptyId
contractId <- nonEmptyId
(scalaTemplateId, javaTemplateId) <- identifierGen
creatingEventId <- nonEmptyId
choice <- nonEmptyId
(scalaChoiceArgument, javaChoiceArgument) <- Gen.sized(valueGen)
actingParties <- Gen.listOf(nonEmptyId)
Expand All @@ -247,7 +246,6 @@ object TransactionGenerator {
eventId,
contractId,
Some(scalaTemplateId),
creatingEventId,
choice,
Some(scalaChoiceArgument),
actingParties,
Expand All @@ -261,7 +259,6 @@ object TransactionGenerator {
eventId,
javaTemplateId,
contractId,
creatingEventId,
choice,
javaChoiceArgument,
actingParties.asJava,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class ExercisedEvent implements TreeEvent {

private final String contractId;

private final String contractCreatingEventId;

private final String choice;

private final Value choiceArgument;
Expand All @@ -37,7 +35,6 @@ public ExercisedEvent(@NonNull List<@NonNull String> witnessParties,
@NonNull String eventId,
@NonNull Identifier templateId,
@NonNull String contractId,
@NonNull String contractCreatingEventId,
@NonNull String choice,
@NonNull Value choiceArgument,
@NonNull List<@NonNull String> actingParties,
Expand All @@ -48,7 +45,6 @@ public ExercisedEvent(@NonNull List<@NonNull String> witnessParties,
this.eventId = eventId;
this.templateId = templateId;
this.contractId = contractId;
this.contractCreatingEventId = contractCreatingEventId;
this.choice = choice;
this.choiceArgument = choiceArgument;
this.actingParties = actingParties;
Expand Down Expand Up @@ -81,11 +77,6 @@ public String getContractId() {
return contractId;
}

@NonNull
public String getContractCreatingEventId() {
return contractCreatingEventId;
}

@NonNull
public String getChoice() {
return choice;
Expand Down Expand Up @@ -124,7 +115,6 @@ public boolean equals(Object o) {
Objects.equals(eventId, that.eventId) &&
Objects.equals(templateId, that.templateId) &&
Objects.equals(contractId, that.contractId) &&
Objects.equals(contractCreatingEventId, that.contractCreatingEventId) &&
Objects.equals(choice, that.choice) &&
Objects.equals(choiceArgument, that.choiceArgument) &&
Objects.equals(actingParties, that.actingParties) &&
Expand All @@ -134,7 +124,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {

return Objects.hash(witnessParties, eventId, templateId, contractId, contractCreatingEventId, choice, choiceArgument, actingParties, consuming, exerciseResult);
return Objects.hash(witnessParties, eventId, templateId, contractId, choice, choiceArgument, actingParties, consuming, exerciseResult);
}

@Override
Expand All @@ -144,7 +134,6 @@ public String toString() {
", eventId='" + eventId + '\'' +
", templateId=" + templateId +
", contractId='" + contractId + '\'' +
", contractCreatingEventId='" + contractCreatingEventId + '\'' +
", choice='" + choice + '\'' +
", choiceArgument=" + choiceArgument +
", actingParties=" + actingParties +
Expand All @@ -162,7 +151,6 @@ public String toString() {
.setConsuming(isConsuming())
.setContractId(getContractId())
.setTemplateId(getTemplateId().toProto())
.setContractCreatingEventId(getContractCreatingEventId())
.addAllActingParties(getActingParties())
.addAllWitnessParties(getWitnessParties())
.addAllChildEventIds(getChildEventIds())
Expand All @@ -176,7 +164,6 @@ public static ExercisedEvent fromProto(EventOuterClass.ExercisedEvent exercisedE
exercisedEvent.getEventId(),
Identifier.fromProto(exercisedEvent.getTemplateId()),
exercisedEvent.getContractId(),
exercisedEvent.getContractCreatingEventId(),
exercisedEvent.getChoice(),
Value.fromProto(exercisedEvent.getChoiceArgument()),
exercisedEvent.getActingPartiesList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ object Generators {
choice <- Arbitrary.arbString.arbitrary
choiceArgument <- valueGen
isConsuming <- Arbitrary.arbBool.arbitrary
contractCreatingEventId <- Arbitrary.arbString.arbitrary
witnessParties <- Gen.listOf(Arbitrary.arbString.arbitrary)
exerciseResult <- valueGen
} yield
Expand All @@ -244,7 +243,6 @@ object Generators {
.setChoice(choice)
.setChoiceArgument(choiceArgument)
.setConsuming(isConsuming)
.setContractCreatingEventId(contractCreatingEventId)
.setEventId(eventId)
.addAllWitnessParties(witnessParties.asJava)
.setExerciseResult(exerciseResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ message ExercisedEvent {
// Required
Identifier template_id = 3;

// The ID of the event in which the target contract has been created.
// Must be a valid LedgerString (as described in ``value.proto``).
// Required
string contract_creating_event_id = 4;
reserved 4; // removed field

// The choice that's been exercised on the target contract.
// Must be a valid NameString (as described in ``value.proto``).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ object MockMessages {
eventIdExercised,
contractId,
Some(templateId),
eventIdCreated,
choice,
None,
List(party),
Expand Down Expand Up @@ -114,7 +113,6 @@ object MockMessages {
randomId("event-id"),
randomId("contract-id"),
Some(Identifier(randomId("package-id"), randomId("moduleName"), randomId("template-id"))),
randomId("event-id"),
randomId("choice-id"),
None,
List(randomId("party")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ trait TransactionConversion {
// or remove this field here altogether.
exercise.contractId.coid,
Some(LfEngineToApi.toApiIdentifier(exercise.templateId)),
exercise.contractId.coid,
exercise.choice,
Some(
LfEngineToApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ class GrpcTransactionService(
eventId.unwrap,
contractId.unwrap,
Some(LfEngineToApi.toApiIdentifier(templateId)),
contractCreatingEventId.unwrap,
choice,
Some(
LfEngineToApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ object domain {
eventId: EventId,
contractId: ContractId,
templateId: Ref.Identifier,
contractCreatingEventId: EventId,
choice: Ref.ChoiceName,
choiceArgument: Value,
actingParties: immutable.Set[Ref.Party],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ abstract class CommandTransactionChecks
exercisedEvent.choice shouldBe "DummyChoice1"
exercisedEvent.contractId shouldBe createdEvent.contractId
exercisedEvent.consuming shouldBe true
exercisedEvent.contractCreatingEventId shouldBe createdEvent.eventId
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,8 @@ trait TransactionConversion {
): domain.Event.ExercisedEvent = {
domain.Event.ExercisedEvent(
eventId,
// TODO right now we assume throughout the codebase that the event id _is_ the contract id.
// this is pretty nasty, we should either not assume that and just look the event id up somewhere,
// or remove this field here altogether.
domain.ContractId(exercise.contractId.coid),
exercise.templateId,
domain.EventId(exercise.contractId.coid),
exercise.choice,
exercise.choiceArgument.value,
exercise.actingParties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ final case class EventRow(
subclassType: String,
templateId: Option[String],
recordArgument: Option[String],
contractCreateEventId: Option[String],
choice: Option[String],
argumentValue: Option[String],
actingParties: Option[String],
Expand Down Expand Up @@ -79,7 +78,6 @@ final case class EventRow(
case "ChoiceExercised" =>
(for {
wp <- Try(witnessParties.parseJson.convertTo[List[ApiTypes.Party]])
createId <- Try(contractCreateEventId.get)
chc <- Try(choice.get)
argJson <- Try(argumentValue.get)
tp <- Try(templateId.get)
Expand All @@ -101,7 +99,6 @@ final case class EventRow(
wp,
ApiTypes.WorkflowId(workflowId),
ApiTypes.ContractId(contractId),
ApiTypes.EventId(createId),
tid,
ApiTypes.Choice(chc),
arg,
Expand Down Expand Up @@ -138,7 +135,6 @@ object EventRow {
None,
None,
None,
None,
c.agreementText,
c.signatories.toJson.compactPrint,
c.observers.toJson.compactPrint,
Expand All @@ -155,7 +151,6 @@ object EventRow {
"ChoiceExercised",
Some(e.templateId.asOpaqueString),
None,
Some(e.contractCreateEvent.unwrap),
Some(e.choice.unwrap),
Some(e.argument.toJson.compactPrint),
Some(e.actingParties.toJson.compactPrint),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ object Queries {
subclass_type TEXT NOT NULL,
template_id TEXT DEFAULT NULL,
record_argument JSON DEFAULT NULL,
contract_create_event_id TEXT DEFAULT NULL,
choice TEXT DEFAULT NULL,
argument_value JSON DEFAULT NULL,
acting_parties JSON DEFAULT NULL,
Expand Down Expand Up @@ -128,10 +127,10 @@ object Queries {
INSERT INTO
event
(id, transaction_id, workflow_id, parent_id, contract_id, witness_parties, subclass_type,
template_id, record_argument, contract_create_event_id, choice, argument_value, acting_parties, is_consuming, agreement_text, signatories, observers, contract_key)
template_id, record_argument, choice, argument_value, acting_parties, is_consuming, agreement_text, signatories, observers, contract_key)
VALUES
(${row.id}, ${row.transactionId}, ${row.workflowId}, ${row.parentId}, ${row.contractId}, ${row.witnessParties}, ${row.subclassType},
${row.templateId}, ${row.recordArgument}, ${row.contractCreateEventId}, ${row.choice}, ${row.argumentValue}, ${row.actingParties}, ${row.isConsuming}, ${row.agreementText}, ${row.signatories}, ${row.observers}, ${row.key})
${row.templateId}, ${row.recordArgument}, ${row.choice}, ${row.argumentValue}, ${row.actingParties}, ${row.isConsuming}, ${row.agreementText}, ${row.signatories}, ${row.observers}, ${row.key})
"""

def eventById(id: String): Fragment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ final case class ChoiceExercised(
witnessParties: List[ApiTypes.Party],
workflowId: ApiTypes.WorkflowId,
contractId: ApiTypes.ContractId,
contractCreateEvent: ApiTypes.EventId,
templateId: DamlLfIdentifier,
choice: ApiTypes.Choice,
argument: ApiValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ case object LedgerApiV1 {
witnessParties = witnessParties,
workflowId = workflowId,
contractId = ApiTypes.ContractId(event.contractId),
contractCreateEvent = ApiTypes.EventId(event.contractCreatingEventId),
templateId = templateIdentifier,
choice = ApiTypes.Choice(event.choice),
argument = modelArgument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class RowSpec extends WordSpec with Matchers {
List(ApiTypes.Party("p01")),
ApiTypes.WorkflowId("w01"),
ApiTypes.ContractId("c01"),
ApiTypes.EventId("e02"),
C.complexRecordId,
ApiTypes.Choice("text"),
C.simpleTextV,
Expand Down
Loading

0 comments on commit 136f6d1

Please sign in to comment.