Skip to content

Commit

Permalink
merge with issue #351 and main
Browse files Browse the repository at this point in the history
  • Loading branch information
gokutheengineer committed Mar 7, 2023
2 parents ef1e0e4 + 8206bcf commit 26ddb9f
Show file tree
Hide file tree
Showing 178 changed files with 4,389 additions and 2,152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
# Not utilizing makefile target here to make use of pipefail bash feature.
run: |
set -euo pipefail
go test -p 1 -json ./... -covermode=count -coverprofile=coverage.out 2>&1 | tee test_results.json
GODEBUG=netdns=cgo go test -p 1 -json ./... -covermode=count -coverprofile=coverage.out 2>&1 | tee test_results.json
- name: Sanitize test results
# We're utilizing `tee` above which can capture non-json stdout output so we need to remove non-json lines before additional parsing and submitting it to the external github action.
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ shared/modules/mocks/*
p2p/types/mocks/*
!p2p/types/mocks/mocks.go

libp2p/types/mocks/*
!libp2p/types/mocks/mocks.go

persistence/types/mocks/*
!persistence/types/mocks/mocks.go

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ mockgen: clean_mocks ## Use `mockgen` to generate mocks used for testing purpose
go generate ./${modules_dir}
echo "Mocks generated in ${modules_dir}/mocks"

$(eval DIRS = p2p persistence)
$(eval DIRS = p2p libp2p persistence)
for dir in $(DIRS); do \
echo "Processing $$dir mocks..."; \
find $$dir/types/mocks -type f ! -name "mocks.go" -exec rm {} \;; \
Expand Down Expand Up @@ -365,6 +365,10 @@ test_hotstuff: ## Run all go unit tests related to hotstuff consensus
test_pacemaker: ## Run all go unit tests related to the hotstuff pacemaker
go test ${VERBOSE_TEST} ./consensus/e2e_tests -run Pacemaker

.PHONY: test_statesync
test_statesync: ## Run all go unit tests related to the hotstuff statesync
go test ${VERBOSE_TEST} ./consensus/e2e_tests -run StateSync

.PHONY: test_vrf
test_vrf: ## Run all go unit tests in the VRF library
go test ${VERBOSE_TEST} ./consensus/leader_election/vrf
Expand Down Expand Up @@ -518,4 +522,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
34 changes: 27 additions & 7 deletions app/client/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"os"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"google.golang.org/protobuf/types/known/anypb"

"github.com/pokt-network/pocket/libp2p"
"github.com/pokt-network/pocket/logger"
"github.com/pokt-network/pocket/p2p"
"github.com/pokt-network/pocket/p2p/providers/addrbook_provider"
Expand All @@ -16,8 +20,6 @@ import (
"github.com/pokt-network/pocket/runtime/defaults"
"github.com/pokt-network/pocket/shared/messaging"
"github.com/pokt-network/pocket/shared/modules"
"github.com/spf13/cobra"
"google.golang.org/protobuf/types/known/anypb"
)

// TECHDEBT: Lowercase variables / constants that do not need to be exported.
Expand Down Expand Up @@ -85,27 +87,29 @@ 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)

setValueInCLIContext(cmd, busCLICtxKey, bus)
p2pM, err := p2p.Create(bus)

// TECHDEBT: simplify after P2P module consolidation.
var err error
p2pMod, err = getP2PModule(runtimeMgr)
if err != nil {
logger.Global.Fatal().Err(err).Msg("Failed to create p2p module")
}
p2pMod = p2pM.(modules.P2PModule)

if err := p2pMod.Start(); err != nil {
logger.Global.Fatal().Err(err).Msg("Failed to start p2p module")
Expand Down Expand Up @@ -271,3 +275,19 @@ func fetchAddressBook(cmd *cobra.Command) (types.AddrBook, error) {
}
return addrBook, err
}

func getP2PModule(runtimeMgr *runtime.Manager) (p2pModule modules.P2PModule, err error) {
bus := runtimeMgr.GetBus()

var mod modules.Module
if runtimeMgr.GetConfig().UseLibP2P {
mod, err = libp2p.Create(bus)
} else {
mod, err = p2p.Create(bus)
}
if err != nil {
return nil, err
}

return mod.(modules.P2PModule), nil
}
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
8 changes: 8 additions & 0 deletions app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.20] - 2023-03-03

- Support libp2p module in debug CLI

## [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
1 change: 1 addition & 0 deletions build/Dockerfile.debian.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FROM golang:${TARGET_GOLANG_VERSION}-bullseye AS builder

ENV PROTOC_VERSION 3.19.4
# Needed to install Tilt without sudo permissions
ENV HOME /root
ENV PATH $PATH:$HOME/.local/bin

### Install dependencies
Expand Down
1 change: 1 addition & 0 deletions build/Dockerfile.debian.prod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FROM golang:${TARGET_GOLANG_VERSION}-bullseye AS builder

ENV PROTOC_VERSION 3.19.4
# Needed to install Tilt without sudo permissions
ENV HOME /root
ENV PATH $PATH:$HOME/.local/bin

### Install dependencies
Expand Down
4 changes: 3 additions & 1 deletion build/config/config1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"root_directory": "/go/src/github.com/pocket-network",
"private_key": "0ca1a40ddecdab4f5b04fa0bfed1d235beaa2b8082e7554425607516f0862075dfe357de55649e6d2ce889acf15eb77e94ab3c5756fe46d3c7538d37f27f115e",
"use_lib_p2p": false,
"consensus": {
"max_mempool_bytes": 500000000,
"pacemaker_config": {
Expand Down Expand Up @@ -28,7 +29,8 @@
"health_check_period": "5m"
},
"p2p": {
"consensus_port": 8080,
"hostname": "node1.consensus",
"port": 42069,
"use_rain_tree": true,
"is_empty_connection_type": false,
"private_key": "0ca1a40ddecdab4f5b04fa0bfed1d235beaa2b8082e7554425607516f0862075dfe357de55649e6d2ce889acf15eb77e94ab3c5756fe46d3c7538d37f27f115e",
Expand Down
Loading

0 comments on commit 26ddb9f

Please sign in to comment.