Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ subprojects {

spotless {
java {
// Upgrade the formatter independently: Spotless 8.11 changes its default to 2.x.
googleJavaFormat(libs.findVersion("google-java-format").get().requiredVersion)
// Keep formatter upgrades limited to layout; do not rewrite Java syntax.
googleJavaFormat(libs.findVersion("google-java-format").get().requiredVersion).cleanup(false)
targetExclude("build/generated/**", "build/generated-src/**")
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lombok-mapstruct-binding = "0.2.0"
grpc = "1.85.1"
protobuf = "4.36.2"
spotbugs = "4.10.5"
google-java-format = "1.36.1"
google-java-format = "2.0.0"
opentelemetry = "1.68.0"
micrometer = "1.17.2"
jjwt = "0.13.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ public Snapshot captureAccount(UUID authenticatedAccountId) {
}
List<String> roles = Arrays.asList(roleValues.clone());
if (roles.stream()
.anyMatch(
value ->
value == null
|| !java.util.Set.of("platformAdmin", "billingAdmin", "support")
.contains(value))
.anyMatch(value ->
value == null
|| !java.util.Set.of("platformAdmin", "billingAdmin", "support")
.contains(value))
|| !roles.equals(roles.stream().distinct().sorted().toList())) {
throw unavailable();
}
Expand All @@ -189,14 +188,13 @@ public Snapshot captureAccount(UUID authenticatedAccountId) {
authority.put("privateRealmGrantVersions", List.of());
source
.accountSecurityCutoff()
.ifPresent(
cutoff ->
authority.put(
"accountSecurityCutoff",
Map.of(
"accountAuthorityGeneration", cutoff.accountAuthorityGeneration(),
"outboxStreamKey", cutoff.outboxStreamKey(),
"outboxSequence", cutoff.outboxSequence())));
.ifPresent(cutoff ->
authority.put(
"accountSecurityCutoff",
Map.of(
"accountAuthorityGeneration", cutoff.accountAuthorityGeneration(),
"outboxStreamKey", cutoff.outboxStreamKey(),
"outboxSequence", cutoff.outboxSequence())));
byte[] issuerBytes =
current.canonicalIssuerProjection().toJson().getBytes(StandardCharsets.UTF_8);
byte[] accountBytes =
Expand Down Expand Up @@ -305,14 +303,13 @@ private void requireOwnerTransaction() {
|| TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
throw unavailable();
}
dsl.connection(
connection -> {
if (connection.getAutoCommit()
|| connection.isReadOnly()
|| connection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) {
throw unavailable();
}
});
dsl.connection(connection -> {
if (connection.getAutoCommit()
|| connection.isReadOnly()
|| connection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) {
throw unavailable();
}
});
}

private static IllegalStateException unavailable() {
Expand Down Expand Up @@ -372,37 +369,34 @@ private Snapshot snapshot(
authority.put("privateRealmGrantVersions", List.of());
tuple
.accountSecurityCutoff()
.ifPresent(
cutoff ->
authority.put(
"accountSecurityCutoff",
Map.of(
"accountAuthorityGeneration",
cutoff.accountAuthorityGeneration(),
"outboxStreamKey",
cutoff.outboxStreamKey(),
"outboxSequence",
cutoff.outboxSequence())));
.ifPresent(cutoff ->
authority.put(
"accountSecurityCutoff",
Map.of(
"accountAuthorityGeneration",
cutoff.accountAuthorityGeneration(),
"outboxStreamKey",
cutoff.outboxStreamKey(),
"outboxSequence",
cutoff.outboxSequence())));
tuple
.tenantBillingCutoff()
.ifPresent(
cutoffs -> {
Map<String, Object> values = new LinkedHashMap<>();
cutoffs.forEach(
(id, cutoff) ->
values.put(
id,
Map.of(
"tenantAuthorityGeneration",
Long.parseLong(cutoff.tenantAuthorityGeneration()),
"tenantBillingSequence",
Long.parseLong(cutoff.tenantBillingSequence()),
"outboxStreamKey",
cutoff.outboxStreamKey(),
"outboxSequence",
Long.parseLong(cutoff.outboxSequence()))));
authority.put("tenantBillingCutoff", Map.copyOf(values));
});
.ifPresent(cutoffs -> {
Map<String, Object> values = new LinkedHashMap<>();
cutoffs.forEach((id, cutoff) ->
values.put(
id,
Map.of(
"tenantAuthorityGeneration",
Long.parseLong(cutoff.tenantAuthorityGeneration()),
"tenantBillingSequence",
Long.parseLong(cutoff.tenantBillingSequence()),
"outboxStreamKey",
cutoff.outboxStreamKey(),
"outboxSequence",
Long.parseLong(cutoff.outboxSequence()))));
authority.put("tenantBillingCutoff", Map.copyOf(values));
});
var upstream = existing.issuerAccount();
var issuanceFenceSource = requireIssuanceFenceSource(member);
byte[] issuer = upstream.canonicalIssuerProjection().toJson().getBytes(StandardCharsets.UTF_8);
Expand Down Expand Up @@ -489,21 +483,19 @@ private Snapshot snapshot(
.toList()));
var checkpoints =
member.outboxCheckpoints().stream()
.map(
checkpoint -> {
Map<String, Object> value = new LinkedHashMap<>();
value.put("outboxStreamKey", checkpoint.outboxStreamKey());
value.put("outboxSequence", checkpoint.outboxSequence());
member.outboxSourceEvidence().stream()
.filter(event -> event.outboxStreamKey().equals(checkpoint.outboxStreamKey()))
.findFirst()
.ifPresent(
event -> {
value.put("sourceEventId", event.eventId());
value.put("sourceEventDigest", event.eventDigest());
});
return Map.copyOf(value);
})
.map(checkpoint -> {
Map<String, Object> value = new LinkedHashMap<>();
value.put("outboxStreamKey", checkpoint.outboxStreamKey());
value.put("outboxSequence", checkpoint.outboxSequence());
member.outboxSourceEvidence().stream()
.filter(event -> event.outboxStreamKey().equals(checkpoint.outboxStreamKey()))
.findFirst()
.ifPresent(event -> {
value.put("sourceEventId", event.eventId());
value.put("sourceEventDigest", event.eventDigest());
});
return Map.copyOf(value);
})
.toList();
Map<String, Object> identity =
Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,26 @@ public void requireHeld(DraftCommitOrderReadEvidence.Request request) {
throw invalid("Complete canonical original Account binding is required");
}
try {
ownerTransaction.execute(
status -> {
DraftAuthorizationFenceBinding retained =
repository
.readOriginalBinding(requested.operationId())
.orElseThrow(AccountDraftCommitOrderReadService::unheld);
if (!Arrays.equals(retained.canonicalBytes(), request.originalAccountBinding())) {
throw unheld();
}
ownerTransaction.execute(status -> {
DraftAuthorizationFenceBinding retained =
repository
.readOriginalBinding(requested.operationId())
.orElseThrow(AccountDraftCommitOrderReadService::unheld);
if (!Arrays.equals(retained.canonicalBytes(), request.originalAccountBinding())) {
throw unheld();
}

var fence = repository.read(retained);
if (fence.ordering() != Ordering.COMMIT_ORDER
|| fence.reservedAt() == null
|| fence.orderedAt() == null
|| !Arrays.equals(fence.binding(), request.originalAccountBinding())) {
throw unheld();
}
Settlement settlement = repository.readSettlement(retained);
if (settlement != Settlement.PENDING) throw unheld();
return null;
});
var fence = repository.read(retained);
if (fence.ordering() != Ordering.COMMIT_ORDER
|| fence.reservedAt() == null
|| fence.orderedAt() == null
|| !Arrays.equals(fence.binding(), request.originalAccountBinding())) {
throw unheld();
}
Settlement settlement = repository.readSettlement(retained);
if (settlement != Settlement.PENDING) throw unheld();
return null;
});
} catch (StatusRuntimeException failure) {
throw failure;
} catch (DataAccessException | org.jooq.exception.DataAccessException unavailable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,17 @@ public ExistingSources readExistingSources(
CreatorPartyEncoding.creation(creator), bootstrap.creatorEvidencePayload())
|| currentTerms.sourceEvidence().stream()
.filter(source -> source.kind() == SourceKind.CREATOR_PARTY)
.noneMatch(
source ->
source.scopeId().equals(association.partySource().creatorPartyId().toString())
&& Objects.equals(
source.generation(),
Long.toString(association.partySource().identityVersion()))
&& source
.sourceVersion()
.equals(Long.toString(association.partySource().sourceVersion()))
&& Arrays.equals(
source.evidence(),
CreatorPartyEncoding.party(association.partySource())))) {
.noneMatch(source ->
source.scopeId().equals(association.partySource().creatorPartyId().toString())
&& Objects.equals(
source.generation(),
Long.toString(association.partySource().identityVersion()))
&& source
.sourceVersion()
.equals(Long.toString(association.partySource().sourceVersion()))
&& Arrays.equals(
source.evidence(),
CreatorPartyEncoding.party(association.partySource())))) {
throw mismatch();
}
return new ExistingSources(membership, issuerAccount, association, currentTerms);
Expand Down Expand Up @@ -172,14 +171,13 @@ private void requireOwnerTransaction() {
|| TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
throw new IllegalStateException("Writable READ_COMMITTED Account transaction required");
}
dsl.connection(
connection -> {
if (connection.getAutoCommit()
|| connection.isReadOnly()
|| connection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) {
throw new IllegalStateException("Writable READ_COMMITTED Account transaction required");
}
});
dsl.connection(connection -> {
if (connection.getAutoCommit()
|| connection.isReadOnly()
|| connection.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED) {
throw new IllegalStateException("Writable READ_COMMITTED Account transaction required");
}
});
}

private static IllegalStateException mismatch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,23 @@ public Optional<Settlement> reconcile(UUID operationId) {
: Optional.empty();

Settlement settled =
ownerTransaction.execute(
status -> {
DraftAuthorizationFenceBinding current =
repository
.readOriginalBinding(operationId)
.orElseThrow(
() -> new IllegalStateException("Original Draft operation disappeared"));
if (!Arrays.equals(current.canonicalBytes(), before.binding().canonicalBytes())) {
throw new IllegalStateException("Original Draft binding changed during recovery");
}
Snapshot after = snapshot(current);
if (after.ordering() != before.ordering()) {
throw new IllegalStateException("Original Draft ordering changed during recovery");
}
retainExactMissing(current, Owner.GAME_DESIGN, gameDesignReadback, after);
retainExactMissing(current, Owner.WORLD, worldReadback, after);
return repository.readSettlement(current);
});
ownerTransaction.execute(status -> {
DraftAuthorizationFenceBinding current =
repository
.readOriginalBinding(operationId)
.orElseThrow(
() -> new IllegalStateException("Original Draft operation disappeared"));
if (!Arrays.equals(current.canonicalBytes(), before.binding().canonicalBytes())) {
throw new IllegalStateException("Original Draft binding changed during recovery");
}
Snapshot after = snapshot(current);
if (after.ordering() != before.ordering()) {
throw new IllegalStateException("Original Draft ordering changed during recovery");
}
retainExactMissing(current, Owner.GAME_DESIGN, gameDesignReadback, after);
retainExactMissing(current, Owner.WORLD, worldReadback, after);
return repository.readSettlement(current);
});
return Optional.of(Objects.requireNonNull(settled));
}

Expand Down Expand Up @@ -143,14 +142,13 @@ private Optional<OwnerReadback> readStoredOwnerResult(
if (!binding.requiredOwners().contains(owner)) return Optional.empty();
return repository
.readOwnerResult(binding, owner)
.map(
stored -> {
OwnerReadback readback = OwnerReadback.fromStored(stored.readback());
if (stored.outcome() != readback.outcome()) {
throw new IllegalStateException("Stored Draft outcome differs from its readback");
}
return verifyOwnerReadback(binding, owner, readback);
});
.map(stored -> {
OwnerReadback readback = OwnerReadback.fromStored(stored.readback());
if (stored.outcome() != readback.outcome()) {
throw new IllegalStateException("Stored Draft outcome differs from its readback");
}
return verifyOwnerReadback(binding, owner, readback);
});
}

private static OwnerReadback verifyOwnerReadback(
Expand Down
Loading
Loading