8000 Delegate Stake for PegNet (for Delegatees: Pool) by SiriusWhi · Pull Request #420 · pegnet/pegnet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Delegate Stake for PegNet (for Delegatees: Pool) #420

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a476b4b
Merge pull request #409 from pegnet/develop
StarNeit Feb 25, 2021
7447c67
DefaultConfig, CreateSPREntry, SPR
Aug 14, 2021
1e4ed5a
Check StakingMode if it is 'DelegatingStake' in ValidateDelegateStaki…
Aug 14, 2021
a79b2ea
DelegateStaker configuration in defaultconfig.ini
Aug 14, 2021
f235240
Add more validation in ValidateDelegateStakingConfig
Aug 14, 2021
6aaeb67
Pass delegatorSignatures to CreateSPREntry()
Aug 14, 2021
b043db7
Add delegatorSignatures to ExtIDs in CreateSPREntry
Aug 14, 2021
b40a800
Add CreateDelegateSPREntry() function
Aug 14, 2021
24f17cc
Set StakingMode correctly in ValidateDelegateStakingConfig
Aug 14, 2021
5c9bf68
New validation for Staking configuration
Aug 14, 2021
49dc19c
LoadDelegatorsSignatures
Aug 14, 2021
1acf3aa
LoadDelegatorsSignatures
Aug 14, 2021
a7e5758
LoadDelegatorsSignatures
Aug 14, 2021
e7e5871
CreateDelegateSPREntry
Aug 15, 2021
5100617
CreateSPREntry()
Aug 15, 2021
d0f28e9
writeStakingRecord()
Aug 15, 2021
cc14973
writeStakingRecord()
Aug 15, 2021
be5e650
writeStakingRecord()
Aug 15, 2021
9ae9c59
Add signauture of delegatorsSignaturesContents to ExtIDs in CreateDel…
Aug 17, 2021
e39e336
Add signauture of delegatorsSignaturesContents to ExtIDs in CreateDel…
Aug 17, 2021
427176d
s4grader
Aug 17, 2021
5b425e9
CreateDelegateSPREntry
Aug 17, 2021
f81ec35
GradingSPRV2
Aug 17, 2021
8a75742
S4Payout
Aug 17, 2021
b3af4af
Add activation height
Aug 17, 2021
0ee08be
Add spr version
Aug 17, 2021
4d2ec60
ValidateS4
Aug 17, 2021
0cad6f0
NewGraderV4
Aug 17, 2021
0b1d4e9
getDelegatorsAddress
Aug 18, 2021
9c8f3ec
getDelegatorsAddress
Aug 18, 2021
995ae05
GetDelegatorsAddress
Aug 18, 2021
084e515
StakingHeights/TestNetwork
Aug 18, 2021
b15ef6d
DelegatedGradedBlock
Aug 18, 2021
e0cddb2
Remove Duplicate Values from delegators list
Aug 19, 2021
4dd18d9
Enhance ValidateS4 function with more validation
Aug 19, 2021
9d93359
Enhance ValidateS4 function with more validation
Aug 19, 2021
982ce14
s4Grader algorithm using balance and grade
Aug 19, 2021
f2492a0
PIP18DelegateStakingActivation
Aug 30, 2021
f9e524d
PIP18DelegateStakingActivation
Aug 30, 2021
d6acc94
PIP18DelegateStakingActivation
Sep 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
RootCmd.AddCommand(networkMinerCmd)
RootCmd.AddCommand(datasources)
RootCmd.AddCommand(staker)
RootCmd.AddCommand(delegateStaker)

decode.AddCommand(decodeEntry)
decode.AddCommand(decodeEblock)
Expand Down Expand Up @@ -337,6 +338,26 @@ var staker = &cobra.Command{
},
}

var delegateStaker = &cobra.Command{
Use: "dstake ",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("This is delegate staking...")
ctx, cancel := context.WithCancel(context.Background())
common.GlobalExitHandler.AddCancel(cancel)

ValidateDelegateStakingConfig(Config) // Will fatal log if it fails

// Services
monitor := LaunchFactomMonitor(Config)

// This is a blocking call
coord_s := LaunchStaker(Config, ctx, monitor)

// Calling cancel() will cancel the staker
var _, _ = cancel, coord_s
},
}

// -------------------------------------------------------------
// RPC Wrapper Commands

Expand Down
41 changes: 41 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,46 @@ func ValidateStakingConfig(config *config.Config) {
if err != nil {
log.WithError(err).Fatal("failed to read staker network from config")
}

StakingMode, err := config.String("Staker.StakingMode")
if err != nil {
log.WithError(err).Fatal("failed to StakingMode from config")
}
if StakingMode != "SoleStake" {
log.WithError(err).Fatal("please set StakingMode correctly in the config")
}
}

// ValidateDelegateStakingConfig will validate the config is up to snuff.
// Do w/e config validation we want. Will fatal if it fails
func ValidateDelegateStakingConfig(config *config.Config) {
_, err := config.String("Staker.Protocol")
if err != nil {
log.WithError(err).Fatal("failed to read staker protocol from config")
}

_, err = config.String("Staker.Network")
if err != nil {
log.WithError(err).Fatal("failed to read staker network from config")
}

StakingMode, err := config.String("Staker.StakingMode")
if err != nil {
log.WithError(err).Fatal("failed to read StakingMode from config")
}
if StakingMode != "DelegatingStake" {
log.WithError(err).Fatal("please set StakingMode correctly in the config")
}

_, err = config.String("DelegateStaker.DelagateeAddress")
if err != nil {
log.WithError(err).Fatal("failed to read DelagateeAddress info from config")
}

_, err = config.String("DelegateStaker.DelegatorList")
if err != nil {
log.WithError(err).Fatal("failed to read DelegatorList info from config")
}
}

func initLogger() {
Expand Down Expand Up @@ -175,6 +215,7 @@ func rootPreRunSetup(cmd *cobra.Command, args []string) error {
common.V20HeightActivation = 0
common.SprSignatureActivation = 0
common.V202EnhanceActivation = 0
common.PIP18DelegateStakingActivation = 0
}

if testingact, _ := cmd.Flags().GetInt32("testingact"); testingact != -1 {
Expand Down
25 changes: 17 additions & 8 deletions common/activation.go
6D47
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@ var (
if height < V202EnhanceActivation {
return 6
}
return 7 // Latest code version
if height < PIP18DelegateStakingActivation {
return 7
}
return 8 // Latest code version
},
TestNetwork: func(height int64) uint8 {
if height < SprSignatureActivation {
return 5
}
if height < V202EnhanceActivation {
return 6
}
return 7 // Latest code version
//if height < SprSignatureActivation {
// return 5
//}
//if height < V202EnhanceActivation {
// return 6
//}
//if height < PIP18DelegateStakingActivation {
// return 7
//}
return 8 // Latest code version
},
}

Expand All @@ -80,6 +86,9 @@ var (
// V202EnhanceActivation indicates the activation of PegNet 2.0.2.
// Estimated to be XXXXX XXX XXX
V202EnhanceActivation int64 = 274036

// PIP18DelegateStakingActivation implements delegate staking.
PIP18DelegateStakingActivation int64 = 314482
)

// NetworkActive returns true if the network height is above the activation height.
Expand Down
54 changes: 54 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
package common

import (
"bufio"
"fmt"
"os"
"strconv"
"strings"

"github.com/zpatrick/go-config"
Expand Down Expand Up @@ -31,6 +34,57 @@ func LoadConfigStakerNetwork(c *config.Config) (string, error) {
return GetNetwork(network)
}

func LoadDelegatorsSignatures(c *config.Config, delegatee string) []byte {
delegateeAddresses, err := c.String("DelegateStaker.DelagateeAddress")
if err != nil {
return nil
}
delegatorList, err := c.String("DelegateStaker.DelegatorList")
if err != nil {
return nil
}

delegateeAddrs := strings.Split(delegateeAddresses, ",")
delegatorsPaths := strings.Split(delegatorList, ",")

var dPath = ""
for i := 0; i < len(delegateeAddrs); i++ {
if delegateeAddrs[i] == delegatee {
dPath = delegatorsPaths[i]
break
}
}

// Read signature data from file
path := os.ExpandEnv(dPath)
f, err := os.Open(path)
if err != nil {
return nil
}

defer f.Close()
scanner := bufio.NewScanner(f)

var delegatorsSigResult []byte
for scanner.Scan() {
sigData := scanner.Text()
sigDataStr := strings.Split(sigData, " ")
var byteArray []byte
for i := 0; i < len(sigDataStr); i++ {
i, _ := strconv.Atoi(sigDataStr[i])
byteArray = append(byteArray, byte(i))
}
fmt.Println(byteArray)
delegatorsSigResult = append(delegatorsSigResult[:], byteArray[:]...)
}

if err := scanner.Err(); err != nil {
return nil
}

return delegatorsSigResult
}

func GetNetwork(network string) (string, error) {
switch strings.ToLower(network) {
case strings.ToLower(MainNetwork):
Expand Down
16 changes: 16 additions & 0 deletions config/defaultconfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
ControlPanelPort=8080

[Staker]
# StakingMode can be "DelegatingStake" or "SoleStake".
StakingMode="SoleStake"

# Factom Connection Options (if using Docker, use values below)
# FactomdLocation="localhost:8088"
# WalletdLocation="localhost:8089"
Expand All @@ -77,8 +80,21 @@
ECAddress=EC3TsJHUs8bzbbVnratBafub6toRYdgzgbR7kWwCW4tqbmyySRmg

# This is your address. Generate a FCT address and put it here, so if you win, you will be rewarded!
# If you have multiple FCT addresses, then you can add multiple ones using comma(,)
# For example, CoinbaseAddress=FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q,FA2ocUwsU6oeG4tjNnZUY7LRqQ8Yg9ciKdMqajeYH3abZju4YREU
CoinbaseAddress=CHANGEME

[DelegateStaker]
# This is a delegatee's FCT address. ex: FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q
# If you want multiple DelegateeAddress, you can add them using comma(,)
# For example, DelagateeAddress=FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q,FA2ocUwsU6oeG4tjNnZUY7LRqQ8Yg9ciKdMqajeYH3abZju4YREU
DelagateeAddress=CHANGEME

# This is a list of delegators signatures. ex: $HOME/.pegnet/delegators01.txt
# In case it is multiple path info, use comma too.
# For example, DelegatorList=$HOME/.pegnet/delegators01.txt,$HOME/.pegnet/delegators02.txt
DelegatorList=CHANGEME

[Miner]
# Factom Connection Options (if using Docker, use values below)
FactomdLocation="localhost:8088"
Expand Down
Loading
0