Skip to content

Commit

Permalink
chore: move share encoding logic from core -> app
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Aug 17, 2022
1 parent a5877a4 commit 8a25644
Show file tree
Hide file tree
Showing 9 changed files with 1,361 additions and 8 deletions.
5 changes: 3 additions & 2 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"bytes"

shares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/x/payment/types"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -120,15 +121,15 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) abci.ResponsePr
}
}

shares, _, err := data.ComputeShares(req.BlockData.OriginalSquareSize)
nsshares, _, err := shares.ComputeShares(&data, req.BlockData.OriginalSquareSize)
if err != nil {
app.Logger().Error(rejectedPropBlockLog, "reason", "failure to compute shares from block data:", "error", err, "proposerAddress", req.Header.ProposerAddress)
return abci.ResponseProcessProposal{
Result: abci.ResponseProcessProposal_REJECT,
}
}

eds, err := da.ExtendShares(req.BlockData.OriginalSquareSize, shares.RawShares())
eds, err := da.ExtendShares(req.BlockData.OriginalSquareSize, nsshares.RawShares())
if err != nil {
app.Logger().Error(
rejectedPropBlockLog,
Expand Down
3 changes: 2 additions & 1 deletion app/split_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"sort"

shares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand Down Expand Up @@ -136,7 +137,7 @@ func newShareSplitter(txConf client.TxConfig, squareSize uint64, data *core.Data
if err != nil {
panic(err)
}
sqwr.evdShares = evdData.SplitIntoShares().RawShares()
sqwr.evdShares = shares.SplitEvidenceIntoShares(evdData).RawShares()

sqwr.txWriter = coretypes.NewContiguousShareWriter(consts.TxNamespaceID)
sqwr.msgWriter = coretypes.NewMessageShareWriter()
Expand Down
7 changes: 4 additions & 3 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
shares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/testutil"
"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/celestiaorg/nmt/namespace"
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestMessageInclusionCheck(t *testing.T) {
data, err := coretypes.DataFromProto(tt.input.BlockData)
require.NoError(t, err)

shares, _, err := data.ComputeShares(tt.input.BlockData.OriginalSquareSize)
shares, _, err := shares.ComputeShares(&data, tt.input.BlockData.OriginalSquareSize)
require.NoError(t, err)

rawShares := shares.RawShares()
Expand Down Expand Up @@ -206,7 +207,7 @@ func TestProcessMessagesWithReservedNamespaces(t *testing.T) {
data, err := coretypes.DataFromProto(input.BlockData)
require.NoError(t, err)

shares, _, err := data.ComputeShares(input.BlockData.OriginalSquareSize)
shares, _, err := shares.ComputeShares(&data, input.BlockData.OriginalSquareSize)
require.NoError(t, err)

rawShares := shares.RawShares()
Expand Down Expand Up @@ -257,7 +258,7 @@ func TestProcessMessageWithUnsortedMessages(t *testing.T) {
data, err := coretypes.DataFromProto(input.BlockData)
require.NoError(t, err)

shares, _, err := data.ComputeShares(input.BlockData.OriginalSquareSize)
shares, _, err := shares.ComputeShares(&data, input.BlockData.OriginalSquareSize)
require.NoError(t, err)

rawShares := shares.RawShares()
Expand Down
3 changes: 2 additions & 1 deletion app/test/split_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
shares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestSplitShares(t *testing.T) {

assert.Equal(t, data.Txs, parsedData.Txs.ToSliceOfBytes())

parsedShares, _, err := parsedData.ComputeShares(tt.squareSize)
parsedShares, _, err := shares.ComputeShares(&parsedData, tt.squareSize)
require.NoError(t, err)

require.Equal(t, square, parsedShares.RawShares())
Expand Down
Loading

0 comments on commit 8a25644

Please sign in to comment.