-
Notifications
You must be signed in to change notification settings - Fork 289
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
feat: support v3 app #3870
feat: support v3 app #3870
Changes from 9 commits
cdcc56e
2025907
e666ddd
d4dd518
122c111
76ef9f3
b1f3223
3ce4e3c
5536bfc
3b6ff9d
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/celestiaorg/celestia-app/v3/app/ante" | ||
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/v3/pkg/da" | ||
square "github.com/celestiaorg/go-square/v2" | ||
"github.com/celestiaorg/go-square/v2/share" | ||
shares "github.com/celestiaorg/go-square/shares" | ||
square "github.com/celestiaorg/go-square/square" | ||
squarev2 "github.com/celestiaorg/go-square/v2" | ||
sharev2 "github.com/celestiaorg/go-square/v2/share" | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
core "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
@@ -27,7 +30,7 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr | |
Height: req.Height, | ||
Time: req.Time, | ||
Version: version.Consensus{ | ||
App: app.BaseApp.AppVersion(), | ||
App: app.AppVersion(), | ||
}, | ||
}) | ||
handler := ante.NewAnteHandler( | ||
|
@@ -47,18 +50,39 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr | |
|
||
// Build the square from the set of valid and prioritised transactions. | ||
// The txs returned are the ones used in the square and block. | ||
dataSquare, txs, err := square.Build(txs, | ||
app.MaxEffectiveSquareSize(sdkCtx), | ||
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion()), | ||
var ( | ||
dataSquareBytes [][]byte | ||
err error | ||
size uint64 | ||
) | ||
switch app.AppVersion() { | ||
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. should we add a unit test to prepare proposal to verify this logic? |
||
case v3: | ||
var dataSquare squarev2.Square | ||
dataSquare, txs, err = squarev2.Build(txs, | ||
app.MaxEffectiveSquareSize(sdkCtx), | ||
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion()), | ||
) | ||
dataSquareBytes = sharev2.ToBytes(dataSquare) | ||
size = uint64(dataSquare.Size()) | ||
case v2, v1: | ||
var dataSquare square.Square | ||
dataSquare, txs, err = square.Build(txs, | ||
app.MaxEffectiveSquareSize(sdkCtx), | ||
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion()), | ||
) | ||
dataSquareBytes = shares.ToBytes(dataSquare) | ||
size = uint64(dataSquare.Size()) | ||
default: | ||
err = fmt.Errorf("unsupported app version: %d", app.AppVersion()) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Erasure encode the data square to create the extended data square (eds). | ||
// Note: uses the nmt wrapper to construct the tree. See | ||
// pkg/wrapper/nmt_wrapper.go for more information. | ||
eds, err := da.ExtendShares(share.ToBytes(dataSquare)) | ||
eds, err := da.ExtendShares(dataSquareBytes) | ||
if err != nil { | ||
app.Logger().Error( | ||
"failure to erasure the data square while creating a proposal block", | ||
|
@@ -84,7 +108,7 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr | |
return abci.ResponsePrepareProposal{ | ||
BlockData: &core.Data{ | ||
Txs: txs, | ||
SquareSize: uint64(dataSquare.Size()), | ||
SquareSize: size, | ||
Hash: dah.Hash(), // also known as the data root | ||
}, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,10 @@ import ( | |
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/v3/pkg/da" | ||
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" | ||
"github.com/celestiaorg/go-square/v2" | ||
"github.com/celestiaorg/go-square/v2/share" | ||
shares "github.com/celestiaorg/go-square/shares" | ||
square "github.com/celestiaorg/go-square/square" | ||
squarev2 "github.com/celestiaorg/go-square/v2" | ||
sharev2 "github.com/celestiaorg/go-square/v2/share" | ||
blobtx "github.com/celestiaorg/go-square/v2/tx" | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
@@ -108,7 +110,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp | |
// - that the sizes match | ||
// - that the namespaces match between blob and PFB | ||
// - that the share commitment is correct | ||
if err := blobtypes.ValidateBlobTx(app.txConfig, blobTx, subtreeRootThreshold); err != nil { | ||
if err := blobtypes.ValidateBlobTx(app.txConfig, blobTx, subtreeRootThreshold, app.AppVersion()); err != nil { | ||
logInvalidPropBlockError(app.Logger(), req.Header, fmt.Sprintf("invalid blob tx %d", idx), err) | ||
return reject() | ||
} | ||
|
@@ -122,24 +124,40 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp | |
|
||
} | ||
|
||
// Construct the data square from the block's transactions | ||
dataSquare, err := square.Construct( | ||
req.BlockData.Txs, | ||
app.MaxEffectiveSquareSize(sdkCtx), | ||
subtreeRootThreshold, | ||
var ( | ||
dataSquareBytes [][]byte | ||
err error | ||
) | ||
if err != nil { | ||
logInvalidPropBlockError(app.Logger(), req.Header, "failure to compute data square from transactions:", err) | ||
|
||
switch app.AppVersion() { | ||
case v3: | ||
var dataSquare squarev2.Square | ||
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. should we add a unit test to process proposal to verify this logic? 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. What logic would this test be verifying? Do we want to build a v3 square with an authored blob and assert that we can parse out the signer or something like that? |
||
dataSquare, err = squarev2.Construct(req.BlockData.Txs, app.MaxEffectiveSquareSize(sdkCtx), subtreeRootThreshold) | ||
dataSquareBytes = sharev2.ToBytes(dataSquare) | ||
// Assert that the square size stated by the proposer is correct | ||
if uint64(dataSquare.Size()) != req.BlockData.SquareSize { | ||
logInvalidPropBlock(app.Logger(), req.Header, "proposed square size differs from calculated square size") | ||
return reject() | ||
} | ||
case v2, v1: | ||
var dataSquare square.Square | ||
dataSquare, err = square.Construct(req.BlockData.Txs, app.MaxEffectiveSquareSize(sdkCtx), subtreeRootThreshold) | ||
dataSquareBytes = shares.ToBytes(dataSquare) | ||
// Assert that the square size stated by the proposer is correct | ||
if uint64(dataSquare.Size()) != req.BlockData.SquareSize { | ||
logInvalidPropBlock(app.Logger(), req.Header, "proposed square size differs from calculated square size") | ||
return reject() | ||
} | ||
default: | ||
logInvalidPropBlock(app.Logger(), req.Header, "unsupported app version") | ||
return reject() | ||
} | ||
|
||
// Assert that the square size stated by the proposer is correct | ||
if uint64(dataSquare.Size()) != req.BlockData.SquareSize { | ||
logInvalidPropBlock(app.Logger(), req.Header, "proposed square size differs from calculated square size") | ||
if err != nil { | ||
logInvalidPropBlockError(app.Logger(), req.Header, "failure to compute data square from transactions:", err) | ||
return reject() | ||
} | ||
|
||
eds, err := da.ExtendShares(share.ToBytes(dataSquare)) | ||
eds, err := da.ExtendShares(dataSquareBytes) | ||
if err != nil { | ||
logInvalidPropBlockError(app.Logger(), req.Header, "failure to erasure the data square", err) | ||
return reject() | ||
|
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.
should we have some kind of test to avoid forgetting to bump versioned ibc modules?