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

Consensus: Consensus version v40, set major release to 4 and reset minor. #6207

Merged
merged 11 commits into from
Dec 20, 2024
50 changes: 31 additions & 19 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,32 +1516,44 @@ func initConsensusProtocols() {
// but our current max is 150000 so using that :
v38.ApprovedUpgrades[protocol.ConsensusV39] = 150000

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

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

vFuture.EnableLogicSigSizePooling = true
v40.EnableLogicSigSizePooling = true

vFuture.Payouts.Enabled = true
vFuture.Payouts.Percent = 50
vFuture.Payouts.GoOnlineFee = 2_000_000 // 2 algos
vFuture.Payouts.MinBalance = 30_000_000_000 // 30,000 algos
vFuture.Payouts.MaxBalance = 70_000_000_000_000 // 70M algos
vFuture.Payouts.MaxMarkAbsent = 32
vFuture.Payouts.ChallengeInterval = 1000
vFuture.Payouts.ChallengeGracePeriod = 200
vFuture.Payouts.ChallengeBits = 5
v40.Payouts.Enabled = true
v40.Payouts.Percent = 50
v40.Payouts.GoOnlineFee = 2_000_000 // 2 algos
v40.Payouts.MinBalance = 30_000_000_000 // 30,000 algos
v40.Payouts.MaxBalance = 70_000_000_000_000 // 70M algos
v40.Payouts.MaxMarkAbsent = 32
v40.Payouts.ChallengeInterval = 1000
v40.Payouts.ChallengeGracePeriod = 200
v40.Payouts.ChallengeBits = 5

vFuture.Bonus.BaseAmount = 10_000_000 // 10 Algos
v40.Bonus.BaseAmount = 10_000_000 // 10 Algos
// 2.9 sec rounds gives about 10.8M rounds per year.
vFuture.Bonus.DecayInterval = 1_000_000 // .99^(10.8M/1M) ~ .897. So ~10% decay per year
v40.Bonus.DecayInterval = 1_000_000 // .99^(10.8M/1M) ~ .897. So ~10% decay per year

v40.Heartbeat = true

v40.EnableCatchpointsWithOnlineAccounts = true

vFuture.Heartbeat = true
Consensus[protocol.ConsensusV40] = v40

// v39 can be upgraded to v40, with an update delay of 7d:
// 208000 = (7 * 24 * 60 * 60 / 2.9 ballpark round times)
// our current max is 250000
v39.ApprovedUpgrades[protocol.ConsensusV40] = 208000

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

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

Consensus[protocol.ConsensusFuture] = vFuture

Expand Down
4 changes: 2 additions & 2 deletions config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (

// VersionMajor is the Major semantic version number (#.y.z) - changed when first public release (0.y.z -> 1.y.z)
// and when backwards compatibility is broken.
const VersionMajor = 3
const VersionMajor = 4

// VersionMinor is the Minor semantic version number (x.#.z) - changed when backwards-compatible features are introduced.
// Not enforced until after initial public release (x > 0).
const VersionMinor = 28
const VersionMinor = 0

// Version is the type holding our full version information.
type Version struct {
Expand Down
12 changes: 11 additions & 1 deletion data/bookkeeping/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,22 @@ import (
var delegatesMoney = basics.MicroAlgos{Raw: 1000 * 1000 * 1000}

var proto1 = protocol.ConsensusVersion("Test1")
var proto1NoBonus = protocol.ConsensusVersion("Test1NoBonus")
var proto2 = protocol.ConsensusVersion("Test2")
var proto3 = protocol.ConsensusVersion("Test3")
var protoUnsupported = protocol.ConsensusVersion("TestUnsupported")
var protoDelay = protocol.ConsensusVersion("TestDelay")

func init() {
verBeforeBonus := protocol.ConsensusV39
params1NB := config.Consensus[verBeforeBonus]
params1NB.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{
proto2: 0,
}
params1NB.MinUpgradeWaitRounds = 0
params1NB.MaxUpgradeWaitRounds = 0
config.Consensus[proto1NoBonus] = params1NB

params1 := config.Consensus[protocol.ConsensusCurrentVersion]
params1.ApprovedUpgrades = map[protocol.ConsensusVersion]uint64{
proto2: 0,
Expand Down Expand Up @@ -263,7 +273,7 @@ func TestBonus(t *testing.T) {
t.Parallel()

var prev Block
prev.CurrentProtocol = proto1
prev.CurrentProtocol = proto1NoBonus
prev.BlockHeader.GenesisID = t.Name()
crypto.RandBytes(prev.BlockHeader.GenesisHash[:])

Expand Down
1 change: 1 addition & 0 deletions data/pools/transactionPool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ func TestStateProofLogging(t *testing.T) {
b.BlockHeader.GenesisHash = mockLedger.GenesisHash()
b.CurrentProtocol = protocol.ConsensusCurrentVersion
b.BlockHeader.Round = 1
b.BlockHeader.Bonus = basics.MicroAlgos{Raw: 10000000}

phdr, err := mockLedger.BlockHdr(0)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 1,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v10.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 10,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v11.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 11,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 2,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 3,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 4,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v5.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 5,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 6,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v7.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 7,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v8.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 8,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
2 changes: 1 addition & 1 deletion data/transactions/logic/langspec_v9.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 9,
"LogicSigVersion": 10,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down
3 changes: 3 additions & 0 deletions ledger/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ return`
blk.TxnCounter = blk.TxnCounter + 2
blk.Payset = append(blk.Payset, txib1, txib2)
blk.TxnCommitments, err = blk.PaysetCommit()
blk.FeesCollected = basics.MicroAlgos{Raw: txib1.Txn.Fee.Raw + txib2.Txn.Fee.Raw}
a.NoError(err)
err = l.appendUnvalidated(blk)
a.NoError(err)
Expand Down Expand Up @@ -731,6 +732,7 @@ return`
blk.TxnCounter = blk.TxnCounter + 2
blk.Payset = append(blk.Payset, txib1, txib2)
blk.TxnCommitments, err = blk.PaysetCommit()
blk.FeesCollected = basics.MicroAlgos{Raw: txib1.Txn.Fee.Raw + txib2.Txn.Fee.Raw}
a.NoError(err)
err = l.appendUnvalidated(blk)
a.NoError(err)
Expand Down Expand Up @@ -867,6 +869,7 @@ return`
blk.TxnCounter = blk.TxnCounter + 2
blk.Payset = append(blk.Payset, txib1, txib2)
blk.TxnCommitments, err = blk.PaysetCommit()
blk.FeesCollected = basics.MicroAlgos{Raw: txib1.Txn.Fee.Raw + txib2.Txn.Fee.Raw}
a.NoError(err)
err = l.appendUnvalidated(blk)
a.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions ledger/catchpointfilewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (cw *catchpointFileWriter) readDatabaseStep(ctx context.Context) error {
if !cw.onlineAccountsDone {
// Create the OnlineAccounts iterator JIT
if cw.onlineAccountRows == nil {
rows, err := cw.tx.MakeOnlineAccountsIter(ctx)
rows, err := cw.tx.MakeOnlineAccountsIter(ctx, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -402,7 +402,7 @@ func (cw *catchpointFileWriter) readDatabaseStep(ctx context.Context) error {
if !cw.onlineRoundParamsDone {
// Create the OnlineRoundParams iterator JIT
if cw.onlineRoundParamsRows == nil {
rows, err := cw.tx.MakeOnlineRoundParamsIter(ctx)
rows, err := cw.tx.MakeOnlineRoundParamsIter(ctx, false)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions ledger/catchpointfilewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,18 +1095,18 @@ assert
t.Log("DB round generator", genDBRound, "validator", valDBRound)
t.Log("Latest round generator", genLatestRound, "validator", valLatestRound)

genOAHash, genOARows, err := calculateVerificationHash(context.Background(), dl.generator.trackerDB().MakeOnlineAccountsIter)
genOAHash, genOARows, err := calculateVerificationHash(context.Background(), dl.generator.trackerDB().MakeOnlineAccountsIter, false)
require.NoError(t, err)
valOAHash, valOARows, err := calculateVerificationHash(context.Background(), dl.validator.trackerDB().MakeOnlineAccountsIter)
valOAHash, valOARows, err := calculateVerificationHash(context.Background(), dl.validator.trackerDB().MakeOnlineAccountsIter, false)
require.NoError(t, err)
require.Equal(t, genOAHash, valOAHash)
require.NotZero(t, genOAHash)
require.Equal(t, genOARows, valOARows)
require.NotZero(t, genOARows)

genORPHash, genORPRows, err := calculateVerificationHash(context.Background(), dl.generator.trackerDB().MakeOnlineRoundParamsIter)
genORPHash, genORPRows, err := calculateVerificationHash(context.Background(), dl.generator.trackerDB().MakeOnlineRoundParamsIter, false)
require.NoError(t, err)
valORPHash, valORPRows, err := calculateVerificationHash(context.Background(), dl.validator.trackerDB().MakeOnlineRoundParamsIter)
valORPHash, valORPRows, err := calculateVerificationHash(context.Background(), dl.validator.trackerDB().MakeOnlineRoundParamsIter, false)
require.NoError(t, err)
require.Equal(t, genORPHash, valORPHash)
require.NotZero(t, genORPHash)
Expand All @@ -1123,13 +1123,13 @@ assert
l := testNewLedgerFromCatchpoint(t, dl.generator.trackerDB(), catchpointFilePath)
defer l.Close()

catchpointOAHash, catchpointOARows, err := calculateVerificationHash(context.Background(), l.trackerDBs.MakeOnlineAccountsIter)
catchpointOAHash, catchpointOARows, err := calculateVerificationHash(context.Background(), l.trackerDBs.MakeOnlineAccountsIter, false)
require.NoError(t, err)
require.Equal(t, genOAHash, catchpointOAHash)
t.Log("catchpoint onlineaccounts hash", catchpointOAHash, "matches")
require.Equal(t, genOARows, catchpointOARows)

catchpointORPHash, catchpointORPRows, err := calculateVerificationHash(context.Background(), l.trackerDBs.MakeOnlineRoundParamsIter)
catchpointORPHash, catchpointORPRows, err := calculateVerificationHash(context.Background(), l.trackerDBs.MakeOnlineRoundParamsIter, false)
require.NoError(t, err)
require.Equal(t, genORPHash, catchpointORPHash)
t.Log("catchpoint onlineroundparams hash", catchpointORPHash, "matches")
Expand Down
4 changes: 2 additions & 2 deletions ledger/catchpointtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ func (ct *catchpointTracker) finishFirstStage(ctx context.Context, dbRound basic
// Generate hashes of the onlineaccounts and onlineroundparams tables.
err := ct.dbs.Snapshot(func(ctx context.Context, tx trackerdb.SnapshotScope) error {
var dbErr error
onlineAccountsHash, _, dbErr = calculateVerificationHash(ctx, tx.MakeOnlineAccountsIter)
onlineAccountsHash, _, dbErr = calculateVerificationHash(ctx, tx.MakeOnlineAccountsIter, false)
if dbErr != nil {
return dbErr

}

onlineRoundParamsHash, _, dbErr = calculateVerificationHash(ctx, tx.MakeOnlineRoundParamsIter)
onlineRoundParamsHash, _, dbErr = calculateVerificationHash(ctx, tx.MakeOnlineRoundParamsIter, false)
if dbErr != nil {
return dbErr
}
Expand Down
9 changes: 5 additions & 4 deletions ledger/catchupaccessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,12 +1031,12 @@
return fmt.Errorf("unable to get state proof verification data: %v", err)
}

onlineAccountsHash, _, err = calculateVerificationHash(ctx, tx.MakeOnlineAccountsIter)
onlineAccountsHash, _, err = calculateVerificationHash(ctx, tx.MakeOnlineAccountsIter, true)

Check warning on line 1034 in ledger/catchupaccessor.go

View check run for this annotation

Codecov / codecov/patch

ledger/catchupaccessor.go#L1034

Added line #L1034 was not covered by tests
if err != nil {
return fmt.Errorf("unable to get online accounts verification data: %v", err)
}

onlineRoundParamsHash, _, err = calculateVerificationHash(ctx, tx.MakeOnlineRoundParamsIter)
onlineRoundParamsHash, _, err = calculateVerificationHash(ctx, tx.MakeOnlineRoundParamsIter, true)

Check warning on line 1039 in ledger/catchupaccessor.go

View check run for this annotation

Codecov / codecov/patch

ledger/catchupaccessor.go#L1039

Added line #L1039 was not covered by tests
if err != nil {
return fmt.Errorf("unable to get online round params verification data: %v", err)
}
Expand All @@ -1058,10 +1058,11 @@
// both at restore time (in catchpointCatchupAccessorImpl) and snapshot time (in catchpointTracker).
func calculateVerificationHash[T crypto.Hashable](
ctx context.Context,
iterFactory func(context.Context) (trackerdb.TableIterator[T], error),
iterFactory func(context.Context, bool) (trackerdb.TableIterator[T], error),
useStaging bool,
) (crypto.Digest, uint64, error) {

rows, err := iterFactory(ctx)
rows, err := iterFactory(ctx, useStaging)
if err != nil {
return crypto.Digest{}, 0, err
}
Expand Down
5 changes: 3 additions & 2 deletions ledger/eval_simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/committee"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/txntest"
"github.com/algorand/go-algorand/ledger/ledgercore"
Expand Down Expand Up @@ -1238,11 +1239,11 @@ func TestRekeying(t *testing.T) {
if err != nil {
return err
}
validatedBlock := ledgercore.MakeValidatedBlock(unfinishedBlock.UnfinishedBlock(), unfinishedBlock.UnfinishedDeltas())
fb := unfinishedBlock.FinishBlock(committee.Seed{0x01}, basics.Address{0x01}, false)

backlogPool := execpool.MakeBacklog(nil, 0, execpool.LowPriority, nil)
defer backlogPool.Shutdown()
_, err = l.Validate(context.Background(), validatedBlock.Block(), backlogPool)
_, err = l.Validate(context.Background(), fb, backlogPool)
return err
}

Expand Down
6 changes: 6 additions & 0 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func makeNewEmptyBlock(t *testing.T, l *Ledger, GenesisID string, initAccounts m
// UpgradeVote: empty,
}

if proto.Payouts.Enabled {
blk.BlockHeader.Proposer = basics.Address{0x01} // Must be set to _something_.
}

blk.TxnCommitments, err = blk.PaysetCommit()
require.NoError(t, err)

Expand Down Expand Up @@ -262,6 +266,8 @@ func TestLedgerBlockHeaders(t *testing.T) {
Round: l.Latest() + 1,
Branch: lastBlock.Hash(),
// Seed: does not matter,
Bonus: bookkeeping.NextBonus(lastBlock.BlockHeader, &proto),
Proposer: basics.Address{0x01}, // Must be set to _something_.
TimeStamp: 0,
GenesisID: t.Name(),
RewardsState: lastBlock.NextRewardsState(l.Latest()+1, proto, poolBal.MicroAlgos, totalRewardUnits, logging.Base()),
Expand Down
4 changes: 2 additions & 2 deletions ledger/store/trackerdb/dualdriver/dualdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@
}

// MakeOnlineAccountsIter implements trackerdb.Reader
func (*reader) MakeOnlineAccountsIter(ctx context.Context) (trackerdb.TableIterator[*encoded.OnlineAccountRecordV6], error) {
func (*reader) MakeOnlineAccountsIter(context.Context, bool) (trackerdb.TableIterator[*encoded.OnlineAccountRecordV6], error) {

Check warning on line 281 in ledger/store/trackerdb/dualdriver/dualdriver.go

View check run for this annotation

Codecov / codecov/patch

ledger/store/trackerdb/dualdriver/dualdriver.go#L281

Added line #L281 was not covered by tests
// TODO: catchpoint
return nil, nil
}

// MakeOnlineRoundParamsIter implements trackerdb.Reader
func (*reader) MakeOnlineRoundParamsIter(ctx context.Context) (trackerdb.TableIterator[*encoded.OnlineRoundParamsRecordV6], error) {
func (*reader) MakeOnlineRoundParamsIter(context.Context, bool) (trackerdb.TableIterator[*encoded.OnlineRoundParamsRecordV6], error) {

Check warning on line 287 in ledger/store/trackerdb/dualdriver/dualdriver.go

View check run for this annotation

Codecov / codecov/patch

ledger/store/trackerdb/dualdriver/dualdriver.go#L287

Added line #L287 was not covered by tests
// TODO: catchpoint
return nil, nil
}
Expand Down
Loading
Loading