Skip to content

Commit

Permalink
Consensus: v36 upgrade (#4722)
Browse files Browse the repository at this point in the history
v36 consensus upgrade
  • Loading branch information
jannotti authored Nov 1, 2022
1 parent a8f1b4a commit 06f9109
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 38 deletions.
26 changes: 17 additions & 9 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,19 +1228,27 @@ func initConsensusProtocols() {
v33.ApprovedUpgrades[protocol.ConsensusV35] = 10000
v34.ApprovedUpgrades[protocol.ConsensusV35] = 10000

v36 := v35
v36.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}

// Boxes (unlimited global storage)
v36.LogicSigVersion = 8
v36.MaxBoxSize = 32768
v36.BoxFlatMinBalance = 2500
v36.BoxByteMinBalance = 400
v36.MaxAppBoxReferences = 8
v36.BytesPerBoxReference = 1024

Consensus[protocol.ConsensusV36] = v36

v35.ApprovedUpgrades[protocol.ConsensusV36] = 140000

// ConsensusFuture is used to test features that are implemented
// but not yet released in a production protocol version.
vFuture := v35
vFuture := v36
vFuture.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{}

vFuture.LogicSigVersion = 8 // When moving this to a release, put a new higher LogicSigVersion here

// Boxes (unlimited global storage)
vFuture.MaxBoxSize = 32768
vFuture.BoxFlatMinBalance = 2500
vFuture.BoxByteMinBalance = 400
vFuture.MaxAppBoxReferences = 8
vFuture.BytesPerBoxReference = 1024
vFuture.LogicSigVersion = 9 // When moving this to a release, put a new higher LogicSigVersion here

Consensus[protocol.ConsensusFuture] = vFuture

Expand Down
11 changes: 11 additions & 0 deletions data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,10 @@ const globalV8TestProgram = globalV7TestProgram + `
// No new globals in v8
`

const globalV9TestProgram = globalV8TestProgram + `
// No new globals in v9
`

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

Expand All @@ -1124,6 +1128,7 @@ func TestGlobal(t *testing.T) {
6: {CallerApplicationAddress, globalV6TestProgram},
7: {CallerApplicationAddress, globalV7TestProgram},
8: {CallerApplicationAddress, globalV8TestProgram},
9: {CallerApplicationAddress, globalV9TestProgram},
}
// tests keys are versions so they must be in a range 1..AssemblerMaxVersion plus zero version
require.LessOrEqual(t, len(tests), AssemblerMaxVersion+1)
Expand Down Expand Up @@ -1622,6 +1627,11 @@ assert
int 1
`

const testTxnProgramTextV9 = testTxnProgramTextV8 + `
assert
int 1
`

func makeSampleTxn() transactions.SignedTxn {
var txn transactions.SignedTxn
copy(txn.Txn.Sender[:], []byte("aoeuiaoeuiaoeuiaoeuiaoeuiaoeui00"))
Expand Down Expand Up @@ -1733,6 +1743,7 @@ func TestTxn(t *testing.T) {
6: testTxnProgramTextV6,
7: testTxnProgramTextV7,
8: testTxnProgramTextV8,
9: testTxnProgramTextV9,
}

for i, txnField := range TxnFieldNames {
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/frames_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ main:
+ // This consumes the top arg. We could complain in assembly if checked stack height against pgm.fp
dup; dup // But the dup;dup restores it, so it _evals_ fine.
retsub
`, AssemblerMaxVersion)
`, fpVersion)

}

Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"EvalMaxVersion": 8,
"LogicSigVersion": 7,
"LogicSigVersion": 8,
"Ops": [
{
"Opcode": 0,
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// LogicVersion defines default assembler and max eval versions
const LogicVersion = 8
const LogicVersion = 9

// rekeyingEnabledVersion is the version of TEAL where RekeyTo functionality
// was enabled. This is important to remember so that old TEAL accounts cannot
Expand Down
2 changes: 1 addition & 1 deletion ledger/apply/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func TestAppCallOptIn(t *testing.T) {
prevMaxAppsOptedIn := config.Consensus[protocol.ConsensusV24].MaxAppsOptedIn
for _, testProtoVer := range optInCountTest {
cparams, ok := config.Consensus[testProtoVer]
a.True(ok)
a.True(ok, testProtoVer)
if cparams.MaxAppsOptedIn > 0 {
a.LessOrEqual(prevMaxAppsOptedIn, cparams.MaxAppsOptedIn)
}
Expand Down
2 changes: 1 addition & 1 deletion ledger/boxtxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var passThruSource = main(`
itxn_submit
`)

const boxVersion = 35
const boxVersion = 36

func boxFee(p config.ConsensusParams, nameAndValueSize uint64) uint64 {
return p.BoxFlatMinBalance + p.BoxByteMinBalance*(nameAndValueSize)
Expand Down
25 changes: 2 additions & 23 deletions ledger/testing/consensusRange.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"fmt"
"testing"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -56,30 +54,11 @@ var consensusByNumber = []protocol.ConsensusVersion{
protocol.ConsensusV32, // unlimited assets and apps
protocol.ConsensusV33, // 320 rounds
protocol.ConsensusV34, // AVM v7, stateproofs
protocol.ConsensusV35, // minor, double upgrade withe v34
protocol.ConsensusV36, // box storage
protocol.ConsensusFuture,
}

// TestReleasedVersion ensures that the necessary tidying is done when a new
// protocol release happens. The new version must be added to
// consensusByNumber, and a new LogicSigVersion must be added to vFuture.
func TestReleasedVersion(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

// This confirms that the proto before future has no ApprovedUpgrades. Once
// it does, that new version should be added to consensusByNumber.
require.Len(t, config.Consensus[consensusByNumber[len(consensusByNumber)-2]].ApprovedUpgrades, 0)
// And no funny business with vFuture
require.Equal(t, protocol.ConsensusFuture, consensusByNumber[len(consensusByNumber)-1])

// Ensure that vFuture gets a new LogicSigVersion when we promote the
// existing one. That allows TestExperimental in the logic package to
// prevent unintended releases of experimental opcodes.
relV := config.Consensus[consensusByNumber[len(consensusByNumber)-2]].LogicSigVersion
futureV := config.Consensus[protocol.ConsensusFuture].LogicSigVersion
require.Less(t, int(relV), int(futureV))
}

// TestConsensusRange allows for running tests against a range of consensus
// versions. Generally `start` will be the version that introduced the feature,
// and `stop` will be 0 to indicate it should work right on up through vFuture.
Expand Down
58 changes: 58 additions & 0 deletions ledger/testing/consensusRange_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 testing

import (
"testing"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/stretchr/testify/require"
)

// TestReleasedVersion ensures that the necessary tidying is done when a new
// protocol release happens. The new version must be added to
// consensusByNumber, and a new LogicSigVersion must be added to vFuture.
func TestReleasedVersion(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

// This confirms that the proto before future has no ApprovedUpgrades. Once
// it does, that new version should be added to consensusByNumber.
require.Len(t, config.Consensus[consensusByNumber[len(consensusByNumber)-2]].ApprovedUpgrades, 0)
// And no funny business with vFuture
require.Equal(t, protocol.ConsensusFuture, consensusByNumber[len(consensusByNumber)-1])

// Ensure that vFuture gets a new LogicSigVersion when we promote the
// existing one. That allows TestExperimental in the logic package to
// prevent unintended releases of experimental opcodes.
relV := config.Consensus[consensusByNumber[len(consensusByNumber)-2]].LogicSigVersion
futureV := config.Consensus[protocol.ConsensusFuture].LogicSigVersion
require.Less(t, int(relV), int(futureV))

// Require that all are present
for _, cv := range consensusByNumber {
if cv == "" {
continue
}
params, ok := config.Consensus[cv]
require.True(t, ok, string(cv))
require.NotZero(t, params) // just making sure an empty one didn't get put in
}

}
7 changes: 6 additions & 1 deletion protocol/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ const ConsensusV35 = ConsensusVersion(
"https://github.com/algorandfoundation/specs/tree/433d8e9a7274b6fca703d91213e05c7e6a589e69",
)

// ConsensusV36 adds box storage
const ConsensusV36 = ConsensusVersion(
"https://github.com/algorandfoundation/specs/tree/44fa607d6051730f5264526bf3c108d51f0eadb6",
)

// ConsensusFuture is a protocol that should not appear in any production
// network, but is used to test features before they are released.
const ConsensusFuture = ConsensusVersion(
Expand All @@ -218,7 +223,7 @@ const ConsensusVAlpha4 = ConsensusVersion("alpha4")

// ConsensusCurrentVersion is the latest version and should be used
// when a specific version is not provided.
const ConsensusCurrentVersion = ConsensusV35
const ConsensusCurrentVersion = ConsensusV36

// Error is used to indicate that an unsupported protocol has been detected.
type Error ConsensusVersion
Expand Down

0 comments on commit 06f9109

Please sign in to comment.