dagconfig

package
v0.6.4-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2020 License: ISC Imports: 9 Imported by: 13

README

dagconfig

ISC License GoDoc

Package dagconfig defines DAG configuration parameters for the standard Kaspad networks and provides the ability for callers to define their own custom Kaspad networks.

Sample Use

package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/kaspanet/kaspad/util"
	"github.com/kaspanet/kaspad/domain/dagconfig"
)

var testnet = flag.Bool("testnet", false, "operate on the testnet Kaspa network")

// By default (without --testnet), use mainnet.
var dagParams = &dagconfig.MainnetParams

func main() {
	flag.Parse()

	// Modify active network parameters if operating on testnet.
	if *testnet {
		dagParams = &dagconfig.TestnetParams
	}

	// later...

	// Create and print new payment address, specific to the active network.
	pubKeyHash := make([]byte, 20)
	addr, err := util.NewAddressPubKeyHash(pubKeyHash, dagParams)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(addr)
}

Documentation

Overview

Package dagconfig defines DAG configuration parameters.

In addition to the main Kaspa network, which is intended for the transfer of monetary value, there also exists the following standard networks:

  • testnet
  • simnet
  • devnet
  • regression test

These networks are incompatible with each other (each sharing a different genesis block) and software should handle errors where input intended for one network is used on an application instance running on a different network.

For library packages, dagconfig provides the ability to lookup DAG parameters and encoding magics when passed a *Params.

For main packages, a (typically global) var may be assigned the address of one of the standard Param vars for use as the application's "active" network. When a network parameter is needed, it may then be looked up through this variable (either directly, or hidden in a library call).

package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/kaspanet/kaspad/util"
	"github.com/kaspanet/kaspad/domain/dagconfig"
)

var testnet = flag.Bool("testnet", false, "operate on the testnet Kaspa network")

// By default (without --testnet), use mainnet.
var dagParams = &dagconfig.MainnetParams

func main() {
	flag.Parse()

	// Modify active network parameters if operating on testnet.
	if *testnet {
		dagParams = &dagconfig.TestnetParams
	}

	// later...

	// Create and print new payment address, specific to the active network.
	pubKeyHash := make([]byte, 20)
	addr, err := util.NewAddressPubKeyHash(pubKeyHash, dagParams)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(addr)
}

If an application does not use one of the standard Kaspa networks, a new Params struct may be created which defines the parameters for the non- standard network. As a general rule of thumb, all network parameters should be unique to the network, but parameter collisions can still occur.

Index

Constants

View Source
const (
	// DeploymentTestDummy defines the rule change deployment ID for testing
	// purposes.
	DeploymentTestDummy = iota

	// DefinedDeployments is the number of currently defined deployments.
	DefinedDeployments
)

Constants that define the deployment offset in the deployments field of the parameters for each deployment. This is useful to be able to get the details of a specific deployment by name.

Variables

View Source
var DevnetParams = Params{
	K:           ghostdagK,
	Name:        "kaspa-devnet",
	Net:         appmessage.Devnet,
	RPCPort:     "16610",
	DefaultPort: "16611",
	DNSSeeds:    []string{},

	GenesisBlock:                   &devnetGenesisBlock,
	GenesisHash:                    &devnetGenesisHash,
	PowMax:                         devnetPowMax,
	BlockCoinbaseMaturity:          100,
	SubsidyReductionInterval:       210000,
	TargetTimePerBlock:             targetTimePerBlock,
	FinalityDuration:               finalityDuration,
	DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
	TimestampDeviationTolerance:    timestampDeviationTolerance,

	RuleChangeActivationThreshold: 1512,
	MinerConfirmationWindow:       2016,

	RelayNonStdTxs: true,

	AcceptUnroutable: true,

	Prefix: util.Bech32PrefixKaspaDev,

	PrivateKeyID: 0xef,

	EnableNonNativeSubnetworks: false,

	DisableDifficultyAdjustment: false,
}

DevnetParams defines the network parameters for the development Kaspa network.

View Source
var (
	// ErrDuplicateNet describes an error where the parameters for a Kaspa
	// network could not be set due to the network already being a standard
	// network or previously-registered into this package.
	ErrDuplicateNet = errors.New("duplicate Kaspa network")
)
View Source
var MainnetParams = Params{
	K:           ghostdagK,
	Name:        "kaspa-mainnet",
	Net:         appmessage.Mainnet,
	RPCPort:     "16110",
	DefaultPort: "16111",
	DNSSeeds:    []string{"dnsseed.kas.pa"},

	GenesisBlock:                   &genesisBlock,
	GenesisHash:                    &genesisHash,
	PowMax:                         mainPowMax,
	BlockCoinbaseMaturity:          100,
	SubsidyReductionInterval:       210000,
	TargetTimePerBlock:             targetTimePerBlock,
	FinalityDuration:               finalityDuration,
	DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
	TimestampDeviationTolerance:    timestampDeviationTolerance,

	RuleChangeActivationThreshold: 1916,
	MinerConfirmationWindow:       2016,

	RelayNonStdTxs: false,

	AcceptUnroutable: false,

	Prefix: util.Bech32PrefixKaspa,

	PrivateKeyID: 0x80,

	EnableNonNativeSubnetworks: false,

	DisableDifficultyAdjustment: false,
}

MainnetParams defines the network parameters for the main Kaspa network.

View Source
var RegressionNetParams = Params{
	K:           ghostdagK,
	Name:        "kaspa-regtest",
	Net:         appmessage.Regtest,
	RPCPort:     "16210",
	DefaultPort: "16211",
	DNSSeeds:    []string{},

	GenesisBlock:                   &regtestGenesisBlock,
	GenesisHash:                    &regtestGenesisHash,
	PowMax:                         regressionPowMax,
	BlockCoinbaseMaturity:          100,
	SubsidyReductionInterval:       150,
	TargetTimePerBlock:             targetTimePerBlock,
	FinalityDuration:               finalityDuration,
	DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
	TimestampDeviationTolerance:    timestampDeviationTolerance,

	RuleChangeActivationThreshold: 108,
	MinerConfirmationWindow:       144,

	RelayNonStdTxs: true,

	AcceptUnroutable: false,

	Prefix: util.Bech32PrefixKaspaReg,

	PrivateKeyID: 0xef,

	EnableNonNativeSubnetworks: false,

	DisableDifficultyAdjustment: false,
}

RegressionNetParams defines the network parameters for the regression test Kaspa network. Not to be confused with the test Kaspa network (version 3), this network is sometimes simply called "testnet".

View Source
var SimnetParams = Params{
	K:           ghostdagK,
	Name:        "kaspa-simnet",
	Net:         appmessage.Simnet,
	RPCPort:     "16510",
	DefaultPort: "16511",
	DNSSeeds:    []string{},

	GenesisBlock:                   &simnetGenesisBlock,
	GenesisHash:                    &simnetGenesisHash,
	PowMax:                         simnetPowMax,
	BlockCoinbaseMaturity:          100,
	SubsidyReductionInterval:       210000,
	TargetTimePerBlock:             time.Millisecond,
	FinalityDuration:               time.Minute,
	DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
	TimestampDeviationTolerance:    timestampDeviationTolerance,

	RuleChangeActivationThreshold: 75,
	MinerConfirmationWindow:       100,

	RelayNonStdTxs: true,

	AcceptUnroutable: false,

	PrivateKeyID: 0x64,

	Prefix: util.Bech32PrefixKaspaSim,

	EnableNonNativeSubnetworks: false,

	DisableDifficultyAdjustment: true,
}

SimnetParams defines the network parameters for the simulation test Kaspa network. This network is similar to the normal test network except it is intended for private use within a group of individuals doing simulation testing. The functionality is intended to differ in that the only nodes which are specifically specified are used to create the network rather than following normal discovery rules. This is important as otherwise it would just turn into another public testnet.

View Source
var TestnetParams = Params{
	K:           ghostdagK,
	Name:        "kaspa-testnet",
	Net:         appmessage.Testnet,
	RPCPort:     "16210",
	DefaultPort: "16211",
	DNSSeeds:    []string{"testnet-dnsseed.kas.pa"},

	GenesisBlock:                   &testnetGenesisBlock,
	GenesisHash:                    &testnetGenesisHash,
	PowMax:                         testnetPowMax,
	BlockCoinbaseMaturity:          100,
	SubsidyReductionInterval:       210000,
	TargetTimePerBlock:             targetTimePerBlock,
	FinalityDuration:               finalityDuration,
	DifficultyAdjustmentWindowSize: difficultyAdjustmentWindowSize,
	TimestampDeviationTolerance:    timestampDeviationTolerance,

	RuleChangeActivationThreshold: 1512,
	MinerConfirmationWindow:       2016,

	RelayNonStdTxs: true,

	AcceptUnroutable: false,

	Prefix: util.Bech32PrefixKaspaTest,

	PrivateKeyID: 0xef,

	EnableNonNativeSubnetworks: false,

	DisableDifficultyAdjustment: false,
}

TestnetParams defines the network parameters for the test Kaspa network.

Functions

func Register

func Register(params *Params) error

Register registers the network parameters for a Kaspa network. This may error with ErrDuplicateNet if the network is already registered (either due to a previous Register call, or the network being one of the default networks).

Network parameters should be registered into this package by a main package as early as possible. Then, library packages may lookup networks or network parameters based on inputs and work regardless of the network being standard or not.

Types

type ConsensusDeployment

type ConsensusDeployment struct {
	// BitNumber defines the specific bit number within the block version
	// this particular soft-fork deployment refers to.
	BitNumber uint8

	// StartTime is the median block time after which voting on the
	// deployment starts.
	StartTime uint64

	// ExpireTime is the median block time after which the attempted
	// deployment expires.
	ExpireTime uint64
}

ConsensusDeployment defines details related to a specific consensus rule change that is voted in. This is part of BIP0009.

type KType

type KType uint8

KType defines the size of GHOSTDAG consensus algorithm K parameter.

type Params

type Params struct {
	// K defines the K parameter for GHOSTDAG consensus algorithm.
	// See ghostdag.go for further details.
	K KType

	// Name defines a human-readable identifier for the network.
	Name string

	// Net defines the magic bytes used to identify the network.
	Net appmessage.KaspaNet

	// RPCPort defines the rpc server port
	RPCPort string

	// DefaultPort defines the default peer-to-peer port for the network.
	DefaultPort string

	// DNSSeeds defines a list of DNS seeds for the network that are used
	// as one method to discover peers.
	DNSSeeds []string

	// GenesisBlock defines the first block of the DAG.
	GenesisBlock *appmessage.MsgBlock

	// GenesisHash is the starting block hash.
	GenesisHash *daghash.Hash

	// PowMax defines the highest allowed proof of work value for a block
	// as a uint256.
	PowMax *big.Int

	// BlockCoinbaseMaturity is the number of blocks required before newly mined
	// coins can be spent.
	BlockCoinbaseMaturity uint64

	// SubsidyReductionInterval is the interval of blocks before the subsidy
	// is reduced.
	SubsidyReductionInterval uint64

	// TargetTimePerBlock is the desired amount of time to generate each
	// block.
	TargetTimePerBlock time.Duration

	// FinalityDuration is the duration of the finality window.
	FinalityDuration time.Duration

	// TimestampDeviationTolerance is the maximum offset a block timestamp
	// is allowed to be in the future before it gets delayed
	TimestampDeviationTolerance uint64

	// DifficultyAdjustmentWindowSize is the size of window that is inspected
	// to calculate the required difficulty of each block.
	DifficultyAdjustmentWindowSize uint64

	// These fields are related to voting on consensus rule changes as
	// defined by BIP0009.
	//
	// RuleChangeActivationThreshold is the number of blocks in a threshold
	// state retarget window for which a positive vote for a rule change
	// must be cast in order to lock in a rule change. It should typically
	// be 95% for the main network and 75% for test networks.
	//
	// MinerConfirmationWindow is the number of blocks in each threshold
	// state retarget window.
	//
	// Deployments define the specific consensus rule changes to be voted
	// on.
	RuleChangeActivationThreshold uint64
	MinerConfirmationWindow       uint64

	// Mempool parameters
	RelayNonStdTxs bool

	// AcceptUnroutable specifies whether this network accepts unroutable
	// IP addresses, such as 10.0.0.0/8
	AcceptUnroutable bool

	// Human-readable prefix for Bech32 encoded addresses
	Prefix util.Bech32Prefix

	// Address encoding magics
	PrivateKeyID byte // First byte of a WIF private key

	// EnableNonNativeSubnetworks enables non-native/coinbase transactions
	EnableNonNativeSubnetworks bool

	// DisableDifficultyAdjustment determine whether to use difficulty
	DisableDifficultyAdjustment bool
}

Params defines a Kaspa network by its parameters. These parameters may be used by Kaspa applications to differentiate networks as well as addresses and keys for one network from those intended for use on another network.

func (*Params) NormalizeRPCServerAddress

func (p *Params) NormalizeRPCServerAddress(addr string) (string, error)

NormalizeRPCServerAddress returns addr with the current network default port appended if there is not already a port specified.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL