From 788a62a234dedb7c2bd85a2a8bb26574381c6a4a Mon Sep 17 00:00:00 2001 From: mattfoley8 Date: Mon, 5 Jun 2023 12:10:48 -0400 Subject: [PATCH 1/3] Consolidate PoS block heights. --- lib/block_view_derived_key.go | 4 +- lib/block_view_stake.go | 12 +++--- lib/block_view_stake_test.go | 28 +++++++------- lib/block_view_types.go | 6 +-- lib/block_view_validator.go | 12 +++--- lib/block_view_validator_test.go | 26 ++++++------- lib/constants.go | 63 +++++++++++++++++++++++--------- lib/db_utils.go | 6 +-- lib/network.go | 6 +-- lib/pos_leader_schedule_test.go | 6 +-- 10 files changed, 99 insertions(+), 70 deletions(-) diff --git a/lib/block_view_derived_key.go b/lib/block_view_derived_key.go index c39055ab8..0ed063d47 100644 --- a/lib/block_view_derived_key.go +++ b/lib/block_view_derived_key.go @@ -310,8 +310,8 @@ func (bav *UtxoView) _connectAuthorizeDerivedKey( } } - // ====== Proof of Stake New Txn Types Fork ====== - if blockHeight >= bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + // ====== Proof of Stake State Setup Fork ====== + if blockHeight >= bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { // StakeLimitMap for stakeLimitKey, stakingLimit := range transactionSpendingLimit.StakeLimitMap { if err = bav.IsValidStakeLimitKey(txn.PublicKey, stakeLimitKey); err != nil { diff --git a/lib/block_view_stake.go b/lib/block_view_stake.go index 66df9a90b..02ef3f37c 100644 --- a/lib/block_view_stake.go +++ b/lib/block_view_stake.go @@ -1103,7 +1103,7 @@ func (bav *UtxoView) _connectStake( _err error, ) { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight || + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight || blockHeight < bav.Params.ForkHeights.BalanceModelBlockHeight { return 0, 0, nil, errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_connectStake: ") } @@ -1275,7 +1275,7 @@ func (bav *UtxoView) _disconnectStake( blockHeight uint32, ) error { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight || + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight || blockHeight < bav.Params.ForkHeights.BalanceModelBlockHeight { return errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_disconnectStake: ") } @@ -1365,7 +1365,7 @@ func (bav *UtxoView) _connectUnstake( _err error, ) { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight || + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight || blockHeight < bav.Params.ForkHeights.BalanceModelBlockHeight { return 0, 0, nil, errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_connectUnstake: ") } @@ -1553,7 +1553,7 @@ func (bav *UtxoView) _disconnectUnstake( blockHeight uint32, ) error { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight || + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight || blockHeight < bav.Params.ForkHeights.BalanceModelBlockHeight { return errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_disconnectUnstake: ") } @@ -1669,7 +1669,7 @@ func (bav *UtxoView) _connectUnlockStake( _err error, ) { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight || + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight || blockHeight < bav.Params.ForkHeights.BalanceModelBlockHeight { return 0, 0, nil, errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_connectUnlockStake: ") } @@ -1795,7 +1795,7 @@ func (bav *UtxoView) _disconnectUnlockStake( blockHeight uint32, ) error { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight || + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight || blockHeight < bav.Params.ForkHeights.BalanceModelBlockHeight { return errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_disconnectUnlockStake: ") } diff --git a/lib/block_view_stake_test.go b/lib/block_view_stake_test.go index f1ff8576f..30175aca9 100644 --- a/lib/block_view_stake_test.go +++ b/lib/block_view_stake_test.go @@ -21,7 +21,7 @@ func _testStaking(t *testing.T, flushToDB bool) { // Local variables var err error - // Initialize fork heights. + // Initialize balance model fork heights. setBalanceModelBlockHeights() defer resetBalanceModelBlockHeights() @@ -98,7 +98,7 @@ func _testStaking(t *testing.T, flushToDB bool) { } { // m0 registers as a validator. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -123,7 +123,7 @@ func _testStaking(t *testing.T, flushToDB bool) { // { // RuleErrorProofOfStakeTxnBeforeBlockHeight - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = math.MaxUint32 + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = math.MaxUint32 GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -137,7 +137,7 @@ func _testStaking(t *testing.T, flushToDB bool) { require.Error(t, err) require.Contains(t, err.Error(), RuleErrorProofofStakeTxnBeforeBlockHeight) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) } @@ -276,7 +276,7 @@ func _testStaking(t *testing.T, flushToDB bool) { // { // RuleErrorProofOfStakeTxnBeforeBlockHeight - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = math.MaxUint32 + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = math.MaxUint32 GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -290,7 +290,7 @@ func _testStaking(t *testing.T, flushToDB bool) { require.Error(t, err) require.Contains(t, err.Error(), RuleErrorProofofStakeTxnBeforeBlockHeight) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) } @@ -472,7 +472,7 @@ func _testStaking(t *testing.T, flushToDB bool) { // { // RuleErrorProofOfStakeTxnBeforeBlockHeight - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = math.MaxUint32 + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = math.MaxUint32 GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -487,7 +487,7 @@ func _testStaking(t *testing.T, flushToDB bool) { require.Error(t, err) require.Contains(t, err.Error(), RuleErrorProofofStakeTxnBeforeBlockHeight) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) } @@ -770,9 +770,9 @@ func TestStakingWithDerivedKey(t *testing.T) { chain, params, db := NewLowDifficultyBlockchain(t) mempool, miner := NewTestMiner(t, chain, params, true) - // Initialize fork heights. + // Initialize PoS fork heights. params.ForkHeights.DeSoUnlimitedDerivedKeysBlockHeight = uint32(0) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) chain.snapshot = nil @@ -1694,7 +1694,7 @@ func TestGetLockedStakeEntriesInRange(t *testing.T) { utxoView._setLockedStakeEntryMappings(lockedStakeEntry) require.NoError(t, utxoView.FlushToDb(blockHeight)) - // Fetch the LockedStakeEntry so it is also cached in the UtxoView. + // Fetch the LockedStakeEntry, so it is also cached in the UtxoView. lockedStakeEntry, err = utxoView.GetLockedStakeEntry(m0PKID, m0PKID, 2) require.NoError(t, err) require.NotNil(t, lockedStakeEntry) @@ -1782,7 +1782,7 @@ func TestStakeLockupEpochDuration(t *testing.T) { // Initialize fork heights. params.ForkHeights.DeSoUnlimitedDerivedKeysBlockHeight = uint32(0) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) chain.snapshot = nil @@ -1951,8 +1951,8 @@ func testStakingToJailedValidator(t *testing.T, flushToDB bool) { chain, params, db := NewLowDifficultyBlockchain(t) mempool, miner := NewTestMiner(t, chain, params, true) - // Initialize fork heights. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + // Initialize PoS fork heights. + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) chain.snapshot = nil diff --git a/lib/block_view_types.go b/lib/block_view_types.go index 7641a34df..d173c354f 100644 --- a/lib/block_view_types.go +++ b/lib/block_view_types.go @@ -1241,7 +1241,7 @@ func (op *UtxoOperation) RawEncodeWithoutMetadata(blockHeight uint64, skipMetada } } - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { // PrevValidatorEntry data = append(data, EncodeToBytes(blockHeight, op.PrevValidatorEntry, skipMetadata...)...) @@ -1870,7 +1870,7 @@ func (op *UtxoOperation) RawDecodeWithoutMetadata(blockHeight uint64, rr *bytes. } } - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { // PrevValidatorEntry if op.PrevValidatorEntry, err = DecodeDeSoEncoder(&ValidatorEntry{}, rr); err != nil { return errors.Wrapf(err, "UtxoOperation.Decode: Problem reading PrevValidatorEntry: ") @@ -1900,7 +1900,7 @@ func (op *UtxoOperation) GetVersionByte(blockHeight uint64) byte { blockHeight, AssociationsAndAccessGroupsMigration, BalanceModelMigration, - ProofOfStakeNewTxnTypesMigration, + ProofOfStake1StateSetupMigration, ) } diff --git a/lib/block_view_validator.go b/lib/block_view_validator.go index 8ba3e82ed..864759b5f 100644 --- a/lib/block_view_validator.go +++ b/lib/block_view_validator.go @@ -994,7 +994,7 @@ func (bav *UtxoView) _connectRegisterAsValidator( _err error, ) { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { return 0, 0, nil, errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_connectRegisterAsValidator: ") } @@ -1115,7 +1115,7 @@ func (bav *UtxoView) _disconnectRegisterAsValidator( blockHeight uint32, ) error { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { return errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_disconnectRegisterAsValidator: ") } @@ -1178,7 +1178,7 @@ func (bav *UtxoView) _connectUnregisterAsValidator( _err error, ) { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { return 0, 0, nil, errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_connectUnregisterAsValidator: ") } @@ -1350,7 +1350,7 @@ func (bav *UtxoView) _disconnectUnregisterAsValidator( blockHeight uint32, ) error { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { return errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_disconnectUnregisterAsValidator: ") } @@ -1436,7 +1436,7 @@ func (bav *UtxoView) _connectUnjailValidator( _err error, ) { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { return 0, 0, nil, errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_connectUnjailValidator: ") } @@ -1541,7 +1541,7 @@ func (bav *UtxoView) _disconnectUnjailValidator( blockHeight uint32, ) error { // Validate the starting block height. - if blockHeight < bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight < bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { return errors.Wrapf(RuleErrorProofofStakeTxnBeforeBlockHeight, "_disconnectUnjailValidator: ") } diff --git a/lib/block_view_validator_test.go b/lib/block_view_validator_test.go index 33a4d210d..102a1b2df 100644 --- a/lib/block_view_validator_test.go +++ b/lib/block_view_validator_test.go @@ -27,7 +27,7 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) { var globalActiveStakeAmountNanos *uint256.Int var err error - // Initialize fork heights. + // Initialize balance model fork heights. setBalanceModelBlockHeights() defer resetBalanceModelBlockHeights() @@ -88,7 +88,7 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) { } { // RuleErrorProofOfStakeTxnBeforeBlockHeight - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = math.MaxUint32 + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = math.MaxUint32 GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -103,7 +103,7 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) { require.Error(t, err) require.Contains(t, err.Error(), RuleErrorProofofStakeTxnBeforeBlockHeight) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) } @@ -432,8 +432,8 @@ func TestValidatorRegistrationWithDerivedKey(t *testing.T) { chain, params, db := NewLowDifficultyBlockchain(t) mempool, miner := NewTestMiner(t, chain, params, true) - // Initialize fork heights. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + // Initialize PoS fork height. + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -710,7 +710,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) { mempool, miner := NewTestMiner(t, chain, params, true) // Initialize PoS fork height. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -1153,7 +1153,7 @@ func _testUpdatingValidatorDisableDelegatedStake(t *testing.T, flushToDB bool) { mempool, miner := NewTestMiner(t, chain, params, true) // Initialize PoS fork height. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -1348,7 +1348,7 @@ func _testUnregisterAsValidator(t *testing.T, flushToDB bool) { mempool, miner := NewTestMiner(t, chain, params, true) // Initialize PoS fork height. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -1550,7 +1550,7 @@ func _testUnjailValidator(t *testing.T, flushToDB bool) { mempool, miner := NewTestMiner(t, chain, params, true) // Initialize PoS fork height. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) chain.snapshot = nil @@ -1721,7 +1721,7 @@ func _testUnjailValidator(t *testing.T, flushToDB bool) { } { // RuleErrorProofofStakeTxnBeforeBlockHeight - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = math.MaxUint32 + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = math.MaxUint32 GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) @@ -1729,7 +1729,7 @@ func _testUnjailValidator(t *testing.T, flushToDB bool) { require.Error(t, err) require.Contains(t, err.Error(), RuleErrorProofofStakeTxnBeforeBlockHeight) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) } @@ -1767,8 +1767,8 @@ func TestUnjailValidatorWithDerivedKey(t *testing.T) { chain, params, db := NewLowDifficultyBlockchain(t) mempool, miner := NewTestMiner(t, chain, params, true) - // Initialize fork heights. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + // Initialize PoS fork height. + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) diff --git a/lib/constants.go b/lib/constants.go index 52c651669..cbdaeb3ed 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -270,10 +270,20 @@ type ForkHeights struct { // to an account balance model for accounting. BalanceModelBlockHeight uint32 - // ProofOfStakeNewTxnTypesBlockHeight defines the height at which we introduced the - // new txn types to support Proof of Stake. These txns include: RegisterAsValidator, - // UnregisterAsValidator, Stake, Unstake, and UnlockStake. - ProofOfStakeNewTxnTypesBlockHeight uint32 + // ProofOfStake1StateSetupBlockHeight defines the height at which we introduced all + // changes to set up the prerequisite state for cutting over to PoS consensus. These + // changes include, for example, introducing the new PoS txn types, consensus params, + // leader schedule generation, and snapshotting. + // + // The ProofOfStake1StateSetupBlockHeight needs to be set before the + // ProofOfStake2ConsensusCutoverBlockHeight so that we allow time for validators to + // register, stake to be assigned, and the validator set, consensus params, and + // leader schedule snapshots to be generated in advance. + ProofOfStake1StateSetupBlockHeight uint32 + + // ProofOfStake2ConsensusCutoverBlockHeight defines the height at which we cut over + // from PoW consensus to PoS consensus. + ProofOfStake2ConsensusCutoverBlockHeight uint32 // Be sure to update EncoderMigrationHeights as well via // GetEncoderMigrationHeights if you're modifying schema. @@ -335,11 +345,12 @@ type MigrationHeight struct { } const ( - DefaultMigration MigrationName = "DefaultMigration" - UnlimitedDerivedKeysMigration MigrationName = "UnlimitedDerivedKeysMigration" - AssociationsAndAccessGroupsMigration MigrationName = "AssociationsAndAccessGroupsMigration" - BalanceModelMigration MigrationName = "BalanceModelMigration" - ProofOfStakeNewTxnTypesMigration MigrationName = "ProofOfStakeNewTxnTypesMigration" + DefaultMigration MigrationName = "DefaultMigration" + UnlimitedDerivedKeysMigration MigrationName = "UnlimitedDerivedKeysMigration" + AssociationsAndAccessGroupsMigration MigrationName = "AssociationsAndAccessGroupsMigration" + BalanceModelMigration MigrationName = "BalanceModelMigration" + ProofOfStake1StateSetupMigration MigrationName = "ProofOfStake1StateSetupMigration" + ProofOfStake2ConsensusCutoverMigration MigrationName = "ProofOfStake2ConsensusCutoverMigration" ) type EncoderMigrationHeights struct { @@ -354,8 +365,11 @@ type EncoderMigrationHeights struct { // This coincides with the BalanceModel block BalanceModel MigrationHeight - // This coincides with the ProofOfStakeNewTxnTypesBlockHeight - ProofOfStakeNewTxnTypesMigration MigrationHeight + // This coincides with the ProofOfStake1StateSetupBlockHeight + ProofOfStake1StateSetupMigration MigrationHeight + + // This coincides with the ProofOfStake2ConsensusCutoverBlockHeight + ProofOfStake2ConsensusCutoverMigration MigrationHeight } func GetEncoderMigrationHeights(forkHeights *ForkHeights) *EncoderMigrationHeights { @@ -380,13 +394,19 @@ func GetEncoderMigrationHeights(forkHeights *ForkHeights) *EncoderMigrationHeigh Height: uint64(forkHeights.BalanceModelBlockHeight), Name: BalanceModelMigration, }, - ProofOfStakeNewTxnTypesMigration: MigrationHeight{ + ProofOfStake1StateSetupMigration: MigrationHeight{ Version: 4, - Height: uint64(forkHeights.ProofOfStakeNewTxnTypesBlockHeight), - Name: ProofOfStakeNewTxnTypesMigration, + Height: uint64(forkHeights.ProofOfStake1StateSetupBlockHeight), + Name: ProofOfStake1StateSetupMigration, + }, + ProofOfStake2ConsensusCutoverMigration: MigrationHeight{ + Version: 5, + Height: uint64(forkHeights.ProofOfStake2ConsensusCutoverBlockHeight), + Name: ProofOfStake2ConsensusCutoverMigration, }, } } + func GetEncoderMigrationHeightsList(forkHeights *ForkHeights) ( _migrationHeightsList []*MigrationHeight) { @@ -645,7 +665,10 @@ var RegtestForkHeights = ForkHeights{ // For convenience, we set the block height to 1 since the // genesis block was created using the utxo model. BalanceModelBlockHeight: uint32(1), - ProofOfStakeNewTxnTypesBlockHeight: uint32(1), + ProofOfStake1StateSetupBlockHeight: uint32(1), + + // FIXME: set to real block height when ready + ProofOfStake2ConsensusCutoverBlockHeight: uint32(math.MaxUint32), // Be sure to update EncoderMigrationHeights as well via // GetEncoderMigrationHeights if you're modifying schema. @@ -799,7 +822,10 @@ var MainnetForkHeights = ForkHeights{ BalanceModelBlockHeight: uint32(226839), // FIXME: set to real block height when ready - ProofOfStakeNewTxnTypesBlockHeight: uint32(math.MaxUint32), + ProofOfStake1StateSetupBlockHeight: uint32(math.MaxUint32), + + // FIXME: set to real block height when ready + ProofOfStake2ConsensusCutoverBlockHeight: uint32(math.MaxUint32), // Be sure to update EncoderMigrationHeights as well via // GetEncoderMigrationHeights if you're modifying schema. @@ -1074,7 +1100,10 @@ var TestnetForkHeights = ForkHeights{ BalanceModelBlockHeight: uint32(683058), // FIXME: set to real block height when ready - ProofOfStakeNewTxnTypesBlockHeight: uint32(math.MaxUint32), + ProofOfStake1StateSetupBlockHeight: uint32(math.MaxUint32), + + // FIXME: set to real block height when ready + ProofOfStake2ConsensusCutoverBlockHeight: uint32(math.MaxUint32), // Be sure to update EncoderMigrationHeights as well via // GetEncoderMigrationHeights if you're modifying schema. diff --git a/lib/db_utils.go b/lib/db_utils.go index 409aa03ed..01eae3507 100644 --- a/lib/db_utils.go +++ b/lib/db_utils.go @@ -6912,7 +6912,7 @@ func (txnMeta *TransactionMetadata) RawEncodeWithoutMetadata(blockHeight uint64, data = append(data, EncodeToBytes(blockHeight, txnMeta.NewMessageTxindexMetadata, skipMetadata...)...) } - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { // encoding RegisterAsValidatorTxindexMetadata data = append(data, EncodeToBytes(blockHeight, txnMeta.RegisterAsValidatorTxindexMetadata, skipMetadata...)...) // encoding UnregisterAsValidatorTxindexMetadata @@ -7176,7 +7176,7 @@ func (txnMeta *TransactionMetadata) RawDecodeWithoutMetadata(blockHeight uint64, } } - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { // decoding RegisterAsValidatorTxindexMetadata if txnMeta.RegisterAsValidatorTxindexMetadata, err = DecodeDeSoEncoder(&RegisterAsValidatorTxindexMetadata{}, rr); err != nil { return errors.Wrapf(err, "TransactionMetadata.Decode: Problem reading RegisterAsValidatorTxindexMetadata: ") @@ -7207,7 +7207,7 @@ func (txnMeta *TransactionMetadata) RawDecodeWithoutMetadata(blockHeight uint64, } func (txnMeta *TransactionMetadata) GetVersionByte(blockHeight uint64) byte { - return GetMigrationVersion(blockHeight, AssociationsAndAccessGroupsMigration, ProofOfStakeNewTxnTypesMigration) + return GetMigrationVersion(blockHeight, AssociationsAndAccessGroupsMigration, ProofOfStake1StateSetupMigration) } func (txnMeta *TransactionMetadata) GetEncoderType() EncoderType { diff --git a/lib/network.go b/lib/network.go index 0ce83d3e4..b407e51c3 100644 --- a/lib/network.go +++ b/lib/network.go @@ -5389,7 +5389,7 @@ type TransactionSpendingLimit struct { // - AssociationOperation: one of { Any, Create, Delete } AssociationLimitMap map[AssociationLimitKey]uint64 - // ===== ENCODER MIGRATION ProofOfStakeNewTxnTypesMigration ===== + // ===== ENCODER MIGRATION ProofOfStake1StateSetupMigration ===== // ValidatorPKID || StakerPKID to amount of stake-able $DESO. // Note that this is not a limit on the number of Stake txns that // this derived key can perform but instead a limit on the amount @@ -5956,7 +5956,7 @@ func (tsl *TransactionSpendingLimit) ToBytes(blockHeight uint64) ([]byte, error) } // StakeLimitMap, UnstakeLimitMap, and UnlockStakeLimitMap, gated by the encoder migration. - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { // StakeLimitMap stakeLimitMapLength := uint64(len(tsl.StakeLimitMap)) data = append(data, UintToBuf(stakeLimitMapLength)...) @@ -6231,7 +6231,7 @@ func (tsl *TransactionSpendingLimit) FromBytes(blockHeight uint64, rr *bytes.Rea } // StakeLimitMap, UnstakeLimitMap, and UnlockStakeLimitMap, gated by the encoder migration. - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { // StakeLimitMap stakeLimitMapLen, err := ReadUvarint(rr) if err != nil { diff --git a/lib/pos_leader_schedule_test.go b/lib/pos_leader_schedule_test.go index c4c44ebe9..207bcfa70 100644 --- a/lib/pos_leader_schedule_test.go +++ b/lib/pos_leader_schedule_test.go @@ -11,7 +11,7 @@ import ( ) func TestGenerateLeaderSchedule(t *testing.T) { - // Initialize fork heights. + // Initialize balance model fork heights. setBalanceModelBlockHeights() defer resetBalanceModelBlockHeights() @@ -19,8 +19,8 @@ func TestGenerateLeaderSchedule(t *testing.T) { chain, params, db := NewLowDifficultyBlockchain(t) mempool, miner := NewTestMiner(t, chain, params, true) - // Initialize PoS txn types block height. - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + // Initialize PoS fork height. + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights) From 88a3565c428e91295d00a9f504694a0a0ae0356b Mon Sep 17 00:00:00 2001 From: mattfoley8 Date: Tue, 6 Jun 2023 09:15:39 -0400 Subject: [PATCH 2/3] Delete the CutoverMigration for now. --- lib/constants.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/constants.go b/lib/constants.go index cbdaeb3ed..6d81834d4 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -345,12 +345,11 @@ type MigrationHeight struct { } const ( - DefaultMigration MigrationName = "DefaultMigration" - UnlimitedDerivedKeysMigration MigrationName = "UnlimitedDerivedKeysMigration" - AssociationsAndAccessGroupsMigration MigrationName = "AssociationsAndAccessGroupsMigration" - BalanceModelMigration MigrationName = "BalanceModelMigration" - ProofOfStake1StateSetupMigration MigrationName = "ProofOfStake1StateSetupMigration" - ProofOfStake2ConsensusCutoverMigration MigrationName = "ProofOfStake2ConsensusCutoverMigration" + DefaultMigration MigrationName = "DefaultMigration" + UnlimitedDerivedKeysMigration MigrationName = "UnlimitedDerivedKeysMigration" + AssociationsAndAccessGroupsMigration MigrationName = "AssociationsAndAccessGroupsMigration" + BalanceModelMigration MigrationName = "BalanceModelMigration" + ProofOfStake1StateSetupMigration MigrationName = "ProofOfStake1StateSetupMigration" ) type EncoderMigrationHeights struct { @@ -367,9 +366,6 @@ type EncoderMigrationHeights struct { // This coincides with the ProofOfStake1StateSetupBlockHeight ProofOfStake1StateSetupMigration MigrationHeight - - // This coincides with the ProofOfStake2ConsensusCutoverBlockHeight - ProofOfStake2ConsensusCutoverMigration MigrationHeight } func GetEncoderMigrationHeights(forkHeights *ForkHeights) *EncoderMigrationHeights { @@ -399,11 +395,6 @@ func GetEncoderMigrationHeights(forkHeights *ForkHeights) *EncoderMigrationHeigh Height: uint64(forkHeights.ProofOfStake1StateSetupBlockHeight), Name: ProofOfStake1StateSetupMigration, }, - ProofOfStake2ConsensusCutoverMigration: MigrationHeight{ - Version: 5, - Height: uint64(forkHeights.ProofOfStake2ConsensusCutoverBlockHeight), - Name: ProofOfStake2ConsensusCutoverMigration, - }, } } From 5d58c0953916f507ea1a50198e0c85797e927da4 Mon Sep 17 00:00:00 2001 From: mattfoley8 Date: Tue, 6 Jun 2023 09:23:16 -0400 Subject: [PATCH 3/3] Merge upstream branch. Resolve conflicts. --- lib/block_view.go | 2 +- lib/block_view_types.go | 6 +++--- lib/block_view_validator_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/block_view.go b/lib/block_view.go index 1dbac280d..0321f0131 100644 --- a/lib/block_view.go +++ b/lib/block_view.go @@ -2963,7 +2963,7 @@ func (bav *UtxoView) _connectUpdateGlobalParams( newGlobalParamsEntry.MaxNonceExpirationBlockHeightOffset = newMaxNonceExpirationBlockHeightOffset } - if blockHeight >= bav.Params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight { + if blockHeight >= bav.Params.ForkHeights.ProofOfStake1StateSetupBlockHeight { var bytesRead int if len(extraData[StakeLockupEpochDuration]) > 0 { newGlobalParamsEntry.StakeLockupEpochDuration, bytesRead = Uvarint(extraData[StakeLockupEpochDuration]) diff --git a/lib/block_view_types.go b/lib/block_view_types.go index c6640015a..2fcab1871 100644 --- a/lib/block_view_types.go +++ b/lib/block_view_types.go @@ -3793,7 +3793,7 @@ func (gp *GlobalParamsEntry) RawEncodeWithoutMetadata(blockHeight uint64, skipMe if MigrationTriggered(blockHeight, BalanceModelMigration) { data = append(data, UintToBuf(gp.MaxNonceExpirationBlockHeightOffset)...) } - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { data = append(data, UintToBuf(gp.StakeLockupEpochDuration)...) data = append(data, UintToBuf(gp.ValidatorJailEpochDuration)...) } @@ -3829,7 +3829,7 @@ func (gp *GlobalParamsEntry) RawDecodeWithoutMetadata(blockHeight uint64, rr *by return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MaxNonceExpirationBlockHeightOffset") } } - if MigrationTriggered(blockHeight, ProofOfStakeNewTxnTypesMigration) { + if MigrationTriggered(blockHeight, ProofOfStake1StateSetupMigration) { gp.StakeLockupEpochDuration, err = ReadUvarint(rr) if err != nil { return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading StakeLockupEpochDuration") @@ -3843,7 +3843,7 @@ func (gp *GlobalParamsEntry) RawDecodeWithoutMetadata(blockHeight uint64, rr *by } func (gp *GlobalParamsEntry) GetVersionByte(blockHeight uint64) byte { - return GetMigrationVersion(blockHeight, BalanceModelMigration, ProofOfStakeNewTxnTypesMigration) + return GetMigrationVersion(blockHeight, BalanceModelMigration, ProofOfStake1StateSetupMigration) } func (gp *GlobalParamsEntry) GetEncoderType() EncoderType { diff --git a/lib/block_view_validator_test.go b/lib/block_view_validator_test.go index 385f6fc89..b2ef8b20e 100644 --- a/lib/block_view_validator_test.go +++ b/lib/block_view_validator_test.go @@ -35,7 +35,7 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) { chain, params, db := NewLowDifficultyBlockchain(t) mempool, miner := NewTestMiner(t, chain, params, true) - params.ForkHeights.ProofOfStakeNewTxnTypesBlockHeight = uint32(1) + params.ForkHeights.ProofOfStake1StateSetupBlockHeight = uint32(1) GlobalDeSoParams.EncoderMigrationHeights = GetEncoderMigrationHeights(¶ms.ForkHeights) GlobalDeSoParams.EncoderMigrationHeightsList = GetEncoderMigrationHeightsList(¶ms.ForkHeights)