Skip to content

Commit

Permalink
Add SendOnly nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Sep 18, 2024
1 parent 4bf96b7 commit c1b83a5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
9 changes: 7 additions & 2 deletions pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.L
mnCfg := cfg.MultiNodeConfig()

var nodes []mn.Node[mn.StringID, *client.Client]
var sendOnlyNodes []mn.SendOnlyNode[mn.StringID, *client.Client]

for i, nodeInfo := range cfg.ListNodes() {
rpcClient, err := client.NewClient(nodeInfo.URL.String(), cfg, DefaultRequestTimeout, logger.Named(lggr, "Client."+*nodeInfo.Name))
Expand All @@ -248,15 +249,19 @@ func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.L
mnCfg, mnCfg, lggr, *nodeInfo.URL.URL(), nil, *nodeInfo.Name,
i, mn.StringID(id), 0, rpcClient, chainFamily)

nodes = append(nodes, newNode)
if nodeInfo.SendOnly {
sendOnlyNodes = append(sendOnlyNodes, newNode)
} else {
nodes = append(nodes, newNode)
}
}

multiNode := mn.NewMultiNode[mn.StringID, *client.Client](
lggr,
mn.NodeSelectionModeRoundRobin,
0,
nodes,
[]mn.SendOnlyNode[mn.StringID, *client.Client]{},
sendOnlyNodes,
mn.StringID(id),
chainFamily,
mnCfg.DeathDeclarationDelay(),
Expand Down
5 changes: 3 additions & 2 deletions pkg/solana/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ type Head struct {
}

func (h *Head) BlockNumber() int64 {
if h.BlockHeight == nil {
if !h.IsValid() {
return 0
}
//nolint:gosec
// nolint:gosec
// G115: integer overflow conversion uint64 -> int64
return int64(*h.BlockHeight)
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/solana/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ func (c *Chain) SetDefaults() {
}

type Node struct {
Name *string
URL *config.URL
Name *string
URL *config.URL
SendOnly bool
}

func (n *Node) ValidateConfig() (err error) {
Expand Down
15 changes: 1 addition & 14 deletions pkg/solana/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func setFromNode(n, f *Node) {
if f.URL != nil {
n.URL = f.URL
}
n.SendOnly = f.SendOnly
}

type TOMLConfig struct {
Expand Down Expand Up @@ -192,20 +193,6 @@ func (c *TOMLConfig) ValidateConfig() (err error) {
if len(c.Nodes) == 0 {
err = errors.Join(err, config.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
}

for _, node := range c.Nodes {
if node.Name == nil {
err = errors.Join(err, config.ErrMissing{Name: "Name", Msg: "required for all nodes"})
} else if *node.Name == "" {
err = errors.Join(err, config.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
}
if node.URL == nil {
err = errors.Join(err, config.ErrMissing{Name: "URL", Msg: "required for all nodes"})
} else if (*url.URL)(node.URL) == nil {
err = errors.Join(err, config.ErrEmpty{Name: "URL", Msg: "required for all nodes"})
}
}

return
}

Expand Down

0 comments on commit c1b83a5

Please sign in to comment.