Skip to content

Commit

Permalink
feat: clean up upon last attest
Browse files Browse the repository at this point in the history
Before this each third attest was treated as a new transaction
  • Loading branch information
turadg committed Mar 1, 2025
1 parent d9611a7 commit 1bfd098
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 155 deletions.
58 changes: 32 additions & 26 deletions packages/fast-usdc/src/exos/transaction-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,40 +217,46 @@ export const prepareTransactionFeedKit = (zone, zcf) => {
}
}

{
const minAttestations = Math.ceil(operators.getSize() / 2);
trace(
'transaction',
txHash,
'has',
found.length,
'of',
minAttestations,
'necessary attestations',
);
if (found.length < minAttestations) {
return;
}
const minAttestations = Math.ceil(operators.getSize() / 2);
trace(
'transaction',
txHash,
'has',
found.length,
'of',
minAttestations,
'necessary attestations',
);

if (found.length < minAttestations) {
return;
}

const riskStores = [...risks.values()].filter(store =>
store.has(txHash),
);
// take the union of risks identified from all operators
const risksIdentified = allRisksIdentified(riskStores, txHash);

// sufficient agreement, so remove from pending risks, then publish
for (const store of found) {
store.delete(txHash);
// Publish at the threshold of agreement
if (found.length === minAttestations) {
// take the union of risks identified from all operators
const risksIdentified = allRisksIdentified(riskStores, txHash);
trace('publishing evidence', evidence, risksIdentified);
publisher.publish({
evidence,
risk: { risksIdentified },
});
return;
}
for (const store of riskStores) {
store.delete(txHash);

if (found.length === pending.getSize()) {
// all have reported so stop tracking
for (const store of found) {
store.delete(txHash);
}
for (const store of riskStores) {
store.delete(txHash);
}
}
trace('publishing evidence', evidence, risksIdentified);
publisher.publish({
evidence,
risk: { risksIdentified },
});
},
},
public: {
Expand Down
14 changes: 8 additions & 6 deletions packages/fast-usdc/test/exos/transaction-feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,19 @@ test('disagreement after publishing', async t => {
updateCount: 1n,
});

// it's simply ignored
t.notThrows(() => op3.operator.submitEvidence(e1bad));
t.throws(() => op3.operator.submitEvidence(e1bad), {
message: /conflicting evidence/,
});
t.like(await evidenceSubscriber.getUpdateSince(0), {
updateCount: 1n,
});

// now another op repeats the bad evidence, so it's published to the stream.
// It's the responsibility of the Advancer to fail because it has already processed that tx hash.
op1.operator.submitEvidence(e1bad);
// Disagreement is still detected after publishing
t.throws(() => op1.operator.submitEvidence(e1bad), {
message: /conflicting evidence/,
});
t.like(await evidenceSubscriber.getUpdateSince(0), {
updateCount: 2n,
updateCount: 1n,
});
});

Expand Down
140 changes: 17 additions & 123 deletions packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3103,158 +3103,52 @@ Generated by [AVA](https://avajs.dev).
},
},
pending: {
'operator-0': {},
'operator-1': {
'0x000008': {
'operator-0': {
'0x0000010': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzvr5wscqq9qe499xw',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzetpwfkrxqq5g04wk9',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037671n,
blockNumber: 21037673n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 5000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000008',
txHash: '0x0000010',
},
},
'operator-2': {
'0x000001': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nqq2qhf2ep2',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037664n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 1000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000001',
},
'0x000002': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nx3skganpde3k2jrpwpc8jqq5jzq8ex',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037665n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 108000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000002',
},
'0x000003': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nx3ssq9qfqjyle',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037666n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 110000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000003',
},
'0x000004': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nx33qq9q874uwh',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037667n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 120000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000004',
},
'0x000005': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nx33sq9qdp5z6c',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037668n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 125000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000005',
},
'0x000006': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nvfhkydgqzs8gv9xu',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037669n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 6000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000006',
},
'0x000007': {
'operator-1': {
'0x0000010': {
aux: {
forwardingChannel: 'channel-21',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzv3nqq2qhf2ep2',
recipientAddress: 'agoric10rchqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq06924zr6mmnd4hnzetpwfkrxqq5g04wk9',
},
blockHash: '0x90d7343e04f8160892e94f02d6a9b9f255663ed0ac34caca98544c8143fee665',
blockNumber: 21037670n,
blockNumber: 21037673n,
blockTimestamp: 1632340000n,
chainId: 1,
tx: {
amount: 150000000n,
amount: 5000000n,
forwardingAddress: 'noble1x0ydg69dh6fqvr27xjvp6maqmrldam6yfelqkd',
sender: '0xDefaultFakeEthereumAddress',
},
txHash: '0x000007',
txHash: '0x0000010',
},
},
'operator-2': {},
},
risks: {
'operator-0': {},
'operator-1': {
'0x000008': {},
'operator-0': {
'0x0000010': {},
},
'operator-2': {
'0x000001': {
risksIdentified: [
'RISK1',
],
},
'0x000002': {},
'0x000003': {},
'0x000004': {},
'0x000005': {},
'0x000006': {},
'0x000007': {},
'operator-1': {
'0x0000010': {},
},
'operator-2': {},
},
settlerKit: {
creator: Object @Alleged: Fast USDC Settler creator {},
Expand Down
Binary file modified packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap
Binary file not shown.

0 comments on commit 1bfd098

Please sign in to comment.