starcoinorg / starcoin

Starcoin - A Move smart contract blockchain network that scales by layering
Apache License 2.0
1.37k stars 288 forks source link

[Feature Request] Mainnet forking and account impersonating #3501

Open pause125 opened 2 years ago

pause125 commented 2 years ago

Feature Request

Describe the Feature Request

Start a local development network that forks mainnet, and impersonate any account to send transactions. This will make Move developers more easy to develop and debug smart contracts.

This feature maybe a good alternative to complete #3493.

Hardhat mainnet forking hardhat impersonateaccount

Describe Preferred Solution

  1. Mainnet forking
    It's easy to fork mainnet, but if we want to fork from a history block_number, we need a local archive node or a service that provides archival data. For now, a local archive node may be more feasible, such that we need fast sync the block and state and more cpu/memory resources are required. Maybe we can also not support forking from history block_number for now.

  2. impersonateaccount I'm not sure how hardhat implemented this and if starcoin support this. If anyone has the relevant knowledge, welcome to offer suggestions.

Describe Alternatives

Related Code

Additional Context

If the feature request is approved, would you be willing to submit a PR? Yes / No (Help can be provided if you need assistance submitting a PR)

jolestar commented 2 years ago

I think we can use a light node to fork the mainnet, and do not need to sync all blocks and states, we just fetch it from the remote full node on demand.

The idea of the light node has another issue #2000

pause125 commented 2 years ago

I'd like to work on this and the light node. Could you please offer some guide where should I start?

jolestar commented 2 years ago

I'd like to work on this and the light node. Could you please offer some guide where should I start?

You can read the https://github.com/starcoinorg/starcoin/blob/master/rpc/client/src/remote_state_reader.rs first, understand how to dry run transactions locally, through the remote state reader.

Light node = P2P remote state reader + P2P chain reader(for get block) + local disk cache.

We can discuss this next meeting https://starcoin.atlassian.net/wiki/spaces/CHAIN/pages/43876777/Weekly+meeting+notes

pause125 commented 2 years ago

I'd like to work on this and the light node. Could you please offer some guide where should I start?

You can read the https://github.com/starcoinorg/starcoin/blob/master/rpc/client/src/remote_state_reader.rs first, understand how to dry run transactions locally, through the remote state reader.

Light node = P2P remote state reader + P2P chain reader(for get block) + local disk cache.

We can discuss this next meeting https://starcoin.atlassian.net/wiki/spaces/CHAIN/pages/43876777/Weekly+meeting+notes

Thanks, I'll learn these code first.