Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: SuiString does not have epoch property (JSON RPC) #244

Closed
mirage007 opened this issue Nov 29, 2024 · 8 comments
Closed

[bug]: SuiString does not have epoch property (JSON RPC) #244

mirage007 opened this issue Nov 29, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@mirage007
Copy link

When trying to call a public read-only function, dev inspect works fine without epoch params, but fails with a non null value:

sample code:


    cfg = SuiConfig.user_config(rpc_url="https://rpc-mainnet.suiscan.xyz:443")
    client = SyncClient(cfg)

    sender = SuiAddress(
        "0x0000000000000000000000000000000000000000000000000000000000000000"
    )

    txn = SyncTransaction(client=client)#, initial_sender=sender)

    txn.move_call(
        target="0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6::staked_sui_vault::afsui_to_sui",
        arguments=[
            ObjectID(
                "0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d"
            ),
            ObjectID(
                "0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610"
            ),
            SuiU64(1000000000),
        ],
    )


    tx_bytes = txn.build_for_inspection()
    inspect_tx = _DebugInspectTransaction(
            sender_address=sender, tx_bytes=tx_bytes, epoch="500"
        )
    req = client.execute(inspect_tx)

    if req.is_ok():
        result = TxInspectionResult.factory(req.result_data)

This generates an error:

build_parm = <pysui.sui.sui_types.scalars.SuiString object at 0x7f24f7944550>
api_parm = SuiApiParam(name='epoch', schema=SuiJsonString(type='string', type_path=['BigInt_for_uint64', 'string']), required=False, description='The epoch to perform the call. Will be set from the system state object if not provided')

    @versionchanged(version="0.24.0", reason="Moved from list to dict for RPC params")
    @deprecated(
        version="0.65.0", reason="Transition to pysui GraphQL SuiClients and QueryNodes"
    )
    def __validate_parameter(
        build_parm: Any, api_parm: SuiApiParam
    ) -> Union[str, SuiRpcApiInvalidParameter]:
        """Validate the specific parameter."""
>       att = getattr(build_parm, api_parm.name)
E       AttributeError: 'SuiString' object has no attribute 'epoch'

.venv/lib/python3.10/site-packages/pysui/sui/sui_txn_validator.py:60: AttributeError

It seems that the issue is that the "epoch" is defined as a string, but the SuiString is missing epoch as a key. After adding it as a key, it passes the validator, but then RPC call returns an error:

'error': 'ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: FAILED_TO_DESERIALIZE_ARGUMENT, sub_status: None, message: None, exec_state: None, location: Undefined, indices: [], offsets: [] }), command: Some(0) } }'

So it seems possible that it expects U64 as per RPC docs instead of String. After changing the _DebugInspectTransaction epoch type to SuiU64, and adding epoch as an property, running gets yet another error:

{'code': -32602,
 'message': 'invalid type: integer `500`, expected a string at line 1 column 4'}

Any pointers would be appreciated!

@FrankC01
Copy link
Owner

FrankC01 commented Nov 29, 2024

You should not be using the private class which is for the SuiTransaction.

Instead, in the builders package exec_builders.py use InspectTransaction. Pass in SuiString("500") as the epoch argument.

And you are correct on the SuiString not having epoch, this is a bug and will be fixed in next release.

This works now:

def transaction_inspect3(
    txb: SyncTransaction,
    sender: Optional[SuiAddress] = None,
    epoch: Optional[SuiString] = None,
):
    """."""
    tx_raw = txb.build_for_inspection()
    # print(tx_raw)
    result = txb.client.execute(
        InspectTransaction(
            sender_address=sender or txb.client.config.active_address,
            tx_bytes=SuiString(tx_raw),
            epoch=epoch or SuiString("12"),
        )
    )
    if result.is_ok():
        # print(result.result_data)
        print(result.result_data.to_json(indent=2))
    else:
        print(result.result_string)

@FrankC01 FrankC01 added the question Further information is requested label Nov 29, 2024
@FrankC01 FrankC01 self-assigned this Nov 30, 2024
@FrankC01 FrankC01 added bug Something isn't working and removed question Further information is requested labels Nov 30, 2024
@FrankC01 FrankC01 added this to pysui Nov 30, 2024
@github-project-automation github-project-automation bot moved this to Backlog in pysui Nov 30, 2024
@FrankC01 FrankC01 changed the title bug: _DebugInspectTransaction doesn't accept epoch as indicated in docs [bug]: SuiString does not have epoch property (JSON RPC) Nov 30, 2024
@mirage007
Copy link
Author

Yes,

it's still the same error, here's the standalone code blurb:

from pysui import SuiConfig, SyncClient, SuiAddress
from pysui.sui.sui_txn import SyncTransaction

from pysui.sui.sui_builders.exec_builders import InspectTransaction
from pysui.sui.sui_txresults.complex_tx import TxInspectionResult
from pysui.sui.sui_types.scalars import SuiString, ObjectID

cfg = SuiConfig.user_config(rpc_url="https://rpc-mainnet.suiscan.xyz:443")
client = SyncClient(cfg)

sender = SuiAddress("0x0000000000000000000000000000000000000000000000000000000000000000")

txn = SyncTransaction(client=client, initial_sender = sender)

txn.move_call(target="0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6::staked_sui_vault::afsui_to_sui",
              arguments = [ObjectID("0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d"),
                          ObjectID("0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610"),
                          SuiString(1000000000)]
         )

tx_bytes = txn.build_for_inspection()

txn2 = InspectTransaction(sender_address=sender, tx_bytes = tx_bytes, epoch = SuiString("500"))

res= client.execute(txn2)

res.result_data

and the full output. To note, it is clearly using executed_epoch = 601 so it's just not paying attention to the epoch param

TxInspectionResult(effects=Effects(status=Status(status='failure', error='VMVerificationOrDeserializationError in command 0', succeeded=False), message_version='v1', gas_used=GasCostSummary(computation_cost=750000, non_refundable_storage_fee=42712, storage_cost=5259200, storage_rebate=4228488), transaction_digest='FdHhKpL2XRK5hifFneeC1tdqQ3MZBekjgbwLHJiX4rBC', gas_object=GenericOwnerRef(reference=GenericRef(object_id='0xa650dcd8569d4fe66e8d69f4d9382dc4f6795c16e46c3d8f1757537ef8776c28', version=438523917, digest='ABdfUGSo62PSf4YwihzmpiHuS7oVbmAHdiUHKRAP3VWh'), owner='0x0000000000000000000000000000000000000000000000000000000000000000'), modified_at_versions=[{'objectId': '0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d', 'sequenceNumber': '438523916'}, {'objectId': '0xa650dcd8569d4fe66e8d69f4d9382dc4f6795c16e46c3d8f1757537ef8776c28', 'sequenceNumber': '1'}, {'objectId': '0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610', 'sequenceNumber': '438523916'}], dependencies=['7aZJpvLooTaCg538EwLwotYHuuxHWR9eMjCwsX8d5eaq', '9Zpr9ReEJrwwQYwUt6NyQ71vHWLS69gnPSzNEnFmp2iA'], mutated=[GenericOwnerRef(reference=GenericRef(object_id='0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d', version=438523917, digest='6qga3wdBobnwRtN4vro5DEV4KruQssFxi8qhZxrwdZga'), owner={'initial_shared_version': 32696040}), GenericOwnerRef(reference=GenericRef(object_id='0xa650dcd8569d4fe66e8d69f4d9382dc4f6795c16e46c3d8f1757537ef8776c28', version=438523917, digest='ABdfUGSo62PSf4YwihzmpiHuS7oVbmAHdiUHKRAP3VWh'), owner='0x0000000000000000000000000000000000000000000000000000000000000000'), GenericOwnerRef(reference=GenericRef(object_id='0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610', version=438523917, digest='G7MCGvpCDRUfRMLquNzGSJtEHFjZccjntuCXvk5ufBMB'), owner={'initial_shared_version': 32347695})], created=[], deleted=[], wrapped=[], unwrapped=[], unwrapped_then_deleted=[], shared_objects=[GenericRef(object_id='0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d', version=438523916, digest='H1g6GWaCmLwM5Db4zobEbzm64uiyfoH47UcZG1hTP6Fh'), GenericRef(object_id='0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610', version=438523916, digest='ANssAZwEcTQiPCzYZ6QTC7133Uz8dh74n5eQqn7XHnPK')], executed_epoch=601, events_digest='0'), events=[], results=[], error='ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: FAILED_TO_DESERIALIZE_ARGUMENT, sub_status: None, message: None, exec_state: None, location: Undefined, indices: [], offsets: [] }), command: Some(0) } }')

@FrankC01
Copy link
Owner

FrankC01 commented Dec 4, 2024

Yes, I added the fix in a branch and will be merging and publishing to PyPi soon

@mirage007
Copy link
Author

Just to clarify. There are 2 issues:

  1. SuiString.epoch is missing, which I think you are addressing in a separate issue.
  2. once 1 is fixed, i still get serialization error above, I'm not exactly sure what's the fix for that.

@FrankC01
Copy link
Owner

FrankC01 commented Dec 5, 2024

So, the epoch missing on SuiString is this issue.

First:
The serialization error is not related to pysui as (with the fix) this works:

def epoch_test():
    cfg = SuiConfig.default_config()
    client = SyncClient(cfg)
    txn = SyncTransaction(client=client, initial_sender=cfg.active_address)
    scoin = txn.split_coin(coin=txn.gas, amounts=[1000000000])
    txn.transfer_objects(transfers=[scoin], recipient=cfg.active_address)

    tx_bytes = txn.build_for_inspection()
    istxn = InspectTransaction(
        sender_address=cfg.active_address, tx_bytes=tx_bytes, epoch=SuiString("25")
    )
    res = client.execute(istxn)
    print(res.result_data.to_json(indent=2))

Second:
Even though the above returns success on the inspect, the executed transaction does not match the epoch I passed in (the above test is against devnet by the way)
.
The following code suggest the epoch value is being ignored:
https://github.com/MystenLabs/sui/blob/8d4a73d3fb93690fbaddc0b75e49cc650b2e28dd/crates/sui-json-rpc/src/transaction_execution_api.rs#L346

I am following up w/Mysten on this.

Finally:
The serialization error is something different that may be related to the target function you are calling.

@mirage007
Copy link
Author

mirage007 commented Dec 5, 2024 via email

@FrankC01
Copy link
Owner

FrankC01 commented Dec 6, 2024

I confirmed with Mysten that epoch is ignored so you don't have to provide the argument. Updated example:

def epoch_test():
    cfg = SuiConfig.default_config()
    client = SyncClient(cfg)
    txn = SyncTransaction(client=client, initial_sender=cfg.active_address)
    scoin = txn.split_coin(coin=txn.gas, amounts=[1000000000])
    txn.transfer_objects(transfers=[scoin], recipient=cfg.active_address)

    tx_bytes = txn.build_for_inspection()
    istxn = InspectTransaction(sender_address=cfg.active_address, tx_bytes=tx_bytes)
    res = client.execute(istxn)
    print(res.result_data.to_json(indent=2))
    ```
 
Your issue, however, is still related to your move call and not pysui. I would check the arguments of the function you are calling to ensure they are corrects as well as adding any `type_arguments` it requires.

@FrankC01 FrankC01 moved this from Backlog to In Progress in pysui Dec 7, 2024
@FrankC01 FrankC01 closed this as completed Dec 9, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in pysui Dec 9, 2024
@mirage007
Copy link
Author

mirage007 commented Dec 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants