diff --git a/web3.js/rollup.config.js b/web3.js/rollup.config.js index 1be9ca30d7..a9d84dcb01 100644 --- a/web3.js/rollup.config.js +++ b/web3.js/rollup.config.js @@ -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: { diff --git a/web3.js/src/loader.ts b/web3.js/src/loader.ts index 6e3781a304..9412f0f6c4 100644 --- a/web3.js/src/loader.ts +++ b/web3.js/src/loader.ts @@ -2,7 +2,7 @@ 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'; @@ -10,6 +10,7 @@ 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 diff --git a/web3.js/src/message.ts b/web3.js/src/message.ts index b9e5199f9e..6e86867c70 100644 --- a/web3.js/src/message.ts +++ b/web3.js/src/message.ts @@ -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'; diff --git a/web3.js/src/transaction-constants.ts b/web3.js/src/transaction-constants.ts new file mode 100644 index 0000000000..591873f8b6 --- /dev/null +++ b/web3.js/src/transaction-constants.ts @@ -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; diff --git a/web3.js/src/transaction.ts b/web3.js/src/transaction.ts index aace388b51..f8466cdf64 100644 --- a/web3.js/src/transaction.ts +++ b/web3.js/src/transaction.ts @@ -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'; @@ -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 @@ -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))); }