Skip to content

Commit

Permalink
fix: eliminate circular dependencies in web3.js (#24729)
Browse files Browse the repository at this point in the history
* chore: enable circular dependency warnings on build
* fix: eliminate circular dependencies in web3.js
  • Loading branch information
steveluscher authored Apr 27, 2022
1 parent b1a331f commit f126f3a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
8 changes: 6 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ function generateConfig(configType, format) {
}),
],
onwarn: function (warning, rollupWarn) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
rollupWarn(warning);
rollupWarn(warning);
if (warning.code === 'CIRCULAR_DEPENDENCY') {
throw new Error(
'Please eliminate the circular dependencies listed ' +
'above and retry the build',
);
}
},
treeshake: {
Expand Down
3 changes: 2 additions & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {Buffer} from 'buffer';
import * as BufferLayout from '@solana/buffer-layout';

import {PublicKey} from './publickey';
import {Transaction, PACKET_DATA_SIZE} from './transaction';
import {Transaction} from './transaction';
import {SYSVAR_RENT_PUBKEY} from './sysvar';
import {sendAndConfirmTransaction} from './util/send-and-confirm-transaction';
import {sleep} from './util/sleep';
import type {Connection} from './connection';
import type {Signer} from './keypair';
import {SystemProgram} from './system-program';
import {IInstructionInputData} from './instruction';
import {PACKET_DATA_SIZE} from './transaction-constants';

// Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
// rest of the Transaction fields
Expand Down
2 changes: 1 addition & 1 deletion src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as BufferLayout from '@solana/buffer-layout';
import {PublicKey} from './publickey';
import type {Blockhash} from './blockhash';
import * as Layout from './layout';
import {PACKET_DATA_SIZE} from './transaction';
import {PACKET_DATA_SIZE} from './transaction-constants';
import * as shortvec from './util/shortvec-encoding';
import {toBuffer} from './util/to-buffer';

Expand Down
10 changes: 10 additions & 0 deletions src/transaction-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Maximum over-the-wire size of a Transaction
*
* 1280 is IPv6 minimum MTU
* 40 bytes is the size of the IPv6 header
* 8 bytes is the size of the fragment header
*/
export const PACKET_DATA_SIZE = 1280 - 40 - 8;

export const SIGNATURE_LENGTH_IN_BYTES = 64;
23 changes: 7 additions & 16 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import nacl from 'tweetnacl';
import bs58 from 'bs58';
import {Buffer} from 'buffer';

import {
PACKET_DATA_SIZE,
SIGNATURE_LENGTH_IN_BYTES,
} from './transaction-constants';
import {Connection} from './connection';
import {Message} from './message';
import {PublicKey} from './publickey';
Expand All @@ -19,21 +23,8 @@ export type TransactionSignature = string;

/**
* Default (empty) signature
*
* Signatures are 64 bytes in length
*/
const DEFAULT_SIGNATURE = Buffer.alloc(64).fill(0);

/**
* Maximum over-the-wire size of a Transaction
*
* 1280 is IPv6 minimum MTU
* 40 bytes is the size of the IPv6 header
* 8 bytes is the size of the fragment header
*/
export const PACKET_DATA_SIZE = 1280 - 40 - 8;

const SIGNATURE_LENGTH = 64;
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);

/**
* Account metadata used to define instructions
Expand Down Expand Up @@ -747,8 +738,8 @@ export class Transaction {
const signatureCount = shortvec.decodeLength(byteArray);
let signatures = [];
for (let i = 0; i < signatureCount; i++) {
const signature = byteArray.slice(0, SIGNATURE_LENGTH);
byteArray = byteArray.slice(SIGNATURE_LENGTH);
const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
signatures.push(bs58.encode(Buffer.from(signature)));
}

Expand Down

0 comments on commit f126f3a

Please sign in to comment.