Skip to content

Commit

Permalink
chore: go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Aug 17, 2024
1 parent 6829070 commit f9e89cc
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 64 deletions.
3 changes: 1 addition & 2 deletions commitments/da_service_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type DaSvcCommitment interface {

type EigenDASvcCommitment []byte


// NewEigenDASvcCommitment creates a new commitment from the given input.
func NewEigenDASvcCommitment(input []byte) EigenDASvcCommitment {
return EigenDASvcCommitment(crypto.Keccak256(input))
Expand All @@ -40,4 +39,4 @@ func (c EigenDASvcCommitment) CommitmentType() DAServiceOPCommitmentType {
// Encode adds a commitment type prefix self describing the commitment.
func (c EigenDASvcCommitment) Encode() []byte {
return append([]byte{byte(EigenDACommitmentType)}, c...)
}
}
4 changes: 1 addition & 3 deletions commitments/eigenda.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package commitments


type CertEncodingCommitment byte

const (
Expand All @@ -16,7 +15,6 @@ type CertCommitment interface {

type CertCommitmentV0 []byte


// NewV0CertCommitment creates a new commitment from the given input.
func NewV0CertCommitment(input []byte) CertCommitmentV0 {
return CertCommitmentV0(input)
Expand All @@ -38,4 +36,4 @@ func (c CertCommitmentV0) CommitmentType() CertEncodingCommitment {
// Encode adds a commitment type prefix self describing the commitment.
func (c CertCommitmentV0) Encode() []byte {
return append([]byte{byte(CertV0)}, c...)
}
}
17 changes: 8 additions & 9 deletions commitments/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
type CommitmentMode string

const (
OptimismGeneric CommitmentMode = "optimism_keccak256"
OptimismAltDA CommitmentMode = "optimism_generic"
SimpleCommitmentMode CommitmentMode = "simple"
OptimismGeneric CommitmentMode = "optimism_keccak256"
OptimismAltDA CommitmentMode = "optimism_generic"
SimpleCommitmentMode CommitmentMode = "simple"
)

func StringToCommitmentMode(s string) (CommitmentMode, error) {
Expand Down Expand Up @@ -49,30 +49,29 @@ func StringToDecodedCommitment(key string, c CommitmentMode) ([]byte, error) {
return b[3:], nil

case SimpleCommitmentMode: // [cert_version, ...]
return b[1:], nil
return b[1:], nil

default:
return nil, fmt.Errorf("unknown commitment type")
}
}

func EncodeCommitment(b []byte, c CommitmentMode) ([]byte, error) {

switch c {
case OptimismGeneric:
return Keccak256Commitment(b).Encode(), nil

case OptimismAltDA:
certCommit := NewV0CertCommitment(b).Encode()
certCommit := NewV0CertCommitment(b).Encode()
svcCommit := EigenDASvcCommitment(certCommit).Encode()
altDACommit := NewGenericCommitment(svcCommit).Encode()
return altDACommit, nil

case SimpleCommitmentMode:
return NewV0CertCommitment(b).Encode(), nil

}

return nil, fmt.Errorf("unknown commitment mode")
}

}
5 changes: 2 additions & 3 deletions commitments/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var ErrInvalidCommitment = errors.New("invalid commitment")
// ErrCommitmentMismatch is returned when the commitment does not match the given input.
var ErrCommitmentMismatch = errors.New("commitment mismatch")


// OPCommitmentType is the commitment type prefix.
type OPCommitmentType byte

Expand All @@ -35,8 +34,8 @@ func CommitmentTypeFromString(s string) (OPCommitmentType, error) {
const (
Keccak256CommitmentType OPCommitmentType = 0
GenericCommitmentType OPCommitmentType = 1
KeccakCommitmentString string = "KeccakCommitment"
GenericCommitmentString string = "GenericCommitment"
KeccakCommitmentString string = "KeccakCommitment"
GenericCommitmentString string = "GenericCommitment"
)

// OPCommitment is the binary representation of a commitment.
Expand Down
39 changes: 19 additions & 20 deletions e2e/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func TestProxyClientWithOversizedBlob(t *testing.T) {
func TestProxyClient_MultiSameContentBlobs_SameBatch(t *testing.T) {
t.Skip("Skipping test until fix is applied to holesky")


t.Parallel()

ts, kill := e2e.CreateTestSuite(t, useMemory(), false)
Expand All @@ -167,32 +166,32 @@ func TestProxyClient_MultiSameContentBlobs_SameBatch(t *testing.T) {
cfg := &client.Config{
URL: ts.Address(),
}

errChan := make(chan error, 10)
var wg sync.WaitGroup

// disperse 10 blobs with the same content in the same batch
for i := 0; i < 4; i ++ {
for i := 0; i < 4; i++ {
wg.Add(1)
go func(){
go func() {
defer wg.Done()
daClient := client.New(cfg)
testPreimage := []byte("hellooooooooooo world!")

t.Log("Setting input data on proxy server...")
blobInfo, err := daClient.SetData(ts.Ctx, testPreimage)
if err != nil {
errChan <- err
return
}

t.Log("Getting input data from proxy server...")
preimage, err := daClient.GetData(ts.Ctx, blobInfo)
if err != nil {
errChan <- err
return
}

if !utils.EqualSlices(preimage, testPreimage) {
errChan <- fmt.Errorf("expected preimage %s, got %s", testPreimage, preimage)
return
Expand All @@ -206,7 +205,7 @@ func TestProxyClient_MultiSameContentBlobs_SameBatch(t *testing.T) {
}

if len(errChan) > 0 {
// iterate over channel and log errors
// iterate over channel and log errors
for i := 0; i < len(errChan); i++ {
err := <-errChan
t.Log(err.Error())
Expand All @@ -218,15 +217,15 @@ func TestProxyClient_MultiSameContentBlobs_SameBatch(t *testing.T) {
// waitTimeout waits for the waitgroup for the specified max timeout.
// Returns true if waiting timed out.
func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
c := make(chan struct{})
go func() {
defer close(c)
wg.Wait()
}()
select {
case <-c:
return false
case <-time.After(timeout):
return true
}
}
c := make(chan struct{})
go func() {
defer close(c)
wg.Wait()
}()
select {
case <-c:
return false
case <-time.After(timeout):
return true
}
}
9 changes: 4 additions & 5 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,15 @@ type Config struct {
EthConfirmationDepth int64

// KZG vars
CacheDir string
G1Path string
G2Path string
CacheDir string
G1Path string
G2Path string
G2PowerOfTauPath string

// Size constraints
MaxBlobLength string
maxBlobLengthBytes uint64


// Memstore
MemstoreEnabled bool
MemstoreBlobExpiration time.Duration
Expand Down Expand Up @@ -360,4 +359,4 @@ func CLIFlags(envPrefix string) []cli.Flag {
EnvVars: prefixEnvVars("S3_ACCESS_KEY_SECRET"),
},
}
}
}
4 changes: 2 additions & 2 deletions server/load_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package server
import (
"context"
"fmt"

"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/api/clients"
Expand Down Expand Up @@ -57,7 +57,7 @@ func LoadStoreRouter(cfg CLIConfig, ctx context.Context, log log.Logger) (*store
if err != nil {
return nil, err
}

eigenda, err := store.NewEigenDAStore(
ctx,
client,
Expand Down
8 changes: 4 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
type Server struct {
log log.Logger
endpoint string
router *store.Router
router *store.Router
m metrics.Metricer
tls *rpc.ServerTLSConfig
httpServer *http.Server
Expand All @@ -51,7 +51,7 @@ func NewServer(host string, port int, router *store.Router, log log.Logger, m me
m: m,
log: log,
endpoint: endpoint,
router: router,
router: router,
httpServer: &http.Server{
Addr: endpoint,
ReadHeaderTimeout: 10 * time.Second,
Expand Down Expand Up @@ -279,7 +279,7 @@ func ReadCommitmentMode(r *http.Request) (commitments.CommitmentMode, error) {

default:
return commitments.SimpleCommitmentMode, fmt.Errorf("unknown commit byte prefix")

}
}

Expand All @@ -295,4 +295,4 @@ func (svr *Server) GetMemStats() *store.Stats {

func (svr *Server) GetS3Stats() *store.Stats {
return svr.router.GetS3Store().Stats()
}
}
3 changes: 1 addition & 2 deletions store/eigenda.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (e EigenDAStore) Put(ctx context.Context, value []byte) (comm []byte, err e
}
cert := (*verify.Certificate)(blobInfo)


err = e.verifier.VerifyCommitment(cert.BlobHeader.Commitment, encodedBlob)
if err != nil {
return nil, err
Expand Down Expand Up @@ -152,4 +151,4 @@ func (e EigenDAStore) EncodeAndVerify(ctx context.Context, key []byte, value []b
}

return value, nil
}
}
2 changes: 1 addition & 1 deletion store/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ func (r *Router) GetMemStore() *MemStore {

func (r *Router) GetS3Store() *S3Store {
return r.s3
}
}
2 changes: 1 addition & 1 deletion store/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"context"
"encoding/hex"
"errors"
"github.com/minio/minio-go/v7"
"io"
"path"
"time"
"github.com/minio/minio-go/v7"

"github.com/minio/minio-go/v7/pkg/credentials"
)
Expand Down
1 change: 0 additions & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package store

import "context"


type Stats struct {
Entries int
Reads int
Expand Down
22 changes: 11 additions & 11 deletions verify/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var ErrBatchMetadataHashNotFound = errors.New("BatchMetadataHash not found for B
// CertVerifier verifies the DA certificate against on-chain EigenDA contracts
// to ensure disperser returned fields haven't been tampered with
type CertVerifier struct {
l log.Logger
l log.Logger
ethConfirmationDepth uint64
manager *binding.ContractEigenDAServiceManagerCaller
ethClient *ethclient.Client
Expand All @@ -42,7 +42,7 @@ func NewCertVerifier(cfg *Config, l log.Logger) (*CertVerifier, error) {
}

return &CertVerifier{
l: l,
l: l,
manager: m,
ethConfirmationDepth: cfg.EthConfirmationDepth,
ethClient: client,
Expand Down Expand Up @@ -104,17 +104,17 @@ func (cv *CertVerifier) VerifyMerkleProof(inclusionProof []byte, root []byte, bl

func (cv *CertVerifier) getContextBlock() (*big.Int, error) {
var blockNumber *big.Int
blockHeader, err := cv.ethClient.BlockByNumber(context.Background(), nil)
if err != nil {
return nil, err
}
blockHeader, err := cv.ethClient.BlockByNumber(context.Background(), nil)
if err != nil {
return nil, err
}

if cv.ethConfirmationDepth == 0 {
return blockHeader.Number(), nil
}
if cv.ethConfirmationDepth == 0 {
return blockHeader.Number(), nil
}

blockNumber = new(big.Int)
blockNumber.Sub(blockHeader.Number(), big.NewInt(int64(cv.ethConfirmationDepth-1)))
blockNumber = new(big.Int)
blockNumber.Sub(blockHeader.Number(), big.NewInt(int64(cv.ethConfirmationDepth-1)))

return blockNumber, nil
}

0 comments on commit f9e89cc

Please sign in to comment.