Documentation
¶
Overview ¶
Package gnoland contains the bootstrapping code to launch a gno.land node.
Index ¶
- Variables
- func EndBlocker(prmk params.ParamsKeeperI, acck auth.AccountKeeperI, gpk auth.GasPriceKeeperI, ...) func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock
- func LoadGenesisParamsFile(path string, ggs *GnoGenesisState) error
- func LoadPackage(mpkg *std.MemPackage, creator bft.Address, fee std.Fee, deposit std.Coins) (std.Tx, error)
- func LoadStreamingGenesisDoc(genesisPath, cacheRoot string, logger *slog.Logger) (*types.GenesisDoc, error)
- func NewApp(dataRootDir string, genesisCfg GenesisAppConfig, appCfg *sdkCfg.AppConfig, ...) (abci.Application, error)
- func NewAppWithOptions(cfg *AppOptions) (abci.Application, error)
- func NewDefaultGenesisConfig(chainid, chaindomain string) *bft.GenesisDoc
- func NewDefaultTMConfig(rootdir string) *tmcfg.Config
- func NewInMemoryNode(logger *slog.Logger, cfg *InMemoryNodeConfig) (*node.Node, error)
- func NoopGenesisTxResultHandler(_ sdk.Context, _ std.Tx, _ sdk.Result)
- func PanicOnFailingTxResultHandler(_ sdk.Context, _ std.Tx, res sdk.Result)
- func ProtoGnoAccount() std.Account
- func ProtoGnoSessionAccount() std.Account
- func SignGenesisTxs(txs []TxWithMetadata, signer GenesisSigner, chainID string) error
- func SortBalances(list []Balance)
- func StreamingGenesisProvider(genesisFile, cacheRoot string, logger *slog.Logger) node.GenesisDocProvider
- func ValidateGenState(state GnoGenesisState) error
- type AppOptions
- type Balance
- type Balances
- func (bs Balances) Get(address crypto.Address) (balance Balance, ok bool)
- func (bs Balances) LeftMerge(from Balances)
- func (bs Balances) List() []Balance
- func (bs Balances) LoadFromEntries(entries ...string) error
- func (bs Balances) LoadFromSheet(sheet io.Reader) error
- func (bs Balances) Set(address crypto.Address, amount std.Coins)
- type BitSet
- type GenesisAppConfig
- type GenesisSigner
- type GenesisStateRef
- func (r *GenesisStateRef) BalanceCount() int
- func (r *GenesisStateRef) IterBalances(ctx context.Context) iter.Seq2[[]byte, error]
- func (r *GenesisStateRef) IterTxs(ctx context.Context) iter.Seq2[[]byte, error]
- func (r *GenesisStateRef) SmallField(key string) (json.RawMessage, bool)
- func (r *GenesisStateRef) StreamJSON(ctx context.Context, w io.Writer) error
- func (r *GenesisStateRef) TxCount() int
- type GenesisTxResultHandler
- type GnoAccount
- func (ga *GnoAccount) GetBaseAccount() *std.BaseAccount
- func (ga *GnoAccount) IsFrozen() bool
- func (ga *GnoAccount) IsTokenLockWhitelisted() bool
- func (goo GnoAccount) MarshalBinary2(cdc *amino.Codec, buf []byte, offset int) (int, error)
- func (ga *GnoAccount) SetFrozen(frozen bool)
- func (ga *GnoAccount) SetTokenLockWhitelisted(whitelisted bool)
- func (goo GnoAccount) SizeBinary2(cdc *amino.Codec) (int, error)
- func (ga *GnoAccount) String() string
- func (goo *GnoAccount) UnmarshalBinary2(cdc *amino.Codec, bz []byte, anyDepth int) error
- type GnoGenesisState
- type GnoSessionAccount
- func (gsa *GnoSessionAccount) GetAllowPaths() []string
- func (goo GnoSessionAccount) MarshalBinary2(cdc *amino.Codec, buf []byte, offset int) (int, error)
- func (gsa *GnoSessionAccount) SetAllowPaths(paths []string)
- func (goo GnoSessionAccount) SizeBinary2(cdc *amino.Codec) (int, error)
- func (goo *GnoSessionAccount) UnmarshalBinary2(cdc *amino.Codec, bz []byte, anyDepth int) error
- func (gsa *GnoSessionAccount) ValidateAllowPaths(paths []string) error
- type GnoTxMetadata
- type InMemoryNodeConfig
- type InitChainerConfig
- type ReplayCategory
- type SignerAccountInfo
- type TxWithMetadata
Constants ¶
This section is empty.
Variables ¶
var ( ErrBalanceEmptyAddress = errors.New("balance address is empty") ErrBalanceEmptyAmount = errors.New("balance amount is empty") )
var Package = amino.RegisterPackage(amino.NewPackage( "github.com/gnolang/gno/gno.land/pkg/gnoland", "gno", amino.GetCallersDirname(), ).WithDependencies( std.Package, auth.Package, bank.Package, vm.Package, ).WithTypes( &GnoAccount{}, "Account", &GnoSessionAccount{}, "SessionAccount", GnoGenesisState{}, "GenesisState", TxWithMetadata{}, "TxWithMetadata", GnoTxMetadata{}, "GnoTxMetadata", SignerAccountInfo{}, "SignerAccountInfo", ))
Functions ¶
func EndBlocker ¶
func EndBlocker( prmk params.ParamsKeeperI, acck auth.AccountKeeperI, gpk auth.GasPriceKeeperI, app endBlockerApp, ) func( ctx sdk.Context, req abci.RequestEndBlock, ) abci.ResponseEndBlock
EndBlocker defines the logic executed after every block. It checks for a governance-requested chain halt, then reads valset changes from the params keeper and propagates them to consensus.
func LoadGenesisParamsFile ¶
func LoadGenesisParamsFile(path string, ggs *GnoGenesisState) error
LoadGenesisParamsFile loads genesis params from the provided file path.
func LoadPackage ¶
func LoadPackage(mpkg *std.MemPackage, creator bft.Address, fee std.Fee, deposit std.Coins) (std.Tx, error)
LoadPackage loads a single package into a `std.Tx`
func LoadStreamingGenesisDoc ¶
func LoadStreamingGenesisDoc(genesisPath, cacheRoot string, logger *slog.Logger) (*types.GenesisDoc, error)
LoadStreamingGenesisDoc parses a genesis JSON file in a single streaming pass and returns a *types.GenesisDoc whose AppState is a *GenesisStateRef backed by an on-disk cache under cacheRoot. The bulk fields under app_state (balances, txs) never enter the heap as a unit; they are written line-by-line to JSONL files as the decoder walks the source.
Cache hit (source hash unchanged from a previous run): the cache files are reused; the source is still walked once to populate the small top-level GenesisDoc fields, but app_state is skipped via Token-level step-overs (no decode of the bulk arrays).
Cache miss: the cache directory <cacheRoot>/<sha256(source)>/ is populated atomically (via tmp dir + rename), and any other entries in cacheRoot are removed (single-cache-on-disk policy).
Memory bound: peak heap is O(largest single element), not O(file size). Verified at ~3.7 MB peak on a 200 MB real genesis.
logger receives Warn entries for unknown top-level fields (which are silently consumed otherwise — the same tolerance GenesisDocFromJSON has). A nil logger falls back to slog.Default.
func NewApp ¶
func NewApp( dataRootDir string, genesisCfg GenesisAppConfig, appCfg *sdkCfg.AppConfig, evsw events.EventSwitch, logger *slog.Logger, skipUpgradeHeight int64, ) (abci.Application, error)
NewApp creates the gno.land application.
func NewAppWithOptions ¶
func NewAppWithOptions(cfg *AppOptions) (abci.Application, error)
NewAppWithOptions creates the gno.land application with specified options.
func NewDefaultGenesisConfig ¶
func NewDefaultGenesisConfig(chainid, chaindomain string) *bft.GenesisDoc
NewDefaultGenesisConfig creates a default configuration for an in-memory node.
func NewDefaultTMConfig ¶
func NewInMemoryNode ¶
NewInMemoryNode creates an in-memory gnoland node. In this mode, the node does not persist any data and uses an in-memory database. The `InMemoryNodeConfig.TMConfig.RootDir` should point to the correct gno repository to load the stdlibs.
func NoopGenesisTxResultHandler ¶
NoopGenesisTxResultHandler is a no-op GenesisTxResultHandler.
func PanicOnFailingTxResultHandler ¶
PanicOnFailingTxResultHandler handles genesis transactions by panicking if res.IsErr() returns true.
func ProtoGnoAccount ¶
func ProtoGnoSessionAccount ¶
func SignGenesisTxs ¶
func SignGenesisTxs(txs []TxWithMetadata, signer GenesisSigner, chainID string) error
SignGenesisTxs will sign all txs passed as argument using the genesis signer. This signature is only valid for genesis transactions as the account number and sequence are 0
func SortBalances ¶
func SortBalances(list []Balance)
SortBalances sorts balances in lexicographic order, compared by .Address instead of .Amount because .Amount's type is Coins that requires a deeper comparison by .Denom and .Amount which are unnecessarily complex yet by the nature of each Balance in Balances, each entry will be keyed by the same Address in a map.
func StreamingGenesisProvider ¶
func StreamingGenesisProvider(genesisFile, cacheRoot string, logger *slog.Logger) node.GenesisDocProvider
StreamingGenesisProvider returns a node.GenesisDocProvider that loads the genesis document from disk via LoadStreamingGenesisDoc, attaching a *GenesisStateRef as AppState rather than the typed in-memory GnoGenesisState. Use this in place of node.DefaultGenesisDocProviderFunc when starting a gnoland node from a real genesis file — the streaming loader keeps peak memory bounded regardless of source-file size.
logger is forwarded to LoadStreamingGenesisDoc so unknown-field warnings surface in the node's normal logging path. A nil logger falls back to slog.Default.
The provider is closure-only — each call re-runs the loader, which is cheap on a warm cache (hash check + open files) and does the full preprocessing pass on a cold cache.
func ValidateGenState ¶
func ValidateGenState(state GnoGenesisState) error
Types ¶
type AppOptions ¶
type AppOptions struct {
DB dbm.DB // required
Logger *slog.Logger // required
EventSwitch events.EventSwitch // required
VMOutput io.Writer // optional
SkipGenesisSigVerification bool // default to verify genesis transactions
SkipUpgradeHeight int64 // if set, skip the halt_min_version check at this height
InitChainerConfig // options related to InitChainer
MinGasPrices string // optional
PruneStrategy types.PruneStrategy
}
AppOptions contains the options to create the gno.land ABCI application.
func TestAppOptions ¶
func TestAppOptions(db dbm.DB) *AppOptions
TestAppOptions provides a "ready" default AppOptions for use with NewAppWithOptions, using the provided db.
type Balances ¶
func GetBalancesFromEntries ¶
func LoadGenesisBalancesFile ¶
LoadGenesisBalancesFile loads genesis balances from the provided file path.
func NewBalances ¶
func NewBalances() Balances
func (Balances) List ¶
List returns a slice of balances, sorted by Balance.Address in lexicographic order.
func (Balances) LoadFromEntries ¶
LoadFromEntries extracts the balance entries in the form of <address>=<amount>
func (Balances) LoadFromSheet ¶
LoadFromSheet extracts the balance sheet from the passed in balance sheet file, that has the format of <address>=<amount>ugnot
type BitSet ¶
type BitSet uint64
bitSet represents a set of flags stored in a 64-bit unsigned integer. Each bit in the BitSet corresponds to a specific flag.
type GenesisAppConfig ¶
type GenesisAppConfig struct {
SkipFailingTxs bool // does not stop the chain from starting if any tx fails
SkipSigVerification bool // does not verify the transaction signatures in genesis
}
GenesisAppConfig wraps the most important genesis params relating to the App
func NewTestGenesisAppConfig ¶
func NewTestGenesisAppConfig() GenesisAppConfig
NewTestGenesisAppConfig returns a testing genesis app config
type GenesisSigner ¶
GenesisSigner defines the interface needed to sign genesis transactions. Both crypto.PrivKey and bft/types.Signer implement this interface.
type GenesisStateRef ¶
type GenesisStateRef struct {
// contains filtered or unexported fields
}
GenesisStateRef is a lazy, on-disk-backed handle to the bulk fields of a genesis app_state. The small sibling fields are loaded into memory eagerly (they total under 10 KB in practice); the bulk arrays — balances and txs — live as JSONL files and are read one element at a time via the iterators.
Construct via OpenGenesisStateRef. The zero value is not usable.
func OpenGenesisStateRef ¶
func OpenGenesisStateRef(cacheDir string) (*GenesisStateRef, error)
OpenGenesisStateRef opens an existing genesis cache directory, validates it has the expected files, and loads the small sibling fields of app_state into memory. The bulk arrays (balances, txs) are not loaded; they are read on-demand via IterBalances and IterTxs.
func (*GenesisStateRef) BalanceCount ¶
func (r *GenesisStateRef) BalanceCount() int
BalanceCount returns the number of balance entries in the cache, as recorded in the manifest. O(1), no file scan.
func (*GenesisStateRef) IterBalances ¶
IterBalances returns an iterator that yields each balance entry as raw JSON bytes (without the trailing newline), one at a time. The iterator stops when the file is exhausted, when ctx is cancelled (yielding ctx.Err() once before stopping), or when a read error occurs.
The yielded byte slice MUST NOT be retained across iterations — the underlying buffer is reused. Copy if you need to keep it.
func (*GenesisStateRef) IterTxs ¶
IterTxs returns an iterator over the tx entries. Same semantics as IterBalances; see that function for caveats on slice retention and cancellation.
func (*GenesisStateRef) SmallField ¶
func (r *GenesisStateRef) SmallField(key string) (json.RawMessage, bool)
SmallField returns the raw JSON bytes of a small sibling field of app_state, looked up by key. Returns false if no such field exists.
func (*GenesisStateRef) StreamJSON ¶
StreamJSON writes the JSON shape of the original app_state object directly to w, reconstituted from the on-disk cache: small sibling fields appear first (sorted by key for deterministic output), followed by the balances and txs arrays read line-by-line from their JSONL caches. The bulk arrays never enter the heap as a unit — each line is streamed straight to w.
This satisfies rpctypes.StreamableResult so a *GenesisStateRef can be served via the /genesis RPC handler without buffering the whole app_state in memory.
ctx is checked between writes; cancellation aborts the stream and returns ctx.Err.
func (*GenesisStateRef) TxCount ¶
func (r *GenesisStateRef) TxCount() int
TxCount returns the number of tx entries in the cache, as recorded in the manifest. O(1), no file scan.
type GenesisTxResultHandler ¶
GenesisTxResultHandler is called in the InitChainer after a genesis transaction is executed.
type GnoAccount ¶
type GnoAccount struct {
std.BaseAccount
Attributes BitSet `json:"attributes" yaml:"attributes"`
}
func (*GnoAccount) GetBaseAccount ¶
func (ga *GnoAccount) GetBaseAccount() *std.BaseAccount
GetBaseAccount returns a pointer to the embedded BaseAccount.
func (*GnoAccount) IsFrozen ¶
func (ga *GnoAccount) IsFrozen() bool
func (*GnoAccount) IsTokenLockWhitelisted ¶
func (ga *GnoAccount) IsTokenLockWhitelisted() bool
IsTokenLockWhitelisted checks whether the account is white listed for the token locking
func (GnoAccount) MarshalBinary2 ¶
func (*GnoAccount) SetFrozen ¶
func (ga *GnoAccount) SetFrozen(frozen bool)
func (*GnoAccount) SetTokenLockWhitelisted ¶
func (ga *GnoAccount) SetTokenLockWhitelisted(whitelisted bool)
SetTokenLockWhitelisted allows the account to bypass global transfer locking restrictions. By default, accounts are restricted with token transfer when global transfer locking is enabled.
func (GnoAccount) SizeBinary2 ¶
func (goo GnoAccount) SizeBinary2(cdc *amino.Codec) (int, error)
func (*GnoAccount) UnmarshalBinary2 ¶
type GnoGenesisState ¶
type GnoGenesisState struct {
Balances []Balance `json:"balances"`
Txs []TxWithMetadata `json:"txs"`
Auth auth.GenesisState `json:"auth"`
Bank bank.GenesisState `json:"bank"`
VM vm.GenesisState `json:"vm"`
// Chain upgrade fields
PastChainIDs []string `json:"past_chain_ids,omitempty"` // Allowlist of chain IDs valid for historical tx signature verification
InitialHeight int64 `json:"initial_height,omitempty"` // Block height to start from after genesis replay
// GasReplayMode controls how historical txs (metadata.BlockHeight > 0) are
// metered during replay. Valid values:
// "" or "strict" — use the new VM's gas meter (default; may fail txs
// that worked on the source chain if gas requirements changed)
// "source" — bypass the new gas meter for historical txs; they
// execute with unlimited gas and the response records
// metadata.GasUsed from the source chain. This preserves the
// historical outcome even if the VM's gas metering changed.
GasReplayMode string `json:"gas_replay_mode,omitempty"`
}
func DefaultGenState ¶
func DefaultGenState() GnoGenesisState
func (GnoGenesisState) MarshalBinary2 ¶
func (GnoGenesisState) SizeBinary2 ¶
func (goo GnoGenesisState) SizeBinary2(cdc *amino.Codec) (int, error)
func (*GnoGenesisState) UnmarshalBinary2 ¶
type GnoSessionAccount ¶
type GnoSessionAccount struct {
std.BaseSessionAccount
AllowPaths []string `json:"allow_paths,omitempty" yaml:"allow_paths,omitempty"`
}
GnoSessionAccount extends BaseSessionAccount with gno.land-specific session fields. AllowPaths is the per-session msg-type/path allow-list using the typed grammar "*" or "<route>/<type>[:<path>]" (see allow_paths.go). Required at create-time; empty is rejected.
func (*GnoSessionAccount) GetAllowPaths ¶
func (gsa *GnoSessionAccount) GetAllowPaths() []string
func (GnoSessionAccount) MarshalBinary2 ¶
func (*GnoSessionAccount) SetAllowPaths ¶
func (gsa *GnoSessionAccount) SetAllowPaths(paths []string)
func (GnoSessionAccount) SizeBinary2 ¶
func (goo GnoSessionAccount) SizeBinary2(cdc *amino.Codec) (int, error)
func (*GnoSessionAccount) UnmarshalBinary2 ¶
func (*GnoSessionAccount) ValidateAllowPaths ¶
func (gsa *GnoSessionAccount) ValidateAllowPaths(paths []string) error
ValidateAllowPaths checks that every entry conforms to the typed grammar. Implements the auth handler's local allowPathsValidator interface, called from handleMsgCreateSession before SetAllowPaths.
type GnoTxMetadata ¶
type GnoTxMetadata struct {
Timestamp int64 `json:"timestamp"`
BlockHeight int64 `json:"block_height,omitempty"` // Original block height for historical tx replay
ChainID string `json:"chain_id,omitempty"` // Originating chain ID, populated by tx-archive export
Failed bool `json:"failed,omitempty"` // True if tx had non-zero return code on source chain
SignerInfo []SignerAccountInfo `json:"signer_info,omitempty"` // Per-signer account metadata for signature verification
GasUsed int64 `json:"gas_used,omitempty"` // Gas consumed on source chain (used when GasReplayMode="source")
GasWanted int64 `json:"gas_wanted,omitempty"` // Gas requested on source chain (informational / report)
}
func (GnoTxMetadata) MarshalBinary2 ¶
func (GnoTxMetadata) SizeBinary2 ¶
func (goo GnoTxMetadata) SizeBinary2(cdc *amino.Codec) (int, error)
func (*GnoTxMetadata) UnmarshalBinary2 ¶
type InMemoryNodeConfig ¶
type InMemoryNodeConfig struct {
PrivValidator bft.PrivValidator // identity of the validator
Genesis *bft.GenesisDoc
TMConfig *tmcfg.Config
DB db.DB // will be initialized if nil
VMOutput io.Writer // optional
SkipGenesisSigVerification bool
// If StdlibDir not set, then it's filepath.Join(TMConfig.RootDir, "gnovm", "stdlibs")
InitChainerConfig
}
type InitChainerConfig ¶
type InitChainerConfig struct {
// Handles the results of each genesis transaction.
GenesisTxResultHandler
// Standard library directory.
StdlibDir string
// Whether to keep a record of the DB operations to load standard libraries,
// so they can be quickly replicated on additional genesis executions.
// This should be used for integration testing, where InitChainer will be
// called several times.
CacheStdlibLoad bool
// StrictReplay refuses to boot the chain if any non-skipped genesis tx
// fails replay. Hardfork operators should enable this so a corrupted
// genesis aborts InitChain loudly instead of producing a chain whose
// AppHash silently diverges from the source.
//
// Skipped txs (those carrying metadata.Failed = true, which were
// intentionally non-applied on the source chain) do not count as
// failures.
StrictReplay bool
// SkipValoperCoverageAssertion turns off the hardfork-mode
// AssertGenesisValopersConsistent auto-call. Useful for paths that
// boot a chain with PastChainIDs set but a synthetic req.Validators
// that won't match any seeded valoper profile — e.g. gnogenesis
// fork test replaces genDoc.Validators with a fresh MockPV whose
// signing addr is never registered, so the assertion would fire
// spuriously. Production hardfork boots leave this false.
SkipValoperCoverageAssertion bool
// contains filtered or unexported fields
}
InitChainerConfig keeps the configuration for the InitChainer. NewAppWithOptions will set InitChainerConfig.InitChainer as its InitChainer function.
func (InitChainerConfig) InitChainer ¶
func (cfg InitChainerConfig) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain
InitChainer is the function that can be used as a sdk.InitChainer.
type ReplayCategory ¶
type ReplayCategory string
ReplayCategory classifies the outcome of a genesis tx replay.
const ( // ReplayCategoryOK: tx replayed successfully (gas matched source within tolerance, if source gas was recorded). ReplayCategoryOK ReplayCategory = "ok" // ReplayCategoryOKGasDiffers: tx succeeded but gas consumption differs from source chain. ReplayCategoryOKGasDiffers ReplayCategory = "ok_gas_differs" // ReplayCategoryFailed: tx failed during replay (any reason not covered by specific categories). ReplayCategoryFailed ReplayCategory = "failed" // ReplayCategorySkippedFailed: tx was marked Failed in source metadata, correctly skipped. ReplayCategorySkippedFailed ReplayCategory = "skipped_failed" )
type SignerAccountInfo ¶
type SignerAccountInfo struct {
Address crypto.Address `json:"address"`
AccountNum uint64 `json:"account_num"` // Stable, never changes once assigned
Sequence uint64 `json:"sequence"` // Pre-tx sequence (value used in GetSignBytes)
}
SignerAccountInfo records a signer's account number and sequence at the time a historical tx was executed on the source chain. Used during hardfork replay to force-set account state so signatures verify correctly.
func (SignerAccountInfo) MarshalBinary2 ¶
func (SignerAccountInfo) SizeBinary2 ¶
func (goo SignerAccountInfo) SizeBinary2(cdc *amino.Codec) (int, error)
func (*SignerAccountInfo) UnmarshalBinary2 ¶
type TxWithMetadata ¶
type TxWithMetadata struct {
Tx std.Tx `json:"tx"`
Metadata *GnoTxMetadata `json:"metadata,omitempty"`
}
func LoadGenesisTxsFile ¶
func LoadGenesisTxsFile(path string, chainID string, genesisRemote string) ([]TxWithMetadata, error)
LoadGenesisTxsFile loads genesis transactions from the provided file path. XXX: Improve the way we generate and load this file
func LoadPackagesFromDir ¶
LoadPackagesFromDir loads gno packages from a directory. It creates and returns a list of transactions based on these packages.
func ReadGenesisTxs ¶
func ReadGenesisTxs(ctx context.Context, path string) ([]TxWithMetadata, error)
ReadGenesisTxs reads the genesis txs from the given file path
func (TxWithMetadata) MarshalBinary2 ¶
func (TxWithMetadata) SizeBinary2 ¶
func (goo TxWithMetadata) SizeBinary2(cdc *amino.Codec) (int, error)