MystenLabs / sui

Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
https://sui.io
Apache License 2.0
5.84k stars 11.06k forks source link

Debugging native rust functions #17098

Open yuvalelmo opened 2 months ago

yuvalelmo commented 2 months ago

Hi, I am trying to debug some CLI Commands, which will ultimately call a move function, that in it's turn is calling a native rust function. The way I'm debugging the code now is using the IDE's debugger, with the sub commands provided in the debugging configuration arguments. It allows me to debug the code on the part of the client_commands.rs file, but I cannot manage to debug the native function that is called from the move code, which is implemented inside sui-move-natives. I tried to put some breakpoints in there, but unfortunately this won't do the trick.

Is it possible to debug this kind of functions? If so, then how do I do this? Thanks!

yuvalelmo commented 2 months ago

Another problem I have is that whenever I call this move function from the CLI, I get this error:

RPC call failed: ErrorObject { code: ServerError(-32002), message: "Failed to sign transaction by a quorum of validators because of locked objects. Retried a conflicting transaction Some(TransactionDigest(FnUF397ofhPF4rdbRPaXkF5yUG8M1RDTnj11oqsMV2ws)), success: Some(false)", data: Some(RawValue({"FnUF397ofhPF4rdbRPaXkF5yUG8M1RDTnj11oqsMV2ws":[["0x1166b06d4fdbb7a3c4cec1fad93b2daf70716fd586d3658816c0a9d7b0a026df",11,"EoN6VqGqXXpToVbP3ARTdiJbpYd2h9jocV3YPk4e469J"],["0x1166b06d4fdbb7a3c4cec1fad93b2daf70716fd586d3658816c0a9d7b0a026df",11,"EoN6VqGqXXpToVbP3ARTdiJbpYd2h9jocV3YPk4e469J"],["0x1166b06d4fdbb7a3c4cec1fad93b2daf70716fd586d3658816c0a9d7b0a026df",11,"EoN6VqGqXXpToVbP3ARTdiJbpYd2h9jocV3YPk4e469J"],["0x1166b06d4fdbb7a3c4cec1fad93b2daf70716fd586d3658816c0a9d7b0a026df",11,"EoN6VqGqXXpToVbP3ARTdiJbpYd2h9jocV3YPk4e469J"]]})) }
amnn commented 2 months ago

Hi @yuvalelmo, you should be able to set a breakpoint in a native function, but it's possible that the issue you're facing comes from the fact that there are multiple copies of the native functions (one for each execution version) and you may have set the breakpoint in a version that is not currently being used?

If you are running the network locally, then you will almost certainly be using this copy of sui-move-natives: https://github.com/MystenLabs/sui/tree/dd84ebd015b15cffbae1537833bbdb55b2840e8f/sui-execution/latest/sui-move-natives

But note that there is a v0, v1, and v2 as well.

yuvalelmo commented 2 months ago

Ok, thanks. I'll try this. Looks like my other problem is making it impossible to even get to the relevant function. I saw on other issues in this repo the the conflicting transaction happens because of locking the gas object. I tried running the transaction from another sui address, and also tried it with just a different gas object ID instead of using a default one, but no outcome from this.

Maybe you have any input regarding this? on the network logs i can see this line a few times in a row (probably because of retry mechanism)

2024-04-14T12:44:07.274572Z  INFO node{name=k#8dcff6d1..}:validator_state_process_tx{tx_digest=TransactionDigest(4NxigJB9hyJnvhDXmckro5DsScmPACC1q4LFTMg7tNd2)}: sui_core::authority::authority_store: Cannot acquire lock: conflicting transaction! prev_tx_digest=TransactionDigest(82uaGcNzmaivR1ND2yBb5J1i6S47JbB1VdQ5KihDd4Wm) cur_tx_digest=TransactionDigest(4NxigJB9hyJnvhDXmckro5DsScmPACC1q4LFTMg7tNd2)

Also, In the explorer, I cannot find any of these transactions 82uaGcNzmaivR1ND2yBb5J1i6S47JbB1VdQ5KihDd4Wm nor 4NxigJB9hyJnvhDXmckro5DsScmPACC1q4LFTMg7tNd2

yuvalelmo commented 2 months ago

Hey, I just noticed this error now on the node logs. it happens whenever I run this function from another address.

thread '<unnamed><unnamed>thread '' panicked at ' panicked at <unnamed>.../sui-execution/latest/sui-adapter/src/programmable_transactions/context.rs' panicked at .../sui-execution/latest/sui-adapter/src/programmable_transactions/context.rs770
.../sui-execution/latest/sui-adapter/src/programmable_transactions/context.rs::2024-04-15T08:43:00.351591Z ERROR node{name=k#99f25ef6..}:execution_driver{tx_digest=TransactionDigest(3SU3MyBjWFuZF1t7H4qFdz9KYKkzUZnShGJA3fiSRNyA)}: telemetry_subscribers: panicked at .../sui-execution/latest/sui-adapter/src/programmable_transactions/context.rs:770:21:

The only serialization I do to the arguments I send to the function is from object to bcs bytes, then to SuiJsonValue like this:

fn serialize_argument<T: serde::Serialize>(object: &T) -> Result<SuiJsonValue, Error> {
    let serialized_numbers = bcs::to_bytes(object)?
        .iter()
        .map(|v| Value::Number(Number::from (*v)))
        .collect();
    let object_as_sui_json = SuiJsonValue::new(Value::Array(serialized_numbers))?;
    Ok(object_as_sui_json)
}
amnn commented 2 months ago

Hi @yuvalelmo, the error that you've shared above looks like it's garbled and incomplete. Can you share the full message, with the stacktrace for the panic, and the steps you took to reproduce it? This includes changes to the validator codebase, e.g. to introduce the native function. It sounds like the problem you are facing is not related to the native function, but some other change, because you are not reaching the point at which the native function would have been called.