Documentation ¶
Overview ¶
Package config manages persistent configuration data for Chain Core.
Package config is a generated protocol buffer package.
It is generated from these files:
config.proto
It has these top-level messages:
Config BlockSigner
Index ¶
- Constants
- Variables
- func Configure(ctx context.Context, db pg.DB, sdb *sinkdb.DB, httpClient *http.Client, ...) error
- func HomeDirFromEnvironment() string
- type BlockSigner
- type CleanFunc
- type Config
- func (*Config) Descriptor() ([]byte, []int)
- func (m *Config) GetBlockHsmAccessToken() string
- func (m *Config) GetBlockHsmUrl() string
- func (m *Config) GetBlockPub() []byte
- func (m *Config) GetBlockchainId() *bc.Hash
- func (m *Config) GetConfiguredAt() uint64
- func (m *Config) GetGeneratorAccessToken() string
- func (m *Config) GetGeneratorUrl() string
- func (m *Config) GetId() string
- func (m *Config) GetIsGenerator() bool
- func (m *Config) GetIsSigner() bool
- func (m *Config) GetMaxIssuanceWindowMs() uint64
- func (m *Config) GetQuorum() uint32
- func (m *Config) GetSigners() []*BlockSigner
- func (*Config) ProtoMessage()
- func (m *Config) Reset()
- func (m *Config) String() string
- type EqualFunc
- type Options
- func (opts *Options) Add(key string, tup []string) sinkdb.Op
- func (opts *Options) AddOrUpdate(key string, tup []string) sinkdb.Op
- func (opts *Options) DefineSet(key string, tupleSize int, cleanFunc CleanFunc, equalFunc EqualFunc)
- func (opts *Options) DefineSingle(key string, tupleSize int, cleanFunc CleanFunc)
- func (opts *Options) Err() error
- func (opts *Options) GetFunc(key string) func() []string
- func (opts *Options) List(ctx context.Context, key string) ([][]string, error)
- func (opts *Options) ListFunc(key string) func() [][]string
- func (opts *Options) Remove(key string, tup []string) sinkdb.Op
- func (opts *Options) Set(key string, tup []string) sinkdb.Op
Constants ¶
const (
GrantPrefix = "/core/grant/" // this is also hardcoded in core/authz.go. meh.
)
Variables ¶
var ( ErrBadGenerator = errors.New("generator returned an unsuccessful response") ErrBadSignerURL = errors.New("block signer URL is invalid") ErrBadSignerPubkey = errors.New("block signer pubkey is invalid") ErrBadQuorum = errors.New("quorum must be greater than 0 if there are signers") ErrNoBlockPub = errors.New("blockpub cannot be empty in mockhsm disabled build") ErrNoBlockHSMURL = errors.New("block hsm URL cannot be empty in mockhsm disabled build") ErrStaleRaftConfig = errors.New("raft core ID doesn't match Postgres core ID") Version, BuildCommit, BuildDate string // These feature flags are marked as enabled by build tags. // See files in $CHAIN/cmd/cored. BuildConfig struct { LocalhostAuth bool `json:"is_localhost_auth"` MockHSM bool `json:"is_mockhsm"` Reset bool `json:"is_reset"` HTTPOk bool `json:"is_http_ok"` InitCluster bool `json:"is_init_cluster"` } )
var ErrConfigOp = errors.New("invalid config operation")
Functions ¶
func Configure ¶
func Configure(ctx context.Context, db pg.DB, sdb *sinkdb.DB, httpClient *http.Client, c *Config) error
Configure configures the core by writing to the database. If running in a cored process, the caller must ensure that the new configuration is properly reloaded, for example by restarting the process.
When running a mockhsm enabled server, if c.IsSigner is true and c.BlockPub is empty, Configure generates a new mockhsm keypair for signing blocks, and assigns it to c.BlockPub.
If c.IsGenerator is true, Configure creates an initial block, saves it, and assigns its hash to c.BlockchainId Otherwise, c.IsGenerator is false, and Configure makes a test request to GeneratorUrl to detect simple configuration mistakes.
func HomeDirFromEnvironment ¶
func HomeDirFromEnvironment() string
HomeDirFromEnvironment returns the directory to use for reading config and storing variable data. It returns $CHAIN_CORE_HOME, or, if that is empty, $HOME/.chaincore.
Types ¶
type BlockSigner ¶
type BlockSigner struct { AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken" json:"access_token,omitempty"` Pubkey []byte `protobuf:"bytes,2,opt,name=pubkey,proto3" json:"pubkey,omitempty"` Url string `protobuf:"bytes,3,opt,name=url" json:"url,omitempty"` }
func (*BlockSigner) Descriptor ¶
func (*BlockSigner) Descriptor() ([]byte, []int)
func (*BlockSigner) GetAccessToken ¶
func (m *BlockSigner) GetAccessToken() string
func (*BlockSigner) GetPubkey ¶
func (m *BlockSigner) GetPubkey() []byte
func (*BlockSigner) GetUrl ¶
func (m *BlockSigner) GetUrl() string
func (*BlockSigner) ProtoMessage ¶
func (*BlockSigner) ProtoMessage()
func (*BlockSigner) Reset ¶
func (m *BlockSigner) Reset()
func (*BlockSigner) String ¶
func (m *BlockSigner) String() string
type CleanFunc ¶
CleanFunc is required when defining a new configuration option. Implementations should validate and canonicalize newTuple in-place.
type Config ¶
type Config struct { Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` IsSigner bool `protobuf:"varint,2,opt,name=is_signer,json=isSigner" json:"is_signer,omitempty"` IsGenerator bool `protobuf:"varint,3,opt,name=is_generator,json=isGenerator" json:"is_generator,omitempty"` BlockchainId *bc.Hash `protobuf:"bytes,4,opt,name=blockchain_id,json=blockchainId" json:"blockchain_id,omitempty"` GeneratorUrl string `protobuf:"bytes,5,opt,name=generator_url,json=generatorUrl" json:"generator_url,omitempty"` GeneratorAccessToken string `protobuf:"bytes,6,opt,name=generator_access_token,json=generatorAccessToken" json:"generator_access_token,omitempty"` BlockHsmUrl string `protobuf:"bytes,7,opt,name=block_hsm_url,json=blockHsmUrl" json:"block_hsm_url,omitempty"` BlockHsmAccessToken string `protobuf:"bytes,8,opt,name=block_hsm_access_token,json=blockHsmAccessToken" json:"block_hsm_access_token,omitempty"` ConfiguredAt uint64 `protobuf:"varint,9,opt,name=configured_at,json=configuredAt" json:"configured_at,omitempty"` BlockPub []byte `protobuf:"bytes,10,opt,name=block_pub,json=blockPub,proto3" json:"block_pub,omitempty"` Signers []*BlockSigner `protobuf:"bytes,11,rep,name=signers" json:"signers,omitempty"` Quorum uint32 `protobuf:"varint,12,opt,name=quorum" json:"quorum,omitempty"` MaxIssuanceWindowMs uint64 `protobuf:"varint,13,opt,name=max_issuance_window_ms,json=maxIssuanceWindowMs" json:"max_issuance_window_ms,omitempty"` }
func CheckConfigExists ¶
Loads config status from sinkdb to see if other raft nodes have configured so that uncofigured nodes can update.
func Load ¶
Load loads the stored configuration, if any, from the database. It will first try to load the config from sinkdb; if that fails, it will try Postgres next. If it finds a config in Postgres but not in sinkdb storage, the config will be added to sinkdb.
func (*Config) Descriptor ¶
func (*Config) GetBlockHsmAccessToken ¶
func (*Config) GetBlockHsmUrl ¶
func (*Config) GetBlockPub ¶
func (*Config) GetBlockchainId ¶
func (*Config) GetConfiguredAt ¶
func (*Config) GetGeneratorAccessToken ¶
func (*Config) GetGeneratorUrl ¶
func (*Config) GetIsGenerator ¶
func (*Config) GetIsSigner ¶
func (*Config) GetMaxIssuanceWindowMs ¶
func (*Config) GetSigners ¶
func (m *Config) GetSigners() []*BlockSigner
func (*Config) ProtoMessage ¶
func (*Config) ProtoMessage()
type EqualFunc ¶
EqualFunc is required when defining a new set configuration option. Both a and b are guaranteed to have already been cleaned by the option's CleanFunc. It is also guaranteed that len(a) == len(b).
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options provides access to Chain Core configuration options. All options should be defined before accessing and modifying any of their values.
func (*Options) Add ¶
Add adds the provided tuple to the configuration option set indicated by key. If the added tuple conflicts with an existing tuple in the set, Add returns an error describing the conflict.
func (*Options) AddOrUpdate ¶
AddOrUpdate adds the provided tuple to the configuration option set indicated by key. If the added tuple conflicts with an existing tuple in the set, AddOrUpdate updates the conflicting tuple to the provided tuple.
func (*Options) DefineSet ¶
DefineSet defines a new configuration option as a set of tuples of size tupleSize. New tuples will be validated and canonicalized by cleanFunc. Equality when adding and removing is determined by equalFunc.
func (*Options) DefineSingle ¶
DefineSingle defines a new configuration option that takes a single tuple value of size tupleSize. New tuples will be validated and canonicalized by cleanFunc.
func (*Options) Err ¶
Err returns any persistent errors encountered by ListFunc's closures when retrieving configuration values. If there are multiple errors, it'll return an arbitrary one.
func (*Options) GetFunc ¶
GetFunc returns a closure that returns the tuple value for the provided key.
The configuration option for key must be defined as a single tuple. GetFunc panics if the provided key is undefined or is defined as a set of tuples.
The returned function performs a stale read of the configuration value. If an error occurs while reading the value, the old value is returned, and the error is saved on the Options type to be returned in Err.
func (*Options) ListFunc ¶
ListFunc returns a closure that returns the set of tuples for the provided key.
The configuration option for key must be a set of tuples. ListFunc panics if the provided key is undefined or is defined as a scalar.
The returned function performs a stale read of the configuration value. If an error occurs while reading the value the old value is returned, and the error is saved on the Options type to be returned in Err.