Skip to content

Commit

Permalink
Merge pull request #458 from oasisprotocol/mitjat/genesis-runtime-nodes
Browse files Browse the repository at this point in the history
analyzer: genesis: parse compute nodes for each runtime
  • Loading branch information
mitjat authored Jun 27, 2023
2 parents fc689e1 + 4ee639d commit 8ba0410
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions analyzer/consensus/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ ON CONFLICT (id) DO UPDATE SET address = EXCLUDED.address;`

// Populate nodes.
queries = append(queries, `TRUNCATE chain.nodes CASCADE;`)
queries = append(queries, `TRUNCATE chain.runtime_nodes CASCADE;`)
query = `INSERT INTO chain.nodes (id, entity_id, expiration, tls_pubkey, tls_next_pubkey, p2p_pubkey, consensus_pubkey, roles)
VALUES
`
queryRt := "" // Query for populating the chain.runtime_nodes table.

for i, signedNode := range document.Registry.Nodes {
var node node.Node
if err := signedNode.Open(registry.RegisterNodeSignatureContext, &node); err != nil {
Expand All @@ -99,10 +102,30 @@ VALUES
if i != len(document.Registry.Nodes)-1 {
query += ",\n"
}

for _, runtime := range node.Runtimes {
if queryRt != "" {
// There's already a values tuple in the query.
queryRt += ",\n"
}
queryRt += fmt.Sprintf(
"\t('%s', '%s')",
runtime.ID.String(),
node.ID.String(),
)
}
}
query += ";"
queries = append(queries, query)

// There might be no runtime_nodes to insert; create a query only if there are.
if queryRt != "" {
queryRt = `INSERT INTO chain.runtime_nodes(runtime_id, node_id)
VALUES
` + queryRt + ";"
queries = append(queries, queryRt)
}

// Populate runtimes.
if len(document.Registry.Runtimes) > 0 {
query = `INSERT INTO chain.runtimes (id, suspended, kind, tee_hardware, key_manager)
Expand Down

0 comments on commit 8ba0410

Please sign in to comment.