From e2aebf5c529e84968498148d7ca5199ea5b1456a Mon Sep 17 00:00:00 2001 From: Warren He Date: Fri, 20 Dec 2019 16:40:59 -0800 Subject: [PATCH 1/2] go staking: undisable transfers for some senders --- .../tendermint/apps/staking/transactions.go | 16 ++++++++++++++-- go/staking/api/api.go | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/go/consensus/tendermint/apps/staking/transactions.go b/go/consensus/tendermint/apps/staking/transactions.go index ab57988e14d..e1d2462b822 100644 --- a/go/consensus/tendermint/apps/staking/transactions.go +++ b/go/consensus/tendermint/apps/staking/transactions.go @@ -2,6 +2,7 @@ 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" @@ -9,6 +10,17 @@ import ( 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 @@ -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) { diff --git a/go/staking/api/api.go b/go/staking/api/api.go index 2c65597d5bc..3d002a1d17c 100644 --- a/go/staking/api/api.go +++ b/go/staking/api/api.go @@ -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 ( From 65a3db6e6c13a4fdeb98cde41dc58efcc9929db1 Mon Sep 17 00:00:00 2001 From: Warren He Date: Mon, 23 Dec 2019 10:52:32 -0800 Subject: [PATCH 2/2] add changelog --- .changelog/2498.feature.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/2498.feature.md diff --git a/.changelog/2498.feature.md b/.changelog/2498.feature.md new file mode 100644 index 00000000000..78f378f0aef --- /dev/null +++ b/.changelog/2498.feature.md @@ -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`.