Skip to content

Commit

Permalink
go/oasis-node/cmd/stake: Use stake.shares flag in gen_reclaim_escrow tx
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanez committed Feb 27, 2020
1 parent cc3f2ff commit 79d178f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changelog/2690.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Use `--stake.shares` flag when specifying shares to reclaim from an escrow

Previously, the `oasis-node stake account gen_reclaim_escrow` subcommand
erroneously used the `--stake.amount` flag for specifying the amount of shares
to reclaim from an escrow.
26 changes: 17 additions & 9 deletions go/oasis-node/cmd/stake/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
// CfgAmount configures the amount of tokens.
CfgAmount = "stake.amount"

// CfgShares configures the amount of shares.
CfgShares = "stake.shares"

// CfgTransferDestination configures the transfer destination address.
CfgTransferDestination = "stake.transfer.destination"

Expand All @@ -43,7 +46,8 @@ const (
var (
accountInfoFlags = flag.NewFlagSet("", flag.ContinueOnError)
amountFlags = flag.NewFlagSet("", flag.ContinueOnError)
escrowFlags = flag.NewFlagSet("", flag.ContinueOnError)
sharesFlags = flag.NewFlagSet("", flag.ContinueOnError)
commonEscrowFlags = flag.NewFlagSet("", flag.ContinueOnError)
commissionScheduleFlags = flag.NewFlagSet("", flag.ContinueOnError)
accountTransferFlags = flag.NewFlagSet("", flag.ContinueOnError)

Expand Down Expand Up @@ -204,8 +208,8 @@ func doAccountReclaimEscrow(cmd *cobra.Command, args []string) {
)
os.Exit(1)
}
if err := reclaim.Shares.UnmarshalText([]byte(viper.GetString(CfgAmount))); err != nil {
logger.Error("failed to parse escrow reclaim amount",
if err := reclaim.Shares.UnmarshalText([]byte(viper.GetString(CfgShares))); err != nil {
logger.Error("failed to parse escrow reclaim shares",
"err", err,
)
os.Exit(1)
Expand Down Expand Up @@ -311,8 +315,10 @@ func registerAccountCmd() {
accountTransferCmd.Flags().AddFlagSet(accountTransferFlags)
accountBurnCmd.Flags().AddFlagSet(cmdConsensus.TxFlags)
accountBurnCmd.Flags().AddFlagSet(amountFlags)
accountEscrowCmd.Flags().AddFlagSet(escrowFlags)
accountReclaimEscrowCmd.Flags().AddFlagSet(escrowFlags)
accountEscrowCmd.Flags().AddFlagSet(commonEscrowFlags)
accountEscrowCmd.Flags().AddFlagSet(amountFlags)
accountReclaimEscrowCmd.Flags().AddFlagSet(commonEscrowFlags)
accountReclaimEscrowCmd.Flags().AddFlagSet(sharesFlags)
accountAmendCommissionScheduleCmd.Flags().AddFlagSet(commissionScheduleFlags)
}

Expand All @@ -325,15 +331,17 @@ func init() {
amountFlags.String(CfgAmount, "0", "amount of tokens for the transaction")
_ = viper.BindPFlags(amountFlags)

sharesFlags.String(CfgShares, "0", "amount of shares for the transaction")
_ = viper.BindPFlags(sharesFlags)

accountTransferFlags.String(CfgTransferDestination, "", "transfer destination account ID")
_ = viper.BindPFlags(accountTransferFlags)
accountTransferFlags.AddFlagSet(cmdConsensus.TxFlags)
accountTransferFlags.AddFlagSet(amountFlags)

escrowFlags.String(CfgEscrowAccount, "", "ID of the escrow account")
_ = viper.BindPFlags(escrowFlags)
escrowFlags.AddFlagSet(cmdConsensus.TxFlags)
escrowFlags.AddFlagSet(amountFlags)
commonEscrowFlags.String(CfgEscrowAccount, "", "ID of the escrow account")
_ = viper.BindPFlags(commonEscrowFlags)
commonEscrowFlags.AddFlagSet(cmdConsensus.TxFlags)

commissionScheduleFlags.StringSlice(CfgCommissionScheduleRates, nil, fmt.Sprintf(
"commission rate step. Multiple of this flag is allowed. "+
Expand Down
4 changes: 2 additions & 2 deletions go/oasis-test-runner/scenario/e2e/gas_fees_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ func (sc *gasFeesImpl) testAddEscrow(ctx context.Context, signer signature.Signe
}

func (sc *gasFeesImpl) testReclaimEscrow(ctx context.Context, signer signature.Signer) (*quantity.Quantity, error) {
return sc.testStakingGas(ctx, signer, false, func(acct *staking.Account, fee transaction.Fee, amount int64) error {
return sc.testStakingGas(ctx, signer, false, func(acct *staking.Account, fee transaction.Fee, shares int64) error {
escrow := staking.ReclaimEscrow{
Account: escrowSigner.Public(),
}
_ = escrow.Shares.FromInt64(amount)
_ = escrow.Shares.FromInt64(shares)

tx := staking.NewReclaimEscrowTx(acct.General.Nonce, &fee, &escrow)
sigTx, err := transaction.Sign(signer, tx)
Expand Down
24 changes: 15 additions & 9 deletions go/oasis-test-runner/scenario/e2e/stake_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const (
// Test escrow amount.
escrowAmount = 3000

// Test reclaim escrow shares.
reclaimEscrowShares = 1234

// Transaction fee amount.
feeAmount = 10

Expand Down Expand Up @@ -167,7 +170,7 @@ func (s *stakeCLIImpl) Run(childEnv *env.Env) error {
return nil
}

// testTransfer tests transfer of 1000 tokens from src to dst.
// testTransfer tests transfer of transferAmount tokens from src to dst.
func (s *stakeCLIImpl) testTransfer(childEnv *env.Env, cli *cli.Helpers, src signature.PublicKey, dst signature.PublicKey) error {
transferTxPath := filepath.Join(childEnv.Dir(), "stake_transfer.json")
if err := s.genTransferTx(childEnv, transferAmount, 0, dst, transferTxPath); err != nil {
Expand Down Expand Up @@ -204,7 +207,7 @@ func (s *stakeCLIImpl) testTransfer(childEnv *env.Env, cli *cli.Helpers, src sig
return nil
}

// testBurn tests burning of 2000 tokens owned by src.
// testBurn tests burning of burnAmount tokens owned by src.
func (s *stakeCLIImpl) testBurn(childEnv *env.Env, cli *cli.Helpers, src signature.PublicKey) error {
burnTxPath := filepath.Join(childEnv.Dir(), "stake_burn.json")
if err := s.genBurnTx(childEnv, burnAmount, 1, burnTxPath); err != nil {
Expand Down Expand Up @@ -232,7 +235,7 @@ func (s *stakeCLIImpl) testBurn(childEnv *env.Env, cli *cli.Helpers, src signatu
return nil
}

// testEscrow tests escrowing of 3000 tokens from src to dst.
// testEscrow tests escrowing escrowAmount tokens from src to dst.
func (s *stakeCLIImpl) testEscrow(childEnv *env.Env, cli *cli.Helpers, src signature.PublicKey, escrow signature.PublicKey) error {
escrowTxPath := filepath.Join(childEnv.Dir(), "stake_escrow.json")
if err := s.genEscrowTx(childEnv, escrowAmount, 2, escrow, escrowTxPath); err != nil {
Expand Down Expand Up @@ -263,10 +266,10 @@ func (s *stakeCLIImpl) testEscrow(childEnv *env.Env, cli *cli.Helpers, src signa
return nil
}

// testReclaimEscrow test reclaiming an escrow of 3000 tokens from escrow account.
// testReclaimEscrow test reclaiming reclaimEscrowShares shares from an escrow account.
func (s *stakeCLIImpl) testReclaimEscrow(childEnv *env.Env, cli *cli.Helpers, src signature.PublicKey, escrow signature.PublicKey) error {
reclaimEscrowTxPath := filepath.Join(childEnv.Dir(), "stake_reclaim_escrow.json")
if err := s.genReclaimEscrowTx(childEnv, escrowAmount, 3, escrow, reclaimEscrowTxPath); err != nil {
if err := s.genReclaimEscrowTx(childEnv, reclaimEscrowShares, 3, escrow, reclaimEscrowTxPath); err != nil {
return err
}
if err := s.showTx(childEnv, reclaimEscrowTxPath); err != nil {
Expand All @@ -282,10 +285,13 @@ func (s *stakeCLIImpl) testReclaimEscrow(childEnv *env.Env, cli *cli.Helpers, sr
return fmt.Errorf("failed to set epoch: %w", err)
}

if err := s.checkBalance(childEnv, src, initBalance-transferAmount-burnAmount-4*feeAmount); err != nil {
// Since we are the only ones who put tokens into the escrow account and there was no slashing,
// we can expect the reclaimed escrow amount to equal the number of reclaimed escrow shares.
var reclaimEscrowAmount int64 = reclaimEscrowShares
if err := s.checkBalance(childEnv, src, initBalance-transferAmount-burnAmount-escrowAmount+reclaimEscrowAmount-4*feeAmount); err != nil {
return err
}
if err := s.checkEscrowBalance(childEnv, escrow, 0); err != nil {
if err := s.checkEscrowBalance(childEnv, escrow, escrowAmount-reclaimEscrowAmount); err != nil {
return err
}
accounts, err := s.listAccounts(childEnv)
Expand Down Expand Up @@ -517,12 +523,12 @@ func (s *stakeCLIImpl) genEscrowTx(childEnv *env.Env, amount int, nonce int, esc
return nil
}

func (s *stakeCLIImpl) genReclaimEscrowTx(childEnv *env.Env, amount int, nonce int, escrow signature.PublicKey, txPath string) error {
func (s *stakeCLIImpl) genReclaimEscrowTx(childEnv *env.Env, shares int, nonce int, escrow signature.PublicKey, txPath string) error {
s.logger.Info("generating stake reclaim escrow tx", stake.CfgEscrowAccount, escrow)

args := []string{
"stake", "account", "gen_reclaim_escrow",
"--" + stake.CfgAmount, strconv.Itoa(amount),
"--" + stake.CfgShares, strconv.Itoa(shares),
"--" + consensus.CfgTxNonce, strconv.Itoa(nonce),
"--" + consensus.CfgTxFile, txPath,
"--" + stake.CfgEscrowAccount, escrow.String(),
Expand Down

0 comments on commit 79d178f

Please sign in to comment.