Skip to content

Commit

Permalink
feat: publish OBSERVED with first evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 17, 2024
1 parent c20866d commit 7e62d8f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 43 deletions.
10 changes: 10 additions & 0 deletions packages/boot/test/fast-usdc/fast-usdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ test.serial('makes usdc advance', async t => {
);
harness?.resetRunPolicy();

t.deepEqual(
storage
.getValues(`published.fastUsdc.txns.${evidence.txHash}`)
.map(defaultSerializer.parse),
[
{ evidence, status: 'OBSERVED' }, // observation includes evidence observed
{ status: 'ADVANCING' },
],
);

const doc = {
node: `fastUsdc.txns`,
owner: `the Ethereum transactions upon which Fast USDC is acting`,
Expand Down
14 changes: 10 additions & 4 deletions packages/fast-usdc/src/exos/status-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const prepareStatusManager = (
sequence: true, // avoid overwriting other output in the block
});
void E(txNode).setValue(
JSON.stringify(pureDataMarshaller.toCapData(harden(record))),
JSON.stringify(pureDataMarshaller.toCapData(record)),
);
};

Expand All @@ -119,7 +119,10 @@ export const prepareStatusManager = (
*/
const publishEvidence = (hash, evidence) => {
// Don't await, just writing to vstorage.
void publishTxnRecord(hash, evidence);
void publishTxnRecord(
hash,
harden({ evidence, status: TxStatus.Observed }),
);
};

/**
Expand All @@ -128,7 +131,7 @@ export const prepareStatusManager = (
*/
const publishStatus = (hash, status) => {
// Don't await, just writing to vstorage.
void publishTxnRecord(hash, { status });
void publishTxnRecord(hash, harden({ status }));
if (TerminalTxStatus[status]) {
// UNTIL https://github.com/Agoric/agoric-sdk/issues/7405
// Queue it for deletion later because if we deleted it now the earlier
Expand Down Expand Up @@ -160,7 +163,10 @@ export const prepareStatusManager = (
harden({ ...evidence, status }),
);
publishEvidence(txHash, evidence);
publishStatus(txHash, status);
if (status !== PendingTxStatus.Observed) {
// publishEvidence publishes Observed
publishStatus(txHash, status);
}
};

/**
Expand Down
66 changes: 35 additions & 31 deletions packages/fast-usdc/test/exos/advancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ test('updates status to ADVANCING in happy path', async t => {
bootstrap: { storage },
} = t.context;

const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_OSMO();
void advancer.handleTransactionEvent(mockEvidence);
const evidence = MockCctpTxEvidences.AGORIC_PLUS_OSMO();
void advancer.handleTransactionEvent(evidence);

// pretend borrow succeeded and funds were depositing to the LCA
resolveLocalTransferV();
Expand All @@ -186,8 +186,11 @@ test('updates status to ADVANCING in happy path', async t => {
await eventLoopIteration();

t.deepEqual(
storage.getDeserialized(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Advancing }],
storage.getDeserialized(`fun.txns.${evidence.txHash}`),
[
{ evidence, status: PendingTxStatus.Observed },
{ status: PendingTxStatus.Advancing },
],
'ADVANCED status in happy path',
);

Expand Down Expand Up @@ -215,11 +218,11 @@ test('updates status to ADVANCING in happy path', async t => {
t.like(inspectNotifyCalls(), [
[
{
txHash: mockEvidence.txHash,
forwardingAddress: mockEvidence.tx.forwardingAddress,
fullAmount: usdc.make(mockEvidence.tx.amount),
txHash: evidence.txHash,
forwardingAddress: evidence.tx.forwardingAddress,
fullAmount: usdc.make(evidence.tx.amount),
destination: {
value: decodeAddressHook(mockEvidence.aux.recipientAddress).query.EUD,
value: decodeAddressHook(evidence.aux.recipientAddress).query.EUD,
},
},
true, // indicates transfer succeeded
Expand Down Expand Up @@ -255,13 +258,13 @@ test('updates status to OBSERVED on insufficient pool funds', async t => {
intermediateRecipient,
});

const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_DYDX();
void advancer.handleTransactionEvent(mockEvidence);
const evidence = MockCctpTxEvidences.AGORIC_PLUS_DYDX();
void advancer.handleTransactionEvent(evidence);
await eventLoopIteration();

t.deepEqual(
storage.getDeserialized(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Observed }],
storage.getDeserialized(`fun.txns.${evidence.txHash}`),
[{ evidence, status: PendingTxStatus.Observed }],
'OBSERVED status on insufficient pool funds',
);

Expand All @@ -285,12 +288,12 @@ test('updates status to OBSERVED if makeChainAddress fails', async t => {
},
} = t.context;

const mockEvidence = MockCctpTxEvidences.AGORIC_UNKNOWN_EUD();
await advancer.handleTransactionEvent(mockEvidence);
const evidence = MockCctpTxEvidences.AGORIC_UNKNOWN_EUD();
await advancer.handleTransactionEvent(evidence);

t.deepEqual(
storage.getDeserialized(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Observed }],
storage.getDeserialized(`fun.txns.${evidence.txHash}`),
[{ evidence, status: PendingTxStatus.Observed }],
'OBSERVED status on makeChainAddress failure',
);

Expand All @@ -314,16 +317,19 @@ test('calls notifyAdvancingResult (AdvancedFailed) on failed transfer', async t
brands: { usdc },
} = t.context;

const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_DYDX();
void advancer.handleTransactionEvent(mockEvidence);
const evidence = MockCctpTxEvidences.AGORIC_PLUS_DYDX();
void advancer.handleTransactionEvent(evidence);

// pretend borrow and deposit to LCA succeed
resolveLocalTransferV();
await eventLoopIteration();

t.deepEqual(
storage.getDeserialized(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Advancing }],
storage.getDeserialized(`fun.txns.${evidence.txHash}`),
[
{ evidence, status: PendingTxStatus.Observed },
{ status: PendingTxStatus.Advancing },
],
'tx is Advancing',
);

Expand All @@ -340,14 +346,12 @@ test('calls notifyAdvancingResult (AdvancedFailed) on failed transfer', async t
t.like(inspectNotifyCalls(), [
[
{
txHash: mockEvidence.txHash,
forwardingAddress: mockEvidence.tx.forwardingAddress,
fullAmount: usdc.make(mockEvidence.tx.amount),
advanceAmount: feeTools.calculateAdvance(
usdc.make(mockEvidence.tx.amount),
),
txHash: evidence.txHash,
forwardingAddress: evidence.tx.forwardingAddress,
fullAmount: usdc.make(evidence.tx.amount),
advanceAmount: feeTools.calculateAdvance(usdc.make(evidence.tx.amount)),
destination: {
value: decodeAddressHook(mockEvidence.aux.recipientAddress).query.EUD,
value: decodeAddressHook(evidence.aux.recipientAddress).query.EUD,
},
},
false, // this indicates transfer failed
Expand All @@ -364,13 +368,13 @@ test('updates status to OBSERVED if pre-condition checks fail', async t => {
},
} = t.context;

const mockEvidence = MockCctpTxEvidences.AGORIC_NO_PARAMS();
const evidence = MockCctpTxEvidences.AGORIC_NO_PARAMS();

await advancer.handleTransactionEvent(mockEvidence);
await advancer.handleTransactionEvent(evidence);

t.deepEqual(
storage.getDeserialized(`fun.txns.${mockEvidence.txHash}`),
[mockEvidence, { status: PendingTxStatus.Observed }],
storage.getDeserialized(`fun.txns.${evidence.txHash}`),
[{ evidence, status: PendingTxStatus.Observed }],
'tx is recorded as OBSERVED',
);

Expand Down
5 changes: 2 additions & 3 deletions packages/fast-usdc/test/exos/settler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ test('happy path: disburse to LPs; StatusManager removes tx', async t => {
await eventLoopIteration();
const { storage } = t.context;
t.deepEqual(storage.getDeserialized(`fun.txns.${cctpTxEvidence.txHash}`), [
cctpTxEvidence,
{ evidence: cctpTxEvidence, status: 'OBSERVED' },
{ status: 'ADVANCING' },
{ status: 'ADVANCED' },
{ status: 'DISBURSED' },
Expand Down Expand Up @@ -314,8 +314,7 @@ test('slow path: forward to EUD; remove pending tx', async t => {
);
const { storage } = t.context;
t.deepEqual(storage.getDeserialized(`fun.txns.${cctpTxEvidence.txHash}`), [
cctpTxEvidence,
{ status: 'OBSERVED' },
{ evidence: cctpTxEvidence, status: 'OBSERVED' },
{ status: 'FORWARDED' },
]);

Expand Down
9 changes: 4 additions & 5 deletions packages/fast-usdc/test/exos/status-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('ADVANCED transactions are published to vstorage', async t => {

const { storage } = t.context;
t.deepEqual(storage.getDeserialized(`fun.txns.${evidence.txHash}`), [
evidence,
{ evidence, status: 'OBSERVED' },
{ status: 'ADVANCING' },
]);
});
Expand Down Expand Up @@ -90,8 +90,7 @@ test('OBSERVED transactions are published to vstorage', async t => {

const { storage } = t.context;
t.deepEqual(storage.getDeserialized(`fun.txns.${evidence.txHash}`), [
evidence,
{ status: 'OBSERVED' },
{ evidence, status: 'OBSERVED' },
]);
});

Expand Down Expand Up @@ -235,7 +234,7 @@ test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
]);
await eventLoopIteration();
t.deepEqual(storage.getDeserialized(`fun.txns.${e1.txHash}`), [
e1,
{ evidence: e1, status: 'OBSERVED' },
{ status: 'ADVANCING' },
{ status: 'ADVANCED' },
]);
Expand All @@ -249,7 +248,7 @@ test('advanceOutcome transitions to ADVANCED and ADVANCE_FAILED', async t => {
]);
await eventLoopIteration();
t.deepEqual(storage.getDeserialized(`fun.txns.${e2.txHash}`), [
e2,
{ evidence: e2, status: 'OBSERVED' },
{ status: 'ADVANCING' },
{ status: 'ADVANCE_FAILED' },
]);
Expand Down

0 comments on commit 7e62d8f

Please sign in to comment.