-
Notifications
You must be signed in to change notification settings - Fork 129
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
Fluffy and the EVM #1162
Comments
Ideally, fluffy just uses the EVMC API ( https://github.com/status-im/nim-evmc ) so that it's easier to spec alternative Portal Network implementations. |
This task is no longer required because the current plan is to connect the Fluffy state bridge to a running execution client. This would be required to keep up with the latest state changes for the latest blocks and therefore we don't need to run the EVM inside the Fluffy bridge. We will likely call |
While not core functionality of a pure Portal node, when we want to build a light client with full EL JSON-RPC API, we will need the EVM to execute certain txs (e.g. for estimateGas)? |
Yes, you are right we would need the EVM for the following endpoints which are listed as part of the portal network spec: Thanks for the reminder. I was thinking about the state bridge when closing this task. I'm going to reopen it with the goal of including the Nimbus EVM in Fluffy at some point. |
Ideally we should pull out the Nimbus EVM into a separate library that we can then import into Fluffy either directly or using nim-evmc. The database layer would need to be swapped out in order to get the data from the portal state network. In order to do this, I believe we should aim to make the Nimbus EVM more modular. I would suggest that we decouple the account ledger and database from the layers above by defining interfaces between them. We could then create another implementation of the state or database layer for the portal network. For example we could have interfaces: In Nimbus we have something like this: After creating interfaces Fluffy look something like: Revm has a modular architecture which we could get some inspiration from. |
One design consideration we need to think about as we integrate the EVM into Fluffy is what database should we use for the temporary state that may be created when writing to contract storage while executing a transaction. At present we only need to implement eth_call and eth_estimateGas which are read only and therefore should throw away any temporary state changes but even so the evm will still need to store temporary updates in a db. Perhaps we should use an in memory database for this purpose to avoid pulling in RocksDb as is used in Nimbus. |
+1 on evmc as a starting point
technically, this already happens - the way eth1 works is that it collects all changes in memory before writing to disk, before a final |
What would be the benefit of using evmc? My understanding is that it would allow us to link in different EVMs into Fluffy or Nimbus if we wanted to but I'm not sure that helps us much with this task because Fluffy will likely need a special purpose EVM that reads state from the portal network.
Yes true but if I was to pull in the Nimbus EVM as implemented then I would need to pull RocksDb into Fluffy which isn't ideal. We already use Sqlite and we would like to keep Fluffy as light weight as possible. For this reason I'll likely need to introduce some interface or similar into the Nimbus EVM (for now just in a feature branch) so that we can configure it to not use RocksDb and instead fetch state data from portal network but also write temporary state changes in memory somehow. |
it does more or less what you want, which is to isolate the nimbus evm from its database - it's also implemented as a compile-time flag which means that it doesn't burden nimbus with abstraction / interface cost at runtime - each interface and abstraction has an associated cost and if there's one thing nimbus has right now, it's too many layers of abstraction and interfaces that don't have a specific reason to exist. That said, there's something called a memory backend for nimbus which also disables the rocksdb backend already - look for |
Thanks, I see what you mean now and I agree this is a good idea. I agree about the abstractions as well and I think it's better that we don't add more if not needed. Using the evmc host interface in Fluffy we should be able to return data from portal using synchronous calls as the API is not an async API. This will be a good starting point but I guess at some point we might want to update the Nimbus EVM to execute in an async way perhaps using another compile time flag so that state access over the portal network don't block. For example if we have a transaction that accesses multiple state values we should be able to do this concurrently if we wrap the evmc host interface calls to make them async. |
I've run into some issues while trying to use the Nimbus EVM via the EVMC API. It appears to me that even when the evmc_enabled flag is set, the Nimbus EVM isn't implemented correctly in a way where it only accesses the standard EVMC interfaces which means (if I'm not mistaken) I can't use it as planned in it's current state. For example in evmc_vm_glue.nim there is an |
Hmm, yes, it has this big todo written there also: https://github.com/status-im/nimbus-eth1/blob/master/nimbus/transaction/evmc_vm_glue.nim#L25-L26 Can you make an issue regarding this? Seems our implementation is incomplete. All I found was this issue regarding testing: #475 |
Yes I noticed that as well. The other even bigger problem is that our EVM doesn't always use the EVMC interface when accessing the database is many places so it appears that fixing it would be a decent amount of work. I discussed this with the team in the weekly meeting yesterday and the conclusion was that for now we don't want to make changes to the Nimbus EVM until we release Nimbus to mainnet. With that in mind my current plan is to use evmone via the EVMC interface in Fluffy. In the future we can update the Nimbus EVM to fully follow the EVMC spec and then swap out evmone for Nimbus EVM in Fluffy. Sure, I'll create a new issue describing the remaining work to be done on EVMC for Nimbus. |
New issue created, see here: #2803 |
I've found a useful tool in the evmone project which can be used to test a EVMC EVM. I've tested it on both evmone and Nimbus EVM.
When I run it against the nimbus evm I get this:
This is to be expected I guess because the Nimbus EVM doesn't yet support being loaded as a stand alone EVMC EVM. |
I've made some progress on this one. Both the history network and state network are required to be enabled as well as the evm. Note that this is just a proof of concept so far and the code still needs to be refined and improved a bit more. It works by first looking up the block header via the history network, then the state root is passed into the PortalEvmState type which is used to look up each piece of state on demand from the portal state network while the evm is executing the bytecode. The evm runs fully in memory and is ephemeral for that reason. For each transaction/call each piece of state is only fetched from the state network once, after which the in memory value is used and updated. The existing content cache which is already running in Fluffy also provides some nice performance benefits for This current implementation uses the EVMC interface and for now we are using evmone. The remaining work is:
|
While a functional state network in Portal is still far away, we can already investigate how easy it is to link the EVM code to Fluffy.
This task is about investigating how convenient it is to add current EVM functionality to Fluffy.
No input needs to come from the network (there isn't one), it is rather to see of we can just drop in the EVM in Fluffy in its current state.
The text was updated successfully, but these errors were encountered: