Let's say I want to keep all the data stored in my contract only up to a specific transaction. Is there any type of rollback process or forking mechanism for smart contracts that will allow me to either return to or create a new contract with a state specified by a specific previous transaction?
1 Answer
Rollback is not possible. Creation of a new smartcontract is always a possibility. Nothing can stop you from deploying a new smartcontract, crafted mimic behavior of old contract, starting from certain initial state corresponding to one of the states of the old one. From the point of view of the network, these two contracts will be completely unrelated.
You will have to:
Figure out state of old smartcontract - tricky, see below
Generate code for the new smartcontract to preset exactly that state - straightforward (unless state/logic of the contract depends on exact value of its own address)
You can access contract's public variables with web3 API: How do I access member variables of a contract from web3.eth?. You can read contract's log records too: web3: How do I get past events of `myContract.myEvent`. You need to be talking to a node having relevant part of the blockchain, with the state you want to clone. The latter can be done by creating partial blockchain export (specify block number range to "geth export") then import it on a brand new node, isolated from the rest of the network (geth --maxpeers 0).
You cannot read private members by name, but can access directly, if you know their address in storage, see https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgetstorageat and https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat. You cannot dump map in full, but if you know key you still can read the value (RPC docs explain how to convert key to storage address). Chances are you can reconstruct relevant key values from log entries or transactions data.