Skip to content

Commit

Permalink
chain-cosmos-sdk.js: shuffle rpcaddresses
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 20, 2019
1 parent 052ed08 commit 71be0a4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/ag-solo/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { execFile } from 'child_process';
import djson from 'deterministic-json';
import { createHash } from 'crypto';
import connect from 'lotion-connect';
import { Readable } from 'stream';

const HELPER = 'ag-cosmos-helper';

Expand Down Expand Up @@ -35,6 +34,18 @@ export async function connectToChain(
// would live in the build tree along with bin/ag-solo . But for now we
// assume that 'ag-cosmos-helper' is on $PATH somewhere.

// Shuffle our rpcAddresses, to help distribute load.
// Modern version of Fisher-Yates shuffle algorithm (in-place).
function shuffle(a) {
for (let i = a.length - 1; i > 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
const x = a[i];
a[i] = a[j];
a[j] = x;
}
}
shuffle(rpcAddresses);

// TODO: --chain-id matches something in the genesis block, should we
// include it in the arguments to `css-solo set-gci-ingress`? It's included
// in the GCI, but if we also need it to establish an RPC connection, then
Expand Down

0 comments on commit 71be0a4

Please sign in to comment.