-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
26 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
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
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
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
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
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
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,21 @@ | ||
package block | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/celestiaorg/rsmt2d" | ||
|
||
"github.com/celestiaorg/celestia-core/pkg/da" | ||
"github.com/celestiaorg/celestia-node/ipld" | ||
) | ||
|
||
func (s *Service) StoreBlockData(ctx context.Context, data *ExtendedBlockData) error { | ||
shares := ipld.ConvertEDStoShares(data) | ||
// TODO @renaynay: it's inefficient that we generate the EDS twice | ||
_, err := ipld.PutData(ctx, shares, s.store) | ||
return err | ||
} | ||
|
||
func (s *Service) GetBlockData(ctx context.Context, dah *da.DataAvailabilityHeader) (*ExtendedBlockData, error) { | ||
return ipld.RetrieveData(ctx, dah, s.store, rsmt2d.NewRSGF8Codec()) | ||
} |
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,30 @@ | ||
package block | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
md "github.com/ipfs/go-merkledag/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestService_BlockStore(t *testing.T) { | ||
// create mock block service (fetcher is not necessary here) | ||
mockStore := md.Mock() | ||
serv := NewBlockService(nil, mockStore) | ||
|
||
_, block := generateRawAndExtendedBlock(t) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
err := serv.StoreBlockData(ctx, block.Data()) | ||
require.NoError(t, err) | ||
|
||
eds, err := serv.GetBlockData(ctx, block.Header().DAH) | ||
require.NoError(t, err) | ||
assert.Equal(t, block.data.Width(), eds.Width()) | ||
assert.Equal(t, block.data.RowRoots(), eds.RowRoots()) | ||
assert.Equal(t, block.data.ColRoots(), eds.ColRoots()) | ||
} |
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