Closed roninjin10 closed 8 months ago
Note: each sub project deserves it's own mini design doc as they kick off. This design doc may be just a few sentences and a api of how it integrates into other stuff.
Developers working with the OP Stack face several challenges:
These issues hinder efficient local development and testing on the OP Stack. There's a clear need for a tool like Mocktimism, which would function as a Docker-compose equivalent for blockchain, allowing developers to easily configure multiple chains. This tool should provide a streamlined development experience, be compatible with existing tools, and adapt to the evolving OP Stack landscape.
Mocktimism is a wrapper around anvil that can be configured to run
This is distinct from anvil because anvil is simply the containers mocktimism is wrapping.
The services spun up (if spinning up an l1 and an l2) will match the current l2 infra in [our docker-compose](https://github.com/ethereum-optimism/optimism/blob/develop/ops-bedrock/docker-compose.yml) and some extras that enable the anvil devnet
Mocktimism is broken up into many sub projects with an estimate of the time to implement. The individual designs are purposefully vague so to let the implementer treat each subtask as a subproject with it’s own short design.
Objective: Establish multiple network environments without relying on Docker.
This is the most risky part of the project and should happen earlier in case any blockers come up or the approach fails to work.
Objective: Ensure configurations are correctly loaded and provide informative error messages during misconfigurations.
Objective: Update op-reth for compatibility with op-node.
Objective: Integrate the working engine API proxy into Anvil.
This is blocked by chatting with anvil team who is currently on vacation. The dev will be back next week. Goal is for us to externalize this work
-engine-api
to Anvil to enable/disable this feature.Objective: Integrate the production services into op-anvil.
The other riskiest part of mocktimism so will happen early
Start via just integrating the existing services. Profile and replace with lighter weight versions if necessary (most likely not necessary).
Lighter weight versions can take advantage of the fact we can listen to every state update to the chains trivially.
Objective: Offer a user-friendly command-line application for Mocktimism.
Objective: Facilitate CI/CD operations using Mocktimism.
.yml
files.Objective: Allow easy installation of Mocktimism via NPM.
Objective: Provide a TypeScript interface similar to anvil-js
for integration into projects.
anvil-js
maintainer to ensure coherence and synergy.Objective: Implement basic test actions for op-viem.
mocktimism_foo
(external work)Objective: Implement features such as setting the base fee.
mocktimism_foo
.Objective: Provide clear and concise documentation in Markdown. This documentation also includes the secondary scope of clearly defining any APIs that are needed to be defined to allow base to collaborate.
Objective: Ensure Mocktimism operates seamlessly with op-anvil and the indexer as first use cases
Objective: Ensure error handling, logging, and visibility into what mocktimism is doing is polished
For any dev tool to be good extra time must be given to making sure error handling and logging are solid
Note: this estimate assumes external work from base engineers working part time will knock out the marked external sections.
To achieve the desired outcome of Mocktimism, the following strategic collaboration and sequencing plan is recommended:
Base will provide crucial engineering assistance for specific sections of the project. Their expertise, particularly in low-level tasks, is expected to accelerate progress in areas such as Anvil modifications, engine API adjustments, and Rust-based developments.
Mocktimism's development will commence in a separate repository distinct from the primary monorepo. This choice is influenced by the following factors:
To maintain transparency and foster community engagement, issue tracking will be managed publicly within the Mocktimism repository. This approach will ensure that both internal teams and external contributors are aligned on project developments.
Whenever tasks are externalized (i.e., handed off from one team to another), a detailed specification outlining the interoperability of services across team boundaries will be mandatory. This approach ensures clear communication and minimizes potential misalignments.
Weekly op-anvil meetings will be conducted to assess progress, discuss challenges, and align on next steps. Furthermore, Will will provide internal updates every Friday, ensuring that stakeholders are kept informed on the project's status.
Note these are subject to change pending syncing with Base on October 13th.
*This project has been referenced by other names in the past including OP-Anvil. Mocktimism is an internal name and the product+devrel teams should decide what the appropiate GTM name(s) is(are) after alpha.
*This is NOT an engineering design doc and even though it will contain some code and API/Usage examples it will not go into any implementation details. The engineering design doc will be linked below when it exists.
TODO make a diagram (omit implementation details for engineering design doc)
Mocktimism is a batteries included OP stack development tool analogous to hardhat and anvil that can be used by OP Stack developers in local and e2e developments.
Local development and test harnesses are vital to all forms of software development. It is a part of the larger "just works" initiative to make existing ethereum tooling work with Optimism.
Developing on the OP Stack has the following challenges:
A good analogy for what Mocktimism is doing is docker-compose for hardhat/anvil. Docker is how one configures a single container. Docker-compose is how one configures multiple containers. Similarly anvil/hardhat are how devs configure a single chain. Mocktimism is how op-chain developers configure multiple chains.
TODO is it clear why these product requirements were chosen
anvil_foo
rpcs to control rollup specific things such as posting a state batch (both manually and automatically)There are also P0 requirements peripheral to the core product
mocktimism feedback
command that allows any user to easily submit feedback about mocktimism including positive feedback--help
cli documentationP1 requirements could get prioritized or cut based on engineering timeline estimates or determined to be worth outsourcing to outside contributors
There are many other product requirements that can be a stretch goal or great additions for outside contributors would be great to add or could be prioritized in a future project should we find them to be a priority.
These requirements though P2 are expected to be targed for in the making of the engineering doc. Anything out of scope will be listed in the out of scope section
Mocktimism does not address the needs of OP Stack component builders such as OP arrogon building a component in the OP stack. The best tool for this job is the existing heavy docker based devnet that can be ran in the monorepo via running make devnet up
Note: this route was strongly considered and worth future exploration.
A better improved optimism devnet can potentially both improve the velocity/quality of core OP stack developers including OP Labs and can consolidate our stack via replacing simple optimism node. This work would also generally show off the modularity of the OP stack.
There is a LOT of overlap between a dockerized modular OP stack devnet and mocktimism. Just like RETH and anvil are two different tools for two different use cases so should be the optimism devnet and mocktimism/op-anvil-hardhat
Mocktimism is not meant to be used in production environments and thus is not a suitable replacement for simple optimism node
Natural follow ups to the optimism version of anvil/hardhat are to add the analogous tooling that compounds even more value onto anvil/hardhat today. While this functionality will exist in Mocktimism it won't be productionized into it's own product as it likely should eventually. The reasons are following:
Though we plan on kicking off partnership efforts this work is not required nor expected to be delivered within the scope of this project for following reasons
e.g. layer zero bridging or connext bridging
Note that should we implement l2 to l2 bridging interface that is used by tools such as connext in the future, mocktimism should also support this functionality via a mocktimism bridge that does l2 to l2 in a lightweight way with an easy way to mock any bridge that plugs into the interface
What we can measure will be easier to nail down after the engineering doc is done. But broadly we want to measure
mocktimism feedback
Successful product should see these numbers trending upwords overtime as more and more folks onboard onto using the product and continue to use it
Mocktimism was identified as
TODO annie to add how this fits into any user personas okrs etc. that product team might require
To understand how mocktimism fits in with other op tooling we simply need to look at how anvil/hardhat fit into existing tooling.
Viem has the concept of test clients. Test clients are very basic wrappers around anvil and hardhat to do things like
Collaboration with Base should happen to include any op-viem specific actions that don't already exist in viem proper to later be upstreamed as a op-viem testing decorator. This has already been discussed with Wilson from base and he is bought in to this idea.
For hackathon participants they need not be blocked by permision issues such as:
Because Mocktimism provides a fully hackable environment where the user can arbitrarily do whatever they want including sending themselves eth or impersonating any account none of these things are issues for hackathon particippants.
To run mocktimism just use the command line. This will look very familiar if you have used anvil in the past.
# To fork a chain registered in the superchain registry simply provide a preset
mocktimism --preset=10 --fork-urls https://example.infura.alchemy.eth-mainnet,https://mainnet.optimism.io
You can now do anything you want on your devnet. Impersonate accounts, deposit from l1 etc.
opViemTestClientL1.impersonateAccount('vitalik.eth')
opViemWalletClientL1.depositETH({
value: BigInt(420),
from: 'vitalik.eth',
to: 'hackathon-user.eth'
})
opViemTestClientL1.mintEth({amount: BigInt(420)})
opViemTestClientL2.impersonateAccount('haydenadams.eth')
opViemWalletClientL2.sendTransaction({
abi: uniswapErc20Abi,
address: uniswapERc20Address,
functionName: 'transfer',
args: {
to: 'hackathon-user.eth',
from: 'haydenadams.eth',
amount: 420
}
})
For better ux many apps such as friend.tech will start offering an onboard-from-l1 experience. In future when superchain bridging is solved they will want to offer an onboard-from-op-chain experience. Doing this breaks the dev experience of single chain apps but not so with Mocktimism.
First op stack developer writes the code to do this cross-chain onboarding experience.
let mintNft
const onboardFromL1 = hasEthOnL1 && !hasEthOnL2
if (onboardFromL1) {
mintNft = () => opViemWalletClientL1.writeContract({
...zoraConfig,
address: zoraNft,
abi: zoraAbi,
functionName: 'mint',
})
} else {
mintNft = () => opViemWalletClientL2.writeContract({
address: zoraNft,
abi: zoraAbi,
functionName: 'mint',
})
}
return (
<button
onclick={mintNft}
>
Mint NFT on zora
</button>
)
Configuring a devnet via command line is convenient but this dev likely wants to use a config file so they can consistently spin up the expected environment
[mocktimism]
preset=zora
forkUrls=["https://mainnet.example.infura.alchemy", "https://zora.example.infura.alchemy"]
forkBlockNumber=90053
automine=true
They can now trivially run this in locally
mocktimism --config ./op.toml
They can also run this in github CI. Note that the more this gets embedded into hardhat and/or anvil in future the more this usage goes from feeling like these tools to literally using their tools
# setup mocktimism.
uses: https://github.com/ethereum-optimism/action-mocktimism
...
# Now just run tests as normally
runs: mocktimism --config ./op.toml & pnpm run test
...
In the fee-estimation project we created tooling for implementing this features and it is currently rolling out to existing tooling such as web3.js ethers.js and viem. We did not however complete the developer story of being able to test these features. In fact, even our @eth-optimism/fee-estimation
package does not have the quality of testing one would want for this feature.
TODO link the github issue of user being unable to test this
Usage is same as the above story
For anticipated use cases the engineering design should be modular enough to support them swapping in a new mocktimism module that follows the correct interface (just like the OP stack)
Hard to know what this looks like before engineering design is complete
TODO this was in the template but I think we can just nuke this section
Our Devx thesis is a major component of creating the best in class developer experience is to make the existing tools that most improve developer experience "just work". Devnets such as Hardhat and Anvil are one of the most important pieces to this puzzle. Mocktimism delivers value to Optimism internally, externally, and compounds via adding value to our other devx efforts such as superchain bridging and op-viem. It is a major foundation to everything we build.
Mocktimism is not only an external need but also an internal need. Examples of internal usage include the following:
The ecopod test setup and development envioronment is split into three use cases which decrease with 1 being the best developer experience and 3 being the worst but necessary.
Mocktimism unifies all three use cases into one with the best features of each.
In the monorepo the OP Devnet is the most common way to run testing but is quite heavy and slow. In certain situations Mocktimism is more practical and we should be able to easily plug in OP anvil or the devnet trivially. Examples include Indexer testing or Optimism ethers-v5 SDK testing and local development.
Support for multichain is pretty new. Foundry only recently added support for testing multichain in foundry testing. Arbitrum and polygon do not have an equivelent product. In short term until these other ecosystems catch up this will be a differentiator.
Anvil does not support OP chains at this moment and thus would not be able to support Mocktimism. This will be unblocked once OP-RETH gets upstreamed into anvil. OP Anvil should be built to plug into anvil in future while providing a reasonable alternative in the meantime
TODO this is out of scope for this doc and should be in eng doc and scoped correctly but will keep it here for now and copy it over later since it is useful
Very rough engineering timeline. This will be explored in more detail in the engineering doc
Mocktimism is such a vital piece that it should follow the entire alpha-beta-GA release schedule. This doc is focused on Mocktimism Beta but we will touch on Mocktimism GA
Mocktimism alpha releases should happen before it's feature complete as soon as it's usable by internal teams
All three of these use cases have such a high need for a tool like Mocktimism that it should be a clear priority for all three if successful. This should require minimal resources to integrate into either local dev flows and/or test flows to be considered successful as Mocktimism is meant to be as easy as spinning up anvil.
Mocktimism should GA in beta so we have the ability to make breaking changes to the API should user feedback require it. Mocktimism is a long term tool and we don't want to start it's stable release on the wrong foot.
Mocktimism beta should have all of Q1 to gather feedback before planning a GA release. GA release should involve working with partners such as Anvil and hardhat to as much as possible embed mocktimism directly into their tooling in the spirit of making existing tools "just work"
Because Mocktimism is such a foundational piece to the OP stack we should be very aware of future work that needs to be prioritized as the OP stack evolves
We should chat with Hardhat and Foundry after initial Mocktimism release to see if they are receptive to further embedding mocktimism into their tooling.
Mocktimism is focused on solving the developer experience of the next 12 months. As OP stack chains become more and more modular and customized it may start to degrade in it's usefulness for chains that are more and more unlike the OP stack. For example, if an OP chain swaps out the EVM for a different execution environment, Mocktimism may not work for this use case. We should monitor this situation and prioritize modularizing Mocktimism along with the OP stack as the need arises such that different mocktimism modules can be swapped in for these use cases. We should do so in the way that creates the least amount of overhead which often will mean running the actual op stack module as is. For our plan to capture the market in 12 months we should not prioritize this just yet however and instead focus in on specifically superchain chains following the law of chains.
Why this is useful can sometimes not be immediately obvious to developers until after than run into an issue. Marketing should highlight "why" this tool exists and why OP stack developers should use it. Recomendations for marketing include the following
Moving this issue to seperate issues
UX - OP
OP Anvil - OP
Low level - Base
Periphial - Outside contributors (P2)
Integration - OP
Questions and goals: