-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Layr-Labs/refactor-project
Refactor project
- Loading branch information
Showing
36 changed files
with
1,158 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/resources/kzg/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package core | ||
|
||
import ( | ||
"errors" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// Assignment | ||
|
||
type OperatorId common.Address | ||
|
||
type OperatorIndex uint | ||
|
||
type ChunkIndex uint | ||
|
||
type Assignments struct { | ||
StakeThreshold uint | ||
NumChunks uint | ||
Assignments []Assignment | ||
} | ||
|
||
type Assignment struct { | ||
StartIndex uint | ||
NumChunks uint | ||
} | ||
|
||
func (c *Assignment) GetIndices() []ChunkIndex { | ||
indices := make([]ChunkIndex, c.NumChunks) | ||
for ind := range indices { | ||
indices[ind] = ChunkIndex(c.StartIndex + uint(ind)) | ||
} | ||
return indices | ||
} | ||
|
||
type AssignmentCoordinator interface { | ||
GetAssignments(state OperatorState, quorum QuorumParams) (Assignments, error) | ||
|
||
GetOperatorAssignment(state OperatorState, quorum QuorumParams, id OperatorId) (Assignment, error) | ||
|
||
ValidateConglomerateChunkSize(state OperatorState, headers []BlobHeader, chunkSize uint) error | ||
|
||
GetChunkSize(state OperatorState, header BlobHeader) (uint, error) | ||
} | ||
|
||
// Implementation | ||
|
||
const BIP_MULTIPLIER = 10000 | ||
|
||
var ( | ||
ErrNotFound = errors.New("not found") | ||
) | ||
|
||
func roundUpDivide(a, b *big.Int) *big.Int { | ||
|
||
one := new(big.Int).SetUint64(1) | ||
res := new(big.Int) | ||
res.Sub(a, one) | ||
res.Div(res, b) | ||
res.Add(res, one) | ||
return res | ||
|
||
} | ||
|
||
type BasicAssignmentCoordinator struct { | ||
} | ||
|
||
func getStakeThreshold(state OperatorState, quorum QuorumParams) uint { | ||
|
||
// Get stake threshold | ||
quorumThreshold := new(big.Int).SetUint64(uint64(quorum.QuorumThresholdBPs)) | ||
stakeThreshold := new(big.Int) | ||
stakeThreshold.Mul(quorumThreshold, state.TotalStake.QuorumStakes[quorum.QuorumID]) | ||
stakeThreshold = roundUpDivide(stakeThreshold, new(big.Int).SetUint64(BIP_MULTIPLIER)) | ||
|
||
return uint(stakeThreshold.Uint64()) | ||
} | ||
|
||
func (c *BasicAssignmentCoordinator) GetAssignments(state OperatorState, quorum QuorumParams) (Assignments, error) { | ||
|
||
numOperators := len(state.Operators) | ||
numOperatorsBig := new(big.Int).SetUint64(uint64(numOperators)) | ||
|
||
chunksByOperator := make([]uint, numOperators) | ||
|
||
// Get NumPar | ||
numChunks := uint(0) | ||
totalStakes := state.TotalStake.QuorumStakes[quorum.QuorumID] | ||
for ind, r := range state.Operators { | ||
|
||
m := new(big.Int).Mul(numOperatorsBig, r.QuorumStakes[quorum.QuorumID]) | ||
m = roundUpDivide(m, totalStakes) | ||
|
||
numChunks += uint(m.Uint64()) | ||
chunksByOperator[ind] = uint(m.Uint64()) | ||
} | ||
|
||
currentIndex := uint(0) | ||
assignments := make([]Assignment, numOperators) | ||
|
||
headerHash := [32]byte{} | ||
|
||
for orderedInd := range chunksByOperator { | ||
|
||
// Find the operator that should be at index currentIndex | ||
operatorInd := GetOperatorAtIndex(headerHash, orderedInd, numOperators) | ||
m := chunksByOperator[operatorInd] | ||
|
||
assignments[operatorInd] = Assignment{ | ||
StartIndex: currentIndex, | ||
NumChunks: m, | ||
} | ||
|
||
currentIndex += m | ||
|
||
} | ||
|
||
stakeThreshold := getStakeThreshold(state, quorum) | ||
|
||
return Assignments{ | ||
StakeThreshold: stakeThreshold, | ||
NumChunks: numChunks, | ||
Assignments: assignments, | ||
}, nil | ||
|
||
} | ||
|
||
// Returns the operator at a given index within the reordered sequence. We reorder the sequence | ||
// by letting the reordered_index = operator_index + headerHash. | ||
// Thus, get get the operator at a given reordered_index, we simply reverse: | ||
// operator_index = reordered_index - headerHash | ||
func GetOperatorAtIndex(headerHash [32]byte, index, numOperators int) int { | ||
|
||
indexBig := new(big.Int).SetUint64(uint64(index)) | ||
offset := new(big.Int).SetBytes(headerHash[:]) | ||
|
||
operatorIndex := new(big.Int).Sub(indexBig, offset) | ||
|
||
operatorIndex.Mod(operatorIndex, new(big.Int).SetUint64(uint64(numOperators))) | ||
|
||
return int(operatorIndex.Uint64()) | ||
} | ||
|
||
func (c *BasicAssignmentCoordinator) GetOperatorAssignment(state OperatorState, quorum QuorumParams, id OperatorId) (Assignment, error) { | ||
|
||
assignments, err := c.GetAssignments(state, quorum) | ||
if err != nil { | ||
return Assignment{}, err | ||
} | ||
|
||
operator, ok := state.OperatorMap[id] | ||
if !ok { | ||
return Assignment{}, ErrNotFound | ||
} | ||
|
||
return assignments.Assignments[operator.Index], nil | ||
} | ||
|
||
func (c *BasicAssignmentCoordinator) ValidateConglomerateChunkSize(state OperatorState, headers []BlobHeader, chunkSize uint) error { | ||
return nil | ||
} | ||
|
||
func (c *BasicAssignmentCoordinator) GetChunkSize(state OperatorState, header BlobHeader) ([]uint, error) { | ||
|
||
numOperators := len(state.Operators) | ||
numOperatorsBig := new(big.Int).SetUint64(uint64(numOperators)) | ||
|
||
chunkSizes := make([]uint, len(header.Quorums)) | ||
|
||
for ind, quorum := range header.Quorums { | ||
quorumThreshold := new(big.Int).SetUint64(uint64(quorum.QuorumThresholdBPs)) | ||
adversaryThreshold := new(big.Int).SetUint64(uint64(quorum.AdversaryThresholdBPs)) | ||
|
||
// Get NumSys | ||
numSys := new(big.Int).Sub(quorumThreshold, adversaryThreshold) | ||
numSys.Mul(numSys, numOperatorsBig) | ||
numSys = roundUpDivide(numSys, new(big.Int).SetUint64(BIP_MULTIPLIER)) | ||
|
||
chunkSizes[ind] = uint(header.OrigDataSize)/uint(numSys.Uint64()) + 1 | ||
} | ||
|
||
return chunkSizes, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package domain | ||
package core | ||
|
||
// Encoding | ||
|
||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package indexer | ||
|
||
type ChainData struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mock | ||
|
||
import ( | ||
"github.com/Layr-Labs/eigenda/core" | ||
) | ||
|
||
type ChainDataMock struct { | ||
} | ||
|
||
func (m *ChainDataMock) GetOperatorState(blockNumber uint) (core.OperatorState, error) { | ||
|
||
return core.OperatorState{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
# Organization | ||
|
||
The EigenDA repo is organized as a monorepo, with each project adhering to the "Ben Johnson" project structure style. Within the core project directories (e.g., `core`, `disperser`, `node`, `retriever`, `indexer`), the main interfaces and data types are defined at the root of the project, while implementations are organized by dependency. For instance, the folder `indexer/inmem` contains implementations of the interfaces in `indexer` which use in-memory storage, while `indexer/leveldb` may contain implementations of the same interfaces that use `leveldb`. Mocks of all interfaces in the `indexer` project go in `indexer/mock`. | ||
|
||
The same pattern is used for intra-project and inter-project dependencies. For instance, the folder `indexer/indexer` contains implementations of the interfaces in `core` which depend on the `indexer` project. | ||
|
||
In general, the `core` project contains implementation all of the important business logic responsible for the security guarantees of the EigenDA protocol, while the other projects add the networking layers needed to run the distributed system. | ||
|
||
|
||
# Directory structure | ||
<pre> | ||
┌── <a href="./api">api</a> Protobuf definitions and contract bindings | ||
├── <a href="./contracts">contracts</a> | ||
| ├── <a href="./contracts/eignlayer-contracts">eigenlayer-contracts</a>: Contracts for the EigenLayer restaking platform | ||
┌── <a href="./core">core</a>: Core logic of the EigenDA protocol | ||
├── <a href="./disperser">disperser</a>: Disperser service | ||
├── <a href="./docs">docs</a>: Documentation and specification | ||
── <a href="./indexer">indexer</a>: A simple indexer for efficently tracking chain state and maintaining accumulators | ||
├── <a href="./node">node</a>: DA node service | ||
├── <a href="./pkg">pkg</a> | ||
| ├── <a href="./pkg/encoding">encoding</a>: Core encoding/decoding functionality and multiproof generation | ||
| └── <a href="./pkg/kzg">kzg</a>: kzg libraries | ||
├── <a href="./retriever">retriever</a>: Retriever service | ||
├── <a href="./test">test</a>: Tools for running integration tests | ||
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# BLS Registry |
Oops, something went wrong.