Skip to content
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

rest api: Allow fast track transaction broadcasting via txHandler #5535

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/pingpong/runCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var generatedAccountsOffset uint64
var generatedAccountSampleMethod string
var configPath string
var latencyPath string
var asyncSending bool

func init() {
rootCmd.AddCommand(runCmd)
Expand Down Expand Up @@ -132,6 +133,7 @@ func init() {
runCmd.Flags().BoolVar(&randomLease, "randomlease", false, "set the lease to contain a random value")
runCmd.Flags().BoolVar(&rekey, "rekey", false, "Create RekeyTo transactions. Requires groupsize=2 and any of random flags exc random dst")
runCmd.Flags().Uint32Var(&duration, "duration", 0, "The number of seconds to run the pingpong test, forever if 0")
runCmd.Flags().BoolVar(&asyncSending, "async", false, "Use async sending mode")
runCmd.Flags().Uint32Var(&nftAsaPerSecond, "nftasapersecond", 0, "The number of NFT-style ASAs to create per second")
runCmd.Flags().StringVar(&pidFile, "pidfile", "", "path to write process id of this pingpong")
runCmd.Flags().StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to `file`")
Expand Down Expand Up @@ -294,6 +296,9 @@ var runCmd = &cobra.Command{
if duration > 0 {
cfg.MaxRuntime = time.Duration(uint32(duration)) * time.Second
}
if asyncSending {
cfg.AsyncSending = true
}
if randomNote {
cfg.RandomNote = true
}
Expand Down
59 changes: 59 additions & 0 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,65 @@
}
}
},
"/v2/transactions/async": {
"post": {
"tags": [
"experimental"
algorandskiy marked this conversation as resolved.
Show resolved Hide resolved
],
"consumes": [
"application/x-binary"
],
"schemes": [
"http"
],
"summary": "Fast track for broadcasting a raw transaction or transaction group to the network through the tx handler without performing most of the checks and reporting detailed errors. Should be only used for development and performance testing.",
"operationId": "RawTransactionAsync",
"parameters": [
{
"description": "The byte encoded signed transaction to broadcast to network",
"name": "rawtxn",
"in": "body",
"required": true,
"schema": {
"type": "string",
"format": "binary"
}
}
],
"responses": {
"200": {
"type": "object"
},
"400": {
"description": "Bad Request - Malformed Algorand transaction ",
"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/transactions/simulate": {
"post": {
"tags": [
Expand Down
71 changes: 71 additions & 0 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6064,6 +6064,77 @@
"x-codegen-request-body-name": "rawtxn"
}
},
"/v2/transactions/async": {
"post": {
"operationId": "RawTransactionAsync",
"requestBody": {
"content": {
"application/x-binary": {
"schema": {
"format": "binary",
"type": "string"
}
}
},
"description": "The byte encoded signed transaction to broadcast to network",
"required": true
},
"responses": {
"200": {
"content": {}
},
"400": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Bad Request - Malformed Algorand transaction "
},
"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": "Fast track for broadcasting a raw transaction or transaction group to the network through the tx handler without performing most of the checks and reporting detailed errors. Should be only used for development and performance testing.",
"tags": [
"experimental"
],
"x-codegen-request-body-name": "rawtxn"
}
},
"/v2/transactions/params": {
"get": {
"operationId": "TransactionParams",
Expand Down
7 changes: 7 additions & 0 deletions daemon/algod/api/client/restClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
// rawRequestPaths is a set of paths where the body should not be urlencoded
var rawRequestPaths = map[string]bool{
"/v2/transactions": true,
"/v2/transactions/async": true,
"/v2/teal/dryrun": true,
"/v2/teal/compile": true,
"/v2/participation": true,
Expand Down Expand Up @@ -527,6 +528,12 @@ func (client RestClient) SendRawTransaction(txn transactions.SignedTxn) (respons
return
}

// SendRawTransactionAsync gets a SignedTxn and broadcasts it to the network
func (client RestClient) SendRawTransactionAsync(txn transactions.SignedTxn) (response model.PostTransactionsResponse, err error) {
err = client.post(&response, "/v2/transactions/async", nil, protocol.Encode(&txn), true)
return
}

// SendRawTransactionGroup gets a SignedTxn group and broadcasts it to the network
func (client RestClient) SendRawTransactionGroup(txgroup []transactions.SignedTxn) error {
// response is not terribly useful: it's the txid of the first transaction,
Expand Down
4 changes: 2 additions & 2 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.