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

[PVM, DAC] Admin proposals #282

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions genesis/camino_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/vms/avm"
"github.com/ava-labs/avalanchego/vms/components/multisig"
"github.com/ava-labs/avalanchego/vms/nftfx"
as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate"
knikos marked this conversation as resolved.
Show resolved Hide resolved
"github.com/ava-labs/avalanchego/vms/platformvm/api"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
"github.com/ava-labs/avalanchego/vms/platformvm/deposit"
Expand Down Expand Up @@ -364,12 +365,12 @@ func buildPGenesis(config *Config, hrp string, xGenesisBytes []byte, xGenesisDat
// Getting args from allocations

for _, allocation := range config.Camino.Allocations {
var addrState pchaintxs.AddressState
var addrState as.AddressState
if allocation.AddressStates.ConsortiumMember {
addrState |= pchaintxs.AddressStateConsortiumMember
addrState |= as.AddressStateConsortiumMember
}
if allocation.AddressStates.KYCVerified {
addrState |= pchaintxs.AddressStateKYCVerified
addrState |= as.AddressStateKYCVerified
}
if addrState != 0 {
platformvmArgs.Camino.AddressStates = append(platformvmArgs.Camino.AddressStates, genesis.AddressState{
Expand Down
63 changes: 63 additions & 0 deletions vms/platformvm/addrstate/address_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package addrstate

type (
AddressState uint64
AddressStateBit uint8
)

// AddressState flags, max 63
const (
// Bits

AddressStateBitRoleAdmin AddressStateBit = 0 // super role

AddressStateBitRoleKYC AddressStateBit = 1 // allows to set KYCVerified and KYCExpired
AddressStateBitRoleOffersAdmin AddressStateBit = 2 // allows to set OffersCreator
AddressStateBitRoleConsortiumAdminProposer AddressStateBit = 3 // allows to create admin add/exclude member proposals

AddressStateBitKYCVerified AddressStateBit = 32
AddressStateBitKYCExpired AddressStateBit = 33
AddressStateBitConsortium AddressStateBit = 38
AddressStateBitNodeDeferred AddressStateBit = 39
AddressStateBitOffersCreator AddressStateBit = 50
AddressStateBitCaminoProposer AddressStateBit = 51

AddressStateBitMax AddressStateBit = 63

// States

AddressStateEmpty AddressState = 0

AddressStateRoleAdmin AddressState = AddressState(1) << AddressStateBitRoleAdmin // 0b1
AddressStateRoleKYC AddressState = AddressState(1) << AddressStateBitRoleKYC // 0b10
AddressStateRoleOffersAdmin AddressState = AddressState(1) << AddressStateBitRoleOffersAdmin // 0b100
AddressStateRoleConsortiumAdminProposer AddressState = AddressState(1) << AddressStateBitRoleConsortiumAdminProposer // 0b1000
AddressStateRoleAll AddressState = AddressStateRoleAdmin | AddressStateRoleKYC | // 0b1111
AddressStateRoleOffersAdmin | AddressStateRoleConsortiumAdminProposer

AddressStateKYCVerified AddressState = AddressState(1) << AddressStateBitKYCVerified // 0b0100000000000000000000000000000000
AddressStateKYCExpired AddressState = AddressState(1) << AddressStateBitKYCExpired // 0b1000000000000000000000000000000000
AddressStateKYCAll AddressState = AddressStateKYCVerified | AddressStateKYCExpired // 0b1100000000000000000000000000000000

AddressStateConsortiumMember AddressState = AddressState(1) << AddressStateBitConsortium // 0b0100000000000000000000000000000000000000
AddressStateNodeDeferred AddressState = AddressState(1) << AddressStateBitNodeDeferred // 0b1000000000000000000000000000000000000000
AddressStateVotableBits AddressState = AddressStateConsortiumMember | AddressStateNodeDeferred // 0b1100000000000000000000000000000000000000

AddressStateOffersCreator AddressState = AddressState(1) << AddressStateBitOffersCreator // 0b00100000000000000000000000000000000000000000000000000
AddressStateCaminoProposer AddressState = AddressState(1) << AddressStateBitCaminoProposer // 0b01000000000000000000000000000000000000000000000000000

AddressStateAthensPhaseBits = AddressStateRoleOffersAdmin | AddressStateOffersCreator
AddressStateBerlinPhaseBits = AddressStateCaminoProposer | AddressStateRoleOffersAdmin

AddressStateValidBits = AddressStateRoleAll | AddressStateKYCAll | AddressStateVotableBits |
AddressStateAthensPhaseBits |
AddressStateBerlinPhaseBits // 0b1100000000001100001100000000000000000000000000001111
)

func (as AddressState) Is(state AddressState) bool {
return as&state == state
}

func (as AddressState) IsNot(state AddressState) bool {
return as&state != state
}
4 changes: 2 additions & 2 deletions vms/platformvm/camino_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/version"
as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate"
knikos marked this conversation as resolved.
Show resolved Hide resolved
"github.com/ava-labs/avalanchego/vms/platformvm/api"
"github.com/ava-labs/avalanchego/vms/platformvm/caminoconfig"
"github.com/ava-labs/avalanchego/vms/platformvm/config"
"github.com/ava-labs/avalanchego/vms/platformvm/genesis"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -189,7 +189,7 @@ func newCaminoGenesisWithUTXOs(caminoGenesisConfig api.Camino, genesisUTXOs []ap
caminoGenesisConfig.ValidatorConsortiumMembers[i] = key.Address()
caminoGenesisConfig.AddressStates = append(caminoGenesisConfig.AddressStates, genesis.AddressState{
Address: key.Address(),
State: txs.AddressStateConsortiumMember,
State: as.AddressStateConsortiumMember,
})
}

Expand Down
9 changes: 5 additions & 4 deletions vms/platformvm/camino_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/keystore"
as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate"
knikos marked this conversation as resolved.
Show resolved Hide resolved
"github.com/ava-labs/avalanchego/vms/platformvm/deposit"
"github.com/ava-labs/avalanchego/vms/platformvm/locked"
"github.com/ava-labs/avalanchego/vms/platformvm/state"
Expand Down Expand Up @@ -251,10 +252,10 @@ type SetAddressStateArgs struct {
api.UserPass
api.JSONFromAddrs

Change platformapi.Owner `json:"change"`
Address string `json:"address"`
State txs.AddressStateBit `json:"state"`
Remove bool `json:"remove"`
Change platformapi.Owner `json:"change"`
Address string `json:"address"`
State as.AddressStateBit `json:"state"`
Remove bool `json:"remove"`
}

// AddAdressState issues an AddAdressStateTx
Expand Down
Loading
Loading