Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Oct 2, 2023
1 parent 18ea0ec commit 1be2354
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 99 deletions.
10 changes: 5 additions & 5 deletions version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ var (
}
AthensPhaseDefaultTime = time.Date(2023, time.July, 1, 8, 0, 0, 0, time.UTC)

DACPhaseTimes = map[uint32]time.Time{
BerlinPhaseTimes = 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)
BerlinPhaseDefaultTime = time.Date(2023, time.July, 1, 8, 0, 0, 0, time.UTC)

// TODO: update this before release
CortinaTimes = map[uint32]time.Time{
Expand Down Expand Up @@ -211,11 +211,11 @@ func GetAthensPhaseTime(networkID uint32) time.Time {
return AthensPhaseDefaultTime
}

func GetDACPhaseTime(networkID uint32) time.Time {
if upgradeTime, exists := DACPhaseTimes[networkID]; exists {
func GetBerlinPhaseTime(networkID uint32) time.Time {
if upgradeTime, exists := BerlinPhaseTimes[networkID]; exists {
return upgradeTime
}
return DACPhaseDefaultTime
return BerlinPhaseDefaultTime
}

func GetCortinaTime(networkID uint32) time.Time {
Expand Down
10 changes: 5 additions & 5 deletions vms/platformvm/camino_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ func apiOfferFromOffer(offer *deposit.Offer) *APIDepositOffer {

type GetUpgradePhasesReply struct {
AthensPhase utilsjson.Uint32 `json:"athensPhase"`
DACPhase utilsjson.Uint32 `json:"dacPhase"`
BerlinPhase utilsjson.Uint32 `json:"berlinPhase"`
}

func (s *CaminoService) GetUpgradePhases(_ *http.Request, _ *struct{}, response *GetUpgradePhasesReply) error {
Expand All @@ -1022,14 +1022,14 @@ func (s *CaminoService) GetUpgradePhases(_ *http.Request, _ *struct{}, response
if s.vm.Config.IsAthensPhaseActivated(s.vm.state.GetTimestamp()) {
response.AthensPhase = 1
}
if s.vm.Config.IsDACPhaseActivated(s.vm.state.GetTimestamp()) {
response.DACPhase = 1
if s.vm.Config.IsBerlinPhaseActivated(s.vm.state.GetTimestamp()) {
response.BerlinPhase = 1
}
return nil
}

type ConsortiumMemberValidator struct {
Weight utilsjson.Uint64 `json:"weight"`
ValidatorWeight utilsjson.Uint64 `json:"validatorWeight"`
ConsortiumMemberAddress string `json:"consortiumMemberAddress"`
}

Expand Down Expand Up @@ -1066,7 +1066,7 @@ func (s *CaminoService) GetValidatorsAt(r *http.Request, args *GetValidatorsAtAr
}

reply.Validators[vdr.NodeID] = ConsortiumMemberValidator{
Weight: utilsjson.Uint64(vdr.Weight),
ValidatorWeight: utilsjson.Uint64(vdr.Weight),
ConsortiumMemberAddress: addrStr,
}
}
Expand Down
8 changes: 4 additions & 4 deletions vms/platformvm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ type Config struct {
// Time of the Athens Phase network upgrade
AthensPhaseTime time.Time

// Time of the DACPhase network upgrade
DACPhaseTime time.Time
// Time of the BerlinPhase network upgrade
BerlinPhaseTime time.Time

// Subnet ID --> Minimum portion of the subnet's stake this node must be
// connected to in order to report healthy.
Expand Down Expand Up @@ -152,8 +152,8 @@ func (c *Config) IsAthensPhaseActivated(timestamp time.Time) bool {
return !timestamp.Before(c.AthensPhaseTime)
}

func (c *Config) IsDACPhaseActivated(timestamp time.Time) bool {
return !timestamp.Before(c.DACPhaseTime)
func (c *Config) IsBerlinPhaseActivated(timestamp time.Time) bool {
return !timestamp.Before(c.BerlinPhaseTime)
}

func (c *Config) GetCreateBlockchainTxFee(timestamp time.Time) uint64 {
Expand Down
24 changes: 14 additions & 10 deletions vms/platformvm/dac/camino_change_base_fee_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var (
)

type BaseFeeProposal struct {
Options []uint64 `serialize:"true"`
Start uint64 `serialize:"true"`
End uint64 `serialize:"true"`
Options []uint64 `serialize:"true"` // New base fee options
Start uint64 `serialize:"true"` // Start time of proposal
End uint64 `serialize:"true"` // End time of proposal
}

func (p *BaseFeeProposal) StartTime() time.Time {
Expand Down Expand Up @@ -74,12 +74,16 @@ func (p *BaseFeeProposal) Visit(visitor VerifierVisitor) error {
}

type BaseFeeProposalState struct {
SimpleVoteOptions[uint64] `serialize:"true"`

Start uint64 `serialize:"true"`
End uint64 `serialize:"true"`
AllowedVoters []ids.ShortID `serialize:"true"`
TotalAllowedVoters uint32 `serialize:"true"`
SimpleVoteOptions[uint64] `serialize:"true"` // New base fee options
// Start time of proposal
Start uint64 `serialize:"true"`
// End time of proposal
End uint64 `serialize:"true"`
// Addresses that are allowed to vote for this proposal
AllowedVoters []ids.ShortID `serialize:"true"`
// Number of addresses that were initially allowed to vote for this proposal.
// This is used to calculate thresholds like "half of total voters".
TotalAllowedVoters uint32 `serialize:"true"`
}

func (p *BaseFeeProposalState) StartTime() time.Time {
Expand Down Expand Up @@ -157,7 +161,7 @@ func (p *BaseFeeProposalState) AddVote(voterAddress ids.ShortID, voteIntf Vote)
}

// Will return modified proposal with added vote ignoring allowed voters, original proposal will not be modified!
func (p *BaseFeeProposalState) ForceAddVote(voterAddress ids.ShortID, voteIntf Vote) (ProposalState, error) { //nolint:revive
func (p *BaseFeeProposalState) ForceAddVote(voterAddress ids.ShortID, voteIntf Vote) (ProposalState, error) {
vote, ok := voteIntf.(*SimpleVote)
if !ok {
return nil, ErrWrongVote
Expand Down
12 changes: 6 additions & 6 deletions vms/platformvm/dac/camino_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type VoteWithAddr struct {
}

type SimpleVote struct {
OptionIndex uint32 `serialize:"true"`
OptionIndex uint32 `serialize:"true"` // Index of voted option
}

func (v *SimpleVote) VotedOptions() any {
Expand All @@ -41,15 +41,15 @@ func (*SimpleVote) Verify() error {
}

type SimpleVoteOption[T any] struct {
Value T `serialize:"true"`
Weight uint32 `serialize:"true"`
Value T `serialize:"true"` // Value that this option represents
Weight uint32 `serialize:"true"` // How much this option was voted
}

type SimpleVoteOptions[T comparable] struct {
Options []SimpleVoteOption[T] `serialize:"true"`
mostVotedWeight uint32
mostVotedOptionIndex uint32
unambiguous bool
mostVotedWeight uint32 // Weight of most voted option
mostVotedOptionIndex uint32 // Index of most voted option
unambiguous bool // True, if there is an option with weight > then other options weight
}

func (p *SimpleVoteOptions[T]) Verify() error {
Expand Down
2 changes: 2 additions & 0 deletions vms/platformvm/locked/camino_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (out *Out) Verify() error {
return out.TransferableOut.Verify()
}

// Used in vms/platformvm/txs/executor/camino_tx_executor.go func outputsAreEqual
func (out *Out) Equal(to any) bool {
toOut, typeAreEq := to.(*Out)
outEq, innerIsEq := out.TransferableOut.(interface{ Equal(any) bool })
Expand All @@ -185,6 +186,7 @@ func (in *In) Verify() error {
return in.TransferableIn.Verify()
}

// Used in vms/platformvm/txs/executor/camino_tx_executor.go func inputsAreEqual
func (in *In) Equal(to any) bool {
toIn, typeAreEq := to.(*In)
inEq, innerIsEq := in.TransferableIn.(interface{ Equal(any) bool })
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/txs/camino_address_state_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ const (
AddressStateCaminoProposer AddressState = AddressState(1) << AddressStateBitCaminoProposer // 0b1000000000000000000000000000000000000000000000000000

AddressStateAthensPhaseBits = AddressStateRoleOffersAdmin | AddressStateOffersCreator
AddressStateDACPhaseBits = AddressStateCaminoProposer
AddressStateBerlinPhaseBits = AddressStateCaminoProposer

AddressStateValidBits = AddressStateRoleAll | AddressStateKYCAll | AddressStateVotableBits |
AddressStateAthensPhaseBits |
AddressStateDACPhaseBits // 0b1100000000001100001100000000000000000000000000000111
AddressStateBerlinPhaseBits // 0b1100000000001100001100000000000000000000000000000111
)

func (as AddressState) Is(state AddressState) bool {
Expand Down
14 changes: 7 additions & 7 deletions vms/platformvm/txs/executor/camino_tx_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var (
errBurnedDepositUnlock = errors.New("burned undeposited tokens")
errAdminCannotBeDeleted = errors.New("admin cannot be deleted")
errNotAthensPhase = errors.New("not allowed before AthensPhase")
errNotDACPhase = errors.New("not allowed before DACPhase")
errNotBerlinPhase = errors.New("not allowed before BerlinPhase")
errOfferCreatorCredentialMismatch = errors.New("offer creator credential isn't matching")
errNotOfferCreator = errors.New("address isn't allowed to create deposit offers")
errDepositCreatorCredentialMismatch = errors.New("deposit creator credential isn't matching")
Expand Down Expand Up @@ -1698,8 +1698,8 @@ func (e *CaminoStandardTxExecutor) AddProposalTx(tx *txs.AddProposalTx) error {

chainTime := e.State.GetTimestamp()

if !e.Config.IsDACPhaseActivated(chainTime) {
return errNotDACPhase
if !e.Config.IsBerlinPhaseActivated(chainTime) {
return errNotBerlinPhase
}

txProposal, err := tx.Proposal()
Expand Down Expand Up @@ -1814,8 +1814,8 @@ func (e *CaminoStandardTxExecutor) AddVoteTx(tx *txs.AddVoteTx) error {

chainTime := e.State.GetTimestamp()

if !e.Config.IsDACPhaseActivated(chainTime) {
return errNotDACPhase
if !e.Config.IsBerlinPhaseActivated(chainTime) {
return errNotBerlinPhase
}

// verify vote with proposal
Expand Down Expand Up @@ -1934,8 +1934,8 @@ func (e *CaminoStandardTxExecutor) FinishProposalsTx(tx *txs.FinishProposalsTx)
switch {
case len(e.Tx.Creds) != 0:
return errWrongCredentialsNumber
case !e.Config.IsDACPhaseActivated(chainTime):
return errNotDACPhase
case !e.Config.IsBerlinPhaseActivated(chainTime):
return errNotBerlinPhase
case !isExpirationTime &&
len(tx.ExpiredSuccessfulProposalIDs)+len(tx.ExpiredFailedProposalIDs) != 0:
return errProposalsAreNotExpiredYet
Expand Down
Loading

0 comments on commit 1be2354

Please sign in to comment.