Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit b94bdcd

Browse files
authored
Merge pull request #200 from streamr-dev/NET-181-resend-gapfill
Fix resend gapfills, improve pipeline error handling
2 parents 0c308f2 + f3f986a commit b94bdcd

31 files changed

+1794
-927
lines changed

jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ module.exports = {
6060
// globals: {},
6161

6262
// An array of directory names to be searched recursively up from the requiring module's location
63-
// moduleDirectories: [
64-
// "node_modules"
65-
// ],
66-
63+
moduleDirectories: [
64+
'node_modules',
65+
path.resolve('./node_modules'), // makes npm link work.
66+
],
6767
// An array of file extensions your modules use
6868
// moduleFileExtensions: [
6969
// "js",

jest.setup.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const Debug = require('debug')
2-
const GitRevisionPlugin = require('git-revision-webpack-plugin')
1+
import GitRevisionPlugin from 'git-revision-webpack-plugin'
2+
import Debug from 'debug'
33

44
const pkg = require('./package.json')
55

6-
if (process.env.DEBUG_CONSOLE) {
7-
// Use debug as console log
8-
// This prevents jest messing with console output
9-
// Ensuring debug messages are printed alongside console messages, in the correct order
10-
console.log = Debug('Streamr::CONSOLE') // eslint-disable-line no-console
11-
}
6+
export default async () => {
7+
if (process.env.DEBUG_CONSOLE) {
8+
// Use debug as console log
9+
// This prevents jest messing with console output
10+
// Ensuring debug messages are printed alongside console messages, in the correct order
11+
console.log = Debug('Streamr::CONSOLE') // eslint-disable-line no-console
12+
}
1213

13-
module.exports = async () => {
1414
if (!process.env.GIT_VERSION) {
1515
const gitRevisionPlugin = new GitRevisionPlugin()
1616
const [GIT_VERSION, GIT_COMMITHASH, GIT_BRANCH] = await Promise.all([

package-lock.json

Lines changed: 704 additions & 734 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test-unit": "jest test/unit --detectOpenHandles",
3030
"coverage": "jest --coverage",
3131
"test-integration": "jest --forceExit test/integration",
32-
"test-integration-no-resend": "jest --testTimeout=10000 --testPathIgnorePatterns='resend|Resend' --testNamePattern='^((?!(resend|Resend|resent|Resent)).)*$' test/integration/*.test.js",
32+
"test-integration-no-resend": "jest --testTimeout=10000 --testPathIgnorePatterns='resend|Resend' --testNamePattern='^((?!(resend|Resend|resent|Resent|gap|Gap)).)*$' test/integration/*.test.js",
3333
"test-integration-resend": "jest --testTimeout=15000 --testNamePattern='(resend|Resend|resent|Resent)' test/integration/*.test.js",
3434
"test-integration-dataunions": "jest --testTimeout=15000 --runInBand test/integration/DataUnionEndpoints",
3535
"test-flakey": "jest --forceExit test/flakey/*",
@@ -49,7 +49,7 @@
4949
"@babel/plugin-proposal-class-properties": "^7.12.1",
5050
"@babel/plugin-transform-classes": "^7.12.1",
5151
"@babel/plugin-transform-modules-commonjs": "^7.12.1",
52-
"@babel/plugin-transform-runtime": "^7.12.10",
52+
"@babel/plugin-transform-runtime": "^7.12.15",
5353
"@babel/preset-env": "^7.12.11",
5454
"@babel/preset-typescript": "^7.12.13",
5555
"@types/debug": "^4.1.5",
@@ -87,7 +87,8 @@
8787
},
8888
"#IMPORTANT": "babel-runtime must be in dependencies, not devDependencies",
8989
"dependencies": {
90-
"@babel/runtime": "^7.12.5",
90+
"@babel/runtime": "^7.12.13",
91+
"@babel/runtime-corejs3": "^7.12.13",
9192
"@ethersproject/address": "^5.0.9",
9293
"@ethersproject/bignumber": "^5.0.13",
9394
"@ethersproject/bytes": "^5.0.9",
@@ -112,7 +113,7 @@
112113
"qs": "^6.9.6",
113114
"quick-lru": "^5.1.1",
114115
"readable-stream": "^3.6.0",
115-
"streamr-client-protocol": "^7.1.2",
116+
"streamr-client-protocol": "^8.0.0-beta.2",
116117
"typescript": "^4.1.4",
117118
"uuid": "^8.3.2",
118119
"webpack-node-externals": "^2.5.2",

src/Config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import qs from 'qs'
2-
// @ts-expect-error
32
import { ControlLayer, MessageLayer } from 'streamr-client-protocol'
43
import Debug from 'debug'
54

@@ -28,6 +27,7 @@ export default function ClientConfig(opts: StreamrClientOptions = {}) {
2827
orderMessages: true,
2928
retryResendAfter: 5000,
3029
gapFillTimeout: 5000,
30+
maxGapRequests: 5,
3131
maxPublishQueueSize: 10000,
3232

3333
// Encryption options

src/Connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
1111
// add global support for pretty millisecond formatting with %n
1212
Debug.formatters.n = (v) => Debug.humanize(v)
1313

14-
class ConnectionError extends Error {
14+
export class ConnectionError extends Error {
1515
constructor(err, ...args) {
1616
if (err instanceof ConnectionError) {
1717
return err

src/Session.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,23 @@ export default class Session extends EventEmitter {
4444
// TODO: move loginFunction to StreamrClient constructor where "auth type" is checked
4545
if (typeof this.options.privateKey !== 'undefined') {
4646
const wallet = new Wallet(this.options.privateKey)
47-
this.loginFunction = async () => this._client.loginEndpoints.loginWithChallengeResponse((d: string) => wallet.signMessage(d), wallet.address)
47+
this.loginFunction = async () => (
48+
this._client.loginEndpoints.loginWithChallengeResponse((d: string) => wallet.signMessage(d), wallet.address)
49+
)
4850
} else if (typeof this.options.ethereum !== 'undefined') {
4951
const provider = new Web3Provider(this.options.ethereum)
5052
const signer = provider.getSigner()
51-
this.loginFunction = async () => this._client.loginEndpoints.loginWithChallengeResponse((d: string) => signer.signMessage(d), await signer.getAddress())
53+
this.loginFunction = async () => (
54+
this._client.loginEndpoints.loginWithChallengeResponse((d: string) => signer.signMessage(d), await signer.getAddress())
55+
)
5256
} else if (typeof this.options.apiKey !== 'undefined') {
53-
this.loginFunction = async () => this._client.loginEndpoints.loginWithApiKey(this.options.apiKey!)
57+
this.loginFunction = async () => (
58+
this._client.loginEndpoints.loginWithApiKey(this.options.apiKey!)
59+
)
5460
} else if (typeof this.options.username !== 'undefined' && typeof this.options.password !== 'undefined') {
55-
this.loginFunction = async () => this._client.loginEndpoints.loginWithUsernamePassword(this.options.username!, this.options.password!)
61+
this.loginFunction = async () => (
62+
this._client.loginEndpoints.loginWithUsernamePassword(this.options.username!, this.options.password!)
63+
)
5664
} else {
5765
if (!this.options.sessionToken) {
5866
this.options.unauthenticated = true

src/StreamrClient.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import EventEmitter from 'eventemitter3'
2-
// @ts-expect-error
32
import { ControlLayer } from 'streamr-client-protocol'
43
import Debug from 'debug'
54

@@ -8,7 +7,7 @@ import { validateOptions } from './stream/utils'
87
import Config from './Config'
98
import StreamrEthereum from './Ethereum'
109
import Session from './Session'
11-
import Connection from './Connection'
10+
import Connection, { ConnectionError } from './Connection'
1211
import Publisher from './publish'
1312
import Subscriber from './subscribe'
1413
import { getUserId } from './user'
@@ -237,12 +236,12 @@ export default class StreamrClient extends EventEmitter {
237236
}
238237

239238
onConnectionError(err: Todo) {
240-
this.emit('error', new Connection.ConnectionError(err))
239+
this.emit('error', new ConnectionError(err))
241240
}
242241

243242
getErrorEmitter(source: Todo) {
244243
return (err: Todo) => {
245-
if (!(err instanceof Connection.ConnectionError || err.reason instanceof Connection.ConnectionError)) {
244+
if (!(err instanceof ConnectionError || err.reason instanceof ConnectionError)) {
246245
// emit non-connection errors
247246
this.emit('error', err)
248247
} else {

src/rest/DataUnionEndpoints.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ async function transportSignatures(client: StreamrClient, messageHash: Todo, opt
433433

434434
// template for withdraw functions
435435
// client could be replaced with AMB (mainnet and sidechain)
436-
async function untilWithdrawIsComplete(client: StreamrClient, getWithdrawTxFunc: (options: DataUnionOptions) => Todo, getBalanceFunc: (options: DataUnionOptions) => Todo, options: DataUnionOptions = {}) {
436+
async function untilWithdrawIsComplete(
437+
client: StreamrClient,
438+
getWithdrawTxFunc: (options: DataUnionOptions) => Todo,
439+
getBalanceFunc: (options: DataUnionOptions) => Todo,
440+
options: DataUnionOptions = {}
441+
) {
437442
const {
438443
pollingIntervalMs = 1000,
439444
retryTimeoutMs = 60000,

src/rest/StreamEndpoints.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,12 @@ export class StreamEndpoints {
217217
streamPartition,
218218
count,
219219
})
220-
const query = {
221-
count,
222-
}
223220

224-
const url = getEndpointUrl(this.client.options.restUrl, 'streams', streamId, 'data', 'partitions', streamPartition, 'last') + `?${qs.stringify(query)}`
221+
const url = (
222+
getEndpointUrl(this.client.options.restUrl, 'streams', streamId, 'data', 'partitions', streamPartition, 'last')
223+
+ `?${qs.stringify({ count })}`
224+
)
225+
225226
const json = await authFetch(url, this.client.session)
226227
return json
227228
}

0 commit comments

Comments
 (0)