Skip to content

Commit

Permalink
API: Add participation key generation endpoint to algod API (#5781)
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Oct 17, 2023
1 parent d3df476 commit a680ce1
Show file tree
Hide file tree
Showing 24 changed files with 889 additions and 370 deletions.
3 changes: 1 addition & 2 deletions cmd/algokey/part.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"encoding/base64"
"fmt"
"math"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -58,7 +57,7 @@ var partGenerateCmd = &cobra.Command{
}

if partKeyDilution == 0 {
partKeyDilution = 1 + uint64(math.Sqrt(float64(partLastRound-partFirstRound)))
partKeyDilution = account.DefaultKeyDilution(basics.Round(partFirstRound), basics.Round(partLastRound))
}

var err error
Expand Down
7 changes: 6 additions & 1 deletion cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/libgoal"
"github.com/algorand/go-algorand/libgoal/participation"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/util"
"github.com/algorand/go-algorand/util/db"
Expand Down Expand Up @@ -912,7 +913,11 @@ var addParticipationKeyCmd = &cobra.Command{
var err error
var part algodAcct.Participation
participationGen := func() {
part, _, err = client.GenParticipationKeysTo(accountAddress, roundFirstValid, roundLastValid, keyDilution, partKeyOutDir)
installFunc := func(keyPath string) error {
_, installErr := client.AddParticipationKey(keyPath)
return installErr
}
part, _, err = participation.GenParticipationKeysTo(accountAddress, roundFirstValid, roundLastValid, keyDilution, partKeyOutDir, installFunc)
}

util.RunFuncWithSpinningCursor(participationGen)
Expand Down
80 changes: 80 additions & 0 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,86 @@
}
}
},
"/v2/participation/generate/{address}": {
"post": {
"tags": [
"private",
"participating"
],
"produces": [
"application/json"
],
"schemes": [
"http"
],
"summary": "Generate and install participation keys to the node.",
"operationId": "GenerateParticipationKeys",
"parameters": [
{
"type": "string",
"description": "An account public key",
"name": "address",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Key dilution for two-level participation keys (defaults to sqrt of validity window).",
"name": "dilution",
"in": "query"
},
{
"type": "integer",
"description": "First round for participation key.",
"name": "first",
"in": "query",
"required": true
},
{
"type": "integer",
"description": "Last round for participation key.",
"name": "last",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "An empty JSON object is returned if the generation process was started. Currently no status is available.",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"401": {
"description": "Invalid API Token",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"503": {
"description": "Service Temporarily Unavailable",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"default": {
"description": "Unknown Error"
}
}
}
},
"/v2/participation/{participation-id}": {
"delete": {
"tags": [
Expand Down
103 changes: 103 additions & 0 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5379,6 +5379,109 @@
"x-codegen-request-body-name": "participationkey"
}
},
"/v2/participation/generate/{address}": {
"post": {
"operationId": "GenerateParticipationKeys",
"parameters": [
{
"description": "An account public key",
"in": "path",
"name": "address",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Key dilution for two-level participation keys (defaults to sqrt of validity window).",
"in": "query",
"name": "dilution",
"schema": {
"type": "integer"
}
},
{
"description": "First round for participation key.",
"in": "query",
"name": "first",
"required": true,
"schema": {
"type": "integer"
}
},
{
"description": "Last round for participation key.",
"in": "query",
"name": "last",
"required": true,
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
},
"description": "An empty JSON object is returned if the generation process was started. Currently no status is available."
},
"400": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Bad Request"
},
"401": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Invalid API Token"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Internal Error"
},
"503": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Service Temporarily Unavailable"
},
"default": {
"content": {},
"description": "Unknown Error"
}
},
"summary": "Generate and install participation keys to the node.",
"tags": [
"private",
"participating"
]
}
},
"/v2/participation/{participation-id}": {
"delete": {
"description": "Delete a given participation key by ID",
Expand Down
8 changes: 5 additions & 3 deletions daemon/algod/api/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package server

import (
"fmt"
"golang.org/x/sync/semaphore"
"net"
"net/http"

Expand Down Expand Up @@ -119,9 +120,10 @@ func NewRouter(logger logging.Logger, node APINodeInterface, shutdown <-chan str

// Registering v2 routes
v2Handler := v2.Handlers{
Node: node,
Log: logger,
Shutdown: shutdown,
Node: node,
Log: logger,
Shutdown: shutdown,
KeygenLimiter: semaphore.NewWeighted(1),
}
nppublic.RegisterHandlers(e, &v2Handler, publicMiddleware...)
npprivate.RegisterHandlers(e, &v2Handler, adminMiddleware...)
Expand Down
7 changes: 4 additions & 3 deletions daemon/algod/api/server/v2/generated/data/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions daemon/algod/api/server/v2/generated/experimental/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions daemon/algod/api/server/v2/generated/model/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a680ce1

Please sign in to comment.