Skip to content

Commit

Permalink
fix that aptos remote debugger coerces remote state value read result…
Browse files Browse the repository at this point in the history
…s to StateValue::Legacy
  • Loading branch information
msmouse committed Nov 30, 2023
1 parent ea53fe3 commit d6f024b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl StateApi {
"StateKey({}) and Ledger version({})",
request.key, ledger_version
),
AptosErrorCode::TableItemNotFound,
AptosErrorCode::StateValueNotFound,
&ledger_info,
)
})?;
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-validator-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ aptos-types = { workspace = true }
async-trait = { workspace = true }
bcs = { workspace = true }
itertools = { workspace = true }
log = "0.4.17"
lru = { workspace = true }
move-binary-format = { workspace = true }
tokio = { workspace = true }
38 changes: 22 additions & 16 deletions aptos-move/aptos-validator-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ pub trait AptosValidatorInterface: Sync {
}

pub struct DebuggerStateView {
query_sender:
Mutex<UnboundedSender<(StateKey, Version, std::sync::mpsc::Sender<Option<Vec<u8>>>)>>,
query_sender: Mutex<
UnboundedSender<(
StateKey,
Version,
std::sync::mpsc::Sender<Result<Option<StateValue>>>,
)>,
>,
version: Version,
}

Expand All @@ -124,13 +129,14 @@ async fn handler_thread<'a>(
mut thread_receiver: UnboundedReceiver<(
StateKey,
Version,
std::sync::mpsc::Sender<Option<Vec<u8>>>,
std::sync::mpsc::Sender<Result<Option<StateValue>>>,
)>,
) {
const M: usize = 1024 * 1024;
let cache = Arc::new(Mutex::new(
LruCache::<(StateKey, Version), Option<Vec<u8>>>::new(M),
));
let cache = Arc::new(Mutex::new(LruCache::<
(StateKey, Version),
Option<StateValue>,
>::new(M)));

loop {
let (key, version, sender) =
Expand All @@ -141,19 +147,20 @@ async fn handler_thread<'a>(
};

if let Some(val) = cache.lock().unwrap().get(&(key.clone(), version)) {
sender.send(val.clone()).unwrap();
sender.send(Ok(val.clone())).unwrap();
} else {
assert!(version > 0, "Expecting a non-genesis version");
let db = db.clone();
let cache = cache.clone();
tokio::spawn(async move {
let val = db
.get_state_value_by_version(&key, version - 1)
.await
.ok()
.and_then(|v| v.map(|s| s.bytes().to_vec()));
cache.lock().unwrap().put((key, version), val.clone());
sender.send(val)
let res = db.get_state_value_by_version(&key, version - 1).await;
match res {
Ok(val) => {
cache.lock().unwrap().put((key, version), val.clone());
sender.send(Ok(val))
},
Err(err) => sender.send(Err(err)),
}
});
}
}
Expand All @@ -180,8 +187,7 @@ impl DebuggerStateView {
query_handler_locked
.send((state_key.clone(), version, tx))
.unwrap();
let bytes_opt = rx.recv()?;
Ok(bytes_opt.map(|bytes| StateValue::new_legacy(bytes.into())))
rx.recv()?
}
}

Expand Down
3 changes: 2 additions & 1 deletion aptos-move/aptos-validator-interface/src/rest_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl AptosValidatorInterface for RestDebuggerInterface {
RestError::Api(AptosErrorResponse {
error:
AptosError {
error_code: AptosErrorCode::StateValueNotFound,
error_code:
AptosErrorCode::StateValueNotFound | AptosErrorCode::TableItemNotFound, /* bug in pre 1.9 nodes */
..
},
..
Expand Down
9 changes: 4 additions & 5 deletions consensus/src/dag/dag_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,10 @@ impl Dag {
.map(|(_, round_nodes)| round_nodes.iter().map(|node| node.is_some()).collect())
.collect();

bitmask.resize((target_round - lowest_round + 1) as usize, vec![
false;
self.author_to_index
.len()
]);
bitmask.resize(
(target_round - lowest_round + 1) as usize,
vec![false; self.author_to_index.len()],
);

DagSnapshotBitmask::new(lowest_round, bitmask)
}
Expand Down

0 comments on commit d6f024b

Please sign in to comment.