Skip to content

Commit

Permalink
fix(vat-bank): allow numeric or string nonces (#10929)
Browse files Browse the repository at this point in the history
closes: #10928 
refs: #8544

## Description

The change in #8544 unintentionally disabled `vat-bank`'s vpurse balance notification feature.

### Security Considerations

Since the `vat-bank.js` on mainnet has not been upgraded to the code in #8544, the #10928 issue only pertains to new or upgraded instances of `vat-bank.js`, such as in CI, local chains, and testnet chains.  There is absolutely no impact if this PR is landed before the next `vat-bank.js` upgrade to #8544 code.

### Scaling Considerations

None.

### Documentation Considerations

None.

### Testing Considerations

A unit test would be beneficial, but is not yet implemented.

### Upgrade Considerations

As above, production chains should not upgrade their `vat-bank.js` to the code in current master until this PR lands.
  • Loading branch information
mergify[bot] authored Feb 4, 2025
2 parents b8d96c7 + 02450a3 commit 4a9a6ad
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
15 changes: 7 additions & 8 deletions packages/cosmic-swingset/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { QueuedActionType } from '@agoric/internal/src/action-types.js';
import type {
CoreEval,
CoreEvalSDKType,
} from '@agoric/cosmic-proto/agoric/swingset/swingset.js';
import type { CoreEvalSDKType } from '@agoric/cosmic-proto/agoric/swingset/swingset.js';
import type { BridgeBigInt } from '@agoric/internal';

// TODO move `walletFlags.js` from @agoric/vats to @agoric/cosmic-proto
type PowerFlag = 'SMART_WALLET' | 'REMOTE_WALLET';
Expand All @@ -11,10 +8,12 @@ type PowerFlag = 'SMART_WALLET' | 'REMOTE_WALLET';
// structs or use some other shared type truth
// https://github.com/Agoric/agoric-sdk/issues/8545

export type { BridgeBigInt };

interface ActionContext<T extends Uppercase<string>> {
type: T;
blockHeight: string;
blockTime: string;
blockHeight: BridgeBigInt;
blockTime: BridgeBigInt;
}

/**
Expand All @@ -39,7 +38,7 @@ export type PleaseProvisionAction = ActionContext<'PLEASE_PROVISION'> & {
* @see VbankBalanceUpdate in vbank.go
*/
export type VbankBalanceUpdateAction = ActionContext<'VBANK_BALANCE_UPDATE'> & {
nonce: string;
nonce: BridgeBigInt;
updated: Array<{ address: string; denom: string; amount: string }>;
};

Expand Down
12 changes: 12 additions & 0 deletions packages/internal/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @jessie-check
// @ts-check

import { M } from '@endo/patterns';

Expand All @@ -11,3 +12,14 @@ export const UnguardedHelperI = M.interface(
// not exposed so sloppy okay
{ sloppy: true },
);

/**
* @typedef {number | `${bigint}`} BridgeBigInt Ensure that callees passed a
* bridge message that was serialised from a Golang int64 or uint64 accept
* either a JS number or a stringified JS bigint.
*/

/**
* @type {import('./types.js').TypedPattern<BridgeBigInt>}
*/
export const BridgeBigIntShape = M.or(M.number(), M.string());
1 change: 1 addition & 0 deletions packages/internal/test/snapshots/exports.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
[
'BridgeBigIntShape',
'BridgeId',
'CosmosInitKeyToBridgeId',
'NonNullish',
Expand Down
Binary file modified packages/internal/test/snapshots/exports.test.js.snap
Binary file not shown.
14 changes: 9 additions & 5 deletions packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { E, Far } from '@endo/far';
import { M, getInterfaceGuardPayload } from '@endo/patterns';

import { AmountMath, AssetKind, BrandShape } from '@agoric/ertp';
import { deeplyFulfilledObject } from '@agoric/internal';
import { deeplyFulfilledObject, BridgeBigIntShape } from '@agoric/internal';
import { prepareGuardedAttenuator } from '@agoric/internal/src/callback.js';
import {
IterableEachTopicI,
Expand All @@ -23,8 +23,8 @@ import {

/**
* @import {Guarded} from '@endo/exo';
* @import {Passable, RemotableObject} from '@endo/pass-style';
* @import {BridgeMessage} from '@agoric/cosmic-swingset/src/types.js';
* @import {RemotableObject} from '@endo/pass-style';
* @import {BridgeMessage, BridgeBigInt} from '@agoric/cosmic-swingset/src/types.js';
*/

const { VirtualPurseControllerI } = makeVirtualPurseKitIKit();
Expand All @@ -42,12 +42,12 @@ const BridgeChannelI = M.interface('BridgeChannel', {

/**
* @typedef {Guarded<{
* update: (value: string, nonce?: string) => void;
* update: (value: string, nonce?: BridgeBigInt) => void;
* }>} BalanceUpdater
*/

const BalanceUpdaterI = M.interface('BalanceUpdater', {
update: M.call(M.string()).optional(M.string()).returns(),
update: M.call(M.string()).optional(BridgeBigIntShape).returns(),
});

/**
Expand All @@ -71,6 +71,10 @@ const prepareBalanceUpdater = zone =>
lastBalanceUpdate: -1n,
}),
{
/**
* @param {string} value
* @param {BridgeBigInt} [nonce]
*/
update(value, nonce = undefined) {
if (nonce !== undefined) {
const thisBalanceUpdate = BigInt(nonce);
Expand Down
10 changes: 9 additions & 1 deletion packages/vats/test/vat-bank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { buildRootObject } from '../src/vat-bank.js';
/**
* @import {Remote} from '@agoric/internal';
* @import {BridgeHandler, ScopedBridgeManager} from '../src/types.js';
* @import {VbankBalanceUpdateAction} from '@agoric/cosmic-swingset/src/types.js';
*/

const { fakeVomKit } = reincarnate({ relaxDurabilityRules: false });
Expand Down Expand Up @@ -200,7 +201,14 @@ test('communication', async t => {
const notifier = E(vpurse).getCurrentAmountNotifier();
const updateRecord = await E(notifier).getUpdateSince();
const balance = { address: 'agoricfoo', denom: 'ubld', amount: '92929' };
const obj = { type: 'VBANK_BALANCE_UPDATE', updated: [balance] };
/** @type {VbankBalanceUpdateAction} */
const obj = {
type: 'VBANK_BALANCE_UPDATE',
blockHeight: 992827,
nonce: 123,
blockTime: Date.now() / 1000,
updated: [balance],
};
assert(bankHandler);
await E(bankHandler).fromBridge(obj);

Expand Down

0 comments on commit 4a9a6ad

Please sign in to comment.