da

package
v0.0.0-...-79e88c3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 20 Imported by: 0

README

Data Availability Layer

This package provides a data availability layer using EigenDA for the ChaosChain Launchpad.

Overview

The DA layer allows storing and retrieving data on EigenDA, a decentralized data availability network. It uses NATS for event broadcasting when data is stored or retrieved.

Requirements

  1. Go 1.21 or higher
  2. NATS server running (default: localhost:4222)
  3. EigenDA authentication private key

Setup

1. Set Environment Variables
# Required: Your EigenDA authentication private key
export EIGENDA_AUTH_PK="your_private_key_here"

# Optional: NATS URL (defaults to localhost:4222)
export NATS_URL="nats://localhost:4222"

Generate your private key by running generate_key.go

2. Install Dependencies
go mod tidy

Testing

Manual Testing

To manually test the EigenDA integration:

# Set environment variables
export EIGENDA_AUTH_PK="your_private_key_here"
export RUN_EIGENDA_TEST=true

# Run the test
go test -v -run TestEigenDAIntegration ./da_layer
What the Test Does
  1. Creates a new DataAvailabilityService
  2. Sets up NATS subscriptions to listen for data events
  3. Stores test data on EigenDA
  4. Waits for the "data stored" event
  5. Retrieves the data from EigenDA
  6. Verifies the retrieved data matches what was stored
  7. Waits for the "data retrieved" event
Expected Output

If everything is working correctly, you should see output similar to:

=== RUN   TestEigenDAIntegration
Setting up test environment for EigenDA tests
Storing data in EigenDA...
Current Blob Status: {
  "status":  "PROCESSING",
  "info":  {}
}
...
Current Blob Status: {
  "status":  "CONFIRMED",
  "info":  {
    "blobHeader": {...},
    "blobVerificationProof": {...}
  }
}
Data stored with ID: f9c979e84c19929dcdfc0c4f7ba65dc3ab47276e6d910480ed2d84ccbd4b8a3d...
Event received: Data stored with ID: f9c979e84c19929dcdfc0c4f7ba65dc3ab47276e6d910480ed2d84ccbd4b8a3d...
Received data stored event for ID: f9c979e84c19929dcdfc0c4f7ba65dc3ab47276e6d910480ed2d84ccbd4b8a3d...
Retrieving data from EigenDA...
Retrieved data: map[message:Hello EigenDA with NATS! testId:test-1234567890 timestamp:1234567890]
Event received: Data retrieved with ID: f9c979e84c19929dcdfc0c4f7ba65dc3ab47276e6d910480ed2d84ccbd4b8a3d...
Received data retrieved event
EigenDA integration test completed successfully!
--- PASS: TestEigenDAIntegration (120.45s)
PASS

Troubleshooting

Common Issues
  1. Authentication Error: Make sure your EIGENDA_AUTH_PK is correctly set and valid.

  2. NATS Connection Error: Ensure NATS server is running and accessible.

  3. Timeout Waiting for Blob Status: EigenDA can sometimes take longer than expected to process blobs. Try increasing the EIGENDA_MAX_WAIT_TIME constant in the code.

  4. Retrieval Error: If you can store but not retrieve data, check that the blob has been fully finalized on EigenDA before attempting retrieval.

Logs

The service outputs detailed logs about blob status during the dispersal process. These can be helpful for diagnosing issues.

Documentation

Index

Constants

View Source
const (
	MASTER_INDEX_FILE = "eigenda_master_index.json"
	CONFIG_DIR        = ".chaoschain"
)

Constants for local storage

View Source
const (
	// Updated EigenDA URLs for Holesky
	MAX_RETRIES = 3

	// NATS subjects
	SUBJECT_DATA_STORED    = "data.stored"
	SUBJECT_DATA_RETRIEVED = "data.retrieved"

	// EigenDA configuration
	EIGENDA_HOST            = "disperser-holesky.eigenda.xyz"
	EIGENDA_PORT            = "443"
	EIGENDA_REQUEST_TIMEOUT = 30 * time.Second
	EIGENDA_POLL_INTERVAL   = 5 * time.Second
	EIGENDA_MAX_WAIT_TIME   = 30 * time.Minute

	// EigenDA API endpoints
	EIGENDA_DISPERSE_URL = "https://disperser-holesky.eigenda.xyz:443/v1/blob"
	EIGENDA_STATUS_URL   = "https://disperser-holesky.eigenda.xyz:443/v1/blob/status"
	EIGENDA_RETRIEVE_URL = "https://disperser-holesky.eigenda.xyz:443/v1/blob"
)

Variables

This section is empty.

Functions

func CloseGlobalDAService

func CloseGlobalDAService()

CloseGlobalDAService closes the global DataAvailabilityService instance

func GenerateKey

func GenerateKey() string

func InitializeMasterIndex

func InitializeMasterIndex() error

InitializeMasterIndex loads the master index from EigenDA or creates a new one

func ListOffchainData

func ListOffchainData(chainID string) ([]string, error)

ListOffchainData lists all off-chain data for a specific chain. This is a placeholder function that would need to be implemented with a proper indexing mechanism, as EigenDA doesn't provide a native way to list or query data.

func SaveOffchainData

func SaveOffchainData(data OffchainData) (string, error)

SaveOffchainData stores off-chain data into EigenDA using the global DataAvailabilityService. It marshals the off-chain data into a map and then stores it via StoreData.

func SetupGlobalDAService

func SetupGlobalDAService(natsURL string) error

SetupGlobalDAService initializes the global DataAvailabilityService instance

func StoreBlobReference

func StoreBlobReference(ref BlobReference) error

StoreBlobReference stores a reference to an EigenDA blob

Types

type BlobReference

type BlobReference struct {
	BlobID      string `json:"blobId"`      // EigenDA blob ID
	ChainID     string `json:"chainId"`     // Chain ID
	BlockHash   string `json:"blockHash"`   // Block hash (used as thread ID)
	BlockHeight int    `json:"blockHeight"` // Block height
	Timestamp   int64  `json:"timestamp"`   // When the blob was stored
	Outcome     string `json:"outcome"`     // Outcome of the consensus (accepted/rejected)
}

BlobReference stores the mapping between EigenDA blob ID, chain ID, and block information

func GetBlobReferenceByBlobID

func GetBlobReferenceByBlobID(blobID string) (BlobReference, bool)

GetBlobReferenceByBlobID returns the blob reference for a specific blob ID

func GetBlobReferenceByBlockHash

func GetBlobReferenceByBlockHash(chainID, blockHash string) (BlobReference, bool)

GetBlobReferenceByBlockHash returns the blob reference for a specific block hash

func GetBlobReferenceByHeight

func GetBlobReferenceByHeight(chainID string, height int) (BlobReference, bool)

GetBlobReferenceByHeight returns the blob reference for a specific block height

func GetBlobReferencesForChain

func GetBlobReferencesForChain(chainID string) []BlobReference

GetBlobReferencesForChain returns all blob references for a specific chain

type ChainIndex

type ChainIndex struct {
	BlobReferences map[string]BlobReference `json:"blobReferences"` // blockHash -> BlobReference
	LastUpdated    int64                    `json:"lastUpdated"`    // Timestamp of last update
}

ChainIndex represents the index of blob references for a specific chain

type DataAvailabilityService

type DataAvailabilityService struct {
	// contains filtered or unexported fields
}

DataAvailabilityService handles interactions with EigenDA

var (
	GlobalDAService *DataAvailabilityService
)

Global instance of the DataAvailabilityService

func GetGlobalDAService

func GetGlobalDAService() *DataAvailabilityService

GetGlobalDAService returns the global DataAvailabilityService instance

func NewDataAvailabilityService

func NewDataAvailabilityService(natsURL string) (*DataAvailabilityService, error)

NewDataAvailabilityService creates a new DA service

func (*DataAvailabilityService) GetBlobStatus

func (s *DataAvailabilityService) GetBlobStatus(dataID string) (interface{}, error)

GetBlobStatus retrieves the current status of a blob from EigenDA

func (*DataAvailabilityService) RetrieveData

func (s *DataAvailabilityService) RetrieveData(dataID string) (map[string]interface{}, error)

RetrieveData retrieves data from EigenDA using dataID

func (*DataAvailabilityService) SetupSubscriptions

func (s *DataAvailabilityService) SetupSubscriptions(dataStoredHandler, dataRetrievedHandler func(dataID string)) error

SetupSubscriptions sets up NATS subscriptions for DA events

func (*DataAvailabilityService) StoreData

func (s *DataAvailabilityService) StoreData(data map[string]interface{}) (string, error)

StoreData stores data in EigenDA and publishes dataID to NATS

type MasterIndex

type MasterIndex struct {
	ChainIndices map[string]ChainIndex `json:"chainIndices"` // chainID -> ChainIndex
	LastUpdated  int64                 `json:"lastUpdated"`  // Timestamp of last update
}

MasterIndex represents the master index of all blob references

type MasterIndexConfig

type MasterIndexConfig struct {
	MasterIndexID string `json:"masterIndexId"`
	LastUpdated   int64  `json:"lastUpdated"`
}

MasterIndexConfig stores the configuration for the master index

type OffchainData

type OffchainData struct {
	ChainID         string                 `json:"chainId"`
	BlockHash       string                 `json:"blockHash"`   // Block hash (used as thread ID)
	BlockHeight     int                    `json:"blockHeight"` // Block height
	Discussions     []consensus.Discussion `json:"discussions"`
	Votes           []Vote                 `json:"votes"`
	Outcome         string                 `json:"outcome"`
	AgentIdentities map[string]string      `json:"agentIdentities"`
	Timestamp       int64                  `json:"timestamp"` // When the data was created
}

OffchainData represents the off-chain data stored in EigenDA for a specific chain.

func GetOffchainData

func GetOffchainData(dataID string) (*OffchainData, error)

GetOffchainData retrieves off-chain data from EigenDA using the global DataAvailabilityService. It takes a dataID and returns the corresponding OffchainData.

type Vote

type Vote struct {
	AgentID      string `json:"agentId"`
	VoteDecision string `json:"voteDecision"`
	Timestamp    int64  `json:"timestamp"`
}

Vote represents an agent's vote off-chain.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL