-
Notifications
You must be signed in to change notification settings - Fork 198
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
[v2] Blob Metadata Store #818
Changes from all commits
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 |
---|---|---|
|
@@ -5,11 +5,14 @@ import ( | |
"errors" | ||
"fmt" | ||
"math/big" | ||
"strconv" | ||
|
||
"github.com/Layr-Labs/eigenda/common" | ||
"github.com/Layr-Labs/eigenda/encoding" | ||
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types" | ||
"github.com/consensys/gnark-crypto/ecc/bn254" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"golang.org/x/crypto/sha3" | ||
) | ||
|
||
type AccountID = string | ||
|
@@ -483,34 +486,80 @@ func (cb Bundles) FromEncodedBundles(eb EncodedBundles) (Bundles, error) { | |
|
||
// PaymentMetadata represents the header information for a blob | ||
type PaymentMetadata struct { | ||
// Existing fields | ||
AccountID string | ||
// AccountID is the ETH account address for the payer | ||
AccountID string `json:"account_id"` | ||
|
||
// New fields | ||
BinIndex uint32 | ||
// BinIndex represents the range of time at which the dispersal is made | ||
BinIndex uint32 `json:"bin_index"` | ||
// TODO: we are thinking the contract can use uint128 for cumulative payment, | ||
// but the definition on v2 uses uint64. Double check with team. | ||
CumulativePayment *big.Int | ||
CumulativePayment *big.Int `json:"cumulative_payment"` | ||
} | ||
|
||
// Hash returns the Keccak256 hash of the PaymentMetadata | ||
func (pm *PaymentMetadata) Hash() []byte { | ||
// Create a byte slice to hold the serialized data | ||
data := make([]byte, 0, len(pm.AccountID)+4+pm.CumulativePayment.BitLen()/8+1) | ||
|
||
// Append AccountID | ||
data = append(data, []byte(pm.AccountID)...) | ||
|
||
// Append BinIndex | ||
binIndexBytes := make([]byte, 4) | ||
binary.BigEndian.PutUint32(binIndexBytes, pm.BinIndex) | ||
data = append(data, binIndexBytes...) | ||
|
||
// Append CumulativePayment | ||
paymentBytes := pm.CumulativePayment.Bytes() | ||
data = append(data, paymentBytes...) | ||
func (pm *PaymentMetadata) Hash() ([32]byte, error) { | ||
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. updated this hash function to make it compatible with solidity |
||
blobHeaderType, err := abi.NewType("tuple", "", []abi.ArgumentMarshaling{ | ||
{ | ||
Name: "accountID", | ||
Type: "string", | ||
}, | ||
{ | ||
Name: "binIndex", | ||
Type: "uint32", | ||
}, | ||
{ | ||
Name: "cumulativePayment", | ||
Type: "uint256", | ||
}, | ||
}) | ||
if err != nil { | ||
return [32]byte{}, err | ||
} | ||
|
||
arguments := abi.Arguments{ | ||
{ | ||
Type: blobHeaderType, | ||
}, | ||
} | ||
|
||
bytes, err := arguments.Pack(pm) | ||
if err != nil { | ||
return [32]byte{}, err | ||
} | ||
|
||
var hash [32]byte | ||
hasher := sha3.NewLegacyKeccak256() | ||
hasher.Write(bytes) | ||
copy(hash[:], hasher.Sum(nil)[:32]) | ||
|
||
return hash, nil | ||
} | ||
|
||
func (pm *PaymentMetadata) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) { | ||
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. Does this belong in core? Is there any way to have this code in the blobstore? 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. They need to belong in the same package as where the type is defined. We can wrap and clone these types in blobstore but not sure if that's worth it |
||
return &types.AttributeValueMemberM{ | ||
Value: map[string]types.AttributeValue{ | ||
"AccountID": &types.AttributeValueMemberS{Value: pm.AccountID}, | ||
"BinIndex": &types.AttributeValueMemberN{Value: fmt.Sprintf("%d", pm.BinIndex)}, | ||
"CumulativePayment": &types.AttributeValueMemberN{ | ||
Value: pm.CumulativePayment.String(), | ||
}, | ||
}, | ||
}, nil | ||
} | ||
|
||
return crypto.Keccak256(data) | ||
func (pm *PaymentMetadata) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error { | ||
m, ok := av.(*types.AttributeValueMemberM) | ||
if !ok { | ||
return fmt.Errorf("expected *types.AttributeValueMemberM, got %T", av) | ||
} | ||
pm.AccountID = m.Value["AccountID"].(*types.AttributeValueMemberS).Value | ||
binIndex, err := strconv.ParseUint(m.Value["BinIndex"].(*types.AttributeValueMemberN).Value, 10, 32) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse BinIndex: %w", err) | ||
} | ||
pm.BinIndex = uint32(binIndex) | ||
pm.CumulativePayment, _ = new(big.Int).SetString(m.Value["CumulativePayment"].(*types.AttributeValueMemberN).Value, 10) | ||
return nil | ||
} | ||
|
||
// OperatorInfo contains information about an operator which is stored on the blockchain state, | ||
|
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.
Where is the json serialization used?
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.
It's used when we marshal/unmarshal the struct to/from json, i.e. in dataapi.
I've removed these for now