Skip to content

Commit

Permalink
Merge pull request #172 from pegnet/staging
Browse files Browse the repository at this point in the history
[PegNet 2.0.2] Enhance PegNet 2.0
  • Loading branch information
StarNeit authored Dec 1, 2020
2 parents 098da4b + 2a1c944 commit 97d2b91
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 111 deletions.
10 changes: 10 additions & 0 deletions cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,16 @@ var conv = &cobra.Command{
os.Exit(1)
}

// Let's check the pXXX -> pSmallAssets
// pSmallAssets means the 16 pAssets which have got small market cap.
if (destAsset == "PEG" || destAsset == "pDCR" || destAsset == "pDGB" || destAsset == "pDOGE" || destAsset == "pHBAR" ||
destAsset == "pONT" || destAsset == "pRVN" || destAsset == "pBAT" || destAsset == "pALGO" || destAsset == "pBIF" ||
destAsset == "pETB" || destAsset == "pKES" || destAsset == "pNGN" || destAsset == "pRWF" || destAsset == "pTZS" ||
destAsset == "pUGX") && uint32(status.Current) >= node.OneWaySmallAssetsConversions {
cmd.PrintErrln(fmt.Sprintf("pXXX -> pSmallAssets conversions are not allowed since block height %d.", node.OneWaySmallAssetsConversions))
os.Exit(1)
}

// Build the transaction from the args
var trans fat2.Transaction
if err := setTransactionInput(&trans, cl, originalSource, srcAsset, amt); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

func init() {
rootCmd.PersistentFlags().String("log", "info", "Change the logging level. Can choose from 'trace', 'debug', 'info', 'warn', 'error', or 'fatal'")
rootCmd.PersistentFlags().StringP("network", "", "", "The network for PegNetD")
rootCmd.PersistentFlags().StringP("server", "s", "http://localhost:8088/v2", "The url to the factomd endpoint without a trailing slash")
rootCmd.PersistentFlags().StringP("wallet", "w", "http://localhost:8089/v2", "The url to the factomd-wallet endpoint without a trailing slash")
rootCmd.PersistentFlags().String("walletuser", "", "The username for Wallet RPC")
Expand Down Expand Up @@ -174,6 +175,7 @@ func always(cmd *cobra.Command, args []string) {
// Setup global command line flag overrides
// This gets run before any command executes. It will init global flags to the config
_ = viper.BindPFlag(config.LoggingLevel, cmd.Flags().Lookup("log"))
_ = viper.BindPFlag(config.Network, cmd.Flags().Lookup("network"))
_ = viper.BindPFlag(config.Server, cmd.Flags().Lookup("server"))
_ = viper.BindPFlag(config.Wallet, cmd.Flags().Lookup("wallet"))
_ = viper.BindPFlag(config.WalletUser, cmd.Flags().Lookup("walletuser"))
Expand Down
1 change: 1 addition & 0 deletions config/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
CustomSQLDBMode = "db.mode"
SQLDBWalMode = "db.wal"

Network = "app.Network"
Server = "app.Server"
Wallet = "app.Wallet"
WalletUser = "app.WalletUser"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AdamSLevy/jsonrpc2/v13 v13.0.1
github.com/Factom-Asset-Tokens/factom v0.0.0-20191114224337-71de98ff5b3e
github.com/mattn/go-sqlite3 v1.11.0
github.com/pegnet/pegnet v0.5.1-0.20200828161600-edf138a7971f
github.com/pegnet/pegnet v0.5.1-0.20201201194922-e59c2d3b3061
github.com/rs/cors v1.7.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ github.com/FactomProject/gocoding v0.0.0-20150814232539-59666ce39524 h1:394GwlJF
github.com/FactomProject/gocoding v0.0.0-20150814232539-59666ce39524/go.mod h1:AtAVT8Uf+wlS9h/RK79oum1xym2r9UR5nb67zVEkq6Y=
github.com/FactomProject/goleveldb v0.2.1 h1:aKHpwSwVKEm/JQ97aLN+O7/xjSXjzof71gpPCukM+Ac=
github.com/FactomProject/goleveldb v0.2.1/go.mod h1:35UcJZvsGJAgxqegkfDb5S78gTlx/Pypzy4rZfM1pQA=
github.com/FactomProject/goleveldb v0.2.2-0.20170418171130-e7800c6976c5 h1:GIdre1zKgtyuc3VqjfyHZQNBj3yMO6HgWAvpO190LKg=
github.com/FactomProject/goleveldb v0.2.2-0.20170418171130-e7800c6976c5/go.mod h1:35UcJZvsGJAgxqegkfDb5S78gTlx/Pypzy4rZfM1pQA=
github.com/FactomProject/logrustash v0.0.0-20171005151533-9c7278ede46e h1:D/yNSYLSqUwukUw3115uW4RR+r0ftMUJFlcTC2e79pI=
github.com/FactomProject/logrustash v0.0.0-20171005151533-9c7278ede46e/go.mod h1:ah6QOMU70BGkGZRLG1Irc7f+j6eDU11tzHCI+rdLcoA=
Expand Down Expand Up @@ -272,6 +273,18 @@ github.com/pegnet/pegnet v0.5.1-0.20200827205036-100de49eec4c h1:h23Cy3bYjLS6lIf
github.com/pegnet/pegnet v0.5.1-0.20200827205036-100de49eec4c/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20200828161600-edf138a7971f h1:yukWrl9DXaByX4//6hBKXwiU6udeN5xq6eJL4RcTD48=
github.com/pegnet/pegnet v0.5.1-0.20200828161600-edf138a7971f/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20201116162515-0f9c58ed3bc7 h1:XtO6k4BpvMITFwT/JgoEi8aeYugW2vWiCGM25CD/Hqw=
github.com/pegnet/pegnet v0.5.1-0.20201116162515-0f9c58ed3bc7/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20201119175358-0112a2ffea41 h1:ze3qZ1/AEbYdhpGmfJqFI/TmO6MMFeEAHNNknyvUzS0=
github.com/pegnet/pegnet v0.5.1-0.20201119175358-0112a2ffea41/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20201201100024-3727fcd665ee h1:myHT9uYoClXjo4Pa2JCH+rVfolZ6125/pQKrIXUDz84=
github.com/pegnet/pegnet v0.5.1-0.20201201100024-3727fcd665ee/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20201201103444-dd2dfbb347b0 h1:PC25ljPWv6pUnSN56u3PZxmtVxtAU5kfcKAP94Nvoms=
github.com/pegnet/pegnet v0.5.1-0.20201201103444-dd2dfbb347b0/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20201201124832-35496e177fd4 h1:CRKVQN1O7VgqScBa6D3Oa1ncZkXbU9t8amhK8eLaZNo=
github.com/pegnet/pegnet v0.5.1-0.20201201124832-35496e177fd4/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pegnet/pegnet v0.5.1-0.20201201194922-e59c2d3b3061 h1:b06v5oukL/aXnyZWWPQUBcd7AtRgxMekGJx0H15iqlY=
github.com/pegnet/pegnet v0.5.1-0.20201201194922-e59c2d3b3061/go.mod h1:NxKKJ9wnx/EvzfHk0p6XPlQqXIJg0iA4po0vzsdNx0o=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
Expand Down
5 changes: 0 additions & 5 deletions node/burns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package node

import (
"encoding/hex"

"github.com/Factom-Asset-Tokens/factom"
)

var (
Expand All @@ -13,9 +11,6 @@ var (
// BurnAddress that can be used for all assets
GlobalBurnAddress = "FA2BURNBABYBURNoooooooooooooooooooooooooooooooDGvNXy"

// Global Burn Address as proper FAAddress
FAGlobalBurnAddress factom.FAAddress

// BurnRCD is the rcd representation of the burn address
BurnRCD = [32]byte{}
)
Expand Down
41 changes: 29 additions & 12 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ var (
// SprSignatureActivation indicates the activation of SPR Signature.
// Estimated to be Aug 28th 2020
SprSignatureActivation uint32 = 260118

// OneWaypAssetsConversions makes some pAssets a 1 way conversion.
// pDCR, pDGB, pDOGE, pHBAR, pONT, pRVN, pBAT, pALGO, pBIF, pETB, pKES, pNGN, pRWF, pTZS, pUGX
// These pAssets have got small marketcap, and these will be disabled for conversion.
// Estimated to be Dec 3th 2020
OneWaySmallAssetsConversions uint32 = 274036

// V202EnhanceActivation indicates the activation of PegNet 2.0.2.
// Estimated to be Dec 3th 2020
V202EnhanceActivation uint32 = 274036
)

func SetAllActivations(act uint32) {
Expand All @@ -76,6 +86,9 @@ func SetAllActivations(act uint32) {
V4OPRUpdate = act
V20HeightActivation = act
V20DevRewardsHeightActivation = act
OneWaySmallAssetsConversions = act
SprSignatureActivation = act
V202EnhanceActivation = act
}

type Pegnetd struct {
Expand All @@ -87,6 +100,9 @@ type Pegnetd struct {
}

func NewPegnetd(ctx context.Context, conf *viper.Viper) (*Pegnetd, error) {
// init chainIds
InitChainsFromConfig(conf)

// TODO : Update emyrk's factom library
n := new(Pegnetd)
n.FactomClient = FactomClientFromConfig(conf)
Expand Down Expand Up @@ -119,18 +135,6 @@ func NewPegnetd(ctx context.Context, conf *viper.Viper) (*Pegnetd, error) {
}
}

// init burn address
FAGlobalBurnAddress, err := factom.NewFAAddress(GlobalBurnAddress)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Info("error getting burn address")
}

log.WithFields(log.Fields{
"addr": FAGlobalBurnAddress,
}).Info("burn address loaded")

grader.InitLX()
return n, nil
}
Expand All @@ -147,3 +151,16 @@ func FactomClientFromConfig(conf *viper.Viper) *factom.Client {

return cl
}

func InitChainsFromConfig(conf *viper.Viper) {
network := conf.GetString(config.Network)
if network == "MainNet" {
OPRChain = factom.NewBytes32("a642a8674f46696cc47fdb6b65f9c87b2a19c5ea8123b3d2f0c13b6f33a9d5ef")
SPRChain = factom.NewBytes32("d5e395125335a21cef0ceca528168e87fe929fdac1f156870c1b1be6502448b4")
TransactionChain = factom.NewBytes32("cffce0f409ebba4ed236d49d89c70e4bd1f1367d86402a3363366683265a242d")
} else if network == "TestNet" {
OPRChain = factom.NewBytes32("ad98d39f002d4cae9ed07a8f5689cb029a83ad3b4bd8d23c49345d4ca7ca4393")
SPRChain = factom.NewBytes32("e3b1668158026b2450d123ba993aca5367a8b96c6018f63640101a28b8ab5bc7")
TransactionChain = factom.NewBytes32("2ac925fe946543a83d4c232d788dd589177611c0dbe970172c21b42039682a8a")
}
}
1 change: 0 additions & 1 deletion node/opr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"fmt"

"github.com/Factom-Asset-Tokens/factom"
"github.com/pegnet/pegnet/modules/grader"
)
Expand Down
13 changes: 9 additions & 4 deletions node/pegnet/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ var (

// -2 is an invalid tx. Usually by timestamps

PFCTOneWayError = errors.New("pFCT conversions are one way only at this height, they cannot be a conversion destination")
PFCTOneWayErrorInt int64 = -3
ZeroRatesError = errors.New("an asset in the conversion has a rate of 0, and not allowed to be used for conversions")
ZeroRatesErrorInt int64 = -4
PFCTOneWayError = errors.New("pFCT conversions are one way only at this height, they cannot be a conversion destination")
PFCTOneWayErrorInt int64 = -3
ZeroRatesError = errors.New("an asset in the conversion has a rate of 0, and not allowed to be used for conversions")
ZeroRatesErrorInt int64 = -4
PSMALLOneWayError = errors.New("small marketcap assets conversions are one way only at this height, they cannot be a conversion destination")
PSMALLOneWayErrorInt int64 = -5
)

// IsRejectedTx takes an error, and returns the integer form of that error
Expand All @@ -27,6 +29,9 @@ func IsRejectedTx(err error) (int64, error) {
if err == PFCTOneWayError {
return PFCTOneWayErrorInt, nil
}
if err == PSMALLOneWayError {
return PSMALLOneWayErrorInt, nil
}
if err == ZeroRatesError {
return ZeroRatesErrorInt, nil
}
Expand Down
60 changes: 0 additions & 60 deletions node/pegnet/txhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,63 +555,3 @@ func (p *Pegnet) InsertDeveloperRewardCoinbase(tx *sql.Tx, txid string, addTxid

return nil
}

// Special construction to nullify burn address
func (p *Pegnet) InsertZeroingCoinbase(tx *sql.Tx, txid string, addTxid string, height uint32, heightTimestamp time.Time, payout uint64, asset string, faAdd factom.FAAddress) error {
txidBytes, err := hex.DecodeString(txid)
if err != nil {
return err
}

// First we need to record the batch. The batch is the entire set of transactions, where
// each tx is a stake payout.
stmt, err := tx.Prepare(`INSERT INTO "pn_history_txbatch"
(entry_hash, height, blockorder, timestamp, executed) VALUES
(?, ?, ?, ?, ?)`)
if err != nil {
return err
}

// The Entryhash is the custom txid, it is not an actual entry on chain
// The executed height is the same height as the recorded.
_, err = stmt.Exec(txidBytes, height, 0, heightTimestamp.Unix(), height)
if err != nil {
return err
}

// Now we record balance zeroing .

// All addresses are stored as bytes in the sqlitedb
add := faAdd[:]
// index for the address
index, _, err := SplitTxID(addTxid)
if err != nil {
return err
}

// Decrease each balance as a coinbase.
// Insert the TX
coinbaseStatement, err := tx.Prepare(`INSERT INTO "pn_history_transaction"
(entry_hash, tx_index, action_type, from_address, from_asset, from_amount, to_asset, to_amount, outputs) VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)`)
if err != nil {
return err
}

_, err = coinbaseStatement.Exec(txidBytes, index, Coinbase, add, "", 0, asset, -payout, "") // -payout means we substract value
if err != nil {
return err
}

// Insert into lookup table
lookup, err := tx.Prepare(insertLookupQuery)
if err != nil {
return err
}

if _, err = lookup.Exec(txidBytes, index, add); err != nil {
return err
}

return nil
}
3 changes: 3 additions & 0 deletions node/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func (d *Pegnetd) GradeS(ctx context.Context, block *factom.EBlock) (graderStake
if block.Height >= SprSignatureActivation {
ver = 6
}
if block.Height >= V202EnhanceActivation {
ver = 7
}

g, err := graderStake.NewGrader(ver, int32(block.Height))
if err != nil {
Expand Down
Loading

0 comments on commit 97d2b91

Please sign in to comment.