github.com/kotalco/kotal@v0.3.0/apis/ethereum/v1alpha1/node.go (about)

     1  package v1alpha1
     2  
     3  import (
     4  	"github.com/kotalco/kotal/apis/shared"
     5  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     6  )
     7  
     8  // NodeStatus defines the observed state of Node
     9  type NodeStatus struct {
    10  	// Consensus is network consensus algorithm
    11  	Consensus string `json:"consensus,omitempty"`
    12  	// Network is the network this node is joining
    13  	Network string `json:"network,omitempty"`
    14  	// EnodeURL is the node URL
    15  	EnodeURL string `json:"enodeURL,omitempty"`
    16  }
    17  
    18  // +kubebuilder:object:root=true
    19  // +kubebuilder:subresource:status
    20  
    21  // Node is the Schema for the nodes API
    22  // +kubebuilder:printcolumn:name="Client",type=string,JSONPath=".spec.client"
    23  // +kubebuilder:printcolumn:name="Consensus",type=string,JSONPath=".status.consensus"
    24  // +kubebuilder:printcolumn:name="Network",type=string,JSONPath=".status.network"
    25  // +kubebuilder:printcolumn:name="enodeURL",type=string,JSONPath=".status.enodeURL",priority=10
    26  type Node struct {
    27  	metav1.TypeMeta   `json:",inline"`
    28  	metav1.ObjectMeta `json:"metadata,omitempty"`
    29  
    30  	Spec   NodeSpec   `json:"spec,omitempty"`
    31  	Status NodeStatus `json:"status,omitempty"`
    32  }
    33  
    34  // +kubebuilder:object:root=true
    35  
    36  // NodeList contains a list of Node
    37  type NodeList struct {
    38  	metav1.TypeMeta `json:",inline"`
    39  	metav1.ListMeta `json:"metadata,omitempty"`
    40  	Items           []Node `json:"items"`
    41  }
    42  
    43  // NodeSpec is the specification of the node
    44  type NodeSpec struct {
    45  
    46  	// Image is Ethereum node client image
    47  	Image string `json:"image,omitempty"`
    48  
    49  	// ExtraArgs is extra arguments to pass down to the cli
    50  	ExtraArgs shared.ExtraArgs `json:"extraArgs,omitempty"`
    51  
    52  	// Replicas is number of replicas
    53  	// +kubebuilder:validation:Enum=0;1
    54  	Replicas *uint `json:"replicas,omitempty"`
    55  
    56  	// Genesis is genesis block configuration
    57  	Genesis *Genesis `json:"genesis,omitempty"`
    58  
    59  	// Network specifies the network to join
    60  	Network string `json:"network,omitempty"`
    61  
    62  	// Client is ethereum client running on the node
    63  	Client EthereumClient `json:"client"`
    64  
    65  	// import is account to import
    66  	Import *ImportedAccount `json:"import,omitempty"`
    67  
    68  	// Bootnodes is set of ethereum node URLS for p2p discovery bootstrap
    69  	// +listType=set
    70  	Bootnodes []Enode `json:"bootnodes,omitempty"`
    71  
    72  	// NodePrivateKeySecretName is the secret name holding node private key
    73  	NodePrivateKeySecretName string `json:"nodePrivateKeySecretName,omitempty"`
    74  
    75  	// StaticNodes is a set of ethereum nodes to maintain connection to
    76  	// +listType=set
    77  	StaticNodes []Enode `json:"staticNodes,omitempty"`
    78  
    79  	// P2PPort is port used for peer to peer communication
    80  	P2PPort uint `json:"p2pPort,omitempty"`
    81  
    82  	// SyncMode is the node synchronization mode
    83  	SyncMode SynchronizationMode `json:"syncMode,omitempty"`
    84  
    85  	// Miner is whether node is mining/validating blocks or no
    86  	Miner bool `json:"miner,omitempty"`
    87  
    88  	// Logging is logging verboisty level
    89  	// +kubebuilder:validation:Enum=off;fatal;error;warn;info;debug;trace;all
    90  	Logging shared.VerbosityLevel `json:"logging,omitempty"`
    91  
    92  	// Coinbase is the account to which mining rewards are paid
    93  	Coinbase shared.EthereumAddress `json:"coinbase,omitempty"`
    94  
    95  	// Hosts is a list of hostnames to to whitelist for RPC access
    96  	// +listType=set
    97  	Hosts []string `json:"hosts,omitempty"`
    98  
    99  	// CORSDomains is the domains from which to accept cross origin requests
   100  	// +listType=set
   101  	CORSDomains []string `json:"corsDomains,omitempty"`
   102  
   103  	// Engine enables authenticated Engine RPC APIs
   104  	Engine bool `json:"engine,omitempty"`
   105  
   106  	// EnginePort is engine authenticated RPC APIs port
   107  	EnginePort uint `json:"enginePort,omitempty"`
   108  
   109  	// JWTSecretName is kubernetes secret name holding JWT secret
   110  	JWTSecretName string `json:"jwtSecretName,omitempty"`
   111  
   112  	// RPC is whether HTTP-RPC server is enabled or not
   113  	RPC bool `json:"rpc,omitempty"`
   114  
   115  	// RPCPort is HTTP-RPC server listening port
   116  	RPCPort uint `json:"rpcPort,omitempty"`
   117  
   118  	// RPCAPI is a list of rpc services to enable
   119  	// +listType=set
   120  	RPCAPI []API `json:"rpcAPI,omitempty"`
   121  
   122  	// WS is whether web socket server is enabled or not
   123  	WS bool `json:"ws,omitempty"`
   124  
   125  	// WSPort is the web socket server listening port
   126  	WSPort uint `json:"wsPort,omitempty"`
   127  
   128  	// WSAPI is a list of WS services to enable
   129  	// +listType=set
   130  	WSAPI []API `json:"wsAPI,omitempty"`
   131  
   132  	// GraphQL is whether GraphQL server is enabled or not
   133  	GraphQL bool `json:"graphql,omitempty"`
   134  
   135  	// GraphQLPort is the GraphQL server listening port
   136  	GraphQLPort uint `json:"graphqlPort,omitempty"`
   137  
   138  	// Resources is node compute and storage resources
   139  	shared.Resources `json:"resources,omitempty"`
   140  }
   141  
   142  // Enode is ethereum node url
   143  type Enode string
   144  
   145  // SynchronizationMode is the node synchronization mode
   146  // +kubebuilder:validation:Enum=fast;full;light;snap
   147  type SynchronizationMode string
   148  
   149  const (
   150  	//SnapSynchronization is the snap synchronization mode
   151  	SnapSynchronization SynchronizationMode = "snap"
   152  
   153  	//FastSynchronization is the fast synchronization mode
   154  	FastSynchronization SynchronizationMode = "fast"
   155  
   156  	//LightSynchronization is the light synchronization mode
   157  	LightSynchronization SynchronizationMode = "light"
   158  
   159  	//FullSynchronization is full archival synchronization mode
   160  	FullSynchronization SynchronizationMode = "full"
   161  )
   162  
   163  // API is RPC API to be exposed by RPC or web socket server
   164  // +kubebuilder:validation:Enum=admin;clique;debug;eea;eth;ibft;miner;net;perm;plugins;priv;txpool;web3
   165  type API string
   166  
   167  const (
   168  	// AdminAPI is administration API
   169  	AdminAPI API = "admin"
   170  
   171  	// CliqueAPI is clique (Proof of Authority consensus) API
   172  	CliqueAPI API = "clique"
   173  
   174  	// DebugAPI is debugging API
   175  	DebugAPI API = "debug"
   176  
   177  	// EEAAPI is EEA (Enterprise Ethereum Alliance) API
   178  	EEAAPI API = "eea"
   179  
   180  	// ETHAPI is ethereum API
   181  	ETHAPI API = "eth"
   182  
   183  	// IBFTAPI is IBFT consensus API
   184  	IBFTAPI API = "ibft"
   185  
   186  	// MinerAPI is miner API
   187  	MinerAPI API = "miner"
   188  
   189  	// NetworkAPI is network API
   190  	NetworkAPI API = "net"
   191  
   192  	// PermissionAPI is permission API
   193  	PermissionAPI API = "perm"
   194  
   195  	// PluginsAPI is plugins API
   196  	PluginsAPI API = "plugins"
   197  
   198  	// PrivacyAPI is privacy API
   199  	PrivacyAPI API = "privacy"
   200  
   201  	// TransactionPoolAPI is transaction pool API
   202  	TransactionPoolAPI API = "txpool"
   203  
   204  	// Web3API is web3 API
   205  	Web3API API = "web3"
   206  )
   207  
   208  // EthereumClient is the ethereum client running on a given node
   209  // +kubebuilder:validation:Enum=besu;geth;nethermind
   210  type EthereumClient string
   211  
   212  func (e EthereumClient) SupportsVerbosityLevel(level shared.VerbosityLevel) bool {
   213  	switch e {
   214  	case BesuClient:
   215  		switch level {
   216  		case shared.NoLogs,
   217  			shared.FatalLogs,
   218  			shared.ErrorLogs,
   219  			shared.WarnLogs,
   220  			shared.InfoLogs,
   221  			shared.DebugLogs,
   222  			shared.TraceLogs,
   223  			shared.AllLogs:
   224  			return true
   225  		}
   226  	case GethClient:
   227  		switch level {
   228  		case shared.NoLogs,
   229  			shared.ErrorLogs,
   230  			shared.WarnLogs,
   231  			shared.InfoLogs,
   232  			shared.DebugLogs,
   233  			shared.AllLogs:
   234  			return true
   235  		}
   236  	case NethermindClient:
   237  		switch level {
   238  		case shared.ErrorLogs,
   239  			shared.WarnLogs,
   240  			shared.InfoLogs,
   241  			shared.DebugLogs,
   242  			shared.TraceLogs:
   243  			return true
   244  		}
   245  
   246  	}
   247  	return false
   248  }
   249  
   250  const (
   251  	// BesuClient is hyperledger besu ethereum client
   252  	BesuClient EthereumClient = "besu"
   253  	// GethClient is go ethereum client
   254  	GethClient EthereumClient = "geth"
   255  	// NethermindClient is Nethermind .NET client
   256  	NethermindClient EthereumClient = "nethermind"
   257  )
   258  
   259  // ImportedAccount is account derived from private key
   260  type ImportedAccount struct {
   261  	// PrivateKeySecretName is the secret name holding account private key
   262  	PrivateKeySecretName string `json:"privateKeySecretName"`
   263  	// PasswordSecretName is the secret holding password used to encrypt account private key
   264  	PasswordSecretName string `json:"passwordSecretName"`
   265  }
   266  
   267  func init() {
   268  	SchemeBuilder.Register(&Node{}, &NodeList{})
   269  }