on master help sign in
Add tool for finding real-world gas usage
8c72e65Fang
find-gas-usage.jsnew file+121
@@ -0,0 +1,121 @@
1+// usage: tweak constants at head of file, then run "node find-gas-usage.js"
2+// for very common events/calls, you may need to use a smaller TO-FROM
3+// range to keep web3 from yelling at you
4+
5+const ORIGIN = 6784800; // launch ceremony begins
6+const PUBLIC = 7033765; // azimuth becomes public
7+const LATEST = 'latest';
8+
9+const FROM = ORIGIN;
10+const TO = LATEST;
11+
12+const VENT = 'ChangedKeys';
13+const FUNC = '0x4447e48c'; // configureKeys
14+const ARGS = 5;
15+
16+// const VENT = 'Spawned';
17+// const FUNC = '0xa0d3253f'; // spawn
18+// const ARGS = 2;
19+
20+// const VENT = 'OwnerChanged';
21+// const FUNC = '0x1e79a85b'; // transferPoint
22+// const ARGS = 3;
23+
24+// const VENT = 'ChangedSpawnProxy';
25+// const FUNC = '0xae326221'; // setSpawnProxy
26+// const ARGS = 2;
27+
28+// const VENT = 'ChangedManagementProxy';
29+// const FUNC = '0x8866bb2c'; // setManagementProxy
30+// const ARGS = 2;
31+
32+// const VENT = 'ChangedTransferProxy';
33+// const FUNC = '0x2c7ba564'; // setTransferProxy
34+// const ARGS = 2;
35+
36+// const VENT = 'ChangedVotingProxy';
37+// const FUNC = '0xa60e8bd6'; // setVotingProxy
38+// const ARGS = 2;
39+
40+// const VENT = 'EscapeRequested';
41+// const FUNC = '0xbf5772b9'; // escape
42+// const ARGS = 2;
43+
44+// const VENT = 'EscapeCanceled';
45+// const FUNC = '0xc6d761d4'; // cancelEscape
46+// const ARGS = 1;
47+
48+// const VENT = 'EscapeAccepted';
49+// const FUNC = '0xc1b9d98b'; // adopt
50+// const ARGS = 1;
51+
52+// const VENT = 'EscapeCanceled';
53+// const FUNC = '0xbbe21ca5'; // reject
54+// const ARGS = 1;
55+
56+// const VENT = 'LostSponsor';
57+// const FUNC = '0x073a7804'; // detach
58+// const ARGS = 1;
59+
60+const LENT = 64 * ARGS + FUNC.length;
61+
62+const Web3 = require('web3');
63+const azimuth = require('azimuth-js');
64+
65+(async () => {
66+ const web3 = new Web3(
67+ new Web3.providers.HttpProvider(
68+ 'https://mainnet.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87'
69+ )
70+ );
71+ const contracts = await azimuth.initContractsPartial(
72+ web3,
73+ '0x223c067f8cf28ae173ee5cafea60ca44c335fecb'
74+ );
75+
76+ const keyEvents = await contracts.azimuth.getPastEvents(VENT, {
77+ fromBlock: FROM,
78+ toBlock: TO,
79+ });
80+
81+ const txsBatch = new web3.BatchRequest();
82+ keyEvents.map(vent => {
83+ txsBatch.add(
84+ web3.eth.getTransaction.request(vent.transactionHash, (err, res) => {})
85+ );
86+ });
87+ const txs = await txsBatch.execute();
88+ const keyTxs = txs.response.filter(tx => {
89+ const head = tx.input.slice(0, 10) === FUNC;
90+ const size = tx.input.length === LENT;
91+ if (head && !size) {
92+ console.log('weird inputs', tx.hash);
93+ }
94+ return head && size;
95+ });
96+
97+ const receiptsBatch = new web3.BatchRequest();
98+ keyTxs.map(tx => {
99+ receiptsBatch.add(
100+ web3.eth.getTransactionReceipt.request(tx.hash, (err, res) => {})
101+ );
102+ });
103+ const recs = await receiptsBatch.execute();
104+
105+ let usage = {};
106+ recs.response.map(rec => {
107+ if (rec.status !== true) {
108+ console.log('rejecting', rec.gasUsed);
109+ return;
110+ }
111+ if (rec.gasUsed > 480000) {
112+ console.log(rec.transactionHash);
113+ }
114+ if (rec.gasUsed in usage) {
115+ usage[rec.gasUsed]++;
116+ } else {
117+ usage[rec.gasUsed] = 1;
118+ }
119+ });
120+ console.log(usage);
121+})();
src/lib/constants.js+15−5
@@ -13,12 +13,22 @@ const GALAXY_ENTROPY_BITS = 384;
13
13
14const SEED_ENTROPY_BITS = 128;
14const SEED_ENTROPY_BITS = 128;
15
15
16−//TODO properly research these, move into azimuth-js
16+//TODO move into azimuth-js
17const GAS_LIMITS = {
17const GAS_LIMITS = {
18+ SPAWN: 250000,
18− TRANSFER: 500000,
19+ TRANSFER: 490000,
19− CONFIGURE_KEYS: 150000,
20+ CONFIGURE_KEYS: 100000,
20− SET_PROXY: 200000,
21+ SET_PROXY: 119000,
21− GIFT_PLANET: 400000, //TODO can maybe do 370000, see also commit 8c0ecaaa
22+ //
23+ ESCAPE: 115000, //NOTE low sample size
24+ ADOPT: 100000, //NOTE low sample size
25+ CANCEL_ESCAPE: 200000, //NOTE no samples
26+ REJECT: 200000, //NOTE no samples
27+ DETACH: 200000, //NOTE no samples
28+ //
29+ GIFT_PLANET: 400000, //NOTE low sample size
30+ //
31+ DEFAULT: 600000,
22};
32};
23
33
24// TODO: this is walletgen-ui specific, move into a wallet router later
34// TODO: this is walletgen-ui specific, move into a wallet router later