Skip to content

Commit

Permalink
[PVM] DAC voting, AddProposalTx, AddVoteTx, FinishProposalsTx
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Aug 14, 2023
1 parent 0c5035f commit 4c1b2c3
Show file tree
Hide file tree
Showing 63 changed files with 9,415 additions and 318 deletions.
8 changes: 4 additions & 4 deletions config/camino.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
)

const (
DaoProposalBondAmountKey = "dao-proposal-bond-amount"
DACProposalBondAmountKey = "dac-proposal-bond-amount"
)

func addCaminoFlags(fs *flag.FlagSet) {
// Bond amount required to place a DAO proposal on the Primary Network
fs.Uint64(DaoProposalBondAmountKey, genesis.LocalParams.CaminoConfig.DaoProposalBondAmount, "Amount, in nAVAX, required to place a DAO proposal")
// Bond amount required to place a DAC proposal on the Primary Network
fs.Uint64(DACProposalBondAmountKey, genesis.LocalParams.CaminoConfig.DACProposalBondAmount, "Amount, in nAVAX, required to place a DAC proposal")
}

func getCaminoPlatformConfig(v *viper.Viper) caminoconfig.Config {
conf := caminoconfig.Config{
DaoProposalBondAmount: v.GetUint64(DaoProposalBondAmountKey),
DACProposalBondAmount: v.GetUint64(DACProposalBondAmountKey),
}
return conf
}
170 changes: 170 additions & 0 deletions database/linkeddb/mock_linkeddb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion genesis/genesis_camino.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
SupplyCap: 1000 * units.MegaAvax,
},
CaminoConfig: caminoconfig.Config{
DaoProposalBondAmount: 1 * units.KiloAvax,
DACProposalBondAmount: 1 * units.KiloAvax,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion genesis/genesis_columbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
SupplyCap: 1000 * units.MegaAvax,
},
CaminoConfig: caminoconfig.Config{
DaoProposalBondAmount: 100 * units.Avax,
DACProposalBondAmount: 100 * units.Avax,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion genesis/genesis_kopernikus.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
SupplyCap: 1000 * units.MegaAvax,
},
CaminoConfig: caminoconfig.Config{
DaoProposalBondAmount: 100 * units.Avax,
DACProposalBondAmount: 100 * units.Avax,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion genesis/genesis_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var (
SupplyCap: 720 * units.MegaAvax,
},
CaminoConfig: caminoconfig.Config{
DaoProposalBondAmount: 100 * units.Avax,
DACProposalBondAmount: 100 * units.Avax,
},
},
}
Expand Down
7 changes: 7 additions & 0 deletions version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ var (
}
AthensPhaseDefaultTime = time.Date(2023, time.July, 1, 8, 0, 0, 0, time.UTC)

DACPhaseTimes = map[uint32]time.Time{
constants.KopernikusID: time.Date(2023, time.July, 4, 13, 0, 0, 0, time.UTC),
constants.ColumbusID: time.Date(2023, time.July, 7, 8, 0, 0, 0, time.UTC),
constants.CaminoID: time.Date(2023, time.July, 17, 8, 0, 0, 0, time.UTC),
}
DACPhaseDefaultTime = time.Date(2023, time.July, 1, 8, 0, 0, 0, time.UTC)

// TODO: update this before release
CortinaTimes = map[uint32]time.Time{
constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC),
Expand Down
44 changes: 44 additions & 0 deletions vms/platformvm/blocks/builder/camino_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ func caminoBuildBlock(
)
}

expiredProposalIDs, err := getExpiredProposals(parentState, timestamp)
if err != nil {
return nil, fmt.Errorf("could not find expired proposals: %w", err)
}
earlyFinishedProposalIDs, err := parentState.GetProposalIDsToFinish()
if err != nil {
return nil, fmt.Errorf("could not find successful proposals: %w", err)
}
if len(expiredProposalIDs) > 0 || len(earlyFinishedProposalIDs) > 0 {
finishProposalsTx, err := txBuilder.FinishProposalsTx(earlyFinishedProposalIDs, expiredProposalIDs)
if err != nil {
return nil, fmt.Errorf("could not build tx to finish proposals: %w", err)
}

return blocks.NewBanffStandardBlock(
timestamp,
parentID,
height,
[]*txs.Tx{finishProposalsTx},
)
}

return nil, nil
}

Expand Down Expand Up @@ -133,3 +155,25 @@ func getNextDepositsToUnlock(

return nextDeposits, nextDepositsEndtime.Equal(chainTime), nil
}

func getExpiredProposals(
preferredState state.Chain,
chainTime time.Time,
) ([]ids.ID, error) {
if !chainTime.Before(mockable.MaxTime) {
return nil, errEndOfTime
}

nextProposals, nextProposalsEndtime, err := preferredState.GetNextToExpireProposalIDsAndTime(nil)
if err == database.ErrNotFound {
return nil, nil
} else if err != nil {
return nil, err
}

if nextProposalsEndtime.Equal(chainTime) {
return nextProposals, nil
}

return nil, nil
}
3 changes: 2 additions & 1 deletion vms/platformvm/blocks/executor/proposal_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) {
onParentAccept.EXPECT().GetDeferredStakerIterator().Return(deferredStakersIt, nil).AnyTimes()

onParentAccept.EXPECT().GetNextToUnlockDepositTime(nil).Return(time.Time{}, database.ErrNotFound).AnyTimes()
onParentAccept.EXPECT().GetNextToUnlockDepositIDsAndTime(nil).Return(nil, time.Time{}, database.ErrNotFound).AnyTimes()
onParentAccept.EXPECT().GetNextProposalExpirationTime(nil).Return(time.Time{}, database.ErrNotFound).AnyTimes()
onParentAccept.EXPECT().GetProposalIDsToFinish().Return(nil, nil).AnyTimes()

env.mockedState.EXPECT().GetUptime(gomock.Any(), gomock.Any()).Return(
time.Duration(1000), /*upDuration*/
Expand Down
3 changes: 2 additions & 1 deletion vms/platformvm/blocks/executor/standard_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ func TestBanffStandardBlockTimeVerification(t *testing.T) {
onParentAccept.EXPECT().GetDeferredStakerIterator().Return(deferredStakersIt, nil).AnyTimes()

onParentAccept.EXPECT().GetNextToUnlockDepositTime(nil).Return(time.Time{}, database.ErrNotFound).AnyTimes()
onParentAccept.EXPECT().GetNextToUnlockDepositIDsAndTime(nil).Return(nil, time.Time{}, database.ErrNotFound).AnyTimes()
onParentAccept.EXPECT().GetNextProposalExpirationTime(nil).Return(time.Time{}, database.ErrNotFound).AnyTimes()
onParentAccept.EXPECT().GetProposalIDsToFinish().Return(nil, nil).AnyTimes()

onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes()

Expand Down
Loading

0 comments on commit 4c1b2c3

Please sign in to comment.