From 913344af9e34f5ee55d94e2a22932dc897790c88 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sat, 9 Dec 2023 20:38:39 -0800 Subject: [PATCH 01/19] Quick fixes for E2E tests --- Tiltfile | 1 + e2e/tests/relay.feature | 1 + go.mod | 4 ++-- localnet/kubernetes/values-appgateserver.yaml | 2 +- localnet/kubernetes/values-relayminer.yaml | 5 ++--- testutil/testclient/localnet.go | 9 ++++----- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Tiltfile b/Tiltfile index b7093223a..8cc6066c8 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) diff --git a/e2e/tests/relay.feature b/e2e/tests/relay.feature index 484172092..1bf624552 100644 --- a/e2e/tests/relay.feature +++ b/e2e/tests/relay.feature @@ -1,5 +1,6 @@ Feature: Relay Namespace + # TODO_TECHDEBT(@Olshansk, #180): This test requires you to run `make supplier1_stake && make app1_stake` first 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/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-appgateserver.yaml b/localnet/kubernetes/values-appgateserver.yaml index 80357e815..51c193a01 100644 --- a/localnet/kubernetes/values-appgateserver.yaml +++ b/localnet/kubernetes/values-appgateserver.yaml @@ -1,2 +1,2 @@ config: - query_node_url: tcp://sequencer-poktroll-sequencer:36657 + query_node_url: tcp://localhost:36657 diff --git a/localnet/kubernetes/values-relayminer.yaml b/localnet/kubernetes/values-relayminer.yaml index 573d05bcb..a6cc144d5 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 + query_node_url: tcp://localhost:36657 + network_node_url: tcp://localhost:36657 diff --git a/testutil/testclient/localnet.go b/testutil/testclient/localnet.go index c0374a7ba..97b07201d 100644 --- a/testutil/testclient/localnet.go +++ b/testutil/testclient/localnet.go @@ -4,12 +4,11 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/pokt-network/poktroll/app" + "github.com/pokt-network/poktroll/cmd/pocketd/cmd" "github.com/regen-network/gocuke" "github.com/spf13/pflag" "github.com/stretchr/testify/require" - - "github.com/pokt-network/poktroll/app" - "github.com/pokt-network/poktroll/cmd/pocketd/cmd" ) const ( @@ -17,13 +16,13 @@ const ( // // 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. From 2fcc88107f5c728c955a98875688f5188afe9d04 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sat, 9 Dec 2023 20:56:26 -0800 Subject: [PATCH 02/19] Adding some comment out code --- e2e/tests/session_steps_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/e2e/tests/session_steps_test.go b/e2e/tests/session_steps_test.go index 0d9b9736f..e611f2b6f 100644 --- a/e2e/tests/session_steps_test.go +++ b/e2e/tests/session_steps_test.go @@ -11,14 +11,13 @@ 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 ( @@ -58,6 +57,10 @@ func (s *suite) AfterTheSupplierCreatesAClaimForTheSessionForServiceForApplicati for _, event := range txEvent.Result.Events { for _, attribute := range event.Attributes { if attribute.Key == "action" { + // if attribute.Value == "/pocket.supplier.MsgSubmitProof" { + // continue + // } + require.Equal( s, "/pocket.supplier.MsgCreateClaim", attribute.Value, From 27d9c3a554cef1cd45e956cb2d1d01ba968b2f0e Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 12:47:18 -0800 Subject: [PATCH 03/19] Clean up some unit tests per #220 --- pkg/client/block/block.go | 9 +++-- pkg/client/interface.go | 5 +-- .../msg_server_delegate_to_gateway_test.go | 39 ++++++++++++------- ...msg_server_undelegate_from_gateway_test.go | 19 +++++++-- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/pkg/client/block/block.go b/pkg/client/block/block.go index bbc61e365..e6868cf78 100644 --- a/pkg/client/block/block.go +++ b/pkg/client/block/block.go @@ -4,7 +4,6 @@ import ( "encoding/json" "github.com/cometbft/cometbft/types" - "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" ) @@ -27,9 +26,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 +37,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/interface.go b/pkg/client/interface.go index 320914246..4790cfed9 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -21,13 +21,12 @@ import ( cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" cosmostypes "github.com/cosmos/cosmos-sdk/types" accounttypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/pokt-network/smt" - "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable" apptypes "github.com/pokt-network/poktroll/x/application/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + "github.com/pokt-network/smt" ) // SupplierClient is an interface for sufficient for a supplier operator to be @@ -111,7 +110,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/x/application/keeper/msg_server_delegate_to_gateway_test.go b/x/application/keeper/msg_server_delegate_to_gateway_test.go index 1e293aa04..654f41282 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway_test.go +++ b/x/application/keeper/msg_server_delegate_to_gateway_test.go @@ -5,13 +5,12 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + "github.com/stretchr/testify/require" ) func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { @@ -57,7 +56,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 +80,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 +133,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 +206,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 +226,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 +247,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_undelegate_from_gateway_test.go b/x/application/keeper/msg_server_undelegate_from_gateway_test.go index 0dfa63546..e261b8831 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway_test.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway_test.go @@ -5,13 +5,12 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + "github.com/stretchr/testify/require" ) func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) { @@ -59,10 +58,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 +89,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 +163,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 +218,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 +245,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) From 90d75bdadf97f78fb771bbccbc4d8ce885f700dc Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 13:08:14 -0800 Subject: [PATCH 04/19] Fixed logs under x/ Did a replace of this: logger\.(Info|Error)\("([^"]+)"(?:, (.*))?\) With: logger.$1(fmt.Sprintf("$2", $3)) --- .../keeper/msg_server_delegate_to_gateway.go | 22 +++++++++---------- .../keeper/msg_server_stake_application.go | 16 +++++++------- .../msg_server_undelegate_from_gateway.go | 16 +++++++------- .../keeper/msg_server_unstake_application.go | 14 ++++++------ x/gateway/keeper/msg_server_stake_gateway.go | 14 ++++++------ .../keeper/msg_server_unstake_gateway.go | 14 ++++++------ x/session/keeper/session_hydrator.go | 9 ++++---- x/supplier/keeper/claim.go | 12 +++++----- .../keeper/msg_server_stake_supplier.go | 16 +++++++------- .../keeper/msg_server_unstake_supplier.go | 14 ++++++------ 10 files changed, 73 insertions(+), 74 deletions(-) diff --git a/x/application/keeper/msg_server_delegate_to_gateway.go b/x/application/keeper/msg_server_delegate_to_gateway.go index f46275545..8b0a40d52 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway.go +++ b/x/application/keeper/msg_server_delegate_to_gateway.go @@ -2,10 +2,10 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/application/types" ) @@ -13,53 +13,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_stake_application.go b/x/application/keeper/msg_server_stake_application.go index cc735919b..2b6b0944b 100644 --- a/x/application/keeper/msg_server_stake_application.go +++ b/x/application/keeper/msg_server_stake_application.go @@ -2,10 +2,10 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/application/types" ) @@ -16,10 +16,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 +28,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 +43,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 +51,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..3e8a6645e 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway.go @@ -2,10 +2,10 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/application/types" ) @@ -16,20 +16,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 +39,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 +48,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_unstake_application.go b/x/application/keeper/msg_server_unstake_application.go index 8f062487b..2e3fa90da 100644 --- a/x/application/keeper/msg_server_unstake_application.go +++ b/x/application/keeper/msg_server_unstake_application.go @@ -2,9 +2,9 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/application/types" ) @@ -16,34 +16,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..d46579284 100644 --- a/x/gateway/keeper/msg_server_stake_gateway.go +++ b/x/gateway/keeper/msg_server_stake_gateway.go @@ -2,10 +2,10 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/gateway/types" ) @@ -16,7 +16,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 +27,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 +42,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..2817dd239 100644 --- a/x/gateway/keeper/msg_server_unstake_gateway.go +++ b/x/gateway/keeper/msg_server_unstake_gateway.go @@ -2,9 +2,9 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/gateway/types" ) @@ -17,7 +17,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 +27,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..9d0e80971 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -9,11 +9,10 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - _ "golang.org/x/crypto/sha3" - "github.com/pokt-network/poktroll/x/session/types" sharedhelpers "github.com/pokt-network/poktroll/x/shared/helpers" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + _ "golang.org/x/crypto/sha3" ) var SHA3HashLen = crypto.SHA3_256.Size() @@ -69,7 +68,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 +170,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..189676499 100644 --- a/x/supplier/keeper/claim.go +++ b/x/supplier/keeper/claim.go @@ -2,10 +2,10 @@ package keeper import ( "encoding/binary" + "fmt" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -21,21 +21,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 +49,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 +65,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..8a6233ff2 100644 --- a/x/supplier/keeper/msg_server_stake_supplier.go +++ b/x/supplier/keeper/msg_server_stake_supplier.go @@ -2,10 +2,10 @@ package keeper import ( "context" + "fmt" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -17,10 +17,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 +29,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 +44,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 +52,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..26349c111 100644 --- a/x/supplier/keeper/msg_server_unstake_supplier.go +++ b/x/supplier/keeper/msg_server_unstake_supplier.go @@ -2,9 +2,9 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -16,7 +16,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 +25,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 } From 9181c56ecd955145a0dbad58fd98897af0ca9059 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 13:41:21 -0800 Subject: [PATCH 05/19] Reverted the hosts in localnet so a new cluster can spin up again --- localnet/kubernetes/values-appgateserver.yaml | 2 +- localnet/kubernetes/values-relayminer.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/localnet/kubernetes/values-appgateserver.yaml b/localnet/kubernetes/values-appgateserver.yaml index 51c193a01..80357e815 100644 --- a/localnet/kubernetes/values-appgateserver.yaml +++ b/localnet/kubernetes/values-appgateserver.yaml @@ -1,2 +1,2 @@ config: - query_node_url: tcp://localhost:36657 + query_node_url: tcp://sequencer-poktroll-sequencer:36657 diff --git a/localnet/kubernetes/values-relayminer.yaml b/localnet/kubernetes/values-relayminer.yaml index a6cc144d5..0fcd2b27c 100644 --- a/localnet/kubernetes/values-relayminer.yaml +++ b/localnet/kubernetes/values-relayminer.yaml @@ -1,3 +1,3 @@ config: - query_node_url: tcp://localhost:36657 - network_node_url: tcp://localhost:36657 + query_node_url: tcp://sequencer-poktroll-sequencer:36657 + network_node_url: tcp://sequencer-poktroll-sequencer:36657 From d1659d6fdf0d2fab1d033bb409bbbf3b8a6bea19 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 14:53:07 -0800 Subject: [PATCH 06/19] E2E tests work --- e2e/tests/session_steps_test.go | 22 +++++++++++----------- pkg/client/block/client.go | 7 +++---- pkg/client/delegation/client.go | 7 +++---- pkg/client/supplier/client.go | 27 +++++++++++++++++++++++---- x/supplier/client/cli/helpers_test.go | 3 +-- 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/e2e/tests/session_steps_test.go b/e2e/tests/session_steps_test.go index e611f2b6f..96248e243 100644 --- a/e2e/tests/session_steps_test.go +++ b/e2e/tests/session_steps_test.go @@ -23,7 +23,7 @@ import ( 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" @@ -57,10 +57,6 @@ func (s *suite) AfterTheSupplierCreatesAClaimForTheSessionForServiceForApplicati for _, event := range txEvent.Result.Events { for _, attribute := range event.Attributes { if attribute.Key == "action" { - // if attribute.Value == "/pocket.supplier.MsgSubmitProof" { - // continue - // } - require.Equal( s, "/pocket.supplier.MsgCreateClaim", attribute.Value, @@ -89,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 @@ -109,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) } @@ -121,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/pkg/client/block/client.go b/pkg/client/block/client.go index 1103a4b66..177a620c1 100644 --- a/pkg/client/block/client.go +++ b/pkg/client/block/client.go @@ -4,7 +4,6 @@ import ( "context" "cosmossdk.io/depinject" - "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" ) @@ -15,11 +14,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..8237075b9 100644 --- a/pkg/client/delegation/client.go +++ b/pkg/client/delegation/client.go @@ -4,7 +4,6 @@ import ( "context" "cosmossdk.io/depinject" - "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" ) @@ -15,11 +14,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 `blocksReplayLimit` field to the blockClient + // struct that defaults to this but can be overridden via an option. defaultRedelegationsReplayLimit = 100 ) diff --git a/pkg/client/supplier/client.go b/pkg/client/supplier/client.go index a0172c3c5..b4a7d0cc0 100644 --- a/pkg/client/supplier/client.go +++ b/pkg/client/supplier/client.go @@ -5,12 +5,12 @@ import ( "cosmossdk.io/depinject" cosmostypes "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/smt" - "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" + "github.com/pokt-network/smt" ) var _ client.SupplierClient = (*supplierClient)(nil) @@ -66,6 +66,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 +84,14 @@ func (sClient *supplierClient) SubmitProof( return err } + // TODO_IMPROVE: log details related to what & how much is being proven + logger.Info(). + Str("supplier_addr", sClient.signingKeyAddr.String()). + Str("app_addr", sessionHeader.ApplicationAddress). + Str("session_id", sessionHeader.SessionId). + Str("service", sessionHeader.Service.Id). + Msg("created a new proof") + return <-errCh } @@ -93,6 +103,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 +116,15 @@ func (sClient *supplierClient) CreateClaim( return err } - err = <-errCh - return err + // TODO_IMPROVE: log details related to how much is claimed + logger.Info(). + Str("supplier_addr", sClient.signingKeyAddr.String()). + Str("app_addr", sessionHeader.ApplicationAddress). + Str("session_id", sessionHeader.SessionId). + Str("service", sessionHeader.Service.Id). + Msg("created a new claim") + + return <-errCh } // validateConfigAndSetDefaults attempts to get the address from the keyring diff --git a/x/supplier/client/cli/helpers_test.go b/x/supplier/client/cli/helpers_test.go index 9c8089868..dbd89c3a7 100644 --- a/x/supplier/client/cli/helpers_test.go +++ b/x/supplier/client/cli/helpers_test.go @@ -17,8 +17,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" testcli "github.com/cosmos/cosmos-sdk/testutil/cli" sdktypes "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/cmd/pocketd/cmd" "github.com/pokt-network/poktroll/testutil/network" "github.com/pokt-network/poktroll/testutil/testkeyring" @@ -27,6 +25,7 @@ import ( sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/client/cli" "github.com/pokt-network/poktroll/x/supplier/types" + "github.com/stretchr/testify/require" ) // TODO_TECHDEBT: This should not be hardcoded once the num blocks per session is configurable. From da65f829adbc2ce5c60cb85f690856da9f76181c Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 15:32:41 -0800 Subject: [PATCH 07/19] A few more minor comments --- .../events/replay_client_example_test.go | 3 +- testutil/network/network.go | 46 +++++++++++-------- testutil/testclient/testsupplier/client.go | 5 +- 3 files changed, 30 insertions(+), 24 deletions(-) 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/testutil/network/network.go b/testutil/network/network.go index 9ded9e609..82a30b4a0 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -20,8 +20,6 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/app" "github.com/pokt-network/poktroll/testutil/sample" appcli "github.com/pokt-network/poktroll/x/application/client/cli" @@ -29,6 +27,7 @@ import ( gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" + "github.com/stretchr/testify/require" ) type ( @@ -101,6 +100,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 +150,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 +206,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 +240,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/testsupplier/client.go b/testutil/testclient/testsupplier/client.go index 841cfc024..5139a87bc 100644 --- a/testutil/testclient/testsupplier/client.go +++ b/testutil/testclient/testsupplier/client.go @@ -6,15 +6,14 @@ import ( "cosmossdk.io/depinject" "github.com/golang/mock/gomock" - "github.com/pokt-network/smt" - "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/supplier" "github.com/pokt-network/poktroll/pkg/client/tx" "github.com/pokt-network/poktroll/testutil/mockclient" "github.com/pokt-network/poktroll/testutil/testclient/testtx" sessiontypes "github.com/pokt-network/poktroll/x/session/types" + "github.com/pokt-network/smt" + "github.com/stretchr/testify/require" ) // NewLocalnetClient creates and returns a new supplier client that connects to From ddbd4d0e2a92b2eabb2457bf5064b85a1164ef12 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 15:38:41 -0800 Subject: [PATCH 08/19] Empty commit From d2fe64e69e16714f7530db5c1406813c5beb044f Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 16:24:59 -0800 Subject: [PATCH 09/19] Fix unit tests and verify e2e tests again --- pkg/client/supplier/client_test.go | 24 ++++++++++++-------- pkg/relayer/relayminer_test.go | 3 +-- testutil/testclient/testtx/client.go | 12 +++++----- x/supplier/keeper/msg_server_submit_proof.go | 1 - 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/pkg/client/supplier/client_test.go b/pkg/client/supplier/client_test.go index 830426946..447abc9c2 100644 --- a/pkg/client/supplier/client_test.go +++ b/pkg/client/supplier/client_test.go @@ -8,16 +8,16 @@ 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/pkg/polylog/polyzero" + "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" @@ -76,7 +76,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) { var ( signAndBroadcastDelay = 50 * time.Millisecond doneCh = make(chan struct{}, 1) - ctx = context.Background() + ctx = polyzero.NewLogger().WithContext(context.Background()) ) keyring, testAppKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName) @@ -85,7 +85,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 +102,9 @@ func TestSupplierClient_CreateClaim(t *testing.T) { ApplicationAddress: testAppAddr.String(), SessionStartBlockHeight: 0, SessionId: "", + Service: &sharedtypes.Service{ + Id: "test_service", + }, } go func() { @@ -132,7 +135,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) { var ( signAndBroadcastDelay = 50 * time.Millisecond doneCh = make(chan struct{}, 1) - ctx = context.Background() + ctx = polyzero.NewLogger().WithContext(context.Background()) ) keyring, testAppKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName) @@ -141,7 +144,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 +160,9 @@ func TestSupplierClient_SubmitProof(t *testing.T) { ApplicationAddress: testAppAddr.String(), SessionStartBlockHeight: 0, SessionId: "", + Service: &sharedtypes.Service{ + Id: "test_service", + }, } kvStore, err := smt.NewKVStore("") diff --git a/pkg/relayer/relayminer_test.go b/pkg/relayer/relayminer_test.go index f7de39d39..d3b3afbe2 100644 --- a/pkg/relayer/relayminer_test.go +++ b/pkg/relayer/relayminer_test.go @@ -6,13 +6,12 @@ import ( "time" "cosmossdk.io/depinject" - "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/pkg/observable/channel" "github.com/pokt-network/poktroll/pkg/polylog/polyzero" "github.com/pokt-network/poktroll/pkg/relayer" "github.com/pokt-network/poktroll/testutil/testrelayer" servicetypes "github.com/pokt-network/poktroll/x/service/types" + "github.com/stretchr/testify/require" ) func TestRelayMiner_StartAndStop(t *testing.T) { diff --git a/testutil/testclient/testtx/client.go b/testutil/testclient/testtx/client.go index 496c99023..bff6b8ae6 100644 --- a/testutil/testclient/testtx/client.go +++ b/testutil/testclient/testtx/client.go @@ -8,15 +8,13 @@ import ( "cosmossdk.io/depinject" cosmostypes "github.com/cosmos/cosmos-sdk/types" "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" + "github.com/stretchr/testify/require" ) type signAndBroadcastFn func(context.Context, cosmostypes.Msg) either.AsyncError @@ -50,12 +48,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 +62,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 +71,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/supplier/keeper/msg_server_submit_proof.go b/x/supplier/keeper/msg_server_submit_proof.go index 2715b7c8d..39ecb427b 100644 --- a/x/supplier/keeper/msg_server_submit_proof.go +++ b/x/supplier/keeper/msg_server_submit_proof.go @@ -4,7 +4,6 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/supplier/types" ) From 8b235bc1e8659ec7bf4aa9092473c54ac94f0cf1 Mon Sep 17 00:00:00 2001 From: Dima Kniazev Date: Mon, 11 Dec 2023 19:12:39 -0800 Subject: [PATCH 10/19] [CI/E2E] e2e fixes for e2e fixes (#258) Add an ability to override an RPC endpoint for e2e tests, so they can run locally and remotely. --- .../run-e2e-test-job-template.yaml | 2 ++ e2e/tests/node.go | 6 ++--- testutil/testclient/localnet.go | 23 +++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) 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/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/testutil/testclient/localnet.go b/testutil/testclient/localnet.go index 97b07201d..e6fa181fb 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" @@ -11,26 +14,26 @@ import ( "github.com/stretchr/testify/require" ) -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://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://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 From b98591013f967e6966a954de91a92a2ada2f05da Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Sun, 10 Dec 2023 12:36:45 -0800 Subject: [PATCH 11/19] Update pull_request_template.md (#254) - Update some comments - Add instructions on E2E tests --- .github/pull_request_template.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 1599a1f49..00f0ce009 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,4 @@ - ### AI Summary reviewpad:summary ## Issue - - #{ISSUE_NUMBER} -[Explain the reasoning for the PR in 1-2 sentences. Consider adding a link or a screenshot.] - ## Type of change Select one or more: @@ -45,7 +44,8 @@ Select one or more: ## Testing - [ ] **Run all unit tests**: `make go_develop_and_test` -- [ ] **Verify Localnet manually**: See the instructions [here](TODO: add link to instructions) +- [ ] **Run E2E tests locally**: `make test_e2e` +- [ ] **Run E2E tests on DevNet`: Add the `devnet-test-e2e` label to the PR. This is VERY expensive, o only do it after all the reviews are complete. ## Sanity Checklist From 2c03b25f523de03c9b02cb3e54f0f1151dc02758 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Mon, 11 Dec 2023 13:17:44 -0800 Subject: [PATCH 12/19] [Logging] Enforce polylog usage after #219 for new logs added (#244) Add a reviewdog workflow to make sure we do not use `log.*` for logging purposes anymore. --------- Co-authored-by: Bryan White --- .github/workflows/reviewdog.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 2fb9c9dd7..c181cf946 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -7,10 +7,10 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} cancel-in-progress: true - + jobs: - # Makes sure that comments like TODO_IN_THIS_PR or TODO_IN_THIS_COMMIT block merging to main - # More info: https://github.com/pokt-network/action-fail-on-found + # Makes sure that comments like TODO_IN_THIS_PR or TODO_IN_THIS_COMMIT block + # merging to main. See https://github.com/pokt-network/action-fail-on-found check_todo_in_this: name: Check TODO_IN_THIS_ runs-on: ubuntu-latest @@ -24,6 +24,23 @@ jobs: fail_on_error: true pattern: TODO_IN_THIS_ + # Ensure that we are using polylog (via logger.) instead of the golang's stdlib + # log package. + check_stdlog_in_off_chain_package: + name: Check stdlog in off-chain source code + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pokt-network/action-fail-on-found@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + level: error + fail_on_error: true + pattern: log\..* + + # There are multiple ways to validate (at compile time) that a struct + # implements a certain interface. This check enforces a common practice. check_non_standard_interface_implementations: name: Check for non-standard interface implementation statements runs-on: ubuntu-latest From c5bc8e75deb53f105b051f2686ecfe75c2902b66 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 13:06:39 -0800 Subject: [PATCH 13/19] Ran make go_imports --- app/app.go | 3 ++- pkg/client/block/block.go | 1 + pkg/client/block/client.go | 1 + pkg/client/delegation/client.go | 1 + pkg/client/interface.go | 3 ++- pkg/client/supplier/client.go | 3 ++- pkg/relayer/proxy/synchronous.go | 1 + testutil/keeper/tokenomics.go | 3 ++- testutil/network/network.go | 3 ++- testutil/testclient/localnet.go | 5 +++-- testutil/testclient/testsupplier/client.go | 5 +++-- testutil/testclient/testtx/client.go | 3 ++- x/application/keeper/msg_server_delegate_to_gateway.go | 1 + x/application/keeper/msg_server_stake_application.go | 1 + x/application/keeper/msg_server_undelegate_from_gateway.go | 1 + x/application/keeper/msg_server_unstake_application.go | 1 + x/gateway/keeper/msg_server_stake_gateway.go | 1 + x/gateway/keeper/msg_server_unstake_gateway.go | 1 + x/session/keeper/session_hydrator.go | 3 ++- x/supplier/keeper/claim.go | 1 + x/supplier/keeper/msg_server_stake_supplier.go | 1 + x/supplier/keeper/msg_server_submit_proof.go | 1 + x/supplier/keeper/msg_server_unstake_supplier.go | 1 + x/tokenomics/genesis.go | 1 + x/tokenomics/keeper/params.go | 1 + x/tokenomics/keeper/query_params.go | 3 ++- x/tokenomics/module.go | 3 ++- x/tokenomics/module_simulation.go | 1 + 28 files changed, 41 insertions(+), 13 deletions(-) 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/pkg/client/block/block.go b/pkg/client/block/block.go index e6868cf78..06f6bf679 100644 --- a/pkg/client/block/block.go +++ b/pkg/client/block/block.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/cometbft/cometbft/types" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" ) diff --git a/pkg/client/block/client.go b/pkg/client/block/client.go index 177a620c1..cb04bdc07 100644 --- a/pkg/client/block/client.go +++ b/pkg/client/block/client.go @@ -4,6 +4,7 @@ import ( "context" "cosmossdk.io/depinject" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" ) diff --git a/pkg/client/delegation/client.go b/pkg/client/delegation/client.go index 8237075b9..bde9309e3 100644 --- a/pkg/client/delegation/client.go +++ b/pkg/client/delegation/client.go @@ -4,6 +4,7 @@ import ( "context" "cosmossdk.io/depinject" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/events" ) diff --git a/pkg/client/interface.go b/pkg/client/interface.go index 4790cfed9..a857c14b2 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -21,12 +21,13 @@ import ( cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" cosmostypes "github.com/cosmos/cosmos-sdk/types" accounttypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/pokt-network/smt" + "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable" apptypes "github.com/pokt-network/poktroll/x/application/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" - "github.com/pokt-network/smt" ) // SupplierClient is an interface for sufficient for a supplier operator to be diff --git a/pkg/client/supplier/client.go b/pkg/client/supplier/client.go index b4a7d0cc0..11259af84 100644 --- a/pkg/client/supplier/client.go +++ b/pkg/client/supplier/client.go @@ -5,12 +5,13 @@ import ( "cosmossdk.io/depinject" cosmostypes "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/smt" + "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" - "github.com/pokt-network/smt" ) var _ client.SupplierClient = (*supplierClient)(nil) 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 82a30b4a0..4a57a2f4e 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -20,6 +20,8 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/app" "github.com/pokt-network/poktroll/testutil/sample" appcli "github.com/pokt-network/poktroll/x/application/client/cli" @@ -27,7 +29,6 @@ import ( gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" - "github.com/stretchr/testify/require" ) type ( diff --git a/testutil/testclient/localnet.go b/testutil/testclient/localnet.go index e6fa181fb..3e30318ed 100644 --- a/testutil/testclient/localnet.go +++ b/testutil/testclient/localnet.go @@ -7,11 +7,12 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/pokt-network/poktroll/app" - "github.com/pokt-network/poktroll/cmd/pocketd/cmd" "github.com/regen-network/gocuke" "github.com/spf13/pflag" "github.com/stretchr/testify/require" + + "github.com/pokt-network/poktroll/app" + "github.com/pokt-network/poktroll/cmd/pocketd/cmd" ) var ( diff --git a/testutil/testclient/testsupplier/client.go b/testutil/testclient/testsupplier/client.go index 5139a87bc..841cfc024 100644 --- a/testutil/testclient/testsupplier/client.go +++ b/testutil/testclient/testsupplier/client.go @@ -6,14 +6,15 @@ import ( "cosmossdk.io/depinject" "github.com/golang/mock/gomock" + "github.com/pokt-network/smt" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/client/supplier" "github.com/pokt-network/poktroll/pkg/client/tx" "github.com/pokt-network/poktroll/testutil/mockclient" "github.com/pokt-network/poktroll/testutil/testclient/testtx" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/smt" - "github.com/stretchr/testify/require" ) // NewLocalnetClient creates and returns a new supplier client that connects to diff --git a/testutil/testclient/testtx/client.go b/testutil/testclient/testtx/client.go index bff6b8ae6..4bc85c218 100644 --- a/testutil/testclient/testtx/client.go +++ b/testutil/testclient/testtx/client.go @@ -8,13 +8,14 @@ import ( "cosmossdk.io/depinject" cosmostypes "github.com/cosmos/cosmos-sdk/types" "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "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" - "github.com/stretchr/testify/require" ) type signAndBroadcastFn func(context.Context, cosmostypes.Msg) either.AsyncError diff --git a/x/application/keeper/msg_server_delegate_to_gateway.go b/x/application/keeper/msg_server_delegate_to_gateway.go index 8b0a40d52..c2ecd82a0 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway.go +++ b/x/application/keeper/msg_server_delegate_to_gateway.go @@ -6,6 +6,7 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/application/types" ) diff --git a/x/application/keeper/msg_server_stake_application.go b/x/application/keeper/msg_server_stake_application.go index 2b6b0944b..da22a134e 100644 --- a/x/application/keeper/msg_server_stake_application.go +++ b/x/application/keeper/msg_server_stake_application.go @@ -6,6 +6,7 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/application/types" ) diff --git a/x/application/keeper/msg_server_undelegate_from_gateway.go b/x/application/keeper/msg_server_undelegate_from_gateway.go index 3e8a6645e..2ebc30416 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway.go @@ -6,6 +6,7 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/application/types" ) diff --git a/x/application/keeper/msg_server_unstake_application.go b/x/application/keeper/msg_server_unstake_application.go index 2e3fa90da..d6f582aaa 100644 --- a/x/application/keeper/msg_server_unstake_application.go +++ b/x/application/keeper/msg_server_unstake_application.go @@ -5,6 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/application/types" ) diff --git a/x/gateway/keeper/msg_server_stake_gateway.go b/x/gateway/keeper/msg_server_stake_gateway.go index d46579284..f5f6e63e2 100644 --- a/x/gateway/keeper/msg_server_stake_gateway.go +++ b/x/gateway/keeper/msg_server_stake_gateway.go @@ -6,6 +6,7 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/gateway/types" ) diff --git a/x/gateway/keeper/msg_server_unstake_gateway.go b/x/gateway/keeper/msg_server_unstake_gateway.go index 2817dd239..3521d1bac 100644 --- a/x/gateway/keeper/msg_server_unstake_gateway.go +++ b/x/gateway/keeper/msg_server_unstake_gateway.go @@ -5,6 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/gateway/types" ) diff --git a/x/session/keeper/session_hydrator.go b/x/session/keeper/session_hydrator.go index 9d0e80971..6e56810a4 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -9,10 +9,11 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + _ "golang.org/x/crypto/sha3" + "github.com/pokt-network/poktroll/x/session/types" sharedhelpers "github.com/pokt-network/poktroll/x/shared/helpers" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" - _ "golang.org/x/crypto/sha3" ) var SHA3HashLen = crypto.SHA3_256.Size() diff --git a/x/supplier/keeper/claim.go b/x/supplier/keeper/claim.go index 189676499..e635a95d6 100644 --- a/x/supplier/keeper/claim.go +++ b/x/supplier/keeper/claim.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/supplier/types" ) diff --git a/x/supplier/keeper/msg_server_stake_supplier.go b/x/supplier/keeper/msg_server_stake_supplier.go index 8a6233ff2..edd8ecee8 100644 --- a/x/supplier/keeper/msg_server_stake_supplier.go +++ b/x/supplier/keeper/msg_server_stake_supplier.go @@ -6,6 +6,7 @@ import ( sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/types" ) diff --git a/x/supplier/keeper/msg_server_submit_proof.go b/x/supplier/keeper/msg_server_submit_proof.go index 39ecb427b..2715b7c8d 100644 --- a/x/supplier/keeper/msg_server_submit_proof.go +++ b/x/supplier/keeper/msg_server_submit_proof.go @@ -4,6 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/supplier/types" ) diff --git a/x/supplier/keeper/msg_server_unstake_supplier.go b/x/supplier/keeper/msg_server_unstake_supplier.go index 26349c111..79f86db3f 100644 --- a/x/supplier/keeper/msg_server_unstake_supplier.go +++ b/x/supplier/keeper/msg_server_unstake_supplier.go @@ -5,6 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/pokt-network/poktroll/x/supplier/types" ) 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" From d62858b8f9eaf40f20b2c6e73c682584820d5a9e Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 13:27:00 -0800 Subject: [PATCH 14/19] Update pkg/client/supplier/client.go Co-authored-by: Bryan White --- pkg/client/supplier/client.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/client/supplier/client.go b/pkg/client/supplier/client.go index 11259af84..f17b77534 100644 --- a/pkg/client/supplier/client.go +++ b/pkg/client/supplier/client.go @@ -87,10 +87,12 @@ func (sClient *supplierClient) SubmitProof( // TODO_IMPROVE: log details related to what & how much is being proven logger.Info(). - Str("supplier_addr", sClient.signingKeyAddr.String()). - Str("app_addr", sessionHeader.ApplicationAddress). - Str("session_id", sessionHeader.SessionId). - Str("service", sessionHeader.Service.Id). + 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 proof") return <-errCh From ebc0d6e0a9a55e17a3267b041fe17de62d0512e9 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 13:35:44 -0800 Subject: [PATCH 15/19] Update pkg/client/delegation/client.go Co-authored-by: Bryan White --- pkg/client/delegation/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/delegation/client.go b/pkg/client/delegation/client.go index bde9309e3..883969f6d 100644 --- a/pkg/client/delegation/client.go +++ b/pkg/client/delegation/client.go @@ -18,7 +18,7 @@ const ( // defaultRedelegationsReplayLimit is the number of redelegations that the // replay observable returned by LastNRedelegations() will be able to replay. - // TODO_TECHDEBT/TODO_FUTURE: add a `blocksReplayLimit` field to the blockClient + // 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 ) From 254568d23929699e54ba29c59dcb385ba8b86689 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 13:35:58 -0800 Subject: [PATCH 16/19] Moved in-line strings to a local constant in tests --- e2e/tests/relay.feature | 1 + pkg/client/supplier/client_test.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/e2e/tests/relay.feature b/e2e/tests/relay.feature index 1bf624552..32f965bb9 100644 --- a/e2e/tests/relay.feature +++ b/e2e/tests/relay.feature @@ -1,6 +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/pkg/client/supplier/client_test.go b/pkg/client/supplier/client_test.go index 447abc9c2..b02a491fa 100644 --- a/pkg/client/supplier/client_test.go +++ b/pkg/client/supplier/client_test.go @@ -20,7 +20,10 @@ import ( "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) @@ -103,7 +106,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) { SessionStartBlockHeight: 0, SessionId: "", Service: &sharedtypes.Service{ - Id: "test_service", + Id: testService, }, } @@ -161,7 +164,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) { SessionStartBlockHeight: 0, SessionId: "", Service: &sharedtypes.Service{ - Id: "test_service", + Id: testService, }, } From 08236ac148bec7e4e57fc414fe9eea8043a09e71 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 14:13:41 -0800 Subject: [PATCH 17/19] Tend to a few more PR comments --- pkg/client/supplier/client.go | 12 +++++++----- pkg/client/supplier/client_test.go | 7 +++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/client/supplier/client.go b/pkg/client/supplier/client.go index f17b77534..4bf4c0554 100644 --- a/pkg/client/supplier/client.go +++ b/pkg/client/supplier/client.go @@ -93,7 +93,7 @@ func (sClient *supplierClient) SubmitProof( "session_id": sessionHeader.SessionId, "service": sessionHeader.Service.Id, }). - Msg("created a new proof") + Msg("submitted a new proof") return <-errCh } @@ -121,10 +121,12 @@ func (sClient *supplierClient) CreateClaim( // TODO_IMPROVE: log details related to how much is claimed logger.Info(). - Str("supplier_addr", sClient.signingKeyAddr.String()). - Str("app_addr", sessionHeader.ApplicationAddress). - Str("session_id", sessionHeader.SessionId). - Str("service", sessionHeader.Service.Id). + 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 diff --git a/pkg/client/supplier/client_test.go b/pkg/client/supplier/client_test.go index b02a491fa..4c92ef3ba 100644 --- a/pkg/client/supplier/client_test.go +++ b/pkg/client/supplier/client_test.go @@ -10,7 +10,6 @@ import ( "github.com/golang/mock/gomock" "github.com/pokt-network/poktroll/pkg/client/keyring" "github.com/pokt-network/poktroll/pkg/client/supplier" - "github.com/pokt-network/poktroll/pkg/polylog/polyzero" "github.com/pokt-network/poktroll/testutil/mockclient" "github.com/pokt-network/poktroll/testutil/testclient/testkeyring" "github.com/pokt-network/poktroll/testutil/testclient/testtx" @@ -22,7 +21,7 @@ import ( const ( testSigningKeyName = "test_signer" - testService = "test_service" + testService = "test_service" ) func TestNewSupplierClient(t *testing.T) { @@ -79,7 +78,7 @@ func TestSupplierClient_CreateClaim(t *testing.T) { var ( signAndBroadcastDelay = 50 * time.Millisecond doneCh = make(chan struct{}, 1) - ctx = polyzero.NewLogger().WithContext(context.Background()) + ctx = context.Background() ) keyring, testAppKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName) @@ -138,7 +137,7 @@ func TestSupplierClient_SubmitProof(t *testing.T) { var ( signAndBroadcastDelay = 50 * time.Millisecond doneCh = make(chan struct{}, 1) - ctx = polyzero.NewLogger().WithContext(context.Background()) + ctx = context.Background() ) keyring, testAppKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName) From 69f9a9efb21633665e57c7d47f9fec05f49ca6ad Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 14:19:49 -0800 Subject: [PATCH 18/19] Consolidated ports 8548 and 8545 --- Dockerfile.dev | 1 - Tiltfile | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 8cc6066c8..c427833e9 100644 --- a/Tiltfile +++ b/Tiltfile @@ -159,7 +159,7 @@ k8s_resource( "relayminers", labels=["blockchains"], resource_deps=["sequencer"], - port_forwards=["8548", "40005"], + port_forwards=["8545", "40005"], ) k8s_resource( "appgateservers", From 9228887a2590f25e08d724dee93a7df7443af4b6 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Tue, 12 Dec 2023 15:04:06 -0800 Subject: [PATCH 19/19] Manually run the following command on the files provided: goimports-reviser -rm-unused -set-alias -format -output write --- pkg/relayer/relayminer_test.go | 3 ++- x/application/keeper/msg_server_delegate_to_gateway_test.go | 3 ++- .../keeper/msg_server_undelegate_from_gateway_test.go | 3 ++- x/supplier/client/cli/helpers_test.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/relayer/relayminer_test.go b/pkg/relayer/relayminer_test.go index d3b3afbe2..f7de39d39 100644 --- a/pkg/relayer/relayminer_test.go +++ b/pkg/relayer/relayminer_test.go @@ -6,12 +6,13 @@ import ( "time" "cosmossdk.io/depinject" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/pkg/observable/channel" "github.com/pokt-network/poktroll/pkg/polylog/polyzero" "github.com/pokt-network/poktroll/pkg/relayer" "github.com/pokt-network/poktroll/testutil/testrelayer" servicetypes "github.com/pokt-network/poktroll/x/service/types" - "github.com/stretchr/testify/require" ) func TestRelayMiner_StartAndStop(t *testing.T) { 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 654f41282..f926af58d 100644 --- a/x/application/keeper/msg_server_delegate_to_gateway_test.go +++ b/x/application/keeper/msg_server_delegate_to_gateway_test.go @@ -5,12 +5,13 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" - "github.com/stretchr/testify/require" ) func TestMsgServer_DelegateToGateway_SuccessfullyDelegate(t *testing.T) { 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 e261b8831..63dba4f31 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway_test.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway_test.go @@ -5,12 +5,13 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" "github.com/pokt-network/poktroll/x/application/keeper" "github.com/pokt-network/poktroll/x/application/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" - "github.com/stretchr/testify/require" ) func TestMsgServer_UndelegateFromGateway_SuccessfullyUndelegate(t *testing.T) { diff --git a/x/supplier/client/cli/helpers_test.go b/x/supplier/client/cli/helpers_test.go index dbd89c3a7..9c8089868 100644 --- a/x/supplier/client/cli/helpers_test.go +++ b/x/supplier/client/cli/helpers_test.go @@ -17,6 +17,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" testcli "github.com/cosmos/cosmos-sdk/testutil/cli" sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + "github.com/pokt-network/poktroll/cmd/pocketd/cmd" "github.com/pokt-network/poktroll/testutil/network" "github.com/pokt-network/poktroll/testutil/testkeyring" @@ -25,7 +27,6 @@ import ( sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/client/cli" "github.com/pokt-network/poktroll/x/supplier/types" - "github.com/stretchr/testify/require" ) // TODO_TECHDEBT: This should not be hardcoded once the num blocks per session is configurable.