Skip to content

Commit

Permalink
Merge branch 'main' into feat/allow-supplier-downstaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk authored Dec 9, 2024
2 parents 91e0cc8 + 29aec8a commit ff8d8ff
Show file tree
Hide file tree
Showing 33 changed files with 1,807 additions and 683 deletions.
497 changes: 342 additions & 155 deletions api/poktroll/application/tx.pulsar.go

Large diffs are not rendered by default.

230 changes: 161 additions & 69 deletions api/poktroll/gateway/tx.pulsar.go

Large diffs are not rendered by default.

176 changes: 134 additions & 42 deletions api/poktroll/service/tx.pulsar.go

Large diffs are not rendered by default.

350 changes: 269 additions & 81 deletions api/poktroll/supplier/tx.pulsar.go

Large diffs are not rendered by default.

230 changes: 161 additions & 69 deletions api/poktroll/tokenomics/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions proto/poktroll/application/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ message MsgUnstakeApplication {
string address = 1;
}

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

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

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

message MsgTransferApplication {
option (cosmos.msg.v1.signer) = "source_address";
Expand Down
4 changes: 3 additions & 1 deletion proto/poktroll/gateway/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ message MsgUnstakeGateway {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the gateway
}

message MsgUnstakeGatewayResponse {}
message MsgUnstakeGatewayResponse {
poktroll.gateway.Gateway gateway = 1;
}

// MsgUpdateParam is the Msg/UpdateParam request type to update a single param.
message MsgUpdateParam {
Expand Down
4 changes: 3 additions & 1 deletion proto/poktroll/service/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@ message MsgAddService {
poktroll.shared.Service service = 2 [(gogoproto.nullable) = false]; // The Service being added to the network
}

message MsgAddServiceResponse {}
message MsgAddServiceResponse {
poktroll.shared.Service service = 1;
}

9 changes: 7 additions & 2 deletions proto/poktroll/supplier/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "poktroll/supplier/params.proto";
import "poktroll/shared/service.proto";
import "poktroll/shared/supplier.proto";

// Msg defines the Msg service.
service Msg {
Expand Down Expand Up @@ -50,15 +51,19 @@ message MsgStakeSupplier {
repeated poktroll.shared.SupplierServiceConfig services = 5; // The list of services this supplier is staked to provide service for
}

message MsgStakeSupplierResponse {}
message MsgStakeSupplierResponse {
poktroll.shared.Supplier supplier = 1;
}

message MsgUnstakeSupplier {
option (cosmos.msg.v1.signer) = "signer";
string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the message signer (i.e. owner or operator)
string operator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the operator (i.e. provider, non-custodial)
}

message MsgUnstakeSupplierResponse {}
message MsgUnstakeSupplierResponse {
poktroll.shared.Supplier supplier = 1;
}

// MsgUpdateParam is the Msg/UpdateParam request type to update a single param.
message MsgUpdateParam {
Expand Down
4 changes: 3 additions & 1 deletion proto/poktroll/tokenomics/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ message MsgUpdateParams {

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}
message MsgUpdateParamsResponse {
Params params = 1;
}

// MsgUpdateParam is the Msg/UpdateParam request type to update a single param.
message MsgUpdateParam {
Expand Down
28 changes: 14 additions & 14 deletions x/application/keeper/msg_server_delegate_to_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) {
},
}

expectedApp := &apptypes.Application{
Address: stakeMsg.GetAddress(),
Stake: stakeMsg.GetStake(),
ServiceConfigs: stakeMsg.GetServices(),
DelegateeGatewayAddresses: make([]string, 0),
PendingUndelegations: make(map[uint64]apptypes.UndelegatingGatewayList),
}

// Stake the application & verify that the application exists
_, err := srv.StakeApplication(ctx, stakeMsg)
require.NoError(t, err)
_, isAppFound := k.GetApplication(ctx, appAddr)
foundApp, isAppFound := k.GetApplication(ctx, appAddr)
require.Equal(t, expectedApp, &foundApp)
require.True(t, isAppFound)

// Prepare the delegation message
Expand All @@ -49,21 +58,17 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) {
GatewayAddress: gatewayAddr1,
}

expectedApp.DelegateeGatewayAddresses = append(expectedApp.DelegateeGatewayAddresses, gatewayAddr1)

// Delegate the application to the gateway
_, err = srv.DelegateToGateway(ctx, delegateMsg)
delegateRes, err := srv.DelegateToGateway(ctx, delegateMsg)
require.NoError(t, err)
require.Equal(t, delegateRes.GetApplication(), expectedApp)

sdkCtx := sdk.UnwrapSDKContext(ctx)
currentHeight := sdkCtx.BlockHeight()
sharedParams := sharedtypes.DefaultParams()
sessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight)
expectedApp := &apptypes.Application{
Address: stakeMsg.GetAddress(),
Stake: stakeMsg.GetStake(),
ServiceConfigs: stakeMsg.GetServices(),
DelegateeGatewayAddresses: []string{gatewayAddr1},
PendingUndelegations: make(map[uint64]apptypes.UndelegatingGatewayList),
}
expectedEvent := &apptypes.EventRedelegation{
Application: expectedApp,
SessionEndHeight: sessionEndHeight,
Expand All @@ -77,11 +82,6 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) {
// Reset the events, as if a new block were created.
ctx, sdkCtx = testevents.ResetEventManager(ctx)

// Verify that the application exists
foundApp, isAppFound := k.GetApplication(ctx, appAddr)
require.True(t, isAppFound)
require.EqualValues(t, expectedApp, &foundApp)

// Prepare a second delegation message
delegateMsg2 := &apptypes.MsgDelegateToGateway{
AppAddress: appAddr,
Expand Down
27 changes: 21 additions & 6 deletions x/application/keeper/msg_server_stake_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) {
require.NoError(t, err)

// Assert that the response contains the staked application.
app := stakeAppRes.GetApplication()
require.Equal(t, stakeMsg.GetAddress(), app.GetAddress())
require.Equal(t, stakeMsg.GetStake(), app.GetStake())
require.Equal(t, stakeMsg.GetServices(), app.GetServiceConfigs())
expectedApp := &apptypes.Application{
Address: stakeMsg.GetAddress(),
Stake: stakeMsg.GetStake(),
ServiceConfigs: stakeMsg.GetServices(),
PendingUndelegations: make(map[uint64]apptypes.UndelegatingGatewayList),
DelegateeGatewayAddresses: make([]string, 0),
}
require.Equal(t, expectedApp, stakeAppRes.GetApplication())

// Assert that the EventApplicationStaked event is emitted.
sharedParams := sharedtypes.DefaultParams()
currentHeight := cosmostypes.UnwrapSDKContext(ctx).BlockHeight()
sessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight)
expectedEvent, err := cosmostypes.TypedEventToEvent(
&apptypes.EventApplicationStaked{
Application: app,
Application: stakeAppRes.GetApplication(),
SessionEndHeight: sessionEndHeight,
},
)
Expand Down Expand Up @@ -85,8 +89,19 @@ func TestMsgServer_StakeApplication_SuccessfulCreateAndUpdate(t *testing.T) {
}

// Update the staked application
_, err = srv.StakeApplication(ctx, updateStakeMsg)
stakeAppRes, err = srv.StakeApplication(ctx, updateStakeMsg)
require.NoError(t, err)

// Assert that the response contains the staked application.
expectedApp = &apptypes.Application{
Address: updateStakeMsg.GetAddress(),
Stake: updateStakeMsg.GetStake(),
ServiceConfigs: updateStakeMsg.GetServices(),
PendingUndelegations: make(map[uint64]apptypes.UndelegatingGatewayList),
DelegateeGatewayAddresses: make([]string, 0),
}
require.Equal(t, expectedApp, stakeAppRes.GetApplication())

foundApp, isAppFound = k.GetApplication(ctx, appAddr)
require.True(t, isAppFound)
require.Equal(t, &upStake, foundApp.Stake)
Expand Down
4 changes: 3 additions & 1 deletion x/application/keeper/msg_server_undelegate_from_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (k msgServer) UndelegateFromGateway(ctx context.Context, msg *apptypes.MsgU
logger.Info(fmt.Sprintf("Emitted application redelegation event %v", event))

isSuccessful = true
return &apptypes.MsgUndelegateFromGatewayResponse{}, nil
return &apptypes.MsgUndelegateFromGatewayResponse{
Application: &foundApp,
}, nil
}

// recordPendingUndelegation adds the given gateway address to the application's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) {
GatewayAddress: expectedGatewayAddresses[3],
}

// Undelegate the application from the gateway
_, err = srv.UndelegateFromGateway(ctx, undelegateMsg)
require.NoError(t, err)

// Assert that the EventRedelegation event is emitted.
expectedGatewayAddresses = append(expectedGatewayAddresses[:3], expectedGatewayAddresses[4:]...)
expectedApp := &apptypes.Application{
Expand All @@ -118,6 +114,11 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) {
},
}

// Undelegate the application from the gateway
undelegateRes, err := srv.UndelegateFromGateway(ctx, undelegateMsg)
require.NoError(t, err)
require.Equal(t, undelegateRes.GetApplication(), expectedApp)

events = sdkCtx.EventManager().Events()
redelgationEvents = testevents.FilterEvents[*apptypes.EventRedelegation](t, events)
lastEventIdx := len(redelgationEvents) - 1
Expand Down
4 changes: 3 additions & 1 deletion x/application/keeper/msg_server_unstake_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,7 @@ func (k msgServer) UnstakeApplication(
}

isSuccessful = true
return &apptypes.MsgUnstakeApplicationResponse{}, nil
return &apptypes.MsgUnstakeApplicationResponse{
Application: &foundApp,
}, nil
}
6 changes: 4 additions & 2 deletions x/application/keeper/msg_server_unstake_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ func TestMsgServer_UnstakeApplication_CancelUnbondingIfRestaked(t *testing.T) {

// Initiate the application unstaking
unstakeMsg := &apptypes.MsgUnstakeApplication{Address: appAddr}
_, err = srv.UnstakeApplication(ctx, unstakeMsg)
unstakeRes, err := srv.UnstakeApplication(ctx, unstakeMsg)
require.NoError(t, err)

// Assert that the EventApplicationUnbondingBegin event is emitted.
foundApp.UnstakeSessionEndHeight = uint64(sessionEndHeight)
foundApp.DelegateeGatewayAddresses = make([]string, 0)
require.Equal(t, &foundApp, unstakeRes.GetApplication())

// Assert that the EventApplicationUnbondingBegin event is emitted.
unbondingEndHeight := apptypes.GetApplicationUnbondingHeight(&sharedParams, &foundApp)
expectedAppUnbondingBeginEvent := &apptypes.EventApplicationUnbondingBegin{
Application: &foundApp,
Expand Down
2 changes: 1 addition & 1 deletion x/application/types/message_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (msg *MsgUpdateParam) ValidateBasic() error {
}
}

// genericTypeIsCoin checks if the parameter type is T, returning an error if not.
// genericParamTypeIs checks if the parameter type is T, returning an error if not.
func genericParamTypeIs[T any](msg *MsgUpdateParam) error {
if _, ok := msg.AsType.(T); !ok {
return ErrAppParamInvalid.Wrapf(
Expand Down
Loading

0 comments on commit ff8d8ff

Please sign in to comment.