Skip to content

Commit

Permalink
Sqlite State Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeuchi authored and ppedziwiatr committed May 12, 2023
1 parent 858fabc commit 0b0cb43
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions warp-academy-docs/docs/sdk/advanced/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,59 @@ const warp = WarpFactory
dbLocation: `./cache/warp/src`
}));
```

### SQLite cache

Warp Contracts implementation of the `BasicSortKeyCache` using the [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3) database.

:::tip
warp-contracts-sqlite uses incremental auto vacuum mode to reduce the size of the storage.
:::

One of the disadvantages of LMDB is its size.
Although Warp LmdbCache implements data pruning to reduce the number of stored entries,
the LMDB storage only increases in size over time.

Since state caching is crucial in D.R.E. nodes, state cache efficiency and size is very important.
These factors have driven us to create yet another cache implementation. This time with a help of better-sqlite3.

This implementation uses:
- [Incremental](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) auto vacuum mode, which means that the sqlite will reuse space marked as deleted,
- [WAL mode](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md), which greatly improves concurrent read and writes performance.

#### Installation
:::caution
SQLite based cache is compatible only with Node.js env.
:::

```
yarn add warp-contracts-sqlite
```

#### Custom options
LmdbCache constructor accepts a second param with custom configuration.

| Option | Required | Description |
|-----------------------|------------|---------------------------------------------------------------------------------------------------------------------------------------|
| maxEntriesPerContract | false | Maximum number of interactions stored per contract id - above this threshold adding another entry triggers removing old interactions. |


#### Usage

```typescript
const warp = WarpFactory.forMainnet().useStateCache(
new SqliteContractCache(
{
...defaultCacheOptions,
dbLocation: `./cache/warp/sqlite/state`
},
{
maxEntriesPerContract: 20
}
)
)
```

:::info
Requires `warp-contracts` SDK ver. min. 1.4.7
:::

4 comments on commit 0b0cb43

@vercel
Copy link

@vercel vercel bot commented on 0b0cb43 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

arditmsg – ./warp-academy-ardit/final/app

arditmsg.vercel.app
arditmsg-git-main-redstone-finance.vercel.app
arditmsg-redstone-finance.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0b0cb43 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

redstone-academy-pst – ./warp-academy-pst/final

pst.redstone.academy
redstone-academy-pst-redstone-finance.vercel.app
redstone-academy-pst-git-main-redstone-finance.vercel.app
pst.academy.warp.cc

@vercel
Copy link

@vercel vercel bot commented on 0b0cb43 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

metamask – ./warp-academy-ardit/final/metamask-app

metamask-redstone-finance.vercel.app
evm-metamask.vercel.app
metamask-git-main-redstone-finance.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0b0cb43 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

academy – ./warp-academy-docs

academy-git-main-redstone-finance.vercel.app
academy-redstone-finance.vercel.app
academy.warp.cc
docs.warp.cc

Please sign in to comment.