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

docs: add specs #34

Merged
merged 71 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7622eb1
feat: added transactions
Teja2045 Aug 23, 2024
22ed2eb
feat: implement client
Teja2045 Aug 23, 2024
7f50ed8
fix tx issue
PrathyushaLakkireddy Aug 23, 2024
7a4f9d4
feat: pause previous code
Teja2045 Aug 23, 2024
e2571f7
adding client injection
Teja2045 Aug 23, 2024
ac8015a
custom txclient
Teja2045 Aug 23, 2024
003164d
fix: client issue debug
Teja2045 Aug 26, 2024
851e607
new chain client
PrathyushaLakkireddy Aug 26, 2024
b08d48f
debug client init
PrathyushaLakkireddy Aug 26, 2024
220a82e
update create client
PrathyushaLakkireddy Aug 26, 2024
969216f
import mnemonic
PrathyushaLakkireddy Aug 26, 2024
2d420c2
docs
Teja2045 Aug 27, 2024
4d55120
Update README.md
Teja2045 Aug 27, 2024
29c4c58
update docs
Teja2045 Aug 27, 2024
8353539
Merge branch 'docs' of https://github.com/vitwit/avail-da-module into…
Teja2045 Aug 27, 2024
6e9e35c
execute submit tx through client
PrathyushaLakkireddy Aug 27, 2024
df60671
fix keyring issue
PrathyushaLakkireddy Aug 27, 2024
7c02caf
import key
PrathyushaLakkireddy Aug 28, 2024
ddd2e37
fix
PrathyushaLakkireddy Aug 28, 2024
8433f8b
refactor
PrathyushaLakkireddy Aug 28, 2024
1758c27
update submitblob tx
PrathyushaLakkireddy Aug 28, 2024
23c3af7
new query
Teja2045 Aug 29, 2024
b67260a
feat: changes
Teja2045 Aug 29, 2024
bba689d
handle error
PrathyushaLakkireddy Aug 30, 2024
0e383fb
post data to da
PrathyushaLakkireddy Sep 2, 2024
5e46f78
Merge pull request #6 from vitwit/teja/changes
PrathyushaLakkireddy Sep 2, 2024
7db9e26
Merge pull request #7 from vitwit/query
Teja2045 Sep 2, 2024
9964d56
execute update tx after da submission
PrathyushaLakkireddy Sep 2, 2024
2031868
Merge pull request #8 from vitwit/teja/changes
PrathyushaLakkireddy Sep 2, 2024
6262360
fix
PrathyushaLakkireddy Sep 2, 2024
41b3697
query and tx
Teja2045 Sep 2, 2024
859813b
Merge branch 'client-issue' of https://github.com/vitwit/avail-da-mod…
Teja2045 Sep 2, 2024
072db7c
update msg
PrathyushaLakkireddy Sep 3, 2024
05702ff
feat: fixed range errors
Teja2045 Sep 3, 2024
e37a100
Merge branch 'client-issue' of https://github.com/vitwit/avail-da-mod…
Teja2045 Sep 3, 2024
95207e8
feat: vote extensions
Teja2045 Sep 3, 2024
0009f0e
refactor core lgic
Teja2045 Sep 3, 2024
4912fa5
feat: enable vote extensions
Teja2045 Sep 4, 2024
1ecc9f1
feat: enable vote extensions
Teja2045 Sep 4, 2024
4b25aae
feat: fix vote extensions bug
Teja2045 Sep 4, 2024
1c75bf6
feat: fix vote extensions bug
Teja2045 Sep 4, 2024
6a0c398
fix: config script for vote extension height
Teja2045 Sep 5, 2024
62bece9
fix typo
PrathyushaLakkireddy Sep 5, 2024
d67f878
fix conflicts
PrathyushaLakkireddy Sep 5, 2024
529337a
fix client
PrathyushaLakkireddy Sep 5, 2024
fc44ca6
feat: enable vote extensions
Teja2045 Sep 5, 2024
145b9cf
Merge branch 'teja/vote-extensions' of https://github.com/vitwit/avai…
Teja2045 Sep 5, 2024
9a4cd8e
remove deadcode
PrathyushaLakkireddy Sep 5, 2024
bbf6587
fix conflicts
PrathyushaLakkireddy Sep 5, 2024
e7dbea9
feat: light client data verification
Teja2045 Sep 5, 2024
b3d6631
feat: enable light client verification
Teja2045 Sep 6, 2024
8525d83
Merge branch 'teja/vote-extensions' of https://github.com/vitwit/avai…
PrathyushaLakkireddy Sep 6, 2024
1d8b3a1
fix
PrathyushaLakkireddy Sep 6, 2024
ff46ba2
docs: add specs
Teja2045 Sep 10, 2024
f66f825
feat: docs: add abstract
Teja2045 Sep 10, 2024
7700b26
Update README.md
Teja2045 Sep 10, 2024
27819f6
feat: add specs
Teja2045 Sep 10, 2024
42034b9
Merge branch 'teja/specs' of https://github.com/vitwit/avail-da-modul…
Teja2045 Sep 11, 2024
e12dc8b
feat: spec
Teja2045 Sep 11, 2024
be8cd98
feat: update docs
Teja2045 Sep 11, 2024
608439d
docs: update specs
Teja2045 Sep 11, 2024
a4db1ea
Update README.md
Teja2045 Sep 11, 2024
abc5bed
Update README.md
Teja2045 Sep 11, 2024
393cb1c
Update README.md
Teja2045 Sep 11, 2024
111bf0e
nit: small changes
Teja2045 Sep 17, 2024
dd6517b
Merge branch 'main' of https://github.com/vitwit/avail-da-module into…
Teja2045 Sep 17, 2024
3faf8f5
chore: conflicts
Teja2045 Sep 17, 2024
a018696
Update 07_vote_extension.md
Teja2045 Sep 17, 2024
1205901
docs: add requirements
Teja2045 Sep 19, 2024
5a8ed1f
Merge branch 'teja/specs' of https://github.com/vitwit/avail-da-modul…
Teja2045 Sep 19, 2024
ff4dd32
Update README.md
Teja2045 Sep 19, 2024
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
32 changes: 32 additions & 0 deletions specs/01_concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
order: 1
-->

# Concepts

### MaxBlocksLimitForBlob

- The `maxBlocksLimitForBlob` defines the maximum number blobs to be posted to Avail DA at once (in on Avail Transaction).

### Blob Interval

- The `Blob Interval` defines the frequency at which block data is posted to the Avail Network.
- For example, if the interval is set to `5`, data will be submitted at block heights `6`, `11`, `16`, and so on.
- At each of these intervals, the block data from the proven height to min(current height, proven height + maxBlocksLimitForBlob) will be posted.

Example:
For Blob Interval = 5 and Maximum Blocks Limit for Blob = 10 :-

- At height `6` and provenHeight = `0`, blocks from `1` to `5` are posted.

- At height `11` and provenHeight still `0`, blocks from `1` to `10` are posted.

### Relayer

- The `Relayer` acts as the transport layer, responsible for handling requests from the `preBlocker` and facilitating transactions between the Cosmos chain and the Avail DA network.
- It performs key functions such as submitting block data to Avail and updating block status on the Cosmos chain. Every validator in the network is required to run the relayer process.
- Relayer should initialized with a chain account so that the validator can use this account to sign `MsgUpdateStatusBlob` transaction.

### Voting Interval

- The `Voting Interval` is the period before validators verify whether data is truly included in Avail and confirm it with the network using vote extensions.
64 changes: 64 additions & 0 deletions specs/02_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
order: 2
-->

# State

The module keeps state of the following primary objects:

## Blocks Range

Tracks the start and end of the current blocks range being posted to `Avail`.

### Blocks Range Start Height

Stores the start height of the range of current blocks being posted to `Avail`.

It is stored in the state as follows:

- PrevHeightKey `0x07` -> Start Height (Uint64)

### Blocks Range End Height

Stores the end height of the range of current blocks being posted to `Avail`.

It is stored in the state as follows:

- NextHeightKey `0x08` -> End Height (Uint64)

## Blocks Submission Status

Indicates the status of the current blocks submission (`READY`, `PENDING`, `IN_VOTING`, `FAILURE`).

** PENDING ** : Blocks data submission has been initiated and is awaiting confirmation
** IN_VOTING ** : Blocks data has been posted to `Avail` and is now pending validators' verification
** FAILURE ** : Blocks data submission or verification has failed and needs to be resubmitted
** READY ** : blocks data submission is successful; the next set of blocks is ready to be posted

It is stored in the state as follows:

- BlobStatusKey `0x06` : status (uint32)

## Voting End Height

The block height at which the voting for the current blocks should conclude.

It is stored in the state as follows:

- VotingEndHeightKey `0x09` : voting end block height (uint64)

## Avail Height

The Avail block height at which the latest blocks data is made available.

It is stored in the state as follows:

AvailHeightKey `0x0A` : avail block height (uint64)

## Proven Height

The latest block height of the Cosmos chain for which data has been successfully posted to Avail and verified by the network.

It is stored in the state as follows:

ProvenHeightKey `0x02` : proven block height (uint64)
14 changes: 14 additions & 0 deletions specs/03_msg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
order: 3
-->

# Messages

## UpdateBlobStatus

The `MsgUpdateBlobStatus` is used to update the status of blocks submission from `PENDING` to either `IN_VOTING` if the submission is successful, or `FAILURE` if it fails. The responsibility for executing this transaction lies with the individual who originally submitted the blocks data to `Avail` (the proposer of the block where the blocks data submission was initiated).

This message will fail under the following conditions:

If the status is nil, meaning it is neither true nor false.
If the status is true but the Avail height is not a valid number.
35 changes: 35 additions & 0 deletions specs/04_client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
order: 4
-->

# Client

A user can query and interact with the `cada` module using the CLI.


## Query

The `query` commands allows users to query `cada` state.


```sh
simd query cada --help
```

#### Query the Status
The `get-da-status` command enables users to retrieve comprehensive information, including the range of blocks currently being posted to Avail, the current status, the last proven height, the Avail height where the data is made available, and the voting block height by which voting should conclude.

```sh
$ simd query cada get-da-status
```

Output:

```yml
last_blob_voting_ends_at: "23"
proven_height: "0"
range:
from: "1"
to: "5"
status: IN_VOTING
```
59 changes: 59 additions & 0 deletions specs/05_prepare_proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
order: 5
-->

# ProofOfBlobProposalHandler: PrepareProposal Method

This documentation provides an overview of the `PrepareProposal` method within the `ProofOfBlobProposalHandler`. This method is critical for preparing a block proposal by aggregating and injecting vote information into the proposal transactions.

## Method Overview

The `PrepareProposal` method performs the following key steps:

### 1. Proposer Address Initialization

The method starts by setting the `proposerAddress` in the keeper with the address provided in the `RequestPrepareProposal`. This address represents the proposer of the current block. Since the `PrepareProposal` ABCI method is exclusively executed by the block proposer, this address can later be used for posting block data to `Avail`.

```go
h.keeper.proposerAddress = req.ProposerAddress
```


### 2. Vote Aggregation

The method then aggregates votes by calling the `aggregateVotes` function, which takes in the current context and the `LocalLastCommit` from the request. This function collects votes from the last commit, which are essential for the consensus process for da verification.

```go
votes, err := h.aggregateVotes(ctx, req.LocalLastCommit)
if err != nil {
fmt.Println("error while aggregating votes", err)
return nil, err
}
```



### 3. Injection of Aggregated Votes

The method creates a new structure, `StakeWeightedVotes`, to hold the aggregated votes and the extended commit information (`ExtendedCommitInfo`).

```go
injectedVoteExtTx := StakeWeightedVotes{
Votes: votes,
ExtendedCommitInfo: req.LocalLastCommit,
}
bz, err := json.Marshal(injectedVoteExtTx)
if err != nil {
fmt.Println("failed to encode injected vote extension tx", "err", err)
}
```

The serialized vote information (`injectedVoteExtTx`) is appended to the list of proposal transactions, which can be later processed in `PreBlocker` abci method.

```go
proposalTxs = append(proposalTxs, bz)

return &abci.ResponsePrepareProposal{
Txs: proposalTxs,
}, nil
```
83 changes: 83 additions & 0 deletions specs/06_preblocker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!--
order: 6
-->

# ProofOfBlobProposalHandler: PreBlocker Method

This documentation provides a detailed overview of the `PreBlocker` method within the `ProofOfBlobProposalHandler`. This method is crucial for processing vote extensions, updating statuses, and initiating block data submissions to Avail.

## Method Overview

The `PreBlocker` method is responsible for two primary tasks: processing votes from vote extensions to update the status and initiating the submission of blocks' data to Avail. Below is a step-by-step explanation of how this method works.

### 1. Process Votes from Vote Extensions and Update the Status

When the current block height matches the voting end height and the status is `IN_VOTING`, the method processes the voting results and updates the state accordingly.

- **Success Condition:** If the collective voting power exceeds 66%, the status is updated to `READY`, and the `provenHeight` is set to the end of the current block range.
- **Failure Condition:** If the voting power is 66% or less, the status is updated to `FAILURE`.

```go
if len(req.Txs) > 0 && currentHeight == int64(votingEndHeight) && blobStatus == IN_VOTING_STATE {
var injectedVoteExtTx StakeWeightedVotes
if err := json.Unmarshal(req.Txs[0], &injectedVoteExtTx); err != nil {
fmt.Println("preblocker failed to decode injected vote extension tx", "err", err)
} else {
from := k.GetStartHeightFromStore(ctx)
to := k.GetEndHeightFromStore(ctx)

pendingRangeKey := Key(from, to)
votingPower := injectedVoteExtTx.Votes[pendingRangeKey]

if votingPower > 66 { // Voting power is greater than 66%
k.setBlobStatusSuccess(ctx)
} else {
k.SetBlobStatusFailure(ctx)
}
}
}
```

### 2. Initiate Block Data Availability (DA) Submission

If the current block height aligns with a voting interval and the status is either `READY` or `FAILURE`, the method updates the block range and sets the status to `PENDING` for the next round of blocks data submission.

- **Range Calculation:** The pending block range to be submitted is calculated based on the last proven height and the current block height.
- **Status Update:** The status is set to `PENDING` to mark the start of the data submission process.

```go
// The following code is executed at block heights that are multiples of the voteInterval,
// i.e., voteInterval+1, 2*voteInterval+1, 3*voteInterval+1, etc.
if !k.IsValidBlockToPostTODA(uint64(currentBlockHeight)) {
return nil
}

provenHeight := k.GetProvenHeightFromStore(ctx)
fromHeight := provenHeight + 1 // Calculate pending range of blocks to post data
endHeight := min(fromHeight+uint64(k.MaxBlocksForBlob), uint64(ctx.BlockHeight())) // Exclusive range i.e., [fromHeight, endHeight)

sdkCtx := sdk.UnwrapSDKContext(ctx)
ok := k.SetBlobStatusPending(sdkCtx, fromHeight, endHeight-1)
if !ok {
return nil
}
```

### 3. Proposer Submits Block Data to Avail DA

If the node running this method is the proposer of the block, it takes responsibility for submitting the blocks data to Avail DA.

- **Block Data Submission:** The proposer gathers the blocks within the calculated range and posts them to Avail DA.

```go
var blocksToSubmit []int64

for i := fromHeight; i < endHeight; i++ {
blocksToSubmit = append(blocksToSubmit, int64(i))
}

// Only the proposer should execute the following code
if bytes.Equal(req.ProposerAddress, k.proposerAddress) {
k.relayer.PostBlocks(ctx, blocksToSubmit, k.cdc, req.ProposerAddress)
}
```
81 changes: 81 additions & 0 deletions specs/07_vote_extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--
order: 7
-->

# Vote Extensions

Vote extensions are used to propagate arbitrary data across the network without needing to implement transactions that modify the state. Validators utilize vote extensions to verify data availability of a specific range of blocks and update the state of the Cada module accordingly.

This specification details the functionality and purpose of the `ExtendVoteHandler` and `VerifyVoteExtensionHandler` methods within the VoteExtHandler struct. These methods are part of a voting extension process where validators extend their votes based on the availability of data in the Avail DA network.

### ExtendVoteHandler

The `ExtendVoteHandler` method is responsible for generating a `vote extension`. It checks the availability of specific data in the Avail by interacting with an Avail light client. The vote extension is then created based on the outcome of this check.

* The method first begins by retrieving several voting-related parameters, including the start and end heights of the blocks being processed, the Avail block height, and the status of the current blob (data)

```go
from := h.Keeper.GetStartHeightFromStore(ctx)
end := h.Keeper.GetEndHeightFromStore(ctx)

availHeight := h.Keeper.GetAvailHeightFromStore(ctx)

pendingRangeKey := Key(from, end)

blobStatus := h.Keeper.GetBlobStatus(ctx)
currentHeight := ctx.BlockHeight()
voteEndHeight := h.Keeper.GetVotingEndHeightFromStore(ctx)
```

* The method checks if the current height is just before the end of the voting period and if the blob is in the voting state. If not, it generates a basic vote extension indicating that no data was verified

```go
if currentHeight+1 != int64(voteEndHeight) || blobStatus != IN_VOTING_STATE {
voteExt := VoteExtension{
Votes: Votes,
}

// json marshalling
votesBytes, err := json.Marshal(voteExt)
if err != nil {
return nil, fmt.Errorf("failed to marshal vote extension: %w", err)
}
abciResponseVoteExt.VoteExtension = votesBytes
return abciResponseVoteExt, nil
}
```

* If the conditions are met, the method queries the Avail light client to determine if the relevant data is available. The result of this check is recorded in a map
```go
ok, err := h.Keeper.relayer.IsDataAvailable(ctx, from, end, availHeight, "http://localhost:8000")
if ok {
h.logger.Info("submitted data to Avail verified successfully at",
"block_height", availHeight,
)
}


Votes[pendingRangeKey] = ok
```

* The outcome (whether the data was available or not) is marshaled into a vote extension and returned as part of the abci.ResponseExtendVote

```go
voteExt := VoteExtension{
Votes: Votes,
}

votesBytes, err := json.Marshal(voteExt)
if err != nil {
return nil, fmt.Errorf("failed to marshal vote extension: %w", err)
}

return &abci.ResponseExtendVote{
VoteExtension: votesBytes,
}, nil
```

### VerifyVoteExtensionHandler
The `VerifyVoteExtensionHandler` method is responsible for validating the format and content of the vote extensions generated by the `ExtendVoteHandler`.

This method performs a basic validation check on the received vote extension, ensuring it meets the necessary format requirements. It then returns a response indicating whether the vote extension is accepted.
Loading
Loading