Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed Feb 1, 2024
1 parent 2f42cf3 commit 0e7b63b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions core/src/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ limited in size, through a mechanism we will defined later on.
If state is not used then all the processing will happen in parallel until it reaches the chain head.

## State
State refers to intermediate state between blocks (think the state for fold operations). Only the
latest data is kept and it is only queryable from the pre-indexer, subgraphs and graphql don't have
access to it.
State refers to intermediate state between blocks (think the state for fold operations). It is only
queryable from the pre-indexer, subgraphs and graphql don't have access to it.

In order to support reverts, it is necessary to be able to retrieve a previous state. State should
store a log of delta operations as well as a snapshot every TBD amount of blocks. Retrieving an old state
will be possible by getting the latest snapshot and applying the delta operations between that block and
the block it is needed at.

This state is necessary so that users can keep track of things like created contracts on ethereum.

Expand Down
8 changes: 7 additions & 1 deletion core/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ mod uniswap;

pub type Item = Box<[u8]>;

enum StateOperation {
Set(Key, Item),
Unset(Key, Item),
}

#[derive(Default)]
pub struct State {
items: HashMap<Box<[u8]>, Item>,
tags: HashMap<&'static str, Vec<Box<[u8]>>>,
deltas: Vec<StateOperation>,
}

#[derive(Hash)]
Expand Down Expand Up @@ -168,7 +174,7 @@ impl IndexWorker {
.transform(EncodedBlock(data), std::mem::take(&mut previous_state));
previous_state = state;
ctx.store
.set(block_ptr.number, &previous_state, triggers)
.set_with_state(block_ptr.number, &previous_state, triggers)
.await?;

cursor
Expand Down

0 comments on commit 0e7b63b

Please sign in to comment.