7568b6680a
* Move PubKey bech32 to legacy package and migrate the usage where possible * update /server * wip * move proto json encoding helper functions to internal * update internal/marshal * wip * update sections which needs legacybech32 * update validators output * fix conflicts * slashing update * add more tests and helper function for ANY JSON serialization * update slashing * Update function documentation * Rename code any-marshal helper functions * Update pubkey unpacking test * Update test comments * solve TestDecodeStore * solve legacytx issues * all code compiles * keyring tests * keyring cleanup * remove AssertMsg * fix some tests * fix add_ledger_test.go * update cli tests * debug cli test * rename clashed bech32 names * linter fixes * update tmservice tests * linter: update legacy deprecated checks * fix names * linting * legacybech32 pubkey type rename * fix staking client * fix test compilation * fix TestGetCmdQuerySigningInfo * rename NewIfcJSONAnyMarshaler * keyring: remove duplicated information from multinfo structure * todo cleanups * Update Changelog * remove some legacybech32 from tests * remove todos * remove printlnJSON from /server CLI and amino encoding * remove protocdc.MarshalJSON * client/show remove duplicated function * remove protocdc package * comment update * remove legacybech32.MustMarshalPubKey from a test * add todo * fix TestPublicKeyUnsafe test * review update * fix bech32 UnmarshalPubKey * Use codec.MarshalIfcJSON * fix linter issues * merging conflict: fix codec.Unmarshal calls * cleanups * Update CHANGELOG.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Reword changelog updates * use pubkey.String for comparison in Test_runAddCmdLedgerWithCustomCoinType * Update GetCmdQuerySigningInfo example * cli: update keys add docs * Add errors AsOf and errors.ErrIO type * restore multisigPubKeyInfo structure bring it back to multiInfo struct * Update codec/proto_codec.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Update crypto/keys/ed25519/ed25519_test.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * Update codec/proto_codec.go Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * move pubkey any marshaling tests * Apply suggestions from code review Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> * review updates * adding missing return * errors: use IsOf instead of AsOf * keyring: add a correct check for key not found in keyring.Get * add checkKeyNotFound * fix linter issues * fix: keyring key not found check * fix keyring tests * fix linting issues * cli tests * fix: 'simd keys show <key> -p' * fix: TestVerifyMultisignature * rename keyring Bech32... functions to Mk... * fix RunAddCmd * Update pubkey display * wip * add more tests * udate keyring output tests * remove todo from ledger tests * rename MkKeyOutput * Changelog update * solve liner issues * add link to github issue Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com> |
||
---|---|---|
.. | ||
api | ||
cmd | ||
config | ||
grpc | ||
mock | ||
rosetta | ||
types | ||
README.md | ||
constructors_test.go | ||
doc.go | ||
export.go | ||
export_test.go | ||
init.go | ||
init_test.go | ||
logger.go | ||
pruning.go | ||
pruning_test.go | ||
rosetta.go | ||
start.go | ||
test_helpers.go | ||
tm_cmds.go | ||
util.go | ||
util_test.go |
README.md
Server
The server
package is responsible for providing the mechanisms necessary to
start an ABCI Tendermint application and provides the CLI framework (based on cobra)
necessary to fully bootstrap an application. The package exposes two core functions: StartCmd
and ExportCmd
which creates commands to start the application and export state respectively.
Preliminary
The root command of an application typically is constructed with:
- command to start an application binary
- three meta commands:
query
,tx
, and a few auxiliary commands such asgenesis
. utilities.
It is vital that the root command of an application uses PersistentPreRun()
cobra command
property for executing the command, so all child commands have access to the server and client contexts.
These contexts are set as their default values initially and maybe modified,
scoped to the command, in their respective PersistentPreRun()
functions. Note that
the client.Context
is typically pre-populated with "default" values that may be
useful for all commands to inherit and override if necessary.
Example:
var (
initClientCtx = client.Context{...}
rootCmd = &cobra.Command{
Use: "simd",
Short: "simulation app",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}
return server.InterceptConfigsPreRunHandler(cmd)
},
}
// add root sub-commands ...
)
The SetCmdClientContextHandler
call reads persistent flags via ReadPersistentCommandFlags
which creates a client.Context
and sets that on the root command's Context
.
The InterceptConfigsPreRunHandler
call creates a viper literal, default server.Context
,
and a logger and sets that on the root command's Context
. The server.Context
will be modified and saved to disk via the internal interceptConfigs
call, which
either reads or creates a Tendermint configuration based on the home path provided.
In addition, interceptConfigs
also reads and loads the application configuration,
app.toml
, and binds that to the server.Context
viper literal. This is vital
so the application can get access to not only the CLI flags, but also to the
application configuration values provided by this file.
StartCmd
The StartCmd
accepts an AppCreator
function which returns an Application
.
The AppCreator
is responsible for constructing the application based on the
options provided to it via AppOptions
. The AppOptions
interface type defines
a single method, Get() interface{}
, and is implemented as a viper
literal that exists in the server.Context
. All the possible options an application
may use and provide to the construction process are defined by the StartCmd
and by the application's config file, app.toml
.
The application can either be started in-process or as an external process. The former creates a Tendermint service and the latter creates a Tendermint Node.
Under the hood, StartCmd
will call GetServerContextFromCmd
, which provides
the command access to a server.Context
. This context provides access to the
viper literal, the Tendermint config and logger. This allows flags to be bound
the viper literal and passed to the application construction.
Example:
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts server.AppOptions) server.Application {
var cache sdk.MultiStorePersistentCache
if cast.ToBool(appOpts.Get(server.FlagInterBlockCache)) {
cache = store.NewCommitKVStoreCacheManager()
}
skipUpgradeHeights := make(map[int64]bool)
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
pruningOpts, err := server.GetPruningOptionsFromFlags(appOpts)
if err != nil {
panic(err)
}
return simapp.NewSimApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(server.FlagHaltTime))),
baseapp.SetInterBlockCache(cache),
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
)
}
Note, some of the options provided are exposed via CLI flags in the start command
and some are also allowed to be set in the application's app.toml
. It is recommend
to use the cast
package for type safety guarantees and due to the limitations of
CLI flag types.