From 9edf8bde865973da0ebb1dd701cb581f5e9df8fe Mon Sep 17 00:00:00 2001 From: hopeyen Date: Tue, 17 Dec 2024 13:20:45 -0800 Subject: [PATCH] refactor: cleanups and logs --- disperser/apiserver/disperse_blob_v2.go | 34 ++++++++++++------------- disperser/apiserver/server_v2.go | 2 +- disperser/cmd/apiserver/main.go | 19 -------------- inabox/deploy/config.go | 12 --------- inabox/deploy/config_types.go | 24 +++++++---------- 5 files changed, 27 insertions(+), 64 deletions(-) diff --git a/disperser/apiserver/disperse_blob_v2.go b/disperser/apiserver/disperse_blob_v2.go index 1d7c1e5749..af227f05e2 100644 --- a/disperser/apiserver/disperse_blob_v2.go +++ b/disperser/apiserver/disperse_blob_v2.go @@ -109,6 +109,22 @@ func (s *DispersalServerV2) validateDispersalRequest(ctx context.Context, req *p return api.NewErrorInvalidArg("blob header must contain commitments") } + blobHeader, err := corev2.BlobHeaderFromProtobuf(blobHeaderProto) + if err != nil { + return api.NewErrorInvalidArg(fmt.Sprintf("invalid blob header: %s", err.Error())) + } + + if blobHeader.PaymentMetadata == (core.PaymentMetadata{}) { + return api.NewErrorInvalidArg("payment metadata is required") + } + if err = s.authenticator.AuthenticateBlobRequest(blobHeader); err != nil { + return api.NewErrorInvalidArg(fmt.Sprintf("authentication failed: %s", err.Error())) + } + + if len(blobHeader.PaymentMetadata.AccountID) == 0 || blobHeader.PaymentMetadata.ReservationPeriod == 0 || blobHeader.PaymentMetadata.CumulativePayment == nil { + return api.NewErrorInvalidArg("invalid payment metadata") + } + if len(blobHeaderProto.GetQuorumNumbers()) == 0 { return api.NewErrorInvalidArg("blob header must contain at least one quorum number") } @@ -124,7 +140,7 @@ func (s *DispersalServerV2) validateDispersalRequest(ctx context.Context, req *p } // validate every 32 bytes is a valid field element - _, err := rs.ToFrArray(data) + _, err = rs.ToFrArray(data) if err != nil { s.logger.Error("failed to convert a 32bytes as a field element", "err", err) return api.NewErrorInvalidArg("encountered an error to convert a 32-bytes into a valid field element, please use the correct format where every 32bytes(big-endian) is less than 21888242871839275222246405745257275088548364400416034343698204186575808495617") @@ -134,22 +150,6 @@ func (s *DispersalServerV2) validateDispersalRequest(ctx context.Context, req *p return api.NewErrorInvalidArg(fmt.Sprintf("invalid blob version %d; valid blob versions are: %v", blobHeaderProto.GetVersion(), onchainState.BlobVersionParameters.Keys())) } - blobHeader, err := corev2.BlobHeaderFromProtobuf(blobHeaderProto) - if err != nil { - return api.NewErrorInvalidArg(fmt.Sprintf("invalid blob header: %s", err.Error())) - } - - if blobHeader.PaymentMetadata == (core.PaymentMetadata{}) { - return api.NewErrorInvalidArg("payment metadata is required") - } - if err = s.authenticator.AuthenticateBlobRequest(blobHeader); err != nil { - return api.NewErrorInvalidArg(fmt.Sprintf("authentication failed: %s", err.Error())) - } - - if len(blobHeader.PaymentMetadata.AccountID) == 0 || blobHeader.PaymentMetadata.ReservationPeriod == 0 || blobHeader.PaymentMetadata.CumulativePayment == nil { - return api.NewErrorInvalidArg("invalid payment metadata") - } - // handle payments and check rate limits reservationPeriod := blobHeaderProto.GetPaymentHeader().GetReservationPeriod() cumulativePayment := new(big.Int).SetBytes(blobHeaderProto.GetPaymentHeader().GetCumulativePayment()) diff --git a/disperser/apiserver/server_v2.go b/disperser/apiserver/server_v2.go index a8f30ce4c0..2dfcd868b1 100644 --- a/disperser/apiserver/server_v2.go +++ b/disperser/apiserver/server_v2.go @@ -269,7 +269,7 @@ func (s *DispersalServerV2) GetPaymentState(ctx context.Context, req *pb.GetPaym // validate the signature if err := s.authenticator.AuthenticatePaymentStateRequest(req.GetSignature(), req.GetAccountId()); err != nil { - s.logger.Debug("failed to validate signature", err) + s.logger.Debug("failed to validate signature", "err", err, "accountID", accountID) return nil, api.NewErrorInvalidArg(fmt.Sprintf("authentication failed: %s", err.Error())) } // on-chain global payment parameters diff --git a/disperser/cmd/apiserver/main.go b/disperser/cmd/apiserver/main.go index a59e40ed67..2659f0c87b 100644 --- a/disperser/cmd/apiserver/main.go +++ b/disperser/cmd/apiserver/main.go @@ -111,25 +111,6 @@ func RunDisperserServer(ctx *cli.Context) error { return fmt.Errorf("failed to make initial query to the on-chain state: %w", err) } - logger.Info("table names", - "res", - config.ReservationsTableName, - "ondemand", - config.OnDemandTableName, - "global", - config.GlobalRateTableName, - "config", - config.AwsClientConfig, - "paymentChainState min num symbols", - paymentChainState.GetMinNumSymbols(), - "paymentChainState GetGlobalSymbolsPerSecond", - paymentChainState.GetGlobalSymbolsPerSecond(), - "paymentChainState GetGlobalRatePeriodInterval", - paymentChainState.GetGlobalRatePeriodInterval(), - "paymentChainState GetPricePerSymbol", - paymentChainState.GetPricePerSymbol(), - ) - offchainStore, err := mt.NewOffchainStore( config.AwsClientConfig, config.ReservationsTableName, diff --git a/inabox/deploy/config.go b/inabox/deploy/config.go index 82dbde7cb4..4dec4ecbfc 100644 --- a/inabox/deploy/config.go +++ b/inabox/deploy/config.go @@ -716,18 +716,6 @@ 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) - - // participant := DisperserClient{ - // Address: address, - // PrivateKeyHex: key[2:], - // } - // env.DisperserClients = append(env.DisperserClients, participant) - // } - name = "retriever0" key, _ = env.getKey(name) logPath, _, _, envFile = env.getPaths(name) diff --git a/inabox/deploy/config_types.go b/inabox/deploy/config_types.go index baaa79a40d..a2670a66a2 100644 --- a/inabox/deploy/config_types.go +++ b/inabox/deploy/config_types.go @@ -16,11 +16,6 @@ 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"` @@ -179,16 +174,15 @@ 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 - DisperserClients []DisperserClient + Churner ChurnerVars + Dispersers []DisperserVars + Batcher []BatcherVars + Encoder []EncoderVars + Operators []OperatorVars + Stakers []Staker + Retriever RetrieverVars + Controller ControllerVars + Relays []RelayVars } func (c Config) IsEigenDADeployed() bool {