From c7b8fd82b9b9bc363d1e215a9d21618b8de0f839 Mon Sep 17 00:00:00 2001 From: Toshihito Kikuchi Date: Thu, 21 Dec 2023 00:32:15 -0800 Subject: [PATCH] address comments --- app/cmd/cli/node.go | 21 +- app/cmd/cli/txUtil.go | 2 +- app/cmd/rpc/rpc_test.go | 73 ++- codec/codec.go | 8 +- proto/x/nodes/msg.proto | 7 +- proto/x/nodes/nodes.proto | 18 +- types/config.go | 64 +-- x/auth/types/txbuilder.go | 29 +- x/nodes/handler.go | 15 +- x/nodes/keeper/params.go | 6 +- x/nodes/keeper/reward.go | 159 ++++-- x/nodes/keeper/reward_test.go | 113 +++- x/nodes/keeper/valStateChanges.go | 20 +- x/nodes/keeper/valStateChanges_test.go | 38 +- x/nodes/keeper/validator.go | 27 +- x/nodes/keeper/validator_test.go | 106 +--- x/nodes/types/errors.go | 68 +-- x/nodes/types/msg.go | 101 ++-- x/nodes/types/msg.pb.go | 128 ++--- x/nodes/types/msg_test.go | 45 +- x/nodes/types/nodes.pb.go | 714 +++---------------------- x/nodes/types/util_test.go | 17 + x/nodes/types/validator.go | 58 +- x/nodes/types/validator_legacy.go | 154 +----- x/pocketcore/keeper/claim.go | 14 +- x/pocketcore/types/expectedKeepers.go | 1 + x/pocketcore/types/service_test.go | 4 + 27 files changed, 762 insertions(+), 1248 deletions(-) diff --git a/app/cmd/cli/node.go b/app/cmd/cli/node.go index 1b8794950..acb74c8bf 100644 --- a/app/cmd/cli/node.go +++ b/app/cmd/cli/node.go @@ -118,8 +118,10 @@ Will prompt the user for the account passphrase.`, }, } +// stakeNewCmd is an upgraded version of `nodesCmd` that captures newer +// on-chain functionality in a cleaner way var stakeNewCmd = &cobra.Command{ - Use: `stakeNew [Memo]`, + Use: "stakeNew [Memo]", Short: "Stake a node in the network", Long: `Stake a node in the network, promoting it to a servicer or a validator. @@ -131,10 +133,23 @@ The command takes the following parameters. Stake Amount to stake in uPOKT ChainIDs Comma-separated chain IDs to host on the node ServiceURL Relay endpoint of the node. Must include the port number. - Delegators Delegator addresses to share rewards + RewardDelegators Addresses to share rewards NetworkID Network ID to submit a transaction to e.g. mainnet or testnet Fee Transaction fee in uPOKT - Memo Text to include in the transaction. No functional effect. + Memo Optional. Text to include in the transaction. No functional effect. + +Example: +$ pocket nodes stakeNew \ + e237efc54a93ed61689959e9afa0d4bd49fa11c0b946c35e6bebaccb052ce3fc \ + fe818527cd743866c1db6bdeb18731d04891df78 \ + 1164b9c95638fc201f35eca2af4c35fe0a81b6cf \ + 8000000000000 \ + DEAD,BEEF \ + https://x.com:443 \ + '{"1000000000000000000000000000000000000000":1,"2000000000000000000000000000000000000000":2}' \ + mainnet \ + 10000 \ + "new stake with delegators!" `, Args: cobra.MinimumNArgs(9), Run: func(cmd *cobra.Command, args []string) { diff --git a/app/cmd/cli/txUtil.go b/app/cmd/cli/txUtil.go index 6232ee5b9..0bccd4943 100644 --- a/app/cmd/cli/txUtil.go +++ b/app/cmd/cli/txUtil.go @@ -305,7 +305,7 @@ func BuildStakeTx( } if len(delegatorsStr) > 0 { - if json.Unmarshal([]byte(delegatorsStr), &msg.Delegators); err != nil { + if json.Unmarshal([]byte(delegatorsStr), &msg.RewardDelegators); err != nil { return nil, err } } diff --git a/app/cmd/rpc/rpc_test.go b/app/cmd/rpc/rpc_test.go index 9237bc106..976ba811f 100644 --- a/app/cmd/rpc/rpc_test.go +++ b/app/cmd/rpc/rpc_test.go @@ -2,11 +2,11 @@ package rpc import ( "bytes" + "encoding/base64" "encoding/hex" "encoding/json" "fmt" "io" - "io/ioutil" "math/rand" "net/http" "net/http/httptest" @@ -1471,7 +1471,7 @@ func newQueryRequest(query string, body io.Reader) *http.Request { func getResponse(rec *httptest.ResponseRecorder) string { res := rec.Result() defer res.Body.Close() - b, err := ioutil.ReadAll(res.Body) + b, err := io.ReadAll(res.Body) if err != nil { fmt.Println("could not read response: " + err.Error()) return "" @@ -1491,7 +1491,7 @@ func getResponse(rec *httptest.ResponseRecorder) string { func getJSONResponse(rec *httptest.ResponseRecorder) []byte { res := rec.Result() defer res.Body.Close() - b, err := ioutil.ReadAll(res.Body) + b, err := io.ReadAll(res.Body) if err != nil { panic("could not read response: " + err.Error()) } @@ -1635,8 +1635,52 @@ func NewValidChallengeProof(t *testing.T, privateKeys []crypto.PrivateKey) (chal return proof } +func generateTestTx() (string, error) { + app.Codec() + privKey, err := crypto.NewPrivateKey("5d86a93dee1ef5f950ccfaafd09d9c812f790c3b2c07945501f68b339118aca0e237efc54a93ed61689959e9afa0d4bd49fa11c0b946c35e6bebaccb052ce3fc") + if err != nil { + return "", err + } + outputAddr, err := types.AddressFromHex("fe818527cd743866c1db6bdeb18731d04891df78") + if err != nil { + return "", err + } + msg := &types2.MsgStake{ + PublicKey: privKey.PublicKey(), + Chains: []string{"DEAD", "BEEF"}, + Value: types.NewInt(8000000000000), + ServiceUrl: "https://x.com:443", + Output: outputAddr, + RewardDelegators: map[string]uint32{ + "1000000000000000000000000000000000000000": 1, + "2000000000000000000000000000000000000000": 2, + }, + } + builder := authTypes.NewTxBuilder( + auth.DefaultTxEncoder(app.Codec()), + auth.DefaultTxDecoder(app.Codec()), + "mainnet", + "memo", + types.NewCoins(types.NewCoin(types.DefaultStakeDenom, types.NewInt(10000))), + ) + entropy := int64(42) + txBytes, err := builder.BuildAndSignWithEntropyForTesting(privKey, msg, entropy) + if err != nil { + return "", err + } + return base64.StdEncoding.EncodeToString(txBytes), nil +} + +// TestMsgStake_Marshaling_BackwardCompatibility verifies MsgStake +// has backward compatibility before/after the Delegators upgrade, +// meaning this test passes without the Delegators patch. func TestMsgStake_Marshaling_BackwardCompatibility(t *testing.T) { - // Tx 3640B15041998FE800C2F61FC033CBF295D9282B5E7045A16F754ED9D8A54AFF in Mainnet + // StakeTxBeforeDelegatorsUpgrade is a transaction in Pocket Mainnet. + // You can get this with the following command. + // + // $ curl -s -X POST -H "Content-Type: application/json" \ + // -d '{"hash":"3640B15041998FE800C2F61FC033CBF295D9282B5E7045A16F754ED9D8A54AFF"}' \ + // /v1/query/tx | jq '.tx' StakeTxBeforeDelegatorsUpgrade := "/wIK4QEKFy94Lm5vZGVzLk1zZ1Byb3RvU3Rha2U4EsUBCiBzfNC5BqUX6Aow9768" + "QTKyYiRdhqrGqeqTIMVSckAe8RIEMDAwMxIEMDAwNBIEMDAwNRIEMDAwORIEMDAy" + @@ -1647,16 +1691,19 @@ func TestMsgStake_Marshaling_BackwardCompatibility(t *testing.T) { "w68+vl2z9nC+zYz3u4J7Oe3ntBOVP+cYHO5+lLuc8nH0OaG6pujXEPo19F5qW4Zh" + "NBEgtChJp+QhYVgIIiBDdXN0b2RpYWwgdG8gTm9uLUN1c3RvZGlhbCBhZ2FpbijS" + "CQ==" - + // StakeTxBeforeDelegatorsUpgrade is a transaction with the Delegators field. + // You can generate this transaction by uncommenting the following two lines. + // StakeTxAfterDelegatorsUpgrade, err := generateTestTx() + // assert.Nil(t, err) StakeTxAfterDelegatorsUpgrade := - "5wIK3gEKFy94Lm5vZGVzLk1zZ1Byb3RvU3Rha2U4EsIBCiDiN+/FSpPtYWiZWemv" + - "oNS9SfoRwLlGw15r66zLBSzj/BIEMDAwMRIEQkVFRhoNODAwMDAwMDAwMDAwMCIR" + + "3wIK3gEKFy94Lm5vZGVzLk1zZ1Byb3RvU3Rha2U4EsIBCiDiN+/FSpPtYWiZWemv" + + "oNS9SfoRwLlGw15r66zLBSzj/BIEREVBRBIEQkVFRhoNODAwMDAwMDAwMDAwMCIR" + "aHR0cHM6Ly94LmNvbTo0NDMqFP6BhSfNdDhmwdtr3rGHMdBIkd94MiwKKDIwMDAw" + "MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAQAjIsCigxMDAwMDAw" + "MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwEAESDgoFdXBva3QSBTEw" + - "MDAwGmQKICMRMWDdwHGZU6kMUecdxLF6UgHw0L1Vcc8lzz8Ynz0ZEkA+A9PANYsP" + - "+z7TduPuM7iM6jRILBJsdz0OMiGFrpGgJAsw7YrzXloJE4hyI921HoQ/bRFdw3/N" + - "Nea33C6VZqUGIgRtZW1vKKCQ7dyJ3LatFw==" + "MDAwGmQKIOI378VKk+1haJlZ6a+g1L1J+hHAuUbDXmvrrMsFLOP8EkDKz4AcELVB" + + "8Lyzi0+MVD/KXDIlTqjNLlBvFzOen7kZpR1it6gD79SLJXfWhB0qeu7Bux2VWQyf" + + "2wBBckGpIesBIgRtZW1vKCo=" originalNCUST := codec.UpgradeFeatureMap[codec.NonCustodialUpdateKey] t.Cleanup(func() { @@ -1670,17 +1717,19 @@ func TestMsgStake_Marshaling_BackwardCompatibility(t *testing.T) { // Initialize app.cdc app.Codec() + // Validate that an old stake messages DOES NOT have delegators stdTx, err := app.UnmarshalTxStr(StakeTxBeforeDelegatorsUpgrade, heightForProto) assert.Nil(t, err) msgStake, ok := stdTx.Msg.(*types2.MsgStake) assert.True(t, ok) - assert.Nil(t, msgStake.Delegators) + assert.Nil(t, msgStake.RewardDelegators) assert.Nil(t, msgStake.ValidateBasic()) + // Validate that an old stake messages DOES have delegators stdTx, err = app.UnmarshalTxStr(StakeTxAfterDelegatorsUpgrade, heightForProto) assert.Nil(t, err) msgStake, ok = stdTx.Msg.(*types2.MsgStake) assert.True(t, ok) - assert.NotNil(t, msgStake.Delegators) + assert.NotNil(t, msgStake.RewardDelegators) assert.Nil(t, msgStake.ValidateBasic()) } diff --git a/codec/codec.go b/codec/codec.go index 18ca368c5..a211337a7 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -60,7 +60,7 @@ const ( ClearUnjailedValSessionKey = "CRVAL" PerChainRTTM = "PerChainRTTM" AppTransferKey = "AppTransfer" - RewardsDelegatorKey = "RewardDelegator" + RewardDelegatorsKey = "RewardDelegators" ) func GetCodecUpgradeHeight() int64 { @@ -295,9 +295,9 @@ func (cdc *Codec) IsAfterAppTransferUpgrade(height int64) bool { TestMode <= -3 } -func (cdc *Codec) IsAfterDelegatorUpgrade(height int64) bool { - return (UpgradeFeatureMap[RewardsDelegatorKey] != 0 && - height >= UpgradeFeatureMap[RewardsDelegatorKey]) || +func (cdc *Codec) IsAfterRewardDelegatorUpgrade(height int64) bool { + return (UpgradeFeatureMap[RewardDelegatorsKey] != 0 && + height >= UpgradeFeatureMap[RewardDelegatorsKey]) || TestMode <= -3 } diff --git a/proto/x/nodes/msg.proto b/proto/x/nodes/msg.proto index 8463fa797..8e0a49d84 100755 --- a/proto/x/nodes/msg.proto +++ b/proto/x/nodes/msg.proto @@ -23,9 +23,10 @@ message MsgProtoStake { (gogoproto.jsontag) = "output_address,omitempty", (gogoproto.moretags) = "yaml:\"output_address\"" ]; - map Delegators = 6 [ - (gogoproto.jsontag) = "delegators,omitempty", - (gogoproto.moretags) = "yaml:\"delegators\"" + // Mapping from delegated-to addresses to a percentage of rewards. + map RewardDelegators = 6 [ + (gogoproto.jsontag) = "reward_delegators,omitempty", + (gogoproto.moretags) = "yaml:\"reward_delegators\"" ]; } diff --git a/proto/x/nodes/nodes.proto b/proto/x/nodes/nodes.proto index 0e5615335..58ddf12bf 100755 --- a/proto/x/nodes/nodes.proto +++ b/proto/x/nodes/nodes.proto @@ -20,23 +20,7 @@ message ProtoValidator { string StakedTokens = 7 [(gogoproto.customtype) = "github.com/pokt-network/pocket-core/types.BigInt", (gogoproto.jsontag) = "tokens", (gogoproto.nullable) = false]; google.protobuf.Timestamp UnstakingCompletionTime = 8 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true, (gogoproto.jsontag) = "unstaking_time", (gogoproto.moretags) = "yaml:\"unstaking_time\""]; bytes OutputAddress = 9 [(gogoproto.casttype) = "github.com/pokt-network/pocket-core/types.Address", (gogoproto.jsontag) = "output_address,omitempty", (gogoproto.moretags) = "yaml:\"output_address\""]; - map Delegators = 10 [(gogoproto.jsontag) = "delegators,omitempty", (gogoproto.moretags) = "yaml:\"delegators\""]; -} - -message ProtoValidatorV8 { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - option (gogoproto.goproto_getters) = false; - - bytes Address = 1 [(gogoproto.casttype) = "github.com/pokt-network/pocket-core/types.Address", (gogoproto.moretags) = "yaml:\"address\"", (gogoproto.jsontag) = "address"]; - bytes PublicKey = 2 [(gogoproto.moretags) = "yaml:\"public_key\"", (gogoproto.jsontag) = "public_key"]; - bool jailed = 3 [(gogoproto.jsontag) = "jailed"]; - int32 status = 4 [(gogoproto.jsontag) = "status"]; - repeated string Chains = 5 [(gogoproto.jsontag) = "chains"]; - string ServiceURL = 6 [(gogoproto.jsontag) = "service_url"]; - string StakedTokens = 7 [(gogoproto.customtype) = "github.com/pokt-network/pocket-core/types.BigInt", (gogoproto.jsontag) = "tokens", (gogoproto.nullable) = false]; - google.protobuf.Timestamp UnstakingCompletionTime = 8 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true, (gogoproto.jsontag) = "unstaking_time", (gogoproto.moretags) = "yaml:\"unstaking_time\""]; - bytes OutputAddress = 9 [(gogoproto.casttype) = "github.com/pokt-network/pocket-core/types.Address", (gogoproto.jsontag) = "output_address,omitempty", (gogoproto.moretags) = "yaml:\"output_address\""]; + map RewardDelegators = 10 [(gogoproto.jsontag) = "reward_delegators,omitempty", (gogoproto.moretags) = "yaml:\"reward_delegators\""]; } message LegacyProtoValidator { diff --git a/types/config.go b/types/config.go index 2773eaf07..700142da8 100644 --- a/types/config.go +++ b/types/config.go @@ -19,38 +19,38 @@ type SDKConfig struct { } type PocketConfig struct { - DataDir string `json:"data_dir"` - GenesisName string `json:"genesis_file"` - ChainsName string `json:"chains_name"` - EvidenceDBName string `json:"evidence_db_name"` - TendermintURI string `json:"tendermint_uri"` - KeybaseName string `json:"keybase_name"` - RPCPort string `json:"rpc_port"` - ClientBlockSyncAllowance int `json:"client_block_sync_allowance"` - ClientSessionSyncAllowance int64 `json:"client_session_sync_allowance"` - MaxEvidenceCacheEntires int `json:"max_evidence_cache_entries"` - MaxSessionCacheEntries int `json:"max_session_cache_entries"` - JSONSortRelayResponses bool `json:"json_sort_relay_responses"` - RemoteCLIURL string `json:"remote_cli_url"` - UserAgent string `json:"user_agent"` - ValidatorCacheSize int64 `json:"validator_cache_size"` - ApplicationCacheSize int64 `json:"application_cache_size"` - RPCTimeout int64 `json:"rpc_timeout"` - PrometheusAddr string `json:"pocket_prometheus_port"` - PrometheusMaxOpenfiles int `json:"prometheus_max_open_files"` - MaxClaimAgeForProofRetry int `json:"max_claim_age_for_proof_retry"` - ProofPrevalidation bool `json:"proof_prevalidation"` - CtxCacheSize int `json:"ctx_cache_size"` - ABCILogging bool `json:"abci_logging"` - RelayErrors bool `json:"show_relay_errors"` - DisableTxEvents bool `json:"disable_tx_events"` - Cache bool `json:"-"` - IavlCacheSize int64 `json:"iavl_cache_size"` - ChainsHotReload bool `json:"chains_hot_reload"` - GenerateTokenOnStart bool `json:"generate_token_on_start"` - LeanPocket bool `json:"lean_pocket"` - LeanPocketUserKeyFileName string `json:"lean_pocket_user_key_file"` - NotClaimPossiblyNegativeRewards bool `json:"not_claim_possibly_negative_rewards"` + DataDir string `json:"data_dir"` + GenesisName string `json:"genesis_file"` + ChainsName string `json:"chains_name"` + EvidenceDBName string `json:"evidence_db_name"` + TendermintURI string `json:"tendermint_uri"` + KeybaseName string `json:"keybase_name"` + RPCPort string `json:"rpc_port"` + ClientBlockSyncAllowance int `json:"client_block_sync_allowance"` + ClientSessionSyncAllowance int64 `json:"client_session_sync_allowance"` + MaxEvidenceCacheEntires int `json:"max_evidence_cache_entries"` + MaxSessionCacheEntries int `json:"max_session_cache_entries"` + JSONSortRelayResponses bool `json:"json_sort_relay_responses"` + RemoteCLIURL string `json:"remote_cli_url"` + UserAgent string `json:"user_agent"` + ValidatorCacheSize int64 `json:"validator_cache_size"` + ApplicationCacheSize int64 `json:"application_cache_size"` + RPCTimeout int64 `json:"rpc_timeout"` + PrometheusAddr string `json:"pocket_prometheus_port"` + PrometheusMaxOpenfiles int `json:"prometheus_max_open_files"` + MaxClaimAgeForProofRetry int `json:"max_claim_age_for_proof_retry"` + ProofPrevalidation bool `json:"proof_prevalidation"` + CtxCacheSize int `json:"ctx_cache_size"` + ABCILogging bool `json:"abci_logging"` + RelayErrors bool `json:"show_relay_errors"` + DisableTxEvents bool `json:"disable_tx_events"` + Cache bool `json:"-"` + IavlCacheSize int64 `json:"iavl_cache_size"` + ChainsHotReload bool `json:"chains_hot_reload"` + GenerateTokenOnStart bool `json:"generate_token_on_start"` + LeanPocket bool `json:"lean_pocket"` + LeanPocketUserKeyFileName string `json:"lean_pocket_user_key_file"` + PreventNegativeRewardClaim bool `json:"prevent_negative_reward_claim"` } func (c PocketConfig) GetLeanPocketUserKeyFilePath() string { diff --git a/x/auth/types/txbuilder.go b/x/auth/types/txbuilder.go index 38be47e77..98fd14837 100644 --- a/x/auth/types/txbuilder.go +++ b/x/auth/types/txbuilder.go @@ -3,13 +3,12 @@ package types import ( "errors" "fmt" - "github.com/tendermint/tendermint/libs/rand" "strings" "github.com/pokt-network/pocket-core/crypto" - crkeys "github.com/pokt-network/pocket-core/crypto/keys" sdk "github.com/pokt-network/pocket-core/types" + "github.com/tendermint/tendermint/libs/rand" ) // TxBuilder implements a transaction context created in SDK modules. @@ -113,6 +112,32 @@ func (bldr TxBuilder) BuildAndSign(address sdk.Address, privateKey crypto.Privat return bldr.txEncoder(NewTx(msg, bldr.fees, sig, bldr.memo, entropy), -1) } +// BuildAndSignWithEntropyForTesting signs a given message with a given +// private key and entropy. +// This is for testing use only. Use BuildAndSign for production use. +func (bldr TxBuilder) BuildAndSignWithEntropyForTesting( + privateKey crypto.PrivateKey, + msg sdk.ProtoMsg, + entropy int64, +) ([]byte, error) { + if bldr.chainID == "" { + return nil, errors.New("cant build and sign transaciton: the chainID is empty") + } + bytesToSign, err := StdSignBytes(bldr.chainID, entropy, bldr.fees, msg, bldr.memo) + if err != nil { + return nil, err + } + sigBytes, err := privateKey.Sign(bytesToSign) + if err != nil { + return nil, err + } + sig := StdSignature{ + Signature: sigBytes, + PublicKey: privateKey.PublicKey(), + } + return bldr.txEncoder(NewTx(msg, bldr.fees, sig, bldr.memo, entropy), -1) +} + // BuildAndSignWithKeyBase builds a single message to be signed, and signs a transaction // with the built message given a address, passphrase, and a set of messages. func (bldr TxBuilder) BuildAndSignWithKeyBase(address sdk.Address, passphrase string, msg sdk.ProtoMsg, legacyCodec bool) ([]byte, error) { diff --git a/x/nodes/handler.go b/x/nodes/handler.go index 541c19d95..37ec16422 100644 --- a/x/nodes/handler.go +++ b/x/nodes/handler.go @@ -60,13 +60,20 @@ func handleStake(ctx sdk.Ctx, msg types.MsgStake, k keeper.Keeper, signer crypto } } - if !k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) && - msg.Delegators != nil { - msg.Delegators = nil + if k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) { + if err := msg.CheckRewardDelegators(); err != nil { + return err.Result() + } + } else if msg.RewardDelegators != nil { + // Ignore the delegators field before the upgrade + msg.RewardDelegators = nil } validator := types.NewValidatorFromMsg(msg) - // StakedTokens is set through StakeValidator. Resetting to 0 for now. + // We used to use NewValidator to initialize the `validator` that does not + // set the field StakedTokens. On the other hand, NewValidatorFromMsg sets + // the field StakedTokens. To keep the same behavior, we reset StakedTokens + // to 0 and leave StakedTokens to be set through StakeValidator below. validator.StakedTokens = sdk.ZeroInt() // check if they can stake if err := k.ValidateValidatorStaking(ctx, validator, msg.Value, sdk.Address(signer.Address())); err != nil { diff --git a/x/nodes/keeper/params.go b/x/nodes/keeper/params.go index d6b3e80c2..c410ce897 100644 --- a/x/nodes/keeper/params.go +++ b/x/nodes/keeper/params.go @@ -144,7 +144,7 @@ func (k Keeper) ServicerStakeFloorMultiplierExponent(ctx sdk.Ctx) (res sdk.BigDe return } -// Split rewards into node's cut and feeCollector's cut (= DAO + Proposer) +// Split block rewards into the node's cut and the feeCollector's (DAO + Proposer) cut func (k Keeper) splitRewards( ctx sdk.Ctx, reward sdk.BigInt, @@ -164,7 +164,7 @@ func (k Keeper) splitRewards( return } -// Split feeCollector's cut into DAO and Propower +// Split feeCollector's cut into the DAO's cut and the Proposer's cut func (k Keeper) splitFeesCollected( ctx sdk.Ctx, feesCollected sdk.BigInt, @@ -178,7 +178,7 @@ func (k Keeper) splitFeesCollected( // dao cut calculation truncates int ex: 1.99uPOKT = 1uPOKT daoCut = feesCollected.ToDec().Mul(daoAllocation).TruncateInt() - // proposer is whatever is left + // proposer gets whatever is left after the DAO's truncated rewards are taken out proposerCut = feesCollected.Sub(daoCut) return } diff --git a/x/nodes/keeper/reward.go b/x/nodes/keeper/reward.go index 78c1b880b..58121b60a 100644 --- a/x/nodes/keeper/reward.go +++ b/x/nodes/keeper/reward.go @@ -1,6 +1,8 @@ package keeper import ( + "encoding/json" + "errors" "fmt" "github.com/pokt-network/pocket-core/codec" @@ -8,46 +10,67 @@ import ( govTypes "github.com/pokt-network/pocket-core/x/gov/types" "github.com/pokt-network/pocket-core/x/nodes/types" pcTypes "github.com/pokt-network/pocket-core/x/pocketcore/types" + "github.com/tendermint/tendermint/libs/log" ) +// GetRewardCost - The cost a servicer needs to pay to earn relay rewards +func (k Keeper) GetRewardCost(ctx sdk.Ctx) sdk.BigInt { + return k.AccountKeeper.GetFee(ctx, pcTypes.MsgClaim{}). + Add(k.AccountKeeper.GetFee(ctx, pcTypes.MsgProof{})) +} + // RewardForRelays - Award coins to an address using the default multiplier func (k Keeper) RewardForRelays(ctx sdk.Ctx, relays sdk.BigInt, address sdk.Address) sdk.BigInt { return k.RewardForRelaysPerChain(ctx, "", relays, address) } -// CalculateRelayReward - Calculate the amount of rewards based on the given -// number of relays and the staked tokens. The returned reward amount includes -// DAO & Proposer portions. +func (k Keeper) calculateRewardRewardPip22( + ctx sdk.Ctx, + relays, stake, multiplier sdk.BigInt, +) sdk.BigInt { + // floorstake to the lowest bin multiple or take ceiling, whichever is smaller + flooredStake := sdk.MinInt( + stake.Sub(stake.Mod(k.ServicerStakeFloorMultiplier(ctx))), + k.ServicerStakeWeightCeiling(ctx). + Sub(k.ServicerStakeWeightCeiling(ctx). + Mod(k.ServicerStakeFloorMultiplier(ctx))), + ) + // Convert from tokens to a BIN number + bin := flooredStake.Quo(k.ServicerStakeFloorMultiplier(ctx)) + // calculate the weight value, weight will be a floatng point number so cast + // to DEC here and then truncate back to big int + weight := bin.ToDec(). + FracPow( + k.ServicerStakeFloorMultiplierExponent(ctx), + Pip22ExponentDenominator, + ). + Quo(k.ServicerStakeWeightMultiplier(ctx)) + coinsDecimal := multiplier.ToDec().Mul(relays.ToDec()).Mul(weight) + // truncate back to int + return coinsDecimal.TruncateInt() +} + +// CalculateRelayReward - Calculates the amount of rewards based on the given +// number of relays and the staked tokens, and splits it to the servicer's cut +// and the DAO & Proposer cut. func (k Keeper) CalculateRelayReward( ctx sdk.Ctx, chain string, relays sdk.BigInt, stake sdk.BigInt, -) (sdk.BigInt, sdk.BigInt) { - // feature flags - isAfterRSCAL := k.Cdc.IsAfterNamedFeatureActivationHeight(ctx.BlockHeight(), codec.RSCALKey) +) (nodeReward, feesCollected sdk.BigInt) { + isAfterRSCAL := k.Cdc.IsAfterNamedFeatureActivationHeight( + ctx.BlockHeight(), + codec.RSCALKey, + ) multiplier := k.GetChainSpecificMultiplier(ctx, chain) var coins sdk.BigInt - //check if PIP22 is enabled, if so scale the rewards if isAfterRSCAL { - //floorstake to the lowest bin multiple or take ceiling, whicherver is smaller - flooredStake := sdk.MinInt( - stake.Sub(stake.Mod(k.ServicerStakeFloorMultiplier(ctx))), - k.ServicerStakeWeightCeiling(ctx). - Sub(k.ServicerStakeWeightCeiling(ctx).Mod(k.ServicerStakeFloorMultiplier(ctx))), - ) - //Convert from tokens to a BIN number - bin := flooredStake.Quo(k.ServicerStakeFloorMultiplier(ctx)) - //calculate the weight value, weight will be a floatng point number so cast - // to DEC here and then truncate back to big int - weight := bin.ToDec(). - FracPow(k.ServicerStakeFloorMultiplierExponent(ctx), Pip22ExponentDenominator). - Quo(k.ServicerStakeWeightMultiplier(ctx)) - coinsDecimal := multiplier.ToDec().Mul(relays.ToDec()).Mul(weight) - //truncate back to int - coins = coinsDecimal.TruncateInt() + // scale the rewards if PIP22 is enabled + coins = k.calculateRewardRewardPip22(ctx, relays, stake, multiplier) } else { + // otherwise just apply rttm coins = multiplier.Mul(relays) } @@ -101,24 +124,41 @@ func (k Keeper) RewardForRelaysPerChain(ctx sdk.Ctx, chain string, relays sdk.Bi toNode, toFeeCollector := k.CalculateRelayReward(ctx, chain, relays, validator.GetTokens()) - if k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) { - rewardCost := k.AccountKeeper.GetFee(ctx, pcTypes.MsgClaim{}). - Add(k.AccountKeeper.GetFee(ctx, pcTypes.MsgProof{})) + // After the delegator upgrade, we compensate a servicer's operator wallet + // for the transaction fee of claim and proof. + if k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) { + rewardCost := k.GetRewardCost(ctx) if toNode.LT(rewardCost) { + // If the servicer's portion is less than the reward cost, we send + // all of the servicer's portion to the servicer and no reward is sent + // to the output address or delegators. This case causes a net loss to + // the servicer. If prevent_negative_reward_claim is set to true, + // a servicer will not claim for tiny evidences that cause a net loss. rewardCost = toNode } - k.mint(ctx, rewardCost, validator.Address) - toNode = toNode.Sub(rewardCost) + if rewardCost.IsPositive() { + k.mint(ctx, rewardCost, validator.Address) + toNode = toNode.Sub(rewardCost) + } } - SplitNodeRewards( + err := SplitNodeRewards( + ctx.Logger(), toNode, address, - validator.Delegators, + validator.RewardDelegators, func(recipient sdk.Address, share sdk.BigInt) { k.mint(ctx, share, recipient) }, ) + if err != nil { + ctx.Logger().Error("unable to split relay rewards", + "height", ctx.BlockHeight(), + "servicer", validator.Address, + "err", err.Error(), + ) + } + if toFeeCollector.IsPositive() { k.mint(ctx, toFeeCollector, k.getFeePool(ctx).GetAddress()) } @@ -127,44 +167,47 @@ func (k Keeper) RewardForRelaysPerChain(ctx sdk.Ctx, chain string, relays sdk.Bi // Splits rewards into the primary recipient and delegator addresses and // invokes a callback per share. +// delegators - a map from address to its share (< 100) +// shareRewardsCallback - a callback to send `coins` of total rewards to `addr` func SplitNodeRewards( + logger log.Logger, rewards sdk.BigInt, primaryRecipient sdk.Address, delegators map[string]uint32, - callback func(sdk.Address, sdk.BigInt), -) { + shareRewardsCallback func(addr sdk.Address, coins sdk.BigInt), +) error { if !rewards.IsPositive() { - return + return errors.New("non-positive rewards") } - totalShare := int64(0) - for _, share := range delegators { - totalShare = totalShare + int64(share) - if totalShare > 100 { - // If the total shares for delegators exceeds 100, - // all rewards go to the primary recipient. - delegators = nil - break - } + normalizedDelegators, err := types.NormalizeRewardDelegators(delegators) + if err != nil { + // If the delegators field is invalid, do nothing. + return errors.New("invalid delegators") } remains := rewards - for addrStr, share := range delegators { - addr, err := sdk.AddressFromHex(addrStr) - if err != nil { - continue - } - percentage := sdk.NewDecWithPrec(int64(share), 2) + for _, pair := range normalizedDelegators { + percentage := sdk.NewDecWithPrec(int64(pair.RewardShare), 2) allocation := rewards.ToDec().Mul(percentage).TruncateInt() if allocation.IsPositive() { - callback(addr, allocation) + shareRewardsCallback(pair.Address, allocation) } remains = remains.Sub(allocation) } if remains.IsPositive() { - callback(primaryRecipient, remains) + shareRewardsCallback(primaryRecipient, remains) + } else { + delegatorsBytes, _ := json.Marshal(delegators) + logger.Error( + "over-distributed rewards to delegators", + "rewards", rewards, + "remains", remains, + "delegators", string(delegatorsBytes), + ) } + return nil } // Calculates a chain-specific Relays-To-Token-Multiplier. @@ -211,14 +254,15 @@ func (k Keeper) blockReward(ctx sdk.Ctx, previousProposer sdk.Address) { return } - if !k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) { - validator.Delegators = nil + if !k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) { + validator.RewardDelegators = nil } - SplitNodeRewards( + err := SplitNodeRewards( + ctx.Logger(), proposerCut, k.GetOutputAddressFromValidator(validator), - validator.Delegators, + validator.RewardDelegators, func(recipient sdk.Address, share sdk.BigInt) { err = k.AccountKeeper.SendCoins( ctx, @@ -236,6 +280,13 @@ func (k Keeper) blockReward(ctx sdk.Ctx, previousProposer sdk.Address) { } }, ) + if err != nil { + ctx.Logger().Error("unable to split block rewards", + "height", ctx.BlockHeight(), + "validator", validator.Address, + "err", err.Error(), + ) + } return } diff --git a/x/nodes/keeper/reward_test.go b/x/nodes/keeper/reward_test.go index 41eb12cf3..509bb1717 100644 --- a/x/nodes/keeper/reward_test.go +++ b/x/nodes/keeper/reward_test.go @@ -8,8 +8,8 @@ import ( "github.com/pokt-network/pocket-core/codec" sdk "github.com/pokt-network/pocket-core/types" "github.com/pokt-network/pocket-core/x/nodes/types" - pcTypes "github.com/pokt-network/pocket-core/x/pocketcore/types" "github.com/stretchr/testify/assert" + "github.com/tendermint/tendermint/libs/log" ) type args struct { @@ -99,17 +99,16 @@ func verifyAccountBalance( ) { acc := k.GetAccount(ctx, address) expectedCoins := sdk.NewCoins(sdk.NewCoin("upokt", expected)) - assert.True(t, acc.Coins.IsEqual(expectedCoins)) - if !acc.Coins.IsEqual(expectedCoins) { - fmt.Println( - "Balance mismatch", + assert.True( + t, + acc.Coins.IsEqual(expectedCoins), + fmt.Sprintf( + "Balance mismatch in %v, actual=%v expected=%v", address, - "actual=", acc.Coins, - "expected=", expectedCoins, - ) - } + ), + ) } func TestKeeper_rewardFromFees(t *testing.T) { @@ -226,8 +225,7 @@ func TestKeeper_rewardFromRelays(t *testing.T) { AmountOf("upokt") relays := sdk.NewInt(10000) - rewardCost := keeper.AccountKeeper.GetFee(context, pcTypes.MsgClaim{}). - Add(keeper.AccountKeeper.GetFee(context, pcTypes.MsgProof{})) + rewardCost := keeper.GetRewardCost(context) totalReward := relays.Mul(keeper.RelaysToTokensMultiplier(context)) nodeReward, _ := keeper.splitRewards(context, totalReward) outputReward := nodeReward.Sub(rewardCost) @@ -477,6 +475,7 @@ func TestKeeper_rewardFromRelaysPIP22EXP(t *testing.T) { func TestKeeper_RewardForRelaysPerChain(t *testing.T) { Height_PIP22 := int64(3) Height_PerChainRTTM := int64(10) + Height_Delegator := int64(10) Chain_Normal := "0001" Chain_HighProfit := "0002" RTTM_Default := int64(10000) @@ -494,6 +493,10 @@ func TestKeeper_RewardForRelaysPerChain(t *testing.T) { QuoRaw(100) } + originalFeatureMap := codec.UpgradeFeatureMap + t.Cleanup(func() { + codec.UpgradeFeatureMap = originalFeatureMap + }) codec.UpgradeFeatureMap[codec.RSCALKey] = Height_PIP22 codec.UpgradeFeatureMap[codec.PerChainRTTM] = Height_PerChainRTTM @@ -557,8 +560,23 @@ func TestKeeper_RewardForRelaysPerChain(t *testing.T) { NumOfRelays, validator.Address, ) - assert.True(t, rewardsHighProfit.Equal(ExpectedRewards(RTTM_High))) + expectedRewardsHighProfit := ExpectedRewards(RTTM_High) + assert.True(t, rewardsHighProfit.Equal(expectedRewardsHighProfit)) assert.True(t, rewardsDefault.LT(rewardsHighProfit)) + + // After the RewardDelegators upgrade, a servicer is compensated for + // the reward cost (= transactions fees). Therefore the expected rewards + // is decreased by the reward cost. + codec.UpgradeFeatureMap[codec.RewardDelegatorsKey] = Height_Delegator + rewardCost := keeper.GetRewardCost(ctx) + expectedRewardsHighProfit = expectedRewardsHighProfit.Sub(rewardCost) + rewardsHighProfit = keeper.RewardForRelaysPerChain( + ctx, + Chain_HighProfit, + NumOfRelays, + validator.Address, + ) + assert.True(t, rewardsHighProfit.Equal(expectedRewardsHighProfit)) } func toArray(addr sdk.Address) [sdk.AddrLen]byte { @@ -578,7 +596,7 @@ func TestKeeper_SplitNodeRewards(t *testing.T) { callback := func(addr sdk.Address, rewards sdk.BigInt) { result[toArray(addr)] = rewards } - + logger := log.NewNopLogger() recipient, _ := sdk.AddressFromHex("ffffffffffffffffffffffffffffffffffffffff") verifyResult := func( @@ -594,6 +612,9 @@ func TestKeeper_SplitNodeRewards(t *testing.T) { continue } assert.True(t, found, "Rewards not dispatched") + if !found { + continue + } assert.Equal(t, expectedBalance, rewardsResult.Uint64(), "Wrong rewards") totalRewards = totalRewards.Sub(rewardsResult) } @@ -607,6 +628,9 @@ func TestKeeper_SplitNodeRewards(t *testing.T) { return } assert.True(t, found) + if !found { + return + } assert.True(t, reward.Equal(totalRewards)) } @@ -626,29 +650,74 @@ func TestKeeper_SplitNodeRewards(t *testing.T) { // All goes to the default recipient. result = map[[sdk.AddrLen]byte]sdk.BigInt{} - SplitNodeRewards(totalBig, recipient, delegatorMap([]uint32{}), callback) + SplitNodeRewards( + logger, + totalBig, + recipient, + delegatorMap([]uint32{}), + callback, + ) verifyResult(t, totalBig, []uint64{}) // All goes to the delegator. result = map[[sdk.AddrLen]byte]sdk.BigInt{} - SplitNodeRewards(totalBig, recipient, delegatorMap([]uint32{100}), callback) + SplitNodeRewards( + logger, + totalBig, + recipient, + delegatorMap([]uint32{100}), + callback, + ) verifyResult(t, totalBig, []uint64{totalBig.Uint64()}) // Multiple delegators. Remainder goes to the recipient. result = map[[sdk.AddrLen]byte]sdk.BigInt{} - SplitNodeRewards(totalBig, recipient, delegatorMap([]uint32{1, 0, 2, 30, 50}), callback) - verifyResult(t, totalBig, []uint64{100, 0, 200, 3001, 5002}) + SplitNodeRewards( + logger, + totalBig, + recipient, + delegatorMap([]uint32{1, 2, 30, 50}), + callback, + ) + verifyResult(t, totalBig, []uint64{100, 200, 3001, 5002}) // Share less than a single token is truncated. result = map[[sdk.AddrLen]byte]sdk.BigInt{} - SplitNodeRewards(totalSmall, recipient, delegatorMap([]uint32{1, 1, 1, 1}), callback) + SplitNodeRewards( + logger, + totalSmall, + recipient, + delegatorMap([]uint32{1, 1, 1, 1}), + callback, + ) verifyResult(t, totalSmall, []uint64{}) result = map[[sdk.AddrLen]byte]sdk.BigInt{} - SplitNodeRewards(totalSmall, recipient, delegatorMap([]uint32{1, 2}), callback) + SplitNodeRewards( + logger, + totalSmall, + recipient, + delegatorMap([]uint32{1, 2}), + callback, + ) verifyResult(t, totalSmall, []uint64{0, 1}) - // Invalid delegator map: all goes to the recipient + // Invalid delegator map: nothing happens result = map[[sdk.AddrLen]byte]sdk.BigInt{} - SplitNodeRewards(totalSmall, recipient, delegatorMap([]uint32{1, 0xffffffff}), callback) - verifyResult(t, totalSmall, []uint64{}) + SplitNodeRewards( + logger, + totalSmall, + recipient, + delegatorMap([]uint32{1, 0xffffffff}), // exceeds 100, no overflow + callback, + ) + assert.Zero(t, len(result)) + result = map[[sdk.AddrLen]byte]sdk.BigInt{} + SplitNodeRewards( + logger, + totalSmall, + recipient, + delegatorMap([]uint32{1, 2, 0}), // zero share + callback, + ) + assert.Zero(t, len(result)) } diff --git a/x/nodes/keeper/valStateChanges.go b/x/nodes/keeper/valStateChanges.go index a6e4646bd..ac33b42bb 100644 --- a/x/nodes/keeper/valStateChanges.go +++ b/x/nodes/keeper/valStateChanges.go @@ -262,12 +262,18 @@ func (k Keeper) ValidateEditStake(ctx sdk.Ctx, currentValidator, newValidtor typ } } - // Delegators can be set/edited only if 1) the feature has been activated - // AND 2) the message is signed by the operator address. - if k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) && - !types.CompareStringMaps(currentValidator.Delegators, newValidtor.Delegators) && + // Following PIP-32, RewardDelegators can be set/edited only if: + // 1) The feature has been activated AND + // 2) the message is signed by the operator address. + // For more details, see + // https://forum.pokt.network/t/pip32-unleashing-the-potential-of-non-custodial-node-running/4796 + if k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) && + !types.CompareStringMaps( + currentValidator.RewardDelegators, + newValidtor.RewardDelegators, + ) && !signer.Equals(currentValidator.Address) { - return types.ErrDisallowedOutputAddressEdit(k.Codespace()) + return types.ErrDisallowedRewardDelegatorEdit(k.Codespace()) } // prevent waiting vals from modifying anything @@ -339,8 +345,8 @@ func (k Keeper) EditStakeValidator(ctx sdk.Ctx, currentValidator, updatedValidat } // After the upgrade, we allow delegators change - if k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) { - currentValidator.Delegators = updatedValidator.Delegators + if k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) { + currentValidator.RewardDelegators = updatedValidator.RewardDelegators } } // update chains diff --git a/x/nodes/keeper/valStateChanges_test.go b/x/nodes/keeper/valStateChanges_test.go index 2950aca58..a476ac9d3 100644 --- a/x/nodes/keeper/valStateChanges_test.go +++ b/x/nodes/keeper/valStateChanges_test.go @@ -500,13 +500,13 @@ func TestValidatorStateChange_Delegators(t *testing.T) { originalTestMode := codec.TestMode originalNCUST := codec.UpgradeFeatureMap[codec.NonCustodialUpdateKey] originalOEDIT := codec.UpgradeFeatureMap[codec.OutputAddressEditKey] - originalDELE := codec.UpgradeFeatureMap[codec.DelegatorsKey] + originalReward := codec.UpgradeFeatureMap[codec.RewardDelegatorsKey] t.Cleanup(func() { codec.UpgradeHeight = originalUpgradeHeight codec.TestMode = originalTestMode codec.UpgradeFeatureMap[codec.NonCustodialUpdateKey] = originalNCUST codec.UpgradeFeatureMap[codec.OutputAddressEditKey] = originalOEDIT - codec.UpgradeFeatureMap[codec.DelegatorsKey] = originalDELE + codec.UpgradeFeatureMap[codec.RewardDelegatorsKey] = originalReward }) // Enable EditStake, NCUST, and OEDIT @@ -534,12 +534,12 @@ func TestValidatorStateChange_Delegators(t *testing.T) { signer crypto.PublicKey, ) sdk.Error { msgStake := types.MsgStake{ - Chains: []string{"0021", "0040"}, - ServiceUrl: "https://www.pokt.network:443", - Value: stakeAmount.Amount, - PublicKey: operatorPubkey, - Output: outputAddress, - Delegators: delegators, + Chains: []string{"0021", "0040"}, + ServiceUrl: "https://www.pokt.network:443", + Value: stakeAmount.Amount, + PublicKey: operatorPubkey, + Output: outputAddress, + RewardDelegators: delegators, } return handleStakeForTesting(ctx, k, msgStake, signer) } @@ -547,41 +547,47 @@ func TestValidatorStateChange_Delegators(t *testing.T) { singleDelegator := map[string]uint32{} singleDelegator[getRandomValidatorAddress().String()] = 1 - // Attempt to set a delegators before DELE upgrade --> The field is ignored + // Attempt to set a delegators before the upgrade --> The field is ignored assert.Nil(t, runStake(operatorPubKey1, singleDelegator, outputPubKey)) validatorCur, found := k.GetValidator(ctx, operatorAddr1) assert.True(t, found) - assert.Nil(t, validatorCur.Delegators) + assert.Nil(t, validatorCur.RewardDelegators) - // Enable DELE - codec.UpgradeFeatureMap[codec.DelegatorsKey] = -1 + // Enable RewardDelegators + codec.UpgradeFeatureMap[codec.RewardDelegatorsKey] = -1 // Attempt to change the delegators with output's signature --> Fail err := runStake(operatorPubKey1, singleDelegator, outputPubKey) assert.NotNil(t, err) assert.Equal(t, k.codespace, err.Codespace()) - assert.Equal(t, types.CodeDisallowedOutputAddressEdit, err.Code()) + assert.Equal(t, types.CodeDisallowedRewardDelegatorEdit, err.Code()) // Attempt to set the delegators with operator's signature --> Success err = runStake(operatorPubKey1, singleDelegator, operatorPubKey1) assert.Nil(t, err) validatorCur, found = k.GetValidator(ctx, operatorAddr1) assert.True(t, found) - assert.True(t, types.CompareStringMaps(validatorCur.Delegators, singleDelegator)) + assert.True( + t, + types.CompareStringMaps(validatorCur.RewardDelegators, singleDelegator), + ) // Attempt to reset the delegators with operator's signature --> Success err = runStake(operatorPubKey1, nil, operatorPubKey1) assert.Nil(t, err) validatorCur, found = k.GetValidator(ctx, operatorAddr1) assert.True(t, found) - assert.Nil(t, validatorCur.Delegators) + assert.Nil(t, validatorCur.RewardDelegators) // New stake with delegators can be signed by the output --> Success err = runStake(operatorPubKey2, singleDelegator, outputPubKey) assert.Nil(t, err) validatorCur, found = k.GetValidator(ctx, operatorAddr2) assert.True(t, found) - assert.True(t, types.CompareStringMaps(validatorCur.Delegators, singleDelegator)) + assert.True( + t, + types.CompareStringMaps(validatorCur.RewardDelegators, singleDelegator), + ) } func TestKeeper_JailValidator(t *testing.T) { diff --git a/x/nodes/keeper/validator.go b/x/nodes/keeper/validator.go index 489ed32f1..92161cebd 100644 --- a/x/nodes/keeper/validator.go +++ b/x/nodes/keeper/validator.go @@ -11,15 +11,10 @@ import ( func (k Keeper) MarshalValidator(ctx sdk.Ctx, validator types.Validator) ([]byte, error) { if k.Cdc.IsAfterNonCustodialUpgrade(ctx.BlockHeight()) { - if k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) { - bz, err := k.Cdc.MarshalBinaryLengthPrefixed(&validator, ctx.BlockHeight()) - if err != nil { - ctx.Logger().Error("could not marshal validator: " + err.Error()) - } - return bz, err + if !k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) { + validator.RewardDelegators = nil } - v := validator.ToLegacy8() - bz, err := k.Cdc.MarshalBinaryLengthPrefixed(&v, ctx.BlockHeight()) + bz, err := k.Cdc.MarshalBinaryLengthPrefixed(&validator, ctx.BlockHeight()) if err != nil { ctx.Logger().Error("could not marshal validator: " + err.Error()) } @@ -35,19 +30,15 @@ func (k Keeper) MarshalValidator(ctx sdk.Ctx, validator types.Validator) ([]byte func (k Keeper) UnmarshalValidator(ctx sdk.Ctx, valBytes []byte) (val types.Validator, err error) { if k.Cdc.IsAfterNonCustodialUpgrade(ctx.BlockHeight()) { - if k.Cdc.IsAfterDelegatorUpgrade(ctx.BlockHeight()) { - err = k.Cdc.UnmarshalBinaryLengthPrefixed(valBytes, &val, ctx.BlockHeight()) - if err != nil { - ctx.Logger().Error("could not unmarshal validator: " + err.Error()) + err = k.Cdc.UnmarshalBinaryLengthPrefixed(valBytes, &val, ctx.BlockHeight()) + if err == nil { + if !k.Cdc.IsAfterRewardDelegatorUpgrade(ctx.BlockHeight()) { + val.RewardDelegators = nil } - return val, err - } - v := types.LegacyValidator8{} - err = k.Cdc.UnmarshalBinaryLengthPrefixed(valBytes, &v, ctx.BlockHeight()) - if err != nil { + } else { ctx.Logger().Error("could not unmarshal validator: " + err.Error()) } - return v.ToValidator(), err + return val, err } v := types.LegacyValidator{} err = k.Cdc.UnmarshalBinaryLengthPrefixed(valBytes, &v, ctx.BlockHeight()) diff --git a/x/nodes/keeper/validator_test.go b/x/nodes/keeper/validator_test.go index 73034fd2a..befbb420d 100644 --- a/x/nodes/keeper/validator_test.go +++ b/x/nodes/keeper/validator_test.go @@ -150,63 +150,18 @@ func Test_sortNoLongerStakedValidators(t *testing.T) { } } -// There are three versions of structs to represent a validator. -// - LegacyValidator - the original version -// - LegacyValidator8 - LegacyValidator + OutputAddress (introduced in 0.8) -// - Validator - LegacyValidator8 + Delegators (introduced in 0.11) +// There are two versions of structs to represent a validator. +// - LegacyValidator - the original version +// - Validator - LegacyValidator + OutputAddress + Delegators (since 0.11) // -// The following two tests verify marshaling/unmarshaling has backward/forward +// The following test verifies marshaling/unmarshaling has backward/forward // compatibility, meaning marshaled bytes can be unmarshaled as a newer version // or an older version. -func TestValidator_Amino_MarshalingCompatibility(t *testing.T) { - _, _, k := createTestInput(t, false) - Marshal := k.Cdc.AminoCodec().MarshalBinaryLengthPrefixed - Unmarshal := k.Cdc.AminoCodec().UnmarshalBinaryLengthPrefixed - - // Amino cannot handle type.Validator because map is not supported. - // We don't have to test type.Validator because it didn't exist while - // we were using Amino (before UpgradeCodecHeight). - var ( - val_1, val_2 types.LegacyValidator8 - valL_1, valL_2 types.LegacyValidator - marshaled []byte - err error - ) - - val_1 = getStakedValidator().ToLegacy8() - val_1.OutputAddress = getRandomValidatorAddress() - valL_1 = val_1.ToLegacy() - - // Validator --> []byte --> Validator - marshaled, err = Marshal(&val_1) - assert.Nil(t, err) - assert.NotNil(t, marshaled) - val_2.Reset() - err = Unmarshal(marshaled, &val_2) - assert.Nil(t, err) - assert.True(t, val_2.ToLegacy().ExactEqualsTo(val_1.ToLegacy())) - assert.True(t, val_2.OutputAddress.Equals(val_1.OutputAddress)) - - // Validator --> []byte --> LegacyValidator - marshaled, err = Marshal(&val_1) - assert.Nil(t, err) - assert.NotNil(t, marshaled) - valL_2.Reset() - err = Unmarshal(marshaled, &valL_2) - assert.Nil(t, err) - assert.True(t, valL_2.ExactEqualsTo(val_1.ToLegacy())) - - // LegacyValidator --> []byte --> Validator - marshaled, err = Marshal(&valL_1) - assert.Nil(t, err) - assert.NotNil(t, marshaled) - val_2.Reset() - err = Unmarshal(marshaled, &val_2) - assert.Nil(t, err) - assert.True(t, val_2.ToLegacy().ExactEqualsTo(valL_1)) - assert.Nil(t, val_2.OutputAddress) -} - +// +// We cover the Proto marshaler only because Amino marshaler does not support +// a map type used in handle type.Validator. +// We used Amino before UpgradeCodecHeight and we no longer use it, so it's +// ok not to cover Amino. func TestValidator_Proto_MarshalingCompatibility(t *testing.T) { _, _, k := createTestInput(t, false) Marshal := k.Cdc.ProtoCodec().MarshalBinaryLengthPrefixed @@ -214,7 +169,6 @@ func TestValidator_Proto_MarshalingCompatibility(t *testing.T) { var ( val_1, val_2 types.Validator - val8_1, val8_2 types.LegacyValidator8 valL_1, valL_2 types.LegacyValidator marshaled []byte err error @@ -222,10 +176,9 @@ func TestValidator_Proto_MarshalingCompatibility(t *testing.T) { val_1 = getStakedValidator() val_1.OutputAddress = getRandomValidatorAddress() - val_1.Delegators = map[string]uint32{} - val_1.Delegators[getRandomValidatorAddress().String()] = 10 - val_1.Delegators[getRandomValidatorAddress().String()] = 20 - val8_1 = val_1.ToLegacy8() + val_1.RewardDelegators = map[string]uint32{} + val_1.RewardDelegators[getRandomValidatorAddress().String()] = 10 + val_1.RewardDelegators[getRandomValidatorAddress().String()] = 20 valL_1 = val_1.ToLegacy() // Validator --> []byte --> Validator @@ -235,19 +188,13 @@ func TestValidator_Proto_MarshalingCompatibility(t *testing.T) { val_2.Reset() err = Unmarshal(marshaled, &val_2) assert.Nil(t, err) - assert.True(t, val_2.ToLegacy().ExactEqualsTo(val_1.ToLegacy())) + assert.True(t, val_2.ToLegacy().Equals(val_1.ToLegacy())) assert.True(t, val_2.OutputAddress.Equals(val_1.OutputAddress)) - assert.True(t, types.CompareStringMaps(val_2.Delegators, val_1.Delegators)) - - // Validator --> []byte --> LegacyValidator8 - marshaled, err = Marshal(&val_1) - assert.Nil(t, err) - assert.NotNil(t, marshaled) - val8_2.Reset() - err = Unmarshal(marshaled, &val8_2) - assert.Nil(t, err) - assert.True(t, val8_2.ToLegacy().ExactEqualsTo(val_1.ToLegacy())) - assert.True(t, val8_2.OutputAddress.Equals(val_1.OutputAddress)) + assert.NotNil(t, val_2.RewardDelegators) + assert.True( + t, + types.CompareStringMaps(val_2.RewardDelegators, val_1.RewardDelegators), + ) // Validator --> []byte --> LegacyValidator marshaled, err = Marshal(&val_1) @@ -256,18 +203,7 @@ func TestValidator_Proto_MarshalingCompatibility(t *testing.T) { valL_2.Reset() err = Unmarshal(marshaled, &valL_2) assert.Nil(t, err) - assert.True(t, valL_2.ExactEqualsTo(val_1.ToLegacy())) - - // LegacyValidator8 --> []byte --> Validator - marshaled, err = Marshal(&val8_1) - assert.Nil(t, err) - assert.NotNil(t, marshaled) - val_2.Reset() - err = Unmarshal(marshaled, &val_2) - assert.Nil(t, err) - assert.True(t, val_2.ToLegacy().ExactEqualsTo(val8_1.ToLegacy())) - assert.True(t, val_2.OutputAddress.Equals(val8_1.OutputAddress)) - assert.Nil(t, val_2.Delegators) + assert.True(t, valL_2.Equals(val_1.ToLegacy())) // LegacyValidator --> []byte --> Validator marshaled, err = Marshal(&valL_1) @@ -276,7 +212,7 @@ func TestValidator_Proto_MarshalingCompatibility(t *testing.T) { val_2.Reset() err = Unmarshal(marshaled, &val_2) assert.Nil(t, err) - assert.True(t, val_2.ToLegacy().ExactEqualsTo(valL_1)) + assert.True(t, val_2.ToLegacy().Equals(valL_1)) assert.Nil(t, val_2.OutputAddress) - assert.Nil(t, val_2.Delegators) + assert.Nil(t, val_2.RewardDelegators) } diff --git a/x/nodes/types/errors.go b/x/nodes/types/errors.go index 09a4eb3aa..ebc1c44e7 100644 --- a/x/nodes/types/errors.go +++ b/x/nodes/types/errors.go @@ -10,34 +10,35 @@ import ( type CodeType = sdk.CodeType const ( - DefaultCodespace sdk.CodespaceType = ModuleName - CodeInvalidValidator CodeType = 101 - CodeInvalidDelegation CodeType = 102 - CodeInvalidInput CodeType = 103 - CodeValidatorJailed CodeType = 104 - CodeValidatorNotJailed CodeType = 105 - CodeMissingSelfDelegation CodeType = 106 - CodeMissingSigningInfo CodeType = 108 - CodeBadSend CodeType = 109 - CodeInvalidStatus CodeType = 110 - CodeMinimumStake CodeType = 111 - CodeNotEnoughCoins CodeType = 112 - CodeValidatorTombstoned CodeType = 113 - CodeCantHandleEvidence CodeType = 114 - CodeNoChains CodeType = 115 - CodeNoServiceURL CodeType = 116 - CodeWaitingValidator CodeType = 117 - CodeInvalidServiceURL CodeType = 118 - CodeInvalidNetworkIdentifier CodeType = 119 - CodeTooManyChains CodeType = 120 - CodeStateConvertError CodeType = 121 - CodeMinimumEditStake CodeType = 122 - CodeNilOutputAddr CodeType = 123 - CodeUnequalOutputAddr CodeType = 124 - CodeUnauthorizedSigner CodeType = 125 - CodeNilSigner CodeType = 126 - CodeDisallowedOutputAddressEdit CodeType = 127 - CodeInvalidaDelegators CodeType = 128 + DefaultCodespace sdk.CodespaceType = ModuleName + CodeInvalidValidator CodeType = 101 + CodeInvalidDelegation CodeType = 102 + CodeInvalidInput CodeType = 103 + CodeValidatorJailed CodeType = 104 + CodeValidatorNotJailed CodeType = 105 + CodeMissingSelfDelegation CodeType = 106 + CodeMissingSigningInfo CodeType = 108 + CodeBadSend CodeType = 109 + CodeInvalidStatus CodeType = 110 + CodeMinimumStake CodeType = 111 + CodeNotEnoughCoins CodeType = 112 + CodeValidatorTombstoned CodeType = 113 + CodeCantHandleEvidence CodeType = 114 + CodeNoChains CodeType = 115 + CodeNoServiceURL CodeType = 116 + CodeWaitingValidator CodeType = 117 + CodeInvalidServiceURL CodeType = 118 + CodeInvalidNetworkIdentifier CodeType = 119 + CodeTooManyChains CodeType = 120 + CodeStateConvertError CodeType = 121 + CodeMinimumEditStake CodeType = 122 + CodeNilOutputAddr CodeType = 123 + CodeUnequalOutputAddr CodeType = 124 + CodeUnauthorizedSigner CodeType = 125 + CodeNilSigner CodeType = 126 + CodeDisallowedOutputAddressEdit CodeType = 127 + CodeInvalidRewardDelegators CodeType = 128 + CodeDisallowedRewardDelegatorEdit CodeType = 129 ) func ErrTooManyChains(codespace sdk.CodespaceType) sdk.Error { @@ -162,7 +163,12 @@ func ErrDisallowedOutputAddressEdit(codespace sdk.CodespaceType) sdk.Error { "Only the owner of the current output address can edit the output address") } -func ErrInvalidDelegators(codespace sdk.CodespaceType, reason string) sdk.Error { - return sdk.NewError(codespace, CodeInvalidaDelegators, - "Invalid delegators: %s", reason) +func ErrInvalidRewardDelegators(codespace sdk.CodespaceType, reason string) sdk.Error { + return sdk.NewError(codespace, CodeInvalidRewardDelegators, + "Invalid reward delegators: %s", reason) +} + +func ErrDisallowedRewardDelegatorEdit(codespace sdk.CodespaceType) sdk.Error { + return sdk.NewError(codespace, CodeDisallowedRewardDelegatorEdit, + "Only the node operator address can edit reward delegators") } diff --git a/x/nodes/types/msg.go b/x/nodes/types/msg.go index d7d26bdbe..fbc23d13c 100644 --- a/x/nodes/types/msg.go +++ b/x/nodes/types/msg.go @@ -148,12 +148,12 @@ var _ codec.ProtoMarshaler = &MsgStake{} // MsgStake - struct for staking transactions type MsgStake struct { - PublicKey crypto.PublicKey `json:"public_key" yaml:"public_key"` - Chains []string `json:"chains" yaml:"chains"` - Value sdk.BigInt `json:"value" yaml:"value"` - ServiceUrl string `json:"service_url" yaml:"service_url"` - Output sdk.Address `json:"output_address,omitempty" yaml:"output_address"` - Delegators map[string]uint32 `json:"delegators,omitempty" yaml:"delegators"` + PublicKey crypto.PublicKey `json:"public_key" yaml:"public_key"` + Chains []string `json:"chains" yaml:"chains"` + Value sdk.BigInt `json:"value" yaml:"value"` + ServiceUrl string `json:"service_url" yaml:"service_url"` + Output sdk.Address `json:"output_address,omitempty" yaml:"output_address"` + RewardDelegators map[string]uint32 `json:"reward_delegators,omitempty" yaml:"reward_delegators"` } func (msg *MsgStake) Marshal() ([]byte, error) { @@ -187,12 +187,12 @@ func (msg *MsgStake) Unmarshal(data []byte) error { return err } newMsg := MsgStake{ - PublicKey: publicKey, - Chains: m.Chains, - Value: m.Value, - ServiceUrl: m.ServiceUrl, - Output: m.OutputAddress, - Delegators: m.Delegators, + PublicKey: publicKey, + Chains: m.Chains, + Value: m.Value, + ServiceUrl: m.ServiceUrl, + Output: m.OutputAddress, + RewardDelegators: m.RewardDelegators, } *msg = newMsg return nil @@ -233,16 +233,9 @@ func (msg MsgStake) ValidateBasic() sdk.Error { if err := ValidateServiceURL(msg.ServiceUrl); err != nil { return err } - if msg.Delegators != nil { - totalShares := uint32(0) - for addrStr, share := range msg.Delegators { - if _, err := sdk.AddressFromHex(addrStr); err != nil { - return ErrInvalidDelegators(DefaultCodespace, err.Error()) - } - totalShares = totalShares + share - if totalShares > 100 { - return ErrInvalidDelegators(DefaultCodespace, "Total share exceeds 100") - } + if msg.RewardDelegators != nil { + if err := msg.CheckRewardDelegators(); err != nil { + return err } } return nil @@ -269,8 +262,8 @@ func (msg *MsgStake) XXX_MessageName() string { func (msg MsgStake) String() string { delegatorsStr := "" - if msg.Delegators != nil { - if jsonBytes, err := json.Marshal(msg.Delegators); err == nil { + if msg.RewardDelegators != nil { + if jsonBytes, err := json.Marshal(msg.RewardDelegators); err == nil { delegatorsStr = string(jsonBytes) } else { delegatorsStr = err.Error() @@ -280,7 +273,7 @@ func (msg MsgStake) String() string { Chains: %s Value: %s OutputAddress: %s -Delegators: %s +RewardDelegators: %s `, msg.PublicKey.RawString(), msg.Chains, @@ -303,12 +296,12 @@ func (msg MsgStake) ToProto() MsgProtoStake { pubKeyBz = msg.PublicKey.RawBytes() } return MsgProtoStake{ - Publickey: pubKeyBz, - Chains: msg.Chains, - Value: msg.Value, - ServiceUrl: msg.ServiceUrl, - OutputAddress: msg.Output, - Delegators: msg.Delegators, + Publickey: pubKeyBz, + Chains: msg.Chains, + Value: msg.Value, + ServiceUrl: msg.ServiceUrl, + OutputAddress: msg.Output, + RewardDelegators: msg.RewardDelegators, } } @@ -319,6 +312,52 @@ func (msg MsgStake) CheckServiceUrlLength(url string) sdk.Error { return nil } +func (msg MsgStake) CheckRewardDelegators() sdk.Error { + _, err := NormalizeRewardDelegators(msg.RewardDelegators) + return err +} + +type AddressAndShare struct { + Address sdk.Address + RewardShare uint32 // always positive +} + +// NormalizeRewardDelegators returns an slice of delegator addresses and +// their shares if the map is valid. +func NormalizeRewardDelegators( + delegators map[string]uint32, +) ([]AddressAndShare, sdk.Error) { + normalized := make([]AddressAndShare, 0, len(delegators)) + totalShares := uint64(0) + for addrStr, rewardShare := range delegators { + if rewardShare == 0 { + return nil, ErrInvalidRewardDelegators( + DefaultCodespace, + "Reward share must be positive", + ) + } + + addr, err := sdk.AddressFromHex(addrStr) + if err != nil { + return nil, ErrInvalidRewardDelegators(DefaultCodespace, err.Error()) + } + + totalShares += uint64(rewardShare) + if totalShares > 100 { + return nil, ErrInvalidRewardDelegators( + DefaultCodespace, + fmt.Sprintf("Total share %d exceeds 100", totalShares), + ) + } + + normalized = append(normalized, AddressAndShare{ + Address: addr, + RewardShare: rewardShare, + }) + } + return normalized, nil +} + func (*MsgProtoStake) XXX_MessageName() string { return "x.nodes.MsgProtoStake8" } diff --git a/x/nodes/types/msg.pb.go b/x/nodes/types/msg.pb.go index 2c6f12326..eb8ec33d7 100644 --- a/x/nodes/types/msg.pb.go +++ b/x/nodes/types/msg.pb.go @@ -31,7 +31,8 @@ type MsgProtoStake struct { Value github_com_pokt_network_pocket_core_types.BigInt `protobuf:"bytes,3,opt,name=value,proto3,customtype=github.com/pokt-network/pocket-core/types.BigInt" json:"value" yaml:"value"` ServiceUrl string `protobuf:"bytes,4,opt,name=ServiceUrl,proto3" json:"service_url" yaml:"service_url"` OutputAddress github_com_pokt_network_pocket_core_types.Address `protobuf:"bytes,5,opt,name=OutputAddress,proto3,casttype=github.com/pokt-network/pocket-core/types.Address" json:"output_address,omitempty" yaml:"output_address"` - Delegators map[string]uint32 `protobuf:"bytes,6,rep,name=Delegators,proto3" json:"delegators,omitempty" yaml:"delegators" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + // Mapping from delegated-to addresses to a percentage of rewards. + RewardDelegators map[string]uint32 `protobuf:"bytes,6,rep,name=RewardDelegators,proto3" json:"reward_delegators,omitempty" yaml:"reward_delegators" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` } func (m *MsgProtoStake) Reset() { *m = MsgProtoStake{} } @@ -315,7 +316,7 @@ func (*MsgSend) XXX_MessageName() string { } func init() { proto.RegisterType((*MsgProtoStake)(nil), "x.nodes.MsgProtoStake") - proto.RegisterMapType((map[string]uint32)(nil), "x.nodes.MsgProtoStake.DelegatorsEntry") + proto.RegisterMapType((map[string]uint32)(nil), "x.nodes.MsgProtoStake.RewardDelegatorsEntry") proto.RegisterType((*LegacyMsgProtoStake)(nil), "x.nodes.LegacyMsgProtoStake") proto.RegisterType((*MsgBeginUnstake)(nil), "x.nodes.MsgBeginUnstake") proto.RegisterType((*LegacyMsgBeginUnstake)(nil), "x.nodes.LegacyMsgBeginUnstake") @@ -327,55 +328,56 @@ func init() { func init() { proto.RegisterFile("x/nodes/msg.proto", fileDescriptor_0de9b62fa75e413f) } var fileDescriptor_0de9b62fa75e413f = []byte{ - // 762 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0xb1, 0x6f, 0xd3, 0x4a, - 0x1c, 0xce, 0x25, 0xaf, 0x89, 0x72, 0x4d, 0xda, 0xd7, 0x6b, 0x2b, 0x59, 0x7d, 0x52, 0x2e, 0xf2, - 0xd3, 0x7b, 0xca, 0xf0, 0x9a, 0x3c, 0xe8, 0x82, 0x22, 0x31, 0x34, 0x50, 0x24, 0x04, 0x11, 0xc5, - 0xa1, 0x08, 0x21, 0xa4, 0xe2, 0x26, 0x57, 0xd7, 0x8d, 0xed, 0x8b, 0xec, 0x73, 0x48, 0x16, 0x84, - 0x98, 0xba, 0x80, 0x3a, 0xc2, 0x56, 0xb1, 0xc0, 0x9f, 0x52, 0x89, 0xa5, 0x23, 0x62, 0x38, 0xa1, -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, - 0xd4, 0x1d, 0xad, 0x41, 0xac, 0x16, 0x7a, 0x0a, 0x67, 0x6f, 0xd8, 0xd4, 0x8c, 0x67, 0xe9, 0x91, - 0xc7, 0x71, 0x6e, 0xd7, 0xa6, 0xe6, 0x58, 0xcb, 0x16, 0x85, 0xac, 0x71, 0x74, 0x4a, 0x6d, 0xe3, - 0x84, 0xa8, 0x0b, 0xb3, 0xf7, 0x68, 0xc8, 0x2e, 0x2c, 0x7b, 0x30, 0x1c, 0xa1, 0x8c, 0x8e, 0x71, - 0x07, 0x23, 0x34, 0xc2, 0xa6, 0x64, 0x8e, 0xa8, 0x50, 0x1b, 0xa6, 0x55, 0x93, 0xba, 0x16, 0x0b, - 0x66, 0x68, 0xe3, 0x02, 0x33, 0x34, 0xb8, 0x29, 0x9a, 0xd7, 0x62, 0x2d, 0x2b, 0x41, 0xa1, 0x9a, - 0x0b, 0x5b, 0x7f, 0xf0, 0x06, 0x83, 0xda, 0xad, 0xe3, 0xd3, 0x02, 0x38, 0x39, 0x2d, 0x80, 0x4f, - 0xa7, 0x05, 0x70, 0x78, 0x56, 0x48, 0x9c, 0x9c, 0x15, 0x12, 0x1f, 0xce, 0x0a, 0x89, 0x87, 0xe7, - 0x7a, 0xa5, 0xf0, 0x77, 0xca, 0x17, 0xb1, 0x93, 0xf6, 0x7f, 0x99, 0xd6, 0xbe, 0x05, 0x00, 0x00, - 0xff, 0xff, 0xfb, 0xe0, 0xcf, 0x4b, 0x66, 0x09, 0x00, 0x00, + // 776 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0xbf, 0x6b, 0x1b, 0x49, + 0x14, 0xd6, 0x48, 0x67, 0x09, 0x8d, 0x25, 0xff, 0x18, 0xdb, 0xb0, 0xd8, 0xa0, 0x11, 0x7b, 0x1c, + 0xa8, 0xb0, 0xa5, 0xbb, 0x73, 0x73, 0xe8, 0x2a, 0xcb, 0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 0x67, 0x4f, 0x8d, 0x09, 0x00, 0x00, } func (this *MsgProtoStake) Equal(that interface{}) bool { @@ -417,11 +419,11 @@ func (this *MsgProtoStake) Equal(that interface{}) bool { if !bytes.Equal(this.OutputAddress, that1.OutputAddress) { return false } - if len(this.Delegators) != len(that1.Delegators) { + if len(this.RewardDelegators) != len(that1.RewardDelegators) { return false } - for i := range this.Delegators { - if this.Delegators[i] != that1.Delegators[i] { + for i := range this.RewardDelegators { + if this.RewardDelegators[i] != that1.RewardDelegators[i] { return false } } @@ -617,9 +619,9 @@ func (m *MsgProtoStake) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Delegators) > 0 { - for k := range m.Delegators { - v := m.Delegators[k] + if len(m.RewardDelegators) > 0 { + for k := range m.RewardDelegators { + v := m.RewardDelegators[k] baseI := i i = encodeVarintMsg(dAtA, i, uint64(v)) i-- @@ -951,8 +953,8 @@ func (m *MsgProtoStake) Size() (n int) { if l > 0 { n += 1 + l + sovMsg(uint64(l)) } - if len(m.Delegators) > 0 { - for k, v := range m.Delegators { + if len(m.RewardDelegators) > 0 { + for k, v := range m.RewardDelegators { _ = k _ = v mapEntrySize := 1 + len(k) + sovMsg(uint64(len(k))) + 1 + sovMsg(uint64(v)) @@ -1269,7 +1271,7 @@ func (m *MsgProtoStake) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Delegators", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardDelegators", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1296,8 +1298,8 @@ func (m *MsgProtoStake) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Delegators == nil { - m.Delegators = make(map[string]uint32) + if m.RewardDelegators == nil { + m.RewardDelegators = make(map[string]uint32) } var mapkey string var mapvalue uint32 @@ -1378,7 +1380,7 @@ func (m *MsgProtoStake) Unmarshal(dAtA []byte) error { iNdEx += skippy } } - m.Delegators[mapkey] = mapvalue + m.RewardDelegators[mapkey] = mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/nodes/types/msg_test.go b/x/nodes/types/msg_test.go index e9da81725..21b14aaf4 100644 --- a/x/nodes/types/msg_test.go +++ b/x/nodes/types/msg_test.go @@ -670,38 +670,45 @@ func TestMsgStake_Delegators(t *testing.T) { delegator1 := crypto.Ed25519PrivateKey{}.GenPrivateKey() delegator2 := crypto.Ed25519PrivateKey{}.GenPrivateKey() msg := MsgStake{ - PublicKey: operator.PublicKey(), - Chains: []string{"0001", "0040", "03DF"}, - Value: sdk.NewInt(1000000000000), - ServiceUrl: "https://pokt.network:1", - Output: sdk.Address(output.PublicKey().Address()), - Delegators: map[string]uint32{}, + PublicKey: operator.PublicKey(), + Chains: []string{"0001", "0040", "03DF"}, + Value: sdk.NewInt(1000000000000), + ServiceUrl: "https://pokt.network:1", + Output: sdk.Address(output.PublicKey().Address()), + RewardDelegators: nil, } assert.Nil(t, msg.ValidateBasic()) + msg.RewardDelegators = map[string]uint32{} + invalidAddr := "1234" - msg.Delegators[invalidAddr] = 10 + msg.RewardDelegators[invalidAddr] = 10 err := msg.ValidateBasic() assert.NotNil(t, err) - assert.Equal(t, CodeInvalidaDelegators, err.Code()) + assert.Equal(t, CodeInvalidRewardDelegators, err.Code()) - // [0] - delete(msg.Delegators, invalidAddr) - msg.Delegators[delegator1.PublicKey().Address().String()] = 0 - assert.Nil(t, msg.ValidateBasic()) + // RewardDelegators: {delegator1: 0} + delete(msg.RewardDelegators, invalidAddr) + msg.RewardDelegators[delegator1.PublicKey().Address().String()] = 0 + assert.NotNil(t, err) + assert.Equal(t, CodeInvalidRewardDelegators, err.Code()) - // [100] - msg.Delegators[delegator1.PublicKey().Address().String()] = 100 + // RewardDelegators: {delegator1: 100} + msg.RewardDelegators[delegator1.PublicKey().Address().String()] = 100 assert.Nil(t, msg.ValidateBasic()) - // [100, 1] - msg.Delegators[delegator2.PubKey().Address().String()] = 1 + // Delegators: {delegator1: 100, delegator2: 1} + msg.RewardDelegators[delegator2.PubKey().Address().String()] = 1 err = msg.ValidateBasic() assert.NotNil(t, err) - assert.Equal(t, CodeInvalidaDelegators, err.Code()) + assert.Equal(t, CodeInvalidRewardDelegators, err.Code()) + + // Delegators: {delegator1: 99, delegator2: 1} + msg.RewardDelegators[delegator1.PublicKey().Address().String()] = 99 + assert.Nil(t, msg.ValidateBasic()) - // [99, 1] - msg.Delegators[delegator1.PublicKey().Address().String()] = 99 + // Delegators: {delegator1: 98, delegator2: 1} + msg.RewardDelegators[delegator1.PublicKey().Address().String()] = 98 assert.Nil(t, msg.ValidateBasic()) } diff --git a/x/nodes/types/nodes.pb.go b/x/nodes/types/nodes.pb.go index 43aaf80fa..33e729066 100644 --- a/x/nodes/types/nodes.pb.go +++ b/x/nodes/types/nodes.pb.go @@ -9,8 +9,8 @@ import ( proto "github.com/cosmos/gogoproto/proto" github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" _ "github.com/gogo/protobuf/gogoproto" + _ "github.com/golang/protobuf/ptypes/timestamp" github_com_pokt_network_pocket_core_types "github.com/pokt-network/pocket-core/types" - _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" @@ -39,7 +39,7 @@ type ProtoValidator struct { StakedTokens github_com_pokt_network_pocket_core_types.BigInt `protobuf:"bytes,7,opt,name=StakedTokens,proto3,customtype=github.com/pokt-network/pocket-core/types.BigInt" json:"tokens"` UnstakingCompletionTime time.Time `protobuf:"bytes,8,opt,name=UnstakingCompletionTime,proto3,stdtime" json:"unstaking_time" yaml:"unstaking_time"` OutputAddress github_com_pokt_network_pocket_core_types.Address `protobuf:"bytes,9,opt,name=OutputAddress,proto3,casttype=github.com/pokt-network/pocket-core/types.Address" json:"output_address,omitempty" yaml:"output_address"` - Delegators map[string]uint32 `protobuf:"bytes,10,rep,name=Delegators,proto3" json:"delegators,omitempty" yaml:"delegators" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + RewardDelegators map[string]uint32 `protobuf:"bytes,10,rep,name=RewardDelegators,proto3" json:"reward_delegators,omitempty" yaml:"reward_delegators" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` } func (m *ProtoValidator) Reset() { *m = ProtoValidator{} } @@ -75,51 +75,6 @@ func (m *ProtoValidator) XXX_DiscardUnknown() { var xxx_messageInfo_ProtoValidator proto.InternalMessageInfo -type ProtoValidatorV8 struct { - Address github_com_pokt_network_pocket_core_types.Address `protobuf:"bytes,1,opt,name=Address,proto3,casttype=github.com/pokt-network/pocket-core/types.Address" json:"address" yaml:"address"` - PublicKey []byte `protobuf:"bytes,2,opt,name=PublicKey,proto3" json:"public_key" yaml:"public_key"` - Jailed bool `protobuf:"varint,3,opt,name=jailed,proto3" json:"jailed"` - Status int32 `protobuf:"varint,4,opt,name=status,proto3" json:"status"` - Chains []string `protobuf:"bytes,5,rep,name=Chains,proto3" json:"chains"` - ServiceURL string `protobuf:"bytes,6,opt,name=ServiceURL,proto3" json:"service_url"` - StakedTokens github_com_pokt_network_pocket_core_types.BigInt `protobuf:"bytes,7,opt,name=StakedTokens,proto3,customtype=github.com/pokt-network/pocket-core/types.BigInt" json:"tokens"` - UnstakingCompletionTime time.Time `protobuf:"bytes,8,opt,name=UnstakingCompletionTime,proto3,stdtime" json:"unstaking_time" yaml:"unstaking_time"` - OutputAddress github_com_pokt_network_pocket_core_types.Address `protobuf:"bytes,9,opt,name=OutputAddress,proto3,casttype=github.com/pokt-network/pocket-core/types.Address" json:"output_address,omitempty" yaml:"output_address"` -} - -func (m *ProtoValidatorV8) Reset() { *m = ProtoValidatorV8{} } -func (m *ProtoValidatorV8) String() string { return proto.CompactTextString(m) } -func (*ProtoValidatorV8) ProtoMessage() {} -func (*ProtoValidatorV8) Descriptor() ([]byte, []int) { - return fileDescriptor_63cb49073b61e33a, []int{1} -} -func (m *ProtoValidatorV8) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ProtoValidatorV8) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ProtoValidatorV8.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ProtoValidatorV8) XXX_Merge(src proto.Message) { - xxx_messageInfo_ProtoValidatorV8.Merge(m, src) -} -func (m *ProtoValidatorV8) XXX_Size() int { - return m.Size() -} -func (m *ProtoValidatorV8) XXX_DiscardUnknown() { - xxx_messageInfo_ProtoValidatorV8.DiscardUnknown(m) -} - -var xxx_messageInfo_ProtoValidatorV8 proto.InternalMessageInfo - type LegacyProtoValidator struct { Address github_com_pokt_network_pocket_core_types.Address `protobuf:"bytes,1,opt,name=Address,proto3,casttype=github.com/pokt-network/pocket-core/types.Address" json:"address" yaml:"address"` PublicKey []byte `protobuf:"bytes,2,opt,name=PublicKey,proto3" json:"public_key" yaml:"public_key"` @@ -135,7 +90,7 @@ func (m *LegacyProtoValidator) Reset() { *m = LegacyProtoValidator{} } func (m *LegacyProtoValidator) String() string { return proto.CompactTextString(m) } func (*LegacyProtoValidator) ProtoMessage() {} func (*LegacyProtoValidator) Descriptor() ([]byte, []int) { - return fileDescriptor_63cb49073b61e33a, []int{2} + return fileDescriptor_63cb49073b61e33a, []int{1} } func (m *LegacyProtoValidator) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -181,7 +136,7 @@ type ValidatorSigningInfo struct { func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } func (*ValidatorSigningInfo) ProtoMessage() {} func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_63cb49073b61e33a, []int{3} + return fileDescriptor_63cb49073b61e33a, []int{2} } func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -254,8 +209,7 @@ func (m *ValidatorSigningInfo) GetJailedBlocksCounter() int64 { func init() { proto.RegisterType((*ProtoValidator)(nil), "x.nodes.ProtoValidator") - proto.RegisterMapType((map[string]uint32)(nil), "x.nodes.ProtoValidator.DelegatorsEntry") - proto.RegisterType((*ProtoValidatorV8)(nil), "x.nodes.ProtoValidatorV8") + proto.RegisterMapType((map[string]uint32)(nil), "x.nodes.ProtoValidator.RewardDelegatorsEntry") proto.RegisterType((*LegacyProtoValidator)(nil), "x.nodes.LegacyProtoValidator") proto.RegisterType((*ValidatorSigningInfo)(nil), "x.nodes.ValidatorSigningInfo") } @@ -263,62 +217,61 @@ func init() { func init() { proto.RegisterFile("x/nodes/nodes.proto", fileDescriptor_63cb49073b61e33a) } var fileDescriptor_63cb49073b61e33a = []byte{ - // 867 bytes of a gzipped FileDescriptorProto + // 858 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x96, 0xbf, 0x6f, 0xdb, 0x46, - 0x14, 0xc7, 0xc5, 0xc8, 0xb2, 0xac, 0x93, 0xe2, 0xa4, 0xb4, 0x82, 0x12, 0x46, 0xa1, 0x13, 0xd8, - 0x21, 0x1a, 0x6a, 0xb2, 0x4d, 0x96, 0xd4, 0x40, 0x80, 0x86, 0x6e, 0x81, 0xba, 0x09, 0xd0, 0x80, - 0xb6, 0x33, 0x64, 0x21, 0x28, 0xf2, 0x44, 0x5f, 0xf8, 0xe3, 0x08, 0xde, 0xd1, 0xb5, 0xfe, 0x83, - 0x76, 0xf3, 0x98, 0xd1, 0x73, 0xff, 0x92, 0x8c, 0x59, 0x0a, 0x14, 0x1d, 0xae, 0x85, 0x0d, 0x14, - 0x05, 0x47, 0x01, 0x5d, 0x3a, 0x15, 0xbc, 0xa3, 0x22, 0xd1, 0x70, 0x8b, 0xc0, 0xe8, 0x54, 0x68, - 0x11, 0xef, 0xbe, 0xef, 0xdd, 0xfb, 0x3e, 0xf1, 0x3e, 0x0f, 0x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0x9c, 0x44, 0x12, 0xc0, 0xff, 0xbf, 0x8d, + 0x51, 0x75, 0x1b, 0xb5, 0x7d, 0x0b, 0x97, 0x65, 0x55, 0xdd, 0x44, 0x57, 0x49, 0x27, 0xa5, 0xa2, + 0xc7, 0x60, 0x27, 0x26, 0x8c, 0x61, 0xdf, 0x19, 0x47, 0xd4, 0x0b, 0x99, 0xe3, 0xd1, 0x3c, 0xe1, + 0x38, 0x33, 0x5a, 0xb2, 0xfd, 0xcf, 0x0b, 0x01, 0x57, 0x27, 0xcc, 0x04, 0xfc, 0x40, 0x39, 0xac, + 0x0c, 0x9b, 0x68, 0x4b, 0xe9, 0xb6, 0x94, 0x0f, 0x94, 0x5a, 0xda, 0x55, 0x0d, 0x5d, 0xb3, 0x5b, + 0x5f, 0xd8, 0xad, 0x4c, 0x58, 0xd8, 0xad, 0x0c, 0x9b, 0x68, 0x4b, 0xe9, 0x35, 0xbb, 0xfd, 0x8d, + 0xa7, 0x17, 0xb0, 0x51, 0x72, 0x65, 0xdf, 0x7b, 0x76, 0xd9, 0xd7, 0x9e, 0x5f, 0xf6, 0xb5, 0x3f, + 0x2f, 0xfb, 0xda, 0xf9, 0x55, 0xbf, 0xf1, 0xfc, 0xaa, 0xdf, 0xf8, 0xed, 0xaa, 0xdf, 0x78, 0xf8, + 0x4a, 0xe0, 0xcc, 0xff, 0x27, 0x49, 0x80, 0xc6, 0xeb, 0xf2, 0x1a, 0xee, 0xfc, 0x1b, 0x00, 0x00, + 0xff, 0xff, 0x49, 0xf4, 0x43, 0x35, 0x3f, 0x09, 0x00, 0x00, } func (this *ProtoValidator) Equal(that interface{}) bool { @@ -372,67 +325,14 @@ func (this *ProtoValidator) Equal(that interface{}) bool { if !bytes.Equal(this.OutputAddress, that1.OutputAddress) { return false } - if len(this.Delegators) != len(that1.Delegators) { - return false - } - for i := range this.Delegators { - if this.Delegators[i] != that1.Delegators[i] { - return false - } - } - return true -} -func (this *ProtoValidatorV8) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ProtoValidatorV8) - if !ok { - that2, ok := that.(ProtoValidatorV8) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !bytes.Equal(this.Address, that1.Address) { - return false - } - if !bytes.Equal(this.PublicKey, that1.PublicKey) { - return false - } - if this.Jailed != that1.Jailed { - return false - } - if this.Status != that1.Status { - return false - } - if len(this.Chains) != len(that1.Chains) { + if len(this.RewardDelegators) != len(that1.RewardDelegators) { return false } - for i := range this.Chains { - if this.Chains[i] != that1.Chains[i] { + for i := range this.RewardDelegators { + if this.RewardDelegators[i] != that1.RewardDelegators[i] { return false } } - if this.ServiceURL != that1.ServiceURL { - return false - } - if !this.StakedTokens.Equal(that1.StakedTokens) { - return false - } - if !this.UnstakingCompletionTime.Equal(that1.UnstakingCompletionTime) { - return false - } - if !bytes.Equal(this.OutputAddress, that1.OutputAddress) { - return false - } return true } func (this *LegacyProtoValidator) Equal(that interface{}) bool { @@ -544,9 +444,9 @@ func (m *ProtoValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Delegators) > 0 { - for k := range m.Delegators { - v := m.Delegators[k] + if len(m.RewardDelegators) > 0 { + for k := range m.RewardDelegators { + v := m.RewardDelegators[k] baseI := i i = encodeVarintNodes(dAtA, i, uint64(v)) i-- @@ -634,7 +534,7 @@ func (m *ProtoValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *ProtoValidatorV8) Marshal() (dAtA []byte, err error) { +func (m *LegacyProtoValidator) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -644,23 +544,16 @@ func (m *ProtoValidatorV8) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ProtoValidatorV8) MarshalTo(dAtA []byte) (int, error) { +func (m *LegacyProtoValidator) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ProtoValidatorV8) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *LegacyProtoValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.OutputAddress) > 0 { - i -= len(m.OutputAddress) - copy(dAtA[i:], m.OutputAddress) - i = encodeVarintNodes(dAtA, i, uint64(len(m.OutputAddress))) - i-- - dAtA[i] = 0x4a - } n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.UnstakingCompletionTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.UnstakingCompletionTime):]) if err2 != nil { return 0, err2 @@ -727,92 +620,6 @@ func (m *ProtoValidatorV8) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *LegacyProtoValidator) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LegacyProtoValidator) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LegacyProtoValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - n3, err3 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.UnstakingCompletionTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.UnstakingCompletionTime):]) - if err3 != nil { - return 0, err3 - } - i -= n3 - i = encodeVarintNodes(dAtA, i, uint64(n3)) - i-- - dAtA[i] = 0x42 - { - size := m.StakedTokens.Size() - i -= size - if _, err := m.StakedTokens.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintNodes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a - if len(m.ServiceURL) > 0 { - i -= len(m.ServiceURL) - copy(dAtA[i:], m.ServiceURL) - i = encodeVarintNodes(dAtA, i, uint64(len(m.ServiceURL))) - i-- - dAtA[i] = 0x32 - } - if len(m.Chains) > 0 { - for iNdEx := len(m.Chains) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Chains[iNdEx]) - copy(dAtA[i:], m.Chains[iNdEx]) - i = encodeVarintNodes(dAtA, i, uint64(len(m.Chains[iNdEx]))) - i-- - dAtA[i] = 0x2a - } - } - if m.Status != 0 { - i = encodeVarintNodes(dAtA, i, uint64(m.Status)) - i-- - dAtA[i] = 0x20 - } - if m.Jailed { - i-- - if m.Jailed { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x18 - } - if len(m.PublicKey) > 0 { - i -= len(m.PublicKey) - copy(dAtA[i:], m.PublicKey) - i = encodeVarintNodes(dAtA, i, uint64(len(m.PublicKey))) - i-- - dAtA[i] = 0x12 - } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintNodes(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *ValidatorSigningInfo) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -843,12 +650,12 @@ func (m *ValidatorSigningInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x28 } - n4, err4 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.JailedUntil, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.JailedUntil):]) - if err4 != nil { - return 0, err4 + n3, err3 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.JailedUntil, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.JailedUntil):]) + if err3 != nil { + return 0, err3 } - i -= n4 - i = encodeVarintNodes(dAtA, i, uint64(n4)) + i -= n3 + i = encodeVarintNodes(dAtA, i, uint64(n3)) i-- dAtA[i] = 0x22 if m.Index != 0 { @@ -920,8 +727,8 @@ func (m *ProtoValidator) Size() (n int) { if l > 0 { n += 1 + l + sovNodes(uint64(l)) } - if len(m.Delegators) > 0 { - for k, v := range m.Delegators { + if len(m.RewardDelegators) > 0 { + for k, v := range m.RewardDelegators { _ = k _ = v mapEntrySize := 1 + len(k) + sovNodes(uint64(len(k))) + 1 + sovNodes(uint64(v)) @@ -931,47 +738,6 @@ func (m *ProtoValidator) Size() (n int) { return n } -func (m *ProtoValidatorV8) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovNodes(uint64(l)) - } - l = len(m.PublicKey) - if l > 0 { - n += 1 + l + sovNodes(uint64(l)) - } - if m.Jailed { - n += 2 - } - if m.Status != 0 { - n += 1 + sovNodes(uint64(m.Status)) - } - if len(m.Chains) > 0 { - for _, s := range m.Chains { - l = len(s) - n += 1 + l + sovNodes(uint64(l)) - } - } - l = len(m.ServiceURL) - if l > 0 { - n += 1 + l + sovNodes(uint64(l)) - } - l = m.StakedTokens.Size() - n += 1 + l + sovNodes(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.UnstakingCompletionTime) - n += 1 + l + sovNodes(uint64(l)) - l = len(m.OutputAddress) - if l > 0 { - n += 1 + l + sovNodes(uint64(l)) - } - return n -} - func (m *LegacyProtoValidator) Size() (n int) { if m == nil { return 0 @@ -1345,7 +1111,7 @@ func (m *ProtoValidator) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 10: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Delegators", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardDelegators", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -1372,8 +1138,8 @@ func (m *ProtoValidator) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Delegators == nil { - m.Delegators = make(map[string]uint32) + if m.RewardDelegators == nil { + m.RewardDelegators = make(map[string]uint32) } var mapkey string var mapvalue uint32 @@ -1454,329 +1220,7 @@ func (m *ProtoValidator) Unmarshal(dAtA []byte) error { iNdEx += skippy } } - m.Delegators[mapkey] = mapvalue - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipNodes(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthNodes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProtoValidatorV8) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProtoValidatorV8: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProtoValidatorV8: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) - if m.Address == nil { - m.Address = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PublicKey = append(m.PublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.PublicKey == nil { - m.PublicKey = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Jailed", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Jailed = bool(v != 0) - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) - } - m.Status = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Status |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Chains", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Chains = append(m.Chains, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ServiceURL", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ServiceURL = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StakedTokens", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.StakedTokens.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field UnstakingCompletionTime", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.UnstakingCompletionTime, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OutputAddress", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowNodes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthNodes - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthNodes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.OutputAddress = append(m.OutputAddress[:0], dAtA[iNdEx:postIndex]...) - if m.OutputAddress == nil { - m.OutputAddress = []byte{} - } + m.RewardDelegators[mapkey] = mapvalue iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/nodes/types/util_test.go b/x/nodes/types/util_test.go index e438ae49f..e1009de3c 100644 --- a/x/nodes/types/util_test.go +++ b/x/nodes/types/util_test.go @@ -26,25 +26,42 @@ func TestValidateServiceURL(t *testing.T) { assert.NotNil(t, ValidateServiceURL(invalidURLBad), "invalid bad url") } +func TestCompareSlices(t *testing.T) { + assert.True(t, CompareSlices([]string{"1"}, []string{"1"})) + assert.True(t, CompareSlices([]int{3, 1}, []int{3, 1})) + assert.False(t, CompareSlices([]int{3, 1}, []int{3, 2})) + assert.False(t, CompareSlices([]int{3, 1}, []int{3})) + + // Empty and nil slices are identical + assert.True(t, CompareSlices([]int{}, nil)) + assert.True(t, CompareSlices(nil, []int{})) + assert.True(t, CompareSlices([]int{}, []int{})) +} + func TestCompareStringMaps(t *testing.T) { m1 := map[string]int{} m2 := map[string]int{} assert.True(t, CompareStringMaps(m1, m2)) + // m1 is non-empty and m2 is empty m1["a"] = 10 m1["b"] = 100 assert.False(t, CompareStringMaps(m1, m2)) + // m1 and m2 are not empty and identical m2["b"] = 100 m2["a"] = 10 assert.True(t, CompareStringMaps(m2, m1)) + // m1 is non-empty and m2 is nil m2 = nil assert.False(t, CompareStringMaps(m1, m2)) assert.False(t, CompareStringMaps(nil, m1)) + // m1 and m2 are both nil m1 = nil assert.True(t, CompareStringMaps(m1, m2)) + // Empty and nil maps are identical assert.True(t, CompareStringMaps(nil, map[string]int{})) } diff --git a/x/nodes/types/validator.go b/x/nodes/types/validator.go index 344ef46a7..7f526e5af 100644 --- a/x/nodes/types/validator.go +++ b/x/nodes/types/validator.go @@ -15,16 +15,17 @@ import ( ) type Validator struct { - Address sdk.Address `json:"address" yaml:"address"` // address of the validator; hex encoded in JSON - PublicKey crypto.PublicKey `json:"public_key" yaml:"public_key"` // the consensus public key of the validator; hex encoded in JSON - Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from staked status? - Status sdk.StakeStatus `json:"status" yaml:"status"` // validator status (staked/unstaking/unstaked) - Chains []string `json:"chains" yaml:"chains"` // validator non native blockchains - ServiceURL string `json:"service_url" yaml:"service_url"` // url where the pocket service api is hosted - StakedTokens sdk.BigInt `json:"tokens" yaml:"tokens"` // tokens staked in the network - UnstakingCompletionTime time.Time `json:"unstaking_time" yaml:"unstaking_time"` // if unstaking, min time for the validator to complete unstaking - OutputAddress sdk.Address `json:"output_address,omitempty" yaml:"output_address"` // the custodial output address of the validator - Delegators map[string]uint32 `json:"delegators,omitempty" yaml:"delegators"` + Address sdk.Address `json:"address" yaml:"address"` // address of the validator; hex encoded in JSON + PublicKey crypto.PublicKey `json:"public_key" yaml:"public_key"` // the consensus public key of the validator; hex encoded in JSON + Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from staked status? + Status sdk.StakeStatus `json:"status" yaml:"status"` // validator status (staked/unstaking/unstaked) + Chains []string `json:"chains" yaml:"chains"` // validator non native blockchains + ServiceURL string `json:"service_url" yaml:"service_url"` // url where the pocket service api is hosted + StakedTokens sdk.BigInt `json:"tokens" yaml:"tokens"` // tokens staked in the network + UnstakingCompletionTime time.Time `json:"unstaking_time" yaml:"unstaking_time"` // if unstaking, min time for the validator to complete unstaking + OutputAddress sdk.Address `json:"output_address,omitempty" yaml:"output_address"` // the custodial output address of the validator + // Mapping from delegated-to addresses to a percentage of rewards + RewardDelegators map[string]uint32 `json:"reward_delegators,omitempty" yaml:"reward_delegators"` } // NewValidator - initialize a new validator @@ -53,7 +54,7 @@ func NewValidatorFromMsg(msg MsgStake) Validator { StakedTokens: msg.Value, UnstakingCompletionTime: time.Time{}, OutputAddress: msg.Output, - Delegators: msg.Delegators, + RewardDelegators: msg.RewardDelegators, } } @@ -184,8 +185,8 @@ func (v Validator) String() string { outputPubKeyString = v.OutputAddress.String() } delegatorsStr := "" - if v.Delegators != nil { - if jsonBytes, err := json.Marshal(v.Delegators); err == nil { + if v.RewardDelegators != nil { + if jsonBytes, err := json.Marshal(v.RewardDelegators); err == nil { delegatorsStr = string(jsonBytes) } else { delegatorsStr = err.Error() @@ -201,7 +202,7 @@ ServiceUrl: %s Chains: %v Unstaking Completion Time: %v Output Address: %s -Delegators: %s +Reward Delegators: %s ---- `, v.Address, @@ -231,7 +232,7 @@ func (v Validator) MarshalJSON() ([]byte, error) { StakedTokens: v.StakedTokens, UnstakingCompletionTime: v.UnstakingCompletionTime, OutputAddress: v.OutputAddress, - Delegators: v.Delegators, + RewardDelegators: v.RewardDelegators, }) } @@ -255,7 +256,7 @@ func (v *Validator) UnmarshalJSON(data []byte) error { Status: bv.Status, UnstakingCompletionTime: bv.UnstakingCompletionTime, OutputAddress: bv.OutputAddress, - Delegators: bv.Delegators, + RewardDelegators: bv.RewardDelegators, } return nil } @@ -276,7 +277,7 @@ func (v ProtoValidator) FromProto() (Validator, error) { StakedTokens: v.StakedTokens, UnstakingCompletionTime: v.UnstakingCompletionTime, OutputAddress: v.OutputAddress, - Delegators: v.Delegators, + RewardDelegators: v.RewardDelegators, }, nil } @@ -292,21 +293,22 @@ func (v Validator) ToProto() ProtoValidator { StakedTokens: v.StakedTokens, UnstakingCompletionTime: v.UnstakingCompletionTime, OutputAddress: v.OutputAddress, - Delegators: v.Delegators, + RewardDelegators: v.RewardDelegators, } } type JSONValidator struct { - Address sdk.Address `json:"address" yaml:"address"` // address of the validator; hex encoded in JSON - PublicKey string `json:"public_key" yaml:"public_key"` // the consensus public key of the validator; hex encoded in JSON - Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from staked status? - Status sdk.StakeStatus `json:"status" yaml:"status"` // validator status (staked/unstaking/unstaked) - Chains []string `json:"chains" yaml:"chains"` // validator non native blockchains - ServiceURL string `json:"service_url" yaml:"service_url"` // url where the pocket service api is hosted - StakedTokens sdk.BigInt `json:"tokens" yaml:"tokens"` // tokens staked in the network - UnstakingCompletionTime time.Time `json:"unstaking_time" yaml:"unstaking_time"` // if unstaking, min time for the validator to complete unstaking - OutputAddress sdk.Address `json:"output_address" yaml:"output_address"` // custodial output address of tokens - Delegators map[string]uint32 `json:"delegators" yaml:"delegators"` + Address sdk.Address `json:"address" yaml:"address"` // address of the validator; hex encoded in JSON + PublicKey string `json:"public_key" yaml:"public_key"` // the consensus public key of the validator; hex encoded in JSON + Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from staked status? + Status sdk.StakeStatus `json:"status" yaml:"status"` // validator status (staked/unstaking/unstaked) + Chains []string `json:"chains" yaml:"chains"` // validator non native blockchains + ServiceURL string `json:"service_url" yaml:"service_url"` // url where the pocket service api is hosted + StakedTokens sdk.BigInt `json:"tokens" yaml:"tokens"` // tokens staked in the network + UnstakingCompletionTime time.Time `json:"unstaking_time" yaml:"unstaking_time"` // if unstaking, min time for the validator to complete unstaking + OutputAddress sdk.Address `json:"output_address" yaml:"output_address"` // custodial output address of tokens + // Mapping from delegated-to addresses to a percentage of rewards + RewardDelegators map[string]uint32 `json:"reward_delegators" yaml:"reward_delegators"` } // Validators is a collection of Validator diff --git a/x/nodes/types/validator_legacy.go b/x/nodes/types/validator_legacy.go index 467c72ec4..6b7ac615a 100644 --- a/x/nodes/types/validator_legacy.go +++ b/x/nodes/types/validator_legacy.go @@ -9,9 +9,8 @@ import ( sdk "github.com/pokt-network/pocket-core/types" ) -// Make sure these structs implement ProtoMarshaler +// Compilation level enforcement to validate that structs implement ProtoMarshaler var _ codec.ProtoMarshaler = &LegacyValidator{} -var _ codec.ProtoMarshaler = &LegacyValidator8{} type LegacyValidator struct { Address sdk.Address `json:"address" yaml:"address"` // address of the validator; hex encoded in JSON @@ -24,7 +23,7 @@ type LegacyValidator struct { UnstakingCompletionTime time.Time `json:"unstaking_time" yaml:"unstaking_time"` // if unstaking, min time for the validator to complete unstaking } -func (v LegacyValidator) ExactEqualsTo(v2 LegacyValidator) bool { +func (v LegacyValidator) Equals(v2 LegacyValidator) bool { return v.Address.Equals(v2.Address) && v.PublicKey.Equals(v2.PublicKey) && v.Jailed == v2.Jailed && @@ -157,6 +156,7 @@ func (v LegacyValidator) ToValidator() Validator { StakedTokens: v.StakedTokens, UnstakingCompletionTime: v.UnstakingCompletionTime, OutputAddress: nil, + RewardDelegators: nil, } } @@ -173,20 +173,6 @@ func (v Validator) ToLegacy() LegacyValidator { } } -func (v Validator) ToLegacy8() LegacyValidator8 { - return LegacyValidator8{ - Address: v.Address, - PublicKey: v.PublicKey, - Jailed: v.Jailed, - Status: v.Status, - Chains: v.Chains, - ServiceURL: v.ServiceURL, - StakedTokens: v.StakedTokens, - UnstakingCompletionTime: v.UnstakingCompletionTime, - OutputAddress: v.OutputAddress, - } -} - // FromProto converts the Protobuf structure to Validator func (v LegacyProtoValidator) FromProto() (LegacyValidator, error) { pubkey, err := crypto.NewPublicKeyBz(v.PublicKey) @@ -218,137 +204,3 @@ func (v LegacyValidator) ToProto() LegacyProtoValidator { UnstakingCompletionTime: v.UnstakingCompletionTime, } } - -type LegacyValidator8 struct { - Address sdk.Address `json:"address" yaml:"address"` // address of the validator; hex encoded in JSON - PublicKey crypto.PublicKey `json:"public_key" yaml:"public_key"` // the consensus public key of the validator; hex encoded in JSON - Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from staked status? - Status sdk.StakeStatus `json:"status" yaml:"status"` // validator status (staked/unstaking/unstaked) - Chains []string `json:"chains" yaml:"chains"` // validator non native blockchains - ServiceURL string `json:"service_url" yaml:"service_url"` // url where the pocket service api is hosted - StakedTokens sdk.BigInt `json:"tokens" yaml:"tokens"` // tokens staked in the network - UnstakingCompletionTime time.Time `json:"unstaking_time" yaml:"unstaking_time"` // if unstaking, min time for the validator to complete unstaking - OutputAddress sdk.Address `json:"output_address,omitempty" yaml:"output_address"` // the custodial output address of the validator -} - -func (v LegacyValidator8) ToLegacy() LegacyValidator { - return LegacyValidator{ - Address: v.Address, - PublicKey: v.PublicKey, - Jailed: v.Jailed, - Status: v.Status, - Chains: v.Chains, - ServiceURL: v.ServiceURL, - StakedTokens: v.StakedTokens, - UnstakingCompletionTime: v.UnstakingCompletionTime, - } -} - -func (v LegacyValidator8) ToValidator() Validator { - return Validator{ - Address: v.Address, - PublicKey: v.PublicKey, - Jailed: v.Jailed, - Status: v.Status, - Chains: v.Chains, - ServiceURL: v.ServiceURL, - StakedTokens: v.StakedTokens, - UnstakingCompletionTime: v.UnstakingCompletionTime, - OutputAddress: v.OutputAddress, - } -} - -func (v LegacyValidator8) ToProto() ProtoValidatorV8 { - return ProtoValidatorV8{ - Address: v.Address, - PublicKey: v.PublicKey.RawBytes(), - Jailed: v.Jailed, - Status: int32(v.Status), - Chains: v.Chains, - ServiceURL: v.ServiceURL, - StakedTokens: v.StakedTokens, - UnstakingCompletionTime: v.UnstakingCompletionTime, - OutputAddress: v.OutputAddress, - } -} - -func (v ProtoValidatorV8) FromProto() (LegacyValidator8, error) { - pubkey, err := crypto.NewPublicKeyBz(v.PublicKey) - if err != nil { - return LegacyValidator8{}, err - } - return LegacyValidator8{ - Address: v.Address, - PublicKey: pubkey, - Jailed: v.Jailed, - Status: sdk.StakeStatus(v.Status), - ServiceURL: v.ServiceURL, - Chains: v.Chains, - StakedTokens: v.StakedTokens, - UnstakingCompletionTime: v.UnstakingCompletionTime, - OutputAddress: v.OutputAddress, - }, nil -} - -func (v *LegacyValidator8) Marshal() ([]byte, error) { - a := v.ToProto() - return a.Marshal() -} - -func (v *LegacyValidator8) MarshalTo(data []byte) (n int, err error) { - a := v.ToProto() - return a.MarshalTo(data) -} - -func (v *LegacyValidator8) MarshalToSizedBuffer(dAtA []byte) (int, error) { - a := v.ToProto() - return a.MarshalToSizedBuffer(dAtA) -} - -func (v *LegacyValidator8) Size() int { - a := v.ToProto() - return a.Size() -} - -func (v *LegacyValidator8) Unmarshal(data []byte) error { - var vp ProtoValidatorV8 - err := vp.Unmarshal(data) - if err != nil { - return err - } - *v, err = vp.FromProto() - return err -} - -func (v *LegacyValidator8) Reset() { - *v = LegacyValidator8{} -} - -func (v LegacyValidator8) String() string { - return fmt.Sprintf(`Address: %s -Public Key: %s -Jailed: %v -Status: %s -Tokens: %s -ServiceUrl: %s -Chains: %v -Unstaking Completion Time: %v -Output Address: %s ----- -`, - v.Address, - v.PublicKey.RawString(), - v.Jailed, - v.Status, - v.StakedTokens, - v.ServiceURL, - v.Chains, - v.UnstakingCompletionTime, - v.OutputAddress, - ) -} - -func (v LegacyValidator8) ProtoMessage() { - val := v.ToValidator() - val.ProtoMessage() -} diff --git a/x/pocketcore/keeper/claim.go b/x/pocketcore/keeper/claim.go index 7807128ed..79a52f896 100644 --- a/x/pocketcore/keeper/claim.go +++ b/x/pocketcore/keeper/claim.go @@ -25,9 +25,8 @@ func (k Keeper) SendClaimTx( // get the private val key (main) account from the keybase address := node.GetAddress() validator := k.posKeeper.Validator(ctx, address) - // The cost to earn relay rewards from an evidence - rewardCost := k.authKeeper.GetFee(ctx, pc.MsgClaim{}). - Add(k.authKeeper.GetFee(ctx, pc.MsgProof{})) + // get the cost to earn relay rewards + rewardCost := k.posKeeper.GetRewardCost(ctx) // retrieve the iterator to go through each piece of evidence in storage iter := pc.EvidenceIterator(node.EvidenceStore) defer iter.Close() @@ -55,7 +54,7 @@ func (k Keeper) SendClaimTx( } continue } - if validator != nil && pc.GlobalPocketConfig.NotClaimPossiblyNegativeRewards { + if validator != nil && pc.GlobalPocketConfig.PreventNegativeRewardClaim { rewardExpected, _ := k.posKeeper.CalculateRelayReward( ctx, evidence.Chain, @@ -64,8 +63,8 @@ func (k Keeper) SendClaimTx( ) if rewardExpected.LTE(rewardCost) { // If the expected amount of relay rewards from this evidence is less - // than the cost of claiming/proofing the evicence, claining the - // evidece is a potential loss. + // than the cost of claiming/proofing the evidence, claiming the + // evidence is a potential loss. // // It's still "potential" because the amount of relay rewards is // calculated when the network processes a proof transaction. It's @@ -77,7 +76,8 @@ func (k Keeper) SendClaimTx( "chain", evidence.Chain, "proofs", evidence.NumOfProofs, "rewardExpected", rewardExpected, - "cost", rewardCost) + "rewardCost", rewardCost, + ) if err := pc.DeleteEvidence( evidence.SessionHeader, evidenceType, diff --git a/x/pocketcore/types/expectedKeepers.go b/x/pocketcore/types/expectedKeepers.go index 88e727348..ce6c17225 100644 --- a/x/pocketcore/types/expectedKeepers.go +++ b/x/pocketcore/types/expectedKeepers.go @@ -32,6 +32,7 @@ type PosKeeper interface { StakeDenom(ctx sdk.Ctx) (res string) GetValidatorsByChain(ctx sdk.Ctx, networkID string) (validators []sdk.Address, total int) MaxChains(ctx sdk.Ctx) (maxChains int64) + GetRewardCost(ctx sdk.Ctx) sdk.BigInt } type AppsKeeper interface { diff --git a/x/pocketcore/types/service_test.go b/x/pocketcore/types/service_test.go index 800ac16c7..a03d6d1e2 100644 --- a/x/pocketcore/types/service_test.go +++ b/x/pocketcore/types/service_test.go @@ -362,6 +362,10 @@ func (m MockPosKeeper) CalculateRelayReward( panic("implement me") } +func (m MockPosKeeper) GetRewardCost(ctx sdk.Ctx) sdk.BigInt { + panic("implement me") +} + func (m MockPosKeeper) RewardForRelays(ctx sdk.Ctx, relays sdk.BigInt, address sdk.Address) sdk.BigInt { panic("implement me") }