Each Dria knowledge is a smart-contract on Arweave, which serves the knowledge on permaweb via a key-value interface. To download them, we require HollowDB client, which is a Node package. Here we have a Fastify server that acts as an API for HollowDB, which we primarily use to download & unbundle the values for Dria HNSW to use.
Install the packages:
yarn install
To run the server, you need to provide a contract ID along with a RocksDB path:
CONTRACT_ID=<contract-id> ROCKSDB_PATH="path/do/rocksdb" yarn start
HollowDB PAI is available as a container:
docker pull firstbatch/dria-hollowdb
In both cases, you will need a Redis container running at the URL defined by REDIS_URL
environment variable.
There are several environment variables to configure the server. You can provide them within the command line, or via .env
file. An example is given here.
-
REDIS_URL=<redis-url>
You need a Redis server running before you start the server, the URL to the server can be provided with aREDIS_URL
environment variable. The connection URL defaults toredis://default:redispw@localhost:6379
. -
WARP_LOG_LEVEL=<log-level>
By default Warp will log atinfo
level, but you can change it via theWARP_LOG_LEVEL
environment variable. Options are the known levels ofdebug
,error
,fatal
,info
,none
,silly
,trace
andwarn
. -
USE_BUNDLR=<true/false>
You can treat the values as transaction ids ifUSE_BUNDLR
environment variable is set to betrue
. When this is the case,REFRESH
will actually fetch the uploaded data and download it to Redis.
Warning
Uploading to Bundlr via PUT
or PUT_MANY
is not yet implemented.
-
USE_HTX=<true/false>
When we haveUSE_BUNDLR=true
we treat the stored values as transaction ids; however, HollowDB may have an alternative approach where values are stored ashash.txid
(due to this implementation). To comply with this approach, setUSE_HTX=true
. -
BUNDLR_FBS=<number>
When using Bundlr, downloading values from Arweave cannot be done in a hugePromise.all
, as it causes timeouts. We instead download values in batches, defaulting to 40 values per batch. To override the batch size, you can provide an integer value to this variable.
HollowDB API exposes the following endpoints:
- GET
/state
- POST
/get
- POST
/getRaw
- POST
/getMany
- POST
/getManyRaw
- POST
put
- POST
putMany
- POST
update
- POST
remove
- POST
refresh
- POST
clear
interface {
key: string
}
// response body
interface {
value: any
}
Returns the value at the given key.
// response body
interface {
value: any
}
Returns the value at the given key
, directly from the cache layer & without involving Warp or Arweave.
interface {
keys: string[]
}
// response body
interface {
values: any[]
}
Returns the values at the given keys
.
interface {
keys: string[]
}
// response body
interface {
values: any[]
}
Returns the values at the given keys
, reads directly from the storage.
This has the advantage of not being bound to the interaction size limit, however, the user must check that the data is fresh with their own methods.
Furthermore, you must make a call to REFRESH
before using this endpoint, and subsequent calls to REFRESH
will update the data with the new on-chain values.
interface {
key: string,
value: any
}
Puts value
at the given key
. The key must not exist already, or it must have null
stored at it.
interface {
keys: string[],
values: any[]
}
Updates given keys
with the provided values
. No key must exist already in the database.
interface {
key: string,
value: any,
proof?: object
}
Updates a key
with the provided value
and an optional proof
.
interface {
key: string,
proof?: object
}
Removes the value at key
, along with an optional proof
.
Syncs & fetches the latest contract state, and returns it.
Syncs & fetches the latest state and stores the latest sort key for each key in the database. Returns the number of keys refreshed for diagnostic purposes.
interface {
keys?: string[]
}
Clears the contents for given keys
with respect to the values written by REFRESH
endpoint. One might want to refresh some keys again, without flushing the entire database, so that is the purpose of this endpoint. Returns the number of keys cleared for diagnostic purposes.
Tip
If no keys
are given to the CLEAR
endpoint (i.e. keys = undefined
) then this will clear all keys.
We have tests that roll a local Arweave and run tests on them with the micro server in the middle.
Note
You need a Redis server running in the background for the tests to work.
To run tests, do:
yarn test