Skip to content

Commit

Permalink
Merge pull request #2498 from oasislabs/pro-wh/feature/xferwl
Browse files Browse the repository at this point in the history
go staking: undisable transfers for some senders
  • Loading branch information
pro-wh authored Dec 23, 2019
2 parents 329e023 + 65a3db6 commit c878579
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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

0 comments on commit c878579

Please sign in to comment.