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

[Code Health] refactor: rename ApplicationTransfer msgs #788

Merged
merged 49 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c9945ad
ignite scaffold message transfer-application-stake address:string ben…
bryanchriswhite Aug 17, 2024
69ee2cb
feat: implement application stake transfer
bryanchriswhite Aug 22, 2024
ce6428e
resolve: merge conflicts
bryanchriswhite Aug 22, 2024
fc60584
chore: revert whitespace changes
bryanchriswhite Aug 16, 2024
49b7592
chore: add address string protobuf options
bryanchriswhite Aug 16, 2024
8046491
test: improve unit tests
bryanchriswhite Aug 16, 2024
c23ca86
chore: add telemetry
bryanchriswhite Aug 16, 2024
ca95a92
fix: MsgTransferApplicationStake#ValidateBasic()
bryanchriswhite Aug 17, 2024
8ac6935
chore: linting
bryanchriswhite Aug 19, 2024
27bb042
test: add makefile target for e2e app transfer
bryanchriswhite Aug 21, 2024
43c7f85
chore: update/lint app transfer autocli
bryanchriswhite Aug 21, 2024
7fd1bee
test: E2E app stake transfer
bryanchriswhite Aug 21, 2024
fa6a63b
chore: remove TODO
bryanchriswhite Aug 22, 2024
1656787
fix: e2e build constraint
bryanchriswhite Aug 22, 2024
0d99a89
chore: linting
bryanchriswhite Aug 22, 2024
56d7f11
chore: review feedback improvements
bryanchriswhite Aug 27, 2024
cb44753
rename: app_stake_transfer to stake_app_transfer
bryanchriswhite Aug 27, 2024
76da405
chore: update test_e2e_app_transfer make target
bryanchriswhite Aug 27, 2024
e9dee27
chore: review feedback improvements
bryanchriswhite Aug 27, 2024
7fe7a0e
Merge remote-tracking branch 'pokt/main' into issues/657/feat/app-sta…
bryanchriswhite Aug 27, 2024
e84f003
chore: post-merge improvements
bryanchriswhite Aug 27, 2024
ea967be
fix: error duplicate code
bryanchriswhite Aug 27, 2024
5de7ddf
fix: #ValidateBasic
bryanchriswhite Aug 27, 2024
451ef64
fix: keeper test
bryanchriswhite Aug 27, 2024
2f43521
Merge branch 'main' into issues/657/feat/app-stake-transfer
Olshansk Aug 28, 2024
1cd9402
refactor: rename TransferApplicationStake to TransferApplication
bryanchriswhite Sep 4, 2024
9107be4
refactor: rename param to application_transfer_and_unboding_period_se…
bryanchriswhite Sep 4, 2024
612087c
chore: regenerate protobufs
bryanchriswhite Sep 4, 2024
ba079e3
Revert "refactor: rename param to application_transfer_and_unboding_p…
bryanchriswhite Sep 5, 2024
366388a
chore: regenerate protobufs
bryanchriswhite Sep 5, 2024
1108394
fix: failing test
bryanchriswhite Sep 5, 2024
48bc132
Merge remote-tracking branch 'pokt/main' into issues/657/feat/app-sta…
bryanchriswhite Sep 5, 2024
dc0e62c
chore: regenerate protobufs
bryanchriswhite Sep 5, 2024
204097f
Merge branch 'issues/657/feat/app-stake-transfer' into issues/657/ref…
bryanchriswhite Sep 5, 2024
4a80fa4
chore: regenerate protobufs
bryanchriswhite Sep 5, 2024
cab0b9d
chore: review feedback improvements
bryanchriswhite Sep 6, 2024
ca1da15
Merge branch 'main' into issues/657/feat/app-stake-transfer
bryanchriswhite Sep 6, 2024
c4155f0
Merge branch 'issues/657/feat/app-stake-transfer' into issues/657/ref…
bryanchriswhite Sep 6, 2024
4814ffc
Merge remote-tracking branch 'pokt/main' into issues/657/feat/app-sta…
bryanchriswhite Sep 16, 2024
75c5927
Merge branch 'issues/657/feat/app-stake-transfer' into issues/657/ref…
bryanchriswhite Sep 16, 2024
dcac5d7
Merge remote-tracking branch 'pokt/main' into issues/657/feat/app-sta…
bryanchriswhite Sep 19, 2024
5551d90
Merge branch 'issues/657/feat/app-stake-transfer' into issues/657/ref…
bryanchriswhite Sep 19, 2024
709569c
fix: linter errors
bryanchriswhite Sep 20, 2024
099d880
chore: cleanup comments
bryanchriswhite Sep 20, 2024
9416419
chore: review feedback improvements
bryanchriswhite Sep 20, 2024
3423d7f
Merge branch 'issues/657/feat/app-stake-transfer' into issues/657/ref…
bryanchriswhite Sep 20, 2024
e143167
Empty commit
bryanchriswhite Sep 20, 2024
cd62416
Merge branch 'issues/657/feat/app-stake-transfer' into issues/657/ref…
bryanchriswhite Sep 23, 2024
c610cf3
Merge remote-tracking branch 'pokt/main' into issues/657/refactor/tra…
bryanchriswhite Sep 23, 2024
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,298 changes: 1,177 additions & 121 deletions api/poktroll/application/tx.pulsar.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions api/poktroll/application/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions e2e/tests/stake_app_transfer.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: App Stake Transfer Namespace

Scenario: User can transfer Application stake to non-existing application address
Given the user has the pocketd binary installed
# Unstake the applications in case they're already staked.
And this test ensures the "application" for account "app2" is not staked
And this test ensures the "application" for account "app3" is not staked
# Stake with 1 uPOKT more than the current stake used in genesis to make
# the transaction succeed.
And the account "app2" has a balance greater than "1000070" uPOKT
And an account exists for "app3"
And the user successfully stakes a "application" with "1000070" uPOKT for "anvil" service from the account "app2"
When the user transfers the "application" stake from account "app2" to account "app3"
Then the user should be able to see standard output containing "txhash:"
And the user should be able to see standard output containing "code: 0"
And the pocketd binary should exit without error
And the user should wait for the "application" module "TransferApplication" message to be submitted
And the "application" for account "app3" is staked with "1000070" uPOKT
And the account balance of "app3" should be "0" uPOKT "less" than before
And the user verifies the "application" for account "app2" is not staked
And the account balance of "app2" should be "0" uPOKT "more" than before
51 changes: 51 additions & 0 deletions e2e/tests/stake_app_transfer_steps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//go:build e2e

package e2e

import (
"github.com/stretchr/testify/require"
)

func (s *suite) TheUserSuccessfullyStakesAWithUpoktForServiceFromTheAccount(actorType string, amount int64, serviceId, accName string) {
s.TheUserStakesAWithUpoktForServiceFromTheAccount(actorType, amount, serviceId, accName)
s.TheUserShouldBeAbleToSeeStandardOutputContaining("txhash:")
s.TheUserShouldBeAbleToSeeStandardOutputContaining("code: 0")
s.ThePocketdBinaryShouldExitWithoutError()
s.TheUserShouldWaitForTheModuleMessageToBeSubmitted("application", "StakeApplication")
s.TheForAccountIsStakedWithUpokt(actorType, accName, amount)
s.TheAccountBalanceOfShouldBeUpoktThanBefore(accName, amount, "less")
}

func (s *suite) TheUserTransfersTheStakeFromAccountToAccount(actorType, fromAccName, toAccName string) {
fromAddr, fromAddrIsFound := accNameToAddrMap[fromAccName]
require.Truef(s, fromAddrIsFound, "account name %s not found in accNameToAddrMap", fromAccName)

toAddr, toAddrIsFound := accNameToAddrMap[toAccName]
require.Truef(s, toAddrIsFound, "account name %s not found in accNameToAddrMap", toAccName)

args := []string{
"tx",
actorType,
"transfer",
fromAddr,
toAddr,
"--from",
fromAccName,
keyRingFlag,
chainIdFlag,
"-y",
}
res, err := s.pocketd.RunCommandOnHost("", args...)
require.NoError(s, err)

s.pocketd.result = res
}

// This helper ensures that the actor is unstaked if it was staked when this step ran.
func (s *suite) ThisTestEnsuresTheForAccountIsNotStaked(actorType, accName string) {
if _, ok := s.getStakedAmount(actorType, accName); ok {
s.TheUserUnstakesAFromTheAccount(actorType, accName)
s.TheUserShouldBeAbleToSeeStandardOutputContaining("txhash:")
s.TheUserShouldBeAbleToSeeStandardOutputContaining("code: 0")
}
}
36 changes: 24 additions & 12 deletions proto/poktroll/application/tx.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package poktroll.application;

option go_package = "github.com/pokt-network/poktroll/x/application/types";
Expand All @@ -9,27 +10,27 @@ import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";

import "poktroll/application/types.proto";
import "poktroll/application/params.proto";
import "poktroll/shared/service.proto";


// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a (governance) operation for updating the module
// parameters. The authority defaults to the x/gov module account.
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
rpc StakeApplication (MsgStakeApplication ) returns (MsgStakeApplicationResponse );
rpc UnstakeApplication (MsgUnstakeApplication ) returns (MsgUnstakeApplicationResponse );
rpc DelegateToGateway (MsgDelegateToGateway ) returns (MsgDelegateToGatewayResponse );
rpc UndelegateFromGateway (MsgUndelegateFromGateway) returns (MsgUndelegateFromGatewayResponse);
rpc UpdateParams (MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc StakeApplication (MsgStakeApplication) returns (MsgStakeApplicationResponse);
rpc UnstakeApplication (MsgUnstakeApplication) returns (MsgUnstakeApplicationResponse);
rpc DelegateToGateway (MsgDelegateToGateway) returns (MsgDelegateToGatewayResponse);
rpc UndelegateFromGateway (MsgUndelegateFromGateway) returns (MsgUndelegateFromGatewayResponse);
rpc TransferApplication (MsgTransferApplication) returns (MsgTransferApplicationResponse);
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/application/MsgUpdateParams";
option (amino.name) = "poktroll/x/application/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Expand All @@ -49,10 +50,12 @@ message MsgUpdateParamsResponse {}

message MsgStakeApplication {
option (cosmos.msg.v1.signer) = "address";

string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application.
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the application has staked. Must be ≥ to the current amount that the application has staked (if any)
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application.
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the application has staked. Must be ≥ to the current amount that the application has staked (if any)
repeated poktroll.shared.ApplicationServiceConfig services = 3; // The list of services this application is staked to request service for
// TODO_POST_MAINNET_CONSIDERATION: Consdier allowing appplications to delegate
// to gateways at time of staking for a better developer experience.
// repeated string gateway_addresss
}

message MsgStakeApplicationResponse {}
Expand All @@ -68,7 +71,6 @@ message MsgDelegateToGateway {
option (cosmos.msg.v1.signer) = "app_address"; // https://docs.cosmos.network/main/build/building-modules/messages-and-queries
string app_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the application.
string gateway_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the gateway the application wants to delegate to.

}

message MsgDelegateToGatewayResponse {}
Expand All @@ -81,3 +83,13 @@ message MsgUndelegateFromGateway {

message MsgUndelegateFromGatewayResponse {}

message MsgTransferApplication {
option (cosmos.msg.v1.signer) = "source_address";
string source_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string destination_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message MsgTransferApplicationResponse {
poktroll.application.Application application = 1;
}

68 changes: 68 additions & 0 deletions x/application/keeper/msg_server_transfer_application_stake.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package keeper

import (
"context"
"fmt"

"github.com/pokt-network/poktroll/telemetry"
"github.com/pokt-network/poktroll/x/application/types"
)

// TransferApplication transfers the stake (held in escrow in the application
// module account) from a source to a (new) destination application account .
func (k msgServer) TransferApplication(ctx context.Context, msg *types.MsgTransferApplication) (*types.MsgTransferApplicationResponse, error) {
isSuccessful := false
defer telemetry.EventSuccessCounter(
"transfer_application_stake",
telemetry.DefaultCounterFn,
func() bool { return isSuccessful },
)

logger := k.Logger().With("method", "TransferApplication")

if err := msg.ValidateBasic(); err != nil {
return nil, err
}

// Ensure destination application does not already exist.
_, isDstFound := k.GetApplication(ctx, msg.GetDestinationAddress())
if isDstFound {
return nil, types.ErrAppDuplicateAddress.Wrapf("destination application (%q) exists", msg.GetDestinationAddress())
}

// Ensure source application exists.
srcApp, isAppFound := k.GetApplication(ctx, msg.GetSourceAddress())
if !isAppFound {
return nil, types.ErrAppNotFound.Wrapf("source application %q not found", msg.GetSourceAddress())
}

// Ensure source application is not already unbonding.
// TODO_TEST: Add E2E coverage to assert that an unbonding app cannot be transferred.
if srcApp.IsUnbonding() {
return nil, types.ErrAppIsUnstaking.Wrapf("cannot transfer stake of unbonding source application %q", msg.GetSourceAddress())
}

// Create a new application derived from the source application.
dstApp := srcApp
dstApp.Address = msg.GetDestinationAddress()

// TODO_NEXT(#789): Reconcile app unbonding logic with the new transfer stake logic.
// I.e., the source should not immediately be transferred.

// TODO_TEST: add E2E coverage to assert #DelegateeGatewayAddresses and #PendingUndelegations
// are present and correct on the dstApp application.

// Update the dstApp in the store
k.SetApplication(ctx, dstApp)
logger.Info(fmt.Sprintf("Successfully transferred application stake from (%s) to (%s)", srcApp.Address, dstApp.Address))

// Remove the transferred app from the store
k.RemoveApplication(ctx, srcApp.GetAddress())
logger.Info(fmt.Sprintf("Successfully removed the application: %+v", srcApp))

isSuccessful = true

return &types.MsgTransferApplicationResponse{
Application: &srcApp,
}, nil
}
Loading
Loading