Skip to content

Commit

Permalink
Feat/Qb-2063: Add sp beneficiary address (#311)
Browse files Browse the repository at this point in the history
* Add beneficiary address to meta node
* update cli & rest api
* update version to v0.12.0
* solve conflicts

---------

Co-authored-by: alexstratos <[email protected]>
  • Loading branch information
Xiong-stratos and alexstratos authored Nov 1, 2023
1 parent 8a3a3c0 commit 19d1774
Show file tree
Hide file tree
Showing 23 changed files with 4,216 additions and 371 deletions.
6 changes: 5 additions & 1 deletion proto/stratos/register/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ message GenesisMetaNode {
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
]; // owner address of the meta node
Description description = 7 [
string beneficiary_address = 7 [
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
]; // reward beneficiary address of the meta node
Description description = 8 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
Expand Down
8 changes: 6 additions & 2 deletions proto/stratos/register/v1/register.proto
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ message MetaNode {
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 7 [
string beneficiary_address = 7 [
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
Description description = 8 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
google.protobuf.Timestamp creation_time = 8 [
google.protobuf.Timestamp creation_time = 9 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.stdtime) = true,
Expand Down
16 changes: 13 additions & 3 deletions proto/stratos/register/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ message MsgCreateMetaNode {
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 5 [
string beneficiary_address = 5 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
Description description = 6 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "description",
Expand Down Expand Up @@ -197,12 +202,17 @@ message MsgUpdateMetaNode {
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
string network_address = 2 [
string beneficiary_address = 2 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "beneficiary_address",
(gogoproto.moretags) = "yaml:\"beneficiary_address\""
];
string network_address = 3 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
];
string owner_address = 3 [
string owner_address = 4 [
(cosmos_proto.scalar) = "cosmos.AddressString",
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
Expand Down
3 changes: 2 additions & 1 deletion x/pot/app_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
balances = make([]banktypes.Balance, 0)

accInitBalance = sdkmath.NewInt(100).Mul(sdkmath.NewInt(stratos.StosToWei))
initFoundationDeposit = sdk.NewCoins(sdk.NewCoin(stratos.Utros, sdkmath.NewInt(40000000000000000)))
initFoundationDeposit = sdk.NewCoins(sdk.NewCoin(stratos.Wei, sdkmath.NewInt(40000000000000000).MulRaw(stratos.GweiToWei)))

nodeInitDeposit = sdkmath.NewInt(1 * stratos.StosToWei)
prepayAmt = sdk.NewCoins(stratos.NewCoin(sdkmath.NewInt(20).Mul(sdkmath.NewInt(stratos.StosToWei))))
Expand Down Expand Up @@ -227,6 +227,7 @@ func setupNodesBenchmark() (createValidatorMsg *stakingtypes.MsgCreateValidator,
keyInfo.P2PAddress(),
keyInfo.P2PPubKey(),
keyInfo.OwnerAddress(),
keyInfo.OwnerAddress(),
registertypes.NewDescription(keyInfo.P2PAddressBech32(), "", "", "", ""),
time,
)
Expand Down
70 changes: 39 additions & 31 deletions x/pot/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import (
)

const (
chainID = "testchain_1-1"
rewardDenom = stratos.Utros
chainID = "testchain_1-1"

stopFlagOutOfTotalMiningReward = true
stopFlagSpecificMinedReward = false
Expand All @@ -58,29 +57,35 @@ var (

foundationDepositorPrivKey = secp256k1.GenPrivKey()
foundationDepositorAccAddr = sdk.AccAddress(foundationDepositorPrivKey.PubKey().Address())
foundationDeposit = sdk.NewCoins(sdk.NewCoin(rewardDenom, sdkmath.NewInt(40000000000000000)))
foundationDeposit = sdk.NewCoins(sdk.NewCoin(stratos.Wei, sdkmath.NewInt(40000000000000000).MulRaw(stratos.GweiToWei)))

nodeInitialDeposit = sdkmath.NewInt(1 * stratos.StosToWei)
initBalance = sdkmath.NewInt(100).Mul(sdkmath.NewInt(stratos.StosToWei))

// wallet private keys
resOwnerPrivKey1 = secp256k1.GenPrivKey()
resOwnerPrivKey2 = secp256k1.GenPrivKey()
resOwnerPrivKey3 = secp256k1.GenPrivKey()
resOwnerPrivKey4 = secp256k1.GenPrivKey()
resOwnerPrivKey5 = secp256k1.GenPrivKey()
metaOwnerPrivKey1 = secp256k1.GenPrivKey()
metaOwnerPrivKey2 = secp256k1.GenPrivKey()
metaOwnerPrivKey3 = secp256k1.GenPrivKey()
resOwnerPrivKey1 = secp256k1.GenPrivKey()
resOwnerPrivKey2 = secp256k1.GenPrivKey()
resOwnerPrivKey3 = secp256k1.GenPrivKey()
resOwnerPrivKey4 = secp256k1.GenPrivKey()
resOwnerPrivKey5 = secp256k1.GenPrivKey()
metaOwnerPrivKey1 = secp256k1.GenPrivKey()
metaOwnerPrivKey2 = secp256k1.GenPrivKey()
metaOwnerPrivKey3 = secp256k1.GenPrivKey()
metaBeneficiaryPrivKey1 = metaOwnerPrivKey1
metaBeneficiaryPrivKey2 = secp256k1.GenPrivKey()
metaBeneficiaryPrivKey3 = secp256k1.GenPrivKey()
// wallet addresses
resOwner1 = sdk.AccAddress(resOwnerPrivKey1.PubKey().Address())
resOwner2 = sdk.AccAddress(resOwnerPrivKey2.PubKey().Address())
resOwner3 = sdk.AccAddress(resOwnerPrivKey3.PubKey().Address())
resOwner4 = sdk.AccAddress(resOwnerPrivKey4.PubKey().Address())
resOwner5 = sdk.AccAddress(resOwnerPrivKey5.PubKey().Address())
metaOwner1 = sdk.AccAddress(metaOwnerPrivKey1.PubKey().Address())
metaOwner2 = sdk.AccAddress(metaOwnerPrivKey2.PubKey().Address())
metaOwner3 = sdk.AccAddress(metaOwnerPrivKey3.PubKey().Address())
resOwner1 = sdk.AccAddress(resOwnerPrivKey1.PubKey().Address())
resOwner2 = sdk.AccAddress(resOwnerPrivKey2.PubKey().Address())
resOwner3 = sdk.AccAddress(resOwnerPrivKey3.PubKey().Address())
resOwner4 = sdk.AccAddress(resOwnerPrivKey4.PubKey().Address())
resOwner5 = sdk.AccAddress(resOwnerPrivKey5.PubKey().Address())
metaOwner1 = sdk.AccAddress(metaOwnerPrivKey1.PubKey().Address())
metaOwner2 = sdk.AccAddress(metaOwnerPrivKey2.PubKey().Address())
metaOwner3 = sdk.AccAddress(metaOwnerPrivKey3.PubKey().Address())
metaBeneficiary1 = sdk.AccAddress(metaBeneficiaryPrivKey1.PubKey().Address())
metaBeneficiary2 = sdk.AccAddress(metaBeneficiaryPrivKey2.PubKey().Address())
metaBeneficiary3 = sdk.AccAddress(metaBeneficiaryPrivKey3.PubKey().Address())

// P2P public key of resource nodes
resNodeP2PPubKey1 = ed25519.GenPrivKey().PubKey()
Expand Down Expand Up @@ -361,17 +366,20 @@ func TestPotVolumeReportMsgs(t *testing.T) {
t.Log(" miningReward = " + rewardDetailMap[resOwner5.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[resOwner5.String()].RewardFromTrafficPool.String())

t.Log("indexing_wallet1: address = " + metaOwner1.String())
t.Log(" miningReward = " + rewardDetailMap[metaOwner1.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[metaOwner1.String()].RewardFromTrafficPool.String())
t.Log("meta_owner_wallet1: address = " + metaOwner1.String())
t.Log("meta_beneficiary_wallet1: address = " + metaBeneficiary1.String())
t.Log(" miningReward = " + rewardDetailMap[metaBeneficiary1.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[metaBeneficiary1.String()].RewardFromTrafficPool.String())

t.Log("indexing_wallet2: address = " + metaOwner2.String())
t.Log(" miningReward = " + rewardDetailMap[metaOwner2.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[metaOwner2.String()].RewardFromTrafficPool.String())
t.Log("meta_owner_wallet2: address = " + metaOwner2.String())
t.Log("meta_beneficiary_wallet2: address = " + metaBeneficiary2.String())
t.Log(" miningReward = " + rewardDetailMap[metaBeneficiary2.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[metaBeneficiary2.String()].RewardFromTrafficPool.String())

t.Log("indexing_wallet3: address = " + metaOwner3.String())
t.Log(" miningReward = " + rewardDetailMap[metaOwner3.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[metaOwner3.String()].RewardFromTrafficPool.String())
t.Log("meta_owner_wallet3: address = " + metaOwner3.String())
t.Log("meta_beneficiary_wallet3: address = " + metaBeneficiary3.String())
t.Log(" miningReward = " + rewardDetailMap[metaBeneficiary3.String()].RewardFromMiningPool.String())
t.Log(" trafficReward = " + rewardDetailMap[metaBeneficiary3.String()].RewardFromTrafficPool.String())
t.Log("---------------------------")

/********************* record data before delivering tx *********************/
Expand Down Expand Up @@ -679,9 +687,9 @@ func setupAllMetaNodes() []registertypes.MetaNode {
var indexingNodes []registertypes.MetaNode

time, _ := time.Parse(time.RubyDate, "Fri Sep 24 10:37:13 -0400 2021")
indexingNode1, _ := registertypes.NewMetaNode(metaNodeP2PAddr1, metaNodeP2PPubKey1, metaOwner1, registertypes.NewDescription("indexingNode1", "", "", "", ""), time)
indexingNode2, _ := registertypes.NewMetaNode(metaNodeP2PAddr2, metaNodeP2PPubKey2, metaOwner2, registertypes.NewDescription("indexingNode2", "", "", "", ""), time)
indexingNode3, _ := registertypes.NewMetaNode(metaNodeP2PAddr3, metaNodeP2PPubKey3, metaOwner3, registertypes.NewDescription("indexingNode3", "", "", "", ""), time)
indexingNode1, _ := registertypes.NewMetaNode(metaNodeP2PAddr1, metaNodeP2PPubKey1, metaOwner1, metaBeneficiary1, registertypes.NewDescription("indexingNode1", "", "", "", ""), time)
indexingNode2, _ := registertypes.NewMetaNode(metaNodeP2PAddr2, metaNodeP2PPubKey2, metaOwner2, metaBeneficiary2, registertypes.NewDescription("indexingNode2", "", "", "", ""), time)
indexingNode3, _ := registertypes.NewMetaNode(metaNodeP2PAddr3, metaNodeP2PPubKey3, metaOwner3, metaBeneficiary3, registertypes.NewDescription("indexingNode3", "", "", "", ""), time)

indexingNode1 = indexingNode1.AddToken(nodeInitialDeposit)
indexingNode2 = indexingNode2.AddToken(nodeInitialDeposit)
Expand Down
10 changes: 9 additions & 1 deletion x/pot/keeper/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"errors"
"sort"
"strings"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -229,7 +230,14 @@ func (k Keeper) CalcRewardForMetaNode(ctx sdk.Context, distributeGoalBalance typ
continue
}

walletAddr, err := sdk.AccAddressFromBech32(node.OwnerAddress)
var walletAddrStr string
if len(strings.TrimSpace(node.BeneficiaryAddress)) == 0 {
walletAddrStr = node.OwnerAddress
} else {
walletAddrStr = node.BeneficiaryAddress
}

walletAddr, err := sdk.AccAddressFromBech32(walletAddrStr)
if err != nil {
continue
}
Expand Down
14 changes: 11 additions & 3 deletions x/register/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
FlagCandidateNetworkAddress = "candidate-network-address"
FlagOpinion = "opinion"
FlagVoterNetworkAddress = "voter-network-address"
FlagBeneficiaryAddress = "beneficiary-address"
)

func flagSetDescriptionCreate() *flag.FlagSet {
Expand Down Expand Up @@ -76,9 +77,16 @@ func flagSetDepositUpdate() *flag.FlagSet {
func flagSetVoting() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagCandidateNetworkAddress, "The network address of the candidate PP node", "")
fs.String(FlagCandidateOwnerAddress, "The owner address of the candidate PP node", "")
fs.String(FlagCandidateNetworkAddress, "", "The network address of the candidate PP node")
fs.String(FlagCandidateOwnerAddress, "", "The owner address of the candidate PP node")
fs.Bool(FlagOpinion, false, "Opinion of the vote for the registration of Meta node.")
fs.String(FlagVoterNetworkAddress, "The address of the PP node that made the vote.", "")
fs.String(FlagVoterNetworkAddress, "", "The address of the PP node that made the vote.")
return fs
}

func flagSetBeneficiaryAddress() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagBeneficiaryAddress, "", "The beneficiary address of the meta node")
return fs
}
26 changes: 24 additions & 2 deletions x/register/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"strings"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

Expand Down Expand Up @@ -99,6 +101,7 @@ func CreateMetaNodeCmd() *cobra.Command {
cmd.Flags().AddFlagSet(flagSetAmount())
cmd.Flags().AddFlagSet(flagSetNetworkAddress())
cmd.Flags().AddFlagSet(flagSetDescriptionCreate())
cmd.Flags().AddFlagSet(flagSetBeneficiaryAddress())

flags.AddTxFlagsToCmd(cmd)

Expand Down Expand Up @@ -217,6 +220,7 @@ func UpdateMetaNodeCmd() *cobra.Command {

cmd.Flags().AddFlagSet(flagSetNetworkAddress())
cmd.Flags().AddFlagSet(flagSetDescriptionCreate())
cmd.Flags().AddFlagSet(flagSetBeneficiaryAddress())

flags.AddTxFlagsToCmd(cmd)

Expand Down Expand Up @@ -406,6 +410,15 @@ func newBuildCreateMetaNodeMsg(clientCtx client.Context, fs *flag.FlagSet) (*typ

ownerAddr := clientCtx.GetFromAddress()

beneficiaryAddr := ownerAddr
flagBeneficiaryAddrStr, _ := fs.GetString(FlagBeneficiaryAddress)
if len(strings.TrimSpace(flagBeneficiaryAddrStr)) > 0 {
beneficiaryAddr, err = sdk.AccAddressFromBech32(flagBeneficiaryAddrStr)
if err != nil {
return nil, err
}
}

pkStr, err := fs.GetString(FlagPubKey)
if err != nil {
return nil, err
Expand All @@ -427,7 +440,7 @@ func newBuildCreateMetaNodeMsg(clientCtx client.Context, fs *flag.FlagSet) (*typ
security,
details,
)
msg, er := types.NewMsgCreateMetaNode(networkAddr, pubKey, amount, ownerAddr, description)
msg, er := types.NewMsgCreateMetaNode(networkAddr, pubKey, amount, ownerAddr, beneficiaryAddr, description)
if er != nil {
return nil, err
}
Expand Down Expand Up @@ -487,6 +500,15 @@ func newBuildUpdateMetaNodeMsg(clientCtx client.Context, fs *flag.FlagSet) (*typ

ownerAddr := clientCtx.GetFromAddress()

beneficiaryAddress := sdk.AccAddress{}
flagBeneficiaryAddressStr, _ := fs.GetString(FlagBeneficiaryAddress)
if len(strings.TrimSpace(flagBeneficiaryAddressStr)) > 0 {
beneficiaryAddress, err = sdk.AccAddressFromBech32(flagBeneficiaryAddressStr)
if err != nil {
return nil, err
}
}

moniker, _ := fs.GetString(FlagMoniker)
identity, _ := fs.GetString(FlagIdentity)
website, _ := fs.GetString(FlagWebsite)
Expand All @@ -500,7 +522,7 @@ func newBuildUpdateMetaNodeMsg(clientCtx client.Context, fs *flag.FlagSet) (*typ
details,
)

msg := types.NewMsgUpdateMetaNode(description, networkAddr, ownerAddr)
msg := types.NewMsgUpdateMetaNode(description, networkAddr, ownerAddr, beneficiaryAddress)
return msg, nil
}

Expand Down
5 changes: 5 additions & 0 deletions x/register/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"strings"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -85,6 +87,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
default:
panic(types.ErrInvalidNodeStat)
}
if len(strings.TrimSpace(metaNode.BeneficiaryAddress)) == 0 {
metaNode.BeneficiaryAddress = metaNode.OwnerAddress
}
k.SetMetaNode(ctx, metaNode)
}
// set initial genesis number of meta nodes
Expand Down
10 changes: 7 additions & 3 deletions x/register/keeper/meta_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (k Keeper) GetAllValidMetaNodes(ctx sdk.Context) (metaNodes []types.MetaNod
}

func (k Keeper) RegisterMetaNode(ctx sdk.Context, networkAddr stratos.SdsAddress, pubKey cryptotypes.PubKey, ownerAddr sdk.AccAddress,
description types.Description, deposit sdk.Coin) (ozoneLimitChange sdkmath.Int, err error) {
beneficiaryAddress sdk.AccAddress, description types.Description, deposit sdk.Coin) (ozoneLimitChange sdkmath.Int, err error) {

if _, found := k.GetMetaNode(ctx, networkAddr); found {
ctx.Logger().Error("Meta node already exist")
Expand All @@ -87,7 +87,7 @@ func (k Keeper) RegisterMetaNode(ctx sdk.Context, networkAddr stratos.SdsAddress
return ozoneLimitChange, types.ErrBadDenom
}

metaNode, err := types.NewMetaNode(networkAddr, pubKey, ownerAddr, description, ctx.BlockHeader().Time)
metaNode, err := types.NewMetaNode(networkAddr, pubKey, ownerAddr, beneficiaryAddress, description, ctx.BlockHeader().Time)
if err != nil {
return ozoneLimitChange, err
}
Expand Down Expand Up @@ -435,7 +435,7 @@ func (k Keeper) HandleVoteForMetaNodeRegistration(ctx sdk.Context, candidateNetw
}

func (k Keeper) UpdateMetaNode(ctx sdk.Context, description types.Description,
networkAddr stratos.SdsAddress, ownerAddr sdk.AccAddress) error {
networkAddr stratos.SdsAddress, ownerAddr sdk.AccAddress, beneficiaryAddr sdk.AccAddress) error {

node, found := k.GetMetaNode(ctx, networkAddr)
if !found {
Expand All @@ -447,6 +447,10 @@ func (k Keeper) UpdateMetaNode(ctx sdk.Context, description types.Description,
return types.ErrInvalidOwnerAddr
}

if len(beneficiaryAddr) > 0 {
node.BeneficiaryAddress = beneficiaryAddr.String()
}

node.Description = description

k.SetMetaNode(ctx, node)
Expand Down
Loading

0 comments on commit 19d1774

Please sign in to comment.