From aa223c645791be158a597efb8579270dbe5bdd82 Mon Sep 17 00:00:00 2001 From: Jon Cinque Date: Wed, 31 Aug 2022 01:02:34 +0200 Subject: [PATCH] [PATCH] feat: double PACKET_DATA_SIZE Try blind double of PACKET_DATA_SIZE; this double things across the board and is not a permanent solution. --- rpc/src/rpc.rs | 16 +++++++++++----- sdk/src/packet.rs | 3 ++- web3.js/src/transaction/constants.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 8d5d12f033..9d46a315ce 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -4393,8 +4393,11 @@ pub mod rpc_obsolete_v1_7 { } } -const MAX_BASE58_SIZE: usize = 1683; // Golden, bump if PACKET_DATA_SIZE changes -const MAX_BASE64_SIZE: usize = 1644; // Golden, bump if PACKET_DATA_SIZE changes +// These values need to be updated if PACKET_DATA_SIZE changes. The correct values can +// be found by hand or by simply encoding `PACKET_DATA_SIZE` bytes and checking length. +// `test_max_encoded_tx_goldens` ensures these values are correct. +const MAX_BASE58_SIZE: usize = 3365; +const MAX_BASE64_SIZE: usize = 3288; fn decode_and_deserialize( encoded: String, encoding: TransactionBinaryEncoding, @@ -8285,7 +8288,7 @@ pub mod tests { } #[test] - fn test_worst_case_encoded_tx_goldens() { + fn test_max_encoded_tx_goldens() { let ff_tx = vec![0xffu8; PACKET_DATA_SIZE]; let tx58 = bs58::encode(&ff_tx).into_string(); assert_eq!(tx58.len(), MAX_BASE58_SIZE); @@ -8295,8 +8298,11 @@ pub mod tests { #[test] fn test_decode_and_deserialize_too_large_payloads_fail() { - // +2 because +1 still fits in base64 encoded worst-case - let too_big = PACKET_DATA_SIZE + 2; + // 4 base64 digits are generated from groups of 3 bytes; however, those 4 digits + // are generated even if the group only has 1 or 2 bytes. + // So, we need 4 - (PACKET_DATA_SIZE % 3) extra bytes to ensure we'll spill over + let extra_bytes = 4 - (PACKET_DATA_SIZE % 3); + let too_big = PACKET_DATA_SIZE + extra_bytes; let tx_ser = vec![0xffu8; too_big]; let tx58 = bs58::encode(&tx_ser).into_string(); let tx58_len = tx58.len(); diff --git a/sdk/src/packet.rs b/sdk/src/packet.rs index 412375e35f..112d962fe8 100644 --- a/sdk/src/packet.rs +++ b/sdk/src/packet.rs @@ -15,7 +15,8 @@ static_assertions::const_assert_eq!(PACKET_DATA_SIZE, 1232); /// 1280 is IPv6 minimum MTU /// 40 bytes is the size of the IPv6 header /// 8 bytes is the size of the fragment header -pub const PACKET_DATA_SIZE: usize = 1280 - 40 - 8; +/// Double the minimum to support larger than MTU transactions +pub const PACKET_DATA_SIZE: usize = 2 * (1280 - 40 - 8); bitflags! { #[repr(C)] diff --git a/web3.js/src/transaction/constants.ts b/web3.js/src/transaction/constants.ts index 075337e8dc..618d48cdfd 100644 --- a/web3.js/src/transaction/constants.ts +++ b/web3.js/src/transaction/constants.ts @@ -5,7 +5,7 @@ * 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 PACKET_DATA_SIZE = 2464; export const VERSION_PREFIX_MASK = 0x7f; -- 2.37.2