Skip to content

Commit

Permalink
refactor: cleanups and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 18, 2024
1 parent 0c52dfb commit 9e52934
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 64 deletions.
34 changes: 17 additions & 17 deletions disperser/apiserver/disperse_blob_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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")
}
Expand All @@ -109,7 +125,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")
Expand All @@ -119,22 +135,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())
Expand Down
2 changes: 1 addition & 1 deletion disperser/apiserver/server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,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
Expand Down
19 changes: 0 additions & 19 deletions disperser/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions inabox/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,18 +714,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)
Expand Down
24 changes: 9 additions & 15 deletions inabox/deploy/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9e52934

Please sign in to comment.