Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Utility] Foundational bugs, tests, code cleanup and improvements (2/3) #550

Merged
merged 44 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4b9593f
Rename converters to utils
Olshansk Feb 21, 2023
85866b7
s/app_staking_adjustment_owner/app_stake_to_session_quota_multiplier_…
Olshansk Feb 21, 2023
750c009
Renamed the rest of the staking adjustments
Olshansk Feb 22, 2023
1a1187c
Consolidated stake status
Olshansk Feb 22, 2023
4e62d37
Consolidated stake status proto
Olshansk Feb 22, 2023
0875fef
All tests passing again
Olshansk Feb 22, 2023
69859b6
Removed mockBusInTestModules
Olshansk Feb 22, 2023
ec2e0b2
Removed the whole getStoreAndHeight thing
Olshansk Feb 22, 2023
e17772b
Merge with main
Olshansk Feb 23, 2023
52066cf
Resolved merge conflicts with master
Olshansk Feb 23, 2023
244963d
s/quota/tokens
Olshansk Feb 23, 2023
4bfa3b9
Replace GenericParam with ServiceUrl
Olshansk Feb 23, 2023
acfdfc6
Removed maxRelays
Olshansk Feb 24, 2023
ecca9cd
Removed baseline_stake_rate
Olshansk Feb 24, 2023
0386df2
Tests passing again
Olshansk Feb 24, 2023
0da331a
Moved transaction.proto from utility/types to shared/core/types
Olshansk Feb 24, 2023
28bb630
Removed DefaultTxResult
Olshansk Feb 24, 2023
e56bcde
Merge with main
Olshansk Feb 26, 2023
b912033
Added a comment
Olshansk Feb 26, 2023
da065bc
Applying an old stashed commit
Olshansk Feb 26, 2023
769ded3
Reviewed validator.go
Olshansk Feb 26, 2023
47182e9
Re-reviewed the utility module interface
Olshansk Feb 26, 2023
519f762
Mostly reviewed block.go but still in progress
Olshansk Feb 26, 2023
d6f1b0d
Reviewed session.go
Olshansk Feb 26, 2023
21057a9
Remove consensus/types/proto/validator.proto
Olshansk Feb 26, 2023
090a53d
Reviewed tx_result.go
Olshansk Feb 27, 2023
d0d005d
A few minor changes to block.go
Olshansk Feb 27, 2023
395de66
fix tests in tx_result.go
Olshansk Feb 27, 2023
faa38e9
Updated all the changelogs
Olshansk Feb 27, 2023
b1758e0
Apply suggestions from deblasis
Olshansk Feb 27, 2023
f23f479
Renamed Url to URL
Olshansk Feb 27, 2023
7c4fbce
Rename keygenerator package to keygen
Olshansk Feb 27, 2023
4f8f24c
Added comments to actor.proto
Olshansk Feb 27, 2023
db69bc8
Add comments related to 556
Olshansk Feb 28, 2023
183983f
Moved TxGossipMessageContentType from utility to shared
Olshansk Feb 28, 2023
53219ad
Updated more comments
Olshansk Feb 28, 2023
086e7a7
Minor edits
Olshansk Feb 28, 2023
51939b3
Update utility/block.go
Olshansk Feb 28, 2023
bd1d89a
Update changelogs
Olshansk Feb 28, 2023
0538925
Pop Tx from mempool when applying block
Olshansk Feb 28, 2023
47d1d92
Fixing remaining lingers
Olshansk Feb 28, 2023
eda1999
Fix broken test
Olshansk Feb 28, 2023
007e2bb
Fix utility changelog
Olshansk Feb 28, 2023
2dbcb7f
Merge with main
Olshansk Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,4 @@ check_cross_module_imports: ## Lists cross-module imports

.PHONY: send_local_tx
send_local_tx: ## A hardcoded send tx to make LocalNet debugging easier
go run app/client/*.go Account Send 00104055c00bed7c983a48aac7dc6335d7c607a7 00204737d2a165ebe4be3a7d5b0af905b0ea91d8 1000
go run app/client/*.go Account Send --non_interactive 00104055c00bed7c983a48aac7dc6335d7c607a7 00204737d2a165ebe4be3a7d5b0af905b0ea91d8 1000
8 changes: 4 additions & 4 deletions app/client/cli/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ If no changes are desired for the parameter, just enter the current param value
// removing all invalid characters from rawChains argument
rawChains := rawChainCleanupRegex.ReplaceAllString(args[2], "")
chains := strings.Split(rawChains, ",")
serviceURI := args[3]
serviceURL := args[3]

msg := &typesUtil.MessageStake{
PublicKey: pk.PublicKey().Bytes(),
Chains: chains,
Amount: amount,
ServiceUrl: serviceURI,
ServiceUrl: serviceURL,
OutputAddress: pk.Address(),
Signer: pk.Address(),
ActorType: cmdDef.ActorType,
Expand Down Expand Up @@ -201,13 +201,13 @@ func newEditStakeCmd(cmdDef actorCmdDef) *cobra.Command {
// removing all invalid characters from rawChains argument
rawChains := rawChainCleanupRegex.ReplaceAllString(args[2], "")
chains := strings.Split(rawChains, ",")
serviceURI := args[3]
serviceURL := args[3]

msg := &typesUtil.MessageEditStake{
Address: fromAddr,
Chains: chains,
Amount: amount,
ServiceUrl: serviceURI,
ServiceUrl: serviceURL,
Signer: pk.Address(),
ActorType: cmdDef.ActorType,
}
Expand Down
6 changes: 3 additions & 3 deletions app/client/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ func NewDebugCommand() *cobra.Command {
bus := runtimeMgr.GetBus()
modulesRegistry := bus.GetModulesRegistry()

rpcUrl := fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort)
rpcURL := fmt.Sprintf("http://%s:%s", rpcHost, defaults.DefaultRPCPort)

addressBookProvider := rpcABP.NewRPCAddrBookProvider(
rpcABP.WithP2PConfig(
runtimeMgr.GetConfig().P2P,
),
rpcABP.WithCustomRPCUrl(rpcUrl),
rpcABP.WithCustomRPCURL(rpcURL),
)
modulesRegistry.RegisterModule(addressBookProvider)

currentHeightProvider := rpcCHP.NewRPCCurrentHeightProvider(
rpcCHP.WithCustomRPCUrl(rpcUrl),
rpcCHP.WithCustomRPCURL(rpcURL),
)
modulesRegistry.RegisterModule(currentHeightProvider)

Expand Down
27 changes: 14 additions & 13 deletions app/client/cli/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"bytes"
"encoding/hex"
"fmt"
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/shared/codec"
"github.com/pokt-network/pocket/shared/converters"
"github.com/pokt-network/pocket/shared/crypto"
utilTypes "github.com/pokt-network/pocket/utility/types"
"path/filepath"
"strconv"
"strings"

"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/shared/codec"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/utils"

"github.com/pokt-network/pocket/app/client/keybase"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -363,7 +364,7 @@ func keysExportCommands() []*cobra.Command {

logger.Global.Info().Str("output_file", outputFile).Msg("Exporting private key string to file...")

return converters.WriteOutput(exportString, outputFile)
return utils.WriteOutput(exportString, outputFile)
},
},
}
Expand All @@ -384,7 +385,7 @@ func keysImportCommands() []*cobra.Command {
if len(args) == 1 {
privateKeyString = args[0]
} else if inputFile != "" {
privateKeyBz, err := converters.ReadInput(inputFile)
privateKeyBz, err := utils.ReadInput(inputFile)
privateKeyString = string(privateKeyBz)
if err != nil {
return err
Expand Down Expand Up @@ -578,11 +579,11 @@ func keysSignTxCommands() []*cobra.Command {
}

// Unmarshal Tx from input file
txBz, err := converters.ReadInput(inputFile)
txBz, err := utils.ReadInput(inputFile)
if err != nil {
return err
}
txProto := new(utilTypes.Transaction)
txProto := new(coreTypes.Transaction)
if err := codec.GetCodec().Unmarshal(txBz, txProto); err != nil {
return err
}
Expand All @@ -599,7 +600,7 @@ func keysSignTxCommands() []*cobra.Command {
}

// Add signature to the transaction
sig := new(utilTypes.Signature)
sig := new(coreTypes.Signature)
sig.PublicKey = privKey.PublicKey().Bytes()
sig.Signature = sigBz
txProto.Signature = sig
Expand All @@ -610,7 +611,7 @@ func keysSignTxCommands() []*cobra.Command {
return err
}

if err := converters.WriteOutput(txBz, outputFile); err != nil {
if err := utils.WriteOutput(txBz, outputFile); err != nil {
return err
}

Expand Down Expand Up @@ -650,11 +651,11 @@ func keysSignTxCommands() []*cobra.Command {
}

// Unmarshal Tx from input file
txBz, err := converters.ReadInput(inputFile)
txBz, err := utils.ReadInput(inputFile)
if err != nil {
return err
}
txProto := new(utilTypes.Transaction)
txProto := new(coreTypes.Transaction)
if err := codec.GetCodec().Unmarshal(txBz, txProto); err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions app/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/rpc"
"github.com/pokt-network/pocket/shared/codec"
"github.com/pokt-network/pocket/shared/converters"
coreTypes "github.com/pokt-network/pocket/shared/core/types"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/utils"
typesUtil "github.com/pokt-network/pocket/utility/types"
"github.com/spf13/cobra"
"golang.org/x/term"
Expand Down Expand Up @@ -89,7 +90,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.PrivateKey) ([]byte, error)
return nil, err
}

tx := &typesUtil.Transaction{
tx := &coreTypes.Transaction{
Msg: anyMsg,
Nonce: fmt.Sprintf("%d", crypto.GetNonce()),
}
Expand All @@ -104,7 +105,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.PrivateKey) ([]byte, error)
return nil, err
}

tx.Signature = &typesUtil.Signature{
tx.Signature = &coreTypes.Signature{
Signature: signature,
PublicKey: pk.PublicKey().Bytes(),
}
Expand Down Expand Up @@ -155,13 +156,13 @@ func readPassphraseMessage(currPwd, prompt string) string {
}

func validateStakeAmount(amount string) error {
am, err := converters.StringToBigInt(amount)
am, err := utils.StringToBigInt(amount)
if err != nil {
return err
}

sr := big.NewInt(stakingRecommendationAmount)
if converters.BigIntLessThan(am, sr) {
if utils.BigIntLessThan(am, sr) {
fmt.Printf("The amount you are staking for is below the recommendation of %d POKT, would you still like to continue? y|n\n", sr.Div(sr, oneMillion).Int64())
if !confirmation(pwd) {
return fmt.Errorf("aborted")
Expand Down
4 changes: 4 additions & 0 deletions app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.19] - 2023-02-28

- Renamed the package names for some basic helpers

## [0.0.0.18] - 2023-02-28

- Implement SLIP-0010 HD child key derivation with the keybase
Expand Down
4 changes: 2 additions & 2 deletions app/client/keybase/debug/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package debug

import (
"fmt"
"github.com/pokt-network/pocket/shared/converters"
"os"
"path/filepath"
r "runtime"
Expand All @@ -12,6 +11,7 @@ import (
"github.com/pokt-network/pocket/runtime"
cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
pocketk8s "github.com/pokt-network/pocket/shared/k8s"
"github.com/pokt-network/pocket/shared/utils"
"gopkg.in/yaml.v2"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -133,7 +133,7 @@ func fetchValidatorPrivateKeysFromFile() (map[string]string, error) {
_, current, _, _ := r.Caller(0)
//nolint:gocritic // Use path to find private-keys yaml file from being called in any location in the repo
yamlFile := filepath.Join(current, privateKeysYamlFile)
if exists, err := converters.FileExists(yamlFile); !exists || err != nil {
if exists, err := utils.FileExists(yamlFile); !exists || err != nil {
return nil, fmt.Errorf("unable to find YAML file: %s", yamlFile)
}

Expand Down
4 changes: 2 additions & 2 deletions app/client/keybase/keybase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/hex"
"testing"

"github.com/pokt-network/pocket/runtime/test_artifacts/keygenerator"
"github.com/pokt-network/pocket/runtime/test_artifacts/keygen"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -441,7 +441,7 @@ func initDB(t *testing.T) Keybase {
func createTestKeys(t *testing.T, n int) []crypto.PrivateKey {
pks := make([]crypto.PrivateKey, 0)
for i := 0; i < n; i++ {
privKeyString, _, _ := keygenerator.GetInstance().Next()
privKeyString, _, _ := keygen.GetInstance().Next()
privKey, err := crypto.NewPrivateKey(privKeyString)
require.NoError(t, err)
pks = append(pks, privKey)
Expand Down
7 changes: 3 additions & 4 deletions app/client/keybase/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"bytes"
"encoding/hex"
"fmt"
"github.com/pokt-network/pocket/shared/crypto/slip"
"strings"

"github.com/pokt-network/pocket/shared/converters"

"github.com/dgraph-io/badger/v3"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/crypto/slip"
"github.com/pokt-network/pocket/shared/utils"
)

const (
Expand All @@ -32,7 +31,7 @@ type badgerKeybase struct {

// NewKeybase creates/Opens the DB at the specified path creating the path if it doesn't exist
func NewKeybase(path string) (Keybase, error) {
pathExists, err := converters.DirExists(path) // Creates path if it doesn't exist
pathExists, err := utils.DirExists(path) // Creates path if it doesn't exist
if err != nil || !pathExists {
return nil, err
}
Expand Down
30 changes: 11 additions & 19 deletions build/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -4040,7 +4040,7 @@
"address": "00104055c00bed7c983a48aac7dc6335d7c607a7",
"public_key": "dfe357de55649e6d2ce889acf15eb77e94ab3c5756fe46d3c7538d37f27f115e",
"chains": null,
"generic_param": "node1.consensus:8080",
"service_url": "node1.consensus:8080",
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4051,7 +4051,7 @@
"address": "00204737d2a165ebe4be3a7d5b0af905b0ea91d8",
"public_key": "eb2c78364525a210d994a83e02d18b4287ab81f6670cf4510ab6c9f51e296d91",
"chains": null,
"generic_param": "node2.consensus:8080",
"service_url": "node2.consensus:8080",
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4062,7 +4062,7 @@
"address": "00304d0101847b37fd62e7bebfbdddecdbb7133e",
"public_key": "1041a9c76539791fef9bee5b4fcd5bf4a1a489e0790c44cbdfa776b901e13b50",
"chains": null,
"generic_param": "node3.consensus:8080",
"service_url": "node3.consensus:8080",
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4073,7 +4073,7 @@
"address": "00404a570febd061274f72b50d0a37f611dfe339",
"public_key": "d6cea8706f6ee6672c1e013e667ec8c46231e0e7abcf97ba35d89fceb8edae45",
"chains": null,
"generic_param": "node4.consensus:8080",
"service_url": "node4.consensus:8080",
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4085,10 +4085,7 @@
{
"address": "88a792b7aca673620132ef01f50e62caa58eca83",
"public_key": "5f78658599943dc3e623539ce0b3c9fe4e192034a1e3fef308bc9f96915754e0",
"chains": [
"0001"
],
"generic_param": "1000000",
"chains": ["0001"],
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4100,10 +4097,8 @@
{
"address": "43d9ea9d9ad9c58bb96ec41340f83cb2cabb6496",
"public_key": "16cd0a304c38d76271f74dd3c90325144425d904ef1b9a6fbab9b201d75a998b",
"chains": [
"0001"
],
"generic_param": "node1.consensus:8080",
"chains": ["0001"],
"service_url": "node1.consensus:8080",
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4115,10 +4110,8 @@
{
"address": "9ba047197ec043665ad3f81278ab1f5d3eaf6b8b",
"public_key": "68efd26af01692fcd77dc135ca1de69ede464e8243e6832bd6c37f282db8c9cb",
"chains": [
"0001"
],
"generic_param": "node1.consensus:8080",
"chains": ["0001"],
"service_url": "node1.consensus:8080",
"staked_amount": "1000000000000",
"paused_height": -1,
"unstaking_height": -1,
Expand All @@ -4130,7 +4123,7 @@
"blocks_per_session": 4,
"app_minimum_stake": "15000000000",
"app_max_chains": 15,
"app_baseline_stake_rate": 100,
"app_session_tokens_multiplier": 100,
"app_unstaking_blocks": 2016,
"app_minimum_pause_blocks": 4,
"app_max_pause_blocks": 672,
Expand Down Expand Up @@ -4184,8 +4177,7 @@
"blocks_per_session_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_minimum_stake_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_max_chains_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_baseline_stake_rate_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_staking_adjustment_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_session_tokens_multiplier_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_unstaking_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_minimum_pause_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
"app_max_paused_blocks_owner": "da034209758b78eaea06dd99c07909ab54c99b45",
Expand Down
5 changes: 5 additions & 0 deletions build/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.19] - 2023-02-28

- Renamed `generic_param` to `service_url` in the config files
- Renamed a few governance parameters to make self explanatory

## [0.0.0.18] - 2023-02-21

- Rename ServiceNode Actor Type Name to Servicer
Expand Down
Loading