Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ADR002 to document the storage #57

Merged
merged 3 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions doc/adr002-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ADR002: Storage Layout

**Author:** Igor Konnov, 2024

This ADR discusses the simple layout of the Soroban transactions that are
fetched from a Stellar network.

Our goals are:

- Store contract calls retrieved from the Horizon API, see [storage.ts][].
- Access calls indendently for verification.
- Tag calls as `stored`, `verified`, `failed`, etc.

To keep things simple in the activation stage, we are simply using the
filesystem instead of a fully-featured database. This is sufficient to
demonstrate our idea. When the users expect a storage that its durable,
consistent, fail-free, etc., we would have to implement the storage with a solid
database library.

In the rest of this document, we refer to the root of the storage directory as
`${STOR}`. We expect the user to provide the Solarkraft commands with the
root directory. By default, `${STOR}` would point to
`$HOME/.solarkraft/.stor`.

## 1. Storing extracted calls

We have the following requirements to the storage:

- It should support contract calls (from transactions) that are extracted for
different contracts.

- It should be relatively easy to order these transactions, e.g., by ledger height.

- Transactions that happen in the same block should not collide.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean by "collide"? In the database sense, have the same primary key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, basically, the block number cannot be used as the unique identifier



Given all these requirements, we store every contract call in its own file called:

```
${STOR}/${contractId}/${height}/entry-${txHash}.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

So you want to say anything about the content format of these files?

Even if it's just pointing to the implementation, I think it would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment

```

The values `${contractId}`, `${height}`, `${txHash}` are the values of the
fields that are defined in [storage.ts][].

The file is a JSON serialization of [ContractCallEntry][]. Some care is required
to serialize big integers, we use [json-bigint][]. Additionally, we serialized
`OrderedMap` as an array.

## 2. Storing verification results

The verification results are to be stored in a file called:

```
${STOR}/${contractId}/${height}/verification-${txHash}.json
```

The exact format of this file is to be defined later.



[storage.ts]: https://github.com/freespek/solarkraft/blob/main/solarkraft/src/fetcher/storage.ts
[ContractCallEntry]: https://github.com/freespek/solarkraft/blob/38d57fd51082feab9215a77c555bdccdc961aa26/solarkraft/src/fetcher/storage.ts#L23
[json-bigint]: https://www.npmjs.com/package/@types/json-bigint
Loading