Skip to content

Commit

Permalink
Merge pull request #399 from oasisprotocol/pro-wh/feature/rtconfig
Browse files Browse the repository at this point in the history
config: allow connecting to a special node for some things
  • Loading branch information
pro-wh authored May 3, 2023
2 parents 4f4ad89 + 3df1916 commit ff7dd31
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 21 deletions.
6 changes: 4 additions & 2 deletions analyzer/runtime/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ var (
// TODO: Would be nice to have an offline test.
PublicSourceConfig = &config.SourceConfig{
ChainName: ChainName,
Nodes: map[string]*config.NodeConfig{
Nodes: map[string]*config.ArchiveConfig{
CurrentArchiveName: {
RPC: sdkConfig.DefaultNetworks.All[string(ChainName)].RPC,
DefaultNode: &config.NodeConfig{
RPC: sdkConfig.DefaultNetworks.All[string(ChainName)].RPC,
},
},
},
FastStartup: false,
Expand Down
43 changes: 39 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (cfg *AnalysisConfig) Validate() error {
} else if cfg.Source.ChainName != "" && cfg.Source.CustomChain != nil {
return fmt.Errorf("source.chain_name and source.custom_chain specified, can only use one")
}
for archiveName, archiveConfig := range cfg.Source.Nodes {
if archiveConfig.DefaultNode == nil && archiveConfig.ConsensusNode == nil && len(archiveConfig.RuntimeNodes) == 0 {
return fmt.Errorf("source.nodes[%v] has none of .default, .consensus, or .runtimes", archiveName)
}
}
if cfg.Analyzers.Consensus != nil {
if err := cfg.Analyzers.Consensus.Validate(); err != nil {
return err
Expand Down Expand Up @@ -131,7 +136,7 @@ type SourceConfig struct {
// Nodes describe the oasis-node(s) to connect to. Keys are "archive
// names," which are named after mainnet releases, in lowercase e.g.
// "cobalt" and "damask."
Nodes map[string]*NodeConfig `koanf:"nodes"`
Nodes map[string]*ArchiveConfig `koanf:"nodes"`

// If set, the analyzer will skip some initial checks, e.g. that
// `rpc` really serves the chain with the chain context we expect.
Expand Down Expand Up @@ -168,10 +173,12 @@ func CustomSingleNetworkSourceConfig(rpc string, chainContext string) *SourceCon
}
}

func SingleNetworkLookup(rpc string) map[string]*NodeConfig {
return map[string]*NodeConfig{
func SingleNetworkLookup(rpc string) map[string]*ArchiveConfig {
return map[string]*ArchiveConfig{
"damask": {
RPC: rpc,
DefaultNode: &NodeConfig{
RPC: rpc,
},
},
}
}
Expand Down Expand Up @@ -200,6 +207,34 @@ type CustomChainConfig struct {
SDKNetwork *sdkConfig.Network `koanf:"sdk_network"`
}

// ArchiveConfig is information about the nodes for a network.
type ArchiveConfig struct {
// DefaultNode is information about the node to get data from by default.
DefaultNode *NodeConfig `koanf:"default"`
// ConsensusNode is information about the node to get consensus data from,
// instead of the default node.
ConsensusNode *NodeConfig `koanf:"consensus"`
// RuntimeNodes is the information about the nodes to get runtime data
// from, instead of the default node.
RuntimeNodes map[common.Runtime]*NodeConfig `koanf:"runtimes"`
}

func (ac *ArchiveConfig) ResolvedConsensusNode() *NodeConfig {
nc := ac.ConsensusNode
if nc != nil {
return nc
}
return ac.DefaultNode
}

func (ac *ArchiveConfig) ResolvedRuntimeNode(runtime common.Runtime) *NodeConfig {
nc := ac.RuntimeNodes[runtime]
if nc != nil {
return nc
}
return ac.DefaultNode
}

// NodeConfig is information about one oasis-node to connect to.
type NodeConfig struct {
// RPC is the node endpoint.
Expand Down
3 changes: 2 additions & 1 deletion config/docker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ analysis:
chain_name: mainnet
nodes:
damask:
rpc: unix:/tmp/node.sock #unix:/node/data/internal.sock
default:
rpc: unix:/tmp/node.sock #unix:/node/data/internal.sock
analyzers:
metadata_registry:
interval: 1h
Expand Down
3 changes: 2 additions & 1 deletion config/local-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ analysis:
chain_name: mainnet
nodes:
damask:
rpc: unix:/tmp/node.sock #unix:/node/data/internal.sock
default:
rpc: unix:/tmp/node.sock #unix:/node/data/internal.sock
analyzers:
metadata_registry:
interval: 1h
Expand Down
16 changes: 8 additions & 8 deletions storage/oasis/nodeapi/history/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (

var _ nodeapi.ConsensusApiLite = (*HistoryConsensusApiLite)(nil)

type APIConstructor func(ctx context.Context, chainContext string, nodeConfig *config.NodeConfig, fastStartup bool) (nodeapi.ConsensusApiLite, error)
type APIConstructor func(ctx context.Context, chainContext string, archiveConfig *config.ArchiveConfig, fastStartup bool) (nodeapi.ConsensusApiLite, error)

var APIConstructors = map[string]APIConstructor{
"damask": func(ctx context.Context, chainContext string, nodeConfig *config.NodeConfig, fastStartup bool) (nodeapi.ConsensusApiLite, error) {
sdkConn, err := connections.SDKConnect(ctx, chainContext, nodeConfig, fastStartup)
"damask": func(ctx context.Context, chainContext string, archiveConfig *config.ArchiveConfig, fastStartup bool) (nodeapi.ConsensusApiLite, error) {
sdkConn, err := connections.SDKConnect(ctx, chainContext, archiveConfig.ResolvedConsensusNode(), fastStartup)
if err != nil {
return nil, err
}
return damask.NewDamaskConsensusApiLite(sdkConn.Consensus()), nil
},
"cobalt": func(ctx context.Context, chainContext string, nodeConfig *config.NodeConfig, fastStartup bool) (nodeapi.ConsensusApiLite, error) {
rawConn, err := connections.RawConnect(nodeConfig)
"cobalt": func(ctx context.Context, chainContext string, archiveConfig *config.ArchiveConfig, fastStartup bool) (nodeapi.ConsensusApiLite, error) {
rawConn, err := connections.RawConnect(archiveConfig.ResolvedConsensusNode())
if err != nil {
return nil, fmt.Errorf("indexer RawConnect: %w", err)
}
Expand All @@ -44,15 +44,15 @@ type HistoryConsensusApiLite struct {
APIs map[string]nodeapi.ConsensusApiLite
}

func NewHistoryConsensusApiLite(ctx context.Context, history *config.History, nodes map[string]*config.NodeConfig, fastStartup bool) (*HistoryConsensusApiLite, error) {
func NewHistoryConsensusApiLite(ctx context.Context, history *config.History, nodes map[string]*config.ArchiveConfig, fastStartup bool) (*HistoryConsensusApiLite, error) {
apis := map[string]nodeapi.ConsensusApiLite{}
for _, record := range history.Records {
if nodeConfig, ok := nodes[record.ArchiveName]; ok {
if archiveConfig, ok := nodes[record.ArchiveName]; ok {
apiConstructor := APIConstructors[record.ArchiveName]
if apiConstructor == nil {
return nil, fmt.Errorf("historical API for archive %s not implemented", record.ArchiveName)
}
api, err := apiConstructor(ctx, record.ChainContext, nodeConfig, fastStartup)
api, err := apiConstructor(ctx, record.ChainContext, archiveConfig, fastStartup)
if err != nil {
return nil, fmt.Errorf("connecting to archive %s: %w", record.ArchiveName, err)
}
Expand Down
8 changes: 4 additions & 4 deletions storage/oasis/nodeapi/history/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ type HistoryRuntimeApiLite struct {
APIs map[string]nodeapi.RuntimeApiLite
}

func NewHistoryRuntimeApiLite(ctx context.Context, history *config.History, sdkPT *sdkConfig.ParaTime, nodes map[string]*config.NodeConfig, fastStartup bool, runtime common.Runtime) (*HistoryRuntimeApiLite, error) {
func NewHistoryRuntimeApiLite(ctx context.Context, history *config.History, sdkPT *sdkConfig.ParaTime, nodes map[string]*config.ArchiveConfig, fastStartup bool, runtime common.Runtime) (*HistoryRuntimeApiLite, error) {
apis := map[string]nodeapi.RuntimeApiLite{}
for _, record := range history.Records {
if nodeConfig, ok := nodes[record.ArchiveName]; ok {
sdkConn, err := connections.SDKConnect(ctx, record.ChainContext, nodeConfig, fastStartup)
if archiveConfig, ok := nodes[record.ArchiveName]; ok {
sdkConn, err := connections.SDKConnect(ctx, record.ChainContext, archiveConfig.ResolvedRuntimeNode(runtime), fastStartup)
if err != nil {
return nil, err
}
sdkClient := sdkConn.Runtime(sdkPT)
rawConn, err := connections.RawConnect(nodeConfig)
rawConn, err := connections.RawConnect(archiveConfig.ResolvedRuntimeNode(runtime))
if err != nil {
return nil, fmt.Errorf("indexer RawConnect: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/config/e2e-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ analysis:
sdk_network: {}
nodes:
damask:
rpc: unix:/testnet/net-runner/network/validator-0/internal.sock
default:
rpc: unix:/testnet/net-runner/network/validator-0/internal.sock
analyzers:
consensus:
from: 1
Expand Down

0 comments on commit ff7dd31

Please sign in to comment.