From cfc72f489cfbe7da3654cb2edc6bdd29f0ae407c Mon Sep 17 00:00:00 2001 From: hopeyen <60078528+hopeyen@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:02:58 +0000 Subject: [PATCH] fix: offchain store in setup --- core/meterer/offchain_store.go | 22 +---- inabox/deploy/config.go | 26 +++--- inabox/deploy/deploy.go | 16 ++-- inabox/deploy/localstack.go | 89 +++--------------- inabox/tests/integration_payment_test.go | 111 ----------------------- inabox/tests/integration_suite_test.go | 4 - inabox/tests/integration_v2_test.go | 2 +- 7 files changed, 41 insertions(+), 229 deletions(-) delete mode 100644 inabox/tests/integration_payment_test.go diff --git a/core/meterer/offchain_store.go b/core/meterer/offchain_store.go index 4481d2cce2..a8933694fc 100644 --- a/core/meterer/offchain_store.go +++ b/core/meterer/offchain_store.go @@ -41,30 +41,16 @@ func NewOffchainStore( return OffchainStore{}, err } - // fmt.Println("check if reservation exists", reservationTableName) - // err = dynamoClient.TableExists(context.Background(), reservationTableName) - // if err != nil { - // return OffchainStore{}, err - // } - // fmt.Println("check if ondemand exists", onDemandTableName) - // err = dynamoClient.TableExists(context.Background(), onDemandTableName) - // if err != nil { - // return OffchainStore{}, err - // } - // fmt.Println("check if global exists", globalBinTableName) - // err = dynamoClient.TableExists(context.Background(), globalBinTableName) - // if err != nil { - // return OffchainStore{}, err - // } - err = CreateReservationTable(cfg, reservationTableName) + fmt.Println("check if payment tables exist", reservationTableName) + err = dynamoClient.TableExists(context.Background(), reservationTableName) if err != nil { return OffchainStore{}, err } - err = CreateOnDemandTable(cfg, onDemandTableName) + err = dynamoClient.TableExists(context.Background(), onDemandTableName) if err != nil { return OffchainStore{}, err } - err = CreateGlobalReservationTable(cfg, globalBinTableName) + err = dynamoClient.TableExists(context.Background(), globalBinTableName) if err != nil { return OffchainStore{}, err } diff --git a/inabox/deploy/config.go b/inabox/deploy/config.go index 53a3ed1217..d16ec72a02 100644 --- a/inabox/deploy/config.go +++ b/inabox/deploy/config.go @@ -227,9 +227,9 @@ func (env *Config) generateDisperserV2Vars(ind int, logPath, dbPath, grpcPort st DISPERSER_SERVER_DISPERSER_VERSION: "2", DISPERSER_SERVER_ENABLE_PAYMENT_METERER: "true", - DISPERSER_SERVER_RESERVATIONS_TABLE_NAME: "e2e-v2-reservation", - DISPERSER_SERVER_ON_DEMAND_TABLE_NAME: "e2e-v2-ondemand", - DISPERSER_SERVER_GLOBAL_RATE_TABLE_NAME: "e2e-v2-global-reservation", + DISPERSER_SERVER_RESERVATIONS_TABLE_NAME: "e2e_v2_reservation", + DISPERSER_SERVER_ON_DEMAND_TABLE_NAME: "e2e_v2_ondemand", + DISPERSER_SERVER_GLOBAL_RATE_TABLE_NAME: "e2e_v2_global_reservation", } env.applyDefaults(&v, "DISPERSER_SERVER", "dis", ind) @@ -714,17 +714,17 @@ func (env *Config) GenerateAllVariables() { filename, []string{grpcPort}) } - // Disperser clients - for i := 0; i < 4; i++ { - name := fmt.Sprintf("client%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) - participant := DisperserClient{ - Address: address, - PrivateKeyHex: key[2:], - } - env.DisperserClients = append(env.DisperserClients, participant) - } + // participant := DisperserClient{ + // Address: address, + // PrivateKeyHex: key[2:], + // } + // env.DisperserClients = append(env.DisperserClients, participant) + // } name = "retriever0" key, _ = env.getKey(name) diff --git a/inabox/deploy/deploy.go b/inabox/deploy/deploy.go index 902474de28..de49d853c4 100644 --- a/inabox/deploy/deploy.go +++ b/inabox/deploy/deploy.go @@ -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) @@ -72,12 +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)) - } - fmt.Println("------- clients -------", clients) + // // 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, @@ -86,7 +86,7 @@ func (env *Config) generateEigenDADeployConfig() EigenDADeployConfig { StakerPrivateKeys: stakers, StakerTokenAmounts: stakes, OperatorPrivateKeys: operators, - ClientPrivateKeys: clients, + // ClientPrivateKeys: clients, ConfirmerPrivateKey: env.getKeyString("batcher0"), } diff --git a/inabox/deploy/localstack.go b/inabox/deploy/localstack.go index 6a68e916da..62dffaf3c4 100644 --- a/inabox/deploy/localstack.go +++ b/inabox/deploy/localstack.go @@ -143,83 +143,24 @@ func DeployResources( return err } - // fmt.Println("Creating payment related tables ---- in localstack") - // // create payment related tables - // err = meterer.CreateReservationTable(cfg, v2MetadataTableName+"_reservation") - // if err != nil { - // fmt.Println("err", err) - // return err - // } - // err = meterer.CreateOnDemandTable(cfg, v2MetadataTableName+"_ondemand") - // if err != nil { - // fmt.Println("err", err) - // return err - // } - // err = meterer.CreateGlobalReservationTable(cfg, v2MetadataTableName+"_global_reservation") - // if err != nil { - // fmt.Println("err", err) - // return err - // } - } - - return err - -} - -func DeployPaymentRelatedTables( - pool *dockertest.Pool, - localStackPort string, -) error { - - if pool == nil { - var err error - pool, err = dockertest.NewPool("") + v2PaymentName := "e2e_v2" + fmt.Println("Creating payment related tables ---- in localstack") + // create payment related tables + err = meterer.CreateReservationTable(cfg, v2PaymentName+"_reservation") if err != nil { - fmt.Println("Could not construct pool: %w", err) + fmt.Println("err", err) + return err + } + err = meterer.CreateOnDemandTable(cfg, v2PaymentName+"_ondemand") + if err != nil { + fmt.Println("err", err) + return err + } + err = meterer.CreateGlobalReservationTable(cfg, v2PaymentName+"_global_reservation") + if err != nil { + fmt.Println("err", err) return err } - } - - // exponential backoff-retry, because the application in - // the container might not be ready to accept connections yet - pool.MaxWait = 10 * time.Second - _, b, _, _ := runtime.Caller(0) - rootPath := filepath.Join(filepath.Dir(b), "../..") - changeDirectory(filepath.Join(rootPath, "inabox")) - if err := pool.Retry(func() error { - fmt.Println("Creating S3 bucket") - return execCmd("./create-s3-bucket.sh", []string{}, []string{fmt.Sprintf("AWS_URL=http://0.0.0.0:%s", localStackPort)}) - }); err != nil { - fmt.Println("Might be connected already:", err) - // return err - } - - 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 deploy hleper") - - v2TableName := "test_v2" - fmt.Println("Creating payment related tables") - // create payment related tables - err := meterer.CreateReservationTable(cfg, v2TableName+"_reservation") - if err != nil { - fmt.Println("err", err) - return err - } - err = meterer.CreateOnDemandTable(cfg, v2TableName+"_ondemand") - if err != nil { - fmt.Println("err", err) - return err - } - err = meterer.CreateGlobalReservationTable(cfg, v2TableName+"_global_reservation") - if err != nil { - fmt.Println("err", err) - return err } return err diff --git a/inabox/tests/integration_payment_test.go b/inabox/tests/integration_payment_test.go deleted file mode 100644 index 53a884e1cc..0000000000 --- a/inabox/tests/integration_payment_test.go +++ /dev/null @@ -1,111 +0,0 @@ -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()) - }) -}) diff --git a/inabox/tests/integration_suite_test.go b/inabox/tests/integration_suite_test.go index 4d4d7be4de..9eb1703e87 100644 --- a/inabox/tests/integration_suite_test.go +++ b/inabox/tests/integration_suite_test.go @@ -101,10 +101,6 @@ var _ = BeforeSuite(func() { fmt.Println("Using in-memory Blob Store") } - // fmt.Println("Making payment related tables....") - // err = deploy.DeployPaymentRelatedTables(pool, localStackPort) - // Expect(err).To(BeNil()) - fmt.Println("Starting anvil") testConfig.StartAnvil() diff --git a/inabox/tests/integration_v2_test.go b/inabox/tests/integration_v2_test.go index dcae3b61f0..5a590aae44 100644 --- a/inabox/tests/integration_v2_test.go +++ b/inabox/tests/integration_v2_test.go @@ -22,7 +22,7 @@ import ( var _ = Describe("Inabox v2 Integration", func() { It("test end to end scenario", func() { - ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcded"