Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

payment failure cases inabox #1035

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions contracts/script/SetUpEigenDA.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,31 @@ contract SetupEigenDA is EigenDADeployer, EigenLayerUtils {


// Register Reservations for client as the eigenDACommunityMultisig
IPaymentVault.Reservation memory reservation = IPaymentVault.Reservation({
symbolsPerSecond: 452198,
IPaymentVault.Reservation memory reservation1 = IPaymentVault.Reservation({
symbolsPerSecond: 50, // 15k symbols over 5 minute bin interval
startTimestamp: uint64(block.timestamp),
endTimestamp: uint64(block.timestamp + 1000000000),
quorumNumbers: hex"0001",
quorumSplits: hex"3232"
});
address clientAddress = address(0x641691973c98dFe68b07Ee3613E270406285DFE8);
vm.startBroadcast(msg.sender);
paymentVault.setReservation(clientAddress, reservation);
vm.startBroadcast();
paymentVault.setReservation(address(0x641691973c98dFe68b07Ee3613E270406285DFE8), reservation1);

// small reservation
IPaymentVault.Reservation memory reservation2 = IPaymentVault.Reservation({
symbolsPerSecond: 15, // 4500 symbols over 5 minute bin interval
startTimestamp: uint64(block.timestamp),
endTimestamp: uint64(block.timestamp + 1000000000),
quorumNumbers: hex"0001",
quorumSplits: hex"3232"
});
paymentVault.setReservation(address(0x56242c5e4C968669FE04331AC89967a7F5A06B24), reservation2);

// Deposit OnDemand
paymentVault.depositOnDemand{value: 0.1 ether}(clientAddress);
vm.stopBroadcast();
paymentVault.depositOnDemand{value: 0.1 ether}(address(0x641691973c98dFe68b07Ee3613E270406285DFE8));
paymentVault.depositOnDemand{value: 2000 gwei}(address(0x55c781dd60F8418Fc8a65D14907aFF47C903a559));

vm.stopBroadcast();
// Deposit stakers into EigenLayer and delegate to operators
for (uint256 i = 0; i < stakerPrivateKeys.length; i++) {
vm.startBroadcast(stakerPrivateKeys[i]);
Expand Down
2 changes: 1 addition & 1 deletion disperser/apiserver/disperse_blob_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *DispersalServerV2) validateDispersalRequest(ctx context.Context, req *p
return api.NewErrorInvalidArg("payment metadata is required")
}

if len(blobHeader.PaymentMetadata.AccountID) == 0 || blobHeader.PaymentMetadata.ReservationPeriod == 0 || blobHeader.PaymentMetadata.CumulativePayment == nil {
if len(blobHeader.PaymentMetadata.AccountID) == 0 || (blobHeader.PaymentMetadata.ReservationPeriod == 0 && blobHeader.PaymentMetadata.CumulativePayment.Cmp(big.NewInt(0)) == 0) {
return api.NewErrorInvalidArg("invalid payment metadata")
}

Expand Down
2 changes: 1 addition & 1 deletion disperser/apiserver/server_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestV2DisperseBlobRequestValidation(t *testing.T) {
PaymentHeader: &pbcommon.PaymentHeader{
AccountId: accountID,
ReservationPeriod: 0,
CumulativePayment: big.NewInt(100).Bytes(),
CumulativePayment: big.NewInt(0).Bytes(),
},
}
blobHeader, err := corev2.BlobHeaderFromProtobuf(invalidReqProto)
Expand Down
94 changes: 94 additions & 0 deletions inabox/tests/integration_v2_payments_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package integration_test

import (
"context"
"crypto/rand"
"time"

"github.com/Layr-Labs/eigenda/api/clients/v2"
auth "github.com/Layr-Labs/eigenda/core/auth/v2"
dispv2 "github.com/Layr-Labs/eigenda/disperser/common/v2"
"github.com/Layr-Labs/eigenda/encoding/utils/codec"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Inabox v2 Integration", func() {
It("reservation runs out", func() {
ctx, cancel := context.WithTimeout(context.Background(), 60*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()))

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)
paddedData2 := codec.ConvertByPaddingEmptyByte(data2)

blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0)
Expect(err).To(BeNil())
Expect(key1).To(Not(BeNil()))
Expect(blobStatus1).To(Not(BeNil()))
Expect(*blobStatus1).To(Equal(dispv2.Queued))

blobStatus2, key2, err := disp.DisperseBlob(ctx, paddedData2, 0, []uint8{0}, 0)
Expect(err).To(BeNil())
Expect(key2).To(Not(BeNil()))
Expect(blobStatus2).To(Not(BeNil()))
Expect(*blobStatus2).To(Equal(dispv2.Queued))

blobStatus3, key3, err := disp.DisperseBlob(ctx, paddedData2, 0, []uint8{0}, 0)
Expect(err.Error()).To(ContainSubstring("neither reservation nor on-demand payment is available"))
Expect(key3).To(Not(BeNil()))
Expect(blobStatus3).To(BeNil())
})

It("ondemand runs out", func() {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
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()))

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)
paddedData2 := codec.ConvertByPaddingEmptyByte(data2)

blobStatus1, key1, err := disp.DisperseBlob(ctx, paddedData1, 0, []uint8{0, 1}, 0)
Expect(err).To(BeNil())
Expect(key1).To(Not(BeNil()))
Expect(blobStatus1).To(Not(BeNil()))
Expect(*blobStatus1).To(Equal(dispv2.Queued))

blobStatus2, key2, err := disp.DisperseBlob(ctx, paddedData2, 0, []uint8{0}, 0)
Expect(err.Error()).To(ContainSubstring("neither reservation nor on-demand payment is available"))
Expect(blobStatus2).To(BeNil())
Expect(key2).To(Not(BeNil()))
})
})
Loading