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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ on-chain changes. `GET /v1/endorsements/{associationSaid}` exposes local deliver
progress without querying Ethereum. See the [operator guide](docs/status-inbox.md)
for bounded retries and manual recovery.

Verifier acceptance persists until verified association revocation. Oracle selection
Verifier acceptance persists until the Verifier reports `revoked`, which includes revocation
of the LE or QVI credential in its chain. Oracle selection
can supersede an older same-LE issuance without changing that upstream acceptance. Revocation withdraws only the matching
association SAID. Storage ACKs do not mean an on-chain transaction has succeeded. The
association SAID, and a withdrawn mapping is not replaced automatically: a claim must be
presented again as a new association. Storage ACKs do not mean an on-chain transaction has succeeded. The
[two-service qualification](docs/two-service-qualification.md) exercises the installed
applications with witnessed KEL/TEL evidence, signed HTTP and Anvil.

Expand Down
6 changes: 6 additions & 0 deletions docs/two-service-qualification.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ The test follows these boundaries:
Submit another token transfer and confirm that both balances remain unchanged,
even though the policy-failure transaction itself has a successful transaction receipt.

6. Issue fresh associations for both wallets, confirm both mappings and a successful
transfer. Revoke the LE credential with the Verifier fixture (`revoke-source --kind le`)
and present that evidence (`present-source`). Require both statuses `revoked` with
`revocationSource.role` `le`, both endorsements `withdraw`/`completed`, both contract
mappings empty and another transfer that leaves both balances unchanged.

A Grant alone is not a revocation proof: the test supplies verified revocation
TEL and witnessed KEL anchor. Authenticated storage ACK, application status and contract state
are asserted separately. Detailed ownership and delivery edge cases remain in the
Expand Down
13 changes: 11 additions & 2 deletions protocol/oracle-api-v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Both also expose GET /v1/endorsements/{associationSaid}, a passive local resourc
Match the configured path/query, authenticate the exact body first, then decode
the producer's v1 object. Require canonical association/LE SAIDs and issuer AID,
a positive integer status revision and matching event identity. Accept producer
acceptance or explicit verified revocation. Validate nonnegative integer issuance
acceptance or an explicit `revoked` status (which includes revocation of the LE or QVI
credential in the association's chain; the event carries no cause). Validate nonnegative integer issuance
sequence and anchor SAID, and a canonical EOA extId on the configured chain.
Observation metadata is informational and is not required by this consumer.
Credential, proof and account verification are trusted producer responsibilities.
Expand Down Expand Up @@ -64,6 +65,9 @@ status separately from Oracle selection: selected, superseded, rejected or revok
active. Current-SAID verified revocation releases that claim. An earlier rejected
association does not activate on duplicates or later revisions; a new association
is required. Never compare sequence numbers from different issuers' KELs.
- A withdrawn mapping is not replaced automatically. After a release, an already
accepted but unselected claim stays unselected; it must be presented again as a
new association before it can be published.
- Revocation is terminal for its association SAID. Old-SAID revocation cannot release
a successor. Issuance history survives release, transfer and restart; a superseded
predecessor cannot return. Distinct associations sharing an issuance anchor have
Expand All @@ -89,7 +93,12 @@ Contract steps come from current local selection and this writer's confirmed
effects, not periodic contract mapping reads. First publication registers identity
then endorses. Same-identity replacement publishes the new SAID. Entity changes
withdraw, remove identity, register identity, then publish. Revocation withdraws
the exact association; the identity hint can remain. Recheck selection after RPC
the exact association; the identity hint can remain. A revoked LE or QVI credential
revokes every association chained to it, so a burst of events queues serial
withdrawals in arrival order, each its own transaction and nonce; fund the writer
for all of them. A revoked association that is not selected completes with no
transaction. Withdrawal is idempotent on the registry, so a retry after the first
landed has no second effect. Recheck selection after RPC
preparation. Resolve an already signed transaction before applying newer status.

Persist signed bytes/hash before submission. Preparation and definite reverted
Expand Down
2 changes: 1 addition & 1 deletion scripts/integration/dependencies.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"verifier": {
"url": "https://github.com/GLEIF-IT/eoa-verifier.git",
"commit": "e05392b200774ac71e5ee4a4e09c76acfb70a53e"
"commit": "7ea246aa27049075ec615b2dd1d409a7eb6a9c8b"
},
"comply": {
"url": "https://github.com/GLEIF-IT/vlei-comply.git",
Expand Down
291 changes: 290 additions & 1 deletion tests/integration/test_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

from unittest.mock import patch

from tests.support.contracts import KEY, drive, observe, pending_transaction
import pytest

from tests.support.contracts import (
KEY,
drive,
observe,
pending_transaction,
send,
withdrawal_logs,
)
from tests.support.posting import posting_service_for, settle
from tests.support.status_events import event_body, post, said
from vlei_oracle.endorsement.posting import PostingService
from vlei_oracle.endorsement.retrying import RecoveryService
from vlei_oracle.persistence.associations import AssociationReader
from vlei_oracle.persistence.posting import PostingReader, PostingWriter


def test_accepted_replaced_and_revoked_status_changes_real_mapping(peers, deployment):
Expand Down Expand Up @@ -197,3 +209,280 @@ def workflow(effects):
return True

drive(postingService.effects, workflow)


WALLETS = {n: "0x" + f"{n}{n}" * 20 for n in (1, 2, 3)}


def drain(postingService, limit=80):
"""Run the ordinary worker until no queued, preparing or pending work remains."""
for _ in range(limit):
yield from postingService.cycle()
reader = postingService.reader
if (
reader.next_pending() is None
and reader.next_prep() is None
and reader.next_queued() is None
):
return
pytest.fail("posting work did not drain")


def withdrawals(store):
"""Return journaled withdrawal transactions in nonce order."""
return sorted(
(
record
for _, record in store.transactions.getItemIter()
if record.functionName == "withdrawEndorsement"
),
key=lambda record: record.nonce,
)


def test_revoked_burst_withdraws_only_selected_wallets_and_resumes_after_restart(
peers, deployment
):
"""Three published wallets, three revocations, one unselected: two serial withdrawals."""
postingService = posting_service_for(peers, deployment)
rival = peers.receiver.hab.pre # A distinct AID standing in for another LE's QVI.
for number in (1, 2, 3):
assert (
post(
peers,
event_body(peers, f"burst-{number}", 10, wallet=WALLETS[number]),
).status_code
== 200
)
# Wallet 3 also has a competing claim; it is never selected and never published.
assert (
post(
peers, event_body(peers, "burst-rival", 900, issuer=rival, wallet=WALLETS[3])
).status_code
== 200
)
assert peers.inbox.statuses.get(keys=(said("burst-rival"),)).selection == "rejected"

def workflow(effects):
yield from drain(postingService)
for number in (1, 2, 3):
assert (yield from observe(effects, WALLETS[number]))[1][1] == said(
f"burst-{number}"
)
published = peers.inbox.transactions.cntAll()
assert not withdrawals(peers.inbox)
firstNonce = max(r.nonce for _, r in peers.inbox.transactions.getItemIter()) + 1

# FIFO burst: wallet 1, the unselected rival, then wallet 2.
for label, wallet, sequence, issuer in (
("burst-1", 1, 10, None),
("burst-rival", 3, 900, rival),
("burst-2", 2, 10, None),
):
assert (
post(
peers,
event_body(
peers,
label,
sequence,
issuer=issuer,
wallet=WALLETS[wallet],
revoked=True,
),
).status_code
== 200
)

# Run until wallet 2's withdrawal is signed but unmined, then restart.
for _ in range(40):
yield from postingService.cycle()
signed = pending_transaction(peers.inbox)
if signed is not None and signed.associationSaid == said("burst-2"):
break
else:
pytest.fail("second withdrawal was never signed")
assert signed.functionName == "withdrawEndorsement"
assert (yield from observe(effects, WALLETS[1]))[1][1] == ""
assert (yield from observe(effects, WALLETS[2]))[1][1] == said("burst-2")
peers.inbox.close()
peers.inbox.reopen()
# A new service over the reopened store, sharing the running RPC client.
resumed = PostingService(
reader=PostingReader(peers.inbox),
associations=AssociationReader(peers.inbox),
writer=PostingWriter(peers.inbox),
effects=effects,
account=postingService.account,
)
assert pending_transaction(peers.inbox) == signed
yield from drain(resumed)

records = withdrawals(peers.inbox)
assert [r.associationSaid for r in records] == [
said("burst-1"),
said("burst-2"),
]
assert [r.nonce for r in records] == [firstNonce, firstNonce + 1]
assert records[1].txHash == signed.txHash
assert all(r.state == "confirmed" for r in records)
assert peers.inbox.transactions.cntAll() == published + 2
assert len((yield from withdrawal_logs(effects))) == 2
assert (yield from observe(effects, WALLETS[1]))[1][1] == ""
assert (yield from observe(effects, WALLETS[2]))[1][1] == ""
assert (yield from observe(effects, WALLETS[3]))[1][1] == said("burst-3")
phase, unselected = PostingReader(peers.inbox).operation_for(
f"{said('burst-rival')}:2"
)
assert phase == "completed" and unselected.outcome == "revoked"
assert unselected.txHash == "" and unselected.lastTransactionHash == ""
return True

drive(postingService.effects, workflow)


def test_withdrawal_retried_after_it_landed_is_not_sent_twice(peers, deployment):
"""A lost receipt dead-letters a mined withdrawal; manual retry resolves it without resending."""
postingService = posting_service_for(peers, deployment)
wallet, association = WALLETS[1], said("landed")
assert post(peers, event_body(peers, "landed", 10, wallet=wallet)).status_code == 200

def workflow(effects):
yield from drain(postingService)
assert (yield from observe(effects, wallet))[1][1] == association
revoked = event_body(peers, "landed", 10, wallet=wallet, revoked=True)
assert post(peers, revoked).status_code == 200
yield from postingService.cycle() # Sign the withdrawal.
yield from postingService.cycle() # Broadcast it; automine lands it.
signed = pending_transaction(peers.inbox)
assert signed.functionName == "withdrawEndorsement"
assert (yield from observe(effects, wallet))[1][1] == ""
nonce = yield from effects.request(
"eth_getTransactionCount", [effects.writer, "latest"]
)

def unavailable(tx_hash):
yield 0.0
raise TimeoutError("transaction receipt unavailable")

with patch.object(effects, "transaction_receipt", unavailable):
for _ in range(3):
yield from postingService.cycle()
phase, operation = PostingReader(peers.inbox).operation_for(
f"{association}:2"
)
assert phase == "dead" and operation.txHash == signed.txHash
peers.inbox.close()
peers.inbox.reopen()
RecoveryService(
PostingReader(peers.inbox), PostingWriter(peers.inbox)
).retry_operation(operation.operationId)
yield from drain(postingService)

phase, operation = PostingReader(peers.inbox).operation_for(
f"{association}:2"
)
assert phase == "completed"
assert [r.txHash for r in withdrawals(peers.inbox)] == [signed.txHash]
assert peers.inbox.transactions.get(keys=(signed.txHash,)).state == "confirmed"
assert len((yield from withdrawal_logs(effects))) == 1
assert (
yield from effects.request(
"eth_getTransactionCount", [effects.writer, "latest"]
)
) == nonce
assert (yield from observe(effects, wallet))[1][1] == ""
# Exact redelivery of the revoked event creates no further effect.
assert post(peers, revoked).status_code == 200
with patch.object(effects, "request", side_effect=AssertionError("idle RPC")):
yield from postingService.cycle()
return True

drive(postingService.effects, workflow)


def test_withdrawal_after_external_withdrawal_has_no_second_effect(peers, deployment):
"""The registry treats a repeated exact withdrawal as a no-op, so replays are safe."""
postingService = posting_service_for(peers, deployment)
wallet, association = WALLETS[1], said("external")
assert post(peers, event_body(peers, "external", 10, wallet=wallet)).status_code == 200

def workflow(effects):
yield from drain(postingService)
assert (yield from observe(effects, wallet))[1][1] == association
# The withdrawal lands before the Oracle's own transaction does.
yield from send(
effects,
effects.contracts["endorsement"],
"withdrawEndorsement",
[wallet, association],
KEY,
)
assert len((yield from withdrawal_logs(effects))) == 1
assert (
post(
peers, event_body(peers, "external", 10, wallet=wallet, revoked=True)
).status_code
== 200
)
yield from drain(postingService)
records = withdrawals(peers.inbox)
assert len(records) == 1 and records[0].state == "confirmed"
assert len((yield from withdrawal_logs(effects))) == 1
assert (yield from observe(effects, wallet))[1][1] == ""
phase, _ = PostingReader(peers.inbox).operation_for(f"{association}:2")
assert phase == "completed"
return True

drive(postingService.effects, workflow)


def test_no_accepted_claim_is_promoted_after_withdrawal(peers, deployment):
"""A rejected claim stays rejected after the owner's withdrawal; only a new claim publishes."""
postingService = posting_service_for(peers, deployment)
rival = peers.receiver.hab.pre
wallet = WALLETS[1]
assert post(peers, event_body(peers, "owner", 10, wallet=wallet)).status_code == 200
competitor = event_body(peers, "competitor", 900, issuer=rival, wallet=wallet)
assert post(peers, competitor).status_code == 200

def workflow(effects):
yield from drain(postingService)
assert (yield from observe(effects, wallet))[1][1] == said("owner")
assert peers.inbox.statuses.get(keys=(said("competitor"),)).selection == "rejected"
assert (
post(
peers, event_body(peers, "owner", 10, wallet=wallet, revoked=True)
).status_code
== 200
)
yield from drain(postingService)
assert (yield from observe(effects, wallet))[1][1] == ""
transactions = peers.inbox.transactions.cntAll()
competing = peers.inbox.statuses.get(keys=(said("competitor"),))
assert (competing.status, competing.selection) == ("accepted", "rejected")
assert AssociationReader(peers.inbox).selected("eip155:31337:" + wallet) is None

# Redelivery cannot promote it, and nothing is sent.
assert post(peers, competitor).status_code == 200
with patch.object(effects, "request", side_effect=AssertionError("idle RPC")):
for _ in range(3):
yield from postingService.cycle()
assert peers.inbox.transactions.cntAll() == transactions
assert (yield from observe(effects, wallet))[1][1] == ""

# A claim must be presented anew, as a new association.
assert (
post(
peers, event_body(peers, "represented", 901, issuer=rival, wallet=wallet)
).status_code
== 200
)
yield from settle(postingService, wallet, said("represented"))
assert (
AssociationReader(peers.inbox).selected("eip155:31337:" + wallet).associationSaid
== said("represented")
)
return True

drive(postingService.effects, workflow)
Loading
Loading