Skip to content

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Nov 24, 2020
2 parents 32945d7 + eadf5d1 commit b626a70
Show file tree
Hide file tree
Showing 26 changed files with 1,124 additions and 394 deletions.
38 changes: 37 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
## [1.2.1](https://github.com/ExchangeUnion/xud/compare/v1.0.0...v1.2.1) (2020-11-19)

This maintenance release includes a number of features, most significantly it switches xud to use lnd's new `sendpaymentv2` call to prepare for multi-channel trades. It also improves xud's shutdown behavior and fixes several bugs.

### Bug Fixes

* added swap success log entry ([#1649](https://github.com/ExchangeUnion/xud/issues/1649)) ([e914ec0](https://github.com/ExchangeUnion/xud/commit/e914ec028f6420bbf2d973b92626f6284a9a8ba5))
* graceful shutdown ([#1994](https://github.com/ExchangeUnion/xud/issues/1994)) ([cde3203](https://github.com/ExchangeUnion/xud/commit/cde320312dcd08f70123b5949d038205748d6148))
* **cli:** typo in unlock.ts ([#1944](https://github.com/ExchangeUnion/xud/issues/1944)) ([7f61b32](https://github.com/ExchangeUnion/xud/commit/7f61b321c7e5c77585650ef7ff8415bdc29f6c15))
* **lnd:** don't calculate negative capacities ([b1020c1](https://github.com/ExchangeUnion/xud/commit/b1020c1a5cf2b386b9948efad9b5868232323945))
* addpair should prevent adding same base and quote assets ([#1559](https://github.com/ExchangeUnion/xud/issues/1559)) ([69f502f](https://github.com/ExchangeUnion/xud/commit/69f502f12b9fab12a558cc304eb5b58e19836561))
* tls certificate check on startup ([#1510](https://github.com/ExchangeUnion/xud/issues/1510)) ([9633678](https://github.com/ExchangeUnion/xud/commit/9633678de77fcd1728118998b896e60ec1261f90))
* use regtest instead of regnet arg ([7c6a226](https://github.com/ExchangeUnion/xud/commit/7c6a22640c414003ec3a88adc623d622065677df))
* **lnd:** handling hold invoice check errors ([#1969](https://github.com/ExchangeUnion/xud/issues/1969)) ([5746516](https://github.com/ExchangeUnion/xud/commit/57465168e24ed467427265af446c27a31427912a)), closes [#1968](https://github.com/ExchangeUnion/xud/issues/1968)
* alias missing in streamorders ([#1725](https://github.com/ExchangeUnion/xud/issues/1725)) ([#1962](https://github.com/ExchangeUnion/xud/issues/1962)) ([d537206](https://github.com/ExchangeUnion/xud/commit/d537206abec4835f96807853c66b23acaeb62e88))
* **cli:** openchannel assertion error for string amount ([#1950](https://github.com/ExchangeUnion/xud/issues/1950)) ([a0cc6d7](https://github.com/ExchangeUnion/xud/commit/a0cc6d74dc73176cb43ba496a73f32be31adb8cd)), closes [#1643](https://github.com/ExchangeUnion/xud/issues/1643)
* **connext:** not enough balance for closechannel ([#1963](https://github.com/ExchangeUnion/xud/issues/1963)) ([6599d88](https://github.com/ExchangeUnion/xud/commit/6599d885cfce3361715b99037013aca89220a658))
* **p2p:** don't reconnect peers when pool closed ([#1965](https://github.com/ExchangeUnion/xud/issues/1965)) ([8483e1e](https://github.com/ExchangeUnion/xud/commit/8483e1e35d7fdc80404cac59768ddc61a773b465)), closes [#1668](https://github.com/ExchangeUnion/xud/issues/1668) [/github.com/ExchangeUnion/xud/issues/1668#issuecomment-684828808](https://github.com//github.com/ExchangeUnion/xud/issues/1668/issues/issuecomment-684828808)
* **rpc:** no success if no channels to close ([#1689](https://github.com/ExchangeUnion/xud/issues/1689)) ([#1942](https://github.com/ExchangeUnion/xud/issues/1942)) ([17e40de](https://github.com/ExchangeUnion/xud/commit/17e40deda3ced6de23030094b6ada5f11dd383df))
* getinfo output for lnd channels ([#1940](https://github.com/ExchangeUnion/xud/issues/1940)) ([#1948](https://github.com/ExchangeUnion/xud/issues/1948)) ([962daa4](https://github.com/ExchangeUnion/xud/commit/962daa46081bc3122a04afa82bbe88eb53ec0026))
* manual ban causes an undefined log entry ([#1779](https://github.com/ExchangeUnion/xud/issues/1779)) ([e7f8178](https://github.com/ExchangeUnion/xud/commit/e7f817841fccee30415f754816644f161fe6cc2c))
* rename tradinglimits reserved_inbound json_name ([7e56011](https://github.com/ExchangeUnion/xud/commit/7e560111dbb10079a6e9c488d46fb0ecc8bb1cb6))


### Features

* **lnd:** SendPaymentV2 ([51c60dc](https://github.com/ExchangeUnion/xud/commit/51c60dcdc09df38a641dcc6142bee2539b8c85f6)), closes [#1590](https://github.com/ExchangeUnion/xud/issues/1590)
* **rpc:** runtime addcurrency for lnd & connext ([#1746](https://github.com/ExchangeUnion/xud/issues/1746)) ([fc83823](https://github.com/ExchangeUnion/xud/commit/fc8382313854b259ca97256004c8ddbb35dcffca))
* **swapclient:** auto init wallets on xud unlock ([#1973](https://github.com/ExchangeUnion/xud/issues/1973)) ([a1287dd](https://github.com/ExchangeUnion/xud/commit/a1287dda7740a92e92d8799bf4f2a8a0279d21a8)), closes [#1929](https://github.com/ExchangeUnion/xud/issues/1929)
* reserved capacity checks on PlaceOrder ([#1949](https://github.com/ExchangeUnion/xud/issues/1949)) ([d458745](https://github.com/ExchangeUnion/xud/commit/d4587458ab15a43bb6f4cfea18ee13cbd2653075)), closes [#1947](https://github.com/ExchangeUnion/xud/issues/1947)
* **lnd:** change gRPC client options ([aefdce8](https://github.com/ExchangeUnion/xud/commit/aefdce84e2c6cae35bf243f21a5224427fe2bfcc))
* removeorder output changed to a more meaningful message ([#1526](https://github.com/ExchangeUnion/xud/issues/1526)) ([ba04193](https://github.com/ExchangeUnion/xud/commit/ba041938cdcddb3aedec0db8fe4f571e2608b9d1))
* **rpc:** SetLogLevel ([#1955](https://github.com/ExchangeUnion/xud/issues/1955)) ([8d10df0](https://github.com/ExchangeUnion/xud/commit/8d10df00f7442ea58286726f0348d0f43eae7622)), closes [#835](https://github.com/ExchangeUnion/xud/issues/835)
* added new grpc method to easily cancel all orders ([#1910](https://github.com/ExchangeUnion/xud/issues/1910)) ([c958e86](https://github.com/ExchangeUnion/xud/commit/c958e862542fb52fdeb6532cbe2d92dd4b52cedf))



# [1.2.0](https://github.com/ExchangeUnion/xud/compare/v1.0.0...v1.2.0) (2020-10-16)

This release includes a number of fixes and features, most significantly related to Connext integration.
Expand Down Expand Up @@ -866,4 +903,3 @@ command line arguments.
* **p2p/orderbook:** update supported pairs ([1014cbd](https://github.com/ExchangeUnion/xud/commit/1014cbd))
* **rpc:** add GetNodeInfo call ([#570](https://github.com/ExchangeUnion/xud/issues/570)) ([1a038a2](https://github.com/ExchangeUnion/xud/commit/1a038a2)), closes [#529](https://github.com/ExchangeUnion/xud/issues/529)
* **swaps:** store swapdeals in database ([#569](https://github.com/ExchangeUnion/xud/pull/569)) ([9a7a629a](https://github.com/ExchangeUnion/xud/commit/9a7a629a9b2c9b8d28d035dc32543aed5e30be47)), closes [#562](https://github.com/ExchangeUnion/xud/issues/562)

28 changes: 28 additions & 0 deletions docs/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/Xud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Xud extends EventEmitter {

this.service = new Service({
version,
nodeKey,
orderBook: this.orderBook,
swapClientManager: this.swapClientManager,
pool: this.pool,
Expand Down
39 changes: 10 additions & 29 deletions lib/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import readline from 'readline';
import { Arguments } from 'yargs';
import { CreateNodeRequest, CreateNodeResponse } from '../../proto/xudrpc_pb';
import { callback, loadXudInitClient } from '../command';
import { getDefaultCertPath, waitForCert } from '../utils';
import { getDefaultCertPath, waitForCert, showSeed } from '../utils';

export const command = 'create';

Expand All @@ -11,37 +11,18 @@ export const describe = 'create a new xud instance and set a password';
export const builder = {};

const formatOutput = (response: CreateNodeResponse.AsObject) => {
if (response.seedMnemonicList.length === 24) {
const WORDS_PER_ROW = 4;
const numberedMnemonic = response.seedMnemonicList.map((value, index) => {
return `${index >= 9 ? '' : ' '}${index + 1}. ${value.padEnd(10)}`;
});
console.log('----------------------BEGIN XUD SEED---------------------');
for (let n = 0; n < response.seedMnemonicList.length / WORDS_PER_ROW; n += 1) {
console.log(numberedMnemonic.slice(n * WORDS_PER_ROW, (n + 1) * WORDS_PER_ROW).join(' '));
}
console.log('-----------------------END XUD SEED----------------------\n');

let walletInitializedMessage = 'The following wallets were initialized: ';

if (response.initializedLndsList.length) {
walletInitializedMessage += response.initializedLndsList.join(', ') + (response.initializedConnext ? ', ETH' : '');
} else if (response.initializedConnext) {
walletInitializedMessage += 'ETH';
}
const { seedMnemonicList } = response;
showSeed(seedMnemonicList);

console.log(walletInitializedMessage);
let walletInitializedMessage = 'The following wallets were initialized: ';

console.log(`
Please write down your 24 word mnemonic. It will allow you to recover your xud \
node key and on-chain funds for the initialized wallets listed above should you \
forget your password or lose your device. Off-chain funds in channels can NOT \
be recovered with it and must be backed up and recovered separately. Keep it \
somewhere safe, it is your ONLY backup in case of data loss.
`);
} else {
console.log('xud was initialized without a seed because no wallets could be initialized.');
if (response.initializedLndsList.length) {
walletInitializedMessage += response.initializedLndsList.join(', ') + (response.initializedConnext ? ', ETH' : '');
} else if (response.initializedConnext) {
walletInitializedMessage += 'ETH';
}

console.log(walletInitializedMessage);
};

export const handler = (argv: Arguments<any>) => {
Expand Down
27 changes: 27 additions & 0 deletions lib/cli/commands/getmnemonic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Arguments } from 'yargs';
import { GetMnemonicRequest, GetMnemonicResponse } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';
import { showSeed } from '../utils';

const formatOutput = (response: GetMnemonicResponse.AsObject) => {
const { seedMnemonicList } = response;

showSeed(seedMnemonicList);

// The mnemonic won't be the same as was returned for the `xucli create` call.
// xud uses aezeed which is salted with random bytes, xud does not store the
// salt or the mnemonic words. Each time xud regenerates the mnemonic, it
// uses a new salt so that the mnemonic is different.
console.log(`
Note that this mnemonic changes each time it is regenerated by xud, but it \
still restores the same xud node key and underlying wallets.
`);
};

export const command = 'getmnemonic';

export const describe = 'show the master xud seed mnemonic';

export const handler = async (argv: Arguments) => {
(await loadXudClient(argv)).getMnemonic(new GetMnemonicRequest(), callback(argv, formatOutput));
};
20 changes: 20 additions & 0 deletions lib/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ export const waitForCert = (certPath: string) => {
});
};

export function showSeed(seedMnemonicList: string[]) {
const WORDS_PER_ROW = 4;
const numberedMnemonic = seedMnemonicList.map((value, index) => {
return `${index >= 9 ? '' : ' '}${index + 1}. ${value.padEnd(10)}`;
});
console.log('----------------------BEGIN XUD SEED---------------------');
for (let n = 0; n < seedMnemonicList.length / WORDS_PER_ROW; n += 1) {
console.log(numberedMnemonic.slice(n * WORDS_PER_ROW, (n + 1) * WORDS_PER_ROW).join(' '));
}
console.log('-----------------------END XUD SEED----------------------\n');

console.log(`
Please write down your 24 word mnemonic. It will allow you to recover your xud \
node key and on-chain funds for the initialized wallets listed above should you \
forget your password or lose your device. Off-chain funds in channels can NOT \
be recovered with it and must be backed up and recovered separately. Keep it \
somewhere safe, it is your ONLY backup in case of data loss.
`);
}

export const waitForClient = (client: XudClient, argv: Arguments, ensureConnection: Function, successCallback: Function, printError?: boolean) => {
client.waitForReady(Date.now() + 3000, (error: Error | null) => {
if (error) {
Expand Down
22 changes: 21 additions & 1 deletion lib/connextclient/ConnextClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ class ConnextClient extends SwapClient {
private outboundAmounts = new Map<string, number>();
private inboundAmounts = new Map<string, number>();

private pendingRequests = new Set<http.ClientRequest>();
private criticalRequestPaths = ['/hashlock-resolve', '/hashlock-transfer'];

/** The minimum incremental quantity that we may use for collateral requests. */
private static MIN_COLLATERAL_REQUEST_SIZES: { [key: string]: number | undefined } = {
ETH: 0.1 * 10 ** 8,
Expand Down Expand Up @@ -888,6 +891,16 @@ class ConnextClient extends SwapClient {
/** Connext client specific cleanup. */
protected disconnect = async () => {
this.setStatus(ClientStatus.Disconnected);

for (const req of this.pendingRequests) {
if (this.criticalRequestPaths.includes(req.path)) {
this.logger.warn(`critical request is pending: ${req.path}`);
continue;
}

this.logger.info(`aborting pending request: ${req.path}`);
req.destroy();
}
}

/**
Expand Down Expand Up @@ -915,7 +928,11 @@ class ConnextClient extends SwapClient {
}

this.logger.trace(`sending request to ${endpoint}${payloadStr ? `: ${payloadStr}` : ''}`);
const req = http.request(options, async (res) => {

let req: http.ClientRequest;
req = http.request(options, async (res) => {
this.pendingRequests.delete(req);

let err: XudError | undefined;
let body;
switch (res.statusCode) {
Expand Down Expand Up @@ -957,6 +974,7 @@ class ConnextClient extends SwapClient {
});

req.on('error', async (err: any) => {
this.pendingRequests.delete(req);
if (err.code === 'ECONNREFUSED') {
await this.disconnect();
}
Expand All @@ -967,7 +985,9 @@ class ConnextClient extends SwapClient {
if (payloadStr) {
req.write(payloadStr);
}

req.end();
this.pendingRequests.add(req);
});
}
}
Expand Down
17 changes: 17 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,23 @@ class GrpcService {
}
}

/**
* See [[Service.getMnemonic]]
*/
public getMnemonic: grpc.handleUnaryCall<xudrpc.GetMnemonicRequest, xudrpc.GetMnemonicResponse> = async (_, callback) => {
if (!this.isReady(this.service, callback)) {
return;
}
try {
const mnemonic = await this.service.getMnemonic();
const response = new xudrpc.GetMnemonicResponse();
response.setSeedMnemonicList(mnemonic);
callback(null, response);
} catch (err) {
callback(getGrpcError(err), null);
}
}

/**
* See [[Service.getNodeInfo]]
*/
Expand Down
8 changes: 8 additions & 0 deletions lib/nodekey/NodeKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { promises as fs } from 'fs';
import { createCipheriv, createDecipheriv, createHash } from 'crypto';
import { entropyToMnemonic } from 'bip39';
import { SwapClientType } from '../constants/enums';
import { encipher } from '../utils/seedutil';

/**
* A class representing an ECDSA public/private key pair that identifies an XU node on the network
Expand Down Expand Up @@ -128,6 +129,13 @@ class NodeKey {
return entropyToMnemonic(childSeedEntropy);
}

public getMnemonic = async () => {
const decipheredSeed = this.privKey.slice(0, 19);
const decipheredSeedHex = decipheredSeed.toString('hex');
const seedMnemonic = await encipher(decipheredSeedHex);

return seedMnemonic;
}
}

export default NodeKey;
Loading

0 comments on commit b626a70

Please sign in to comment.