From 935ad2c371da8405bb85922b9941d35b3dc68ceb Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Wed, 29 Sep 2021 15:43:36 -0500 Subject: [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.ts | 4 +++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 1a0dcdeb6c..e33492fa84 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -4214,8 +4214,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, @@ -7749,7 +7752,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); @@ -7759,8 +7762,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 efea219043..473a92ecfe 100644 --- a/sdk/src/packet.rs +++ b/sdk/src/packet.rs @@ -12,7 +12,8 @@ use { /// 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 591873f8b6..f94d5778ba 100644 --- a/web3.js/src/transaction-constants.ts +++ b/web3.js/src/transaction-constants.ts @@ -5,6 +5,6 @@ * 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 SIGNATURE_LENGTH_IN_BYTES = 64; -- 2.32.0 (Apple Git-132)