Skip to content

Commit 306c587

Browse files
cmwatersrootulpninabarbakadze
authored
feat: support v3 app (#3870)
Adds v3 as an app version. --------- Co-authored-by: Rootul P <[email protected]> Co-authored-by: nina / ნინა <[email protected]>
1 parent 228a32d commit 306c587

15 files changed

+283
-87
lines changed

app/app.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/celestiaorg/celestia-app/v3/app/posthandler"
1313
appv1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1"
1414
appv2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2"
15+
appv3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3"
1516
"github.com/celestiaorg/celestia-app/v3/pkg/proof"
1617
blobkeeper "github.com/celestiaorg/celestia-app/v3/x/blob/keeper"
1718
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
@@ -108,6 +109,7 @@ var maccPerms = map[string][]string{
108109
const (
109110
v1 = appv1.Version
110111
v2 = appv2.Version
112+
v3 = appv3.Version
111113
DefaultInitialVersion = v1
112114
)
113115

@@ -340,11 +342,11 @@ func New(
340342
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
341343
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
342344
)
343-
// PacketForwardMiddleware is used only for version 2.
344-
transferStack = module.NewVersionedIBCModule(packetForwardMiddleware, transferStack, v2, v2)
345+
// PacketForwardMiddleware is used only for version >= 2.
346+
transferStack = module.NewVersionedIBCModule(packetForwardMiddleware, transferStack, v2, v3)
345347
// Token filter wraps packet forward middleware and is thus the first module in the transfer stack.
346348
tokenFilterMiddelware := tokenfilter.NewIBCMiddleware(transferStack)
347-
transferStack = module.NewVersionedIBCModule(tokenFilterMiddelware, transferStack, v1, v2)
349+
transferStack = module.NewVersionedIBCModule(tokenFilterMiddelware, transferStack, v1, v3)
348350

349351
app.EvidenceKeeper = *evidencekeeper.NewKeeper(
350352
appCodec,

app/check_tx.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
4141
switch req.Type {
4242
// new transactions must be checked in their entirety
4343
case abci.CheckTxType_New:
44-
// FIXME: we have a hardcoded subtree root threshold here. This is because we can't access
45-
// the app version because the context is not initialized
46-
err := blobtypes.ValidateBlobTx(app.txConfig, btx, appconsts.DefaultSubtreeRootThreshold)
44+
appVersion := app.AppVersion()
45+
err := blobtypes.ValidateBlobTx(app.txConfig, btx, appconsts.SubtreeRootThreshold(appVersion), appVersion)
4746
if err != nil {
4847
return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false)
4948
}

app/module/versioned_ibc_module_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestVersionedIBCModule(t *testing.T) {
2323
mockWrappedModule := mocks.NewMockIBCModule(ctrl)
2424
mockNextModule := mocks.NewMockIBCModule(ctrl)
2525

26-
versionedModule := module.NewVersionedIBCModule(mockWrappedModule, mockNextModule, 2, 2)
26+
versionedModule := module.NewVersionedIBCModule(mockWrappedModule, mockNextModule, 2, 3)
2727

2828
testCases := []struct {
2929
name string

app/modules.go

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,95 +96,95 @@ func (app *App) setupModuleManager(skipGenesisInvariants bool) error {
9696
app.manager, err = module.NewManager([]module.VersionedModule{
9797
{
9898
Module: genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, app.txConfig),
99-
FromVersion: v1, ToVersion: v2,
99+
FromVersion: v1, ToVersion: v3,
100100
},
101101
{
102102
Module: auth.NewAppModule(app.appCodec, app.AccountKeeper, nil),
103-
FromVersion: v1, ToVersion: v2,
103+
FromVersion: v1, ToVersion: v3,
104104
},
105105
{
106106
Module: vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
107-
FromVersion: v1, ToVersion: v2,
107+
FromVersion: v1, ToVersion: v3,
108108
},
109109
{
110110
Module: bank.NewAppModule(app.appCodec, app.BankKeeper, app.AccountKeeper),
111-
FromVersion: v1, ToVersion: v2,
111+
FromVersion: v1, ToVersion: v3,
112112
},
113113
{
114114
Module: capability.NewAppModule(app.appCodec, *app.CapabilityKeeper),
115-
FromVersion: v1, ToVersion: v2,
115+
FromVersion: v1, ToVersion: v3,
116116
},
117117
{
118118
Module: feegrantmodule.NewAppModule(app.appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
119-
FromVersion: v1, ToVersion: v2,
119+
FromVersion: v1, ToVersion: v3,
120120
},
121121
{
122122
Module: crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
123-
FromVersion: v1, ToVersion: v2,
123+
FromVersion: v1, ToVersion: v3,
124124
},
125125
{
126126
Module: gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
127-
FromVersion: v1, ToVersion: v2,
127+
FromVersion: v1, ToVersion: v3,
128128
},
129129
{
130130
Module: mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper),
131-
FromVersion: v1, ToVersion: v2,
131+
FromVersion: v1, ToVersion: v3,
132132
},
133133
{
134134
Module: slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
135-
FromVersion: v1, ToVersion: v2,
135+
FromVersion: v1, ToVersion: v3,
136136
},
137137
{
138138
Module: distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
139-
FromVersion: v1, ToVersion: v2,
139+
FromVersion: v1, ToVersion: v3,
140140
},
141141
{
142142
Module: staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
143-
FromVersion: v1, ToVersion: v2,
143+
FromVersion: v1, ToVersion: v3,
144144
},
145145
{
146146
Module: evidence.NewAppModule(app.EvidenceKeeper),
147-
FromVersion: v1, ToVersion: v2,
147+
FromVersion: v1, ToVersion: v3,
148148
},
149149
{
150150
Module: authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
151-
FromVersion: v1, ToVersion: v2,
151+
FromVersion: v1, ToVersion: v3,
152152
},
153153
{
154154
Module: ibc.NewAppModule(app.IBCKeeper),
155-
FromVersion: v1, ToVersion: v2,
155+
FromVersion: v1, ToVersion: v3,
156156
},
157157
{
158158
Module: params.NewAppModule(app.ParamsKeeper),
159-
FromVersion: v1, ToVersion: v2,
159+
FromVersion: v1, ToVersion: v3,
160160
},
161161
{
162162
Module: transfer.NewAppModule(app.TransferKeeper),
163-
FromVersion: v1, ToVersion: v2,
163+
FromVersion: v1, ToVersion: v3,
164164
},
165165
{
166166
Module: blob.NewAppModule(app.appCodec, app.BlobKeeper),
167-
FromVersion: v1, ToVersion: v2,
167+
FromVersion: v1, ToVersion: v3,
168168
},
169169
{
170170
Module: blobstream.NewAppModule(app.appCodec, app.BlobstreamKeeper),
171171
FromVersion: v1, ToVersion: v1,
172172
},
173173
{
174174
Module: signal.NewAppModule(app.SignalKeeper),
175-
FromVersion: v2, ToVersion: v2,
175+
FromVersion: v2, ToVersion: v3,
176176
},
177177
{
178178
Module: minfee.NewAppModule(app.ParamsKeeper),
179-
FromVersion: v2, ToVersion: v2,
179+
FromVersion: v2, ToVersion: v3,
180180
},
181181
{
182182
Module: packetforward.NewAppModule(app.PacketForwardKeeper),
183-
FromVersion: v2, ToVersion: v2,
183+
FromVersion: v2, ToVersion: v3,
184184
},
185185
{
186186
Module: ica.NewAppModule(nil, &app.ICAHostKeeper),
187-
FromVersion: v2, ToVersion: v2,
187+
FromVersion: v2, ToVersion: v3,
188188
},
189189
})
190190
if err != nil {
@@ -303,7 +303,7 @@ func allStoreKeys() []string {
303303
// versionedStoreKeys returns the store keys for each app version.
304304
func versionedStoreKeys() map[uint64][]string {
305305
return map[uint64][]string{
306-
1: {
306+
v1: {
307307
authtypes.StoreKey,
308308
authzkeeper.StoreKey,
309309
banktypes.StoreKey,
@@ -321,7 +321,7 @@ func versionedStoreKeys() map[uint64][]string {
321321
stakingtypes.StoreKey,
322322
upgradetypes.StoreKey,
323323
},
324-
2: {
324+
v2: {
325325
authtypes.StoreKey,
326326
authzkeeper.StoreKey,
327327
banktypes.StoreKey,
@@ -341,6 +341,26 @@ func versionedStoreKeys() map[uint64][]string {
341341
stakingtypes.StoreKey,
342342
upgradetypes.StoreKey,
343343
},
344+
v3: { // same as v2
345+
authtypes.StoreKey,
346+
authzkeeper.StoreKey,
347+
banktypes.StoreKey,
348+
blobtypes.StoreKey,
349+
capabilitytypes.StoreKey,
350+
distrtypes.StoreKey,
351+
evidencetypes.StoreKey,
352+
feegrant.StoreKey,
353+
govtypes.StoreKey,
354+
ibchost.StoreKey,
355+
ibctransfertypes.StoreKey,
356+
icahosttypes.StoreKey,
357+
minttypes.StoreKey,
358+
packetforwardtypes.StoreKey,
359+
signaltypes.StoreKey,
360+
slashingtypes.StoreKey,
361+
stakingtypes.StoreKey,
362+
upgradetypes.StoreKey,
363+
},
344364
}
345365
}
346366

app/prepare_proposal.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package app
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/celestiaorg/celestia-app/v3/app/ante"
78
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
89
"github.com/celestiaorg/celestia-app/v3/pkg/da"
9-
square "github.com/celestiaorg/go-square/v2"
10-
"github.com/celestiaorg/go-square/v2/share"
10+
shares "github.com/celestiaorg/go-square/shares"
11+
square "github.com/celestiaorg/go-square/square"
12+
squarev2 "github.com/celestiaorg/go-square/v2"
13+
sharev2 "github.com/celestiaorg/go-square/v2/share"
1114
"github.com/cosmos/cosmos-sdk/telemetry"
1215
abci "github.com/tendermint/tendermint/abci/types"
1316
core "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -27,7 +30,7 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr
2730
Height: req.Height,
2831
Time: req.Time,
2932
Version: version.Consensus{
30-
App: app.BaseApp.AppVersion(),
33+
App: app.AppVersion(),
3134
},
3235
})
3336
handler := ante.NewAnteHandler(
@@ -47,18 +50,39 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr
4750

4851
// Build the square from the set of valid and prioritised transactions.
4952
// The txs returned are the ones used in the square and block.
50-
dataSquare, txs, err := square.Build(txs,
51-
app.MaxEffectiveSquareSize(sdkCtx),
52-
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion()),
53+
var (
54+
dataSquareBytes [][]byte
55+
err error
56+
size uint64
5357
)
58+
switch app.AppVersion() {
59+
case v3:
60+
var dataSquare squarev2.Square
61+
dataSquare, txs, err = squarev2.Build(txs,
62+
app.MaxEffectiveSquareSize(sdkCtx),
63+
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion()),
64+
)
65+
dataSquareBytes = sharev2.ToBytes(dataSquare)
66+
size = uint64(dataSquare.Size())
67+
case v2, v1:
68+
var dataSquare square.Square
69+
dataSquare, txs, err = square.Build(txs,
70+
app.MaxEffectiveSquareSize(sdkCtx),
71+
appconsts.SubtreeRootThreshold(app.GetBaseApp().AppVersion()),
72+
)
73+
dataSquareBytes = shares.ToBytes(dataSquare)
74+
size = uint64(dataSquare.Size())
75+
default:
76+
err = fmt.Errorf("unsupported app version: %d", app.AppVersion())
77+
}
5478
if err != nil {
5579
panic(err)
5680
}
5781

5882
// Erasure encode the data square to create the extended data square (eds).
5983
// Note: uses the nmt wrapper to construct the tree. See
6084
// pkg/wrapper/nmt_wrapper.go for more information.
61-
eds, err := da.ExtendShares(share.ToBytes(dataSquare))
85+
eds, err := da.ExtendShares(dataSquareBytes)
6286
if err != nil {
6387
app.Logger().Error(
6488
"failure to erasure the data square while creating a proposal block",
@@ -84,7 +108,7 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr
84108
return abci.ResponsePrepareProposal{
85109
BlockData: &core.Data{
86110
Txs: txs,
87-
SquareSize: uint64(dataSquare.Size()),
111+
SquareSize: size,
88112
Hash: dah.Hash(), // also known as the data root
89113
},
90114
}

app/process_proposal.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
1010
"github.com/celestiaorg/celestia-app/v3/pkg/da"
1111
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
12-
"github.com/celestiaorg/go-square/v2"
13-
"github.com/celestiaorg/go-square/v2/share"
12+
shares "github.com/celestiaorg/go-square/shares"
13+
square "github.com/celestiaorg/go-square/square"
14+
squarev2 "github.com/celestiaorg/go-square/v2"
15+
sharev2 "github.com/celestiaorg/go-square/v2/share"
1416
blobtx "github.com/celestiaorg/go-square/v2/tx"
1517
"github.com/cosmos/cosmos-sdk/telemetry"
1618
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -108,7 +110,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
108110
// - that the sizes match
109111
// - that the namespaces match between blob and PFB
110112
// - that the share commitment is correct
111-
if err := blobtypes.ValidateBlobTx(app.txConfig, blobTx, subtreeRootThreshold); err != nil {
113+
if err := blobtypes.ValidateBlobTx(app.txConfig, blobTx, subtreeRootThreshold, app.AppVersion()); err != nil {
112114
logInvalidPropBlockError(app.Logger(), req.Header, fmt.Sprintf("invalid blob tx %d", idx), err)
113115
return reject()
114116
}
@@ -122,24 +124,40 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
122124

123125
}
124126

125-
// Construct the data square from the block's transactions
126-
dataSquare, err := square.Construct(
127-
req.BlockData.Txs,
128-
app.MaxEffectiveSquareSize(sdkCtx),
129-
subtreeRootThreshold,
127+
var (
128+
dataSquareBytes [][]byte
129+
err error
130130
)
131-
if err != nil {
132-
logInvalidPropBlockError(app.Logger(), req.Header, "failure to compute data square from transactions:", err)
131+
132+
switch app.AppVersion() {
133+
case v3:
134+
var dataSquare squarev2.Square
135+
dataSquare, err = squarev2.Construct(req.BlockData.Txs, app.MaxEffectiveSquareSize(sdkCtx), subtreeRootThreshold)
136+
dataSquareBytes = sharev2.ToBytes(dataSquare)
137+
// Assert that the square size stated by the proposer is correct
138+
if uint64(dataSquare.Size()) != req.BlockData.SquareSize {
139+
logInvalidPropBlock(app.Logger(), req.Header, "proposed square size differs from calculated square size")
140+
return reject()
141+
}
142+
case v2, v1:
143+
var dataSquare square.Square
144+
dataSquare, err = square.Construct(req.BlockData.Txs, app.MaxEffectiveSquareSize(sdkCtx), subtreeRootThreshold)
145+
dataSquareBytes = shares.ToBytes(dataSquare)
146+
// Assert that the square size stated by the proposer is correct
147+
if uint64(dataSquare.Size()) != req.BlockData.SquareSize {
148+
logInvalidPropBlock(app.Logger(), req.Header, "proposed square size differs from calculated square size")
149+
return reject()
150+
}
151+
default:
152+
logInvalidPropBlock(app.Logger(), req.Header, "unsupported app version")
133153
return reject()
134154
}
135-
136-
// Assert that the square size stated by the proposer is correct
137-
if uint64(dataSquare.Size()) != req.BlockData.SquareSize {
138-
logInvalidPropBlock(app.Logger(), req.Header, "proposed square size differs from calculated square size")
155+
if err != nil {
156+
logInvalidPropBlockError(app.Logger(), req.Header, "failure to compute data square from transactions:", err)
139157
return reject()
140158
}
141159

142-
eds, err := da.ExtendShares(share.ToBytes(dataSquare))
160+
eds, err := da.ExtendShares(dataSquareBytes)
143161
if err != nil {
144162
logInvalidPropBlockError(app.Logger(), req.Header, "failure to erasure the data square", err)
145163
return reject()

app/test/std_sdk_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/celestiaorg/celestia-app/v3/app"
99
"github.com/celestiaorg/celestia-app/v3/app/encoding"
1010
"github.com/celestiaorg/celestia-app/v3/app/grpc/tx"
11+
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
1112
v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2"
1213
"github.com/celestiaorg/celestia-app/v3/pkg/user"
1314
"github.com/celestiaorg/celestia-app/v3/test/util/blobfactory"
@@ -307,7 +308,7 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() {
307308
name: "signal a version change",
308309
msgFunc: func() (msgs []sdk.Msg, signer string) {
309310
valAccount := s.getValidatorAccount()
310-
msg := signal.NewMsgSignalVersion(valAccount, 2)
311+
msg := signal.NewMsgSignalVersion(valAccount, appconsts.LatestVersion+1)
311312
return []sdk.Msg{msg}, s.getValidatorName()
312313
},
313314
expectedCode: abci.CodeTypeOK,

0 commit comments

Comments
 (0)