-
Notifications
You must be signed in to change notification settings - Fork 165
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
disperser meterer for payments #779
base: master
Are you sure you want to change the base?
Changes from 5 commits
435e46d
c5858cf
57c83d7
8eaa2a8
41fd0c8
b14bf86
8548415
1b65acf
671df9b
533e6d3
13f8fde
4afd390
1af7037
d93c91c
e8386ab
e1d454b
18ddb8a
24977c1
ba7bb66
dd2ab52
500ecc4
75acda3
243a2f9
219acf5
9239918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"fmt" | ||
"math" | ||
"strconv" | ||
"sync" | ||
|
||
commonaws "github.com/Layr-Labs/eigenda/common/aws" | ||
|
@@ -156,6 +157,51 @@ func (c *Client) UpdateItem(ctx context.Context, tableName string, key Key, item | |
return resp.Attributes, err | ||
} | ||
|
||
func (c *Client) UpdateItemIncrement(ctx context.Context, tableName string, key Key, item Item) (Item, error) { | ||
update := expression.UpdateBuilder{} | ||
for itemKey, itemValue := range item { | ||
if _, ok := key[itemKey]; ok { | ||
// Cannot update the key | ||
continue | ||
} | ||
// fmt.Println("updating item", itemKey, itemValue) | ||
// ADD numeric values | ||
if n, ok := itemValue.(*types.AttributeValueMemberN); ok { | ||
// update = update.Add(expression.Name(itemKey), expression.Value(n.Value)) | ||
// update = update.Add(expression.Name(itemKey), expression.Value(n.Value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove? |
||
f, _ := strconv.ParseFloat(n.Value, 64) | ||
update = update.Add(expression.Name(itemKey), expression.Value(aws.Float64(f))) | ||
|
||
} else { | ||
// For non-numeric values, use SET as before | ||
update = update.Set(expression.Name(itemKey), expression.Value(itemValue)) | ||
} | ||
} | ||
|
||
expr, err := expression.NewBuilder().WithUpdate(update).Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fmt.Println("update item increment", expr.Update()) | ||
resp, err := c.dynamoClient.UpdateItem(ctx, &dynamodb.UpdateItemInput{ | ||
TableName: aws.String(tableName), | ||
Key: key, | ||
ExpressionAttributeNames: expr.Names(), | ||
ExpressionAttributeValues: expr.Values(), | ||
UpdateExpression: expr.Update(), | ||
ReturnValues: types.ReturnValueUpdatedNew, | ||
}) | ||
if err != nil { | ||
fmt.Println("error updating item", err) | ||
return nil, err | ||
} | ||
|
||
fmt.Println("update item increment", resp.Attributes) | ||
|
||
return resp.Attributes, nil | ||
} | ||
|
||
func (c *Client) GetItem(ctx context.Context, tableName string, key Key) (Item, error) { | ||
resp, err := c.dynamoClient.GetItem(ctx, &dynamodb.GetItemInput{Key: key, TableName: aws.String(tableName)}) | ||
if err != nil { | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package core | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/math" | ||
"github.com/ethereum/go-ethereum/signer/core/apitypes" | ||
) | ||
|
||
// EIP712Domain represents the EIP-712 domain for our blob headers | ||
var EIP712Domain = apitypes.TypedDataDomain{ | ||
Name: "EigenDA", | ||
Version: "1", | ||
ChainId: (*math.HexOrDecimal256)(big.NewInt(17000)), | ||
VerifyingContract: common.HexToAddress("0x1234000000000000000000000000000000000000").Hex(), | ||
} | ||
|
||
// Protocol defines parameters: epoch length and rate-limit window interval | ||
type ActiveReservation struct { | ||
dataRate uint32 // bandwith being reserved | ||
startEpoch uint32 // index of epoch where reservation begins | ||
endEpoch uint32 // index of epoch where reservation ends | ||
quorumSplit []byte // each byte is a percentage at the corresponding quorum index | ||
} | ||
|
||
// Protocol defines parameters: FixedFeePerByte; fine to leave global rate-limit offchain atm | ||
type OnDemandPayment struct { | ||
amountDeposited big.Int | ||
// amountCollected big.Int | ||
} | ||
|
||
// // Create the typed data for EIP-712 signature verification | ||
// typedData := apitypes.TypedData{ | ||
// Types: apitypes.Types{ | ||
// "EIP712Domain": []apitypes.Type{ | ||
// {Name: "name", Type: "string"}, | ||
// {Name: "version", Type: "string"}, | ||
// {Name: "chainId", Type: "uint256"}, | ||
// {Name: "verifyingContract", Type: "address"}, | ||
// }, | ||
// "BlobHeader": []apitypes.Type{ | ||
// {Name: "version", Type: "uint32"}, | ||
// {Name: "accountID", Type: "string"}, | ||
// {Name: "nonce", Type: "uint32"}, | ||
// {Name: "binIndex", Type: "uint32"}, | ||
// {Name: "cumulativePayment", Type: "uint64"}, | ||
// {Name: "commitment", Type: "bytes"}, | ||
// {Name: "dataLength", Type: "uint32"}, | ||
// {Name: "blobQuorumParams", Type: "BlobQuorumParam[]"}, | ||
// }, | ||
// "BlobQuorumParam": []apitypes.Type{ | ||
// {Name: "quorumID", Type: "uint8"}, | ||
// {Name: "adversaryThreshold", Type: "uint32"}, | ||
// {Name: "quorumThreshold", Type: "uint32"}, | ||
// }, | ||
// }, | ||
// Domain: EIP712Domain, | ||
// PrimaryType: "BlobHeader", | ||
// Message: apitypes.TypedDataMessage{ | ||
// "version": header.Version, | ||
// "accountID": header.AccountID, | ||
// "nonce": header.Nonce, | ||
// "binIndex": header.BinIndex, | ||
// "cumulativePayment": header.CumulativePayment, | ||
// "commitment": header.Commitment.Bytes(), | ||
// "dataLength": header.DataLength, | ||
// "blobQuorumParams": header.BlobQuorumParams, | ||
// }, | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is using the template above, but it's unclear to me why this is failing silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently dynamoDB doesn't let user update the primary key or sort key of an existing item, so if the current itemKey is part of the item's key, we simply move on to the next attribute in the item map. I think this is failing silently because we want to operate on other fields anyway.
some 3 alternative ways that still ensure consistency: