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

go staking: undisable transfers for some senders #2498

Merged
merged 2 commits into from
Dec 23, 2019
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: 7 additions & 0 deletions .changelog/2498.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Undisable transfers for some senders.

Ostensibly for faucet purposes while we run the rest of the network with transfers disabled,
this lets us identify a whitelist of accounts from which we allow transfers when otherwise transfers are disabled.

Configure this with a map of allowed senders' public keys -> `true` in the new `undisable_transfers_from` field in the
staking consensus parameters object along with `"disable_transfers": true`.
16 changes: 14 additions & 2 deletions go/consensus/tendermint/apps/staking/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ package staking

import (
"github.com/oasislabs/oasis-core/go/common/cbor"
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
"github.com/oasislabs/oasis-core/go/common/quantity"
"github.com/oasislabs/oasis-core/go/consensus/tendermint/abci"
"github.com/oasislabs/oasis-core/go/consensus/tendermint/api"
stakingState "github.com/oasislabs/oasis-core/go/consensus/tendermint/apps/staking/state"
staking "github.com/oasislabs/oasis-core/go/staking/api"
)

func isTransferPermitted(params *staking.ConsensusParameters, fromID signature.PublicKey) (permitted bool) {
permitted = true
if params.DisableTransfers {
permitted = false
if params.UndisableTransfersFrom != nil && params.UndisableTransfersFrom[fromID] {
permitted = true
}
}
return
}

func (app *stakingApplication) transfer(ctx *abci.Context, state *stakingState.MutableState, xfer *staking.Transfer) error {
if ctx.IsCheckOnly() {
return nil
Expand All @@ -23,11 +35,11 @@ func (app *stakingApplication) transfer(ctx *abci.Context, state *stakingState.M
return err
}

if params.DisableTransfers {
fromID := ctx.TxSigner()
if !isTransferPermitted(params, fromID) {
return staking.ErrForbidden
}

fromID := ctx.TxSigner()
from := state.Account(fromID)

if fromID.Equal(xfer.To) {
Expand Down
5 changes: 3 additions & 2 deletions go/staking/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ type ConsensusParameters struct {
GasCosts transaction.Costs `json:"gas_costs,omitempty"`
MinDelegationAmount quantity.Quantity `json:"min_delegation,omitempty"`

DisableTransfers bool `json:"disable_transfers,omitempty"`
DisableDelegation bool `json:"disable_delegation,omitempty"`
DisableTransfers bool `json:"disable_transfers,omitempty"`
DisableDelegation bool `json:"disable_delegation,omitempty"`
UndisableTransfersFrom map[signature.PublicKey]bool `json:"undisable_transfers_from,omitempty"`
}

const (
Expand Down