The current actor model hasn't quite worked out how we (I) had hoped.
The core idea was that each account actor would be independent, and could therefore operate on its own with minimal synchronization required. On the surface this maps well to the Miden "model", however this hasn't quite worked out in practice, in part because:
- SQLite requires synchronizing writes and each actor wants to update the notes table.
- Chain data is shared amongst all actors.
- No control over which account gets processed because each actor has equal rights to the permits.
- No control over how many actors are currently active, can only be approximately bounded by activity and idleness.
This has effectively led to a model where we have "actors" which constantly sync with the co-ordinator after and before every action. This results in actor state changes being hard to get quite correct, with some sprawling and inadvertent coupling of the state model code. Making this bug-free is and will remain a challenge.
This is becoming more of a concern given the official faucet will be a network account; as will several other core network components e.g. AggLayer. Having the ntxb code be simple and effective therefore has a strong derisking component to it.
Suggested route
We already have a core event loop, which handles chain sync and database writes. I think we should retain this, but instead of spawning long lived actors, it could be responsible for spawning concurrent account transaction attempts.
Each attempt would only for as long as a single transaction. This would allow:
- Note failures return directly to the core loop where we can update the database.
- Allow prioritizing certain accounts e.g. the native faucet.
- Managing number of "live" accounts.
This also means we would have less memory usage because less accounts are simply idling in-memory - we should consider simplifying our data model as well by adding a cache layer in-front of the database.
The current actor model hasn't quite worked out how we (I) had hoped.
The core idea was that each account actor would be independent, and could therefore operate on its own with minimal synchronization required. On the surface this maps well to the Miden "model", however this hasn't quite worked out in practice, in part because:
This has effectively led to a model where we have "actors" which constantly sync with the co-ordinator after and before every action. This results in actor state changes being hard to get quite correct, with some sprawling and inadvertent coupling of the state model code. Making this bug-free is and will remain a challenge.
This is becoming more of a concern given the official faucet will be a network account; as will several other core network components e.g. AggLayer. Having the ntxb code be simple and effective therefore has a strong derisking component to it.
Suggested route
We already have a core event loop, which handles chain sync and database writes. I think we should retain this, but instead of spawning long lived actors, it could be responsible for spawning concurrent account transaction attempts.
Each attempt would only for as long as a single transaction. This would allow:
This also means we would have less memory usage because less accounts are simply idling in-memory - we should consider simplifying our data model as well by adding a cache layer in-front of the database.