pendulum-chain / spacewalk

Apache License 2.0
35 stars 7 forks source link

Investigate root cause of vaults RPC issue #30

Closed ebma closed 2 years ago

ebma commented 2 years ago

During the development of the vault client we encountered the following error:

WARN vault::deposit: Failed to process transaction: RuntimeError(SubxtBasicError(Rpc(Request("{\"jsonrpc\":\"2.0\",\"error\":{\"code\":1002,\"message\":\"Verification Error: Runtime error: Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction\",\"data\":\"Runtime error: Execution failed: Error calling api function: Failed to convert parameter `tx` from node to runtime of validate_transaction\"},\"id\":41}")))

The error was shown after calling an extrinsic of the spacewalk pallet from within the vault client. To be precise it is thrown after this function call (that can be found in /clients/runtime/rpc.rs):

self.api.tx()
                .spacewalk() 
                .report_stellar_transaction(tx_envelope_xdr.to_vec()) 
                .sign_and_submit_then_watch(&signer)
                .await

After trying lots of things, the error was finally resolved in this commit by replacing the files of the substrate template testchain with the interbtc chain. But the root cause of this error remains unknown. Since we want the vault and spacewalk to work with other parachains as well, it is important to pin down this issue in case it pops up again.

There likely is a type mismatch somewhere, i.e. the vault client expects the chain it connects to, to have a certain type for e.g. addresses of the keypair.

To investigate this issue I would suggest starting with the substrate template chain again and modifying parts of it step by step until this RPC issue does not occur anymore. Note that every time the chain runtime changes, you should recreate the metadata-standalone.scale file used by the vault (see here or in the README of the vault client).

ebma commented 2 years ago

I think that the root cause of the issue is a mismatch of Address types.

The interbtc test chain uses AccountId as Address whereas the substrate template chain wraps the AccountId with MultiAddress<AccountId, ()> before using it as Address.

So after changing the Address field in the SpacewalkRuntime Config in clients/runtime/src/lib.rs as follows:

impl Config for SpacewalkRuntime {
    type Index = Index;
    type BlockNumber = BlockNumber;
    type Hash = H256;
    type Hashing = BlakeTwo256;
    type AccountId = AccountId;
-   type Address = Self::AccountId;
+   type Address = spacewalk_runtime::Address;
    type Header = Header<Self::BlockNumber, BlakeTwo256>;
    type Extrinsic = OpaqueExtrinsic;
    type Signature = MultiSignature;
}

i.e.using the Address that is defined in the testchain runtime, the extrinsic calls worked even for the default substrate chain for which the RPC error occurred previously.

If we encounter this RPC error again in the future, I assume that checking if all the types defined in the impl Config for SpacewalkRuntime block of the spacevault client are matching the types of the target chain will fix the problem.