diff --git a/app/app.go b/app/app.go index 832803804e..7f7ba2e959 100644 --- a/app/app.go +++ b/app/app.go @@ -5,11 +5,24 @@ import ( "io" "slices" + "github.com/celestiaorg/celestia-app/v2/app/ante" + "github.com/celestiaorg/celestia-app/v2/app/encoding" "github.com/celestiaorg/celestia-app/v2/app/module" "github.com/celestiaorg/celestia-app/v2/app/posthandler" + appv1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" + appv2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" + "github.com/celestiaorg/celestia-app/v2/pkg/proof" + blobkeeper "github.com/celestiaorg/celestia-app/v2/x/blob/keeper" + blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" + blobstreamkeeper "github.com/celestiaorg/celestia-app/v2/x/blobstream/keeper" + blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types" "github.com/celestiaorg/celestia-app/v2/x/minfee" mintkeeper "github.com/celestiaorg/celestia-app/v2/x/mint/keeper" minttypes "github.com/celestiaorg/celestia-app/v2/x/mint/types" + "github.com/celestiaorg/celestia-app/v2/x/paramfilter" + "github.com/celestiaorg/celestia-app/v2/x/signal" + signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types" + "github.com/celestiaorg/celestia-app/v2/x/tokenfilter" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" @@ -54,6 +67,13 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" + packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" + icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" "github.com/cosmos/ibc-go/v6/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" @@ -61,37 +81,13 @@ import ( ibcporttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types" "github.com/spf13/cast" abci "github.com/tendermint/tendermint/abci/types" tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - - "github.com/celestiaorg/celestia-app/v2/app/ante" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - appv1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" - appv2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" - "github.com/celestiaorg/celestia-app/v2/pkg/proof" - blobkeeper "github.com/celestiaorg/celestia-app/v2/x/blob/keeper" - blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" - "github.com/celestiaorg/celestia-app/v2/x/paramfilter" - "github.com/celestiaorg/celestia-app/v2/x/tokenfilter" - - blobstreamkeeper "github.com/celestiaorg/celestia-app/v2/x/blobstream/keeper" - blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types" - "github.com/celestiaorg/celestia-app/v2/x/signal" - signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types" - ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types" - - "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" - packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper" - packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" - - icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host" - icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper" - icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" - icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" ) // maccPerms is short for module account permissions. @@ -153,18 +149,18 @@ type App struct { FeeGrantKeeper feegrantkeeper.Keeper ICAHostKeeper icahostkeeper.Keeper PacketForwardKeeper *packetforwardkeeper.Keeper + BlobKeeper blobkeeper.Keeper + BlobstreamKeeper blobstreamkeeper.Keeper ScopedIBCKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes ScopedTransferKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes ScopedICAHostKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes - BlobKeeper blobkeeper.Keeper - BlobstreamKeeper blobstreamkeeper.Keeper - mm *module.Manager configurator module.Configurator - // used as a coordination mechanism for height based upgrades - upgradeHeight int64 + // upgradeHeightV2 is used as a coordination mechanism for the height-based + // upgrade from v1 to v2. + upgradeHeightV2 int64 // used to define what messages are accepted for a given app version MsgGateKeeper *ante.MsgVersioningGateKeeper } @@ -180,7 +176,7 @@ func New( traceStore io.Writer, invCheckPeriod uint, encodingConfig encoding.Config, - upgradeHeight int64, + upgradeHeightV2 int64, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { @@ -207,6 +203,7 @@ func New( keys: keys, tkeys: tkeys, memKeys: memKeys, + upgradeHeightV2: upgradeHeightV2, } app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) @@ -259,7 +256,6 @@ func New( // upgrade. This keeper is not used for the actual upgrades but merely for compatibility reasons. Ideally IBC has their own upgrade module // for performing IBC based upgrades. Note, as we use rolling upgrades, IBC technically never needs this functionality. app.UpgradeKeeper = upgradekeeper.NewKeeper(nil, keys[upgradetypes.StoreKey], appCodec, "", app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - app.upgradeHeight = upgradeHeight app.BlobstreamKeeper = *blobstreamkeeper.NewKeeper( appCodec, @@ -268,10 +264,11 @@ func New( &stakingKeeper, ) - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks + // Register the staking hooks. NOTE: stakingKeeper is passed by reference + // above so that it will contain these hooks. app.StakingKeeper = *stakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), + stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), app.BlobstreamKeeper.Hooks(), ), @@ -341,18 +338,23 @@ func New( packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout ) - // Create evidence Keeper for to register the IBC light client misbehaviour evidence route - evidenceKeeper := evidencekeeper.NewKeeper( - appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper, + app.EvidenceKeeper = *evidencekeeper.NewKeeper( + appCodec, + keys[evidencetypes.StoreKey], + &app.StakingKeeper, + app.SlashingKeeper, ) - // If evidence needs to be handled for the app, set routes in router here and seal - app.EvidenceKeeper = *evidenceKeeper - - govConfig := govtypes.DefaultConfig() app.GovKeeper = govkeeper.NewKeeper( - appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, - &stakingKeeper, govRouter, bApp.MsgServiceRouter(), govConfig, + appCodec, + keys[govtypes.StoreKey], + app.GetSubspace(govtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + &stakingKeeper, + govRouter, + bApp.MsgServiceRouter(), + govtypes.DefaultConfig(), ) app.BlobKeeper = *blobkeeper.NewKeeper( @@ -399,7 +401,6 @@ func New( app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) - // initialize BaseApp app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) @@ -446,7 +447,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // For v1 only we upgrade using a agreed upon height known ahead of time if currentVersion == v1 { // check that we are at the height before the upgrade - if req.Height == app.upgradeHeight-1 { + if req.Height == app.upgradeHeightV2-1 { app.SetInitialAppVersionInConsensusParams(ctx, v2) app.SetAppVersion(ctx, v2) } diff --git a/app/app_test.go b/app/app_test.go index b83a0f9c68..b2aa6ca064 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -27,6 +27,15 @@ func TestNew(t *testing.T) { t.Run("initializes ScopedICAHostKeeper", func(t *testing.T) { assert.NotNil(t, got.ScopedICAHostKeeper) }) + t.Run("initializes StakingKeeper", func(t *testing.T) { + assert.NotNil(t, got.StakingKeeper) + }) + t.Run("should have set StakingKeeper hooks", func(t *testing.T) { + // StakingKeeper doesn't expose a GetHooks method so this checks if + // hooks have been set by verifying the a subsequent call to SetHooks + // will panic. + assert.Panics(t, func() { got.StakingKeeper.SetHooks(nil) }) + }) } // NoopWriter is a no-op implementation of a writer. diff --git a/app/modules.go b/app/modules.go index 210d0f75cd..85dd05049f 100644 --- a/app/modules.go +++ b/app/modules.go @@ -307,39 +307,39 @@ func versionedStoreKeys() map[uint64][]string { authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, - stakingtypes.StoreKey, - minttypes.StoreKey, + blobstreamtypes.StoreKey, + blobtypes.StoreKey, + capabilitytypes.StoreKey, distrtypes.StoreKey, - slashingtypes.StoreKey, - govtypes.StoreKey, - upgradetypes.StoreKey, - feegrant.StoreKey, evidencetypes.StoreKey, - capabilitytypes.StoreKey, - blobstreamtypes.StoreKey, - ibctransfertypes.StoreKey, + feegrant.StoreKey, + govtypes.StoreKey, ibchost.StoreKey, - blobtypes.StoreKey, + ibctransfertypes.StoreKey, + minttypes.StoreKey, + slashingtypes.StoreKey, + stakingtypes.StoreKey, + upgradetypes.StoreKey, }, 2: { authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, - stakingtypes.StoreKey, - minttypes.StoreKey, + blobstreamtypes.StoreKey, + capabilitytypes.StoreKey, distrtypes.StoreKey, - slashingtypes.StoreKey, - govtypes.StoreKey, - upgradetypes.StoreKey, - feegrant.StoreKey, evidencetypes.StoreKey, - capabilitytypes.StoreKey, - blobstreamtypes.StoreKey, - ibctransfertypes.StoreKey, + feegrant.StoreKey, + govtypes.StoreKey, ibchost.StoreKey, - packetforwardtypes.StoreKey, + ibctransfertypes.StoreKey, icahosttypes.StoreKey, + minttypes.StoreKey, + packetforwardtypes.StoreKey, signaltypes.StoreKey, + slashingtypes.StoreKey, + stakingtypes.StoreKey, + upgradetypes.StoreKey, }, } } diff --git a/go.mod b/go.mod index 491c2ff94f..37cb5f81e5 100644 --- a/go.mod +++ b/go.mod @@ -15,8 +15,8 @@ require ( github.com/cosmos/cosmos-sdk v0.46.16 github.com/cosmos/gogoproto v1.4.12 github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2 - github.com/cosmos/ibc-go/v6 v6.3.0 - github.com/ethereum/go-ethereum v1.13.15 + github.com/cosmos/ibc-go/v6 v6.3.1 + github.com/ethereum/go-ethereum v1.14.0 github.com/gogo/protobuf v1.3.3 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.4 @@ -74,7 +74,7 @@ require ( github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.19.6 // indirect github.com/cosmos/ledger-cosmos-go v0.13.2 // indirect - github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect + github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/danieljoos/wincred v1.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -92,7 +92,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.6.0 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/ethereum/c-kzg-4844 v0.4.0 // indirect + github.com/ethereum/c-kzg-4844 v1.0.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-kit/kit v0.12.0 // indirect @@ -225,16 +225,16 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/mod v0.14.0 // indirect - golang.org/x/net v0.23.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.17.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/term v0.18.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect - golang.org/x/tools v0.17.0 // indirect + golang.org/x/tools v0.20.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/api v0.162.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/go.sum b/go.sum index e7122025b2..b2d741136a 100644 --- a/go.sum +++ b/go.sum @@ -384,16 +384,14 @@ github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y= -github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac= -github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY= -github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= -github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 h1:aPEJyR4rPBvDmeyi+l/FS/VtA00IWvjeFvjen1m1l1A= -github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593/go.mod h1:6hk1eMY/u5t+Cf18q5lFMUA1Rc+Sm5I6Ra1QuPyxXCo= -github.com/cockroachdb/redact v1.0.8 h1:8QG/764wK+vmEYoOlfobpe12EQcS81ukx/a4hdVMxNw= -github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM= -github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= +github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= +github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= +github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= +github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= @@ -437,8 +435,8 @@ github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU= github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2 h1:Hz4nkpStoXIHrC77CIEyu2mRiN2qysGEZPFRf0fpv7w= github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.2/go.mod h1:Jo934o/sW7fNxuOa/TjCalSalz+1Fd649eLyANaJx8g= -github.com/cosmos/ibc-go/v6 v6.3.0 h1:2EkkqDEd9hTQvzB/BsPhYZsu7T/dzAVA8+VD2UuJLSQ= -github.com/cosmos/ibc-go/v6 v6.3.0/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w= +github.com/cosmos/ibc-go/v6 v6.3.1 h1:/5ur3AsmNW8WuOevfODHlaY5Ze236PBNE3vVo9o3fQA= +github.com/cosmos/ibc-go/v6 v6.3.1/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w= github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw= github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= @@ -448,8 +446,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0q github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= -github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= -github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/crate-crypto/go-kzg-4844 v1.0.0 h1:TsSgHwrkTKecKJ4kadtHi4b3xHW5dCFUDFnUp1TsawI= +github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM= github.com/creachadair/taskgroup v0.3.2/go.mod h1:wieWwecHVzsidg2CsUnFinW1faVN4+kq+TDlRJQ0Wbk= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= @@ -528,11 +526,11 @@ github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go. github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= -github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY= -github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA= +github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/ethereum/go-ethereum v1.13.15 h1:U7sSGYGo4SPjP6iNIifNoyIAiNjrmQkz6EwQG+/EZWo= -github.com/ethereum/go-ethereum v1.13.15/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= +github.com/ethereum/go-ethereum v1.14.0 h1:xRWC5NlB6g1x7vNy4HDBLuqVNbtLrc7v8S6+Uxim1LU= +github.com/ethereum/go-ethereum v1.14.0/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= @@ -565,6 +563,8 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= +github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= +github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1453,8 +1453,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1498,8 +1498,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1566,8 +1566,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1726,14 +1726,14 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1820,8 +1820,8 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= +golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/proof/proof.go b/pkg/proof/proof.go index ca4a6091cf..4860a63d85 100644 --- a/pkg/proof/proof.go +++ b/pkg/proof/proof.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "math" "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" "github.com/celestiaorg/celestia-app/v2/pkg/da" @@ -32,7 +33,11 @@ func NewTxInclusionProof(txs [][]byte, txIndex, appVersion uint64) (ShareProof, return ShareProof{}, err } - shareRange, err := builder.FindTxShareRange(int(txIndex)) + txIndexInt, err := safeConvertUint64ToInt(txIndex) + if err != nil { + return ShareProof{}, err + } + shareRange, err := builder.FindTxShareRange(txIndexInt) if err != nil { return ShareProof{}, err } @@ -165,3 +170,10 @@ func NewShareInclusionProof( NamespaceVersion: uint32(namespace.Version), }, nil } + +func safeConvertUint64ToInt(val uint64) (int, error) { + if val > math.MaxInt { + return 0, fmt.Errorf("value %d is too large to convert to int", val) + } + return int(val), nil +} diff --git a/pkg/proof/querier.go b/pkg/proof/querier.go index f9cb7b0a47..3f10220860 100644 --- a/pkg/proof/querier.go +++ b/pkg/proof/querier.go @@ -3,6 +3,7 @@ package proof import ( "bytes" "fmt" + "math" "strconv" "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" @@ -98,17 +99,23 @@ func QueryShareInclusionProof(_ sdk.Context, path []string, req abci.RequestQuer return nil, err } - nID, err := ParseNamespace(dataSquare, int(beginShare), int(endShare)) + begin, err := safeConvertInt64ToInt(beginShare) + if err != nil { + return nil, err + } + end, err := safeConvertInt64ToInt(endShare) if err != nil { return nil, err } + nID, err := ParseNamespace(dataSquare, begin, end) + if err != nil { + return nil, err + } + + shareRange := shares.NewRange(begin, end) // create and marshal the share inclusion proof, which we return in the form of []byte - shareProof, err := NewShareInclusionProof( - dataSquare, - nID, - shares.NewRange(int(beginShare), int(endShare)), - ) + shareProof, err := NewShareInclusionProof(dataSquare, nID, shareRange) if err != nil { return nil, err } @@ -123,7 +130,7 @@ func QueryShareInclusionProof(_ sdk.Context, path []string, req abci.RequestQuer // ParseNamespace validates the share range, checks if it only contains one namespace and returns // that namespace ID. -func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (appns.Namespace, error) { +func ParseNamespace(rawShares []shares.Share, startShare int, endShare int) (appns.Namespace, error) { if startShare < 0 { return appns.Namespace{}, fmt.Errorf("start share %d should be positive", startShare) } @@ -156,3 +163,13 @@ func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (appns.N } return startShareNs, nil } + +func safeConvertInt64ToInt(x int64) (int, error) { + if x < math.MinInt { + return 0, fmt.Errorf("value %d is too small to be converted to int", x) + } + if x > math.MaxInt { + return 0, fmt.Errorf("value %d is too large to be converted to int", x) + } + return int(x), nil +} diff --git a/scripts/single-node.sh b/scripts/single-node.sh index b16e2ab545..a4596daffc 100755 --- a/scripts/single-node.sh +++ b/scripts/single-node.sh @@ -5,6 +5,12 @@ set -o errexit # Stop script execution if an undefined variable is used set -o nounset +if ! [ -x "$(command -v celestia-appd)" ] +then + echo "celestia-appd could not be found. Please install the celestia-appd binary using 'make install' and make sure the PATH contains the directory where the binary exists. By default, go will install the binary under '~/go/bin'" + exit 1 +fi + CHAIN_ID="private" KEY_NAME="validator" KEYRING_BACKEND="test" @@ -20,10 +26,11 @@ echo "" # Ask the user for confirmation before deleting the existing celestia-app home # directory. -read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response +echo "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " +read -r response # Check the user's response -if [[ $response != "y" ]]; then +if [ "$response" != "y" ]; then # Exit if the user did not respond with "y" echo "You must delete $CELESTIA_APP_HOME to continue." exit 1 @@ -35,37 +42,38 @@ rm -r "$CELESTIA_APP_HOME" echo "Initializing validator and node config files..." celestia-appd init ${CHAIN_ID} \ --chain-id ${CHAIN_ID} \ - --home ${CELESTIA_APP_HOME} \ - &> /dev/null # Hide output to reduce terminal noise + --home "${CELESTIA_APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise echo "Adding a new key to the keyring..." celestia-appd keys add ${KEY_NAME} \ --keyring-backend=${KEYRING_BACKEND} \ - --home ${CELESTIA_APP_HOME} \ - &> /dev/null # Hide output to reduce terminal noise + --home "${CELESTIA_APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise echo "Adding genesis account..." celestia-appd add-genesis-account \ - $(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home ${CELESTIA_APP_HOME}) \ + "$(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home "${CELESTIA_APP_HOME}")" \ $COINS \ - --home ${CELESTIA_APP_HOME} + --home "${CELESTIA_APP_HOME}" echo "Creating a genesis tx..." celestia-appd gentx ${KEY_NAME} ${DELEGATION_AMOUNT} \ --fees ${FEES} \ --keyring-backend=${KEYRING_BACKEND} \ --chain-id ${CHAIN_ID} \ - --home ${CELESTIA_APP_HOME} \ - &> /dev/null # Hide output to reduce terminal noise + --home "${CELESTIA_APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise echo "Collecting genesis txs..." celestia-appd collect-gentxs \ - --home ${CELESTIA_APP_HOME} \ - &> /dev/null # Hide output to reduce terminal noise + --home "${CELESTIA_APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise -# Set proper defaults and change ports # If you encounter: `sed: -I or -i may not be used with stdin` on MacOS you can mitigate by installing gnu-sed # https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d?permalink_comment_id=3082272#gistcomment-3082272 + +# Override the default RPC servier listening address sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${CELESTIA_APP_HOME}"/config/config.toml # Enable transaction indexing @@ -80,7 +88,7 @@ sed -i'.bak' 's#"604800s"#"60s"#g' "${CELESTIA_APP_HOME}"/config/genesis.json # Start celestia-app echo "Starting celestia-app..." celestia-appd start \ - --home ${CELESTIA_APP_HOME} \ + --home "${CELESTIA_APP_HOME}" \ --api.enable \ --grpc.enable \ --grpc-web.enable diff --git a/test/e2e/benchmark/throughput.go b/test/e2e/benchmark/throughput.go index 86fca7bb93..227417de4d 100644 --- a/test/e2e/benchmark/throughput.go +++ b/test/e2e/benchmark/throughput.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "os" "time" "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" @@ -24,8 +23,6 @@ func main() { } func E2EThroughput() error { - os.Setenv("KNUU_NAMESPACE", "test") - latestVersion, err := testnets.GetLatestVersion() testnets.NoError("failed to get latest version", err) diff --git a/test/e2e/check_upgrades.go b/test/e2e/check_upgrades.go index f8f751c4c4..c4510050de 100644 --- a/test/e2e/check_upgrades.go +++ b/test/e2e/check_upgrades.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "math/rand" - "os" "os/exec" "strings" "time" @@ -22,8 +21,6 @@ import ( ) func MinorVersionCompatibility(logger *log.Logger) error { - os.Setenv("KNUU_NAMESPACE", "test") - versionStr, err := getAllVersions() testnets.NoError("failed to get versions", err) versions := testnets.ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates() @@ -130,8 +127,6 @@ func MinorVersionCompatibility(logger *log.Logger) error { } func MajorUpgradeToV2(logger *log.Logger) error { - os.Setenv("KNUU_NAMESPACE", "test") - latestVersion, err := testnets.GetLatestVersion() testnets.NoError("failed to get latest version", err) diff --git a/test/e2e/readme.md b/test/e2e/readme.md index 06e69b795e..ab0dbe8264 100644 --- a/test/e2e/readme.md +++ b/test/e2e/readme.md @@ -1,12 +1,12 @@ -# End to End Testing +# End-to-End Testing -Celestia uses the [knuu](https://github.com/celestiaorg/knuu) framework to orchestrate clusters of nodes in a network for end to end testing. This relies on Docker and a kubeconfig (in `~/.kube/config`) to access the Kubernetes cluster. +Celestia uses the [knuu](https://github.com/celestiaorg/knuu) framework to orchestrate clusters of nodes in a network for end-to-end testing. This relies on Docker and a kubeconfig (in `~/.kube/config`) to access the Kubernetes cluster. -End to end tests pull docker images from ghcr.io/celestiaorg/celestia-app. These are automatically published when tagging a new release or when opening a pull request. If you wish to manually test a specific commit, you can manually publish the image by first running `make build-ghcr-docker` (from the root directory) and then running `make publish-ghcr-docker`. You must have permission to push to the ghcr.io/celestiaorg/celestia-app repository. +End-to-end tests pull docker images from `ghcr.io/celestiaorg/celestia-app`. These are automatically published when tagging a new release or when opening a pull request. If you wish to manually test a specific commit, you can manually publish the image by first running `make build-ghcr-docker` (from the root directory) and then running `make publish-ghcr-docker`. You must have permission to push to the `ghcr.io/celestiaorg/celestia-app` repository. ## Usage -**Prerequisite: Requires a kubeconfig file.** Access to the specific `kubeconfig` file used by this project is limited to internal contributors only. +**Prerequisite: Requires a kubeconfig file.** Access to the specific `kubeconfig` file used by this project is limited to internal contributors only. You can run the End-to-End tests using either of the following commands: @@ -25,7 +25,7 @@ go run ./test/e2e E2ESimple ``` ```shell -make test-e2e E2ESimple +make test-e2e E2ESimple ``` **Optional parameters**: @@ -40,8 +40,112 @@ Logs of each of the nodes are posted to Grafana and can be accessed through Cele To view the metrics from the testnet, you should set the `GRAFANA_ENDPOINT`, `GRAFANA_USERNAME`, and `GRAFANA_TOKEN` environment variables. This uses Prometheus alongside the Jaeger and Otlp Exporter. +## Running locally + +It is also possible to run the whole workloads locally using minikube. + +### Backup existing configuration + +By default, the instructions below will overwrite your existing cluster configuration. To back up your configuration: + +```shell +cp ${HOME}/.kube/config ${HOME}/.kube/config_backup +``` + +This will back up your default kubernetes configuration. If you use a different directory/file, and you plan on referencing it when creating the minikube cluster below, please back it up. + +### Install minikube + +Minikube is required to be installed on your machine. If you have a linux machine, follow the [minikube docs](https://kubernetes.io/fr/docs/tasks/tools/install-minikube/). If you're on macOS ARM, this [tutorial](https://devopscube.com/minikube-mac/) can be helpful to run it using qemu. + +### Create namespace + +The command in [usage](#usage) specifies an environment variable `KNUU_NAMESPACE` to the value `test`. This namespace will need to be created before running that command: + +```shell +kubectl create namespace test +``` + +If another namespace is to be used, please create it using the same command while changing `test` to your target namespace. + +### Check the logs + +After you start the E2E tests, you can check if you have the validators running: + +```shell +kubectl get pods --namespace test +NAME READY STATUS RESTARTS AGE +timeout-handler-09e1a426-jwm7n 1/1 Running 0 2m18s +timeout-handler-921a1b93-52g6d 1/1 Running 0 40m +timeout-handler-c3442f46-lvxw2 1/1 Running 0 37m +timeout-handler-f5ccc2c9-7hld2 1/1 Running 0 34m +val0-3a7e2e1e-zs8h5 1/1 Running 0 60s +val1-9b802df8-tcvnb 1/1 Running 0 51s +val2-91b57a4d-ht57t 1/1 Running 0 42s +val3-dcc2ef6c-cg8k5 1/1 Running 0 32s +``` + +The logs can be checked using: + +```shell +kubectl logs --namespace test -f +``` + +With `` being a pod name like `val0-3a7e2e1e-zs8h5`. + +### Destroy the pods + +By default, the pods will be killed automatically after 60 minutes. However, if you want to clean up the cluster manually and destroy all the replica sets in the `test` namespace: + +```shell +kubectl delete replicasets --all --namespace test +kubectl delete pods --all --namespace test # to force the destruction of pods which are in the termination state +``` + +Note: This will delete all the created replica sets and pods in the default kubernetes cluster under the `test` namespace. Make sure to run it against the correct cluster and double-check the replica set list that is going to be destroyed using this command: + +```shell +kubectl get replicasets --namespace test +``` + +And the list of pods: + +```shell +kubectl get pods --namespace test +``` + +Also, you will have dangling persistent volume claims and persistent volumes. If you want to remove those too: + +```shell +kubectl delete pvc --all --namespace test +kubectl delete pv --all --namespace test +``` + +### Restoring old cluster configuration + +If you followed the [backup your existing cluster configuration](#backup-existing-configuration) section, you can restore your previous cluster configuration using: + +```shell +cp ${HOME}/.kube/config_backup ${HOME}/.kube/config +``` + ## Known issues ### `no configuration has been provided, try setting KUBERNETES_MASTER environment variable` This happens when the kubernetes configuration is missing. Knuu expects the cluster configuration to be in `${HOME}/.kube/config`. Make sure to put the cluster configuration in that file. + +### `failed to start testnets: node val0 failed to start: error waiting for instance 'val0-d0f34ee4' to be running: timeout while waiting for instance 'val0-d0f34ee4' to be running` + +This usually happens locally when minikube is unable to start the pods which can happen if the pvcs/pvs are not correctly allocated, the cluster nodes don't have enough resources to run the workloads, or the used virtualization engine is unable to start the pods. + +If you run into this issue, try running the tests using the docker engine, increasing the cluster's nodes to two nodes, and increasing the resources needed: + +```shell +minikube delete # delete the existing cluster so that we're able to start a new one with a different vm driver. +minikube start --driver docker --network socket_vmnet --nodes 2 --cpus=4 --memory=4g +``` + +The above command assumes the user's machine has more than eight cores, more than 8gb of RAM, and also docker has access to all those resources. + +NB: This command requires the docker daemon to be up. Make sure to start docker before executing it. diff --git a/test/e2e/simple.go b/test/e2e/simple.go index 98a4ffb928..d0890aece4 100644 --- a/test/e2e/simple.go +++ b/test/e2e/simple.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "os" "time" "github.com/celestiaorg/celestia-app/v2/app" @@ -20,8 +19,6 @@ import ( // and MsgSends over 30 seconds and then asserts that at least 10 transactions were // committed. func E2ESimple(logger *log.Logger) error { - os.Setenv("KNUU_NAMESPACE", "test") - latestVersion, err := testnets.GetLatestVersion() testnets.NoError("failed to get latest version", err) diff --git a/test/interchain/go.mod b/test/interchain/go.mod index 5f1f9ab219..8caa4104e5 100644 --- a/test/interchain/go.mod +++ b/test/interchain/go.mod @@ -45,7 +45,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.19.6 // indirect - github.com/cosmos/ibc-go/v6 v6.3.0 // indirect + github.com/cosmos/ibc-go/v6 v6.3.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.2 // indirect github.com/danieljoos/wincred v1.1.2 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect diff --git a/test/interchain/go.sum b/test/interchain/go.sum index 6b6a31a70a..d56acc4ab9 100644 --- a/test/interchain/go.sum +++ b/test/interchain/go.sum @@ -313,8 +313,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU= github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= -github.com/cosmos/ibc-go/v6 v6.3.0 h1:2EkkqDEd9hTQvzB/BsPhYZsu7T/dzAVA8+VD2UuJLSQ= -github.com/cosmos/ibc-go/v6 v6.3.0/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w= +github.com/cosmos/ibc-go/v6 v6.3.1 h1:/5ur3AsmNW8WuOevfODHlaY5Ze236PBNE3vVo9o3fQA= +github.com/cosmos/ibc-go/v6 v6.3.1/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w= github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw= github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= diff --git a/test/testground/go.mod b/test/testground/go.mod index 9bb25f037e..ab50c4d983 100644 --- a/test/testground/go.mod +++ b/test/testground/go.mod @@ -39,7 +39,7 @@ require ( github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 // indirect github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 // indirect github.com/celestiaorg/nmt v0.20.0 // indirect - github.com/celestiaorg/rsmt2d v0.12.0 // indirect + github.com/celestiaorg/rsmt2d v0.13.0 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect @@ -51,12 +51,12 @@ require ( github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect + github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogoproto v1.4.12 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.19.6 // indirect - github.com/cosmos/ibc-go/v6 v6.3.0 // indirect + github.com/cosmos/ibc-go/v6 v6.3.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.2 // indirect github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect @@ -72,7 +72,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.6.0 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect - github.com/ethereum/go-ethereum v1.13.14 // indirect + github.com/ethereum/go-ethereum v1.13.15 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/frankban/quicktest v1.14.5 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect @@ -195,12 +195,13 @@ require ( go.uber.org/goleak v1.1.12 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect + golang.org/x/arch v0.1.0 // indirect golang.org/x/crypto v0.21.0 // indirect golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.17.0 // indirect - golang.org/x/sync v0.6.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/test/testground/go.sum b/test/testground/go.sum index 77f3db8da5..5b07912262 100644 --- a/test/testground/go.sum +++ b/test/testground/go.sum @@ -350,8 +350,8 @@ github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA= github.com/celestiaorg/nmt v0.20.0 h1:9i7ultZ8Wv5ytt8ZRaxKQ5KOOMo4A2K2T/aPGjIlSas= github.com/celestiaorg/nmt v0.20.0/go.mod h1:Oz15Ub6YPez9uJV0heoU4WpFctxazuIhKyUtaYNio7E= -github.com/celestiaorg/rsmt2d v0.12.0 h1:bs1eIiz0zVS02jJV6OE6Ra+f3/c6Uq2eWnOSugrrdGY= -github.com/celestiaorg/rsmt2d v0.12.0/go.mod h1:A4vb0pYoWR4MYGqaJHlNjnu5Zd4iTs2RUYN3YogHFgE= +github.com/celestiaorg/rsmt2d v0.13.0 h1:cea8wg8MtTuUs9OTrP19QccuxvlMh0GFy7VAKc0/M+Q= +github.com/celestiaorg/rsmt2d v0.13.0/go.mod h1:P7t92OATXbBmc/P5uR+GCOBv+PV8wLb0vU32ucrb148= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= @@ -447,8 +447,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= -github.com/cosmos/cosmos-proto v1.0.0-beta.4 h1:aEL7tU/rLOmxZQ9z4i7mzxcLbSCY48OdY7lIWTLG7oU= -github.com/cosmos/cosmos-proto v1.0.0-beta.4/go.mod h1:oeB+FyVzG3XrQJbJng0EnV8Vljfk9XvTIpGILNU/9Co= +github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= +github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -458,8 +458,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU= github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= -github.com/cosmos/ibc-go/v6 v6.3.0 h1:2EkkqDEd9hTQvzB/BsPhYZsu7T/dzAVA8+VD2UuJLSQ= -github.com/cosmos/ibc-go/v6 v6.3.0/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w= +github.com/cosmos/ibc-go/v6 v6.3.1 h1:/5ur3AsmNW8WuOevfODHlaY5Ze236PBNE3vVo9o3fQA= +github.com/cosmos/ibc-go/v6 v6.3.1/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w= github.com/cosmos/ledger-cosmos-go v0.13.2 h1:aY0KZSmUwNKbBm9OvbIjvf7Ozz2YzzpAbgvN2C8x2T0= github.com/cosmos/ledger-cosmos-go v0.13.2/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5XV6svsnkk9vdJtLr8= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= @@ -555,8 +555,8 @@ github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZ github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY= github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0HwTQtm6CQ= -github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= +github.com/ethereum/go-ethereum v1.13.15 h1:U7sSGYGo4SPjP6iNIifNoyIAiNjrmQkz6EwQG+/EZWo= +github.com/ethereum/go-ethereum v1.13.15/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1523,8 +1523,9 @@ go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.1.0 h1:oMxhUYsO9VsR1dcoVUjJjIGhx1LXol3989T/yZ59Xsw= +golang.org/x/arch v0.1.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1718,8 +1719,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/test/testground/network/consensus_node.go b/test/testground/network/consensus_node.go index 52d658432b..14260c6ea1 100644 --- a/test/testground/network/consensus_node.go +++ b/test/testground/network/consensus_node.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "math" "net" "os" "path/filepath" @@ -278,7 +279,11 @@ func addPeersToAddressBook(path string, peers []PeerPacket) error { } for _, peer := range peers { - id, ip, port, err := parsePeerID(peer.PeerID) + id, ip, peerPort, err := parsePeerID(peer.PeerID) + if err != nil { + return err + } + port, err := safeConvertIntToUint16(peerPort) if err != nil { return err } @@ -286,7 +291,7 @@ func addPeersToAddressBook(path string, peers []PeerPacket) error { netAddr := p2p.NetAddress{ ID: p2p.ID(id), IP: ip, - Port: uint16(port), + Port: port, } err = addrBook.AddAddress(&netAddr, &netAddr) @@ -321,3 +326,10 @@ func parsePeerID(input string) (string, net.IP, int, error) { return address, ip, portInt, nil } + +func safeConvertIntToUint16(x int) (uint16, error) { + if x >= 0 && x <= math.MaxUint16 { + return uint16(x), nil + } + return 0, fmt.Errorf("%v is negative or too large to convert to uint16", x) +} diff --git a/test/txsim/run_test.go b/test/txsim/run_test.go index 49f8dce9b0..0c595befd9 100644 --- a/test/txsim/run_test.go +++ b/test/txsim/run_test.go @@ -124,11 +124,13 @@ func TestTxSimulator(t *testing.T) { blocks, err := testnode.ReadBlockchain(context.Background(), rpcAddr) require.NoError(t, err) for _, block := range blocks { - msgs, err := testnode.DecodeBlockData(block.Data) + txs, err := testnode.DecodeBlockData(block.Data) require.NoError(t, err, block.Height) - for _, msg := range msgs { - if _, ok := tc.expMessages[sdk.MsgTypeURL(msg)]; ok { - tc.expMessages[sdk.MsgTypeURL(msg)]-- + for _, tx := range txs { + for _, msg := range tx.GetMsgs() { + if _, ok := tc.expMessages[sdk.MsgTypeURL(msg)]; ok { + tc.expMessages[sdk.MsgTypeURL(msg)]-- + } } } } diff --git a/test/util/testnode/read.go b/test/util/testnode/read.go index 81f65d8532..1e5983480c 100644 --- a/test/util/testnode/read.go +++ b/test/util/testnode/read.go @@ -55,10 +55,10 @@ func ReadBlockHeights(ctx context.Context, rpcAddress string, fromHeight, toHeig return blocks, nil } -func DecodeBlockData(data types.Data) ([]sdk.Msg, error) { +func DecodeBlockData(data types.Data) ([]sdk.Tx, error) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) decoder := encCfg.TxConfig.TxDecoder() - msgs := make([]sdk.Msg, 0) + txs := make([]sdk.Tx, 0) for _, txBytes := range data.Txs { blobTx, isBlobTx := blob.UnmarshalBlobTx(txBytes) if isBlobTx { @@ -68,9 +68,9 @@ func DecodeBlockData(data types.Data) ([]sdk.Msg, error) { if err != nil { return nil, fmt.Errorf("decoding tx: %s: %w", string(txBytes), err) } - msgs = append(msgs, tx.GetMsgs()...) + txs = append(txs, tx) } - return msgs, nil + return txs, nil } func CalculateMeanGasFromRecentBlocks(ctx context.Context, rpcAddress, msgType string, blocks int64) (float64, int64, error) { diff --git a/tools/blockscan/main.go b/tools/blockscan/main.go new file mode 100644 index 0000000000..b880f52df6 --- /dev/null +++ b/tools/blockscan/main.go @@ -0,0 +1,160 @@ +package main + +import ( + "context" + "errors" + "fmt" + "log" + "os" + "os/signal" + "strconv" + + "github.com/celestiaorg/celestia-app/v2/test/util/testnode" + sdk "github.com/cosmos/cosmos-sdk/types" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/tendermint/tendermint/rpc/client/http" + "github.com/tendermint/tendermint/types" +) + +func main() { + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + + if err := Run(ctx); err != nil && !errors.Is(err, context.Canceled) { + log.Println("ERR:", err) + } +} + +func Run(ctx context.Context) error { + if len(os.Args) < 2 || len(os.Args) > 4 { + fmt.Print(` +Usage: blockscan [from-height] [to-height] +`) + return nil + } + var ( + err error + fromHeight, toHeight int64 + ) + + if len(os.Args) >= 3 { + fromHeight, err = strconv.ParseInt(os.Args[2], 10, 64) + if err != nil { + return err + } + } + if len(os.Args) == 4 { + toHeight, err = strconv.ParseInt(os.Args[3], 10, 64) + if err != nil { + return err + } + } + + return Scan(ctx, os.Args[1], fromHeight, toHeight) +} + +func Scan(ctx context.Context, rpcAddress string, fromHeight, toHeight int64) error { + client, err := http.New(rpcAddress, "/websocket") + if err != nil { + return err + } + + status, err := client.Status(ctx) + if err != nil { + return err + } + + if fromHeight == 0 && toHeight == 0 { + fmt.Printf("Trailing chain %s...\n", status.NodeInfo.Network) + return Trail(ctx, client) + } + + if toHeight == 0 { + toHeight = fromHeight + fmt.Printf("Scanning height %d...\n", fromHeight) + } else { + if fromHeight > toHeight { + return fmt.Errorf("fromHeight must be less or equal to toHeight") + } + fmt.Printf("Scanning from height %d to %d...\n", fromHeight, toHeight) + } + + for height := fromHeight; height <= toHeight; height++ { + block, err := client.Block(ctx, &height) + if err != nil { + return err + } + if err := PrintBlock(block.Block); err != nil { + return err + } + } + + return nil +} + +func Trail(ctx context.Context, client *http.HTTP) error { + if err := client.Start(); err != nil { + return err + } + defer func() { + if err := client.Stop(); err != nil { + log.Println("ERR:", err) + } + }() + sub, err := client.Subscribe(ctx, "blockscan", "tm.event='NewBlock'") + if err != nil { + return err + } + defer func() { + if err := client.UnsubscribeAll(ctx, "blockscan"); err != nil { + log.Println("ERR:", err) + } + }() + + for { + select { + case <-ctx.Done(): + return nil + case result := <-sub: + blockResult, ok := result.Data.(types.EventDataNewBlock) + if !ok { + return fmt.Errorf("unexpected result type: %T", result.Data) + } + if err := PrintBlock(blockResult.Block); err != nil { + return err + } + } + } +} + +func PrintBlock(block *types.Block) error { + fmt.Println("Height:", block.Height) + txs, err := testnode.DecodeBlockData(block.Data) + if err != nil { + return err + } + for _, tx := range txs { + authTx, ok := tx.(authsigning.Tx) + if !ok { + return fmt.Errorf("tx is not an auth.Tx") + } + PrintTx(authTx) + } + return nil +} + +func PrintTx(tx authsigning.Tx) { + msgs := tx.GetMsgs() + fmt.Printf(`Tx - Signer: %s, Fee: %s { +%s +} +`, tx.GetSigners(), tx.GetFee(), printMessages(msgs)) +} + +func printMessages(msgs []sdk.Msg) string { + output := "" + for _, msg := range msgs { + output += fmt.Sprintf(" - %s\n", sdk.MsgTypeURL(msg)) + } + return output +} diff --git a/tools/blockscan/readme.md b/tools/blockscan/readme.md new file mode 100644 index 0000000000..72ad411379 --- /dev/null +++ b/tools/blockscan/readme.md @@ -0,0 +1,23 @@ +# Blockscan + +This is an inspection tool to scan blocks and display the contents of the transactions that fill them. + +## Usage + +The format for running blockscan is as follows: + +```bash +Usage: blockscan [from-height] [to-height] +``` + +Here is an example command for following the head of mainnet: + +```bash +go run ./tools/blockscan https://rpc.lunaroasis.net:443 +``` + +There are three options for scanning transactions: + +- **Trail**: This sets up a websocket and follows the head of the chain until the command is interrupted or killed +- **Range**: This returns information of all transactions across an inclusive range: `go run ./tools/blockscan https://rpc.lunaroasis.net:443 100 200` +- **Single**: This returns the information of a single block: `go run ./tools/blockscan https://rpc.lunaroasis.net:443 100` diff --git a/x/blobstream/client/verify.go b/x/blobstream/client/verify.go index 3ee653f158..7cce38db70 100644 --- a/x/blobstream/client/verify.go +++ b/x/blobstream/client/verify.go @@ -3,6 +3,8 @@ package client import ( "context" "encoding/hex" + "fmt" + "math" "math/big" "os" "strconv" @@ -89,7 +91,7 @@ func txCmd() *cobra.Command { return err } - _, err = VerifyShares(cmd.Context(), logger, config, uint64(tx.Height), uint64(shareRange.Start), uint64(shareRange.End)) + _, err = VerifyShares(cmd.Context(), logger, config, tx.Height, uint64(shareRange.Start), uint64(shareRange.End)) return err }, } @@ -107,7 +109,11 @@ func blobCmd() *cobra.Command { return err } - blobIndex, err := strconv.ParseUint(args[1], 10, 64) + blobIndex, err := strconv.ParseInt(args[1], 10, 64) + if err != nil { + return err + } + blobIndexInt, err := safeConvertInt64ToInt(blobIndex) if err != nil { return err } @@ -149,12 +155,12 @@ func blobCmd() *cobra.Command { version := blockRes.Block.Header.Version.App maxSquareSize := appconsts.SquareSizeUpperBound(version) subtreeRootThreshold := appconsts.SubtreeRootThreshold(version) - blobShareRange, err := square.BlobShareRange(blockRes.Block.Txs.ToSliceOfBytes(), int(tx.Index), int(blobIndex), maxSquareSize, subtreeRootThreshold) + blobShareRange, err := square.BlobShareRange(blockRes.Block.Txs.ToSliceOfBytes(), int(tx.Index), blobIndexInt, maxSquareSize, subtreeRootThreshold) if err != nil { return err } - _, err = VerifyShares(cmd.Context(), logger, config, uint64(tx.Height), uint64(blobShareRange.Start), uint64(blobShareRange.End)) + _, err = VerifyShares(cmd.Context(), logger, config, tx.Height, uint64(blobShareRange.Start), uint64(blobShareRange.End)) return err }, } @@ -167,10 +173,13 @@ func sharesCmd() *cobra.Command { Args: cobra.ExactArgs(3), Short: "Verifies that a range of shares has been committed to by the Blobstream contract. The range should be end exclusive.", RunE: func(cmd *cobra.Command, args []string) error { - height, err := strconv.ParseUint(args[0], 10, 0) + height, err := strconv.ParseInt(args[0], 10, 64) if err != nil { return err } + if height < 0 { + return fmt.Errorf("height must be a positive integer") + } startShare, err := strconv.ParseUint(args[1], 10, 0) if err != nil { return err @@ -194,7 +203,7 @@ func sharesCmd() *cobra.Command { return addVerifyFlags(command) } -func VerifyShares(ctx context.Context, logger tmlog.Logger, config VerifyConfig, height uint64, startShare uint64, endShare uint64) (isCommittedTo bool, err error) { +func VerifyShares(ctx context.Context, logger tmlog.Logger, config VerifyConfig, height int64, startShare uint64, endShare uint64) (isCommittedTo bool, err error) { trpc, err := http.New(config.TendermintRPC, "/websocket") if err != nil { return false, err @@ -220,8 +229,13 @@ func VerifyShares(ctx context.Context, logger tmlog.Logger, config VerifyConfig, endShare, ) + if height < 0 { + return false, fmt.Errorf("height must be a positive integer") + } + + unsignedHeight := uint64(height) logger.Debug("getting shares proof from tendermint node") - sharesProofs, err := trpc.ProveShares(ctx, height, startShare, endShare) + sharesProofs, err := trpc.ProveShares(ctx, unsignedHeight, startShare, endShare) if err != nil { return false, err } @@ -252,7 +266,7 @@ func VerifyShares(ctx context.Context, logger tmlog.Logger, config VerifyConfig, resp, err := queryClient.DataCommitmentRangeForHeight( ctx, - &types.QueryDataCommitmentRangeForHeightRequest{Height: height}, + &types.QueryDataCommitmentRangeForHeightRequest{Height: unsignedHeight}, ) if err != nil { return false, err @@ -271,13 +285,12 @@ func VerifyShares(ctx context.Context, logger tmlog.Logger, config VerifyConfig, ) logger.Debug("getting the data root to commitment inclusion proof") - dcProof, err := trpc.DataRootInclusionProof(ctx, height, resp.DataCommitment.BeginBlock, resp.DataCommitment.EndBlock) + dcProof, err := trpc.DataRootInclusionProof(ctx, unsignedHeight, resp.DataCommitment.BeginBlock, resp.DataCommitment.EndBlock) if err != nil { return false, err } - heightI := int64(height) - block, err := trpc.Block(ctx, &heightI) + block, err := trpc.Block(ctx, &height) if err != nil { return false, err } @@ -324,12 +337,12 @@ func VerifyDataRootInclusion( _ context.Context, bsWrapper *wrapper.Wrappers, nonce uint64, - height uint64, + height int64, dataRoot []byte, proof merkle.Proof, ) (bool, error) { tuple := wrapper.DataRootTuple{ - Height: big.NewInt(int64(height)), + Height: big.NewInt(height), DataRoot: *(*[32]byte)(dataRoot), } @@ -354,3 +367,13 @@ func VerifyDataRootInclusion( } return valid, nil } + +func safeConvertInt64ToInt(x int64) (int, error) { + if x < math.MinInt { + return 0, fmt.Errorf("value %d is too small to be converted to int", x) + } + if x > math.MaxInt { + return 0, fmt.Errorf("value %d is too large to be converted to int", x) + } + return int(x), nil +}