{"record":{"id":"0cccf38c445d1abb","repo":"nautechsystems/nautilus_trader","slug":"e-0cccf3","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/grpc/builder.rs","lineNumber":182,"sourceCode":"            .map_err(|e| anyhow::anyhow!(\"Cannot create sign doc: {e}\"))?;\n\n        account.sign(sign_doc)\n    }\n\n    /// Build and simulate a transaction to estimate gas.\n    ///\n    /// Returns the raw transaction bytes suitable for simulation.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if transaction building fails.\n    pub fn build_for_simulation(\n        &self,\n        account: &Account,\n        msgs: impl IntoIterator<Item = Any>,\n    ) -> Result<Vec<u8>, anyhow::Error> {\n        let tx_raw = self.build_transaction(account, msgs, None, None)?;\n        tx_raw.to_bytes().map_err(|e| anyhow::anyhow!(\"{e}\"))\n    }\n}\n\nimpl Debug for TxBuilder {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        f.debug_struct(stringify!(TxBuilder))\n            .field(\"chain_id\", &self.chain_id)\n            .field(\"fee_denom\", &self.fee_denom)\n            .finish()\n    }\n}\n","sourceCodeStart":164,"sourceCodeEnd":194,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/grpc/builder.rs#L164-L194","documentation":"build_for_simulation serializes the built (signed) RawTx into bytes via tx_raw.to_bytes() and wraps any failure in anyhow with the bare error. This fails when the protobuf encoding of the complete transaction cannot be produced, e.g. invalid nested messages or an internal serialization bug.","triggerScenarios":"Calling build_for_simulation when tx_raw.to_bytes() fails after build_transaction succeeded — an encoding failure on the finalized signed tx.","commonSituations":"Simulating a tx built from messages that individually encode but jointly produce an invalid payload; version skew between proto definitions used to build vs encode the tx.","solutions":["Inspect the propagated error to identify which field failed to encode and correct the corresponding msg.","Rebuild the transaction after refreshing account sequence/number from query_address so the signed doc matches chain state.","Pin consistent versions of the cosmos/prost proto crates so build and encode use identical schemas.","Fall back to a smaller message batch to isolate the offending message."],"exampleFix":"// before\ntx_raw.to_bytes().map_err(|e| anyhow::anyhow!(\"{e}\"))\n// after: add context for diagnosability\ntx_raw.to_bytes().map_err(|e| anyhow::anyhow!(\"Cannot encode tx to bytes for simulation: {e}\"))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let bytes = match builder.build_for_simulation(&account, msgs) {\n    Ok(b) => b,\n    Err(e) => { tracing::error!(\"tx encode failed: {e:#}\"); return Err(e); }\n};","preventionTips":["Simulate early in development to catch encoding problems before mainnet use","Log the full anyhow error chain ({e:#}) for root cause","Test with production-shaped messages, not just minimal fixtures"],"tags":["grpc","cosmos","simulation","serialization"],"backgroundTag":"protobuf-marshal-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}