Skip to content

Commit

Permalink
Added docs for state services
Browse files Browse the repository at this point in the history
  • Loading branch information
rpanic committed Oct 27, 2023
1 parent 185b591 commit 0e2e1e5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/sequencer/src/state/StateServices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## State Service Architecture

The state services are built using a abstraction stack, where every service that is below the root is based on the parent.
All of this services have the ability to base off one another to allow for diff-based changes.
You can think of it a bit like git, where every commit is only the diff between the parents state and the next state.

*But*, in this architecture there is no such thing as branching, it is strictly linear and behaves almost like a traditional stack.
That means, for example, that you shouldn't change state in a service that has one or more children, as these changes might not get reflected instantly in the children's perception of state.

Now I will go over all the different kinds of stateservices

Btw all of this also applies to to merkle tree stores

### AsyncStateService

This is always the base for the whole stack and is meant to be implemented by the actual persistence layer.
That means primarily the DB (but is also implemented by the in-memory state service).
It's functions are async-based in order to enable external DB APIs

### CachedStateService

It receives a AsyncStateService as a parent and can build on top of it.
It "caches" in the sense that it can preload state entries from the parent (asynchronously) and then lets circuits among others perform synchronous operations on them.
It additionally caches write operations that can then later be merged back into the parent (or thrown away).

### SyncCachedStateService

These are the same as CachedStateService, with the difference that it accepts a CachedStateService and requires no preloading.

### PreFilledStateService

Pre-filled with only a part of the data needed. This is mostly used in Task implementation where all state needed is passed as args.

0 comments on commit 0e2e1e5

Please sign in to comment.