-
Notifications
You must be signed in to change notification settings - Fork 307
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
Refactor DAH creation to better accommodate celestia-node use case #539
Changes from all commits
d74db86
6bcf9ed
9e34a3c
f9df60e
59a9c1a
697caf4
b53fe91
2ebacd2
ee4a20b
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,8 +14,8 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
maxDAHSize = consts.MaxSquareSize * 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
minDAHSize = consts.MinSquareSize * 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
maxExtendedSquareWidth = consts.MaxSquareSize * 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
minExtendedSquareWidth = consts.MinSquareSize * 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// DataAvailabilityHeader (DAHeader) contains the row and column roots of the erasure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -38,10 +38,23 @@ type DataAvailabilityHeader struct { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// NewDataAvailabilityHeader generates a DataAvailability header using the provided square size and shares | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func NewDataAvailabilityHeader(squareSize uint64, shares [][]byte) (DataAvailabilityHeader, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func NewDataAvailabilityHeader(eds *rsmt2d.ExtendedDataSquare) DataAvailabilityHeader { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// generate the row and col roots using the EDS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dah := DataAvailabilityHeader{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RowsRoots: eds.RowRoots(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ColumnRoots: eds.ColRoots(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// generate the hash of the data using the new roots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dah.Hash() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return dah | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func ExtendShares(squareSize uint64, shares [][]byte) (*rsmt2d.ExtendedDataSquare, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Check that square size is with range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if squareSize < consts.MinSquareSize || squareSize > consts.MaxSquareSize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+54
to
56
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. the diff make it's difficult to see the differences... I reccomend simply looking at the file. The previous celestia-core/pkg/da/data_availability_header.go Lines 40 to 74 in 422eb4d
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. So this is the main change and the somewhere else mentioned celestia-node use-case is to re-use this function, right? 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. yep, this is the main change, and celestia-node would use both of the new functions outlined here. This way they would have access to the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return DataAvailabilityHeader{}, fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"invalid square size: min %d max %d provided %d", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
consts.MinSquareSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
consts.MaxSquareSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -50,32 +63,14 @@ func NewDataAvailabilityHeader(squareSize uint64, shares [][]byte) (DataAvailabi | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// check that valid number of shares have been provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if squareSize*squareSize != uint64(len(shares)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return DataAvailabilityHeader{}, fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"must provide valid number of shares for square size: got %d wanted %d", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
len(shares), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
squareSize*squareSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tree := wrapper.NewErasuredNamespacedMerkleTree(squareSize) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO(ismail): for better efficiency and a larger number shares | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// we should switch to the rsmt2d.LeopardFF16 codec: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
extendedDataSquare, err := rsmt2d.ComputeExtendedDataSquare(shares, rsmt2d.NewRSGF8Codec(), tree.Constructor) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return DataAvailabilityHeader{}, err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// generate the row and col roots using the EDS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dah := DataAvailabilityHeader{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RowsRoots: extendedDataSquare.RowRoots(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ColumnRoots: extendedDataSquare.ColRoots(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// generate the hash of the data using the new roots | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dah.Hash() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return dah, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return rsmt2d.ComputeExtendedDataSquare(shares, consts.DefaultCodec(), tree.Constructor) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// String returns hex representation of merkle hash of the DAHeader. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -143,16 +138,16 @@ func (dah *DataAvailabilityHeader) ValidateBasic() error { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if dah == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return errors.New("nil data availability header is not valid") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(dah.ColumnRoots) < minDAHSize || len(dah.RowsRoots) < minDAHSize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(dah.ColumnRoots) < minExtendedSquareWidth || len(dah.RowsRoots) < minExtendedSquareWidth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"minimum valid DataAvailabilityHeader has at least %d row and column roots", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
minDAHSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
minExtendedSquareWidth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(dah.ColumnRoots) > maxDAHSize || len(dah.RowsRoots) > maxDAHSize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(dah.ColumnRoots) > maxExtendedSquareWidth || len(dah.RowsRoots) > maxExtendedSquareWidth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"maximum valid DataAvailabilityHeader has at most %d row and column roots", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
maxDAHSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
maxExtendedSquareWidth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if len(dah.ColumnRoots) != len(dah.RowsRoots) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -190,13 +185,11 @@ func MinDataAvailabilityHeader() DataAvailabilityHeader { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for i := 0; i < consts.MinSharecount; i++ { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shares[i] = tailPaddingShare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dah, err := NewDataAvailabilityHeader( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
consts.MinSquareSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shares, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
eds, err := ExtendShares(consts.MinSquareSize, shares) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
panic(err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dah := NewDataAvailabilityHeader(eds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return dah | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
instead of generating the extended data square for the user, accept it as input to create a data availability header