diff --git a/.github/workflows-helpers/run-e2e-test-job-template.yaml b/.github/workflows-helpers/run-e2e-test-job-template.yaml index 9dd133b89..28c60748e 100644 --- a/.github/workflows-helpers/run-e2e-test-job-template.yaml +++ b/.github/workflows-helpers/run-e2e-test-job-template.yaml @@ -31,6 +31,8 @@ spec: name: celestia-secret - name: POCKET_NODE value: tcp://${NAMESPACE}-sequencer:36657 + - name: SEQUENCER_RPC_ENDPOINT + value: ${NAMESPACE}-sequencer:36657 - name: E2E_DEBUG_OUTPUT value: "false" # Flip to true to see the command and result of the execution - name: POKTROLLD_HOME diff --git a/Dockerfile.dev b/Dockerfile.dev index 4d5645fa6..be65919a6 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -23,6 +23,5 @@ RUN ignite chain init --skip-proto EXPOSE 8545 EXPOSE 8546 EXPOSE 8547 -EXPOSE 8548 ENTRYPOINT ["ignite"] diff --git a/Tiltfile b/Tiltfile index e7444a901..ec07451c3 100644 --- a/Tiltfile +++ b/Tiltfile @@ -33,6 +33,7 @@ if localnet_config["helm_chart_local_repo"]["enabled"]: print("Using local helm chart repo " + helm_chart_local_repo) chart_prefix = helm_chart_local_repo + "/charts/" + # Import files into Kubernetes ConfigMap def read_files_from_directory(directory): files = listdir(directory) @@ -158,7 +159,7 @@ k8s_resource( "relayminers", labels=["blockchains"], resource_deps=["sequencer"], - port_forwards=["8548", "40005"], + port_forwards=["8545", "40005"], ) k8s_resource( "appgateservers", diff --git a/app/app.go b/app/app.go index 9f2b7de84..352038462 100644 --- a/app/app.go +++ b/app/app.go @@ -110,6 +110,8 @@ import ( ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" + "github.com/spf13/cast" + appparams "github.com/pokt-network/poktroll/app/params" "github.com/pokt-network/poktroll/docs" applicationmodule "github.com/pokt-network/poktroll/x/application" @@ -133,7 +135,6 @@ import ( tokenomicsmodule "github.com/pokt-network/poktroll/x/tokenomics" tokenomicsmodulekeeper "github.com/pokt-network/poktroll/x/tokenomics/keeper" tokenomicsmoduletypes "github.com/pokt-network/poktroll/x/tokenomics/types" - "github.com/spf13/cast" ) const ( diff --git a/e2e/tests/node.go b/e2e/tests/node.go index 174beff69..5bf187556 100644 --- a/e2e/tests/node.go +++ b/e2e/tests/node.go @@ -118,9 +118,9 @@ func (p *pocketdBin) runCurlPostCmd(rpcUrl string, service string, data string, dataStr := fmt.Sprintf("%s", data) urlStr := fmt.Sprintf("%s/%s", rpcUrl, service) base := []string{ - "-v", // verbose output - "-sS", // silent with error - "POST", // HTTP method + "-v", // verbose output + "-sS", // silent with error + "-X", "POST", // HTTP method "-H", "Content-Type: application/json", // HTTP headers "--data", dataStr, urlStr, // POST data } diff --git a/e2e/tests/relay.feature b/e2e/tests/relay.feature index 484172092..32f965bb9 100644 --- a/e2e/tests/relay.feature +++ b/e2e/tests/relay.feature @@ -1,5 +1,7 @@ Feature: Relay Namespace + # TODO_TECHDEBT(@Olshansk, #180): This test requires you to run `make supplier1_stake && make app1_stake` first + # As a shorter workaround, we can also add steps that stake the application and supplier as part of the scenario. Scenario: App can send relay to Supplier Given the user has the pocketd binary installed And the application "app1" is staked for service "anvil" diff --git a/e2e/tests/session_steps_test.go b/e2e/tests/session_steps_test.go index 0d9b9736f..96248e243 100644 --- a/e2e/tests/session_steps_test.go +++ b/e2e/tests/session_steps_test.go @@ -11,20 +11,19 @@ import ( "time" abci "github.com/cometbft/cometbft/abci/types" - "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/pkg/client/events" "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable" "github.com/pokt-network/poktroll/pkg/observable/channel" "github.com/pokt-network/poktroll/testutil/testclient" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" + "github.com/stretchr/testify/require" ) const ( createClaimTimeoutDuration = 10 * time.Second eitherEventsReplayBufferSize = 100 - msgClaimSenderQueryFmt = "tm.event='Tx' AND message.sender='%s'" + msgClaimSenderQueryFmt = "tm.event='Tx' AND message.sender='%s' AND message.action='/pocket.supplier.MsgCreateClaim'" testServiceId = "anvil" eitherEventsBzReplayObsKey = "eitherEventsBzReplayObsKey" preExistingClaimsKey = "preExistingClaimsKey" @@ -86,17 +85,21 @@ func (s *suite) AfterTheSupplierCreatesAClaimForTheSessionForServiceForApplicati func (s *suite) TheClaimCreatedBySupplierForServiceForApplicationShouldBePersistedOnchain(supplierName, serviceId, appName string) { ctx := context.Background() - claimsRes, err := s.supplierQueryClient.AllClaims(ctx, &suppliertypes.QueryAllClaimsRequest{ + allClaimsRes, err := s.supplierQueryClient.AllClaims(ctx, &suppliertypes.QueryAllClaimsRequest{ Filter: &suppliertypes.QueryAllClaimsRequest_SupplierAddress{ SupplierAddress: accNameToAddrMap[supplierName], }, }) require.NoError(s, err) - require.NotNil(s, claimsRes) + require.NotNil(s, allClaimsRes) // Assert that the number of claims has increased by one. preExistingClaims := s.scenarioState[preExistingClaimsKey].([]suppliertypes.Claim) - require.Len(s, claimsRes.Claim, len(preExistingClaims)+1) + // NB: We are avoiding the use of require.Len here because it provides unreadable output + // TODO_TECHDEBT: Due to the speed of the blocks of the LocalNet sequencer, along with the small number + // of blocks per session, multiple claims may be created throughout the duration of the test. Until + // these values are appropriately adjusted + require.Greater(s, len(allClaimsRes.Claim), len(preExistingClaims), "number of claims must have increased") // TODO_IMPROVE: assert that the root hash of the claim contains the correct // SMST sum. The sum can be retrieved by parsing the last 8 bytes as a @@ -106,7 +109,7 @@ func (s *suite) TheClaimCreatedBySupplierForServiceForApplicationShouldBePersist // TODO_IMPROVE: add assertions about serviceId and appName and/or incorporate // them into the scenarioState key(s). - claim := claimsRes.Claim[0] + claim := allClaimsRes.Claim[0] require.Equal(s, accNameToAddrMap[supplierName], claim.SupplierAddress) } @@ -118,9 +121,9 @@ func (s *suite) TheSupplierHasServicedASessionWithRelaysForServiceForApplication // Query for any existing claims so that we can compensate for them in the // future assertions about changes in on-chain claims. - claimsRes, err := s.supplierQueryClient.AllClaims(ctx, &suppliertypes.QueryAllClaimsRequest{}) + allClaimsRes, err := s.supplierQueryClient.AllClaims(ctx, &suppliertypes.QueryAllClaimsRequest{}) require.NoError(s, err) - s.scenarioState[preExistingClaimsKey] = claimsRes.Claim + s.scenarioState[preExistingClaimsKey] = allClaimsRes.Claim // Construct an events query client to listen for tx events from the supplier. msgSenderQuery := fmt.Sprintf(msgClaimSenderQueryFmt, accNameToAddrMap[supplierName]) diff --git a/go.mod b/go.mod index ddb25c1fd..08aa46324 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( github.com/athanorlabs/go-dleq v0.1.0 github.com/cometbft/cometbft v0.37.2 github.com/cometbft/cometbft-db v0.8.0 + github.com/cosmos/cosmos-proto v1.0.0-beta.2 github.com/cosmos/cosmos-sdk v0.47.3 github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-go/v7 v7.1.0 @@ -45,6 +46,7 @@ require ( go.uber.org/multierr v1.11.0 golang.org/x/crypto v0.15.0 golang.org/x/sync v0.5.0 + google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb google.golang.org/grpc v1.59.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -88,7 +90,6 @@ require ( github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v0.20.0 // indirect @@ -284,7 +285,6 @@ require ( google.golang.org/api v0.143.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/localnet/kubernetes/values-relayminer.yaml b/localnet/kubernetes/values-relayminer.yaml index 573d05bcb..0fcd2b27c 100644 --- a/localnet/kubernetes/values-relayminer.yaml +++ b/localnet/kubernetes/values-relayminer.yaml @@ -1,4 +1,3 @@ config: query_node_url: tcp://sequencer-poktroll-sequencer:36657 network_node_url: tcp://sequencer-poktroll-sequencer:36657 - \ No newline at end of file diff --git a/pkg/client/block/block.go b/pkg/client/block/block.go index bbc61e365..06f6bf679 100644 --- a/pkg/client/block/block.go +++ b/pkg/client/block/block.go @@ -27,9 +27,9 @@ func (blockEvent *cometBlockEvent) Hash() []byte { return blockEvent.Block.LastBlockID.Hash.Bytes() } -// newCometBlockEventFactoryFn is a factory function that returns a functon +// newCometBlockEventFactoryFn is a factory function that returns a function // that attempts to deserialize the given bytes into a comet block. -// if the resulting block has a height of zero, assume the event was not a block +// If the resulting block has a height of zero, assume the event was not a block // event and return an ErrUnmarshalBlockEvent error. func newCometBlockEventFactoryFn() events.NewEventsFn[client.Block] { return func(blockMsgBz []byte) (client.Block, error) { @@ -38,7 +38,9 @@ func newCometBlockEventFactoryFn() events.NewEventsFn[client.Block] { return nil, err } - // If msg does not match the expected format then the block's height has a zero value. + // The header height should never be zero. If it is, it means that blockMsg + // does not match the expected format which led unmarshaling to fail, + // and blockHeader.height to have a default value. if blockMsg.Block.Header.Height == 0 { return nil, events.ErrEventsUnmarshalEvent. Wrapf("with block data: %s", string(blockMsgBz)) diff --git a/pkg/client/block/client.go b/pkg/client/block/client.go index 1103a4b66..cb04bdc07 100644 --- a/pkg/client/block/client.go +++ b/pkg/client/block/client.go @@ -15,11 +15,11 @@ const ( // the chain. // See: https://docs.cosmos.network/v0.47/learn/advanced/events#default-events committedBlocksQuery = "tm.event='NewBlock'" - // TODO_TECHDEBT/TODO_FUTURE: add a `blocksReplayLimit` field to the block - // client struct that defaults to this but can be overridden via an option - // in future work. + // defaultBlocksReplayLimit is the number of blocks that the replay // observable returned by LastNBlocks() will be able to replay. + // TODO_TECHDEBT/TODO_FUTURE: add a `blocksReplayLimit` field to the blockClient + // struct that defaults to this but can be overridden via an option. defaultBlocksReplayLimit = 100 ) diff --git a/pkg/client/delegation/client.go b/pkg/client/delegation/client.go index c45d3859a..883969f6d 100644 --- a/pkg/client/delegation/client.go +++ b/pkg/client/delegation/client.go @@ -15,11 +15,11 @@ const ( // See: https://docs.cosmos.network/v0.47/learn/advanced/events#subscribing-to-events // And: https://docs.cosmos.network/v0.47/learn/advanced/events#default-events delegationEventQuery = "message.action='pocket.application.EventRedelegation'" - // TODO_TECHDEBT/TODO_FUTURE: add a `blocksReplayLimit` field to the block - // client struct that defaults to this but can be overridden via an option - // in future work. + // defaultRedelegationsReplayLimit is the number of redelegations that the // replay observable returned by LastNRedelegations() will be able to replay. + // TODO_TECHDEBT/TODO_FUTURE: add a `redelegationsReplayLimit` field to the `delegationClient` + // struct that defaults to this but can be overridden via an option. defaultRedelegationsReplayLimit = 100 ) diff --git a/pkg/client/events/replay_client_example_test.go b/pkg/client/events/replay_client_example_test.go index 15a656665..69cb3a2f0 100644 --- a/pkg/client/events/replay_client_example_test.go +++ b/pkg/client/events/replay_client_example_test.go @@ -6,7 +6,6 @@ import ( "fmt" "cosmossdk.io/depinject" - "github.com/pokt-network/poktroll/pkg/client/events" "github.com/pokt-network/poktroll/pkg/observable" "github.com/pokt-network/poktroll/pkg/polylog" @@ -23,6 +22,8 @@ const ( replayObsBufferSize = 1 ) +var _ EventType = (*eventType)(nil) + // Define an interface to represent the onchain event type EventType interface { GetName() string // Illustrative only; arbitrary interfaces are supported. diff --git a/pkg/client/interface.go b/pkg/client/interface.go index 320914246..a857c14b2 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -111,7 +111,7 @@ type Block interface { // Redelegation is an interface which wraps the EventRedelegation event // emitted by the application module. -// See: proto/pocket/application/types/event.proto#EventRedelegatio +// See: proto/pocket/application/types/event.proto#EventRedelegation type Redelegation interface { GetAppAddress() string GetGatewayAddress() string diff --git a/pkg/client/supplier/client.go b/pkg/client/supplier/client.go index a0172c3c5..4bf4c0554 100644 --- a/pkg/client/supplier/client.go +++ b/pkg/client/supplier/client.go @@ -9,6 +9,7 @@ import ( "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/keyring" + "github.com/pokt-network/poktroll/pkg/polylog" sessiontypes "github.com/pokt-network/poktroll/x/session/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -66,6 +67,8 @@ func (sClient *supplierClient) SubmitProof( sessionHeader sessiontypes.SessionHeader, proof *smt.SparseMerkleClosestProof, ) error { + logger := polylog.Ctx(ctx) + proofBz, err := proof.Marshal() if err != nil { return err @@ -82,6 +85,16 @@ func (sClient *supplierClient) SubmitProof( return err } + // TODO_IMPROVE: log details related to what & how much is being proven + logger.Info(). + Fields(map[string]any{ + "supplier_addr": sClient.signingKeyAddr.String(), + "app_addr": sessionHeader.ApplicationAddress, + "session_id": sessionHeader.SessionId, + "service": sessionHeader.Service.Id, + }). + Msg("submitted a new proof") + return <-errCh } @@ -93,6 +106,8 @@ func (sClient *supplierClient) CreateClaim( sessionHeader sessiontypes.SessionHeader, rootHash []byte, ) error { + logger := polylog.Ctx(ctx) + msg := &suppliertypes.MsgCreateClaim{ SupplierAddress: sClient.signingKeyAddr.String(), SessionHeader: &sessionHeader, @@ -104,8 +119,17 @@ func (sClient *supplierClient) CreateClaim( return err } - err = <-errCh - return err + // TODO_IMPROVE: log details related to how much is claimed + logger.Info(). + Fields(map[string]any{ + "supplier_addr": sClient.signingKeyAddr.String(), + "app_addr": sessionHeader.ApplicationAddress, + "session_id": sessionHeader.SessionId, + "service": sessionHeader.Service.Id, + }). + Msg("created a new claim") + + return <-errCh } // validateConfigAndSetDefaults attempts to get the address from the keyring diff --git a/pkg/client/supplier/client_test.go b/pkg/client/supplier/client_test.go index 830426946..4c92ef3ba 100644 --- a/pkg/client/supplier/client_test.go +++ b/pkg/client/supplier/client_test.go @@ -8,19 +8,21 @@ import ( "cosmossdk.io/depinject" "github.com/golang/mock/gomock" - "github.com/pokt-network/smt" - "github.com/stretchr/testify/require" - - "github.com/pokt-network/poktroll/testutil/mockclient" - "github.com/pokt-network/poktroll/pkg/client/keyring" "github.com/pokt-network/poktroll/pkg/client/supplier" + "github.com/pokt-network/poktroll/testutil/mockclient" "github.com/pokt-network/poktroll/testutil/testclient/testkeyring" "github.com/pokt-network/poktroll/testutil/testclient/testtx" sessiontypes "github.com/pokt-network/poktroll/x/session/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + "github.com/pokt-network/smt" + "github.com/stretchr/testify/require" ) -var testSigningKeyName = "test_signer" +const ( + testSigningKeyName = "test_signer" + testService = "test_service" +) func TestNewSupplierClient(t *testing.T) { ctrl := gomock.NewController(t) @@ -85,7 +87,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) { require.NoError(t, err) txCtxMock, _ := testtx.NewAnyTimesTxTxContext(t, keyring) - txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, signAndBroadcastDelay) + txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, ctx, signAndBroadcastDelay) signingKeyOpt := supplier.WithSigningKeyName(testAppKey.Name) deps := depinject.Supply( @@ -102,6 +104,9 @@ func TestSupplierClient_CreateClaim(t *testing.T) { ApplicationAddress: testAppAddr.String(), SessionStartBlockHeight: 0, SessionId: "", + Service: &sharedtypes.Service{ + Id: testService, + }, } go func() { @@ -141,7 +146,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) { require.NoError(t, err) txCtxMock, _ := testtx.NewAnyTimesTxTxContext(t, keyring) - txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, signAndBroadcastDelay) + txClientMock := testtx.NewOneTimeDelayedSignAndBroadcastTxClient(t, ctx, signAndBroadcastDelay) signingKeyOpt := supplier.WithSigningKeyName(testAppKey.Name) deps := depinject.Supply( @@ -157,6 +162,9 @@ func TestSupplierClient_SubmitProof(t *testing.T) { ApplicationAddress: testAppAddr.String(), SessionStartBlockHeight: 0, SessionId: "", + Service: &sharedtypes.Service{ + Id: testService, + }, } kvStore, err := smt.NewKVStore("") diff --git a/pkg/relayer/proxy/synchronous.go b/pkg/relayer/proxy/synchronous.go index 341413d34..c748be383 100644 --- a/pkg/relayer/proxy/synchronous.go +++ b/pkg/relayer/proxy/synchronous.go @@ -8,6 +8,7 @@ import ( "net/url" sdkerrors "cosmossdk.io/errors" + "github.com/pokt-network/poktroll/pkg/polylog" "github.com/pokt-network/poktroll/pkg/relayer" "github.com/pokt-network/poktroll/x/service/types" diff --git a/testutil/keeper/tokenomics.go b/testutil/keeper/tokenomics.go index ed811ff3b..bf33cb087 100644 --- a/testutil/keeper/tokenomics.go +++ b/testutil/keeper/tokenomics.go @@ -12,9 +12,10 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/x/tokenomics/keeper" "github.com/pokt-network/poktroll/x/tokenomics/types" - "github.com/stretchr/testify/require" ) func TokenomicsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { diff --git a/testutil/network/network.go b/testutil/network/network.go index 9ded9e609..4a57a2f4e 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -101,6 +101,9 @@ func DefaultConfig() network.Config { } } +// TODO_CLEANUP: Refactor the genesis state helpers below to consolidate usage +// and reduce the code footprint. + // DefaultApplicationModuleGenesisState generates a GenesisState object with a given number of applications. // It returns the populated GenesisState object. func DefaultApplicationModuleGenesisState(t *testing.T, n int) *apptypes.GenesisState { @@ -148,24 +151,6 @@ func ApplicationModuleGenesisStateWithAddresses(t *testing.T, addresses []string return state } -// DefaultGatewayModuleGenesisState generates a GenesisState object with a given number of gateways. -// It returns the populated GenesisState object. -func DefaultGatewayModuleGenesisState(t *testing.T, n int) *gatewaytypes.GenesisState { - t.Helper() - state := gatewaytypes.DefaultGenesis() - for i := 0; i < n; i++ { - stake := sdk.NewCoin("upokt", sdk.NewInt(int64(i))) - gateway := gatewaytypes.Gateway{ - Address: sample.AccAddress(), - Stake: &stake, - } - // TODO_CONSIDERATION: Evaluate whether we need `nullify.Fill` or if we should enforce `(gogoproto.nullable) = false` everywhere - // nullify.Fill(&gateway) - state.GatewayList = append(state.GatewayList, gateway) - } - return state -} - // DefaultSupplierModuleGenesisState generates a GenesisState object with a given number of suppliers. // It returns the populated GenesisState object. func DefaultSupplierModuleGenesisState(t *testing.T, n int) *suppliertypes.GenesisState { @@ -222,8 +207,27 @@ func SupplierModuleGenesisStateWithAddresses(t *testing.T, addresses []string) * return state } +// DefaultGatewayModuleGenesisState generates a GenesisState object with a given +// number of gateways. It returns the populated GenesisState object. +func DefaultGatewayModuleGenesisState(t *testing.T, n int) *gatewaytypes.GenesisState { + t.Helper() + state := gatewaytypes.DefaultGenesis() + for i := 0; i < n; i++ { + stake := sdk.NewCoin("upokt", sdk.NewInt(int64(i))) + gateway := gatewaytypes.Gateway{ + Address: sample.AccAddress(), + Stake: &stake, + } + // TODO_CONSIDERATION: Evaluate whether we need `nullify.Fill` or if we should enforce `(gogoproto.nullable) = false` everywhere + // nullify.Fill(&gateway) + state.GatewayList = append(state.GatewayList, gateway) + } + return state +} + // GatewayModuleGenesisStateWithAddresses generates a GenesisState object with // a gateway list full of gateways with the given addresses. +// It returns the populated GenesisState object. func GatewayModuleGenesisStateWithAddresses(t *testing.T, addresses []string) *gatewaytypes.GenesisState { t.Helper() state := gatewaytypes.DefaultGenesis() @@ -237,6 +241,9 @@ func GatewayModuleGenesisStateWithAddresses(t *testing.T, addresses []string) *g return state } +// TODO_CLEANUP: Consolidate all of the helpers below to use shared business +// logic and move into its own helpers file. + // InitAccount initializes an Account by sending it some funds from the validator // in the network to the address provided func InitAccount(t *testing.T, net *Network, addr sdk.AccAddress) { diff --git a/testutil/testclient/localnet.go b/testutil/testclient/localnet.go index c0374a7ba..3e30318ed 100644 --- a/testutil/testclient/localnet.go +++ b/testutil/testclient/localnet.go @@ -1,6 +1,9 @@ package testclient import ( + "fmt" + "os" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -12,26 +15,26 @@ import ( "github.com/pokt-network/poktroll/cmd/pocketd/cmd" ) -const ( +var ( // CometLocalTCPURL provides a default URL pointing to the localnet TCP endpoint. - // - // TODO_IMPROVE: It would be nice if the value could be set correctly based - // on whether the test using it is running in tilt or not. - CometLocalTCPURL = "tcp://sequencer-poktroll-sequencer:36657" + CometLocalTCPURL = "tcp://localhost:36657" // CometLocalWebsocketURL provides a default URL pointing to the localnet websocket endpoint. - // - // TODO_IMPROVE: It would be nice if the value could be set correctly based - // on whether the test using it is running in tilt or not. - CometLocalWebsocketURL = "ws://sequencer-poktroll-sequencer:36657/websocket" -) + CometLocalWebsocketURL = "ws://localhost:36657/websocket" -// EncodingConfig encapsulates encoding configurations for the Pocket application. -var EncodingConfig = app.MakeEncodingConfig() + // EncodingConfig encapsulates encoding configurations for the Pocket application. + EncodingConfig = app.MakeEncodingConfig() +) // init initializes the SDK configuration upon package import. func init() { cmd.InitSDKConfig() + + // If SEQUENCER_RPC_ENDPOINT environment variable is set, use it to override the default localnet endpoint. + if endpoint := os.Getenv("SEQUENCER_RPC_ENDPOINT"); endpoint != "" { + CometLocalTCPURL = fmt.Sprintf("tcp://%s", endpoint) + CometLocalWebsocketURL = fmt.Sprintf("ws://%s/websocket", endpoint) + } } // NewLocalnetClientCtx creates a client context specifically tailored for localnet diff --git a/testutil/testclient/testtx/client.go b/testutil/testclient/testtx/client.go index 496c99023..4bc85c218 100644 --- a/testutil/testclient/testtx/client.go +++ b/testutil/testclient/testtx/client.go @@ -10,11 +10,10 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/testutil/mockclient" - "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/tx" "github.com/pokt-network/poktroll/pkg/either" + "github.com/pokt-network/poktroll/testutil/mockclient" "github.com/pokt-network/poktroll/testutil/testclient/testblock" "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" ) @@ -50,12 +49,13 @@ func NewLocalnetClient(t *testing.T, opts ...client.TxClientOption) client.TxCli // expectation to perform a SignAndBroadcast operation with a specified delay. func NewOneTimeDelayedSignAndBroadcastTxClient( t *testing.T, + ctx context.Context, delay time.Duration, ) *mockclient.MockTxClient { t.Helper() signAndBroadcast := newSignAndBroadcastSucceedsDelayed(delay) - return NewOneTimeSignAndBroadcastTxClient(t, signAndBroadcast) + return NewOneTimeSignAndBroadcastTxClient(t, ctx, signAndBroadcast) } // NewOneTimeSignAndBroadcastTxClient constructs a mock TxClient with the @@ -63,6 +63,7 @@ func NewOneTimeDelayedSignAndBroadcastTxClient( // the return from the given signAndBroadcast function. func NewOneTimeSignAndBroadcastTxClient( t *testing.T, + ctx context.Context, signAndBroadcast signAndBroadcastFn, ) *mockclient.MockTxClient { t.Helper() @@ -71,7 +72,7 @@ func NewOneTimeSignAndBroadcastTxClient( txClient := mockclient.NewMockTxClient(ctrl) txClient.EXPECT().SignAndBroadcast( - gomock.AssignableToTypeOf(context.Background()), + gomock.Eq(ctx), gomock.Any(), ).DoAndReturn(signAndBroadcast).Times(1) diff --git a/x/application/keeper/msg_server_delegate_to_gateway.go b/x/application/keeper/msg_server_delegate_to_gateway.go index f46275545..c2ecd82a0 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway.go +++ b/x/application/keeper/msg_server_delegate_to_gateway.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,53 +14,53 @@ func (k msgServer) DelegateToGateway(goCtx context.Context, msg *types.MsgDelega ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "DelegateToGateway") - logger.Info("About to delegate application to gateway with msg: %v", msg) + logger.Info(fmt.Sprintf("About to delegate application to gateway with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { - logger.Error("Delegation Message failed basic validation: %v", err) + logger.Error(fmt.Sprintf("Delegation Message failed basic validation: %v", err)) return nil, err } // Retrieve the application from the store app, found := k.GetApplication(ctx, msg.AppAddress) if !found { - logger.Info("Application not found with address [%s]", msg.AppAddress) + logger.Info(fmt.Sprintf("Application not found with address [%s]", msg.AppAddress)) return nil, sdkerrors.Wrapf(types.ErrAppNotFound, "application not found with address: %s", msg.AppAddress) } - logger.Info("Application found with address [%s]", msg.AppAddress) + logger.Info(fmt.Sprintf("Application found with address [%s]", msg.AppAddress)) // Check if the gateway is staked if _, found := k.gatewayKeeper.GetGateway(ctx, msg.GatewayAddress); !found { - logger.Info("Gateway not found with address [%s]", msg.GatewayAddress) + logger.Info(fmt.Sprintf("Gateway not found with address [%s]", msg.GatewayAddress)) return nil, sdkerrors.Wrapf(types.ErrAppGatewayNotFound, "gateway not found with address: %s", msg.GatewayAddress) } // Ensure the application is not already delegated to the maximum number of gateways maxDelegatedParam := k.GetParams(ctx).MaxDelegatedGateways if int64(len(app.DelegateeGatewayAddresses)) >= maxDelegatedParam { - logger.Info("Application already delegated to maximum number of gateways: %d", maxDelegatedParam) + logger.Info(fmt.Sprintf("Application already delegated to maximum number of gateways: %d", maxDelegatedParam)) return nil, sdkerrors.Wrapf(types.ErrAppMaxDelegatedGateways, "application already delegated to %d gateways", maxDelegatedParam) } // Check if the application is already delegated to the gateway for _, gatewayAddr := range app.DelegateeGatewayAddresses { if gatewayAddr == msg.GatewayAddress { - logger.Info("Application already delegated to gateway with address [%s]", msg.GatewayAddress) + logger.Info(fmt.Sprintf("Application already delegated to gateway with address [%s]", msg.GatewayAddress)) return nil, sdkerrors.Wrapf(types.ErrAppAlreadyDelegated, "application already delegated to gateway with address: %s", msg.GatewayAddress) } } // Update the application with the new delegatee public key app.DelegateeGatewayAddresses = append(app.DelegateeGatewayAddresses, msg.GatewayAddress) - logger.Info("Successfully added delegatee public key to application") + logger.Info(fmt.Sprintf("Successfully added delegatee public key to application")) // Update the application store with the new delegation k.SetApplication(ctx, app) - logger.Info("Successfully delegated application to gateway for app: %+v", app) + logger.Info(fmt.Sprintf("Successfully delegated application to gateway for app: %+v", app)) // Emit the application redelegation change event if err := ctx.EventManager().EmitTypedEvent(msg.NewRedelegationEvent()); err != nil { - logger.Error("Failed to emit application redelegation event: %v", err) + logger.Error(fmt.Sprintf("Failed to emit application redelegation event: %v", err)) return nil, err } diff --git a/x/application/keeper/msg_server_delegate_to_gateway_test.go b/x/application/keeper/msg_server_delegate_to_gateway_test.go index 1e293aa04..f926af58d 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway_test.go +++ b/x/application/keeper/msg_server_delegate_to_gateway_test.go @@ -57,7 +57,9 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { require.Equal(t, 1, len(events)) require.Equal(t, "pocket.application.EventRedelegation", events[0].Type) require.Equal(t, "app_address", events[0].Attributes[0].Key) + require.Equal(t, "gateway_address", events[0].Attributes[1].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[0].Attributes[0].Value) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddr1), events[0].Attributes[1].Value) // Verify that the application exists foundApp, isAppFound := k.GetApplication(ctx, appAddr) @@ -79,7 +81,11 @@ func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { require.Equal(t, 2, len(events)) require.Equal(t, "pocket.application.EventRedelegation", events[1].Type) require.Equal(t, "app_address", events[1].Attributes[0].Key) + require.Equal(t, "gateway_address", events[1].Attributes[1].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[1].Attributes[0].Value) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddr2), events[1].Attributes[1].Value) + + // Verify that the application exists foundApp, isAppFound = k.GetApplication(ctx, appAddr) require.True(t, isAppFound) require.Equal(t, 2, len(foundApp.DelegateeGatewayAddresses)) @@ -128,7 +134,9 @@ func TestMsgServer_DelegateToGateway_FailDuplicate(t *testing.T) { require.Equal(t, 1, len(events)) require.Equal(t, "pocket.application.EventRedelegation", events[0].Type) require.Equal(t, "app_address", events[0].Attributes[0].Key) + require.Equal(t, "gateway_address", events[0].Attributes[1].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[0].Attributes[0].Value) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddr), events[0].Attributes[1].Value) // Verify that the application exists foundApp, isAppFound := k.GetApplication(ctx, appAddr) @@ -199,11 +207,8 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) wctx := sdk.WrapSDKContext(ctx) - // Generate an address for the application and gateway + // Generate an address for the application appAddr := sample.AccAddress() - gatewayAddr := sample.AccAddress() - // Mock the gateway being staked via the staked gateway map - keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr) // Prepare the application stakeMsg := &types.MsgStakeApplication{ @@ -222,17 +227,13 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) { _, isAppFound := k.GetApplication(ctx, appAddr) require.True(t, isAppFound) - // Prepare the delegation message - delegateMsg := &types.MsgDelegateToGateway{ - AppAddress: appAddr, - GatewayAddress: gatewayAddr, - } - // Delegate the application to the max number of gateways maxDelegatedParam := k.GetParams(ctx).MaxDelegatedGateways + gatewayAddresses := make([]string, maxDelegatedParam) for i := int64(0); i < k.GetParams(ctx).MaxDelegatedGateways; i++ { // Prepare the delegation message gatewayAddr := sample.AccAddress() + gatewayAddresses[i] = gatewayAddr // Mock the gateway being staked via the staked gateway map keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr) delegateMsg := &types.MsgDelegateToGateway{ @@ -247,12 +248,25 @@ func TestMsgServer_DelegateToGateway_FailMaxReached(t *testing.T) { require.True(t, isAppFound) require.Equal(t, int(i+1), len(foundApp.DelegateeGatewayAddresses)) } + events := ctx.EventManager().Events() require.Equal(t, int(maxDelegatedParam), len(events)) - for _, event := range events { + for i, event := range events { require.Equal(t, "pocket.application.EventRedelegation", event.Type) require.Equal(t, "app_address", event.Attributes[0].Key) + require.Equal(t, "gateway_address", event.Attributes[1].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), event.Attributes[0].Value) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddresses[i]), event.Attributes[1].Value) + } + + // Generate an address for the gateway that'll exceed the max + gatewayAddr := sample.AccAddress() + keepertest.AddGatewayToStakedGatewayMap(t, gatewayAddr) + + // Prepare the delegation message + delegateMsg := &types.MsgDelegateToGateway{ + AppAddress: appAddr, + GatewayAddress: gatewayAddr, } // Attempt to delegate the application when the max is already reached diff --git a/x/application/keeper/msg_server_stake_application.go b/x/application/keeper/msg_server_stake_application.go index cc735919b..da22a134e 100644 --- a/x/application/keeper/msg_server_stake_application.go +++ b/x/application/keeper/msg_server_stake_application.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,10 +17,10 @@ func (k msgServer) StakeApplication( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "StakeApplication") - logger.Info("About to stake application with msg: %v", msg) + logger.Info(fmt.Sprintf("About to stake application with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { - logger.Error("invalid MsgStakeApplication: %v", err) + logger.Error(fmt.Sprintf("invalid MsgStakeApplication: %v", err)) return nil, err } @@ -28,11 +29,11 @@ func (k msgServer) StakeApplication( var coinsToDelegate sdk.Coin app, isAppFound := k.GetApplication(ctx, msg.Address) if !isAppFound { - logger.Info("Application not found. Creating new application for address %s", msg.Address) + logger.Info(fmt.Sprintf("Application not found. Creating new application for address %s", msg.Address)) app = k.createApplication(ctx, msg) coinsToDelegate = *msg.Stake } else { - logger.Info("Application found. Updating application for address %s", msg.Address) + logger.Info(fmt.Sprintf("Application found. Updating application for address %s", msg.Address)) currAppStake := *app.Stake if err = k.updateApplication(ctx, &app, msg); err != nil { return nil, err @@ -43,7 +44,7 @@ func (k msgServer) StakeApplication( // Retrieve the address of the application appAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error("could not parse address %s", msg.Address) + logger.Error(fmt.Sprintf("could not parse address %s", msg.Address)) return nil, err } @@ -51,13 +52,13 @@ func (k msgServer) StakeApplication( // Send the coins from the application to the staked application pool err = k.bankKeeper.DelegateCoinsFromAccountToModule(ctx, appAddress, types.ModuleName, []sdk.Coin{coinsToDelegate}) if err != nil { - logger.Error("could not send %v coins from %s to %s module account due to %v", coinsToDelegate, appAddress, types.ModuleName, err) + logger.Error(fmt.Sprintf("could not send %v coins from %s to %s module account due to %v", coinsToDelegate, appAddress, types.ModuleName, err)) return nil, err } // Update the Application in the store k.SetApplication(ctx, app) - logger.Info("Successfully updated application stake for app: %+v", app) + logger.Info(fmt.Sprintf("Successfully updated application stake for app: %+v", app)) return &types.MsgStakeApplicationResponse{}, nil } diff --git a/x/application/keeper/msg_server_undelegate_from_gateway.go b/x/application/keeper/msg_server_undelegate_from_gateway.go index 7c38d5725..2ebc30416 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,20 +17,20 @@ func (k msgServer) UndelegateFromGateway( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "UndelegateFromGateway") - logger.Info("About to undelegate application from gateway with msg: %v", msg) + logger.Info(fmt.Sprintf("About to undelegate application from gateway with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { - logger.Error("Undelegation Message failed basic validation: %v", err) + logger.Error(fmt.Sprintf("Undelegation Message failed basic validation: %v", err)) return nil, err } // Retrieve the application from the store app, found := k.GetApplication(ctx, msg.AppAddress) if !found { - logger.Info("Application not found with address [%s]", msg.AppAddress) + logger.Info(fmt.Sprintf("Application not found with address [%s]", msg.AppAddress)) return nil, sdkerrors.Wrapf(types.ErrAppNotFound, "application not found with address: %s", msg.AppAddress) } - logger.Info("Application found with address [%s]", msg.AppAddress) + logger.Info(fmt.Sprintf("Application found with address [%s]", msg.AppAddress)) // Check if the application is already delegated to the gateway foundIdx := -1 @@ -39,7 +40,7 @@ func (k msgServer) UndelegateFromGateway( } } if foundIdx == -1 { - logger.Info("Application not delegated to gateway with address [%s]", msg.GatewayAddress) + logger.Info(fmt.Sprintf("Application not delegated to gateway with address [%s]", msg.GatewayAddress)) return nil, sdkerrors.Wrapf(types.ErrAppNotDelegated, "application not delegated to gateway with address: %s", msg.GatewayAddress) } @@ -48,11 +49,11 @@ func (k msgServer) UndelegateFromGateway( // Update the application store with the new delegation k.SetApplication(ctx, app) - logger.Info("Successfully undelegated application from gateway for app: %+v", app) + logger.Info(fmt.Sprintf("Successfully undelegated application from gateway for app: %+v", app)) // Emit the application redelegation event if err := ctx.EventManager().EmitTypedEvent(msg.NewRedelegationEvent()); err != nil { - logger.Error("Failed to emit application redelegation event: %v", err) + logger.Error(fmt.Sprintf("Failed to emit application redelegation event: %v", err)) return nil, err } diff --git a/x/application/keeper/msg_server_undelegate_from_gateway_test.go b/x/application/keeper/msg_server_undelegate_from_gateway_test.go index 0dfa63546..63dba4f31 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway_test.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway_test.go @@ -59,10 +59,12 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) { } events := ctx.EventManager().Events() require.Equal(t, int(maxDelegatedGateways), len(events)) - for _, event := range events { + for i, event := range events { require.Equal(t, "pocket.application.EventRedelegation", event.Type) require.Equal(t, "app_address", event.Attributes[0].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), event.Attributes[0].Value) + require.Equal(t, "gateway_address", event.Attributes[1].Key) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddresses[i]), event.Attributes[1].Value) } // Verify that the application exists @@ -88,6 +90,10 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) { require.Equal(t, "pocket.application.EventRedelegation", events[7].Type) require.Equal(t, "app_address", events[7].Attributes[0].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[7].Attributes[0].Value) + require.Equal(t, "gateway_address", events[7].Attributes[1].Key) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddresses[3]), events[7].Attributes[1].Value) + + // Verify that the application exists foundApp, isAppFound = k.GetApplication(ctx, appAddr) require.True(t, isAppFound) require.Equal(t, appAddr, foundApp.Address) @@ -158,6 +164,8 @@ func TestMsgServer_UndelegateFromGateway_FailNotDelegated(t *testing.T) { require.Equal(t, "pocket.application.EventRedelegation", events[0].Type) require.Equal(t, "app_address", events[0].Attributes[0].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[0].Attributes[0].Value) + require.Equal(t, "gateway_address", events[0].Attributes[1].Key) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddr2), events[0].Attributes[1].Value) // Ensure the failed undelegation did not affect the application _, err = srv.UndelegateFromGateway(wctx, undelegateMsg) @@ -211,6 +219,8 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegateFromUnstakedGatew require.Equal(t, "pocket.application.EventRedelegation", events[0].Type) require.Equal(t, "app_address", events[0].Attributes[0].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[0].Attributes[0].Value) + require.Equal(t, "gateway_address", events[0].Attributes[1].Key) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddr), events[0].Attributes[1].Value) // Verify that the application exists foundApp, isAppFound := k.GetApplication(ctx, appAddr) @@ -236,6 +246,10 @@ func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegateFromUnstakedGatew require.Equal(t, "pocket.application.EventRedelegation", events[1].Type) require.Equal(t, "app_address", events[1].Attributes[0].Key) require.Equal(t, fmt.Sprintf("\"%s\"", appAddr), events[1].Attributes[0].Value) + require.Equal(t, "gateway_address", events[0].Attributes[1].Key) + require.Equal(t, fmt.Sprintf("\"%s\"", gatewayAddr), events[0].Attributes[1].Value) + + // Verify that the application exists foundApp, isAppFound = k.GetApplication(ctx, appAddr) require.True(t, isAppFound) require.Equal(t, appAddr, foundApp.Address) diff --git a/x/application/keeper/msg_server_unstake_application.go b/x/application/keeper/msg_server_unstake_application.go index 8f062487b..d6f582aaa 100644 --- a/x/application/keeper/msg_server_unstake_application.go +++ b/x/application/keeper/msg_server_unstake_application.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,34 +17,34 @@ func (k msgServer) UnstakeApplication( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "UnstakeApplication") - logger.Info("About to unstake application with msg: %v", msg) + logger.Info(fmt.Sprintf("About to unstake application with msg: %v", msg)) // Check if the application already exists or not var err error app, isAppFound := k.GetApplication(ctx, msg.Address) if !isAppFound { - logger.Info("Application not found. Cannot unstake address %s", msg.Address) + logger.Info(fmt.Sprintf("Application not found. Cannot unstake address %s", msg.Address)) return nil, types.ErrAppNotFound } - logger.Info("Application found. Unstaking application for address %s", msg.Address) + logger.Info(fmt.Sprintf("Application found. Unstaking application for address %s", msg.Address)) // Retrieve the address of the application appAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error("could not parse address %s", msg.Address) + logger.Error(fmt.Sprintf("could not parse address %s", msg.Address)) return nil, err } // Send the coins from the application pool back to the application err = k.bankKeeper.UndelegateCoinsFromModuleToAccount(ctx, types.ModuleName, appAddress, []sdk.Coin{*app.Stake}) if err != nil { - logger.Error("could not send %v coins from %s module to %s account due to %v", app.Stake, appAddress, types.ModuleName, err) + logger.Error(fmt.Sprintf("could not send %v coins from %s module to %s account due to %v", app.Stake, appAddress, types.ModuleName, err)) return nil, err } // Update the Application in the store k.RemoveApplication(ctx, appAddress.String()) - logger.Info("Successfully removed the application: %+v", app) + logger.Info(fmt.Sprintf("Successfully removed the application: %+v", app)) return &types.MsgUnstakeApplicationResponse{}, nil } diff --git a/x/gateway/keeper/msg_server_stake_gateway.go b/x/gateway/keeper/msg_server_stake_gateway.go index 919e0f4dd..f5f6e63e2 100644 --- a/x/gateway/keeper/msg_server_stake_gateway.go +++ b/x/gateway/keeper/msg_server_stake_gateway.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +17,7 @@ func (k msgServer) StakeGateway( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "StakeGateway") - logger.Info("About to stake gateway with msg: %v", msg) + logger.Info(fmt.Sprintf("About to stake gateway with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { return nil, err @@ -27,11 +28,11 @@ func (k msgServer) StakeGateway( var coinsToDelegate sdk.Coin gateway, isGatewayFound := k.GetGateway(ctx, msg.Address) if !isGatewayFound { - logger.Info("Gateway not found. Creating new gateway for address %s", msg.Address) + logger.Info(fmt.Sprintf("Gateway not found. Creating new gateway for address %s", msg.Address)) gateway = k.createGateway(ctx, msg) coinsToDelegate = *msg.Stake } else { - logger.Info("Gateway found. Updating gateway stake for address %s", msg.Address) + logger.Info(fmt.Sprintf("Gateway found. Updating gateway stake for address %s", msg.Address)) currGatewayStake := *gateway.Stake if err = k.updateGateway(ctx, &gateway, msg); err != nil { return nil, err @@ -42,20 +43,20 @@ func (k msgServer) StakeGateway( // Retrieve the address of the gateway gatewayAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error("could not parse address %s", msg.Address) + logger.Error(fmt.Sprintf("could not parse address %s", msg.Address)) return nil, err } // Send the coins from the gateway to the staked gateway pool err = k.bankKeeper.DelegateCoinsFromAccountToModule(ctx, gatewayAddress, types.ModuleName, []sdk.Coin{coinsToDelegate}) if err != nil { - logger.Error("could not send %v coins from %s to %s module account due to %v", coinsToDelegate, gatewayAddress, types.ModuleName, err) + logger.Error(fmt.Sprintf("could not send %v coins from %s to %s module account due to %v", coinsToDelegate, gatewayAddress, types.ModuleName, err)) return nil, err } // Update the Gateway in the store k.SetGateway(ctx, gateway) - logger.Info("Successfully updated stake for gateway: %+v", gateway) + logger.Info(fmt.Sprintf("Successfully updated stake for gateway: %+v", gateway)) return &types.MsgStakeGatewayResponse{}, nil } diff --git a/x/gateway/keeper/msg_server_unstake_gateway.go b/x/gateway/keeper/msg_server_unstake_gateway.go index 16c913693..3521d1bac 100644 --- a/x/gateway/keeper/msg_server_unstake_gateway.go +++ b/x/gateway/keeper/msg_server_unstake_gateway.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,7 +18,7 @@ func (k msgServer) UnstakeGateway( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "UnstakeGateway") - logger.Info("About to unstake gateway with msg: %v", msg) + logger.Info(fmt.Sprintf("About to unstake gateway with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { return nil, err @@ -27,27 +28,27 @@ func (k msgServer) UnstakeGateway( var err error gateway, isGatewayFound := k.GetGateway(ctx, msg.Address) if !isGatewayFound { - logger.Info("Gateway not found. Cannot unstake address %s", msg.Address) + logger.Info(fmt.Sprintf("Gateway not found. Cannot unstake address %s", msg.Address)) return nil, types.ErrGatewayNotFound } - logger.Info("Gateway found. Unstaking gateway for address %s", msg.Address) + logger.Info(fmt.Sprintf("Gateway found. Unstaking gateway for address %s", msg.Address)) // Retrieve the address of the gateway gatewayAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error("could not parse address %s", msg.Address) + logger.Error(fmt.Sprintf("could not parse address %s", msg.Address)) return nil, err } // Send the coins from the gateway pool back to the gateway err = k.bankKeeper.UndelegateCoinsFromModuleToAccount(ctx, types.ModuleName, gatewayAddress, []sdk.Coin{*gateway.Stake}) if err != nil { - logger.Error("could not send %v coins from %s module to %s account due to %v", gateway.Stake, gatewayAddress, types.ModuleName, err) + logger.Error(fmt.Sprintf("could not send %v coins from %s module to %s account due to %v", gateway.Stake, gatewayAddress, types.ModuleName, err)) return nil, err } // Update the Gateway in the store k.RemoveGateway(ctx, gatewayAddress.String()) - logger.Info("Successfully removed the gateway: %+v", gateway) + logger.Info(fmt.Sprintf("Successfully removed the gateway: %+v", gateway)) return &types.MsgUnstakeGatewayResponse{}, nil } diff --git a/x/session/keeper/session_hydrator.go b/x/session/keeper/session_hydrator.go index 5035b192f..6e56810a4 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -69,7 +69,7 @@ func (k Keeper) HydrateSession(ctx sdk.Context, sh *sessionHydrator) (*types.Ses if err := k.hydrateSessionID(ctx, sh); err != nil { return nil, sdkerrors.Wrapf(types.ErrSessionHydration, "failed to hydrate the session ID: %v", err) } - logger.Info("Finished hydrating session ID: %s", sh.sessionHeader.SessionId) + logger.Info(fmt.Sprintf("Finished hydrating session ID: %s", sh.sessionHeader.SessionId)) if err := k.hydrateSessionApplication(ctx, sh); err != nil { return nil, sdkerrors.Wrapf(types.ErrSessionHydration, "failed to hydrate application for session: %v", err) @@ -171,12 +171,12 @@ func (k Keeper) hydrateSessionSuppliers(ctx sdk.Context, sh *sessionHydrator) er } if len(candidateSuppliers) == 0 { - logger.Error("[ERROR] no suppliers found for session") + logger.Error(fmt.Sprintf("[ERROR] no suppliers found for session")) return sdkerrors.Wrapf(types.ErrSessionSuppliersNotFound, "could not find suppliers for service %s at height %d", sh.sessionHeader.Service, sh.sessionHeader.SessionStartBlockHeight) } if len(candidateSuppliers) < NumSupplierPerSession { - logger.Info("[WARN] number of available suppliers (%d) is less than the number of suppliers per session (%d)", len(candidateSuppliers), NumSupplierPerSession) + logger.Info(fmt.Sprintf("[WARN] number of available suppliers (%d) is less than the number of suppliers per session (%d)", len(candidateSuppliers), NumSupplierPerSession)) sh.session.Suppliers = candidateSuppliers } else { sh.session.Suppliers = pseudoRandomSelection(candidateSuppliers, NumSupplierPerSession, sh.sessionIdBz) diff --git a/x/supplier/keeper/claim.go b/x/supplier/keeper/claim.go index 511d8f7da..e635a95d6 100644 --- a/x/supplier/keeper/claim.go +++ b/x/supplier/keeper/claim.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/binary" + "fmt" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -21,21 +22,21 @@ func (k Keeper) InsertClaim(ctx sdk.Context, claim types.Claim) { primaryKey := types.ClaimPrimaryKey(claim.SessionId, claim.SupplierAddress) primaryStore.Set(primaryKey, claimBz) - logger.Info("inserted claim for supplier %s with primaryKey %s", claim.SupplierAddress, primaryKey) + logger.Info(fmt.Sprintf("inserted claim for supplier %s with primaryKey %s", claim.SupplierAddress, primaryKey)) // Update the address index: supplierAddress -> [ClaimPrimaryKey] addressStoreIndex := prefix.NewStore(parentStore, types.KeyPrefix(types.ClaimSupplierAddressPrefix)) addressKey := types.ClaimSupplierAddressKey(claim.SupplierAddress, primaryKey) addressStoreIndex.Set(addressKey, primaryKey) - logger.Info("indexed claim for supplier %s with primaryKey %s", claim.SupplierAddress, primaryKey) + logger.Info(fmt.Sprintf("indexed claim for supplier %s with primaryKey %s", claim.SupplierAddress, primaryKey)) // Update the session end height index: sessionEndHeight -> [ClaimPrimaryKey] sessionHeightStoreIndex := prefix.NewStore(parentStore, types.KeyPrefix(types.ClaimSessionEndHeightPrefix)) heightKey := types.ClaimSupplierEndSessionHeightKey(claim.SessionEndBlockHeight, primaryKey) sessionHeightStoreIndex.Set(heightKey, primaryKey) - logger.Info("indexed claim for supplier %s at session ending height %d", claim.SupplierAddress, claim.SessionEndBlockHeight) + logger.Info(fmt.Sprintf("indexed claim for supplier %s at session ending height %d", claim.SupplierAddress, claim.SessionEndBlockHeight)) } // RemoveClaim removes a claim from the store @@ -49,7 +50,7 @@ func (k Keeper) RemoveClaim(ctx sdk.Context, sessionId, supplierAddr string) { primaryKey := types.ClaimPrimaryKey(sessionId, supplierAddr) claim, foundClaim := k.getClaimByPrimaryKey(ctx, primaryKey) if !foundClaim { - logger.Error("trying to delete non-existent claim with primary key %s for supplier %s and session %s", primaryKey, supplierAddr, sessionId) + logger.Error(fmt.Sprintf("trying to delete non-existent claim with primary key %s for supplier %s and session %s", primaryKey, supplierAddr, sessionId)) return } @@ -65,7 +66,7 @@ func (k Keeper) RemoveClaim(ctx sdk.Context, sessionId, supplierAddr string) { addressStoreIndex.Delete(addressKey) sessionHeightStoreIndex.Delete(heightKey) - logger.Info("deleted claim with primary key %s for supplier %s and session %s", primaryKey, supplierAddr, sessionId) + logger.Info(fmt.Sprintf("deleted claim with primary key %s for supplier %s and session %s", primaryKey, supplierAddr, sessionId)) } // GetClaim returns a Claim given a SessionId & SupplierAddr diff --git a/x/supplier/keeper/msg_server_stake_supplier.go b/x/supplier/keeper/msg_server_stake_supplier.go index 5fea47135..edd8ecee8 100644 --- a/x/supplier/keeper/msg_server_stake_supplier.go +++ b/x/supplier/keeper/msg_server_stake_supplier.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,10 +18,10 @@ func (k msgServer) StakeSupplier( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "StakeSupplier") - logger.Info("About to stake supplier with msg: %v", msg) + logger.Info(fmt.Sprintf("About to stake supplier with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { - logger.Error("invalid MsgStakeSupplier: %v", msg) + logger.Error(fmt.Sprintf("invalid MsgStakeSupplier: %v", msg)) return nil, err } @@ -29,11 +30,11 @@ func (k msgServer) StakeSupplier( var coinsToDelegate sdk.Coin supplier, isSupplierFound := k.GetSupplier(ctx, msg.Address) if !isSupplierFound { - logger.Info("Supplier not found. Creating new supplier for address %s", msg.Address) + logger.Info(fmt.Sprintf("Supplier not found. Creating new supplier for address %s", msg.Address)) supplier = k.createSupplier(ctx, msg) coinsToDelegate = *msg.Stake } else { - logger.Info("Supplier found. Updating supplier for address %s", msg.Address) + logger.Info(fmt.Sprintf("Supplier found. Updating supplier for address %s", msg.Address)) currSupplierStake := *supplier.Stake if err = k.updateSupplier(ctx, &supplier, msg); err != nil { return nil, err @@ -44,7 +45,7 @@ func (k msgServer) StakeSupplier( // Retrieve the address of the supplier supplierAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error("could not parse address %s", msg.Address) + logger.Error(fmt.Sprintf("could not parse address %s", msg.Address)) return nil, err } @@ -52,13 +53,13 @@ func (k msgServer) StakeSupplier( // Send the coins from the supplier to the staked supplier pool err = k.bankKeeper.DelegateCoinsFromAccountToModule(ctx, supplierAddress, types.ModuleName, []sdk.Coin{coinsToDelegate}) if err != nil { - logger.Error("could not send %v coins from %s to %s module account due to %v", coinsToDelegate, supplierAddress, types.ModuleName, err) + logger.Error(fmt.Sprintf("could not send %v coins from %s to %s module account due to %v", coinsToDelegate, supplierAddress, types.ModuleName, err)) return nil, err } // Update the Supplier in the store k.SetSupplier(ctx, supplier) - logger.Info("Successfully updated supplier stake for supplier: %+v", supplier) + logger.Info(fmt.Sprintf("Successfully updated supplier stake for supplier: %+v", supplier)) return &types.MsgStakeSupplierResponse{}, nil } diff --git a/x/supplier/keeper/msg_server_unstake_supplier.go b/x/supplier/keeper/msg_server_unstake_supplier.go index 830a4c37a..79f86db3f 100644 --- a/x/supplier/keeper/msg_server_unstake_supplier.go +++ b/x/supplier/keeper/msg_server_unstake_supplier.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,7 +17,7 @@ func (k msgServer) UnstakeSupplier( ctx := sdk.UnwrapSDKContext(goCtx) logger := k.Logger(ctx).With("method", "UnstakeSupplier") - logger.Info("About to unstake supplier with msg: %v", msg) + logger.Info(fmt.Sprintf("About to unstake supplier with msg: %v", msg)) if err := msg.ValidateBasic(); err != nil { return nil, err @@ -25,27 +26,27 @@ func (k msgServer) UnstakeSupplier( // Check if the supplier already exists or not supplier, isSupplierFound := k.GetSupplier(ctx, msg.Address) if !isSupplierFound { - logger.Info("Supplier not found. Cannot unstake address %s", msg.Address) + logger.Info(fmt.Sprintf("Supplier not found. Cannot unstake address %s", msg.Address)) return nil, types.ErrSupplierNotFound } - logger.Info("Supplier found. Unstaking supplier for address %s", msg.Address) + logger.Info(fmt.Sprintf("Supplier found. Unstaking supplier for address %s", msg.Address)) // Retrieve the address of the supplier supplierAddress, err := sdk.AccAddressFromBech32(msg.Address) if err != nil { - logger.Error("could not parse address %s", msg.Address) + logger.Error(fmt.Sprintf("could not parse address %s", msg.Address)) return nil, err } // Send the coins from the supplier pool back to the supplier err = k.bankKeeper.UndelegateCoinsFromModuleToAccount(ctx, types.ModuleName, supplierAddress, []sdk.Coin{*supplier.Stake}) if err != nil { - logger.Error("could not send %v coins from %s module to %s account due to %v", supplier.Stake, supplierAddress, types.ModuleName, err) + logger.Error(fmt.Sprintf("could not send %v coins from %s module to %s account due to %v", supplier.Stake, supplierAddress, types.ModuleName, err)) return nil, err } // Update the Supplier in the store k.RemoveSupplier(ctx, supplierAddress.String()) - logger.Info("Successfully removed the supplier: %+v", supplier) + logger.Info(fmt.Sprintf("Successfully removed the supplier: %+v", supplier)) return &types.MsgUnstakeSupplierResponse{}, nil } diff --git a/x/tokenomics/genesis.go b/x/tokenomics/genesis.go index 33aba20b3..6197d5960 100644 --- a/x/tokenomics/genesis.go +++ b/x/tokenomics/genesis.go @@ -2,6 +2,7 @@ package tokenomics import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/tokenomics/keeper" "github.com/pokt-network/poktroll/x/tokenomics/types" ) diff --git a/x/tokenomics/keeper/params.go b/x/tokenomics/keeper/params.go index e6c5423f7..b3d0075f7 100644 --- a/x/tokenomics/keeper/params.go +++ b/x/tokenomics/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/tokenomics/types" ) diff --git a/x/tokenomics/keeper/query_params.go b/x/tokenomics/keeper/query_params.go index 2d380efca..f8a4d0dc4 100644 --- a/x/tokenomics/keeper/query_params.go +++ b/x/tokenomics/keeper/query_params.go @@ -4,9 +4,10 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/tokenomics/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/pokt-network/poktroll/x/tokenomics/types" ) func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { diff --git a/x/tokenomics/module.go b/x/tokenomics/module.go index 159d42526..e88612416 100644 --- a/x/tokenomics/module.go +++ b/x/tokenomics/module.go @@ -14,10 +14,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + "github.com/pokt-network/poktroll/x/tokenomics/client/cli" "github.com/pokt-network/poktroll/x/tokenomics/keeper" "github.com/pokt-network/poktroll/x/tokenomics/types" - "github.com/spf13/cobra" ) var ( diff --git a/x/tokenomics/module_simulation.go b/x/tokenomics/module_simulation.go index 9076699f1..6251a26e0 100644 --- a/x/tokenomics/module_simulation.go +++ b/x/tokenomics/module_simulation.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/pokt-network/poktroll/testutil/sample" tokenomicssimulation "github.com/pokt-network/poktroll/x/tokenomics/simulation" "github.com/pokt-network/poktroll/x/tokenomics/types"