Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #429 from web3well/bug/submit-error
Browse files Browse the repository at this point in the history
Correctly bubble up bundle submit errors
  • Loading branch information
jacque006 authored Dec 15, 2022
2 parents da03830 + ce5d8b3 commit 46dfe7b
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 62 deletions.
2 changes: 1 addition & 1 deletion aggregator-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/koa__cors": "^3.3.0",
"@types/koa__router": "^8.0.11",
"@types/node-fetch": "^2.6.1",
"bls-wallet-clients": "0.8.0-56f33ec",
"bls-wallet-clients": "0.8.1-758c7c4",
"fp-ts": "^2.12.1",
"io-ts": "^2.2.16",
"io-ts-reporters": "^2.0.1",
Expand Down
14 changes: 6 additions & 8 deletions aggregator-proxy/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,6 @@
version "5.5.0"
resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.5.0.tgz#530f4f608f9ca9d4f89c24ab95db58ab56ab99a0"
integrity sha512-hLv8XaQ8PTI9g2RHoQGf/WSxBfTB/NudRacbzdxmst5VHAqd1sMibWG7SENzT5Dj3yZ3kJYx+WiRYEcQTAkcYA==
dependencies:
"@ethersproject/bytes" "^5.5.0"
"@ethersproject/logger" "^5.5.0"

"@ethersproject/[email protected]", "@ethersproject/rlp@^5.5.0", "@ethersproject/rlp@^5.6.0":
version "5.6.0"
Expand Down Expand Up @@ -885,13 +882,14 @@ [email protected]:
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==

[email protected].0-56f33ec:
version "0.8.0-56f33ec"
resolved "https://registry.yarnpkg.com/bls-wallet-clients/-/bls-wallet-clients-0.8.0-56f33ec.tgz#a0ed67df429c6c1d39ddd272accfb7087c5e6613"
integrity sha512-uHKV4ep+K2MqArNsarM1nRCQwls5DymUSyZcLh5WWJAQM1Ht9hwBv5Hjti/TXqP3MEw3HsZZPvBwZKvFx33hEA==
[email protected].1-758c7c4:
version "0.8.1-758c7c4"
resolved "https://registry.yarnpkg.com/bls-wallet-clients/-/bls-wallet-clients-0.8.1-758c7c4.tgz#1366b8c704912bdacc933c44061a3198dec80ec5"
integrity sha512-bvI0BJVKZow1y/0BDmhFSlr3ScQQDofUX+6J+BB9pLMu2WIQogmfpLqHsH5oOOq+RQbR/ivNoknR+YU4Un0HRQ==
dependencies:
"@thehubbleproject/bls" "^0.5.1"
ethers "5.5.4"
node-fetch "2.6.7"

bn.js@^4.11.9:
version "4.12.0"
Expand Down Expand Up @@ -1352,7 +1350,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd"
integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==

node-fetch@2:
node-fetch@2, [email protected]:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down
6 changes: 3 additions & 3 deletions aggregator/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type {
Signature,
VerificationGateway,
OperationResultError,
} from "https://esm.sh/[email protected].0-efa2e06";
} from "https://esm.sh/[email protected].1-758c7c4";

export {
Aggregator as AggregatorClient,
Expand All @@ -61,10 +61,10 @@ export {
MockERC20__factory,
VerificationGateway__factory,
decodeError,
} from "https://esm.sh/[email protected].0-efa2e06";
} from "https://esm.sh/[email protected].1-758c7c4";

// Workaround for esbuild's export-star bug
import blsWalletClients from "https://esm.sh/[email protected].0-efa2e06";
import blsWalletClients from "https://esm.sh/[email protected].1-758c7c4";
const {
bundleFromDto,
bundleToDto,
Expand Down
20 changes: 17 additions & 3 deletions contracts/clients/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,23 @@ Exposes typed functions for interacting with the Aggregator's HTTP API.
```ts
import { Aggregator } from 'bls-wallet-clients';

const aggregator = new Aggregator('https://rinkarby.blswallet.org');

await aggregator.add(...);
const aggregator = new Aggregator('https://arbitrum-goerli.blswallet.org');
const resp = await aggregator.add(bundle); // See BlsWalletWrapper section below
// Aggregator did not accept bundle
if ("failures" in resp) {
throw new Error(resp.failures.join(", "));
}

let receipt;
while (!receipt) {
receipt = await aggregator.lookupReceipt(resp.hash);
// There was an issue submitting the bundle on chain
if (receipt && "submitError" in receipt) {
throw new Error(receipt.submitError);
}
// Some function which waits i.e. setTimeout
await sleep(5000);
}
```

## BlsWalletWrapper
Expand Down
14 changes: 7 additions & 7 deletions contracts/clients/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bls-wallet-clients",
"version": "0.8.0",
"version": "0.8.1",
"description": "Client libraries for interacting with BLS Wallet components",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand All @@ -23,17 +23,17 @@
"dependencies": {
"@thehubbleproject/bls": "^0.5.1",
"ethers": "5.5.4",
"node-fetch": "2"
"node-fetch": "2.6.7"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.0",
"chai": "^4.3.6",
"@types/mocha": "^10.0.1",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"mocha": "^10.1.0",
"mocha": "^10.2.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^4.9.4"
}
}
64 changes: 55 additions & 9 deletions contracts/clients/src/Aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export type EstimateFeeResponse = {
successes: boolean[];
};

export type BundleReceiptError = {
submitError: string | undefined;
};

export type BundleReceipt = {
transactionIndex: number;
transactionHash: string;
Expand All @@ -42,9 +46,19 @@ export type BundleReceipt = {
blockNumber: number;
};

/**
* Client used to interact with a BLS Wallet Aggregator instance
*/
export default class Aggregator {
// Fetch implementation to use
private readonly fetchImpl;
origin: string;

/**
* Constructs an Aggregator object
*
* @param url URL of the aggregator instance
*/
constructor(url: string) {
const parsedUrl = new URL(url);

Expand All @@ -53,8 +67,16 @@ export default class Aggregator {
}

this.origin = new URL(url).origin;
// Prefer runtime's imeplmentation of fetch over node-fetch
this.fetchImpl = globalThis.fetch ?? fetch;
}

/**
* Sends a bundle to the aggregator
*
* @param bundle Bundle to send
* @returns The hash of the bundle or an array of failures if the aggregator did not accept the bundle
*/
async add(
bundle: Bundle,
): Promise<{ hash: string } | { failures: TransactionFailure[] }> {
Expand All @@ -71,24 +93,36 @@ export default class Aggregator {
return json;
}

/**
* Estimates the fee required for a bundle by the aggreagtor to submit it.
*
* @param bundle Bundle to estimates the fee for
* @returns Estimate of the fee needed to submit the bundle
*/
async estimateFee(bundle: Bundle): Promise<EstimateFeeResponse> {
const result = await this.jsonPost("/estimateFee", bundleToDto(bundle));

return result as EstimateFeeResponse;
}

async lookupReceipt(hash: string): Promise<BundleReceipt | undefined> {
const response = await fetch(`${this.origin}/bundleReceipt/${hash}`);

if (response.status === 404) {
return undefined;
}

return await response.json();
/**
* Looks for a transaction receipt for a Bundle sent to the aggregator.
* This will return undefined if the bundle has not yet been submitted by the aggregator.
*
* @param hash Hash of the bundle to find a transaction receipt for.
* @returns The bundle receipt, a submission error if the aggregator was unable to submit the bundle on chain, or undefined if the receipt was not found.
*/
async lookupReceipt(
hash: string,
): Promise<BundleReceipt | BundleReceiptError | undefined> {
return this.jsonGet<BundleReceipt | BundleReceiptError>(
`${this.origin}/bundleReceipt/${hash}`,
);
}

// Note: This should be private instead of exposed. Leaving as is for compatibility.
async jsonPost(path: string, body: unknown): Promise<unknown> {
const resp = await fetch(`${this.origin}${path}`, {
const resp = await this.fetchImpl(`${this.origin}${path}`, {
method: "POST",
body: JSON.stringify(body),
headers: {
Expand All @@ -108,4 +142,16 @@ export default class Aggregator {

return json;
}

private async jsonGet<T>(path: string): Promise<T | undefined> {
const resp = await this.fetchImpl(path);
const json = await resp.json();

const isValidNonEmptyJson = json && Object.keys(json).length;
if (isValidNonEmptyJson) {
return json as T;
}

return undefined;
}
}
78 changes: 55 additions & 23 deletions contracts/clients/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,26 @@
version "5.5.3"
resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.5.3.tgz#56c2b070542ac44eb5de2ed3cf6784acd60a3130"
integrity sha512-ZHXxXXXWHuwCQKrgdpIkbzMNJMvs+9YWemanwp1fA7XZEv7QlilseysPvQe0D7Q7DlkJX/w/bGA1MdgK2TbGvA==
dependencies:
"@ethersproject/abstract-provider" "^5.5.0"
"@ethersproject/abstract-signer" "^5.5.0"
"@ethersproject/address" "^5.5.0"
"@ethersproject/basex" "^5.5.0"
"@ethersproject/bignumber" "^5.5.0"
"@ethersproject/bytes" "^5.5.0"
"@ethersproject/constants" "^5.5.0"
"@ethersproject/hash" "^5.5.0"
"@ethersproject/logger" "^5.5.0"
"@ethersproject/networks" "^5.5.0"
"@ethersproject/properties" "^5.5.0"
"@ethersproject/random" "^5.5.0"
"@ethersproject/rlp" "^5.5.0"
"@ethersproject/sha2" "^5.5.0"
"@ethersproject/strings" "^5.5.0"
"@ethersproject/transactions" "^5.5.0"
"@ethersproject/web" "^5.5.0"
bech32 "1.1.4"
ws "7.4.6"

"@ethersproject/[email protected]":
version "5.6.0"
Expand Down Expand Up @@ -488,6 +508,13 @@
version "5.5.0"
resolved "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.5.0.tgz"
integrity sha512-5VmseH7qjtNmDdZBswavhotYbWB0bOwKIlOTSlX14rKn5c11QmJwGt4GHeo7NrL/Ycl7uo9AHvEqs5xZgFBTng==
dependencies:
"@ethersproject/bytes" "^5.5.0"
"@ethersproject/logger" "^5.5.0"
"@ethersproject/properties" "^5.5.0"
bn.js "^4.11.9"
elliptic "6.5.4"
hash.js "1.1.7"

"@ethersproject/[email protected]", "@ethersproject/signing-key@^5.6.0":
version "5.6.0"
Expand Down Expand Up @@ -741,15 +768,20 @@
dependencies:
"@types/chai" "*"

"@types/chai@*", "@types/chai@^4.3.3":
"@types/chai@*":
version "4.3.3"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.3.tgz#3c90752792660c4b562ad73b3fbd68bf3bc7ae07"
integrity sha512-hC7OMnszpxhZPduX+m+nrx+uFoLkWOMiR4oa/AZF3MuSETYTZmFfJAHqZEM8MVlvfG7BEUcgvtwoCTxBp6hm3g==

"@types/mocha@^10.0.0":
version "10.0.0"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.0.tgz#3d9018c575f0e3f7386c1de80ee66cc21fbb7a52"
integrity sha512-rADY+HtTOA52l9VZWtgQfn4p+UDVM2eDVkMZT1I6syp0YKxW2F9v+0pbRZLsvskhQv/vMb6ZfCay81GHbz5SHg==
"@types/chai@^4.3.4":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==

"@types/mocha@^10.0.1":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.1.tgz#2f4f65bb08bc368ac39c96da7b2f09140b26851b"
integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==

acorn-walk@^8.1.1:
version "8.2.0"
Expand Down Expand Up @@ -875,14 +907,14 @@ chai-as-promised@^7.1.1:
dependencies:
check-error "^1.0.2"

chai@^4.3.6:
version "4.3.6"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c"
integrity sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==
chai@^4.3.7:
version "4.3.7"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51"
integrity sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==
dependencies:
assertion-error "^1.1.0"
check-error "^1.0.2"
deep-eql "^3.0.1"
deep-eql "^4.1.2"
get-func-name "^2.0.0"
loupe "^2.3.1"
pathval "^1.1.1"
Expand Down Expand Up @@ -959,10 +991,10 @@ decamelize@^4.0.0:
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837"
integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==

deep-eql@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==
deep-eql@^4.1.2:
version "4.1.3"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d"
integrity sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==
dependencies:
type-detect "^4.0.0"

Expand Down Expand Up @@ -1282,10 +1314,10 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

mocha@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.1.0.tgz#dbf1114b7c3f9d0ca5de3133906aea3dfc89ef7a"
integrity sha512-vUF7IYxEoN7XhQpFLxQAEMtE4W91acW4B6En9l97MwE9stL1A9gusXfoHZCLVHDUJ/7V5+lbCM6yMqzo5vNymg==
mocha@^10.2.0:
version "10.2.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8"
integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==
dependencies:
ansi-colors "4.1.1"
browser-stdout "1.3.1"
Expand Down Expand Up @@ -1324,7 +1356,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25"
integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==

node-fetch@2:
node-fetch@2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down Expand Up @@ -1497,10 +1529,10 @@ type-detect@^4.0.0, type-detect@^4.0.5:
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==

typescript@^4.8.4:
version "4.8.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
typescript@^4.9.4:
version "4.9.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"advanced-css-reset": "^1.2.2",
"async-mutex": "^0.3.2",
"axios": "^0.27.2",
"bls-wallet-clients": "0.8.0-efa2e06",
"bls-wallet-clients": "0.8.1-758c7c4",
"browser-passworder": "^2.0.3",
"bs58check": "^2.1.2",
"crypto-browserify": "^3.12.0",
Expand Down
3 changes: 3 additions & 0 deletions extension/source/background/AggregatorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ export default class AggregatorController {
const aggregator = new Aggregator(knownTx.aggregatorUrl);

const bundleReceipt = await aggregator.lookupReceipt(hash);
if (bundleReceipt && 'submitError' in bundleReceipt) {
throw new Error(bundleReceipt.submitError);
}

if (bundleReceipt) {
this.InternalRpc().updateTransactionHashByBundleHash(
Expand Down
Loading

0 comments on commit 46dfe7b

Please sign in to comment.