Skip to content

Commit

Permalink
Merge branch 'Layr-Labs:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xujk-byte authored Jan 27, 2025
2 parents f62e1f8 + 77d4442 commit 2e4bf2e
Show file tree
Hide file tree
Showing 162 changed files with 6,557 additions and 3,246 deletions.
2 changes: 1 addition & 1 deletion .github/actions/test-coverage/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ runs:
go-version: ${{inputs.go-version}}

- name: Download coverage artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6
with:
name: coverage
path: .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:

- name: Save logs
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6
with:
name: inabox-logs
path: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
aws configure --profile test-profile set region us-east-1
aws configure --profile test-profile set source_profile default
- uses: actions/setup-go@v3
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34
with:
go-version: '1.21' # The Go version to download (if necessary) and use.
- run: go version

- name: Checkout EigenDA
uses: actions/checkout@v3
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- name: Build
run: make build
Expand All @@ -41,7 +41,7 @@ jobs:
run: ./test.sh -coverprofile=coverage.out

- name: Upload coverage artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6
with:
name: coverage
path: coverage.out
Expand Down
13 changes: 13 additions & 0 deletions api/clients/codecs/polynomial_form.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package codecs

// PolynomialForm is an enum that describes the different ways a polynomial may be represented.
type PolynomialForm uint

const (
// PolynomialFormEval is short for polynomial "evaluation form".
// The field elements represent the evaluation of the polynomial at roots of unity.
PolynomialFormEval PolynomialForm = iota
// PolynomialFormCoeff is short for polynomial "coefficient form".
// The field elements represent the coefficients of the polynomial.
PolynomialFormCoeff
)
4 changes: 2 additions & 2 deletions api/clients/retrieval_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (r *retrievalClient) RetrieveBlobChunks(ctx context.Context,
for i := 0; i < len(operators); i++ {
reply := <-chunksChan
if reply.Err != nil {
r.logger.Error("failed to get chunks from operator", "operator", reply.OperatorID.Hex(), "err", reply.Err)
r.logger.Warn("failed to get chunks from operator", "operator", reply.OperatorID.Hex(), "err", reply.Err)
continue
}
assignment, ok := assignments[reply.OperatorID]
Expand All @@ -206,7 +206,7 @@ func (r *retrievalClient) RetrieveBlobChunks(ctx context.Context,

err = r.verifier.VerifyFrames(reply.Chunks, assignment.GetIndices(), blobHeader.BlobCommitments, encodingParams)
if err != nil {
r.logger.Error("failed to verify chunks from operator", "operator", reply.OperatorID.Hex(), "err", err)
r.logger.Warn("failed to verify chunks from operator", "operator", reply.OperatorID.Hex(), "err", err)
continue
} else {
r.logger.Info("verified chunks from operator", "operator", reply.OperatorID.Hex())
Expand Down
3 changes: 1 addition & 2 deletions api/clients/v2/accountant.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (a *Accountant) BlobPaymentInfo(ctx context.Context, numSymbols uint32, quo
}

// AccountBlob accountant provides and records payment information
func (a *Accountant) AccountBlob(ctx context.Context, numSymbols uint32, quorums []uint8, salt uint32) (*core.PaymentMetadata, error) {
func (a *Accountant) AccountBlob(ctx context.Context, numSymbols uint32, quorums []uint8) (*core.PaymentMetadata, error) {
reservationPeriod, cumulativePayment, err := a.BlobPaymentInfo(ctx, numSymbols, quorums)
if err != nil {
return nil, err
Expand All @@ -119,7 +119,6 @@ func (a *Accountant) AccountBlob(ctx context.Context, numSymbols uint32, quorums
AccountID: a.accountID,
ReservationPeriod: reservationPeriod,
CumulativePayment: cumulativePayment,
Salt: salt,
}

return pm, nil
Expand Down
42 changes: 19 additions & 23 deletions api/clients/v2/accountant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

const numBins = uint32(3)
const salt = uint32(0)

func TestNewAccountant(t *testing.T) {
reservation := &core.ReservedPayment{
Expand Down Expand Up @@ -71,7 +70,7 @@ func TestAccountBlob_Reservation(t *testing.T) {
symbolLength := uint32(500)
quorums := []uint8{0, 1}

header, err := accountant.AccountBlob(ctx, symbolLength, quorums, salt)
header, err := accountant.AccountBlob(ctx, symbolLength, quorums)

assert.NoError(t, err)
assert.Equal(t, meterer.GetReservationPeriod(uint64(time.Now().Unix()), reservationWindow), header.ReservationPeriod)
Expand All @@ -80,15 +79,15 @@ func TestAccountBlob_Reservation(t *testing.T) {

symbolLength = uint32(700)

header, err = accountant.AccountBlob(ctx, symbolLength, quorums, salt)
header, err = accountant.AccountBlob(ctx, symbolLength, quorums)

assert.NoError(t, err)
assert.NotEqual(t, 0, header.ReservationPeriod)
assert.Equal(t, big.NewInt(0), header.CumulativePayment)
assert.Equal(t, isRotation([]uint64{1200, 0, 200}, mapRecordUsage(accountant.periodRecords)), true)

// Second call should use on-demand payment
header, err = accountant.AccountBlob(ctx, 300, quorums, salt)
header, err = accountant.AccountBlob(ctx, 300, quorums)

assert.NoError(t, err)
assert.Equal(t, uint32(0), header.ReservationPeriod)
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestAccountBlob_OnDemand(t *testing.T) {
numSymbols := uint32(1500)
quorums := []uint8{0, 1}

header, err := accountant.AccountBlob(ctx, numSymbols, quorums, salt)
header, err := accountant.AccountBlob(ctx, numSymbols, quorums)
assert.NoError(t, err)

expectedPayment := big.NewInt(int64(numSymbols * pricePerSymbol))
Expand Down Expand Up @@ -147,7 +146,7 @@ func TestAccountBlob_InsufficientOnDemand(t *testing.T) {
numSymbols := uint32(2000)
quorums := []uint8{0, 1}

_, err = accountant.AccountBlob(ctx, numSymbols, quorums, salt)
_, err = accountant.AccountBlob(ctx, numSymbols, quorums)
assert.Contains(t, err.Error(), "neither reservation nor on-demand payment is available")
}

Expand Down Expand Up @@ -176,25 +175,25 @@ func TestAccountBlobCallSeries(t *testing.T) {
now := time.Now().Unix()

// First call: Use reservation
header, err := accountant.AccountBlob(ctx, 800, quorums, salt)
header, err := accountant.AccountBlob(ctx, 800, quorums)
assert.NoError(t, err)
assert.Equal(t, meterer.GetReservationPeriod(uint64(now), reservationWindow), header.ReservationPeriod)
assert.Equal(t, big.NewInt(0), header.CumulativePayment)

// Second call: Use remaining reservation + overflow
header, err = accountant.AccountBlob(ctx, 300, quorums, salt)
header, err = accountant.AccountBlob(ctx, 300, quorums)
assert.NoError(t, err)
assert.Equal(t, meterer.GetReservationPeriod(uint64(now), reservationWindow), header.ReservationPeriod)
assert.Equal(t, big.NewInt(0), header.CumulativePayment)

// Third call: Use on-demand
header, err = accountant.AccountBlob(ctx, 500, quorums, salt)
header, err = accountant.AccountBlob(ctx, 500, quorums)
assert.NoError(t, err)
assert.Equal(t, uint32(0), header.ReservationPeriod)
assert.Equal(t, big.NewInt(500), header.CumulativePayment)

// Fourth call: Insufficient on-demand
_, err = accountant.AccountBlob(ctx, 600, quorums, salt)
_, err = accountant.AccountBlob(ctx, 600, quorums)
assert.Error(t, err)
assert.Contains(t, err.Error(), "neither reservation nor on-demand payment is available")
}
Expand Down Expand Up @@ -223,20 +222,20 @@ func TestAccountBlob_BinRotation(t *testing.T) {
quorums := []uint8{0, 1}

// First call
_, err = accountant.AccountBlob(ctx, 800, quorums, salt)
_, err = accountant.AccountBlob(ctx, 800, quorums)
assert.NoError(t, err)
assert.Equal(t, isRotation([]uint64{800, 0, 0}, mapRecordUsage(accountant.periodRecords)), true)

// next reservation duration
time.Sleep(1000 * time.Millisecond)

// Second call
_, err = accountant.AccountBlob(ctx, 300, quorums, salt)
_, err = accountant.AccountBlob(ctx, 300, quorums)
assert.NoError(t, err)
assert.Equal(t, isRotation([]uint64{800, 300, 0}, mapRecordUsage(accountant.periodRecords)), true)

// Third call
_, err = accountant.AccountBlob(ctx, 500, quorums, salt)
_, err = accountant.AccountBlob(ctx, 500, quorums)
assert.NoError(t, err)
assert.Equal(t, isRotation([]uint64{800, 800, 0}, mapRecordUsage(accountant.periodRecords)), true)
}
Expand Down Expand Up @@ -270,7 +269,7 @@ func TestConcurrentBinRotationAndAccountBlob(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
_, err := accountant.AccountBlob(ctx, 100, quorums, salt)
_, err := accountant.AccountBlob(ctx, 100, quorums)
assert.NoError(t, err)
}()
}
Expand Down Expand Up @@ -308,24 +307,21 @@ func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) {
now := time.Now().Unix()

// Okay reservation
header, err := accountant.AccountBlob(ctx, 800, quorums, salt)
header, err := accountant.AccountBlob(ctx, 800, quorums)
assert.NoError(t, err)
assert.Equal(t, salt, header.Salt)
assert.Equal(t, meterer.GetReservationPeriod(uint64(now), reservationWindow), header.ReservationPeriod)
assert.Equal(t, big.NewInt(0), header.CumulativePayment)
assert.Equal(t, isRotation([]uint64{800, 0, 0}, mapRecordUsage(accountant.periodRecords)), true)

// Second call: Allow one overflow
header, err = accountant.AccountBlob(ctx, 500, quorums, salt+1)
header, err = accountant.AccountBlob(ctx, 500, quorums)
assert.NoError(t, err)
assert.Equal(t, salt+1, header.Salt)
assert.Equal(t, big.NewInt(0), header.CumulativePayment)
assert.Equal(t, isRotation([]uint64{1300, 0, 300}, mapRecordUsage(accountant.periodRecords)), true)

// Third call: Should use on-demand payment
header, err = accountant.AccountBlob(ctx, 200, quorums, salt+2)
header, err = accountant.AccountBlob(ctx, 200, quorums)
assert.NoError(t, err)
assert.Equal(t, salt+2, header.Salt)
assert.Equal(t, uint32(0), header.ReservationPeriod)
assert.Equal(t, big.NewInt(200), header.CumulativePayment)
assert.Equal(t, isRotation([]uint64{1300, 0, 300}, mapRecordUsage(accountant.periodRecords)), true)
Expand Down Expand Up @@ -355,12 +351,12 @@ func TestAccountBlob_ReservationOverflowReset(t *testing.T) {
quorums := []uint8{0, 1}

// full reservation
_, err = accountant.AccountBlob(ctx, 1000, quorums, salt)
_, err = accountant.AccountBlob(ctx, 1000, quorums)
assert.NoError(t, err)
assert.Equal(t, isRotation([]uint64{1000, 0, 0}, mapRecordUsage(accountant.periodRecords)), true)

// no overflow
header, err := accountant.AccountBlob(ctx, 500, quorums, salt)
header, err := accountant.AccountBlob(ctx, 500, quorums)
assert.NoError(t, err)
assert.Equal(t, isRotation([]uint64{1000, 0, 0}, mapRecordUsage(accountant.periodRecords)), true)
assert.Equal(t, big.NewInt(500), header.CumulativePayment)
Expand All @@ -369,7 +365,7 @@ func TestAccountBlob_ReservationOverflowReset(t *testing.T) {
time.Sleep(time.Duration(reservationWindow) * time.Second)

// Third call: Should use new bin and allow overflow again
_, err = accountant.AccountBlob(ctx, 500, quorums, salt)
_, err = accountant.AccountBlob(ctx, 500, quorums)
assert.NoError(t, err)
assert.Equal(t, isRotation([]uint64{1000, 500, 0}, mapRecordUsage(accountant.periodRecords)), true)
}
Expand Down
9 changes: 5 additions & 4 deletions api/clients/v2/disperser_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *disperserClient) DisperseBlob(
}

symbolLength := encoding.GetBlobLengthPowerOf2(uint(len(data)))
payment, err := c.accountant.AccountBlob(ctx, uint32(symbolLength), quorums, salt)
payment, err := c.accountant.AccountBlob(ctx, uint32(symbolLength), quorums)
if err != nil {
return nil, [32]byte{}, fmt.Errorf("error accounting blob: %w", err)
}
Expand Down Expand Up @@ -187,19 +187,20 @@ func (c *disperserClient) DisperseBlob(
BlobCommitments: blobCommitments,
QuorumNumbers: quorums,
PaymentMetadata: *payment,
Salt: salt,
}

sig, err := c.signer.SignBlobRequest(blobHeader)
if err != nil {
return nil, [32]byte{}, fmt.Errorf("error signing blob request: %w", err)
}
blobHeader.Signature = sig
blobHeaderProto, err := blobHeader.ToProtobuf()
if err != nil {
return nil, [32]byte{}, fmt.Errorf("error converting blob header to protobuf: %w", err)
}
request := &disperser_rpc.DisperseBlobRequest{
Data: data,
Blob: data,
Signature: sig,
BlobHeader: blobHeaderProto,
}

Expand Down Expand Up @@ -264,7 +265,7 @@ func (c *disperserClient) GetBlobCommitment(ctx context.Context, data []byte) (*
}

request := &disperser_rpc.BlobCommitmentRequest{
Data: data,
Blob: data,
}
return c.client.GetBlobCommitment(ctx, request)
}
Expand Down
47 changes: 47 additions & 0 deletions api/clients/v2/mock/cert_verifier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/clients/v2/mock/relay_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewRelayClient() *MockRelayClient {
}

func (c *MockRelayClient) GetBlob(ctx context.Context, relayKey corev2.RelayKey, blobKey corev2.BlobKey) ([]byte, error) {
args := c.Called(blobKey)
args := c.Called(ctx, relayKey, blobKey)
if args.Get(0) == nil {
return nil, args.Error(1)
}
Expand Down
Loading

0 comments on commit 2e4bf2e

Please sign in to comment.