-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reintroduce the blobstream module
- Loading branch information
Showing
12 changed files
with
422 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package blobstream | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
var _ Module = (*API)(nil) | ||
|
||
// Module defines the API related to interacting with the data root tuples proofs | ||
// | ||
//go:generate mockgen -destination=mocks/api.go -package=mocks . Module | ||
type Module interface { | ||
// GetDataRootTupleRoot collects the data roots over a provided ordered range of blocks, | ||
// and then creates a new Merkle root of those data roots. The range is end exclusive. | ||
// It's in the header module because it only needs access to the headers to generate the proof. | ||
GetDataRootTupleRoot(ctx context.Context, start, end uint64) (*DataRootTupleRoot, error) | ||
|
||
// GetDataRootTupleInclusionProof creates an inclusion proof, for the data root tuple of block | ||
// height `height`, in the set of blocks defined by `start` and `end`. The range | ||
// is end exclusive. | ||
// It's in the header module because it only needs access to the headers to generate the proof. | ||
GetDataRootTupleInclusionProof( | ||
ctx context.Context, | ||
height, start, end uint64, | ||
) (*DataRootTupleInclusionProof, error) | ||
} | ||
|
||
// API is a wrapper around the Module for RPC. | ||
type API struct { | ||
Internal struct { | ||
GetDataRootTupleRoot func(ctx context.Context, start, end uint64) (*DataRootTupleRoot, error) `perm:"read"` | ||
GetDataRootTupleInclusionProof func( | ||
ctx context.Context, | ||
height, start, end uint64, | ||
) (*DataRootTupleInclusionProof, error) `perm:"read"` | ||
} | ||
} | ||
|
||
func (api *API) GetDataRootTupleRoot(ctx context.Context, start, end uint64) (*DataRootTupleRoot, error) { | ||
return api.Internal.GetDataRootTupleRoot(ctx, start, end) | ||
} | ||
|
||
func (api *API) GetDataRootTupleInclusionProof( | ||
ctx context.Context, | ||
height, start, end uint64, | ||
) (*DataRootTupleInclusionProof, error) { | ||
return api.Internal.GetDataRootTupleInclusionProof(ctx, height, start, end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package blobstream | ||
|
||
import "go.uber.org/fx" | ||
|
||
func ConstructModule() fx.Option { | ||
return fx.Module("blobstream", | ||
fx.Provide(NewService), | ||
fx.Provide(func(serv *Service) Module { | ||
return serv | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package blobstream | ||
|
||
import ( | ||
"context" | ||
|
||
logging "github.com/ipfs/go-log/v2" | ||
|
||
headerServ "github.com/celestiaorg/celestia-node/nodebuilder/header" | ||
) | ||
|
||
var _ Module = (*Service)(nil) | ||
|
||
var log = logging.Logger("go-blobstream") | ||
|
||
type Service struct { | ||
headerServ headerServ.Module | ||
} | ||
|
||
func NewService(headerMod headerServ.Module) *Service { | ||
return &Service{ | ||
headerServ: headerMod, | ||
} | ||
} | ||
|
||
// GetDataRootTupleRoot collects the data roots over a provided ordered range of blocks, | ||
// and then creates a new Merkle root of those data roots. The range is end exclusive. | ||
func (s *Service) GetDataRootTupleRoot(ctx context.Context, start, end uint64) (*DataRootTupleRoot, error) { | ||
log.Debugw("validating the data commitment range", "start", start, "end", end) | ||
err := s.validateDataRootTupleRootRange(ctx, start, end) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Debugw("fetching the data root tuples", "start", start, "end", end) | ||
encodedDataRootTuples, err := s.fetchEncodedDataRootTuples(ctx, start, end) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Debugw("hashing the data root tuples", "start", start, "end", end) | ||
root, err := hashDataRootTuples(encodedDataRootTuples) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// Create data commitment | ||
dataRootTupleRoot := DataRootTupleRoot(root) | ||
return &dataRootTupleRoot, nil | ||
} | ||
|
||
// GetDataRootTupleInclusionProof creates an inclusion proof for the data root of block | ||
// height `height` in the set of blocks defined by `start` and `end`. The range | ||
// is end exclusive. | ||
func (s *Service) GetDataRootTupleInclusionProof( | ||
ctx context.Context, | ||
height, start, end uint64, | ||
) (*DataRootTupleInclusionProof, error) { | ||
log.Debugw( | ||
"validating the data root inclusion proof request", | ||
"start", | ||
start, | ||
"end", | ||
end, | ||
"height", | ||
height, | ||
) | ||
err := s.validateDataRootInclusionProofRequest(ctx, height, start, end) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Debugw("fetching the data root tuples", "start", start, "end", end) | ||
|
||
encodedDataRootTuples, err := s.fetchEncodedDataRootTuples(ctx, start, end) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Debugw("proving the data root tuples", "start", start, "end", end) | ||
proof, err := proveDataRootTuples(encodedDataRootTuples, start, height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
dataRootTupleInclusionProof := DataRootTupleInclusionProof(proof) | ||
return &dataRootTupleInclusionProof, nil | ||
} |
Oops, something went wrong.