Skip to content

Commit

Permalink
Merge pull request #4904 from Algo-devops-service/relbeta3.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
algojohnlee authored Dec 15, 2022
2 parents 0c126f6 + e673f96 commit e9e1851
Show file tree
Hide file tree
Showing 25 changed files with 1,003 additions and 100 deletions.
2 changes: 1 addition & 1 deletion buildnumber.dat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1
10 changes: 6 additions & 4 deletions cmd/opdoc/opdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ type OpRecord struct {
ArgEnum []string `json:",omitempty"`
ArgEnumTypes string `json:",omitempty"`

Doc string
DocExtra string `json:",omitempty"`
ImmediateNote string `json:",omitempty"`
Groups []string
Doc string
DocExtra string `json:",omitempty"`
ImmediateNote string `json:",omitempty"`
IntroducedVersion uint64
Groups []string
}

// LanguageSpec records the ops of the language at some version
Expand Down Expand Up @@ -332,6 +333,7 @@ func buildLanguageSpec(opGroups map[string][]string) *LanguageSpec {
records[i].DocExtra = logic.OpDocExtra(spec.Name)
records[i].ImmediateNote = logic.OpImmediateNote(spec.Name)
records[i].Groups = opGroups[spec.Name]
records[i].IntroducedVersion = spec.Version
}
return &LanguageSpec{
EvalMaxVersion: docVersion,
Expand Down
30 changes: 29 additions & 1 deletion daemon/algod/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,35 @@ The API is defined using [OpenAPI v2](https://swagger.io/specification/v2/) in *

1. Document your changes by editing **algod.oas2.json**
2. Regenerate the endpoints by running **make generate**.
3. Update the implementation in **server/v2/handlers.go**. It is sometimes useful to consult **generated/routes.go** to make sure the handler properly implements **ServerInterface**.
3. Update the implementation in **server/v2/handlers.go**. It is sometimes useful to consult **generated/\*/\*/routes.go** to make sure the handler properly implements **ServerInterface**.

### Adding a new V2 API
When adding a new endpoint to the V2 APIs, you will need to add `tags` to the path. The tags are a way of separating our
APIs into groups--the motivation of which is to more easily be able to conditionally enable and/or disable groups of
endpoints based on the use case for the node.

Each API in `algod.oas2.json`, except for some pre-existing `common` APIs, should have two tags.
1. Either `public` or `private`. This controls the type of authentication used by the API--the `public` APIs use the
`algod.token` token, while the `private` APIs use the admin token, found in `algod.admin.token` within the algod data
directory.
2. The type, or group, of API. This is currently `participating`, `nonparticipating`, or `data`, but may expand in the
future to encompass different sets of APIs such as `experimental` APIs. Additional APIs should be added to one of the
existing sets of tags based on its use case--unless you intend to create a new group in which case you will need to
additionally ensure your new APIs are registered.

For backwards compatibility, the default set of APIs registered will always be `participating` and `nonparticipating`
APIs.

The current set of API groups and some rough descriptions of how to think about them:
* `participating`
* APIs used in forming blocks/transactions and generally advancing the chain. Things which use the txn pool,
participation keys, the agreement service, etc.
* `nonparticipating`
* Generally available APIs used to do things such as fetch data. For example, GetGenesis, GetBlock, Catchpoint Catchup, etc.
* `data`
* A special set of APIs which require manipulating the node state in order to provide additional data about the node state
at some predefined granularity. For example, SetSyncRound and GetLedgerStateDelta used together control and expose StateDelta objects
containing per-round ledger differences that get compacted when actually written to the ledger DB.

## What codegen tool is used?

Expand Down
8 changes: 4 additions & 4 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@
"get": {
"description": "Get ledger deltas for a round.",
"tags": [
"private",
"public",
"data"
],
"produces": [
Expand Down Expand Up @@ -1861,7 +1861,7 @@
"delete": {
"description": "Unset the ledger sync round.",
"tags": [
"private",
"public",
"data"
],
"schemes": [
Expand Down Expand Up @@ -1905,7 +1905,7 @@
"get": {
"description": "Gets the minimum sync round for the ledger.",
"tags": [
"private",
"public",
"data"
],
"schemes": [
Expand Down Expand Up @@ -1951,7 +1951,7 @@
"post": {
"description": "Sets the minimum sync round on the ledger.",
"tags": [
"private",
"public",
"data"
],
"schemes": [
Expand Down
8 changes: 4 additions & 4 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3903,7 +3903,7 @@
},
"summary": "Get a LedgerStateDelta object for a given round",
"tags": [
"private",
"public",
"data"
]
}
Expand Down Expand Up @@ -4019,7 +4019,7 @@
},
"summary": "Removes minimum sync round restriction from the ledger.",
"tags": [
"private",
"public",
"data"
]
},
Expand Down Expand Up @@ -4093,7 +4093,7 @@
},
"summary": "Returns the minimum sync round the ledger is keeping in cache.",
"tags": [
"private",
"public",
"data"
]
}
Expand Down Expand Up @@ -4165,7 +4165,7 @@
},
"summary": "Given a round, tells the ledger to keep that round in its cache.",
"tags": [
"private",
"public",
"data"
]
}
Expand Down
12 changes: 0 additions & 12 deletions daemon/algod/api/generated_server.yml

This file was deleted.

11 changes: 0 additions & 11 deletions daemon/algod/api/generated_types.yml

This file was deleted.

11 changes: 0 additions & 11 deletions daemon/algod/api/private_server.yml

This file was deleted.

10 changes: 0 additions & 10 deletions daemon/algod/api/private_types.yml

This file was deleted.

4 changes: 2 additions & 2 deletions daemon/algod/api/server/v2/generated/data/data_routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ generate:
output-options:
include-tags:
- data
- private
- public
exclude-tags:
- common
- public
- private
- participating
- nonparticipating
type-mappings:
Expand Down
16 changes: 8 additions & 8 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.

1 change: 1 addition & 0 deletions data/pools/transactionPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ func (pool *TransactionPool) addToPendingBlockEvaluatorOnce(txgroup []transactio
Round: r,
FirstValid: tx.Txn.FirstValid,
LastValid: tx.Txn.LastValid,
Early: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions data/transactions/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type TxnDeadError struct {
Round basics.Round
FirstValid basics.Round
LastValid basics.Round
Early bool
}

func (err *TxnDeadError) Error() string {
Expand Down
14 changes: 7 additions & 7 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,12 @@ type EvalContext struct {
// Set of PC values that branches we've seen so far might
// go. So, if checkStep() skips one, that branch is trying to
// jump into the middle of a multibyte instruction
branchTargets map[int]bool
branchTargets []bool

// Set of PC values that we have begun a checkStep() with. So
// if a back jump is going to a value that isn't here, it's
// jumping into the middle of multibyte instruction.
instructionStarts map[int]bool
instructionStarts []bool

programHashCached crypto.Digest

Expand Down Expand Up @@ -933,8 +933,8 @@ func check(program []byte, params *EvalParams, mode runMode) (err error) {
cx.EvalParams = params
cx.runModeFlags = mode
cx.program = program
cx.branchTargets = make(map[int]bool)
cx.instructionStarts = make(map[int]bool)
cx.branchTargets = make([]bool, len(program)+1) // teal v2 allowed jumping to the end of the prog
cx.instructionStarts = make([]bool, len(program)+1)

maxCost := cx.remainingBudget()
staticCost := 0
Expand Down Expand Up @@ -1229,7 +1229,7 @@ func (cx *EvalContext) checkStep() (int, error) {
fmt.Fprintf(cx.Trace, "%3d %s\n", prevpc, spec.Name)
}
for pc := prevpc + 1; pc < cx.pc; pc++ {
if _, ok := cx.branchTargets[pc]; ok {
if pc < len(cx.branchTargets) && cx.branchTargets[pc] {
return 0, fmt.Errorf("branch target %d is not an aligned instruction", pc)
}
}
Expand Down Expand Up @@ -2183,7 +2183,7 @@ func checkBranch(cx *EvalContext) error {
}
if target < cx.pc+3 {
// If a branch goes backwards, we should have already noted that an instruction began at that location.
if _, ok := cx.instructionStarts[target]; !ok {
if ok := cx.instructionStarts[target]; !ok {
return fmt.Errorf("back branch target %d is not an aligned instruction", target)
}
}
Expand All @@ -2204,7 +2204,7 @@ func checkSwitch(cx *EvalContext) error {

if target < eoi {
// If a branch goes backwards, we should have already noted that an instruction began at that location.
if _, ok := cx.instructionStarts[target]; !ok {
if ok := cx.instructionStarts[target]; !ok {
return fmt.Errorf("back branch target %d is not an aligned instruction", target)
}
}
Expand Down
48 changes: 48 additions & 0 deletions data/transactions/logic/evalBench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package logic_test

import (
"testing"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/data/txntest"
"github.com/algorand/go-algorand/protocol"
"github.com/stretchr/testify/require"
)

func BenchmarkCheckSignature(b *testing.B) {
proto := config.Consensus[protocol.ConsensusCurrentVersion]
txns := txntest.CreateTinyManTxGroup(b, true)
ops, err := logic.AssembleString(txntest.TmLsig)
require.NoError(b, err)
stxns := []transactions.SignedTxn{{Txn: txns[3].Txn(), Lsig: transactions.LogicSig{Logic: ops.Program}}}
txgroup := transactions.WrapSignedTxnsWithAD(stxns)
ep := logic.EvalParams{
Proto: &proto,
TxnGroup: txgroup,
SigLedger: &logic.NoHeaderLedger{},
}
b.ResetTimer()

for i := 0; i < b.N; i++ {
err = logic.CheckSignature(0, &ep)
require.NoError(b, err)
}
}
40 changes: 40 additions & 0 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,46 @@ byte base64 5rZMNsevs5sULO+54aN+OvU6lQ503z2X+SSYUABIx7E=
}
}

func TestBranchEnd(t *testing.T) {
partitiontest.PartitionTest(t)

t.Parallel()
for v := uint64(2); v <= AssemblerMaxVersion; v++ {
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) {
ops := testProg(t, `int 1
b end
end:
`, v)
var txn transactions.SignedTxn
txn.Lsig.Logic = ops.Program
ep := defaultEvalParams(txn)
err := CheckSignature(0, ep)
require.NoError(t, err)
})
}
for v := uint64(2); v <= AssemblerMaxVersion; v++ {
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) {
ops := testProg(t, `int 1
return
`, v)
var txn transactions.SignedTxn
txn.Lsig.Logic = ops.Program
ep := defaultEvalParams(txn)
err := CheckSignature(0, ep)
require.NoError(t, err)
})
}

// now craft pushint \x01 + cut program and ensure the checker does not fail
// this \x01 varint value forces nextpc=3 with program length=3
pushint := OpsByName[LogicVersion]["pushint"]
var txn transactions.SignedTxn
txn.Lsig.Logic = []byte{LogicVersion, pushint.Opcode, 0x01}
ep := defaultEvalParams(txn)
err := CheckSignature(0, ep)
require.NoError(t, err)
}

const tlhcProgramText = `txn CloseRemainderTo
addr DFPKC2SJP3OTFVJFMCD356YB7BOT4SJZTGWLIPPFEWL3ZABUFLTOY6ILYE
==
Expand Down
Loading

0 comments on commit e9e1851

Please sign in to comment.