Skip to content

Commit

Permalink
Feat/docker for lc (#14)
Browse files Browse the repository at this point in the history
* initial commit

* update

* Add resubscription
  • Loading branch information
tarassh authored Aug 30, 2024
1 parent 6d6dcc6 commit 5ea4848
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ settings.json
c_cpp_properties.json
*.log

gcp-credentials.json
# disable for testign
# gcp-credentials.json
65 changes: 65 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Use an official Golang image as a base image
FROM golang:1.22-alpine AS builder

# Install necessary dependencies
RUN apk add --no-cache git make bash curl

# Set the working directory for IPFS Kubo
WORKDIR /go/src/ipfs-kubo

# Clone the IPFS Kubo repository
RUN git clone https://github.com/ipfs/kubo.git .

# Checkout the specific version v0.29.0
RUN git checkout v0.29.0

# Build IPFS Kubo
RUN make build

# Set the working directory for the light-client
WORKDIR /go/src/light-client

RUN apk add --no-cache gcc musl-dev

# Clone the light-client repository
COPY . .

# Initialize submodules
RUN git submodule update --init --recursive

# Build the light-client
RUN make build-light

# Create a minimal runtime image
FROM alpine:latest

# Copy the built IPFS Kubo binary
COPY --from=builder /go/src/ipfs-kubo/cmd/ipfs/ipfs /usr/local/bin/ipfs

# Copy the built light-client binary
COPY --from=builder /go/src/light-client/bin/light-client /usr/local/bin/light-client

# Copy the GCP credentials file
COPY --from=builder /go/src/light-client/test/data/gcp-credentials.json /gcp-credentials.json

# Copy trusted setup files
COPY --from=builder /go/src/light-client/test/data/trusted_setup.txt /root/.pinner/trusted_setup.txt

# Expose the default IPFS port
EXPOSE 4001

# Expose the default IPFS API port
EXPOSE 5001

# Expose the default IPFS Gateway port
EXPOSE 8080

# Initialize IPFS
RUN ipfs init

# Copy the entrypoint script
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Set the entrypoint for the container
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
6 changes: 3 additions & 3 deletions STRATEGY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sampling Strategy for Data Availability Sampling
# Sampling Strategy for Data Availability

## Background

Expand All @@ -8,7 +8,7 @@ The data availability sampling strategy is designed to ensure that data remains

In this system, 1D erasure coding is applied to data organized into rows, where each row is extended to 128 cells. The first 64 cells contain the original data, while the remaining 64 cells store redundancy generated through the erasure coding process. This structure allows for the recovery of the original data even if some cells are lost or corrupted. However, to achieve a high level of confidence in data integrity—such as 99%—it is crucial to test every row. By verifying each row individually, we ensure that the erasure coding effectively protects the data and that the system maintains its reliability across all rows.

### Samples number estimation
### Samples number estimations

$$
S \geq R - R \times \left(1 - C\right)^{\frac{1}{E}}
Expand Down Expand Up @@ -44,4 +44,4 @@ $$

This result indicates that you would need to sample at least 8.89 cells per row to achieve a 99% confidence level that at least 64 of the 128 cells are intact, ensuring that the row can be fully recovered.

If to put the results in percentage perspective, you would need to sample at least 7% of the cells in each row to achieve a 99% confidence level that the row can be fully recovered. The value remains the same for all rows, as the erasure coding process is consistent across the data.
If to put the results in percentage perspective, you would need to sample at least 7% of the cells in each row to achieve a 99% confidence level that the row can be fully recovered. The value remains the same for all rows, as the erasure coding process is consistent across the data.
61 changes: 58 additions & 3 deletions internal/light-client/event-listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eventlistener
import (
"context"
"net/url"
"time"

logging "github.com/ipfs/go-log/v2"

Expand Down Expand Up @@ -66,22 +67,76 @@ func (el *EventListener) SubscribeToLogs(ctx context.Context) {
Addresses: []common.Address{el.contractAddress},
}

// Initial subscription
sub, err := el.client.SubscribeFilterLogs(ctx, query, el.logs)
if err != nil {
log.Fatalf("Failed to subscribe to logs: %v", err)
log.Errorf("Failed to subscribe to logs: %v", err)
el.retrySubscription(ctx, query) // Try to recover by retrying the subscription
return
}

el.subscription = sub

go func() {
for err := range sub.Err() {
log.Fatalf("Subscription error: %v", err)
for {
select {
case err := <-sub.Err():
if err != nil {
log.Errorf("Subscription error: %v", err)
el.retrySubscription(ctx, query) // Try to recover by retrying the subscription
return
}
case <-ctx.Done():
log.Infof("Context canceled, stopping log subscription.")
return
}
}
}()

log.Infof("Subscribed to logs for contract: %v", el.contractAddress.Hex())
}

func (el *EventListener) retrySubscription(ctx context.Context, query ethereum.FilterQuery) {
backoff := 2 * time.Second // Initial backoff duration
maxBackoff := 1 * time.Minute // Maximum backoff duration

for {
select {
case <-ctx.Done():
log.Infof("Context canceled, aborting subscription retry.")
return
default:
sub, err := el.client.SubscribeFilterLogs(ctx, query, el.logs)
if err != nil {
log.Errorf("Retrying subscription to logs failed: %v", err)

// Increase backoff duration, but don't exceed maxBackoff
time.Sleep(backoff)
backoff *= 2
if backoff > maxBackoff {
backoff = maxBackoff
}
continue
}

el.subscription = sub

go func() {
for err := range sub.Err() {
if err != nil {
log.Errorf("Subscription error after retry: %v", err)
el.retrySubscription(ctx, query) // Retry again if needed
return
}
}
}()

log.Infof("Successfully resubscribed to logs for contract: %v", el.contractAddress.Hex())
return
}
}
}

// ProcessLogs processes the logs emitted by the contract
func (el *EventListener) ProcessLogs() {
for vLog := range el.logs {
Expand Down
25 changes: 25 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# Check if CLIENT_ID is set; if not, exit with an error
if [ -z "$CLIENT_ID" ]; then
echo "Error: CLIENT_ID environment variable is not set."
exit 1
fi

# Start IPFS daemon in the background
ipfs daemon --enable-gc=true &

# Wait for IPFS daemon to start
until netstat -an | grep 'LISTEN' | grep ':5001'; do
printf '.'
sleep 1
done

# Start light-client with the provided and hardcoded arguments
light-client \
--loglevel debug \
--rpc-url wss://moonbase-alpha.blastapi.io/618fd77b-a090-457b-b08a-373398006a5e \
--contract 0x916B54696A70588a716F899bE1e8f2A5fFd5f135 \
--topic-id DAS-TO-BQ \
--gcp-creds-file /gcp-credentials.json \
--client-id "$CLIENT_ID"
13 changes: 13 additions & 0 deletions test/data/gcp-credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "covalent-network-team-sandbox",
"private_key_id": "78c57ca75a6e0b75109830277d1a839da4d7a734",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDftv6m5FOyUIkR\nRFGQTDlJ++D1HbkUcMxP2d+69imEO1+MX+LLF8+hKNbz46EtWBenXHGmVxcozrWJ\nK3n0qwUTL1B4T3aVRy5Ougn+ic8jSSe96zoC0QDNHC/KAoa/Omwew6JNQpHC+hEc\nYI9x40Qioic7WKGEYc5ASmrLLtjcRftduZ1F4F5mP8U1YcDCDHTyXTVWiFJ5XaeG\nQg+a/aiRNFeiZ75PBCWXTDoHzZMrXfCGXhB3v27ycbS4x5pxuwx0zTmtPyImPffq\nTpj/3ITGsGQJ4tMZHz6xnRrQM/wkA/3gzhGZwF52UGzphxV4BjQp5PGOIlR6Cx63\nLsRPuYJXAgMBAAECggEAZfW0GAImNzXHUqxNdDOZRKPcgjqauLs0EwyckExS3aZl\nxMeKyL9AbRX86ckME2t71FYoogQ9VObpC+xZt+4d8QF2bm7g/+YiL9VQascKNe3I\nhCFqHhB9if3XtfzyxsLsthS5qva1EiUAmWtU1TYcPqCiusSJUJl29Aw2ogXm5nTQ\nQY800WOU3UZ20rIugpQh4epriQeMK8cVmY95M+3+w9rt8uT4LL53tueBtOvV0AtW\ns2KslH/LAT76QK+hyeHFvinjjwUJ95ndYrrPwRHOKT4dqeWnCFG8p+pP0DAr1SDH\nyGBkThOL/OQOX8RDZwVQmAfqr7Uu7WOqKyAZ7YJwiQKBgQD9B+WVg9CQurMrfTp5\n+ikkOSb7JscvL4+cTpZj7r3nEs6M9lLYT9B54ZKu1rU3oxXnX0m9uzg3v2Jop23t\n5A7G8Ofwwdt5slJ6qj52ZJxntNdlzWvDNI2RftfZMA9jFrP/Ebsjg0BcgEMBHOWQ\nTsc0kiFbVswuX+RWrjX0sFbJKwKBgQDiVwhixj/ZUaoz+XiceSso+M3kPmJPKvTd\nuhdY2aNZxY3/sUJSpp4XBWnu6t7KQB1C4z0WBQrMVJAg5lWq3E4KDUVbWyE1g3Fm\nHwnHtLwuj+4AN0bt5sYR35mkX6GInFg5WrlyCg56lQ6Ic/Ge+30+GK5Vbtm2jrEM\ndQwAILt9hQKBgQC5mrZMw2EVGO5eg0CGwvq0yHuQlPRc521XgcoNSc3hF0mN2w4Q\nABPzo4SeXX6Wbjmd+6ay1wc41VlRXSdk7fns8j+gugLNNQINWp3w6IJWDDBIS7O1\nf/IsfLfGZ9uRmtCz1ITKWve2IpuD0HeQMEkthdeUEYo6pjpvXuDTORqf+wKBgQCy\nYSkov1meqi/bmmcl2pDbT4rksQ3FmvM0s+6mhY+ptnp843SDsvCw8AFW3CANgY4O\nIw0Hh53E/3g/lYg6ijmuzlq07xMzG46Jjzij/Zq5j5Fg9i+eWtwLRg/Obdfe1Gjr\nesbgS3CxxzuW6tmoFEfWYpkyl5RZvgdm6/AzQZjCCQKBgQD0ZJuKkPaQ7iDOnKOq\n1V877XiuvglGCy024sqhh7Iy8V+HJ2kxjGjYq8FZLbOVVdqf8IP7OKu3rR4RnJEl\n42s981p0UfcI0KSO85h/+c3jZ4/la17FCgeQo2YkIri/KKy7scqT+1dryzhPCj1k\ncM4BjiW2kw6Zzb+PSe2mzYOARg==\n-----END PRIVATE KEY-----\n",
"client_email": "das-ligent-clients-pub-sub@covalent-network-team-sandbox.iam.gserviceaccount.com",
"client_id": "102608612746177537483",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/das-ligent-clients-pub-sub%40covalent-network-team-sandbox.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}

0 comments on commit 5ea4848

Please sign in to comment.