From 8d915aa5b01dbfe8908915a0bdd50fe50020cb1b Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Mon, 7 Dec 2020 11:11:44 -0700 Subject: [PATCH] v1.3: rpc getConfirmedBlock backports (#13993) * Check SlotNotRooted if confirmed block not found in blockstore or bigtable (#13776) * Separate blockstore checks for not (yet) rooted and cleaned up (#13814) * Add logging in check_blockstore_max_root (#13887) --- core/src/rpc.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 32c6b7eda5..945dfa9d76 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -607,6 +607,29 @@ impl JsonRpcRequestProcessor { } } + fn check_blockstore_max_root( + &self, + result: &std::result::Result, + slot: Slot, + ) -> Result<()> + where + T: std::fmt::Debug, + { + if result.is_err() { + let err = result.as_ref().unwrap_err(); + debug!( + "check_blockstore_max_root, slot: {:?}, max root: {:?}, err: {:?}", + slot, + self.blockstore.max_root(), + err + ); + if slot >= self.blockstore.max_root() { + return Err(RpcCustomError::BlockNotAvailable { slot }.into()); + } + } + Ok(()) + } + fn check_slot_cleaned_up( &self, result: &std::result::Result, @@ -645,6 +668,7 @@ impl JsonRpcRequestProcessor { .highest_confirmed_root() { let result = self.blockstore.get_confirmed_block(slot); + self.check_blockstore_max_root(&result, slot)?; if result.is_err() { if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage { return Ok(self @@ -750,6 +774,7 @@ impl JsonRpcRequestProcessor { .highest_confirmed_root() { let result = self.blockstore.get_block_time(slot); + self.check_blockstore_max_root(&result, slot)?; if result.is_err() { if let Some(bigtable_ledger_storage) = &self.bigtable_ledger_storage { return Ok(self