Skip to content

Commit

Permalink
[payment] transactor ping payment vault contract (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen authored Dec 10, 2024
1 parent ccc1e9a commit 2f5ced8
Show file tree
Hide file tree
Showing 23 changed files with 441 additions and 254 deletions.
14 changes: 7 additions & 7 deletions api/clients/accountant.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a *Accountant) BlobPaymentInfo(ctx context.Context, numSymbols uint64, quo
relativeBinRecord.Usage += numSymbols

// first attempt to use the active reservation
binLimit := a.reservation.SymbolsPerSec * uint64(a.reservationWindow)
binLimit := a.reservation.SymbolsPerSecond * uint64(a.reservationWindow)
if relativeBinRecord.Usage <= binLimit {
if err := QuorumCheck(quorumNumbers, a.reservation.QuorumNumbers); err != nil {
return 0, big.NewInt(0), err
Expand Down Expand Up @@ -166,7 +166,7 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState
return fmt.Errorf("reservation cannot be nil")
} else if paymentState.GetReservation().GetQuorumNumbers() == nil {
return fmt.Errorf("reservation quorum numbers cannot be nil")
} else if paymentState.GetReservation().GetQuorumSplit() == nil {
} else if paymentState.GetReservation().GetQuorumSplits() == nil {
return fmt.Errorf("reservation quorum split cannot be nil")
} else if paymentState.GetBinRecords() == nil {
return fmt.Errorf("bin records cannot be nil")
Expand All @@ -177,7 +177,7 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState
a.cumulativePayment = new(big.Int).SetBytes(paymentState.CumulativePayment)
a.pricePerSymbol = uint32(paymentState.PaymentGlobalParams.PricePerSymbol)

a.reservation.SymbolsPerSec = uint64(paymentState.PaymentGlobalParams.GlobalSymbolsPerSecond)
a.reservation.SymbolsPerSecond = uint64(paymentState.PaymentGlobalParams.GlobalSymbolsPerSecond)
a.reservation.StartTimestamp = uint64(paymentState.Reservation.StartTimestamp)
a.reservation.EndTimestamp = uint64(paymentState.Reservation.EndTimestamp)
a.reservationWindow = uint32(paymentState.PaymentGlobalParams.ReservationWindow)
Expand All @@ -188,11 +188,11 @@ func (a *Accountant) SetPaymentState(paymentState *disperser_rpc.GetPaymentState
}
a.reservation.QuorumNumbers = quorumNumbers

quorumSplit := make([]uint8, len(paymentState.Reservation.QuorumSplit))
for i, quorum := range paymentState.Reservation.QuorumSplit {
quorumSplit[i] = uint8(quorum)
quorumSplits := make([]uint8, len(paymentState.Reservation.QuorumSplits))
for i, quorum := range paymentState.Reservation.QuorumSplits {
quorumSplits[i] = uint8(quorum)
}
a.reservation.QuorumSplit = quorumSplit
a.reservation.QuorumSplits = quorumSplits

binRecords := make([]BinRecord, len(paymentState.BinRecords))
for i, record := range paymentState.BinRecords {
Expand Down
80 changes: 40 additions & 40 deletions api/clients/accountant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const numBins = uint32(3)

func TestNewAccountant(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 100,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 100,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(500),
Expand All @@ -48,11 +48,11 @@ func TestNewAccountant(t *testing.T) {

func TestAccountBlob_Reservation(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(500),
Expand Down Expand Up @@ -96,11 +96,11 @@ func TestAccountBlob_Reservation(t *testing.T) {

func TestAccountBlob_OnDemand(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(1500),
Expand Down Expand Up @@ -152,11 +152,11 @@ func TestAccountBlob_InsufficientOnDemand(t *testing.T) {

func TestAccountBlobCallSeries(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(1000),
Expand Down Expand Up @@ -200,11 +200,11 @@ func TestAccountBlobCallSeries(t *testing.T) {

func TestAccountBlob_BinRotation(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 1000,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 1000,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(1000),
Expand Down Expand Up @@ -242,11 +242,11 @@ func TestAccountBlob_BinRotation(t *testing.T) {

func TestConcurrentBinRotationAndAccountBlob(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 1000,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 1000,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(1000),
Expand Down Expand Up @@ -288,11 +288,11 @@ func TestConcurrentBinRotationAndAccountBlob(t *testing.T) {

func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 200,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(1000),
Expand Down Expand Up @@ -333,11 +333,11 @@ func TestAccountBlob_ReservationWithOneOverflow(t *testing.T) {

func TestAccountBlob_ReservationOverflowReset(t *testing.T) {
reservation := &core.ActiveReservation{
SymbolsPerSec: 1000,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplit: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
SymbolsPerSecond: 1000,
StartTimestamp: 100,
EndTimestamp: 200,
QuorumSplits: []byte{50, 50},
QuorumNumbers: []uint8{0, 1},
}
onDemand := &core.OnDemandPayment{
CumulativePayment: big.NewInt(1000),
Expand Down
2 changes: 1 addition & 1 deletion api/docs/disperser_v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ <h3 id="disperser.v2.Reservation">Reservation</h3>
</tr>

<tr>
<td>quorum_split</td>
<td>quorum_splits</td>
<td><a href="#uint32">uint32</a></td>
<td>repeated</td>
<td><p> </p></td>
Expand Down
2 changes: 1 addition & 1 deletion api/docs/disperser_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ GetPaymentStateRequest contains parameters to query the payment state of an acco
| start_timestamp | [uint32](#uint32) | | |
| end_timestamp | [uint32](#uint32) | | |
| quorum_numbers | [uint32](#uint32) | repeated | |
| quorum_split | [uint32](#uint32) | repeated | |
| quorum_splits | [uint32](#uint32) | repeated | |



Expand Down
2 changes: 1 addition & 1 deletion api/docs/eigenda-protos.html
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,7 @@ <h3 id="disperser.v2.Reservation">Reservation</h3>
</tr>

<tr>
<td>quorum_split</td>
<td>quorum_splits</td>
<td><a href="#uint32">uint32</a></td>
<td>repeated</td>
<td><p> </p></td>
Expand Down
2 changes: 1 addition & 1 deletion api/docs/eigenda-protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ GetPaymentStateRequest contains parameters to query the payment state of an acco
| start_timestamp | [uint32](#uint32) | | |
| end_timestamp | [uint32](#uint32) | | |
| quorum_numbers | [uint32](#uint32) | repeated | |
| quorum_split | [uint32](#uint32) | repeated | |
| quorum_splits | [uint32](#uint32) | repeated | |



Expand Down
90 changes: 45 additions & 45 deletions api/grpc/disperser/v2/disperser_v2.pb.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/proto/disperser/v2/disperser_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ message Reservation {
uint32 start_timestamp = 2;
uint32 end_timestamp = 3;
repeated uint32 quorum_numbers = 4;
repeated uint32 quorum_split = 5;
repeated uint32 quorum_splits = 5;
}

// BinRecord is the usage record of an account in a bin. The API should return the active bin
Expand Down
8 changes: 4 additions & 4 deletions core/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ type Reader interface {
GetAllVersionedBlobParams(ctx context.Context) (map[uint8]*BlobVersionParameters, error)

// GetActiveReservations returns active reservations (end timestamp > current timestamp)
GetActiveReservations(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]ActiveReservation, error)
GetActiveReservations(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*ActiveReservation, error)

// GetActiveReservationByAccount returns active reservation by account ID
GetActiveReservationByAccount(ctx context.Context, blockNumber uint32, accountID string) (ActiveReservation, error)
GetActiveReservationByAccount(ctx context.Context, accountID gethcommon.Address) (*ActiveReservation, error)

// GetOnDemandPayments returns all on-demand payments
GetOnDemandPayments(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]OnDemandPayment, error)
GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*OnDemandPayment, error)

// GetOnDemandPaymentByAccount returns on-demand payment of an account
GetOnDemandPaymentByAccount(ctx context.Context, blockNumber uint32, accountID string) (OnDemandPayment, error)
GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*OnDemandPayment, error)

// GetRelayURL returns the relay URL address for the given key.
GetRelayURL(ctx context.Context, key uint32) (string, error)
Expand Down
Loading

0 comments on commit 2f5ced8

Please sign in to comment.