Fixing message too long and overflow panics (#288)

This commit is contained in:
galactus 2024-01-18 15:11:29 +01:00 committed by GitHub
parent e3bfaac726
commit 4d4019264e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -63,7 +63,10 @@ impl TxStore {
let length_before = self.store.len();
self.store
.retain(|_k, v| v.last_valid_blockheight >= current_finalized_blockheight);
log::info!("Cleaned {} transactions", length_before - self.store.len());
log::info!(
"Cleaned {} transactions",
length_before.saturating_sub(self.store.len())
);
}
pub fn is_transaction_confirmed(&self, signature: &String) -> bool {

View File

@ -14,6 +14,7 @@ use anyhow::Context;
use jsonrpsee::{core::SubscriptionResult, server::ServerBuilder, PendingSubscriptionSink};
use prometheus::{opts, register_int_counter, IntCounter};
use solana_lite_rpc_core::{
encoding,
stores::{block_information_store::BlockInformation, data_cache::DataCache, tx_store::TxProps},
AnyhowJoinHandle,
};
@ -314,11 +315,27 @@ impl LiteRpcServer for LiteBridge {
) -> crate::rpc::Result<String> {
RPC_SEND_TX.inc();
// Copied these constants from solana labs code
const MAX_BASE58_SIZE: usize = 1683;
const MAX_BASE64_SIZE: usize = 1644;
let SendTransactionConfig {
encoding,
max_retries,
} = send_transaction_config.unwrap_or_default();
let expected_size = match encoding {
encoding::BinaryEncoding::Base58 => MAX_BASE58_SIZE,
encoding::BinaryEncoding::Base64 => MAX_BASE64_SIZE,
};
if tx.len() > expected_size {
return Err(jsonrpsee::core::Error::Custom(format!(
"Transaction too large, expected : {} transaction len {}",
expected_size,
tx.len()
)));
}
let raw_tx = match encoding.decode(tx) {
Ok(raw_tx) => raw_tx,
Err(err) => {