Skip to content

Commit

Permalink
feat: client keys setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 16, 2024
1 parent 65f65fe commit 09bf5b1
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 78 deletions.
24 changes: 11 additions & 13 deletions inabox/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ func (env *Config) GenerateAllVariables() {
name := fmt.Sprintf("staker%v", i)
key, address := env.getKey(name)

// Create staker paritipants
// Create client paritipants
participant := Staker{
Address: address,
PrivateKey: key[2:],
Expand All @@ -714,19 +714,17 @@ func (env *Config) GenerateAllVariables() {
filename, []string{grpcPort})
}

// // Payment clients
// for i := 0; i < env.Services.Counts.NumOpr; i++ {

// name := fmt.Sprintf("staker%v", i)
// key, address := env.getKey(name)
// Disperser clients
for i := 0; i < 4; i++ {
name := fmt.Sprintf("client%v", i)
key, address := env.getKey(name)

// // Create staker paritipants
// participant := Staker{
// Address: address,
// PrivateKey: key[2:],
// }
// env.Stakers = append(env.Stakers, participant)
// }
participant := DisperserClient{
Address: address,
PrivateKeyHex: key[2:],
}
env.DisperserClients = append(env.DisperserClients, participant)
}

name = "retriever0"
key, _ = env.getKey(name)
Expand Down
24 changes: 15 additions & 9 deletions inabox/deploy/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type Staker struct {
Stake string `json:"stake"`
}

type DisperserClient struct {
Address string `json:"address"`
PrivateKeyHex string `json:"privateKeyHex"`
}

// Docker compose
type testbed struct {
Services map[string]map[string]interface{} `yaml:"services"`
Expand Down Expand Up @@ -174,15 +179,16 @@ type Config struct {

Telemetry TelemetryConfig `yaml:"telemetry"`

Churner ChurnerVars
Dispersers []DisperserVars
Batcher []BatcherVars
Encoder []EncoderVars
Operators []OperatorVars
Stakers []Staker
Retriever RetrieverVars
Controller ControllerVars
Relays []RelayVars
Churner ChurnerVars
Dispersers []DisperserVars
Batcher []BatcherVars
Encoder []EncoderVars
Operators []OperatorVars
Stakers []Staker
Retriever RetrieverVars
Controller ControllerVars
Relays []RelayVars
DisperserClients []DisperserClient
}

func (c Config) IsEigenDADeployed() bool {
Expand Down
15 changes: 8 additions & 7 deletions inabox/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (env *Config) generateEigenDADeployConfig() EigenDADeployConfig {

operators := make([]string, 0)
stakers := make([]string, 0)
// clients := make([]string, 0)
clients := make([]string, 0)
maxOperatorCount := env.Services.Counts.NumMaxOperatorCount

numStrategies := len(env.Services.Stakes)
Expand Down Expand Up @@ -72,11 +72,12 @@ func (env *Config) generateEigenDADeployConfig() EigenDADeployConfig {
operators = append(operators, env.getKeyString(operatorName))
}

// // 4 clients: with both, with reservations, with on-demand payments, without payments
// for i := 0; i < 4; i++ {
// clientName := fmt.Sprintf("client%d", i)
// clients = append(clients, env.getKeyString(clientName))
// }
// 4 clients: with both, with reservations, with on-demand payments, without payments
for i := 0; i < 4; i++ {
clientName := fmt.Sprintf("client%d", i)
clients = append(clients, env.getKeyString(clientName))
}
fmt.Println("------- clients -------", clients)

config := EigenDADeployConfig{
UseDefaults: true,
Expand All @@ -85,7 +86,7 @@ func (env *Config) generateEigenDADeployConfig() EigenDADeployConfig {
StakerPrivateKeys: stakers,
StakerTokenAmounts: stakes,
OperatorPrivateKeys: operators,
// ClientPrivateKeys: clients,
ClientPrivateKeys: clients,
ConfirmerPrivateKey: env.getKeyString("batcher0"),
}

Expand Down
111 changes: 111 additions & 0 deletions inabox/tests/integration_payment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package integration_test

import (
"context"
"crypto/rand"
"fmt"
"time"

"github.com/Layr-Labs/eigenda/api/clients/v2"
auth "github.com/Layr-Labs/eigenda/core/auth/v2"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Inabox v2 Integration - Payment", func() {
It("test reserved payment only scenario", func() {
ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
defer cancel()

privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdee"
signer := auth.NewLocalBlobRequestSigner(privateKeyHex)

accountID, err := signer.GetAccountID()
fmt.Println("accountID", accountID)
Expect(err).To(BeNil())

disp, err := clients.NewDisperserClient(&clients.DisperserClientConfig{
Hostname: "localhost",
Port: "32005",
}, signer, nil, nil)
Expect(err).To(BeNil())
Expect(disp).To(Not(BeNil()))
err = disp.PopulateAccountant(ctx)
Expect(err).To(BeNil())

data1 := make([]byte, 992)
_, err = rand.Read(data1)
Expect(err).To(BeNil())
data2 := make([]byte, 123)
_, err = rand.Read(data2)
Expect(err).To(BeNil())

paddedData1 := codec.ConvertByPaddingEmptyByte(data1)

blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0)
Expect(err).To(Not(BeNil()))
Expect(key1).To(BeNil())
Expect(blobStatus1).To(BeNil())
})
It("test ondemand payment only scenario", func() {
ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
defer cancel()

privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdee"
signer := auth.NewLocalBlobRequestSigner(privateKeyHex)

disp, err := clients.NewDisperserClient(&clients.DisperserClientConfig{
Hostname: "localhost",
Port: "32005",
}, signer, nil, nil)
Expect(err).To(BeNil())
Expect(disp).To(Not(BeNil()))
err = disp.PopulateAccountant(ctx)
Expect(err).To(BeNil())

data1 := make([]byte, 992)
_, err = rand.Read(data1)
Expect(err).To(BeNil())
data2 := make([]byte, 123)
_, err = rand.Read(data2)
Expect(err).To(BeNil())

paddedData1 := codec.ConvertByPaddingEmptyByte(data1)

blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0)
Expect(err).To(Not(BeNil()))
Expect(key1).To(BeNil())
Expect(blobStatus1).To(BeNil())
})
It("test failing payment scenario", func() {
ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
defer cancel()

privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdee"
signer := auth.NewLocalBlobRequestSigner(privateKeyHex)

disp, err := clients.NewDisperserClient(&clients.DisperserClientConfig{
Hostname: "localhost",
Port: "32005",
}, signer, nil, nil)
Expect(err).To(BeNil())
Expect(disp).To(Not(BeNil()))
err = disp.PopulateAccountant(ctx)
Expect(err).To(BeNil())

data1 := make([]byte, 992)
_, err = rand.Read(data1)
Expect(err).To(BeNil())
data2 := make([]byte, 123)
_, err = rand.Read(data2)
Expect(err).To(BeNil())

paddedData1 := codec.ConvertByPaddingEmptyByte(data1)

blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0)
Expect(err).To(Not(BeNil()))
Expect(key1).To(BeNil())
Expect(blobStatus1).To(BeNil())
})
})
49 changes: 0 additions & 49 deletions inabox/tests/integration_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,12 @@ var _ = Describe("Inabox v2 Integration", func() {
ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
defer cancel()

// cfg := aws.ClientConfig{
// Region: "us-east-1",
// AccessKey: "localstack",
// SecretAccessKey: "localstack",
// EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort),
// }

// fmt.Println("Creating v2 tables IN integration_v2_test.go")
// fmt.Println("Creating payment related tables v2")
// // create payment related tables
// err := meterer.CreateReservationTable(cfg, "e2e-v2-reservation")
// fmt.Println("err", err)
// Expect(err).To(BeNil())

// err = meterer.CreateOnDemandTable(cfg, "e2e-v2-ondemand")
// fmt.Println("err", err)
// Expect(err).To(BeNil())
// err = meterer.CreateGlobalReservationTable(cfg, "e2e-v2-global-reservation")
// fmt.Println("err", err)
// Expect(err).To(BeNil())
// fmt.Println("offchain store dynamodb created")

privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcded"
signer := auth.NewLocalBlobRequestSigner(privateKeyHex)

// reserved := core.ReservedPayment{
// SymbolsPerSecond: 452198,
// StartTimestamp: 1734305428,
// EndTimestamp: 2734305428,
// QuorumNumbers: []uint8{0, 1},
// QuorumSplits: []uint8{50, 50},
// }

// accountId, err := signer.GetAccountID()
// Expect(err).To(BeNil())

// // // Get public key
// // publicKey := privateKey.Public()
// // publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
// // Expect(ok)
// // address := crypto.PubkeyToAddress(*publicKeyECDSA)
// fmt.Println("address", accountId)

// onDemand := core.OnDemandPayment{CumulativePayment: big.NewInt(100000)}
// reservationWindow := 60
// pricePerSymbol := 47000000
// minNumSymbols := 8192
// numBins := 3

// accountant := clients.NewAccountant(accountId, &reserved, &onDemand, uint32(reservationWindow), uint32(pricePerSymbol), uint32(minNumSymbols), uint32(numBins))

disp, err := clients.NewDisperserClient(&clients.DisperserClientConfig{
Hostname: "localhost",
Port: "32005",
// }, signer, nil, accountant)
}, signer, nil, nil)
Expect(err).To(BeNil())
Expect(disp).To(Not(BeNil()))
Expand Down

0 comments on commit 09bf5b1

Please sign in to comment.