Skip to content

[tmpnet] Avoid serializing the node data directory #3881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025

Conversation

maru-ava
Copy link
Contributor

@maru-ava maru-ava commented Apr 11, 2025

PR Chain: tmpnet+kube

This PR chain enables tmpnet to deploy temporary networks to Kubernetes. Early PRs refactor tmpnet to support the addition in #3615 of a new tmpnet node runtime for kube.

Why this should be merged

This is intended to simplify usage by CLI. It also moves responsibility for setting the data dir to the runtime since the dir will differ between the node (local fs) and kube runtimes (pvc).

How this was tested

CI, local testing of tmpnetctl

Need to be documented in RELEASES.md?

N/A

TODO

@maru-ava maru-ava added the tooling Build, test and development tooling label Apr 11, 2025
@maru-ava maru-ava self-assigned this Apr 11, 2025
@github-project-automation github-project-automation bot moved this to Backlog 🗄️ in avalanchego Apr 11, 2025
@@ -768,16 +757,13 @@ func (n *Network) GetNodeURIs() []NodeURI {
// collecting the bootstrap details for restarting a node).
// For consumption outside of avalanchego. Needs to be kept exported.
func (n *Network) GetBootstrapIPsAndIDs(skippedNode *Node) ([]string, []string, error) {
// Collect staking addresses of non-ephemeral nodes for use in bootstrapping a node
nodes, err := ReadNodes(n, false /* includeEphemeral */)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's much value in forcing a read here. The network can always be reloaded to achieve a similar result.

@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch from d07f5ad to ddeec15 Compare April 11, 2025 21:49
func (n *Node) readConfig() error {
bytes, err := os.ReadFile(n.getConfigPath())
func (n *Node) readConfig(dataDir string) error {
configPath := getNodeConfigPath(dataDir)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When read, the node is provided the path where it is stored

@maru-ava maru-ava moved this from Backlog 🗄️ to In Review 👀 in avalanchego Apr 11, 2025
@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch from ddeec15 to 4795146 Compare April 11, 2025 22:57
// Construct a unique data dir to ensure the two nodes' data will be stored
// separately. Usually the dir name is the node ID but in this one case the nodes have
// the same node ID.
node2.DataDir = filepath.Join(network.Dir, node1.DataDir+"second")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not for this test, the node data dir could always be computed as [network dir]/[node id]

@@ -133,10 +133,9 @@ func NewEthClient(tc tests.TestContext, nodeURI tmpnet.NodeURI) ethclient.Client
}

// Adds an ephemeral node intended to be used by a single test.
func AddEphemeralNode(tc tests.TestContext, network *tmpnet.Network, flags tmpnet.FlagsMap) *tmpnet.Node {
func AddEphemeralNode(tc tests.TestContext, network *tmpnet.Network, node *tmpnet.Node) *tmpnet.Node {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The need to be able to set the DataDir suggested accepting a node instead of a FlagsMap here.

@@ -240,13 +240,6 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
n.PrimaryChainConfigs[alias].SetDefaults(chainConfig)
}

// Ensure nodes are configured
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovered during testing that this configuration is duplicative - it's already being done on network bootstrap, node start, and node read

}
flags.SetDefault(config.PluginDirKey, processConfig.PluginDir)

flags.SetDefault(config.DataDirKey, node.DataDir)
Copy link
Contributor Author

@maru-ava maru-ava Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kube runtime will set its own data dir since it uses a different filesystem

@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch 2 times, most recently from b5d8d9d to d320e14 Compare April 11, 2025 23:55
DefaultFlags FlagsMap `json:",omitempty"`
DefaultRuntimeConfig NodeRuntimeConfig `json:",omitempty"`
PreFundedKeys []*secp256k1.PrivateKey `json:",omitempty"`
UUID string `json:"uuid,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing the serialized json, realized that fields should all be in lowerCamelCase

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

tests/e2e/helpers.go:136

  • [nitpick] The AddEphemeralNode function signature now takes a node pointer rather than flags. Consider updating its documentation comment to reflect this change for clarity.
func AddEphemeralNode(tc tests.TestContext, network *tmpnet.Network, node *tmpnet.Node) *tmpnet.Node {

tests/fixture/tmpnet/network.go:550

  • Ensure that node.DataDir is always properly initialized before this check, as the removal of GetDataDir may lead to unintended empty values in some cases.
if len(node.DataDir) == 0 {

tests/e2e/faultinjection/duplicate_node_id.go:43

  • [nitpick] Since duplicate node IDs require an explicitly modified DataDir, consider adding an inline comment to explain the rationale behind manually overriding the DataDir for clarity.
node2.DataDir = node1.DataDir + "-second"

@maru-ava maru-ava force-pushed the tmpnet-start-network-vars branch from 0ccb028 to d736aec Compare April 12, 2025 21:22
@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch 3 times, most recently from ca83ff8 to 465cd68 Compare April 12, 2025 22:22
@maru-ava maru-ava force-pushed the tmpnet-start-network-vars branch from d736aec to af712ec Compare April 13, 2025 22:28
@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch from 465cd68 to f0440ce Compare April 13, 2025 22:29
@maru-ava maru-ava force-pushed the tmpnet-start-network-vars branch from af712ec to 196fd09 Compare April 14, 2025 18:01
@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch from f0440ce to 1c1ab28 Compare April 14, 2025 18:10
Copy link
Contributor

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code all LGTM.

Just one high level understanding question on the intended usage: Previously, a Node's data directory was included in its Flags, which would get serialized when Write was called for a given Network, and now that's not the case. How does that simplify the CLI's usage of tmpnet? Is it that networks/nodes can be restarted using different data directories than before?

@maru-ava
Copy link
Contributor Author

maru-ava commented Apr 16, 2025

The code all LGTM.

Just one high level understanding question on the intended usage: Previously, a Node's data directory was included in its Flags, which would get serialized when Write was called for a given Network, and now that's not the case. How does that simplify the CLI's usage of tmpnet? Is it that networks/nodes can be restarted using different data directories than before?

Yes, CLI supports moving the directory of an existing network to a different location, so including the data dir meant that CLI needed to support rewriting those paths. With this change, that rewriting is no longer necessary.

Edit: A side-effect of the change is better separation between node flags for the process runtime and the kube runtime since they will use different data dirs. Updated the description to reflect this.

Base automatically changed from tmpnet-start-network-vars to master April 17, 2025 00:21
This is intended to simplify usage by CLI.
@maru-ava maru-ava force-pushed the tmpnet-implicit-data-dir branch from 1c1ab28 to 3b43707 Compare April 17, 2025 00:32
@maru-ava maru-ava enabled auto-merge April 17, 2025 00:33
@maru-ava maru-ava added this pull request to the merge queue Apr 17, 2025
Merged via the queue into master with commit 273c73d Apr 17, 2025
24 checks passed
@github-project-automation github-project-automation bot moved this from In Review 👀 to Done ✅ in avalanchego Apr 17, 2025
@maru-ava maru-ava deleted the tmpnet-implicit-data-dir branch April 17, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tooling Build, test and development tooling
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants