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

Enable DAO Proposal to execute Arbitray Tx #19

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b3b27d6
DaoProposal implementation
peak3d May 20, 2022
a1b1941
Archive proposals instead deleting them
peak3d May 21, 2022
e867eca
Use more fields to create DaoProposalID
peak3d May 21, 2022
038afcc
Burn fees from UTXO preceeding Stake UTXOs to reduce splitting
peak3d May 21, 2022
a396670
Add Dao Locked amount to GetStakeReply / Allow json encoding for UTXO…
peak3d May 21, 2022
1264033
Implement Dao Votes / Check for already Validator
peak3d May 22, 2022
d866c9f
Implement TimedTx interface / Add TX to metrics
peak3d May 23, 2022
edb6a27
Pass NodeID through Proposal bytes
peak3d May 23, 2022
f3c946e
Implement GetDaoProposal
peak3d May 24, 2022
adf89dd
Bump module version (0.3.0)
peak3d May 24, 2022
8a1728b
Code style / linter
peak3d May 24, 2022
59346ba
Keep only proposalId of accepted proposals in state
peak3d May 25, 2022
674881d
More Linter
peak3d May 28, 2022
ed6bcae
initial changes -> does not build
Aug 18, 2022
28452cf
in case i break my pc
Aug 19, 2022
dd13468
Update Dao Structure and State
Aug 25, 2022
8a5da28
Add Voteable Interface for proposable Tx
Aug 25, 2022
d8d6c19
Ignore VoteableTx when processing a incoming TX
Aug 25, 2022
ffb2a06
Add/Adjust new TX
Aug 25, 2022
9339a56
Cleanup AdvanceTime
Aug 25, 2022
4ed7e5f
Plumbing
Aug 25, 2022
831cd6b
Revert Personal changes to genesis
Aug 25, 2022
3ab82b1
typos and cleanup
Aug 25, 2022
0a84e25
add validation for the duration of a vote
Aug 25, 2022
6168c94
Linter Issues
Aug 25, 2022
80e270d
Ignore votes from validators who were not part of the set when the vo…
Aug 25, 2022
1f80e85
ignore not found errors in the concludeproposal for block builder
Aug 26, 2022
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ linters:
- goconst
- gocritic
- gofmt
- gofumpt
- goimports
- revive
- gosec
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v0.7.1
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
8 changes: 8 additions & 0 deletions genesis/genesis_camino.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/chain4travel/caminogo/utils/units"
"github.com/chain4travel/caminogo/vms/platformvm/dao"
"github.com/chain4travel/caminogo/vms/platformvm/reward"
)

Expand Down Expand Up @@ -75,6 +76,13 @@ var (
MintingPeriod: 365 * 24 * time.Hour,
SupplyCap: 1000 * units.MegaAvax,
},
DaoConfig: dao.Config{
ProposalTxFee: units.MilliAvax,
VoteTxFee: 0,
ProposalBondAmount: 1 * units.Avax,
MinProposalDuration: 1 * time.Minute,
MaxProposalDuration: 24 * 7 * 31 * time.Hour,
},
},
}
)
8 changes: 8 additions & 0 deletions genesis/genesis_columbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/chain4travel/caminogo/utils/units"
"github.com/chain4travel/caminogo/vms/platformvm/dao"
"github.com/chain4travel/caminogo/vms/platformvm/reward"
)

Expand Down Expand Up @@ -75,6 +76,13 @@ var (
MintingPeriod: 365 * 24 * time.Hour,
SupplyCap: 1000 * units.MegaAvax,
},
DaoConfig: dao.Config{
ProposalTxFee: units.MilliAvax,
VoteTxFee: 0,
ProposalBondAmount: 1 * units.Avax,
MinProposalDuration: 1 * time.Minute,
MaxProposalDuration: 24 * 7 * 31 * time.Hour,
},
},
}
)
8 changes: 8 additions & 0 deletions genesis/genesis_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/chain4travel/caminogo/utils/formatting"
"github.com/chain4travel/caminogo/utils/units"
"github.com/chain4travel/caminogo/utils/wrappers"
"github.com/chain4travel/caminogo/vms/platformvm/dao"
"github.com/chain4travel/caminogo/vms/platformvm/reward"
)

Expand Down Expand Up @@ -140,6 +141,13 @@ var (
MintingPeriod: 365 * 24 * time.Hour,
SupplyCap: 720 * units.MegaAvax,
},
DaoConfig: dao.Config{
ProposalTxFee: units.MilliAvax,
VoteTxFee: 0,
ProposalBondAmount: 1 * units.Avax,
MinProposalDuration: 1 * time.Minute,
MaxProposalDuration: 24 * 7 * 31 * time.Hour,
},
},
}
)
Expand Down
5 changes: 5 additions & 0 deletions genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/chain4travel/caminogo/utils/constants"
"github.com/chain4travel/caminogo/vms/platformvm/dao"
"github.com/chain4travel/caminogo/vms/platformvm/reward"
)

Expand All @@ -42,6 +43,8 @@ type StakingConfig struct {
MaxStakeDuration time.Duration `json:"maxStakeDuration"`
// RewardConfig is the config for the reward function.
RewardConfig reward.Config `json:"rewardConfig"`
// DaoConfig is the config for the dao function.
DaoConfig dao.Config `json:"daoConfig"`
}

type TxFeeConfig struct {
Expand All @@ -53,6 +56,8 @@ type TxFeeConfig struct {
CreateSubnetTxFee uint64 `json:"createSubnetTxFee"`
// Transaction fee for create blockchain transactions
CreateBlockchainTxFee uint64 `json:"createBlockchainTxFee"`
// Fee that must be burned by every create staker transaction
AddStakerTxFee uint64 `json:"addStakerTxFee"`
}

type Params struct {
Expand Down
1 change: 1 addition & 0 deletions ipcs/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func isTimeoutError(err error) bool {
return iErr.Timeout()
}

//nolint:nolintlint,deadcode,unused
// isSyscallError checks if an error is one of the given syscall.Errno codes
func isSyscallError(err error, codes ...syscall.Errno) bool {
opErr, ok := err.(*net.OpError)
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fi
TESTS=${TESTS:-"golangci_lint license_header"}

function test_golangci_lint {
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
golangci-lint run --config .golangci.yml
}

Expand Down
1 change: 1 addition & 0 deletions snow/networking/benchlist/benchlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestBenchlistAdd(t *testing.T) {
// Advance the time
b.lock.Lock()
now = now.Add(minimumFailingDuration)
b.clock.Set(now)
b.lock.Unlock()

// Register another failure
Expand Down
2 changes: 1 addition & 1 deletion version/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
var (
// GitCommit will be set with -X during build step
GitCommit string
ModuleVersion = NewDefaultVersion(0, 2, 0)
ModuleVersion = NewDefaultVersion(0, 3, 0)
ModuleVersionApp = NewDefaultApplication(
constants.PlatformName,
ModuleVersion.Major(),
Expand Down
20 changes: 10 additions & 10 deletions vms/platformvm/add_delegator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func (tx *UnsignedAddDelegatorTx) SemanticVerify(vm *VM, parentState MutableStat
startTime := tx.StartTime()
maxLocalStartTime := vm.clock.Time().Add(maxFutureStartTime)
if startTime.After(maxLocalStartTime) {
return errFutureStakeTime
return errFutureStartTime
}

_, _, err := tx.Execute(vm, parentState, stx)
// We ignore [errFutureStakeTime] here because an advanceTimeTx will be
// We ignore [errFutureStartTime] here because an advanceTimeTx will be
// issued before this transaction is issued.
if errors.Is(err, errFutureStakeTime) {
if errors.Is(err, errFutureStartTime) {
return nil
}
return err
Expand Down Expand Up @@ -190,7 +190,7 @@ func (tx *UnsignedAddDelegatorTx) Execute(
)
}

pendingValidator := pendingStakers.GetValidator(tx.Validator.NodeID)
pendingValidator, _ := pendingStakers.GetValidator(tx.Validator.NodeID)
pendingDelegators := pendingValidator.Delegators()

var (
Expand Down Expand Up @@ -265,15 +265,15 @@ func (tx *UnsignedAddDelegatorTx) Execute(
// Make sure the tx doesn't start too far in the future. This is done
// last to allow SemanticVerification to explicitly check for this
// error.
maxStartTime := currentTimestamp.Add(maxFutureStartTime)
maxStartTime := vm.clock.Time().Add(maxFutureStartTime)
if validatorStartTime.After(maxStartTime) {
return nil, nil, errFutureStakeTime
return nil, nil, errFutureStartTime
}
}

// Set up the state if this tx is committed
newlyPendingStakers := pendingStakers.AddStaker(stx)
onCommitState := newVersionedState(parentState, currentStakers, newlyPendingStakers)
onCommitState := newVersionedStateWithNewStakerChainState(vm, parentState, currentStakers, newlyPendingStakers)

// Consume the UTXOS
consumeInputs(onCommitState, tx.Ins)
Expand All @@ -282,7 +282,7 @@ func (tx *UnsignedAddDelegatorTx) Execute(
produceOutputs(onCommitState, txID, vm.ctx.AVAXAssetID, tx.Outs)

// Set up the state if this tx is aborted
onAbortState := newVersionedState(parentState, currentStakers, pendingStakers)
onAbortState := newVersionedStateWithNewStakerChainState(vm, parentState, currentStakers, pendingStakers)
// Consume the UTXOS
consumeInputs(onAbortState, tx.Ins)
// Produce the UTXOS
Expand Down Expand Up @@ -525,7 +525,7 @@ func (vm *VM) maxSubnetStakeAmount(
)

pendingStakers := vm.internalState.PendingStakerChainState()
pendingValidator := pendingStakers.GetValidator(nodeID)
pendingValidator, _ := pendingStakers.GetValidator(nodeID)

currentStakers := vm.internalState.CurrentStakerChainState()
currentValidator, err := currentStakers.GetValidator(nodeID)
Expand Down Expand Up @@ -561,7 +561,7 @@ func (vm *VM) maxPrimarySubnetStakeAmount(
currentStakers := vm.internalState.CurrentStakerChainState()
pendingStakers := vm.internalState.PendingStakerChainState()

pendingValidator := pendingStakers.GetValidator(nodeID)
pendingValidator, _ := pendingStakers.GetValidator(nodeID)
currentValidator, err := currentStakers.GetValidator(nodeID)

switch err {
Expand Down
14 changes: 7 additions & 7 deletions vms/platformvm/add_subnet_validator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ func (tx *UnsignedAddSubnetValidatorTx) SemanticVerify(vm *VM, parentState Mutab
startTime := tx.StartTime()
maxLocalStartTime := vm.clock.Time().Add(maxFutureStartTime)
if startTime.After(maxLocalStartTime) {
return errFutureStakeTime
return errFutureStartTime
}

_, _, err := tx.Execute(vm, parentState, stx)
// We ignore [errFutureStakeTime] here because an advanceTimeTx will be
// We ignore [errFutureStartTime] here because an advanceTimeTx will be
// issued before this transaction is issued.
if errors.Is(err, errFutureStakeTime) {
if errors.Is(err, errFutureStartTime) {
return nil
}
return err
Expand Down Expand Up @@ -184,7 +184,7 @@ func (tx *UnsignedAddSubnetValidatorTx) Execute(
}

// Ensure that this transaction isn't a duplicate add validator tx.
pendingValidator := pendingStakers.GetValidator(tx.Validator.NodeID)
pendingValidator, _ := pendingStakers.GetValidator(tx.Validator.NodeID)
subnets := pendingValidator.SubnetValidators()
if _, validates := subnets[tx.Validator.Subnet]; validates {
return nil, nil, fmt.Errorf(
Expand Down Expand Up @@ -231,13 +231,13 @@ func (tx *UnsignedAddSubnetValidatorTx) Execute(
// error.
maxStartTime := currentTimestamp.Add(maxFutureStartTime)
if validatorStartTime.After(maxStartTime) {
return nil, nil, errFutureStakeTime
return nil, nil, errFutureStartTime
}
}

// Set up the state if this tx is committed
newlyPendingStakers := pendingStakers.AddStaker(stx)
onCommitState := newVersionedState(parentState, currentStakers, newlyPendingStakers)
onCommitState := newVersionedStateWithNewStakerChainState(vm, parentState, currentStakers, newlyPendingStakers)

// Consume the UTXOS
consumeInputs(onCommitState, tx.Ins)
Expand All @@ -246,7 +246,7 @@ func (tx *UnsignedAddSubnetValidatorTx) Execute(
produceOutputs(onCommitState, txID, vm.ctx.AVAXAssetID, tx.Outs)

// Set up the state if this tx is aborted
onAbortState := newVersionedState(parentState, currentStakers, pendingStakers)
onAbortState := newVersionedStateWithNewStakerChainState(vm, parentState, currentStakers, pendingStakers)
// Consume the UTXOS
consumeInputs(onAbortState, tx.Ins)
// Produce the UTXOS
Expand Down
44 changes: 36 additions & 8 deletions vms/platformvm/add_validator_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/chain4travel/caminogo/utils/crypto"
"github.com/chain4travel/caminogo/vms/components/avax"
"github.com/chain4travel/caminogo/vms/components/verify"
"github.com/chain4travel/caminogo/vms/platformvm/dao"
"github.com/chain4travel/caminogo/vms/platformvm/reward"
"github.com/chain4travel/caminogo/vms/secp256k1fx"

Expand All @@ -39,11 +40,14 @@ var (
errStakeTooShort = errors.New("staking period is too short")
errStakeTooLong = errors.New("staking period is too long")
errInsufficientDelegationFee = errors.New("staker charges an insufficient delegation fee")
errFutureStakeTime = fmt.Errorf("staker is attempting to start staking more than %s ahead of the current chain time", maxFutureStartTime)
errTooManyShares = fmt.Errorf("a staker can only require at most %d shares from delegators", reward.PercentDenominator)

// TODO @Jax this should be in the dao config on the vm
validatorVotingDurration = time.Hour * 24 * 7 * 2 // Two weeks

_ UnsignedProposalTx = &UnsignedAddValidatorTx{}
_ TimedTx = &UnsignedAddValidatorTx{}
_ UnsingedVoteableTx = &UnsignedAddValidatorTx{}
)

// UnsignedAddValidatorTx is an unsigned addValidatorTx
Expand Down Expand Up @@ -135,13 +139,13 @@ func (tx *UnsignedAddValidatorTx) SemanticVerify(vm *VM, parentState MutableStat
startTime := tx.StartTime()
maxLocalStartTime := vm.clock.Time().Add(maxFutureStartTime)
if startTime.After(maxLocalStartTime) {
return errFutureStakeTime
return errFutureStartTime
}

_, _, err := tx.Execute(vm, parentState, stx)
// We ignore [errFutureStakeTime] here because an advanceTimeTx will be
// We ignore [errFutureStartTime] here because an advanceTimeTx will be
// issued before this transaction is issued.
if errors.Is(err, errFutureStakeTime) {
if errors.Is(err, errFutureStartTime) {
return nil
}
return err
Expand Down Expand Up @@ -238,15 +242,15 @@ func (tx *UnsignedAddValidatorTx) Execute(
// Make sure the tx doesn't start too far in the future. This is done
// last to allow SemanticVerification to explicitly check for this
// error.
maxStartTime := currentTimestamp.Add(maxFutureStartTime)
maxStartTime := vm.clock.Time().Add(maxFutureStartTime)
if startTime.After(maxStartTime) {
return nil, nil, errFutureStakeTime
return nil, nil, errFutureStartTime
}
}

// Set up the state if this tx is committed
newlyPendingStakers := pendingStakers.AddStaker(stx)
onCommitState := newVersionedState(parentState, currentStakers, newlyPendingStakers)
onCommitState := newVersionedStateWithNewStakerChainState(vm, parentState, currentStakers, newlyPendingStakers)

// Consume the UTXOS
consumeInputs(onCommitState, tx.Ins)
Expand All @@ -255,7 +259,7 @@ func (tx *UnsignedAddValidatorTx) Execute(
produceOutputs(onCommitState, txID, vm.ctx.AVAXAssetID, tx.Outs)

// Set up the state if this tx is aborted
onAbortState := newVersionedState(parentState, currentStakers, pendingStakers)
onAbortState := newVersionedStateWithNewStakerChainState(vm, parentState, currentStakers, pendingStakers)
// Consume the UTXOS
consumeInputs(onAbortState, tx.Ins)
// Produce the UTXOS
Expand All @@ -270,6 +274,30 @@ func (tx *UnsignedAddValidatorTx) InitiallyPrefersCommit(vm *VM) bool {
return tx.StartTime().After(vm.clock.Time())
}

func (tx *UnsignedAddValidatorTx) VerifyWithProposalContext(parentState MutableState, proposal dao.ProposalConfiguration) error {
if proposal.EndTime().Sub(proposal.StartTime()) != validatorVotingDurration {
return fmt.Errorf("voting time for a validator need exactly to be %d", validatorVotingDurration)
}

currentValidators := parentState.CurrentStakerChainState()
activeSet, err := currentValidators.ValidatorSet(constants.PrimaryNetworkID)
if err != nil {
return err
}

absoluteMajority := activeSet.Len()/2 + 1

if absoluteMajority >= int(proposal.Thresh) {
return fmt.Errorf("AddValidatorTx needs at least an absolute majority approval of currently %d votes", absoluteMajority)
}

return nil
}

func (tx *UnsignedAddValidatorTx) RequiresAcceptedProposal() bool {
return true
}

// NewAddValidatorTx returns a new NewAddValidatorTx
func (vm *VM) newAddValidatorTx(
stakeAmt, // Amount the validator stakes
Expand Down
Loading