Skip to content

Commit

Permalink
feat: accountant initialize payment state
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Oct 25, 2024
1 parent 180aa89 commit a622cdd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
5 changes: 0 additions & 5 deletions core/meterer/meterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ func (m *Meterer) Start(ctx context.Context) {
ticker := time.NewTicker(1 * time.Hour)
defer ticker.Stop()

// initial tick immediately upto Start
if err := m.ChainPaymentState.RefreshOnchainPaymentState(ctx, nil); err != nil {
m.logger.Error("Failed to make initial query to the on-chain state", "error", err)
}

for {
select {
case <-ticker.C:
Expand Down
5 changes: 5 additions & 0 deletions core/meterer/meterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func setup(_ *testing.M) {
// metrics.NewNoopMetrics(),
)

// initialize the on-chain state
if err := mt.ChainPaymentState.RefreshOnchainPaymentState(context.Background(), nil); err != nil {
panic("failed to make initial query to the on-chain state")
}

mt.Start(context.Background())
}

Expand Down
3 changes: 2 additions & 1 deletion core/meterer/onchain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meterer
import (
"context"
"errors"
"fmt"
"sync"

"github.com/Layr-Labs/eigenda/core"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccountOnChain(ctx context
}
res, err := pcs.tx.GetActiveReservationByAccount(ctx, blockNumber, accountID)
if err != nil {
return core.ActiveReservation{}, errors.New("reservation account not found on-chain")
return core.ActiveReservation{}, fmt.Errorf("reservation account not found on-chain: %w", err)
}
return res, nil
}
Expand Down
2 changes: 1 addition & 1 deletion disperser/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (s *DispersalServer) disperseBlob(ctx context.Context, blob *core.Blob, aut
s.logger.Debug("received a new blob dispersal request", "authenticatedAddress", authenticatedAddress, "origin", origin, "blobSizeBytes", blobSize, "securityParams", strings.Join(securityParamsStrings, ", "))

// If paymentHeader is not empty, we use the meterer, otherwise we use the ratelimiter if the ratelimiter is available
if *paymentHeader != (core.PaymentMetadata{}) {
if paymentHeader != nil && *paymentHeader != (core.PaymentMetadata{}) {
err := s.meterer.MeterRequest(ctx, *blob, *paymentHeader)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions disperser/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func RunDisperserServer(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to create onchain payment state: %w", err)
}
// fresh payment state
if err := paymentChainState.RefreshOnchainPaymentState(context.Background(), nil); err != nil {
return fmt.Errorf("failed to make initial query to the on-chain state: %w", err)
}

offchainStore, err := mt.NewOffchainStore(
config.AwsClientConfig,
Expand All @@ -132,6 +136,7 @@ func RunDisperserServer(ctx *cli.Context) error {
logging.NewNoopLogger(),
// metrics.NewNoopMetrics(),
)

}

var ratelimiter common.RateLimiter
Expand Down

0 comments on commit a622cdd

Please sign in to comment.