Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace request and xhr with axios #230

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

mainnet-pat
Copy link
Contributor

@mainnet-pat mainnet-pat commented Aug 19, 2024

Resolves #95

@woodser
Copy link
Owner

woodser commented Aug 19, 2024

Thanks. Can you remove the file changes to ./dist please?

@mainnet-pat
Copy link
Contributor Author

mainnet-pat commented Aug 19, 2024

I thought the wasm must be recompiled for this to work.

Or you want to recompile yourself?

Dist .js files contain old logic too

@woodser
Copy link
Owner

woodser commented Aug 19, 2024

Yeah I always update the dist files at the end of the release on the master branch, since they contain large binaries and other generated artifacts which don't need to be in the repository, and which can cause merge conflicts on rebasing/testing with other commits. It also makes it easier to view the diffs.

@mainnet-pat
Copy link
Contributor Author

mainnet-pat commented Aug 20, 2024

Removed. Also tested the code in node and in firefox and brave. Because of the digest ping pong the console looks really ugly

image

@mainnet-pat
Copy link
Contributor Author

Fixed handling of binary requests and responses, thoroughly tested on both daemon and wallet-rpc being auth-protected.

import { createWalletFull, MoneroNetworkType, MoneroWalletListener } from "../..";
import { connectToWalletRpc } from "../..";

describe("Axios", function() {
Copy link
Owner

@woodser woodser Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but let's actually remove this test, since it's redundant with existing tests like the sample code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

@@ -57,3 +57,5 @@ new TestMoneroConnectionManager().runTests();

// test scratchpad
require("./Scratchpad");

require("./Axios");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

@woodser
Copy link
Owner

woodser commented Aug 20, 2024

I'm getting an error building the dist files myself, specifically the web worker:

[100%] Built target monero_wallet_full

> monero-ts@0.10.0 build_web_worker
> webpack --config ./webpack.worker.js

assets by status 1.78 MiB [cached] 97 assets
runtime modules 1010 bytes 5 modules
modules by path ./node_modules/ 2.01 MiB
  javascript modules 2 MiB 274 modules
  json modules 12.7 KiB
    modules by path ./node_modules/browserify-sign/ 2.23 KiB 2 modules
    + 4 modules
modules by path ./src/main/ts/ 835 KiB
  modules by path ./src/main/ts/wallet/ 438 KiB 33 modules
  modules by path ./src/main/ts/daemon/ 211 KiB 30 modules
  modules by path ./src/main/ts/common/*.ts 186 KiB 14 modules
modules by path ./dist/*.js 460 KiB
  ./dist/monero_wallet_keys.js 110 KiB [built] [code generated]
  ./dist/monero_wallet_full.js 350 KiB [built] [code generated]
+ 15 modules

ERROR in /Users/woodser/git/monero-ts/index.ts
./index.ts 1:0-12
[tsl] ERROR in /Users/woodser/git/monero-ts/index.ts(1,1)
      TS6200: Definitions of the following identifiers conflict with those in another file: GenUtils, Filter, MoneroError, HttpClient, LibraryUtils, MoneroRpcConnection, MoneroRpcError, SslOptions, TaskLooper, ConnectionType, MoneroAltChain, MoneroBan, MoneroBlockHeader, MoneroBlock, MoneroBlockTemplate, MoneroConnectionSpan, MoneroDaemonConfig, MoneroDaemonInfo, MoneroDaemonListener, MoneroDaemonSyncInfo, MoneroDaemonUpdateCheckResult, MoneroDaemonUpdateDownloadResult, MoneroFeeEstimate, MoneroHardForkInfo, MoneroKeyImage, MoneroKeyImageSpentStatus, MoneroMinerTxSum, MoneroMiningStatus, MoneroNetworkType, MoneroOutput, MoneroOutputHistogramEntry, MoneroSubmitTxResult, MoneroTx, MoneroTxPoolStats, MoneroVersion, MoneroPeer, MoneroPruneResult, MoneroAccount, MoneroAccountTag, MoneroAddressBookEntry, MoneroCheck, MoneroCheckReserve, MoneroCheckTx, MoneroDestination, MoneroIntegratedAddress, MoneroKeyImageImportResult, MoneroMultisigInfo, MoneroMultisigInitResult, MoneroMultisigSignResult, MoneroOutputWallet, MoneroOutputQuery, MoneroTxPriority, MoneroTxConfig, MoneroSubaddress, MoneroSyncResult, MoneroTransfer, MoneroIncomingTransfer, MoneroOutgoingTransfer, MoneroTransferQuery, MoneroTxSet, MoneroTxWallet, MoneroTxQuery, MoneroWalletListener, MoneroWalletConfig, MoneroMessageSignatureType, MoneroMessageSignatureResult, MoneroConnectionManagerListener, MoneroConnectionManager, MoneroDaemon, MoneroWallet, MoneroDaemonRpc, MoneroWalletRpc, MoneroWalletKeys, MoneroWalletFull, MoneroUtils, ThreadPool
ts-loader-default_e3b0c44298fc1c14
 @ ./dist/monero_wallet_full.js 9:10941-10960 9:12280-12299
 @ ./src/main/ts/common/LibraryUtils.ts 97:27-73
 @ ./src/main/ts/common/MoneroWebWorker.ts 9:39-64

Monero web worker config (webpack 5.88.2) compiled with 1 error in 7172 ms

This is after deleting ./build, ./browser_build, and ./node_modules, running npm install, then ./bin/build_all.sh for a full rebuild.

@mainnet-pat
Copy link
Contributor Author

mainnet-pat commented Aug 20, 2024

Yeah I had this error. I had to do:

rm -rf dist/
./bin/build_all.sh

Maybe it is the quirk of new emscription? It seemingly have nothing to do with my changes

@woodser
Copy link
Owner

woodser commented Aug 20, 2024

That did the trick :)

@woodser
Copy link
Owner

woodser commented Aug 20, 2024

Hm, it's strange though. I get this error every time running ./bin/build_dist.sh without first deleting the dist directory. But this behavior only happens with this PR applied. Otherwise it always works.

We're going to have to figure this out before I can incorporate this change, unfortunately.

@mainnet-pat
Copy link
Contributor Author

Can confirm this on master, after removing new redundant axios tests the issue went away. Please try again.

I have omitted pushing dist changes as you asked

@woodser
Copy link
Owner

woodser commented Aug 20, 2024

That works :)

@mainnet-pat
Copy link
Contributor Author

perfect

@woodser
Copy link
Owner

woodser commented Aug 21, 2024

The tests are all working, except one failure on "Can manage connections", which passes on master.

In case it's related, this part of the code is making requests to multiple monero-wallet-rpc servers simultaneously, in order to test getting the best connection.

The easiest way to run this test is in Node.js, with npm run test -- --grep "Can manage connections", after setting MONERO_BINS_DIR in TestUtils.ts to the directory of your monerod and monero-wallet-rpc binaries.

If you want to run the test in the browser, run ./bin/start_wallet_rpc_test_servers.sh in another terminal to pre-start monero-wallet-rpc processes for the test to use, then ./bin/build_dist.sh && ./bin/build_browser.sh, then run the test at this link: http://localhost:8080/tests.html?grep=Test%20connection%20manager%20Can%20manage%20connections

@mainnet-pat
Copy link
Contributor Author

mainnet-pat commented Aug 21, 2024

Fixed the failing test.

My observation: await connectionManager.checkConnections(); invokes await connection.checkConnection() which sends get_blocks_by_height.bin binary request to wallet rpc, not a daemon, so it is always 404.

But if it is indeed daemon it asks for first 100 blocks which might be a bit too heavy for a connection check. Maybe something like get_block_count or get_version would suffice?

@woodser
Copy link
Owner

woodser commented Aug 21, 2024

My observation: await connectionManager.checkConnections(); invokes await connection.checkConnection() which sends get_blocks_by_height.bin binary request to wallet rpc, not a daemon, so it is always 404.

Yeah it assumes a connection to monerod (almost always true), and falls back to treating a 404 as connected and uses the latency check.

But if it is indeed daemon it asks for first 100 blocks which might be a bit too heavy for a connection check. Maybe something like get_block_count or get_version would suffice?

The idea is to get a measurement which reflects if the node is under load, with the first 100 blocks being relatively light compared to later blocks for fully syncing the wallet.

Copy link
Owner

@woodser woodser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works. Just some final cleanup requested.


// normalize response
let normalizedResponse: any = {};

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line


normalizedResponse.statusCode = resp.status;
normalizedResponse.statusText = resp.statusText;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line

@@ -200,7 +119,7 @@ export default class HttpClient {
});
return HttpClient.HTTPS_AGENT;
}

protected static parseXhrResponseHeaders(headersStr) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can be removed completely now.

const randNum = Math.round(Math.random() * characters.length);
token += characters.slice(randNum, randNum+1);
}
return token;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra empty line

@mainnet-pat
Copy link
Contributor Author

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request and Request-Promise packages are deprecated [4 XMR]
2 participants