Skip to content

Commit

Permalink
Merge branch 'master' into markm-compress-with-split-reform
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed May 17, 2024
2 parents cb1bf94 + 303a9f2 commit dfae2c8
Show file tree
Hide file tree
Showing 125 changed files with 1,502 additions and 1,054 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/mergify-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ jobs:
with:
fetch-depth: 0
- shell: bash
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
HEAD_LABEL: ${{ github.event.pull_request.head.label }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BASE_LABEL: ${{ github.event.pull_request.base.label }}
run: |
HEAD_SHA=${{ github.event.pull_request.head.sha }}
HEAD_LABEL="${{ github.event.pull_request.head.label }}"
BASE_SHA=${{ github.event.pull_request.base.sha }}
BASE_LABEL="${{ github.event.pull_request.base.label }}"
merge_commits=$(git rev-list --merges "$BASE_SHA".."$HEAD_SHA")
if [ -n "$merge_commits" ]; then
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,26 @@ jobs:
- name: Install graphviz
run: sudo apt install -y graphviz

# This is now redundant with Lerna's --reject-cycles but keep it here so we have
# test coverage of this script we use for visualizing the dep graph.
- name: Check for cycles
run: scripts/check-dependency-cycles.sh

# install node_modules
- uses: ./.github/actions/restore-node

# Releasing SDK builds all packages in this order during `lerna publish`.
# Due to ambient types, certain build orders (from the dependency graph)
# may break the type resolution. Run this in the PR to find out before
# attempting to merge to master. This takes about 1min locally and since
# this job is about 30s in CI doing it here doesn't add to wall wait
# for CI resolution.
# We prepack only because full pack removes the declarations, relying on ambient
# resolution in the repo filesystem which will not be available when the packages
# are pulled from npm.
- name: Pack packages
run: yarn lerna run --reject-cycles --concurrency 1 prepack

##################
# Lint tests
# We run per package bc of https://github.com/typescript-eslint/typescript-eslint/issues/1192
Expand Down
46 changes: 43 additions & 3 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,60 @@ Our use of TypeScript has to accomodate both .js development in agoric-sdk (whic

## Best practices

- `.d.ts` for types modules
- package entrypoint(s) exports explicit types
- for packages upon which other packages expect ambient types:
- `exported.js` exports the explicit types and ambient re-exports

## .d.ts modules

We cannot use `.ts` files any modules that are transitively imported into an Endo bundle. The reason is that the Endo bundler doesn't understand `.ts` syntax and we don't want it to until we have sufficient auditability of the transformation. Moreover we've tried to avoid a build step in order to import a module. (The one exception so far is `@agoric/cosmic-proto` because we codegen the types. Those modules are written in `.ts` syntax and build to `.js` by a build step that creates `dist`, which is the package export.)

A `.d.ts` module allows defining the type in `.ts` syntax, without any risk that it will be included in runtime code. The `.js` is what actually gets imported.

The are some consequences to this approach.

### File pair

You have to create a `.js` and `.d.ts` pair for each module. Usually it's of the form,

```js
// Empty JS file to correspond with its .d.ts twin
export {};
```

### Lack of type checking

We have `"skipLibCheck": true"` in the root tsconfig.json because some libraries we depend on have their own type errors. (A massive one is the output of Telescope, used in `@agoric/cosmic-proto`.)

This means that the types you write in `.d.ts` file won't be checked by `tsc`. To gain some confidence, you can temporarily flip that setting in a package's own `tsconfig.json` and pay attention to only the relevant errors.

### Alternatives

We've experimented with having `.ts` files. It works, and gets around the skipLibCheck problem, but it complicates the build and exports. It also necessitates a build step even in package that don't currently need it.

## entrypoint

This is usually an `index.js` file which contains a wildcard export like,

```js
// eslint-disable-next-line import/export -- just types
export * from './src/types.js';
```

The `types.js` file either defines the types itself or is an empty file (described above) paired with a `.d.ts` or `.ts` twin.

One option considered is having the conditional package `"exports"` include `"types"` but that has to be a .d.ts file. That could be generated from a `.ts` but it would require a build step, which we've so far avoided.

Once we have [JSDoc export type support](https://github.com/microsoft/TypeScript/issues/48104) we'll be able instead to keep the `index.js` entrypoint and have it export the types from `.ts` files without a runtime import of the module containing them.

## exported.js

The `exported.js` re-exports types into global namespace, for consumers that expect these to
be ambient. This could be called "ambient.js" but we retain the filename for backwards compatibility.

The pattern is to make these two files like this at package root:


`exported.js`

```ts
Expand Down Expand Up @@ -44,7 +86,6 @@ Why the _ prefix? Because without it TS gets confused between the
import and export symbols. ([h/t](https://stackoverflow.com/a/66588974))
Note one downside vs ambients is that these types will appear to be on `globalThis`.


## Generating API docs

We use [TypeDoc](https://typedoc.org/) to render API docs in HTML.
Expand All @@ -53,4 +94,3 @@ We use [TypeDoc](https://typedoc.org/) to render API docs in HTML.
yarn docs
open api-docs/index.html
```

5 changes: 1 addition & 4 deletions golang/cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/cosmos/ibc-go/v6 v6.3.1
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
Expand Down Expand Up @@ -192,9 +192,6 @@ replace (
// Pick up an IAVL race fix.
github.com/cosmos/iavl => github.com/cosmos/iavl v0.19.7

// Async version negotiation
github.com/cosmos/ibc-go/v6 => github.com/agoric-labs/ibc-go/v6 v6.2.1-alpha.agoric.3

// use cometbft
// Use our fork at least until post-v0.34.14 is released with
// https://github.com/tendermint/tendermint/issue/6899 resolved.
Expand Down
4 changes: 2 additions & 2 deletions golang/cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.4 h1:i5IgChQjTyWulV/y5
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.4/go.mod h1:d7e4h+w7FNBNmE6ysp6duBVuQg67pqMtvsLwpT9ca3E=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1 h1:2jvHI/2d+psWAZy6FQ0vXJCHUtfU3ZbbW+pQFL04arQ=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/agoric-labs/ibc-go/v6 v6.2.1-alpha.agoric.3 h1:YqvVwK+Lg/ZsuwyVm9UbPs8K55fg00R3Y9KnmaTBdgc=
github.com/agoric-labs/ibc-go/v6 v6.2.1-alpha.agoric.3/go.mod h1:V9NOCRS9RPkSJNJQIPRAjZn/lo2mCAAKOSv3/83ISDY=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -382,6 +380,8 @@ github.com/cosmos/iavl v0.19.7 h1:ij32FaEnwxfEurtK0QKDNhTWFnz6NUmrI5gky/WnoY0=
github.com/cosmos/iavl v0.19.7/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2 h1:Hz4nkpStoXIHrC77CIEyu2mRiN2qysGEZPFRf0fpv7w=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2/go.mod h1:Jo934o/sW7fNxuOa/TjCalSalz+1Fd649eLyANaJx8g=
github.com/cosmos/ibc-go/v6 v6.3.1 h1:/5ur3AsmNW8WuOevfODHlaY5Ze236PBNE3vVo9o3fQA=
github.com/cosmos/ibc-go/v6 v6.3.1/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
Expand Down
5 changes: 3 additions & 2 deletions golang/cosmos/x/vibc/types/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"

"github.com/cosmos/ibc-go/v6/modules/core/exported"

Expand All @@ -19,7 +18,9 @@ const (
// asynchronous versions. If it does, then the VM must supply an empty
// version string to indicate that the VM explicitly (possibly async)
// performs the Write* method.
AsyncVersions = ibckeeper.AsyncVersionNegotiation
// This flag is created in anticipation of ibc-go implementing async versions,
// see https://github.com/Agoric/agoric-sdk/issues/9358 for more details.
AsyncVersions = false
)

var (
Expand Down
1 change: 1 addition & 0 deletions packages/ERTP/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @jessie-check
/// <reference types="@agoric/internal/exported" />

export * from './amountMath.js';
export * from './issuerKit.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Ensure this is a module.
export {};

/// <reference types="ses"/>
/// <reference types="ses" />
/**
* @import {Passable, RemotableObject} from '@endo/pass-style')
* @import {CopyBag, CopySet, Key} from '@endo/patterns')
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 74.99
"atLeast": 75.02
}
}
2 changes: 0 additions & 2 deletions packages/SwingSet/src/vats/timer/types.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/agoric-cli/src/publish.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
/// <reference types="ses"/>
/// <reference types="ses" />

import { E } from '@endo/far';

Expand Down
2 changes: 1 addition & 1 deletion packages/assert/src/types-ambient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
/// <reference types="ses"/>
/// <reference types="ses" />

// Based on
// https://github.com/endojs/endo/blob/HEAD/packages/ses/src/error/types.js
Expand Down
2 changes: 1 addition & 1 deletion packages/base-zone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
"workerThreads": false
},
"typeCoverage": {
"atLeast": 89.87
"atLeast": 90.77
}
}
2 changes: 1 addition & 1 deletion packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@
"workerThreads": false
},
"typeCoverage": {
"atLeast": 86.47
"atLeast": 86.74
}
}
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"workerThreads": false
},
"typeCoverage": {
"atLeast": 74.28
"atLeast": 74.23
}
}
4 changes: 1 addition & 3 deletions packages/cache/src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @jessie-check

// XXX ambient types runtime imports until https://github.com/Agoric/agoric-sdk/issues/6512
import '@agoric/internal/exported.js';
/// <reference types="@agoric/internal/exported" />

// eslint-disable-next-line import/export
export * from './types.js';
Expand Down
1 change: 0 additions & 1 deletion packages/casting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"dependencies": {
"@agoric/internal": "^0.3.2",
"@agoric/notifier": "^0.6.2",
"@agoric/spawner": "^0.6.8",
"@agoric/store": "^0.9.2",
"@cosmjs/encoding": "^0.32.3",
"@cosmjs/proto-signing": "^0.32.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/casting/src/follower-cosmjs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="ses"/>
/// <reference types="ses" />

import { E, Far } from '@endo/far';
import * as tendermint34 from '@cosmjs/tendermint-rpc';
Expand Down
2 changes: 1 addition & 1 deletion packages/casting/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import '@agoric/internal/exported.js';
/// <reference types="@agoric/internal/exported" />

// eslint-disable-next-line import/export
export * from './types.js'; // no named exports
Expand Down
1 change: 0 additions & 1 deletion packages/deploy-script-support/src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check

/// <reference types="../../time/src/types.js" />
/// <reference path="../../zoe/exported.js" />

import { E } from '@endo/far';
Expand Down
3 changes: 1 addition & 2 deletions packages/governance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@agoric/assert": "^0.6.0",
"@agoric/ertp": "^0.16.2",
"@agoric/internal": "^0.3.2",
"@agoric/network": "^0.1.0",
"@agoric/notifier": "^0.6.2",
"@agoric/store": "^0.9.2",
"@agoric/time": "^0.3.2",
Expand Down Expand Up @@ -78,6 +77,6 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 89.31
"atLeast": 89.32
}
}
6 changes: 2 additions & 4 deletions packages/governance/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/// <reference types="@agoric/internal/exported" />
/// <reference types="@agoric/ertp/exported" />
// XXX ambient types runtime imports until https://github.com/Agoric/agoric-sdk/issues/6512
import '@agoric/internal/exported.js';
import '@agoric/ertp/exported.js';
import '@agoric/zoe/exported.js';

/// <reference path="./types-ambient.js" />

export {
ChoiceMethod,
ElectionType,
Expand Down
4 changes: 2 additions & 2 deletions packages/inter-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "yarn build:bundles",
"build:bundles": "node ./scripts/build-bundles.js",
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*' src/types.js",
"postpack": "git clean -f '*.d.ts*'",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
Expand Down Expand Up @@ -84,6 +84,6 @@
"access": "public"
},
"typeCoverage": {
"atLeast": 95.86
"atLeast": 95.87
}
}
5 changes: 3 additions & 2 deletions packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="@agoric/internal/exported" />
/// <reference types="@agoric/governance/exported" />

// XXX ambient types runtime imports until https://github.com/Agoric/agoric-sdk/issues/6512
import '@agoric/internal/exported.js';
import '@agoric/governance/exported.js';
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/auction/auctioneer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@agoric/governance/exported.js';
/// <reference types="@agoric/governance/exported" />
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';

Expand Down
6 changes: 4 additions & 2 deletions packages/inter-protocol/src/auction/scheduleMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { TimeMath } from '@agoric/time';
import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
import { assertAllDefined, makeTracer } from '@agoric/internal';

/** @import {TimestampRecord} from '@agoric/time'; */

const { subtract, multiply, floorDivide } = natSafeMath;
const { Fail } = assert;

Expand Down Expand Up @@ -35,7 +37,7 @@ const subtract1 = relTime =>
* their collateral).
*
* @param {Awaited<import('./params.js').AuctionParamManager>} params
* @param {Timestamp} baseTime
* @param {TimestampRecord} baseTime
* @returns {import('./scheduler.js').Schedule}
*/
export const computeRoundTiming = (params, baseTime) => {
Expand Down Expand Up @@ -83,7 +85,7 @@ export const computeRoundTiming = (params, baseTime) => {
// computed start is `startDelay + baseTime + freq - (baseTime mod freq)`.
// That is, if there are hourly starts, we add an hour to the time, and
// subtract baseTime mod freq. Then we add the delay.
/** @type {import('@agoric/time').TimestampRecord} */
/** @type {TimestampRecord} */
const startTime = TimeMath.addAbsRel(
TimeMath.addAbsRel(
baseTime,
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/econCommitteeCharter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check
/// <reference types="@agoric/governance/exported" />

import '@agoric/governance/exported.js';
import { M, mustMatch } from '@agoric/store';
import { TimestampShape } from '@agoric/time';
import { prepareExo, provideDurableMapStore } from '@agoric/vat-data';
Expand Down
1 change: 1 addition & 0 deletions packages/inter-protocol/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @jessie-check
/// <reference types="@agoric/vats/src/core/types-ambient" />

export { calculateCurrentDebt } from './interest-math.js';
3 changes: 0 additions & 3 deletions packages/inter-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// @jessie-check

// XXX ambient types runtime imports until https://github.com/Agoric/agoric-sdk/issues/6512
import '@agoric/vats/src/core/types-ambient.js';

import { AmountMath } from '@agoric/ertp';
import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/psm/psm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @jessie-check
/// <reference types="@agoric/governance/exported" />

// XXX ambient types runtime imports until https://github.com/Agoric/agoric-sdk/issues/6512
import '@agoric/governance/exported.js';
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';

Expand Down
Loading

0 comments on commit dfae2c8

Please sign in to comment.