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

Leanpocket V0 #4

Open
wants to merge 79 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
780a49b
#1441
oten91 Jul 21, 2022
27f7ba7
#1441 update changelog.md
oten91 Jul 21, 2022
c09c1d3
adding rpc for querying accounts.
oten91 Jul 14, 2022
10c8453
#1401 updating rpc-spec.yaml & changelog.md
oten91 Jul 21, 2022
f4bc540
#1447
oten91 Jul 21, 2022
bc8a518
Add new parameter for future blocksize max bytes management
oten91 Jul 18, 2022
9d61e33
Adding Tests to check behaviour before and after activation
oten91 Jul 20, 2022
d898a08
optimizing based on tendermint's behaviour
oten91 Jul 22, 2022
be19a0d
Ammended to include information about release windows
luyzdeleon Jul 22, 2022
0dc33fd
PIP22 Stake Weighted Servicer Rewards
Andrew-Pohl Jul 25, 2022
01a0b29
Adding new params entries to ParamSetPairs() params.go
oten91 Jul 26, 2022
1d01dfb
Add initial node isolation poc
May 14, 2022
46ee74a
Change validation to use isolated session cache
May 14, 2022
9d84265
Update send and claimtx isolated methods
May 14, 2022
1d7b0d5
Add modified end block for all nodes
May 14, 2022
f20ddc4
Remove unnecessary comment
May 14, 2022
e2b3a8e
Add cache initialization
May 15, 2022
5730a7b
Consolidate variables into cache
May 15, 2022
46ead44
Refractor some naming and add get servicers command
May 15, 2022
4da9151
Remove early return for loading servicers
May 15, 2022
80c3e5e
Refractor some naming consistency
May 15, 2022
b2603d6
Refractor some naming consistency
May 15, 2022
6d656eb
Fix servicer map check
May 15, 2022
8f675cd
Add basic unit tests
May 15, 2022
b807dad
Add leanpocket config
May 15, 2022
8626450
Add back flag for lean pocket
May 15, 2022
80861ec
Add relay unit tests
May 15, 2022
881ef4e
Load config for get-servicer command
May 16, 2022
793be69
Fix cache test
May 16, 2022
bb625f0
Fix loading servicer files
May 16, 2022
07da738
Small evidence db name change for consistency
May 16, 2022
fa9517e
Fix tx signing and generation using the correct key
May 16, 2022
765e4c9
Remove unnecessary print for node address
May 16, 2022
b636f87
Add light node loading from one file
May 25, 2022
bfbd715
More renaming to light node
May 25, 2022
2b41467
Fix get light node
May 25, 2022
d03991d
Properly add to light node slices
May 25, 2022
cb16e9b
Fix light node file loading by removing hard coded value
May 25, 2022
195e152
Isolate evidence and sealed map for each nodes
May 27, 2022
dbcba3a
delete cache evidence when receiving proof msg
May 29, 2022
74d62df
fix lite node typo
May 31, 2022
91e962d
Fix relay leak by not copying map
Jun 2, 2022
03d4387
Various locking optimizations by using goroutines or rwlocks
Jun 2, 2022
6336723
add sync status with leanmint
Jun 6, 2022
b37a35e
add lightnode failsafe checks
Jun 6, 2022
3f6590a
Refractor code, prom, and feather impl (#10)
nodiesBlade Jun 21, 2022
a920094
fix time start for claims tx
Jun 21, 2022
a40f1f6
renaming/refractoring methods to meet lean conventions
Jun 22, 2022
648bba7
Add hotload functionality
Jun 23, 2022
e878cb0
Disable implicit loading validators and hot reloading
Jun 23, 2022
17e7c0b
Fix get session lean unit test
Jun 26, 2022
8f4d16b
deduplicate user provided private keys
Jun 26, 2022
2c66eae
Add a runtime argument to set-validators, removing need for startup s…
Jun 27, 2022
95e19da
Add custom sync method only for lean pokt
Jun 27, 2022
7d4f2e1
Remove DRY, fix unit tests (#12)
nodiesBlade Jul 5, 2022
f1874ac
add more tests to leannode_tests
Jul 7, 2022
99f566c
Add multiple nodes relay integration test
Jul 7, 2022
a543cf8
Adjust custom genesis session count and validators
Jul 7, 2022
1b2d0b1
make comment more direct for generate genesis
Jul 7, 2022
f642cea
rename leannode file to pocketnode
Jul 7, 2022
dbcba40
fix challenge request for lean node error naming + logic
Jul 7, 2022
496972f
remove extra space in default config
Jul 7, 2022
fc4e20c
refractor tendermint privval naming for original and lean pokt
Jul 7, 2022
9b03fdc
Change legacy nomenclature to global
Jul 8, 2022
41120d1
Change get nodes cli behavior and naming
Jul 8, 2022
45a1686
rename forceSetValidators
Jul 8, 2022
f698a50
Local Pocket Node rpc call
Jul 10, 2022
55fb269
add go routine for lean pocket for processing claim/proof
Jul 10, 2022
5fc46af
Fix initialization of pocket caches
Jul 10, 2022
e1ddcfe
fix useLean command and loading validators
Jul 12, 2022
b30e53f
localnet fixes / tweaks
Jul 12, 2022
1ef69f7
pass node only in relay validate method
Jul 12, 2022
1552963
revise localnodes endpoints and update swagger api specs
Jul 12, 2022
3202f79
remove useLean as pocket accounts specific name spaces would not work…
Jul 13, 2022
9523ff4
remove useLean in init app
Jul 13, 2022
594909b
remove verbose logging for claim/proof processing
Jul 15, 2022
432b293
Remove nil error for is catching up
Jul 19, 2022
601c135
Format all go files
Jul 28, 2022
4bfd9d0
Rebase via merge upstream/ethereal-wombat < origin/leanpocketv0
Jul 28, 2022
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

# Ignore vendor folder: every environment needs to build their own based on package management.
vendor/
pocket

# Log files should be ignored
*.log
logs/Logs
*.idea/

main


app/cmd/rpc/data/pocket_evidence.db
app/cmd/rpc/data/session.db

tests/unit/*.log
tests/unit/*.json

Expand Down
27 changes: 22 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This Contribution Guide aims to guide contributors through the process of propos

#### Communicating proposals

The first step towards contribution is to effectively propose your change by opening up a new issue using the **Contribution Proposal** issue template. Communicating your proposal effectively will be of the upmost importance throughout the lifecycle of your contribution, so make sure your description is clear and concise.
The first step towards contribution is to effectively propose your change by opening up a new issue using the **Contribution Proposal** issue template. Communicating your proposal effectively will be of the upmost importance throughout the lifecycle of your contribution, so make sure your description is clear and concise. Feel free to also use the `#core-research` channel in our [Official Discord server](https://bit.ly/POKTARCADEdscrd) to ask any questions regarding the proposal you want to make to the repository.

#### Consensus-breaking changes

Expand Down Expand Up @@ -65,7 +65,6 @@ And you will build a `pocket` binary in the root folder which can now be run.

- Code must adhere to the official Go formatting guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt)).
- Code must be documented adhering to the official Go commentary guidelines.
- Pull requests need to be based on and opened against the `staging` branch.

### Quality Assurance

Expand All @@ -81,13 +80,31 @@ The Regression Testing suite of Pocket Core is a series of scenarios that need t

### The Pull Request Process

#### Submitting a PR
#### Submitting a PR to a Release Window

Open a PR against the `staging` branch in the official repository: `https://github.com/pokt-network/pocket-core`. To learn how to open a PR in Github please follow this [guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
Every PR will target an upcoming Release Window for the Pocket Core repository, these windows will be listed as Github Projects in the repository and will be listed in the repository [Projects Page](https://github.com/pokt-network/pocket-core/projects?type=classic). Every project in this page will represent a Release Window which contains the following:

- A PR Cut-out date by which PR's must be approved to be included in the release.
- An integration branch to submit PR's to for this release.

Open a PR against the **integration branch** in the official repository: `https://github.com/pokt-network/pocket-core`. To learn how to open a PR in Github please follow this [guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).

#### The PR review process

Every Pull Request will require at least 1 reviewer from the Core team. Every proposal is different in scope and complexity, so the following points will increase the likelihood of you submitting a successful Pull Request:
Every Pull Request will require at least 2 reviewers from the Core team. The reviews will be done in a 2 phase approach:

1. A functional PR review where the code will be extensively reviewed by a Core Team member and feedback will be provided until the code quality meets the functional requirements of the intended Proposal.
2. An Integration approval, every friday the Core Team will be evaluating PR's ready to be included, and selecting those into QA builds that will be tested as part of the Regression testing performed before each released is launched.

#### The PR Success Criteria

The Core Team will be requiring the following before merging a Pull Request:

- It has a linked Contribution Proposal issue specifying the functionality implemented in the PR.
- There is an associated pull request to the [Pocket Core Functional Tests repository](https://github.com/pokt-network/pocket-core-func-tests) with the appropiate QA scenarios associated with the functionality or fix contained in the PR.
- Enough evidence (either automated or manual) of testing of these new scenarios included in the PR. This evidence must be presented in the format template contained [here](https://github.com/pokt-network/pocket-core/tree/staging/doc/qa/regression).

Every proposal is different in scope and complexity, so the following points will increase the likelihood of you submitting a successful Pull Request:

- Your proposal issue is clear, concise and informative.
- Your PR is within the scope of the proposal.
Expand Down
52 changes: 52 additions & 0 deletions app/cmd/cli/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func init() {
accountsCmd.AddCommand(signNexMS)
accountsCmd.AddCommand(buildMultisig)
accountsCmd.AddCommand(unsafeDeleteCmd)
accountsCmd.AddCommand(getNodesLean)
accountsCmd.AddCommand(setValidatorsLean)
}

// accountsCmd represents the accounts namespace command
Expand Down Expand Up @@ -104,6 +106,29 @@ Will prompt the user for a passphrase to encrypt the generated keypair.`,
},
}

var getNodesLean = &cobra.Command{
Use: "get-validators",
Short: "Retrieves all nodes set by set-validators",
Long: `Retrieves all nodes set by set-validators`,
Run: func(cmd *cobra.Command, args []string) {
app.InitConfig(datadir, tmNode, persistentPeers, seeds, remoteCLIURL)
config := app.GlobalConfig
if !config.PocketConfig.LeanPocket {
fmt.Println("Lean pocket is not enabled")
return
}

keys, err := app.LoadFilePVKeysFromFileLean(config.PocketConfig.DataDir + app.FS + config.TendermintConfig.PrivValidatorKey)
if err != nil {
fmt.Println("Failed to read set validators")
return
}
for _, value := range keys {
fmt.Printf("Node Address: %s\n", strings.ToLower(value.Address.String()))
}
},
}

var getValidator = &cobra.Command{
Use: "get-validator",
Short: "Retrieves the main validator from the priv_val file",
Expand All @@ -120,6 +145,33 @@ var getValidator = &cobra.Command{
},
}

var setValidatorsLean = &cobra.Command{
Use: `set-validators <path to keyfile>`,
Short: "Sets the main validator accounts for tendermint; NOTE: keyfile should be a json string array of private keys",
Long: `Sets the main validator accounts that will be used across all Tendermint functions; NOTE: keyfile should be a json string array of private keys`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
app.InitConfig(datadir, tmNode, persistentPeers, seeds, remoteCLIURL)

if !app.GlobalConfig.PocketConfig.LeanPocket {
fmt.Println("Lean pocket is not enabled")
return
}

keys, err := app.ReadValidatorPrivateKeyFileLean(args[0])
if err != nil {
fmt.Println("Failed to read validators json file ", err)
os.Exit(1)
}
err = app.SetValidatorsFilesLean(keys)
if err != nil {
fmt.Println("Failed to set validators", err)
os.Exit(1)
return
}
},
}

var setValidator = &cobra.Command{
Use: "set-validator <address>",
Short: "Sets the main validator account for tendermint",
Expand Down
5 changes: 4 additions & 1 deletion app/cmd/cli/queryUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ var (
GetAllParamsPath,
GetParamPath,
GetStopPath,
GetQueryChains string
GetQueryChains,
QueryAccounts string
)

func init() {
Expand All @@ -63,6 +64,8 @@ func init() {
GetHeightPath = route.Path
case "QueryAccount":
GetAccountPath = route.Path
case "QueryAccounts":
GetAccountPath = route.Path
case "QueryApp":
GetAppPath = route.Path
case "QueryTX":
Expand Down
29 changes: 16 additions & 13 deletions app/cmd/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ import (
)

var (
datadir string
tmNode string
remoteCLIURL string
persistentPeers string
seeds string
simulateRelay bool
keybase bool
mainnet bool
allBlockTxs bool
testnet bool
profileApp bool
useCache bool
datadir string
tmNode string
remoteCLIURL string
persistentPeers string
seeds string
simulateRelay bool
keybase bool
mainnet bool
allBlockTxs bool
testnet bool
profileApp bool
useCache bool
forceSetValidatorsLean bool
useLean bool
)

var CLIVersion = app.AppVersion
Expand Down Expand Up @@ -58,6 +60,7 @@ func init() {
startCmd.Flags().BoolVar(&testnet, "testnet", false, "run with testnet genesis")
startCmd.Flags().BoolVar(&profileApp, "profileApp", false, "expose cpu & memory profiling")
startCmd.Flags().BoolVar(&useCache, "useCache", false, "use cache")
startCmd.Flags().BoolVar(&forceSetValidatorsLean, "forceSetValidators", false, "reads your lean_pocket_user_key_file (lean_nodes_keys.json) and updates your last signed state/validator files before starting your node")
rootCmd.AddCommand(startCmd)
rootCmd.AddCommand(resetCmd)
rootCmd.AddCommand(version)
Expand Down Expand Up @@ -92,7 +95,7 @@ func start(cmd *cobra.Command, args []string) {
if testnet {
genesisType = app.TestnetGenesisType
}
tmNode := app.InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL, keybase, genesisType, useCache)
tmNode := app.InitApp(datadir, tmNode, persistentPeers, seeds, remoteCLIURL, keybase, genesisType, useCache, forceSetValidatorsLean)
go rpc.StartRPC(app.GlobalConfig.PocketConfig.RPCPort, app.GlobalConfig.PocketConfig.RPCTimeout, simulateRelay, profileApp, allBlockTxs, app.GlobalConfig.PocketConfig.ChainsHotReload)
// trap kill signals (2,3,15,9)
signalChannel := make(chan os.Signal, 1)
Expand Down
14 changes: 7 additions & 7 deletions app/cmd/rpc/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func NewInMemoryTendermintNode(t *testing.T, genesisState []byte) (tendermintNod
if err != nil {
panic(err)
}
pocketTypes.ClearEvidence()
pocketTypes.ClearSessionCache()
pocketTypes.CleanPocketNodes()
inMemKB = nil
//err = os.RemoveAll(tendermintNode.Config().DBPath)
if err != nil {
Expand Down Expand Up @@ -166,11 +165,12 @@ func inMemTendermintNode(genesisState []byte) (*node.Node, keys.Keybase) {
}
db := dbm.NewMemDB()
nodeKey := p2p.NodeKey{PrivKey: pk}
privVal := privval.GenFilePV(c.TmConfig.PrivValidatorKey, c.TmConfig.PrivValidatorState)
privVal.Key.PrivKey = pk
privVal.Key.PubKey = pk.PubKey()
privVal.Key.Address = pk.PubKey().Address()
pocketTypes.InitPVKeyFile(privVal.Key)
privVal := privval.GenFilePVLean(c.TmConfig.PrivValidatorKey, c.TmConfig.PrivValidatorState)
privVal.Keys[0].PrivKey = pk
privVal.Keys[0].PubKey = pk.PubKey()
privVal.Keys[0].Address = pk.PubKey().Address()
pocketTypes.CleanPocketNodes()
pocketTypes.AddPocketNodeByFilePVKey(privVal.Keys[0], c.Logger)

creator := func(logger log.Logger, db dbm.DB, _ io.Writer) *app.PocketCoreApp {
m := map[string]pocketTypes.HostedBlockchain{sdk.PlaceholderHash: {
Expand Down
49 changes: 49 additions & 0 deletions app/cmd/rpc/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
types4 "github.com/pokt-network/pocket-core/app/cmd/rpc/types"
sdk "github.com/pokt-network/pocket-core/types"
types2 "github.com/pokt-network/pocket-core/x/auth/types"
types3 "github.com/pokt-network/pocket-core/x/pocketcore/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/types"
Expand All @@ -24,6 +26,31 @@ func Version(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
WriteResponse(w, APIVersion, r.URL.Path, r.Host)
}

func LocalNodes(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
value := r.URL.Query().Get("authtoken")
if value != app.AuthToken.Value {
WriteErrorResponse(w, 401, "wrong authtoken "+value)
return
}
var localNodes []types4.PublicPocketNode
for _, node := range types3.GlobalPocketNodes {
if node == nil {
nodiesBlade marked this conversation as resolved.
Show resolved Hide resolved
continue
}
localNodes = append(localNodes, types4.PublicPocketNode{Address: node.GetAddress().String()})
}
j, err := json.Marshal(localNodes)
if err != nil {
WriteErrorResponse(w, 400, err.Error())
return
}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
_, err = w.Write(j)
if err != nil {
WriteErrorResponse(w, 400, err.Error())
}
}

type HeightParams struct {
Height int64 `json:"height"`
}
Expand Down Expand Up @@ -364,6 +391,28 @@ func Account(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
WriteJSONResponse(w, string(s), r.URL.Path, r.Host)
}

func Accounts(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var params = PaginatedHeightParams{Height: 0}
if err := PopModel(w, r, ps, &params); err != nil {
WriteErrorResponse(w, 400, err.Error())
return
}
if params.Height == 0 {
params.Height = app.PCA.BaseApp.LastBlockHeight()
}
res, err := app.PCA.QueryAccounts(params.Height, params.Page, params.PerPage)
if err != nil {
WriteErrorResponse(w, 400, err.Error())
return
}
s, err := json.Marshal(res)
if err != nil {
WriteErrorResponse(w, 400, err.Error())
return
}
WriteJSONResponse(w, string(s), r.URL.Path, r.Host)
}

func Nodes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var params = HeightAndValidatorOptsParams{}
if err := PopModel(w, r, ps, &params); err != nil {
Expand Down
22 changes: 22 additions & 0 deletions app/cmd/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,28 @@ func TestRPC_QueryAccount(t *testing.T) {
stopCli()
}

func TestRPC_QueryAccounts(t *testing.T) {
codec.UpgradeHeight = 7000
_, _, cleanup := NewInMemoryTendermintNode(t, oneValTwoNodeGenesisState())
_, stopCli, evtChan := subscribeTo(t, tmTypes.EventNewBlock)
<-evtChan
kb := getInMemoryKeybase()
cb, err := kb.GetCoinbase()
assert.Nil(t, err)
var params = PaginatedHeightParams{
Height: 0,
}
address := cb.GetAddress().String()
q := newQueryRequest("accounts", newBody(params))
rec := httptest.NewRecorder()
Accounts(rec, q, httprouter.Params{})
body := rec.Body.String()
assert.True(t, strings.Contains(body, address))

cleanup()
stopCli()
}

func TestRPC_QueryNodes(t *testing.T) {
codec.UpgradeHeight = 7000
_, _, cleanup := NewInMemoryTendermintNode(t, oneValTwoNodeGenesisState())
Expand Down
2 changes: 2 additions & 0 deletions app/cmd/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func GetRoutes() Routes {
Route{Name: "Stop", Method: "POST", Path: "/v1/private/stop", HandlerFunc: Stop},
Route{Name: "ServiceCORS", Method: "OPTIONS", Path: "/v1/client/relay", HandlerFunc: Relay},
Route{Name: "QueryAccount", Method: "POST", Path: "/v1/query/account", HandlerFunc: Account},
Route{Name: "QueryAccounts", Method: "POST", Path: "/v1/query/accounts", HandlerFunc: Accounts},
Route{Name: "QueryAccountTxs", Method: "POST", Path: "/v1/query/accounttxs", HandlerFunc: AccountTxs},
Route{Name: "QueryACL", Method: "POST", Path: "/v1/query/acl", HandlerFunc: ACL},
Route{Name: "QueryAllParams", Method: "POST", Path: "/v1/query/allparams", HandlerFunc: AllParams},
Expand All @@ -120,6 +121,7 @@ func GetRoutes() Routes {
Route{Name: "QueryTX", Method: "POST", Path: "/v1/query/tx", HandlerFunc: Tx},
Route{Name: "QueryUpgrade", Method: "POST", Path: "/v1/query/upgrade", HandlerFunc: Upgrade},
Route{Name: "QuerySigningInfo", Method: "POST", Path: "/v1/query/signinginfo", HandlerFunc: SigningInfo},
Route{Name: "LocalNodes", Method: "POST", Path: "/v1/private/nodes", HandlerFunc: LocalNodes},
Route{Name: "QueryChains", Method: "POST", Path: "/v1/private/chains", HandlerFunc: Chains},
}
return routes
Expand Down
5 changes: 5 additions & 0 deletions app/cmd/rpc/types/public_pocket_node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package types

type PublicPocketNode struct {
Address string `json:"address"`
}
Loading